aboutsummaryrefslogtreecommitdiff
path: root/go/ui
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-01-31 00:16:53 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:45 +0100
commite6a1bb4ba06361abdc2cf1bed4041fe3013b188b (patch)
treec329a9d8d071bd2a5e3d6b5bb531da67ece2b227 /go/ui
parent24cea3f7c1e3679ba19ed1d49674e1228eb50ce1 (diff)
downloadmuhqs-game-e6a1bb4ba06361abdc2cf1bed4041fe3013b188b.tar.gz
muhqs-game-e6a1bb4ba06361abdc2cf1bed4041fe3013b188b.zip
intermediate commit
Diffstat (limited to 'go/ui')
-rw-r--r--go/ui/hand.go8
-rw-r--r--go/ui/mapView.go24
-rw-r--r--go/ui/prompt.go78
-rw-r--r--go/ui/textBox.go9
4 files changed, 104 insertions, 15 deletions
diff --git a/go/ui/hand.go b/go/ui/hand.go
index 5421f6fb..f7157232 100644
--- a/go/ui/hand.go
+++ b/go/ui/hand.go
@@ -40,7 +40,7 @@ func NewHandView(x, y, width, height int, h *game.Hand, bottomAligned bool) *Han
func (hv *HandView) render() *ebiten.Image {
img := ebiten.NewImage(hv.Width, hv.Height)
- handCards := hv.hand.GetCards()
+ handCards := hv.hand.Cards()
nHandCards := len(handCards)
for i, card := range handCards {
cardImg := assets.GetCard(card.Path(), "en")
@@ -92,7 +92,7 @@ func (hv *HandView) FindObjectAt(x, y int) interface{} {
return nil
}
- return HandCard{hv.hand.GetCards()[i]}
+ return HandCard{hv.hand.Cards()[i]}
}
func (hv *HandView) setHighlights(cards []*game.Card) {
@@ -104,6 +104,10 @@ func (hv *HandView) HighlightCard(card *game.Card) {
hv.setHighlights([]*game.Card{card})
}
+func (hv *HandView) AddHighlightCard(card *game.Card) {
+ hv.setHighlights(append(hv.highlights, card))
+}
+
func (hv *HandView) ClearHighlights() {
hv.setHighlights([]*game.Card{})
}
diff --git a/go/ui/mapView.go b/go/ui/mapView.go
index c966f1a8..8c83bd41 100644
--- a/go/ui/mapView.go
+++ b/go/ui/mapView.go
@@ -35,7 +35,7 @@ func NewMapView(g *game.State) *MapView {
return &vw
}
-func (mv *MapView) GetHeight() int {
+func (mv *MapView) Height() int {
return len(mv.gameState.Map.Tiles) * TILE_HEIGHT
}
@@ -133,9 +133,9 @@ func (vw *MapView) drawMapLayer(screen *ebiten.Image) {
}
func getPermanentSymbol(p game.Permanent, i int) *ebiten.Image {
- permanentSymbol := assets.GetSymbol(strings.ToLower(p.GetCard().Name))
+ permanentSymbol := assets.GetSymbol(strings.ToLower(p.Card().Name))
if permanentSymbol == nil {
- symbol := fmt.Sprintf("%c%d", unicode.ToUpper(rune(p.GetCard().Type.String()[0])), i)
+ symbol := fmt.Sprintf("%c%d", unicode.ToUpper(rune(p.Card().Type.String()[0])), i)
permanentSymbol = assets.GetGenericSymbol(symbol)
if permanentSymbol == nil {
log.Fatalf("Failed to generate generic symbol %s", symbol)
@@ -151,13 +151,13 @@ func (vw *MapView) drawPermanentsLayer(screen *ebiten.Image) {
for i, p := range vw.gameState.Permanents {
permanentSymbol := getPermanentSymbol(p, i)
- t := p.GetTile()
+ t := p.Tile()
x_px := t.Position.X*TILE_WIDTH + (TILE_WIDTH-PERMANENT_WIDTH)/2
y_px := t.Position.Y*TILE_HEIGHT + (TILE_HEIGHT-PERMANENT_HEIGHT)/2
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(x_px), float64(y_px))
- op.ColorM.ScaleWithColor(p.GetController().Color)
+ op.ColorM.ScaleWithColor(p.Controller().Color)
for _, h := range vw.permanentsHighlights {
if p == h {
@@ -206,7 +206,7 @@ func (vw *MapView) FindObjectAt(screenX, screenY int) interface{} {
relativeY >= yMargin && relativeY <= TILE_HEIGHT-yMargin {
for _, p := range vw.gameState.Permanents {
- pos := p.GetTile().Position
+ pos := p.Tile().Position
if pos.X == x && pos.Y == y {
if isSymbolTransparentAt(p, relativeX, relativeY) {
break
@@ -225,8 +225,12 @@ func (vw *MapView) FindObjectAt(screenX, screenY int) interface{} {
}
func (vw *MapView) HighlightPositions(pos []game.Position) {
- vw.ForceRedraw()
vw.tileHighlights = pos
+ vw.ForceRedraw()
+}
+
+func (vw *MapView) AddHighlightPosition(pos game.Position) {
+ vw.HighlightPositions(append(vw.tileHighlights, pos))
}
func (vw *MapView) HighlightTiles(tiles []*game.Tile) {
@@ -241,13 +245,17 @@ func (vw *MapView) HighlightTile(t *game.Tile) {
vw.HighlightTiles([]*game.Tile{t})
}
+func (vw *MapView) AddHighlightTile(t *game.Tile) {
+ vw.AddHighlightPosition(t.Position)
+}
+
func (vw *MapView) ClearTileHighlights() {
vw.HighlightTiles([]*game.Tile{})
}
func (vw *MapView) HighlightPermanents(permanents []game.Permanent) {
- vw.ForceRedraw()
vw.permanentsHighlights = permanents
+ vw.ForceRedraw()
}
func (vw *MapView) HighlightPermanent(p game.Permanent) {
diff --git a/go/ui/prompt.go b/go/ui/prompt.go
new file mode 100644
index 00000000..bfcd5d14
--- /dev/null
+++ b/go/ui/prompt.go
@@ -0,0 +1,78 @@
+package ui
+
+import (
+ "log"
+
+ "github.com/hajimehoshi/ebiten/v2"
+
+ "muhq.space/muhqs-game/go/game"
+)
+
+type promptType int
+
+const (
+ handCard promptType = iota
+
+ PROMPT_HEIGHT int = 50
+)
+
+type Prompt struct {
+ promptType promptType
+ y, width int
+ sel []interface{}
+ components []Widget
+}
+
+func NewHandCardPrompt(y, width int, promptText string) *Prompt {
+ p := &Prompt{
+ y: y,
+ width: width,
+ promptType: handCard,
+ components: []Widget{NewCenteringFixedTextBox(0, y, width, PROMPT_HEIGHT, promptText)},
+ }
+ return p
+}
+
+func (p *Prompt) Add(obj interface{}) {
+ var ok bool
+ switch p.promptType {
+ case handCard:
+ _, ok = obj.(HandCard)
+ }
+
+ if !ok {
+ log.Fatalf("Invalid type %T for prompt %d", obj, p.promptType)
+ }
+
+ p.sel = append(p.sel, obj)
+}
+
+func (p *Prompt) Confirm() game.Action {
+ switch p.promptType {
+ case handCard:
+ cards := make([]*game.Card, 0, len(p.sel))
+ for _, c := range p.sel {
+ cards = append(cards, c.(HandCard).C)
+ }
+ return game.NewHandCardSelection(cards)
+ }
+
+ return nil
+}
+
+func (p *Prompt) Height() int {
+ return PROMPT_HEIGHT
+}
+
+func (p *Prompt) Draw(screen *ebiten.Image) {
+ for _, comp := range p.components {
+ comp.Draw(screen)
+ }
+}
+
+func (p *Prompt) Contains(x, y int) bool {
+ return x >= 0 && y >= 0 && x <= p.width && y >= p.y && y <= p.y+PROMPT_HEIGHT
+}
+
+func (p *Prompt) FindObjectAt(screenX, screenY int) interface{} { return nil }
+func (*Prompt) Render(Widget) *ebiten.Image { return nil }
diff --git a/go/ui/textBox.go b/go/ui/textBox.go
index dd10e8e2..78199410 100644
--- a/go/ui/textBox.go
+++ b/go/ui/textBox.go
@@ -55,7 +55,7 @@ func NewCenteringAutoTextBox(x, y int, t string) *TextBox {
func NewUnitInfo(x, y int, u *game.Unit) *TextBox {
info := fmt.Sprintf("%s\nDamage: %d\nHealth: %d\nUpkeep: %d",
- u.String(), u.GetDamage(), u.Health, u.Upkeep)
+ u.String(), u.Damage(), u.Health, u.Upkeep)
if u.Movement != game.INVALID_MOVEMENT() {
info = fmt.Sprintf("%s\nMovement: %s", info, u.Movement.String())
@@ -69,8 +69,7 @@ func NewUnitInfo(x, y int, u *game.Unit) *TextBox {
}
func NewPermInfo(x, y int, p game.Permanent) *TextBox {
- info := fmt.Sprintf("%s\nDamage: %d",
- p.String(), p.GetDamage())
+ info := fmt.Sprintf("%s\nDamage: %d", p.String(), p.Damage())
return NewAutoTextBox(x, y, info)
}
@@ -135,7 +134,7 @@ func NewPocList(centerX, bottomY int, poc game.PileOfCards) *PocList {
func (w *PocList) setText() {
t := ""
- for _, c := range w.poc.GetCards() {
+ for _, c := range w.poc.Cards() {
t = fmt.Sprintf("%s%s\n", t, c.Name)
}
@@ -151,7 +150,7 @@ func (w *PocList) setText() {
}
func (w *PocList) FindObjectAt(x, y int) interface{} {
- cards := w.poc.GetCards()
+ cards := w.poc.Cards()
if len(cards) == 0 {
return nil
}