-
Notifications
You must be signed in to change notification settings - Fork 0
/
home_menu.go
207 lines (178 loc) · 6.45 KB
/
home_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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// 拠点でのコマンド選択画面
package states
import (
"github.com/ebitenui/ebitenui"
"github.com/ebitenui/ebitenui/widget"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
gc "github.com/kijimaD/ruins/lib/components"
"github.com/kijimaD/ruins/lib/effects"
"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"
gs "github.com/kijimaD/ruins/lib/systems"
"github.com/kijimaD/ruins/lib/views"
"github.com/kijimaD/ruins/lib/worldhelper/equips"
"github.com/kijimaD/ruins/lib/worldhelper/material"
ecs "github.com/x-hgg-x/goecs/v2"
)
type HomeMenuState struct {
ui *ebitenui.UI
trans *states.Transition
memberContainer *widget.Container // メンバー一覧コンテナ
actionListContainer *widget.Container // 選択肢アクション一覧コンテナ
actionDescContainer *widget.Container // 選択肢アクションの説明コンテナ
}
func (st HomeMenuState) String() string {
return "HomeMenu"
}
// State interface ================
func (st *HomeMenuState) OnPause(world w.World) {}
func (st *HomeMenuState) OnResume(world w.World) {}
func (st *HomeMenuState) OnStart(world w.World) {
// デバッグ用
// 初回のみ追加する
memberCount := 0
gameComponents := world.Components.Game.(*gc.Components)
world.Manager.Join(
gameComponents.Member,
).Visit(ecs.Visit(func(entity ecs.Entity) {
memberCount++
}))
if memberCount == 0 {
spawner.SpawnItem(world, "木刀", raw.SpawnInBackpack)
spawner.SpawnItem(world, "ハンドガン", raw.SpawnInBackpack)
spawner.SpawnItem(world, "レイガン", raw.SpawnInBackpack)
armor := spawner.SpawnItem(world, "西洋鎧", raw.SpawnInBackpack)
spawner.SpawnItem(world, "作業用ヘルメット", raw.SpawnInBackpack)
spawner.SpawnItem(world, "革のブーツ", raw.SpawnInBackpack)
spawner.SpawnItem(world, "ルビー原石", raw.SpawnInBackpack)
spawner.SpawnItem(world, "回復薬", raw.SpawnInBackpack)
spawner.SpawnItem(world, "回復薬", raw.SpawnInBackpack)
spawner.SpawnItem(world, "回復スプレー", raw.SpawnInBackpack)
spawner.SpawnItem(world, "回復スプレー", raw.SpawnInBackpack)
spawner.SpawnItem(world, "手榴弾", raw.SpawnInBackpack)
spawner.SpawnItem(world, "手榴弾", raw.SpawnInBackpack)
spawner.SpawnItem(world, "手榴弾", raw.SpawnInBackpack)
spawner.SpawnItem(world, "手榴弾", raw.SpawnInBackpack)
ishihara := spawner.SpawnMember(world, "イシハラ", true)
spawner.SpawnMember(world, "シラセ", true)
spawner.SpawnMember(world, "ヒラヤマ", true)
spawner.SpawnAllMaterials(world)
material.PlusAmount("鉄", 40, world)
material.PlusAmount("鉄くず", 4, world)
material.PlusAmount("緑ハーブ", 2, world)
material.PlusAmount("フェライトコア", 30, world)
spawner.SpawnAllRecipes(world)
equips.Equip(world, armor, ishihara, gc.EquipmentSlotZero)
}
// ステータス反映(最大HP)
_ = gs.EquipmentChangedSystem(world)
// 完全回復
effects.AddEffect(nil, effects.Healing{Amount: gc.RatioAmount{Ratio: float64(1.0)}}, effects.Party{})
effects.AddEffect(nil, effects.RecoveryStamina{Amount: gc.RatioAmount{Ratio: float64(1.0)}}, effects.Party{})
effects.RunEffectQueue(world)
st.ui = st.initUI(world)
}
func (st *HomeMenuState) OnStop(world w.World) {}
func (st *HomeMenuState) Update(world w.World) states.Transition {
effects.RunEffectQueue(world)
_ = gs.EquipmentChangedSystem(world)
if inpututil.IsKeyJustPressed(ebiten.KeySlash) {
return states.Transition{Type: states.TransPush, NewStates: []states.State{&DebugMenuState{}}}
}
st.ui.Update()
if st.trans != nil {
next := *st.trans
st.trans = nil
return next
}
return states.Transition{Type: states.TransNone}
}
func (st *HomeMenuState) Draw(world w.World, screen *ebiten.Image) {
st.ui.Draw(screen)
}
// ================
func (st *HomeMenuState) initUI(world w.World) *ebitenui.UI {
rootContainer := eui.NewVerticalContainer()
st.memberContainer = eui.NewRowContainer()
st.actionListContainer = eui.NewRowContainer()
st.actionDescContainer = eui.NewRowContainer()
actionContainer := eui.NewVSplitContainer(st.actionListContainer, st.actionDescContainer)
{
rootContainer.AddChild(st.memberContainer)
rootContainer.AddChild(actionContainer)
}
st.updateActionList(world)
st.updateMemberContainer(world)
return &ebitenui.UI{Container: rootContainer}
}
var homeMenuTrans = []struct {
label string
trans states.Transition
desc string
}{
{
label: "出発",
trans: states.Transition{Type: states.TransPush, NewStates: []states.State{&DungeonSelectState{}}},
desc: "遺跡に出発する",
},
{
label: "合成",
trans: states.Transition{Type: states.TransPush, NewStates: []states.State{&CraftMenuState{category: ItemCategoryTypeItem}}},
desc: "アイテムを合成する",
},
{
label: "入替",
trans: states.Transition{Type: states.TransNone},
desc: "仲間を入れ替える(未実装)",
},
{
label: "所持",
trans: states.Transition{Type: states.TransSwitch, NewStates: []states.State{&InventoryMenuState{category: ItemCategoryTypeItem}}},
desc: "所持品を確認する",
},
{
label: "装備",
trans: states.Transition{Type: states.TransSwitch, NewStates: []states.State{&EquipMenuState{}}},
desc: "装備を変更する",
},
{
label: "終了",
trans: states.Transition{Type: states.TransSwitch, NewStates: []states.State{&MainMenuState{}}},
desc: "タイトル画面に戻る",
},
}
// 選択肢を更新する
func (st *HomeMenuState) updateActionList(world w.World) {
st.actionListContainer.RemoveChildren()
for _, data := range homeMenuTrans {
data := data
btn := eui.NewItemButton(
data.label,
func(args *widget.ButtonClickedEventArgs) {
st.trans = &data.trans
},
world,
)
btn.GetWidget().CursorEnterEvent.AddHandler(func(args interface{}) {
st.actionDescContainer.RemoveChildren()
st.actionDescContainer.AddChild(eui.NewMenuText(data.desc, world))
st.updateMemberContainer(world)
})
st.actionListContainer.AddChild(btn)
}
}
// メンバー一覧を更新する
func (st *HomeMenuState) updateMemberContainer(world w.World) {
st.memberContainer.RemoveChildren()
gameComponents := world.Components.Game.(*gc.Components)
world.Manager.Join(
gameComponents.Member,
gameComponents.InParty,
).Visit(ecs.Visit(func(entity ecs.Entity) {
views.AddMemberBar(world, st.memberContainer, entity)
}))
}