aboutsummaryrefslogtreecommitdiff
path: root/go/client
diff options
context:
space:
mode:
Diffstat (limited to 'go/client')
-rw-r--r--go/client/game.go173
1 files changed, 114 insertions, 59 deletions
diff --git a/go/client/game.go b/go/client/game.go
index 32fb5f2f..5ae2fbe8 100644
--- a/go/client/game.go
+++ b/go/client/game.go
@@ -26,6 +26,8 @@ const (
STATE_BAR_WIDTH = 300
POC_BUTTON_WIDTH = 150
+
+ AUTO_PROGRESS_PROMPT = true
)
type Game struct {
@@ -70,11 +72,7 @@ func newGame(app *app) *Game {
"Pass",
func(*ui.SimpleButton) {
if g.prompt != nil {
- a := g.prompt.Confirm()
- g.declareAction(a)
- g.RemoveWidget(g.prompt)
- g.prompt = nil
-
+ g.progressPrompt()
} else if g.hasPriority {
g.passPriority()
}
@@ -108,6 +106,11 @@ func (g *Game) addActivePlayer(name string, deckList string) *Game {
return g.initPlayerUi(p)
}
+func (g *Game) addPrompt(action game.Action, prompt string) {
+ g.prompt = ui.NewPrompt(g.Height/2, g.Width, action, prompt)
+ g.AddWidget(g.prompt)
+}
+
func (g *Game) getPlayer(name string) *game.Player {
for _, p := range g.gameState.Players {
if p.Name == name {
@@ -227,7 +230,7 @@ func (g *Game) addActionChoice(perm game.Permanent, x, y int) {
g.removeChoice()
a := actions[c.GetChoosen(x, y)]
if a.Targets() != nil && a.Targets().RequireSelection() {
- g.selectedObject = a
+ g.addPrompt(a, fmt.Sprintf("Select targets for %v", a))
} else {
g.declareAction(a)
}
@@ -242,7 +245,23 @@ func (g *Game) removeChoice() {
g.choice = nil
}
-func (g *Game) AddHighlight(obj interface{}) {
+func (g *Game) progressPrompt() {
+ a := g.prompt.Action()
+ targets := a.Targets()
+ if targets.RequireSelection() {
+ targets.Next()
+ } else {
+ g.declareAction(a)
+ g.removePrompt()
+ }
+}
+
+func (g *Game) removePrompt() {
+ g.RemoveWidget(g.prompt)
+ g.prompt = nil
+}
+
+func (g *Game) addHighlight(obj interface{}) {
switch obj := obj.(type) {
case ui.HandCard:
g.handLayer.AddHighlightCard(obj.C)
@@ -257,18 +276,27 @@ func (g *Game) AddHighlight(obj interface{}) {
}
}
+func (g *Game) addHighlights(objs []interface{}) {
+ for _, obj := range objs {
+ g.addHighlight(obj)
+ }
+}
+
func (g *Game) clearMapHighlights() {
g.mapView.ClearPermanentsHighlights()
g.mapView.ClearTileHighlights()
g.mapView.ForceRedraw()
}
-func (g *Game) declareAction(a game.Action) {
- g.playerCtrl.SendAction(a)
+func (g *Game) clearHighlights() {
g.clearMapHighlights()
g.handLayer.ClearHighlights()
+}
+
+func (g *Game) declareAction(a game.Action) {
+ g.playerCtrl.SendAction(a)
+ g.clearHighlights()
g.hasPriority = false
- g.hidePassButton()
g.stateBar.ForceRedraw()
}
@@ -280,6 +308,34 @@ func (g *Game) hidePassButton() {
g.RemoveWidget(g.passButton)
}
+func (g *Game) updatePassButton() {
+ if g.prompt == nil && !g.hasPriority {
+ g.hidePassButton()
+ }
+
+ passButtonLabel := "pass"
+ if g.prompt != nil {
+ targets := g.prompt.Action().Targets()
+ if targets.RequireSelection() {
+ if !targets.Cur().HasSelection() {
+ g.hidePassButton()
+ return
+ }
+ passButtonLabel = "next"
+ } else {
+ passButtonLabel = "confirm"
+ }
+
+ if AUTO_PROGRESS_PROMPT && !targets.Cur().AllowSelection() {
+ g.progressPrompt()
+ return
+ }
+ }
+
+ g.showPassButton()
+ g.passButton.UpdateLabel(passButtonLabel)
+}
+
func (g *Game) passPriority() {
g.declareAction(game.NewPassPriority(g.activePlayer))
}
@@ -290,7 +346,6 @@ func (g *Game) handlePlayerNotifications() {
log.Println("Received", n)
switch n.Notification {
case game.PriorityNotification:
- g.showPassButton()
g.hasPriority = true
case game.DeclaredActionNotification:
@@ -318,10 +373,7 @@ func (g *Game) handlePlayerNotifications() {
g.showStore()
}
}
-
- g.prompt = ui.NewPrompt(g.Height/2, g.Width, ctx.Action, ctx.Prompt)
- g.AddWidget(g.prompt)
- g.showPassButton()
+ g.addPrompt(ctx.Action, ctx.Prompt)
}
g.stateBar.ForceRedraw()
@@ -348,77 +400,81 @@ func (g *Game) findObjectAt(x, y int) interface{} {
return nil
}
-func (g *Game) handleTargetSelection(obj interface{}) {
- a := g.selectedObject.(game.Action)
- err := a.Targets().AddSelection(obj)
- if err != nil {
- log.Println("Not added", obj, "as target for", a, "because", err)
- }
-
- if !a.Targets().RequireSelection() {
- g.declareAction(a)
- g.selectedObject = nil
- }
-}
-
func (g *Game) handleSelection(obj interface{}, x, y int) {
if obj == nil {
fmt.Printf("No object found at cursor position (%d, %d)\n", x, y)
return
}
- if _, ok := g.selectedObject.(game.Action); ok {
- g.handleTargetSelection(obj)
- } else {
- switch obj := obj.(type) {
- case *game.Tile:
- if g.storesOnMap && obj.Type == game.TileTypes.Store && g.activePlayer.KnowsStore(obj.Position) {
- if g.storeView != nil {
- g.hideStore()
- }
+ switch obj := obj.(type) {
+ case *game.Tile:
+ if g.storesOnMap && obj.Type == game.TileTypes.Store &&
+ g.activePlayer.KnowsStore(obj.Position) {
- g.storeView = ui.NewPocList(x, y, g.gameState.Map.StoreOn(obj.Position))
- g.showStore()
+ if g.storeView != nil {
+ g.hideStore()
}
- case game.Permanent:
- perm := obj
- g.addPermActionChoice(perm, x, y)
+ g.storeView = ui.NewPocList(x, y, g.gameState.Map.StoreOn(obj.Position))
+ g.showStore()
+ }
- case ui.HandCard:
- g.selectedObject = game.NewPlayAction(g.activePlayer, obj.C)
- g.handLayer.HighlightCard(obj.C)
+ case game.Permanent:
+ perm := obj
+ g.addPermActionChoice(perm, x, y)
- default:
- log.Panicf("Object of type %T not handled", obj)
+ case ui.HandCard:
+ a := game.NewPlayAction(g.activePlayer, obj.C)
+ if a.Targets().RequireSelection() {
+ g.addPrompt(a, fmt.Sprintf("Select targets to play %v", obj.C.Name))
+ g.handLayer.HighlightCard(obj.C)
+ } else {
+ g.declareAction(a)
}
+
+ default:
+ log.Panicf("Object of type %T not handled", obj)
}
}
-func (g *Game) highlightTargets() {
- a, ok := g.selectedObject.(game.Action)
- if !ok {
+func (g *Game) updateHighlight() {
+ g.clearHighlights()
+ if g.prompt == nil {
return
}
- options := a.Targets().Options()
- for _, option := range options {
- g.AddHighlight(option)
+ a := g.prompt.Action()
+ if pa, ok := a.(*game.PlayAction); ok {
+ g.addHighlight(ui.HandCard{C: pa.Card})
+ }
+
+ targets := a.Targets()
+ if len(targets.Targets()) == 0 {
+ return
+ }
+
+ for _, t := range targets.Targets() {
+ g.addHighlights(t.Selection())
+ }
+
+ target := targets.Cur()
+ if target.AllowSelection() {
+ options := target.Options()
+ g.addHighlights(options)
}
}
func (g *Game) Update() error {
g.handlePlayerNotifications()
- g.highlightTargets()
+ g.updateHighlight()
+ g.updatePassButton()
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
x, y := ebiten.CursorPosition()
obj := g.findObjectAt(x, y)
if g.prompt != nil {
- if err := g.prompt.Add(obj); err == nil {
- g.AddHighlight(obj)
- } else {
+ if err := g.prompt.Add(obj); err != nil {
log.Println("Not added", obj, "to active prompt:", err)
g.handleSelection(obj, x, y)
}
@@ -431,8 +487,7 @@ func (g *Game) Update() error {
g.removeChoice()
g.selectedObject = nil
g.ResetHover()
- g.clearMapHighlights()
- g.handLayer.ClearHighlights()
+ g.clearHighlights()
g.hideStore()
g.RemoveWidget(g.discardPileView)
if g.prompt != nil {