-
Notifications
You must be signed in to change notification settings - Fork 0
/
dungeon_select.go
132 lines (110 loc) · 3.67 KB
/
dungeon_select.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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 DungeonSelectState struct {
ui *ebitenui.UI
trans *states.Transition
dungeonSelectContainer *widget.Container
dungeonDescContainer *widget.Container
}
func (st DungeonSelectState) String() string {
return "DungeonSelect"
}
// State interface ================
func (st *DungeonSelectState) OnPause(world w.World) {}
func (st *DungeonSelectState) OnResume(world w.World) {}
func (st *DungeonSelectState) OnStart(world w.World) {
// prefabs := world.Resources.Prefabs.(*resources.Prefabs)
// st.dungeonSelect = append(st.dungeonSelect, loader.AddEntities(world, prefabs.Menu.DungeonSelect)...)
st.ui = st.initUI(world)
}
func (st *DungeonSelectState) OnStop(world w.World) {}
func (st *DungeonSelectState) Update(world w.World) states.Transition {
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
return states.Transition{Type: states.TransPop}
}
// world.Manager.Join(world.Components.Engine.Text, world.Components.Engine.UITransform).Visit(ecs.Visit(func(entity ecs.Entity) {
// text := world.Components.Engine.Text.Get(entity).(*ec.Text)
// if text.ID == "description" {
// switch st.selection {
// case 0:
// text.Text = "鬱蒼とした森の奥地にある遺跡"
// case 1:
// text.Text = "切り立った山の洞窟にある遺跡"
// case 2:
// text.Text = "雲にまで届く塔を持つ遺跡"
// }
// }
// }))
if st.trans != nil {
next := *st.trans
st.trans = nil
return next
}
st.ui.Update()
return states.Transition{Type: states.TransNone}
}
func (st *DungeonSelectState) Draw(world w.World, screen *ebiten.Image) {
st.ui.Draw(screen)
}
func (st *DungeonSelectState) initUI(world w.World) *ebitenui.UI {
rootContainer := eui.NewVerticalContainer()
st.dungeonSelectContainer = eui.NewRowContainer()
rootContainer.AddChild(st.dungeonSelectContainer)
st.dungeonDescContainer = eui.NewRowContainer()
rootContainer.AddChild(st.dungeonDescContainer)
st.updateMenuContainer(world)
return &ebitenui.UI{Container: rootContainer}
}
func (st *DungeonSelectState) updateMenuContainer(world w.World) {
st.dungeonSelectContainer.RemoveChildren()
for _, data := range dungeonSelectTrans {
data := data
btn := eui.NewItemButton(
data.label,
func(args *widget.ButtonClickedEventArgs) {
st.trans = &data.trans
},
world,
)
btn.GetWidget().CursorEnterEvent.AddHandler(func(args interface{}) {
st.dungeonDescContainer.RemoveChildren()
st.dungeonDescContainer.AddChild(eui.NewMenuText(data.desc, world))
})
st.dungeonSelectContainer.AddChild(btn)
}
}
// MEMO: まだtransは全部同じ
var dungeonSelectTrans = []struct {
label string
desc string
trans states.Transition
}{
{
label: "森の遺跡",
desc: "鬱蒼とした森の奥地にある遺跡",
trans: states.Transition{Type: states.TransReplace, NewStates: []states.State{&DungeonState{}}},
},
{
label: "山の遺跡",
desc: "切り立った山の洞窟にある遺跡",
trans: states.Transition{Type: states.TransReplace, NewStates: []states.State{&DungeonState{}}},
},
{
label: "塔の遺跡",
desc: "雲にまで届く塔を持つ遺跡",
trans: states.Transition{Type: states.TransReplace, NewStates: []states.State{&DungeonState{}}},
},
{
label: "拠点メニューに戻る",
desc: "",
trans: states.Transition{Type: states.TransSwitch, NewStates: []states.State{&HomeMenuState{}}},
},
}