From 06647b11ee163bc40daf454d87e1fcae563c3ced Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 23 May 2024 14:11:43 +0200 Subject: update --- Scenes/UI/Menu.gd | 88 ++++++++++++++++++++++++++++++++++++++++++++--------- Scenes/UI/Menu.tscn | 51 +++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 15 deletions(-) (limited to 'Scenes/UI') 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 ### diff --git a/Scenes/UI/Menu.tscn b/Scenes/UI/Menu.tscn index 38c3ee4..e7c7b13 100644 --- a/Scenes/UI/Menu.tscn +++ b/Scenes/UI/Menu.tscn @@ -32,6 +32,7 @@ theme_override_font_sizes/font_size = 5 theme_override_styles/panel = SubResource("StyleBoxFlat_flq5r") theme_override_styles/tabbar_background = SubResource("StyleBoxFlat_u0ugs") clip_tabs = false +tab_focus_mode = 0 script = ExtResource("1_vwah3") [node name="Bombs" type="MarginContainer" parent="."] @@ -101,6 +102,7 @@ text = "Components" label_settings = SubResource("LabelSettings_qokw0") [node name="BombComponents" type="ItemList" parent="Bombs/Panel/HBoxContainer/VBoxContainer3"] +visible = false layout_mode = 2 theme_override_font_sizes/font_size = 4 select_mode = 1 @@ -114,6 +116,52 @@ item_2/text = "RemoteDetonate" item_3/text = "Water" item_4/text = "Salt" +[node name="VBoxContainer" type="VBoxContainer" parent="Bombs/Panel/HBoxContainer/VBoxContainer3"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="Slot1" type="Button" parent="Bombs/Panel/HBoxContainer/VBoxContainer3/VBoxContainer"] +layout_mode = 2 +theme_override_font_sizes/font_size = 4 +text = "Empty" +flat = true + +[node name="Slot2" type="Button" parent="Bombs/Panel/HBoxContainer/VBoxContainer3/VBoxContainer"] +layout_mode = 2 +theme_override_font_sizes/font_size = 4 +text = "Empty" +flat = true + +[node name="Slot3" type="Button" parent="Bombs/Panel/HBoxContainer/VBoxContainer3/VBoxContainer"] +layout_mode = 2 +theme_override_font_sizes/font_size = 4 +text = "Empty" +flat = true + +[node name="MarginContainer" type="MarginContainer" parent="Bombs/Panel"] +layout_mode = 2 +offset_right = 232.0 +offset_bottom = 136.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="CenterContainer" type="CenterContainer" parent="Bombs/Panel/MarginContainer"] +layout_mode = 2 + +[node name="BombComponents" type="ItemList" parent="Bombs/Panel/MarginContainer/CenterContainer"] +unique_name_in_owner = true +visible = false +custom_minimum_size = Vector2(50, 0) +layout_mode = 2 +theme_override_font_sizes/font_size = 4 +auto_height = true +text_overrun_behavior = 0 +fixed_column_width = 500 + [node name="System" type="MarginContainer" parent="."] visible = false layout_mode = 2 @@ -167,6 +215,9 @@ step = 0.05 [connection signal="pressed" from="Bombs/Panel/HBoxContainer/VBoxContainer/ButtonBombBreakables" to="." method="_on_button_bomb_breakables_pressed"] [connection signal="item_selected" from="Bombs/Panel/HBoxContainer/VBoxContainer2/BombPower" to="." method="_on_bomb_power_item_selected"] [connection signal="multi_selected" from="Bombs/Panel/HBoxContainer/VBoxContainer3/BombComponents" to="." method="_on_bomb_components_multi_selected"] +[connection signal="pressed" from="Bombs/Panel/HBoxContainer/VBoxContainer3/VBoxContainer/Slot1" to="." method="_on_slot_pressed" binds= [0]] +[connection signal="pressed" from="Bombs/Panel/HBoxContainer/VBoxContainer3/VBoxContainer/Slot2" to="." method="_on_slot_pressed" binds= [1]] +[connection signal="pressed" from="Bombs/Panel/HBoxContainer/VBoxContainer3/VBoxContainer/Slot3" to="." method="_on_slot_pressed" binds= [2]] [connection signal="pressed" from="System/Panel/VBoxContainer/ButtonResume" to="." method="_on_button_resume_pressed"] [connection signal="pressed" from="System/Panel/VBoxContainer/ButtonQuit" to="." method="_on_button_quit_pressed"] [connection signal="value_changed" from="System/Panel/VBoxContainer2/SliderVolume" to="." method="_on_slider_volume_value_changed"] -- cgit v1.2.3