-
Notifications
You must be signed in to change notification settings - Fork 0
/
field_menu.go
95 lines (75 loc) · 2.09 KB
/
field_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
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"
)
type FieldMenuState struct {
ui *ebitenui.UI
trans *states.Transition
fieldMenuContainer *widget.Container
}
func (st FieldMenuState) String() string {
return "FieldMenu"
}
// State interface ================
func (st *FieldMenuState) OnPause(world w.World) {}
func (st *FieldMenuState) OnResume(world w.World) {}
func (st *FieldMenuState) OnStart(world w.World) {
st.ui = st.initUI(world)
}
func (st *FieldMenuState) OnStop(world w.World) {}
func (st *FieldMenuState) Update(world w.World) states.Transition {
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
return states.Transition{Type: states.TransPop}
}
st.ui.Update()
if st.trans != nil {
next := *st.trans
st.trans = nil
return next
}
return states.Transition{Type: states.TransNone}
}
func (st *FieldMenuState) Draw(world w.World, screen *ebiten.Image) {
st.ui.Draw(screen)
}
// ================
func (st *FieldMenuState) initUI(world w.World) *ebitenui.UI {
rootContainer := eui.NewVerticalTransContainer()
st.fieldMenuContainer = eui.NewVerticalContainer()
rootContainer.AddChild(st.fieldMenuContainer)
st.updateMenuContainer(world)
return &ebitenui.UI{Container: rootContainer}
}
func (st *FieldMenuState) updateMenuContainer(world w.World) {
st.fieldMenuContainer.RemoveChildren()
for _, data := range fieldMenuTrans {
data := data
btn := eui.NewItemButton(
data.label,
func(args *widget.ButtonClickedEventArgs) {
st.trans = &data.trans
},
world,
)
st.fieldMenuContainer.AddChild(btn)
}
}
var fieldMenuTrans = []struct {
label string
trans states.Transition
}{
{
label: "閉じる",
trans: states.Transition{Type: states.TransPop},
},
{
label: "終了",
trans: states.Transition{Type: states.TransSwitch, NewStates: []states.State{&MainMenuState{}}},
},
}