From ada59f2f5b2c2be0999131fe98af985effb5829d Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 3 Sep 2025 13:10:15 +0200 Subject: show all store available store cards when prompting to buy a card --- go/client/game.go | 87 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 32 deletions(-) (limited to 'go/client') diff --git a/go/client/game.go b/go/client/game.go index 308095a4..4805ec80 100644 --- a/go/client/game.go +++ b/go/client/game.go @@ -57,10 +57,10 @@ type Game struct { discardPileButton *ui.SimpleButton cardsInDiscardPile int - storeVisible bool - storeView *ui.PocList - storeButton *ui.SimpleButton - cardsInStore int + storesVisible bool + storeViews []*ui.PocList + storeButton *ui.SimpleButton + cardsInStore int stackBuffer *ui.Buffer prompt *ui.Prompt @@ -159,8 +159,13 @@ func (g *Game) initMapUi() { g.mapView = ui.NewMapView(g.gameState, &g.Collection) g.AddWidget(g.mapView) - storeTiles := g.gameState.Map().FilterTiles(func(t *game.Tile) bool { return t.Type == game.TileTypes.Store }) - g.storesOnMap = len(storeTiles) > 0 + // Detect if the map has store tiles. + g.gameState.Map().FilterTiles(func(t *game.Tile) bool { + if t.Type == game.TileTypes.Store { + g.storesOnMap = true + } + return false + }) } func (g *Game) addActivePlayer(name string, deckList string) *Game { @@ -226,7 +231,8 @@ func (g *Game) initPlayerUi(player *game.Player) *Game { y = g.Height - DEFAULT_BUTTON_HEIGHT g.discardPileView = ui.NewPocList(x, y, g.activePlayer().DiscardPile, &g.Collection) - if !g.storesOnMap { + // Init the store view and the store button if we know there is only the active player's one. + if len(g.gameState.Map().Stores) == 0 { x = g.stateBar.Width + g.discardPileButton.Width y = g.Height - DEFAULT_BUTTON_HEIGHT g.storeButton = ui.NewSimpleButton(x, y, @@ -234,17 +240,17 @@ func (g *Game) initPlayerUi(player *game.Player) *Game { DEFAULT_BUTTON_HEIGHT, fmt.Sprintf("Store [%d]", g.activePlayer().Store.Size()), func(*ui.SimpleButton) { - if !g.storeVisible { - g.showStore() + if !g.storesVisible { + g.showStores() } else { - g.hideStore() + g.hideStores() } }) g.AddWidget(g.storeButton) x = g.storeButton.X + g.storeButton.Width/2 y = g.Height - DEFAULT_BUTTON_HEIGHT - g.storeView = ui.NewPocList(x, y, g.activePlayer().Store, &g.Collection) + g.storeViews = []*ui.PocList{ui.NewPocList(x, y, g.activePlayer().Store, &g.Collection)} } return g @@ -266,18 +272,35 @@ func (g *Game) showWinners() { }) } -func (g *Game) showStore() { - if g.storeVisible { +func (g *Game) showStores() { + if g.storesVisible { return } - g.storeVisible = true - g.storeView.ForceRedraw() - g.AddWidget(g.storeView) + g.storesVisible = true + + if g.storesOnMap { + // Reset the store views + g.storeViews = []*ui.PocList{} + for _, t := range g.gameState.Map().AllTiles() { + if t.Type == game.TileTypes.Store && g.activePlayer().KnowsStore(t.Position) { + x, y := g.mapView.GetScreenPosition(t) + g.storeViews = append(g.storeViews, + ui.NewPocList(x, y, g.gameState.Map().StoreOn(t.Position), &g.Collection)) + } + } + } + + for _, s := range g.storeViews { + s.ForceRedraw() + g.AddWidget(s) + } } -func (g *Game) hideStore() { - g.storeVisible = false - g.RemoveWidget(g.storeView) +func (g *Game) hideStores() { + g.storesVisible = false + for _, s := range g.storeViews { + g.RemoveWidget(s) + } } func (g *Game) showMessage(message string) { @@ -469,7 +492,7 @@ func (g *Game) clearHighlights() { func (g *Game) declareAction(a game.Action) { if _, ok := a.(*game.BuyAction); ok { - g.hideStore() + g.hideStores() } g.playerCtrl.SendAction(a) g.clearHighlights() @@ -556,7 +579,7 @@ func (g *Game) reset() { g.selectedObject = nil g.ResetHover() g.clearHighlights() - g.hideStore() + g.hideStores() g.RemoveWidget(g.discardPileView) g.RemoveWidget(g.resetButton) if g.prompt != nil { @@ -604,9 +627,7 @@ func (g *Game) handlePlayerNotifications() { case game.TargetSelectionPrompt: ctx := n.Context.(game.TargetSelectionCtx) if _, ok := ctx.Action.(*game.BuyAction); ok { - if !g.storesOnMap { - g.showStore() - } + g.showStores() } g.addPrompt(ctx.Action, ctx.Prompt) @@ -666,15 +687,17 @@ func (g *Game) handleSelection(obj any, x, y int) { 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() + // The user selected a store tile which they know. + if obj.Type == game.TileTypes.Store && + g.activePlayer().KnowsStore(obj.Position) && !g.storesVisible { + + for _, s := range g.storeViews { + poc := g.gameState.Map().StoreOn(obj.Position) + if s.Poc == poc { + g.show(s) + break + } } - - g.storeView = ui.NewPocList(x, y, g.gameState.Map().StoreOn(obj.Position), &g.Collection) - g.showStore() } case game.Permanent: -- cgit v1.2.3