aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-08-07 17:59:58 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-07 17:59:58 +0200
commit157179e6963cb74fc8bfe5e661429ce60c53f34d (patch)
tree171b1dc1f91d37fafe93f443e3e75f98ac7ba427
parent22859c22caec95d5e980ade4adc0b6eb777d437b (diff)
downloadmuhqs-game-157179e6963cb74fc8bfe5e661429ce60c53f34d.tar.gz
muhqs-game-157179e6963cb74fc8bfe5e661429ce60c53f34d.zip
add specialized longtap hover detector
-rw-r--r--go/ui/collection.go2
-rw-r--r--go/ui/hoverDetector.go31
-rw-r--r--go/ui/hoverable.go4
-rw-r--r--go/ui/touchManager.go2
-rw-r--r--go/ui/update.go23
5 files changed, 40 insertions, 22 deletions
diff --git a/go/ui/collection.go b/go/ui/collection.go
index c5f59540..84b37366 100644
--- a/go/ui/collection.go
+++ b/go/ui/collection.go
@@ -189,7 +189,7 @@ func (c *Collection) Update() error {
}
case HoverEnd:
if c.hovering != nil {
- w.Hover(false, ev.X, ev.Y)
+ c.hovering.Hover(false, ev.X, ev.Y)
c.hovering = nil
}
case HoverStart:
diff --git a/go/ui/hoverDetector.go b/go/ui/hoverDetector.go
index 385b2ffd..d18ea53e 100644
--- a/go/ui/hoverDetector.go
+++ b/go/ui/hoverDetector.go
@@ -6,23 +6,23 @@ package ui
type _hoverDetector struct {
last_x, last_y int
ticks int
+ threshold int
}
-const HOVER_THRESHOLD = 60
var (
- hoverDetector _hoverDetector
- longtapHoverDetector _hoverDetector
+ hoverDetector = _hoverDetector{threshold: 60}
+ longtapHoverDetector = _longtapHoverDetector{}
)
func (h *_hoverDetector) update(x, y int) (ev InputEvent, ch bool) {
if x == h.last_x && y == h.last_y {
h.ticks = h.ticks + 1
- if h.ticks == HOVER_THRESHOLD {
+ if h.ticks == h.threshold {
return InputEvent{HoverStart, x, y, nil}, true
}
} else {
- if h.ticks > HOVER_THRESHOLD {
+ if h.ticks > h.threshold {
ev = InputEvent{HoverEnd, h.last_x, h.last_y, nil}
ch = true
}
@@ -32,3 +32,24 @@ func (h *_hoverDetector) update(x, y int) (ev InputEvent, ch bool) {
return
}
+
+type _longtapHoverDetector struct {
+ active *longtap
+}
+
+func (h *_longtapHoverDetector) update(longtap *longtap) (ev InputEvent, ch bool) {
+ if longtap != nil && h.active == nil {
+ h.active = longtap
+ return InputEvent{HoverStart, longtap.x, longtap.y, nil}, true
+ }
+ return InputEvent{}, false
+}
+
+func (h *_longtapHoverDetector) reset() (ev InputEvent, ch bool) {
+ if h.active != nil {
+ ev := InputEvent{HoverEnd, h.active.x, h.active.y, nil}
+ h.active = nil
+ return ev, true
+ }
+ return InputEvent{}, false
+}
diff --git a/go/ui/hoverable.go b/go/ui/hoverable.go
index 3f7e8def..c70340bb 100644
--- a/go/ui/hoverable.go
+++ b/go/ui/hoverable.go
@@ -84,10 +84,10 @@ type hoverPermInfo struct {
hoverWidget
}
-func (h *hoverPermInfo) init(w Widget, c *Collection) {
+func (h *hoverPermInfo) init(mv *MapView, c *Collection) {
h.c = c
h.createHint = func(x, y int) Widget {
- obj := w.FindObjectAt(x, y)
+ obj := mv.FindObjectAt(x, y)
if obj == nil {
return nil
}
diff --git a/go/ui/touchManager.go b/go/ui/touchManager.go
index b675ff0e..ccc07217 100644
--- a/go/ui/touchManager.go
+++ b/go/ui/touchManager.go
@@ -22,7 +22,7 @@ import (
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
-const LONGTAP_THRESHOLD = 75
+const LONGTAP_THRESHOLD = 60
type TouchType int
diff --git a/go/ui/update.go b/go/ui/update.go
index c4ed3224..621d5dea 100644
--- a/go/ui/update.go
+++ b/go/ui/update.go
@@ -79,6 +79,13 @@ func Update() error {
return err
}
+ var hoverEv InputEvent
+ var hoverChange bool
+ if len(TouchManager.taps) > 0 || TouchManager.pan != nil || TouchManager.pinch != nil {
+ hoverEv, hoverChange = longtapHoverDetector.reset()
+ if hoverChange { AppendInput(hoverEv) }
+ }
+
for _, tap := range TouchManager.taps {
AppendInput(InputEvent{Tap, tap.x, tap.y, nil})
}
@@ -90,16 +97,8 @@ func Update() error {
}
- var hoverEv InputEvent
- var hoverChange bool
- if TouchManager.longtap != nil {
- hoverEv, hoverChange = longtapHoverDetector.update(TouchManager.longtap.x, TouchManager.longtap.y)
- } else {
- hoverEv, hoverChange = longtapHoverDetector.update(-1, -1)
- }
- if hoverChange {
- AppendInput(hoverEv)
- }
+ hoverEv, hoverChange = longtapHoverDetector.update(TouchManager.longtap)
+ if hoverChange { AppendInput(hoverEv) }
// TODO: handle pinching
if TouchManager.pinch != nil {
@@ -107,9 +106,7 @@ 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 {