From 3d36d1d0254b8aeecc889a2a49cbcced458cbe9c Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sat, 25 Feb 2023 23:08:47 +0100 Subject: intermediate commit * Implement move artifact action * Fix widget update memory leak * update the highlights not during on each frame * do not update the unchanged label of a button * Allow to exit the game by pressing 'q' * Implement some cards from the magic set * Improve permanent formatting * Some tweaks to UnitAI code --- go/client/game.go | 14 ++++++++++++-- go/client/main.go | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'go/client') diff --git a/go/client/game.go b/go/client/game.go index 8dc69b25..0e516815 100644 --- a/go/client/game.go +++ b/go/client/game.go @@ -32,6 +32,8 @@ const ( ) type Game struct { + app *app + selectedObject interface{} handLayer *ui.HandView @@ -58,6 +60,7 @@ type Game struct { func newGame(app *app) *Game { g := &Game{ + app: app, Collection: ui.Collection{ Width: app.windowWidth, Height: app.windowHeight, @@ -110,6 +113,7 @@ func (g *Game) addActivePlayer(name string, deckList string) *Game { func (g *Game) addPrompt(action game.Action, prompt string) { g.prompt = ui.NewPrompt(g.Height/2, g.Width, action, prompt) g.AddWidget(g.prompt) + g.updateHighlight() } func (g *Game) getPlayer(name string) *game.Player { @@ -202,9 +206,11 @@ func (g *Game) addPermActionChoice(perm game.Permanent, x, y int) { } perms := []game.Permanent{perm} + labels := []string{perm.Card().Name} for _, p := range perm.Pile() { if len(p.CurrentlyAvailActions()) > 0 { perms = append(perms, p) + labels = append(labels, p.Card().Name) } } @@ -215,7 +221,7 @@ func (g *Game) addPermActionChoice(perm game.Permanent, x, y int) { p := perms[c.GetChoosen(x, y)] g.addActionChoice(p, x, y) } - g.addChoice(ui.NewPermChoice(x, y, perms, onClick)) + g.addChoice(ui.NewChoice(x, y, utils.TypedSliceToInterfaceSlice(labels), onClick)) } else { g.selectedObject = perms[0] g.addActionChoice(perms[0], x, y) @@ -289,6 +295,7 @@ func (g *Game) progressPrompt() { targets := a.Targets() if targets.RequireSelection() { targets.Next() + g.updateHighlight() } else { g.declareAction(a) g.removePrompt() @@ -515,12 +522,16 @@ func (g *Game) Update() error { if err := g.prompt.Add(obj); err != nil { log.Println("Not added", obj, "to active prompt:", err) g.handleSelection(obj, x, y) + } else { + g.updateHighlight() } } else { g.handleSelection(obj, x, y) } } else if inpututil.IsKeyJustPressed(ebiten.KeySpace) { g.passButton.Click(0, 0) + } else if inpututil.IsKeyJustPressed(ebiten.KeyQ) { + return fmt.Errorf("Exit") } else if inpututil.IsKeyJustPressed(ebiten.KeyEscape) { g.removeChoice() g.selectedObject = nil @@ -541,7 +552,6 @@ func (g *Game) Update() error { return err } - g.updateHighlight() g.updatePassButton() return nil } diff --git a/go/client/main.go b/go/client/main.go index 82b60a40..86491a4d 100644 --- a/go/client/main.go +++ b/go/client/main.go @@ -94,6 +94,8 @@ func main() { app.pushActivity(startMenu) if err := ebiten.RunGame(app); err != nil { - log.Fatal(err) + if err.Error() != "Exit" { + log.Fatal(err) + } } } -- cgit v1.2.3