aboutsummaryrefslogtreecommitdiff
path: root/go/client
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-15 13:13:06 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:49 +0100
commitf9ab2cfdb25eb3fcd85868a2e375326a9c8b6022 (patch)
treeb96f16e6cf4a6dcf93b9557a7219179ab2f46c8d /go/client
parent805cbf397589e5cb861f866713c2eb4bec9ce40b (diff)
downloadmuhqs-game-f9ab2cfdb25eb3fcd85868a2e375326a9c8b6022.tar.gz
muhqs-game-f9ab2cfdb25eb3fcd85868a2e375326a9c8b6022.zip
intermediate commit
* fix a lot of target and action bugs * check target selection before adding it to the prompt * use the store view for stores on the map * fix card highlighting in CardGrid * Only prompt for Upkeep-/DiscardActions if appropriate * Add helper for areaEffects granting new FullActions * Add Target() helper selecting the first target to the Action interface * Fix BuyAction and DiscardAction targets * Remember the stores a player has seen
Diffstat (limited to 'go/client')
-rw-r--r--go/client/game.go95
1 files changed, 65 insertions, 30 deletions
diff --git a/go/client/game.go b/go/client/game.go
index f954362a..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
@@ -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,7 +351,7 @@ func (g *Game) passPriority() {
func (g *Game) handlePlayerNotifications() {
n := g.playerCtrl.RecvNotification()
for n != nil {
- log.Println("Received notification", n)
+ log.Println("Received", n)
switch n.Notification {
case game.PriorityNotification:
g.showPassButton()
@@ -394,7 +407,10 @@ func (g *Game) findObjectAt(x, y int) interface{} {
func (g *Game) handleTargetSelection(obj interface{}) {
a := g.selectedObject.(game.Action)
- a.Targets().AddSelection(obj)
+ 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)
@@ -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
@@ -449,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
}
- hoverHint = ui.NewScaledCardView(wx, wy, 500, 700, obj.Path())
+ if wx < 0 {
+ wx = 0
+ }
+ 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 {
@@ -508,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)
}
@@ -523,6 +556,8 @@ func (g *Game) Update() error {
g.hoverDetector.reset()
g.clearMapHighlights()
g.handLayer.ClearHighlights()
+ g.hideStore()
+ g.removeWidget(g.discardPileView)
}
return nil
}