aboutsummaryrefslogtreecommitdiff
path: root/go/ui
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-04 18:51:31 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:47 +0100
commite9070ef3752c5d2ab1f9faac48095995772ce726 (patch)
treed1842db95e73039224476d0a5794d951e3fdfb3b /go/ui
parentea54efacae089aa3644cfe00c8e180d5cc2c8d9e (diff)
downloadmuhqs-game-e9070ef3752c5d2ab1f9faac48095995772ce726.tar.gz
muhqs-game-e9070ef3752c5d2ab1f9faac48095995772ce726.zip
improve permanent pile support
* Fix alot of bugs caused by permanents without tiles * Implement a permanent choice to select the permanents in a pile * Fix how pile hooks are called
Diffstat (limited to 'go/ui')
-rw-r--r--go/ui/choice.go20
-rw-r--r--go/ui/mapView.go12
-rw-r--r--go/ui/textBox.go7
3 files changed, 32 insertions, 7 deletions
diff --git a/go/ui/choice.go b/go/ui/choice.go
index 003c2a6a..bacc6657 100644
--- a/go/ui/choice.go
+++ b/go/ui/choice.go
@@ -1,8 +1,11 @@
package ui
import (
+ "fmt"
+
"github.com/hajimehoshi/ebiten/v2"
"muhq.space/muhqs-game/go/game"
+ "muhq.space/muhqs-game/go/utils"
)
type Choice struct {
@@ -59,14 +62,21 @@ func (c *Choice) Render() *ebiten.Image {
return nil
}
-func NewActionChoice(x, y int, actions []game.Action, onClick func(*Choice, int, int)) *Choice {
+func NewObjectChoice(x, y int, objs []interface{}, onClick func(*Choice, int, int)) *Choice {
// TODO: use dynamic with width and height
width := 200
choiceHeight := 40
- labels := make([]string, 0, len(actions))
- for _, action := range actions {
- labels = append(labels, action.String())
+ labels := make([]string, 0, len(objs))
+ for _, obj := range objs {
+ labels = append(labels, fmt.Sprintf("%v", obj))
}
-
return NewChoice(x, y, width, choiceHeight, labels, onClick)
}
+
+func NewActionChoice(x, y int, actions []game.Action, onClick func(*Choice, int, int)) *Choice {
+ return NewObjectChoice(x, y, utils.TypedSliceToInterfaceSlice(actions), onClick)
+}
+
+func NewPermChoice(x, y int, perms []game.Permanent, onClick func(*Choice, int, int)) *Choice {
+ return NewObjectChoice(x, y, utils.TypedSliceToInterfaceSlice(perms), onClick)
+}
diff --git a/go/ui/mapView.go b/go/ui/mapView.go
index 8c83bd41..a6fd55c1 100644
--- a/go/ui/mapView.go
+++ b/go/ui/mapView.go
@@ -150,8 +150,12 @@ func (vw *MapView) drawPermanentsLayer(screen *ebiten.Image) {
vw.permanentsLayer = vw.newLayerImage()
for i, p := range vw.gameState.Permanents {
- permanentSymbol := getPermanentSymbol(p, i)
t := p.Tile()
+ // Skip permanents with no containing tiles (e.g. piled ones)
+ if t == nil {
+ continue
+ }
+ permanentSymbol := getPermanentSymbol(p, i)
x_px := t.Position.X*TILE_WIDTH + (TILE_WIDTH-PERMANENT_WIDTH)/2
y_px := t.Position.Y*TILE_HEIGHT + (TILE_HEIGHT-PERMANENT_HEIGHT)/2
@@ -206,7 +210,11 @@ func (vw *MapView) FindObjectAt(screenX, screenY int) interface{} {
relativeY >= yMargin && relativeY <= TILE_HEIGHT-yMargin {
for _, p := range vw.gameState.Permanents {
- pos := p.Tile().Position
+ t := p.Tile()
+ if t == nil {
+ continue
+ }
+ pos := t.Position
if pos.X == x && pos.Y == y {
if isSymbolTransparentAt(p, relativeX, relativeY) {
break
diff --git a/go/ui/textBox.go b/go/ui/textBox.go
index d0afbd9b..58a3e679 100644
--- a/go/ui/textBox.go
+++ b/go/ui/textBox.go
@@ -66,6 +66,13 @@ func NewUnitInfo(x, y int, u *game.Unit) *TextBox {
info = fmt.Sprintf("%s\nAttack: %s", info, u.Attack.String())
}
+ if len(u.Pile()) > 0 {
+ info = fmt.Sprintf("%s\nPile:", info)
+ for _, p := range u.Pile() {
+ info = fmt.Sprintf("%s\n %s", info, p.Card().Name)
+ }
+ }
+
return NewAutoTextBox(x, y, info)
}