aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-09-03 14:26:21 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-09-03 14:26:21 +0200
commit24a6b1d7aced3e2da8a4c26dfa844a6eaaf4632e (patch)
tree40310c055521bad4fc2bd706e8fdb9b7dc1fb2cd
parent0587acd2dd03cb92d67ad0651eedda7275c084d7 (diff)
downloadmuhqs-game-24a6b1d7aced3e2da8a4c26dfa844a6eaaf4632e.tar.gz
muhqs-game-24a6b1d7aced3e2da8a4c26dfa844a6eaaf4632e.zip
add ui to packages and format code
-rw-r--r--go/Makefile2
-rw-r--r--go/ui/buffer.go4
-rw-r--r--go/ui/button.go1
-rw-r--r--go/ui/cardView.go3
-rw-r--r--go/ui/choice.go4
-rw-r--r--go/ui/collection.go3
-rw-r--r--go/ui/colors.go5
-rw-r--r--go/ui/constants.go1
-rw-r--r--go/ui/eventHandlers.go12
-rw-r--r--go/ui/hoverDetector.go3
-rw-r--r--go/ui/hoverable.go3
-rw-r--r--go/ui/prompt.go2
-rw-r--r--go/ui/touchManager.go44
-rw-r--r--go/ui/update.go12
14 files changed, 52 insertions, 47 deletions
diff --git a/go/Makefile b/go/Makefile
index 3eb0319a..d3657827 100644
--- a/go/Makefile
+++ b/go/Makefile
@@ -9,7 +9,7 @@ ASSETSTOCOPY = $(addprefix assets/,$(ASSETS:$(ASSETSROOT)/%=copy/%))
SHELL := bash
-PACKAGES := activities assets client dummy-ui game log server
+PACKAGES := activities assets client dummy-ui game log server ui
APPS := server client dummy-ui
OBJS := $(foreach app,$(APPS),$(app)/$(app))
diff --git a/go/ui/buffer.go b/go/ui/buffer.go
index 7a69766d..d2a4667e 100644
--- a/go/ui/buffer.go
+++ b/go/ui/buffer.go
@@ -22,8 +22,8 @@ type Buffer struct {
font *text.GoTextFace
lineSpacing float64
xMargin float64
- bg color.Color
- fg color.Color
+ bg color.Color
+ fg color.Color
}
func NewBuffer(x, y int, width, height int) *Buffer {
diff --git a/go/ui/button.go b/go/ui/button.go
index 6e8fd8b7..5bda91aa 100644
--- a/go/ui/button.go
+++ b/go/ui/button.go
@@ -51,7 +51,6 @@ func NewRoundSimpleButton(x, y, r int, label string, onClick func(b *SimpleButto
}
func (b *SimpleButton) drawLabel(img *ebiten.Image) {
-
w, h := text.Measure(b.label, b.font, b.font.Size*b.lineSpacing)
x := float64(b.Width)/2 - w/2
y := float64(b.Height)/2 - h/2
diff --git a/go/ui/cardView.go b/go/ui/cardView.go
index 0dff9481..066b73fc 100644
--- a/go/ui/cardView.go
+++ b/go/ui/cardView.go
@@ -56,7 +56,8 @@ func NewToggleCardView(x, y, wdth, hght int, cardPath string) *ToggleCardView {
cv := &ToggleCardView{
EventHandlersMap: NewEventHandlersMap(),
cv: NewScaledCardView(x, y, wdth, hght, cardPath),
- expanded: true}
+ expanded: true,
+ }
cv.tgglBtn = NewSimpleButton(x, y+10, 80, 50, ">", func(b *SimpleButton) {
shift := float64(cv.cv.Width - 80)
diff --git a/go/ui/choice.go b/go/ui/choice.go
index f937646b..5954c1fa 100644
--- a/go/ui/choice.go
+++ b/go/ui/choice.go
@@ -40,7 +40,9 @@ func (c *Choice) setText() {
func (c *Choice) GetChoosen(x, y int) int {
i := (y - c.Y) / (c.Height / len(c.choices))
- if i == len(c.choices) { i = i - 1 }
+ if i == len(c.choices) {
+ i = i - 1
+ }
return i
}
diff --git a/go/ui/collection.go b/go/ui/collection.go
index 20dff35e..3de52e11 100644
--- a/go/ui/collection.go
+++ b/go/ui/collection.go
@@ -97,7 +97,6 @@ func (c *Collection) Contains(x, y int) bool {
}
func (c *Collection) FindWidgetAt(x, y int) Widget {
-
// Iterate the widget in reverse order to ensure that upper widgets are
// considered first
for i := len(c.widgets) - 1; i >= 0; i-- {
@@ -111,7 +110,6 @@ func (c *Collection) FindWidgetAt(x, y int) Widget {
}
func (c *Collection) FindObjectAt(x, y int) any {
-
// Iterate the widget in reverse order to ensure that upper widgets are
// considered first
for i := len(c.widgets) - 1; i >= 0; i-- {
@@ -128,7 +126,6 @@ func (c *Collection) switchFocus(fcsbl Widget) {
log.Printf("switch focus from %v to %v\n", c.focused, fcsbl)
if c.focused != nil {
c.focused.Focus(false)
-
}
if fcsbl != nil {
fcsbl.Focus(true)
diff --git a/go/ui/colors.go b/go/ui/colors.go
index b296f163..e647b1fc 100644
--- a/go/ui/colors.go
+++ b/go/ui/colors.go
@@ -10,11 +10,12 @@ var (
HighlightSelectionColor = color.RGBA{0xc7, 0x89, 0x33, 0xff}
HighlightOptionColor = color.RGBA{0xc7, 0x52, 0x33, 0xff}
- HighlightMovementColor = color.RGBA{27, 59, 217, 0x80}
+ HighlightMovementColor = color.RGBA{27, 59, 217, 0x80}
HighlightAttackColor = color.RGBA{199, 53, 19, 0x80}
WarningBg = color.RGBA{0xff, 0, 0, 0x80}
)
var PlayerColors = []color.RGBA{
{1, 0xff, 1, 0xff},
- {0x7f, 0x7f, 0xff, 0xff}}
+ {0x7f, 0x7f, 0xff, 0xff},
+}
diff --git a/go/ui/constants.go b/go/ui/constants.go
index 052ae527..4bc12558 100644
--- a/go/ui/constants.go
+++ b/go/ui/constants.go
@@ -1,4 +1,5 @@
//go:build !wasm
+
package ui
const (
diff --git a/go/ui/eventHandlers.go b/go/ui/eventHandlers.go
index 701190cf..d21b6e40 100644
--- a/go/ui/eventHandlers.go
+++ b/go/ui/eventHandlers.go
@@ -1,10 +1,12 @@
package ui
-type ClickHandler = func(int, int)
-type HoverHandler = func(bool, int, int)
-type ScrollHandler = func(int, int)
-type UpdateHandler = func() error
-type FocusHandler = func(bool)
+type (
+ ClickHandler = func(int, int)
+ HoverHandler = func(bool, int, int)
+ ScrollHandler = func(int, int)
+ UpdateHandler = func() error
+ FocusHandler = func(bool)
+)
type EventHandlers interface {
IsClickable() bool
diff --git a/go/ui/hoverDetector.go b/go/ui/hoverDetector.go
index d18ea53e..8404e736 100644
--- a/go/ui/hoverDetector.go
+++ b/go/ui/hoverDetector.go
@@ -9,9 +9,8 @@ type _hoverDetector struct {
threshold int
}
-
var (
- hoverDetector = _hoverDetector{threshold: 60}
+ hoverDetector = _hoverDetector{threshold: 60}
longtapHoverDetector = _longtapHoverDetector{}
)
diff --git a/go/ui/hoverable.go b/go/ui/hoverable.go
index 3d547421..89adb912 100644
--- a/go/ui/hoverable.go
+++ b/go/ui/hoverable.go
@@ -10,7 +10,7 @@ const (
)
type hoverWidget struct {
- c *Collection
+ c *Collection
createHint func(x, y int) Widget
reset func()
xMax, yMax int
@@ -63,7 +63,6 @@ type hoverCardView struct {
func (h *hoverCardView) init(w Widget, c *Collection) {
h.c = c
h.createHint = func(x, y int) Widget {
-
obj := w.FindObjectAt(x, y)
if obj == nil {
return nil
diff --git a/go/ui/prompt.go b/go/ui/prompt.go
index 5448dfde..338121c6 100644
--- a/go/ui/prompt.go
+++ b/go/ui/prompt.go
@@ -67,7 +67,7 @@ func (p *Prompt) Contains(x, y int) bool {
}
func (p *Prompt) FindObjectAt(screenX, screenY int) any { return nil }
-func (*Prompt) Render(Widget) *ebiten.Image { return nil }
+func (*Prompt) Render(Widget) *ebiten.Image { return nil }
func (p *Prompt) setTextBgAlpha(alpha uint8) {
for _, comp := range p.components {
diff --git a/go/ui/touchManager.go b/go/ui/touchManager.go
index dfe4774a..9429b3b4 100644
--- a/go/ui/touchManager.go
+++ b/go/ui/touchManager.go
@@ -34,15 +34,15 @@ const (
)
var touchTypes = struct {
- tap TouchType
- longtap TouchType
- pan TouchType
- pinch TouchType
+ tap TouchType
+ longtap TouchType
+ pan TouchType
+ pinch TouchType
}{
- tap: _tap,
- longtap: _longtap,
- pan: _pan,
- pinch: _pinch,
+ tap: _tap,
+ longtap: _longtap,
+ pan: _pan,
+ pinch: _pinch,
}
// TouchInput is a "manager" for touch input and provides logical encapsulations of
@@ -51,10 +51,10 @@ type TouchInput struct {
touchIDs []ebiten.TouchID
touches map[ebiten.TouchID]*touch
- pinch *pinch
- pan *pan
- longtap *longtap
- taps []tap
+ pinch *pinch
+ pan *pan
+ longtap *longtap
+ taps []tap
}
func (t *TouchInput) consumetap(i int) {
@@ -65,9 +65,7 @@ func (t *TouchInput) consumetap(i int) {
}
}
-var (
- TouchManager *TouchInput
-)
+var TouchManager *TouchInput
func init() {
TouchManager = NewTouchInput()
@@ -181,10 +179,10 @@ func (in *TouchInput) Update() error {
t := in.touches[id]
t.isLongtap = true
in.longtap = &longtap{
- id: id,
- tap: tap{t.originX, t.originY},
+ id: id,
+ tap: tap{t.originX, t.originY},
duration: t.duration,
- }
+ }
}
}
}
@@ -193,10 +191,10 @@ func (in *TouchInput) Update() error {
}
type touch struct {
- originX, originY int
- currX, currY int
- duration int
- wasPinch, isPan, isLongtap bool
+ originX, originY int
+ currX, currY int
+ duration int
+ wasPinch, isPan, isLongtap bool
}
type pinch struct {
@@ -252,6 +250,6 @@ type tap struct {
type longtap struct {
tap
- id ebiten.TouchID
+ id ebiten.TouchID
duration int
}
diff --git a/go/ui/update.go b/go/ui/update.go
index 9c8ce82c..73c9d787 100644
--- a/go/ui/update.go
+++ b/go/ui/update.go
@@ -110,7 +110,9 @@ func Update() error {
var hoverChange bool
if len(TouchManager.taps) > 0 || TouchManager.pan != nil || TouchManager.pinch != nil {
hoverEv, hoverChange = longtapHoverDetector.reset()
- if hoverChange { AppendInput(hoverEv) }
+ if hoverChange {
+ AppendInput(hoverEv)
+ }
}
for _, tap := range TouchManager.taps {
@@ -125,7 +127,9 @@ func Update() error {
}
hoverEv, hoverChange = longtapHoverDetector.update(TouchManager.longtap)
- if hoverChange { AppendInput(hoverEv) }
+ if hoverChange {
+ AppendInput(hoverEv)
+ }
// TODO: handle pinching
if TouchManager.pinch != nil {
@@ -133,7 +137,9 @@ func Update() error {
x, y := ebiten.CursorPosition()
hoverEv, hoverChange = hoverDetector.update(x, y)
- if hoverChange { AppendInput(hoverEv) }
+ if hoverChange {
+ AppendInput(hoverEv)
+ }
scrollX, scrollY := ebiten.Wheel()
if scrollX != 0 || scrollY != 0 {