Skip to content

Commit

Permalink
feat: change levelup screen to popup
Browse files Browse the repository at this point in the history
  • Loading branch information
zwindler committed Jul 23, 2023
1 parent 5929d07 commit c37dd3d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 40 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ Every session, I'll add an entry in this file telling what I did and what I lear
sudo apt-get install golang gcc libgl1-mesa-dev xorg-dev
```

## 2023-07-23

Following on yesterday's idea (changing the levelup screen to just a ShowCustomConfirm popup). Documentation is here (https://pkg.go.dev/fyne.io/fyne/v2/dialog#ShowCustomConfirm)

```go
func ShowCustomConfirm(title, confirm, dismiss string, content fyne.CanvasObject,
callback func(bool), parent fyne.Window)
```

I just have to implement callback (which is code from the Validate button in my previous levelup.go screen). Basically it's just `player.RefreshStats()`

```go
dialog.ShowCustomConfirm("Level up!", "Validate", "Close", levelUpPopup, func(validate bool) {
if validate {
player.RefreshStats()
updateStatsBox()
}
}, currentWindow)
```

Easy peasy

## 2023-07-22

Making better AI will require looking into "pathfinding" topics. Fortunately, friends from Twitter gave me some documentation to read:
Expand Down
9 changes: 8 additions & 1 deletion screens/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/layout"
)

Expand Down Expand Up @@ -223,7 +224,13 @@ func mapKeyListener(event *fyne.KeyEvent) {
if player.ChangeXP(npc.LootXP) {
levelUpEntry := fmt.Sprintf("Level up! You are now level %d", model.Player.Level)
addLogEntry(levelUpEntry)
ShowLevelUpScreen(currentWindow)
levelUpPopup := showLevelUpScreen()
dialog.ShowCustomConfirm("Level up!", "Validate", "Close", levelUpPopup, func(validate bool) {
if validate {
player.RefreshStats()
updateStatsBox()
}
}, currentWindow)
}
player.ChangeGold(npc.LootGold)
NPCList.RemoveNPCByIndex(npcId)
Expand Down
42 changes: 3 additions & 39 deletions screens/levelup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import (
"fyne.io/fyne/v2/widget"
)

func ShowLevelUpScreen(window fyne.Window) {

characterNameLabel := widget.NewLabel("Character's name")
characterNameValue := widget.NewLabel(model.Player.CharacterName)

func showLevelUpScreen() *fyne.Container {
pointsToSpendLabel := widget.NewLabel("Remaining points")
pointsToSpendValue := widget.NewLabel(fmt.Sprintf("%d", model.Player.PointsToSpend))

Expand Down Expand Up @@ -44,42 +40,9 @@ func ShowLevelUpScreen(window fyne.Window) {
&model.Player.DexterityValue, currentDexterity, &model.Player.PointsToSpend,
dexterityLabel, pointsToSpendValue)

backButton := widget.NewButton("Back", func() {
ShowGameScreen(window)
})
validateButton := widget.NewButton("Validate", func() {
model.Player.GetMaxHP()
model.Player.CurrentHP = model.Player.MaxHP

model.Player.GetMaxMP()
model.Player.CurrentMP = model.Player.MaxMP

model.Player.DetermineBaseDamage()

ShowGameScreen(window)
})

firstLine := container.New(layout.NewFormLayout(),
characterNameLabel,
characterNameValue,
)

slidersLine := container.New(layout.NewGridLayout(5),
return container.New(layout.NewGridLayout(5),
pointsToSpendLabel, strengthLabel, constitutionLabel, intelligenceLabel, dexterityLabel,
pointsToSpendValue, strengthRange, constitutionRange, intelligenceRange, dexterityRange)

lastLine := container.NewHBox(
backButton,
validateButton,
)

content := container.NewVBox(
firstLine,
slidersLine,
lastLine,
)

window.SetContent(content)
}

func createSliderLevelUpWithCallback(characteristic string, min float64, max float64,
Expand Down Expand Up @@ -109,3 +72,4 @@ func createSliderLevelUpWithCallback(characteristic string, min float64, max flo
}
return slider
}

0 comments on commit c37dd3d

Please sign in to comment.