aboutsummaryrefslogtreecommitdiff
path: root/go/ui/mapView.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/ui/mapView.go')
-rw-r--r--go/ui/mapView.go70
1 files changed, 40 insertions, 30 deletions
diff --git a/go/ui/mapView.go b/go/ui/mapView.go
index 0553b348..721356ff 100644
--- a/go/ui/mapView.go
+++ b/go/ui/mapView.go
@@ -2,13 +2,12 @@ package ui
import (
"fmt"
+ "image/color"
"log"
"math"
"strings"
"unicode"
- "golang.org/x/exp/slices"
-
"github.com/hajimehoshi/ebiten/v2"
"muhq.space/muhqs-game/go/assets"
"muhq.space/muhqs-game/go/game"
@@ -27,12 +26,16 @@ type MapView struct {
gameState *game.State
mapLayer *ebiten.Image
permanentsLayer *ebiten.Image
- tileHighlights []game.Position
- permanentsHighlights []game.Permanent
+ tileHighlights map[game.Position]color.Color
+ permanentsHighlights map[game.Permanent]color.Color
}
func NewMapView(g *game.State) *MapView {
- vw := &MapView{gameState: g}
+ vw := &MapView{
+ gameState: g,
+ tileHighlights: make(map[game.Position]color.Color),
+ permanentsHighlights: make(map[game.Permanent]color.Color),
+ }
vw.hoverPermInfo.init(vw)
return vw
}
@@ -128,8 +131,8 @@ func (vw *MapView) drawMapLayer(screen *ebiten.Image) {
op.GeoM.Translate(x_px, y_px)
- if slices.Contains(vw.tileHighlights, pos) {
- op.ColorM.Scale(1, 0, 0, 0.5)
+ if color, found := vw.tileHighlights[pos]; found {
+ op.ColorM.ScaleWithColor(color)
}
vw.mapLayer.DrawImage(tileImg, op)
@@ -175,11 +178,8 @@ func (vw *MapView) drawPermanentsLayer(screen *ebiten.Image) {
op.GeoM.Translate(float64(x_px), float64(y_px))
op.ColorM.ScaleWithColor(p.Controller().Color)
- for _, h := range vw.permanentsHighlights {
- if p == h {
- op.ColorM.Scale(255, 0.5, 0.5, 1)
- break
- }
+ if color, found := vw.permanentsHighlights[p]; found {
+ op.ColorM.ScaleWithColor(color)
}
vw.permanentsLayer.DrawImage(permanentSymbol, op)
@@ -244,50 +244,60 @@ func (vw *MapView) FindObjectAt(screenX, screenY int) interface{} {
return nil
}
-func (vw *MapView) HighlightPositions(pos []game.Position) {
- vw.tileHighlights = pos
+func (vw *MapView) HighlightPositions(pos []game.Position, col color.Color) {
+ highlights := make(map[game.Position]color.Color)
+ for _, p := range pos {
+ highlights[p] = col
+ }
+ vw.tileHighlights = highlights
vw.ForceRedraw()
}
-func (vw *MapView) AddHighlightPosition(pos game.Position) {
- vw.HighlightPositions(append(vw.tileHighlights, pos))
+func (vw *MapView) AddHighlightPosition(pos game.Position, color color.Color) {
+ vw.tileHighlights[pos] = color
+ vw.ForceRedraw()
}
-func (vw *MapView) HighlightTiles(tiles []*game.Tile) {
+func (vw *MapView) HighlightTiles(tiles []*game.Tile, color color.Color) {
pos := make([]game.Position, 0, len(tiles))
for _, t := range tiles {
pos = append(pos, t.Position)
}
- vw.HighlightPositions(pos)
+ vw.HighlightPositions(pos, color)
}
-func (vw *MapView) HighlightTile(t *game.Tile) {
- vw.HighlightTiles([]*game.Tile{t})
+func (vw *MapView) HighlightTile(t *game.Tile, color color.Color) {
+ vw.HighlightTiles([]*game.Tile{t}, color)
}
-func (vw *MapView) AddHighlightTile(t *game.Tile) {
- vw.AddHighlightPosition(t.Position)
+func (vw *MapView) AddHighlightTile(t *game.Tile, color color.Color) {
+ vw.AddHighlightPosition(t.Position, color)
}
func (vw *MapView) ClearTileHighlights() {
- vw.HighlightTiles([]*game.Tile{})
+ vw.HighlightTiles([]*game.Tile{}, nil)
}
-func (vw *MapView) HighlightPermanents(permanents []game.Permanent) {
- vw.permanentsHighlights = permanents
+func (vw *MapView) HighlightPermanents(permanents []game.Permanent, col color.Color) {
+ highlights := make(map[game.Permanent]color.Color)
+ for _, p := range permanents {
+ highlights[p] = col
+ }
+ vw.permanentsHighlights = highlights
vw.ForceRedraw()
}
-func (vw *MapView) AddHighlightPermanent(p game.Permanent) {
- vw.HighlightPermanents(append(vw.permanentsHighlights, p))
+func (vw *MapView) AddHighlightPermanent(p game.Permanent, color color.Color) {
+ vw.ForceRedraw()
+ vw.permanentsHighlights[p] = color
}
-func (vw *MapView) HighlightPermanent(p game.Permanent) {
- vw.HighlightPermanents([]game.Permanent{p})
+func (vw *MapView) HighlightPermanent(p game.Permanent, color color.Color) {
+ vw.HighlightPermanents([]game.Permanent{p}, color)
}
func (vw *MapView) ClearPermanentsHighlights() {
- vw.HighlightPermanents([]game.Permanent{})
+ vw.HighlightPermanents([]game.Permanent{}, nil)
}
func (mv *MapView) Contains(x, y int) bool {