aboutsummaryrefslogtreecommitdiff
path: root/go/client/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/client/main.go')
-rw-r--r--go/client/main.go60
1 files changed, 49 insertions, 11 deletions
diff --git a/go/client/main.go b/go/client/main.go
index b8f1bf7a..62fa52c1 100644
--- a/go/client/main.go
+++ b/go/client/main.go
@@ -85,6 +85,7 @@ type Game struct {
storeView *ui.PocList
storeButton *ui.SimpleButton
stackBuffer *ui.Buffer
+ prompt *ui.Prompt
widgets []ui.Widget
activePlayer *game.Player
@@ -107,7 +108,14 @@ func NewGame() *Game {
DEFAULT_BUTTON_HEIGHT,
"Pass",
func(*ui.SimpleButton) {
- if g.hasPriority {
+ if g.prompt != nil {
+
+ a := g.prompt.Confirm()
+ log.Println("Prompt confirmation returned", a)
+ g.declareAction(a)
+ g.prompt = nil
+ g.removeWidget(g.prompt)
+ } else if g.hasPriority {
g.passPriority()
}
})
@@ -168,9 +176,9 @@ func (g *Game) initPlayerUi(player *game.Player) {
var x, y int
g.handLayer = ui.NewHandView(0,
- g.mapView.GetHeight(),
+ g.mapView.Height(),
HAND_VIEW_WIDTH,
- screenHeight-g.mapView.GetHeight()-DEFAULT_BUTTON_HEIGHT,
+ screenHeight-g.mapView.Height()-DEFAULT_BUTTON_HEIGHT,
player.Hand,
true)
g.addWidget(g.handLayer)
@@ -261,7 +269,7 @@ func (g *Game) removeWidgetAt(idx int) {
}
func (g *Game) addActionChoice(perm game.Permanent, x, y int) {
- actions := perm.GetAvailActionPrototypes()
+ actions := perm.AvailActionPrototypes()
if len(actions) > 0 {
g.selectedObject = perm
onClick := func(c *ui.Choice, x, y int) {
@@ -278,6 +286,15 @@ func (g *Game) removeActionChoice() {
g.actionChoice = nil
}
+func (g *Game) AddHighlight(obj interface{}) {
+ switch obj := obj.(type) {
+ case ui.HandCard:
+ g.handLayer.AddHighlightCard(obj.C)
+ case *game.Tile:
+ g.mapView.AddHighlightTile(obj)
+ }
+}
+
func (g *Game) clearMapHighlights() {
g.mapView.ClearPermanentsHighlights()
g.mapView.ClearTileHighlights()
@@ -289,12 +306,20 @@ func (g *Game) declareAction(a game.Action) {
g.clearMapHighlights()
g.handLayer.ClearHighlights()
g.hasPriority = false
- g.removeWidget(g.passButton)
+ g.hidePassButton()
g.stateBar.ForceRedraw()
}
+func (g *Game) showPassButton() {
+ g.addWidget(g.passButton)
+}
+
+func (g *Game) hidePassButton() {
+ g.removeWidget(g.passButton)
+}
+
func (g *Game) passPriority() {
- g.declareAction(game.NewPassPriorityAction(g.activePlayer))
+ g.declareAction(game.NewPassPriority(g.activePlayer))
}
func (g *Game) handlePlayerNotifications() {
@@ -302,7 +327,7 @@ func (g *Game) handlePlayerNotifications() {
for n != nil {
switch n.Notification {
case game.PriorityNotification:
- g.addWidget(g.passButton)
+ g.showPassButton()
g.hasPriority = true
case game.DeclaredActionNotification:
@@ -321,6 +346,14 @@ func (g *Game) handlePlayerNotifications() {
if !g.storesOnMap {
g.showStore()
}
+
+ case game.HandCardSelectionPrompt:
+ ctx := n.Context.([]int)
+ min, max := ctx[0], ctx[1]
+ promptTxt := fmt.Sprintf("Select between %d and %d hand cards", min, max)
+ g.prompt = ui.NewHandCardPrompt(screenHeight/2, screenWidth, promptTxt)
+ g.addWidget(g.prompt)
+ g.showPassButton()
}
g.stateBar.ForceRedraw()
@@ -362,7 +395,7 @@ func (g *Game) handleSelection(obj interface{}, x, y int) {
var action game.Action
switch obj := g.selectedObject.(type) {
case *game.MoveActionPrototype:
- action = obj.Specialize(tile)
+ action = obj.Specialize(g.gameState, tile)
case *game.Card:
if obj.IsPermanent() {
action = game.NewPlayAction(g.activePlayer, obj, tile.Position)
@@ -384,7 +417,7 @@ func (g *Game) handleSelection(obj interface{}, x, y int) {
} else {
switch obj := g.selectedObject.(type) {
case *game.AttackActionPrototype:
- action := obj.Specialize(perm)
+ action := obj.Specialize(g.gameState, perm)
g.selectedObject = nil
g.declareAction(action)
g.mapView.HighlightPermanent(perm)
@@ -437,7 +470,7 @@ func (g *Game) handleHover(obj interface{}, x, y int) {
hoverHint = ui.NewPermInfo(x+ui.TILE_WIDTH, y, obj)
case *game.Tile:
if g.storesOnMap && obj.Type == game.TileTypes.Store {
- poc := g.gameState.Map.GetStoreOn(obj.Position)
+ poc := g.gameState.Map.StoreOn(obj.Position)
hoverHint = ui.NewPocList(x, y, poc)
// Set a special hoverDetector resetFunc keeping the hovering store
// around and allow card selection until the cursor leaves the store widget.
@@ -473,7 +506,12 @@ func (g *Game) Update() error {
obj := g.findObjectAt(x, y)
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
- g.handleSelection(obj, x, y)
+ if g.prompt != nil {
+ g.prompt.Add(obj)
+ g.AddHighlight(obj)
+ } else {
+ g.handleSelection(obj, x, y)
+ }
g.hightlightSelection(obj)
} else if g.hoverDetector.startedHovering() && g.selectedObject == nil && obj != nil {
g.handleHover(obj, x, y)