-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug_menu.go
106 lines (86 loc) · 2.52 KB
/
debug_menu.go
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package states
import (
"github.com/ebitenui/ebitenui"
"github.com/ebitenui/ebitenui/widget"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/kijimaD/ruins/lib/engine/states"
w "github.com/kijimaD/ruins/lib/engine/world"
"github.com/kijimaD/ruins/lib/eui"
"github.com/kijimaD/ruins/lib/raw"
"github.com/kijimaD/ruins/lib/spawner"
)
type DebugMenuState struct {
ui *ebitenui.UI
trans *states.Transition
debugMenuContainer *widget.Container
}
func (st DebugMenuState) String() string {
return "DebugMenu"
}
// State interface ================
func (st *DebugMenuState) OnPause(world w.World) {}
func (st *DebugMenuState) OnResume(world w.World) {}
func (st *DebugMenuState) OnStart(world w.World) {
st.ui = st.initUI(world)
}
func (st *DebugMenuState) OnStop(world w.World) {}
func (st *DebugMenuState) Update(world w.World) states.Transition {
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
return states.Transition{Type: states.TransPop}
}
if st.trans != nil {
next := *st.trans
st.trans = nil
return next
}
st.ui.Update()
return states.Transition{Type: states.TransNone}
}
func (st *DebugMenuState) Draw(world w.World, screen *ebiten.Image) {
st.ui.Draw(screen)
}
// ================
func (st *DebugMenuState) initUI(world w.World) *ebitenui.UI {
rootContainer := eui.NewVerticalTransContainer()
st.debugMenuContainer = eui.NewVerticalContainer()
rootContainer.AddChild(st.debugMenuContainer)
st.updateMenuContainer(world)
return &ebitenui.UI{Container: rootContainer}
}
func (st *DebugMenuState) updateMenuContainer(world w.World) {
st.debugMenuContainer.RemoveChildren()
for _, data := range debugMenuTrans {
data := data
btn := eui.NewItemButton(
data.label,
func(args *widget.ButtonClickedEventArgs) {
data.f(world)
st.trans = &data.trans
},
world,
)
st.debugMenuContainer.AddChild(btn)
}
}
var debugMenuTrans = []struct {
label string
f func(world w.World)
trans states.Transition
}{
{
label: "回復薬スポーン(インベントリ)",
f: func(world w.World) { spawner.SpawnItem(world, "回復薬", raw.SpawnInBackpack) },
trans: states.Transition{Type: states.TransNone},
},
{
label: "手榴弾スポーン(インベントリ)",
f: func(world w.World) { spawner.SpawnItem(world, "手榴弾", raw.SpawnInBackpack) },
trans: states.Transition{Type: states.TransNone},
},
{
label: "閉じる",
f: func(world w.World) {},
trans: states.Transition{Type: states.TransPop},
},
}