Line data Source code
1 : package states
2 :
3 : import (
4 : "github.com/hajimehoshi/ebiten/v2"
5 : "github.com/kijimaD/ruins/internal/keybind"
6 : "github.com/kijimaD/ruins/internal/menuloop"
7 : "github.com/kijimaD/ruins/internal/resources"
8 : "github.com/kijimaD/ruins/internal/widgets/menuframe"
9 : "github.com/kijimaD/ruins/internal/widgets/styled"
10 : "github.com/kijimaD/ruins/internal/widgets/uicore"
11 : w "github.com/kijimaD/ruins/internal/world"
12 : "github.com/kijimaD/ruins/internal/world/query"
13 : )
14 :
15 : // ViewUI は人物画面のタブ本体を組む。
16 : // 装備選択の入れ子モーダルは equip overlay が ScreenRenderer として本体の上へ重ねる。
17 : func (st *CharacterState) ViewUI(world w.World, props CharacterProps, cursor menuloop.Selection, res resources.UIResources) uicore.Drawable {
18 1 : var content []uicore.Drawable
19 1 : var pager string
20 1 : if charTabAt(cursor.TabIndex) == charTabEquip {
21 1 : content, pager = buildEquipListUI(world, props.EquipSlots, cursor.ItemIndex, res)
22 2 : } else if infoIdx := cursor.TabIndex - charFirstInfoTab; infoIdx >= 0 && infoIdx < len(props.InfoTabs) {
23 1 : content, pager = buildInfoTableUI(world, props.InfoTabs[infoIdx], cursor.ItemIndex, res)
24 1 : }
25 1 : return menuframe.TabScreen(world, res, props.TargetName, characterTabLabels(world), cursor.TabIndex, content, keybind.HelpHint(world), pager)
26 : }
27 :
28 : // buildEquipListUI は装備4列とフッタ右端のページ表示を返す。
29 : func buildEquipListUI(world w.World, slots []equipItemData, itemIndex int, res resources.UIResources) ([]uicore.Drawable, string) {
30 1 : cols := styled.Cols(styled.Fit(), styled.Icon(), styled.Name(), styled.Num())
31 1 : rows := make([]menuframe.Row, len(slots))
32 1 : for i, slot := range slots {
33 1 : var icon *ebiten.Image
34 1 : weight := ""
35 1 : if slot.Entity != nil {
36 1 : icon = menuIcon(world, *slot.Entity)
37 1 : weight = query.GetEntityWeight(world, *slot.Entity).KgString()
38 1 : }
39 1 : rows[i] = menuframe.Row{Cells: []styled.Cell{styled.TextCell(slot.SlotLabel), styled.IconCell(icon), styled.TextCell(slot.ItemName), styled.TextCell(weight)}}
40 : }
41 1 : return menuframe.RenderList(itemIndex, rows, cols, menuframe.ListOpts{EmptyText: query.T(world, "No equipment slots"), ItemsPerPage: menuframe.ListCapacity(world, true, true)}, res)
42 : }
|