From c37dd3d5d320994b27acec6eb4c0d41abdfad28a Mon Sep 17 00:00:00 2001 From: Denis GERMAIN Date: Sun, 23 Jul 2023 10:54:07 +0200 Subject: [PATCH] feat: change levelup screen to popup --- README.md | 22 ++++++++++++++++++++++ screens/game.go | 9 ++++++++- screens/levelup.go | 42 +++--------------------------------------- 3 files changed, 33 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 0696f88..a3ad7d0 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/screens/game.go b/screens/game.go index 03c5bd0..84c7d29 100644 --- a/screens/game.go +++ b/screens/game.go @@ -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" ) @@ -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) diff --git a/screens/levelup.go b/screens/levelup.go index a79f690..036ad75 100644 --- a/screens/levelup.go +++ b/screens/levelup.go @@ -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)) @@ -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, @@ -109,3 +72,4 @@ func createSliderLevelUpWithCallback(characteristic string, min float64, max flo } return slider } +