diff options
Diffstat (limited to 'go/client')
| -rw-r--r-- | go/client/game.go | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/go/client/game.go b/go/client/game.go index 00ef4153..77baa4ad 100644 --- a/go/client/game.go +++ b/go/client/game.go @@ -70,7 +70,7 @@ type Game struct { handLayer *ui.HandView stateBar *ui.StateBar mapView *ui.MapView - actionChoice *ui.Choice + choice *ui.Choice passButton *ui.SimpleButton discardPileView *ui.PocList discardPileButton *ui.SimpleButton @@ -252,23 +252,51 @@ func (g *Game) removeWidgetAt(idx int) { g.widgets = g.widgets[:nwidgets-1] } +func (g *Game) addPermActionChoice(perm game.Permanent, x, y int) { + if len(perm.Pile()) == 0 { + g.addActionChoice(perm, x, y) + return + } + + perms := []game.Permanent{perm} + for _, p := range perm.Pile() { + if len(p.AvailActions()) > 0 { + perms = append(perms, p) + } + } + + if len(perms) > 1 { + g.selectedObject = perms + onClick := func(c *ui.Choice, x, y int) { + g.removeChoice() + p := perms[c.GetChoosen(x, y)] + g.addActionChoice(p, x, y) + } + g.choice = ui.NewPermChoice(x, y, perms, onClick) + g.addWidget(g.choice) + } else { + g.selectedObject = perms[0] + g.addActionChoice(perms[0], x, y) + } +} + func (g *Game) addActionChoice(perm game.Permanent, x, y int) { actions := perm.AvailActions() if len(actions) > 0 { g.selectedObject = perm onClick := func(c *ui.Choice, x, y int) { - g.removeActionChoice() + g.removeChoice() a := actions[c.GetChoosen(x, y)] g.selectedObject = a } - g.actionChoice = ui.NewActionChoice(x, y, actions, onClick) - g.addWidget(g.actionChoice) + g.choice = ui.NewActionChoice(x, y, actions, onClick) + g.addWidget(g.choice) } } -func (g *Game) removeActionChoice() { - g.removeWidget(g.actionChoice) - g.actionChoice = nil +func (g *Game) removeChoice() { + g.removeWidget(g.choice) + g.choice = nil } func (g *Game) AddHighlight(obj interface{}) { @@ -394,7 +422,7 @@ func (g *Game) handleSelection(obj interface{}, x, y int) { case game.Permanent: perm := obj - g.addActionChoice(perm, x, y) + g.addPermActionChoice(perm, x, y) case ui.HandCard: g.selectedObject = game.NewPlayAction(g.activePlayer, obj.C) @@ -496,7 +524,7 @@ func (g *Game) Update() error { } else if inpututil.IsKeyJustPressed(ebiten.KeySpace) { g.passButton.Click(0, 0) } else if inpututil.IsKeyJustPressed(ebiten.KeyEscape) { - g.removeActionChoice() + g.removeChoice() g.selectedObject = nil g.hoverDetector.reset() g.clearMapHighlights() |
