aboutsummaryrefslogtreecommitdiff
path: root/go/client
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-08 17:50:10 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:50:10 +0200
commit45df9bf319d38db916ca983b8c92bb912f5ce9ee (patch)
treed7966002dad4a20bc3ef385bd152554fe278a6df /go/client
parenteb10f6f4940ecd09fd7d881fe5e1735ff146f919 (diff)
downloadmuhqs-game-45df9bf319d38db916ca983b8c92bb912f5ce9ee.tar.gz
muhqs-game-45df9bf319d38db916ca983b8c92bb912f5ce9ee.zip
intermediate commit
Diffstat (limited to 'go/client')
-rw-r--r--go/client/game.go121
1 files changed, 75 insertions, 46 deletions
diff --git a/go/client/game.go b/go/client/game.go
index 76b04fa7..b459d42a 100644
--- a/go/client/game.go
+++ b/go/client/game.go
@@ -19,12 +19,15 @@ const (
RESOLVE_BUTTON_X = 500
STACK_BUFFER_WIDTH = 300
- HOVER_THRESHOLD = 60
+ HOVER_THRESHOLD = 60
+ HOVER_CARD_WIDTH = 500
+ HOVER_CARD_HEIGHT = 700
- HAND_VIEW_HEIGHT = 500
- HAND_VIEW_WIDTH = 500
+ HAND_VIEW_WIDTH = 500
STATE_BAR_WIDTH = 300
+
+ POC_BUTTON_WIDTH = 150
)
// A simple structure to detect if the cursor has not moved for HOVER_THRESHOLD
@@ -153,7 +156,7 @@ func (g *Game) getPlayer(name string) *game.Player {
func (g *Game) initPlayerUi(player *game.Player) *Game {
g.activePlayer = player
- g.playerCtrl = game.NewChanPlayerControl()
+ g.playerCtrl = game.NewChanPlayerControl(player)
player.Ctrl = g.playerCtrl
var x, y int
@@ -175,7 +178,7 @@ func (g *Game) initPlayerUi(player *game.Player) *Game {
g.discardPileButton = ui.NewSimpleButton(g.stateBar.Width,
g.height-DEFAULT_BUTTON_HEIGHT,
- 150,
+ POC_BUTTON_WIDTH,
DEFAULT_BUTTON_HEIGHT,
"DiscardPile",
func(*ui.SimpleButton) {
@@ -196,7 +199,7 @@ func (g *Game) initPlayerUi(player *game.Player) *Game {
x = g.stateBar.Width + g.discardPileButton.Width
y = g.height - DEFAULT_BUTTON_HEIGHT
g.storeButton = ui.NewSimpleButton(x, y,
- 150,
+ POC_BUTTON_WIDTH,
DEFAULT_BUTTON_HEIGHT,
"Store",
func(*ui.SimpleButton) {
@@ -287,7 +290,11 @@ func (g *Game) addActionChoice(perm game.Permanent, x, y int) {
onClick := func(c *ui.Choice, x, y int) {
g.removeChoice()
a := actions[c.GetChoosen(x, y)]
- g.selectedObject = a
+ if a.Targets() != nil && a.Targets().RequireSelection() {
+ g.selectedObject = a
+ } else {
+ g.declareAction(a)
+ }
}
g.choice = ui.NewActionChoice(x, y, actions, onClick)
g.addWidget(g.choice)
@@ -303,8 +310,14 @@ func (g *Game) AddHighlight(obj interface{}) {
switch obj := obj.(type) {
case ui.HandCard:
g.handLayer.AddHighlightCard(obj.C)
+ case *game.Card:
+ g.handLayer.AddHighlightCard(obj)
case *game.Tile:
g.mapView.AddHighlightTile(obj)
+ case *game.Unit:
+ g.mapView.AddHighlightPermanent(obj)
+ default:
+ log.Fatalf("Unhandled highlight of type %T", obj)
}
}
@@ -338,6 +351,7 @@ func (g *Game) passPriority() {
func (g *Game) handlePlayerNotifications() {
n := g.playerCtrl.RecvNotification()
for n != nil {
+ log.Println("Received", n)
switch n.Notification {
case game.PriorityNotification:
g.showPassButton()
@@ -355,16 +369,15 @@ func (g *Game) handlePlayerNotifications() {
g.stackBuffer.RemoveLast()
g.mapView.ForceRedraw()
- case game.BuyPrompt:
- if !g.storesOnMap {
- g.showStore()
+ case game.TargetSelectionPrompt:
+ ctx := n.Context.(game.TargetSelectionCtx)
+ if _, ok := ctx.Action.(*game.BuyAction); ok {
+ 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(g.height/2, g.width, promptTxt)
+ g.prompt = ui.NewPrompt(g.height/2, g.width, ctx.Action, ctx.Prompt)
g.addWidget(g.prompt)
g.showPassButton()
}
@@ -394,9 +407,12 @@ func (g *Game) findObjectAt(x, y int) interface{} {
func (g *Game) handleTargetSelection(obj interface{}) {
a := g.selectedObject.(game.Action)
- a.Targets().AddTarget(obj)
+ err := a.Targets().AddSelection(obj)
+ if err != nil {
+ log.Println("Not added", obj, "as target for", a, "because", err)
+ }
- if !a.Targets().RequireTargets() {
+ if !a.Targets().RequireSelection() {
g.declareAction(a)
g.selectedObject = nil
}
@@ -416,7 +432,14 @@ func (g *Game) handleSelection(obj interface{}, x, y int) {
obj.Click(x, y)
case *game.Tile:
- g.mapView.HighlightTile(obj)
+ if g.storesOnMap && obj.Type == game.TileTypes.Store && g.activePlayer.KnowsStore(obj.Position) {
+ if g.storeView != nil {
+ g.hideStore()
+ }
+
+ g.storeView = ui.NewPocList(x, y, g.gameState.Map.StoreOn(obj.Position))
+ g.showStore()
+ }
case game.Permanent:
perm := obj
@@ -426,12 +449,6 @@ func (g *Game) handleSelection(obj interface{}, x, y int) {
g.selectedObject = game.NewPlayAction(g.activePlayer, obj.C)
g.handLayer.HighlightCard(obj.C)
- case *game.Card:
- if g.gameState.IsActivePlayer(g.activePlayer) &&
- g.gameState.ActivePhase == game.Phases.BuyPhase {
- g.declareAction(game.NewBuyAction(g.activePlayer, obj))
- }
-
default:
log.Fatalf("Object of type %T not handled", obj)
}
@@ -444,7 +461,7 @@ func (g *Game) highlightTargets() {
return
}
- options := a.Targets().NextOptions()
+ options := a.Targets().Options()
for _, option := range options {
g.AddHighlight(option)
}
@@ -455,30 +472,36 @@ func (g *Game) handleHover(obj interface{}, x, y int) {
switch obj := obj.(type) {
case *game.Card:
wx, wy := x, y
- if x+500 > g.width || y+700 > g.height {
- wx = x - 500
- wy = y - 700
+ if x+HOVER_CARD_WIDTH > g.width || y+HOVER_CARD_HEIGHT > g.height {
+ wx = x - HOVER_CARD_WIDTH
+ wy = y - HOVER_CARD_HEIGHT
+ }
+ if wx < 0 {
+ wx = 0
}
- hoverHint = ui.NewScaledCardView(wx, wy, 500, 700, obj.Path())
+ if wy < 0 {
+ wy = 0
+ }
+ hoverHint = ui.NewScaledCardView(wx, wy, HOVER_CARD_WIDTH, HOVER_CARD_HEIGHT, obj.Path())
case *game.Unit:
hoverHint = ui.NewUnitInfo(x+ui.TILE_WIDTH, y, obj)
case game.Permanent:
hoverHint = ui.NewPermInfo(x+ui.TILE_WIDTH, y, obj)
- case *game.Tile:
- if g.storesOnMap && obj.Type == game.TileTypes.Store {
- 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.
- g.hoverDetector.resetFunc = func() bool {
- x, y := ebiten.CursorPosition()
- if hoverHint.Contains(x, y) {
- return false
- }
- g.removeWidget(hoverHint)
- return true
- }
- }
+ // case *game.Tile:
+ // if g.storesOnMap && obj.Type == game.TileTypes.Store {
+ // 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.
+ // g.hoverDetector.resetFunc = func() bool {
+ // x, y := ebiten.CursorPosition()
+ // if hoverHint.Contains(x, y) {
+ // return false
+ // }
+ // g.removeWidget(hoverHint)
+ // return true
+ // }
+ // }
}
if hoverHint != nil {
@@ -514,8 +537,12 @@ func (g *Game) Update() error {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
if g.prompt != nil {
- g.prompt.Add(obj)
- g.AddHighlight(obj)
+ if err := g.prompt.Add(obj); err == nil {
+ g.AddHighlight(obj)
+ } else {
+ log.Println("Not added", obj, "to active prompt:", err)
+ g.handleSelection(obj, x, y)
+ }
} else {
g.handleSelection(obj, x, y)
}
@@ -529,6 +556,8 @@ func (g *Game) Update() error {
g.hoverDetector.reset()
g.clearMapHighlights()
g.handLayer.ClearHighlights()
+ g.hideStore()
+ g.removeWidget(g.discardPileView)
}
return nil
}