diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-09-03 13:10:15 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-09-03 13:10:15 +0200 |
| commit | ada59f2f5b2c2be0999131fe98af985effb5829d (patch) | |
| tree | b5f4b1114794c551333489252c7e7fbb2b424f27 | |
| parent | 67faa0f3bf6fb047d19372c9b671a45887b99f6e (diff) | |
| download | muhqs-game-ada59f2f5b2c2be0999131fe98af985effb5829d.tar.gz muhqs-game-ada59f2f5b2c2be0999131fe98af985effb5829d.zip | |
show all store available store cards when prompting to buy a card
| -rw-r--r-- | go/client/game.go | 87 | ||||
| -rw-r--r-- | go/ui/mapView.go | 8 | ||||
| -rw-r--r-- | go/ui/textBox.go | 10 |
3 files changed, 68 insertions, 37 deletions
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: diff --git a/go/ui/mapView.go b/go/ui/mapView.go index 83404241..528ce6db 100644 --- a/go/ui/mapView.go +++ b/go/ui/mapView.go @@ -428,6 +428,14 @@ func (vw *MapView) FindObjectAt(screenX, screenY int) any { return nil } +func (vw *MapView) GetScreenPosition(t *game.Tile) (int, int) { + scaled_tile_wdth := int(float64(TILE_WIDTH) * vw.scale) + scaled_tile_hght := int(float64(TILE_HEIGHT) * vw.scale) + x := scaled_tile_wdth * t.Position.X + y := scaled_tile_hght * t.Position.Y + return x, y +} + func (vw *MapView) HighlightPositions(pos []game.Position, col color.Color) { highlights := make(map[game.Position][]color.Color) for _, p := range pos { diff --git a/go/ui/textBox.go b/go/ui/textBox.go index e2238078..1b0cae5e 100644 --- a/go/ui/textBox.go +++ b/go/ui/textBox.go @@ -141,7 +141,7 @@ type PocList struct { hoverCardView centerX int bottomY int - poc game.PileOfCards + Poc game.PileOfCards } func NewPocList(centerX, bottomY int, poc game.PileOfCards, c *Collection) *PocList { @@ -149,7 +149,7 @@ func NewPocList(centerX, bottomY int, poc game.PileOfCards, c *Collection) *PocL TextBox: *(NewAutoTextBox(-1, -1, "").Centering(true)), centerX: centerX, bottomY: bottomY, - poc: poc, + Poc: poc, } w.hoverCardView.init(w, c) @@ -165,7 +165,7 @@ func NewPocList(centerX, bottomY int, poc game.PileOfCards, c *Collection) *PocL func (w *PocList) setText() { w.Width, w.Height = -1, -1 t := "" - for _, c := range w.poc.Cards() { + for _, c := range w.Poc.Cards() { t = fmt.Sprintf("%s%s\n", t, c.Name) } @@ -185,7 +185,7 @@ func (w *PocList) FindObjectAt(_x, _y int) any { return nil } - cards := w.poc.Cards() + cards := w.Poc.Cards() if len(cards) == 0 { return nil } @@ -193,7 +193,7 @@ func (w *PocList) FindObjectAt(_x, _y int) any { y := _y - w.Y _, height := text.Measure(w.text, w.font, w.font.Size*w.lineSpacing) - i := y / (int(height) / w.poc.Size()) + i := y / (int(height) / w.Poc.Size()) if i >= len(cards) { return nil |
