aboutsummaryrefslogtreecommitdiff
path: root/go/client
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-04 18:51:31 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:47 +0100
commite9070ef3752c5d2ab1f9faac48095995772ce726 (patch)
treed1842db95e73039224476d0a5794d951e3fdfb3b /go/client
parentea54efacae089aa3644cfe00c8e180d5cc2c8d9e (diff)
downloadmuhqs-game-e9070ef3752c5d2ab1f9faac48095995772ce726.tar.gz
muhqs-game-e9070ef3752c5d2ab1f9faac48095995772ce726.zip
improve permanent pile support
* Fix alot of bugs caused by permanents without tiles * Implement a permanent choice to select the permanents in a pile * Fix how pile hooks are called
Diffstat (limited to 'go/client')
-rw-r--r--go/client/game.go46
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()