ChocolateBird/widgets/PartyMenu.gd

110 lines
3.7 KiB
GDScript3
Raw Permalink Normal View History

extends Panel
2023-12-09 22:30:43 +10:30
onready var sidebar_classic := $'%sidebar_classic'
onready var sbc_menu_item_containers := [$'%menu_items_1', $'%menu_items_2']
onready var lbl_time := $'%lbl_time'
onready var lbl_gilcount := $'%lbl_gilcount'
2023-12-09 22:30:43 +10:30
onready var characters_container := $'%characters_container'
onready var items_menu := $'%items_menu'
onready var items_container := $'%items_container'
onready var lbl_item_description := $'%lbl_item_description'
2023-12-09 22:30:43 +10:30
enum Submenu {PARTY, ITEMS}
const str2submenu := {
'party': Submenu.PARTY,
'items': Submenu.ITEMS,
}
var submenu2sbc_label := {}
onready var submenu2widget := {
Submenu.PARTY: characters_container,
Submenu.ITEMS: items_menu,
}
func update_labels(data: Dictionary):
var characters = data.characters
2023-12-09 22:30:43 +10:30
var character_panels = characters_container.get_children()
for i in len(characters):
var p = character_panels[i]
p.visible = not characters[i].is_absent
p.update_labels(data, i)
lbl_time.text = Common.game_time_frames_to_hhmm(data.game_time_frames)
lbl_gilcount.text = '%d' % data.current_gil
# Populate inventory
2023-12-09 22:30:43 +10:30
for child in items_container.get_children():
child.queue_free()
for i in 256:
var item_id = data.inventory_item_ids[i]
var item_qty = data.inventory_item_qtys[i]
2023-12-11 01:43:40 +10:30
# var item_name = StringLoader.tables.items[item_id]
var item_name = StringLoader.tables.item_long_names[item_id].rstrip(' ')
2023-12-09 22:30:43 +10:30
var lbl_item_name := Label.new()
var lbl_item_qty := Label.new()
lbl_item_qty.align = HALIGN_RIGHT
if item_qty > 0:
lbl_item_name.text = item_name
lbl_item_qty.text = 'x%d'%item_qty
var desc = StringLoader.get_inventory_item_desc(item_id)
if desc:
lbl_item_name.mouse_filter = MOUSE_FILTER_PASS
lbl_item_name.hint_tooltip = desc
2023-12-09 22:30:43 +10:30
items_container.add_child(lbl_item_name)
items_container.add_child(lbl_item_qty)
func _init_sidebar_classic() -> void:
for menu_item_container in sbc_menu_item_containers:
for label in menu_item_container.get_children():
var submenu = str2submenu.get(label.name, -1)
if submenu > -1:
self.submenu2sbc_label[submenu] = label
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
2023-12-09 22:30:43 +10:30
_init_sidebar_classic()
var _err = change_submenu(Submenu.PARTY)
const active_label_colour := Color.yellow
const inactive_label_colour := Color.white
func change_submenu(submenu_id) -> int:
# print(submenu)
if not (submenu_id in submenu2widget):
return ERR_DOES_NOT_EXIST
# Make everything inactive/invisible
for submenu in submenu2widget.values():
submenu.visible = false
for label in submenu2sbc_label.values():
label.modulate = inactive_label_colour
# Make the selected submenu active/visible
submenu2widget[submenu_id].visible = true
submenu2sbc_label[submenu_id].modulate = active_label_colour
return OK
func change_submenu_by_name(name: String) -> int:
var submenu = str2submenu.get(name, -1)
if submenu < 0:
return ERR_DOES_NOT_EXIST
return change_submenu(submenu)
2023-12-09 22:30:43 +10:30
func _on_sidebar_classic_click(pos: Vector2) -> int:
for menu_item_container in sbc_menu_item_containers:
var rect: Rect2 = menu_item_container.get_global_rect()
if rect.has_point(pos):
var local_y := pos.y - rect.position.y
var menu_items: Array = menu_item_container.get_children()
# A y-check is sufficient if we assume all labels are the same height
var label_height: float = menu_items[0].rect_size.y
var selected_label: int = int(local_y/label_height)
if selected_label < len(menu_items):
return change_submenu_by_name(menu_items[selected_label].name)
return ERR_CANT_RESOLVE
2023-12-09 22:30:43 +10:30
func _input(event: InputEvent) -> void:
if (event is InputEventMouseButton or event is InputEventScreenTouch) and event.pressed:
var pos: Vector2 = event.position
if sidebar_classic.get_global_rect().has_point(pos):
var _err = _on_sidebar_classic_click(pos)