blob: a6b32cf9a360e1e50b8acba4e7674827c6b63909 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
package main
import (
"log"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
type (
keyAction func(*Game) bool
keyBindings map[interface{}]keyAction
)
func (g *Game) handleKeyBindings(bindings keyBindings) {
for _k, a := range bindings {
var remove bool
switch k := _k.(type) {
case ebiten.MouseButton:
if inpututil.IsMouseButtonJustPressed(k) {
remove = a(g)
}
case ebiten.Key:
if inpututil.IsKeyJustPressed(k) {
remove = a(g)
}
}
if remove {
delete(bindings, _k)
}
}
}
func selection(g *Game) bool {
x, y := ebiten.CursorPosition()
obj := g.findObjectAt(x, y)
if g.prompt != nil {
if err := g.prompt.Add(obj); err != nil {
log.Println("Not added", obj, "to active prompt:", err)
g.handleSelection(obj, x, y)
} else {
g.updateHighlight()
}
} else {
g.handleSelection(obj, x, y)
}
return false
}
func pass(g *Game) bool {
g.passButton.Click(0, 0)
return false
}
func reset(g *Game) bool {
g.removeChoice()
g.selectedObject = nil
g.ResetHover()
g.clearHighlights()
g.hideStore()
g.RemoveWidget(g.discardPileView)
if g.prompt != nil {
if g.prompt.Action().Targets().NoSelections() {
g.removePrompt()
} else {
g.prompt.ClearSelections()
}
}
return false
}
|