summaryrefslogtreecommitdiff
path: root/Scenes/UI/Menu.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-05-23 14:11:43 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-05-23 14:11:43 +0200
commit06647b11ee163bc40daf454d87e1fcae563c3ced (patch)
tree866823ed79fa1c3bbdcb8b0be417f028f0c92d9b /Scenes/UI/Menu.gd
parent276b7664bd4a475a3ca93a682c16b49c504c58f7 (diff)
update
Diffstat (limited to 'Scenes/UI/Menu.gd')
-rw-r--r--Scenes/UI/Menu.gd88
1 files changed, 73 insertions, 15 deletions
diff --git a/Scenes/UI/Menu.gd b/Scenes/UI/Menu.gd
index ce45a26..9b41b20 100644
--- a/Scenes/UI/Menu.gd
+++ b/Scenes/UI/Menu.gd
@@ -3,24 +3,39 @@ extends TabContainer
@onready var audio_bus = AudioServer.get_bus_index("Master")
+@onready var focused_tab = 0
+@onready var focused_tab_elements: Dictionary = {
+ 0: $Bombs/Panel/HBoxContainer/VBoxContainer/ButtonBombNormal,
+ 1: $System/Panel/VBoxContainer/ButtonResume,
+}
+@onready var exclude_from_focus = [
+ %BombComponents,
+]
+
+var current_slot_idx = 0
+
func _ready():
hide()
self._ready_bombs()
self._ready_system()
+
+ var tabs = get_children()
+ for idx in tabs.size():
+ for child in Utilities.get_all_children(tabs[idx]):
+ if child is Control and not exclude_from_focus.has(child):
+ child.focus_entered.connect(func():
+ focused_tab_elements[idx] = child
+ )
func _input(event: InputEvent):
if event.is_action_pressed("ui_menu"):
- print(Global.player.position)
- print("pressed")
if get_tree().paused: # game is paused
self.close_menu()
- print("was paused")
else: # game is running
self.open_menu()
- print("was running")
if event.is_action_pressed("ui_menu_left"):
if get_current_tab() > 0:
@@ -29,29 +44,29 @@ func _input(event: InputEvent):
if get_current_tab() < get_tab_count() - 1:
set_current_tab(get_current_tab() + 1)
- connect("tab_changed", func(tab_id):
- if tab_id == 0:
- (func(): $Bombs/Panel/HBoxContainer/VBoxContainer/ButtonBombNormal.grab_focus()).call_deferred()
- elif tab_id == 1:
- (func(): $System/Panel/VBoxContainer/ButtonResume.grab_focus()).call_deferred()
+ tab_changed.connect(func(tab_idx):
+ focused_tab = tab_idx
+ (func(): focused_tab_elements[tab_idx].grab_focus()).call_deferred()
)
+
+ _input_bombs(event)
func open_menu():
get_tree().paused = true
+ tab_changed.emit(focused_tab)
show()
-
- (func(): $Bombs/Panel/HBoxContainer/VBoxContainer/ButtonBombNormal.grab_focus()).call_deferred()
func close_menu():
+ %BombComponents.hide()
+
hide()
get_tree().paused = false
func get_player():
return Global.player
- #return get_tree().get_current_scene().get_node("Player")
### Bombs ###
@@ -61,6 +76,19 @@ func _ready_bombs():
for component in Bomb.COMPONENT_TYPE:
var idx = Bomb.COMPONENT_TYPE[component]
$Bombs/Panel/HBoxContainer/VBoxContainer3/BombComponents.set_item_text(idx, component.capitalize())
+
+ for idx in Global.player.bomb_components.size():
+ var component = Bomb.COMPONENT_TYPE.find_key(Global.player.bomb_components[idx])
+ if component:
+ $Bombs/Panel/HBoxContainer/VBoxContainer3/VBoxContainer.get_node("Slot" + str(idx+1)).text = component.capitalize()
+
+ %BombComponents.item_activated.connect(Callable(self, "_on_bomb_components_item_selected"))
+
+
+func _input_bombs(event):
+ if %BombComponents.visible and event.is_action_pressed("ui_cancel"):
+ %BombComponents.hide()
+ focused_tab_elements[focused_tab].grab_focus()
func _on_button_bomb_normal_pressed():
@@ -77,9 +105,39 @@ func _on_bomb_power_item_selected(index):
func _on_bomb_components_multi_selected(_index, _selected):
- Global.player.bomb_components = []
- for idx in $Bombs/Panel/HBoxContainer/VBoxContainer3/BombComponents.get_selected_items():
- Global.player.bomb_components.append(idx) # same as enum idx
+ pass
+ #Global.player.bomb_components = {}
+ #for idx in $Bombs/Panel/HBoxContainer/VBoxContainer3/BombComponents.get_selected_items():
+ #Global.player.bomb_components.append(idx) # same as enum idx
+
+
+func _on_slot_pressed(slot_idx):
+ %BombComponents.clear()
+
+ for component in Bomb.COMPONENT_TYPE:
+ var idx = Bomb.COMPONENT_TYPE[component]
+ %BombComponents.add_item(
+ component.capitalize(),
+ null,
+ Global.player.bomb_components.find_key(idx) == null
+ )
+ # todo position swap
+ # make all selectable
+ # but when already in bomb_components, swap position
+ # nonetheless, hightlight already selected item differently
+
+ %BombComponents.show()
+ %BombComponents.force_update_list_size()
+ %BombComponents.grab_focus()
+
+ current_slot_idx = slot_idx
+
+
+func _on_bomb_components_item_selected(idx):
+ Global.player.bomb_components[current_slot_idx] = idx
+ %BombComponents.hide()
+ $Bombs/Panel/HBoxContainer/VBoxContainer3/VBoxContainer.get_node("Slot" + str(current_slot_idx+1)).grab_focus()
+ $Bombs/Panel/HBoxContainer/VBoxContainer3/VBoxContainer.get_node("Slot" + str(current_slot_idx+1)).text = Bomb.COMPONENT_TYPE.find_key(idx).capitalize()
### System ###