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: $Character/Panel/HBoxContainer/Collaborations/TextureButton, 2: $System/Panel/VBoxContainer/ButtonResume, } @onready var exclude_from_focus = [ %BombComponents, ] var current_slot_idx = 0 var character_empty_slot: TextureButton func _ready(): hide() self._ready_bombs() self._ready_character() 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"): if get_tree().paused: # game is paused self.close_menu() else: # game is running self.open_menu() if self.visible: if event.is_action_pressed("ui_menu_left"): if get_current_tab() > 0: set_current_tab(get_current_tab() - 1) if event.is_action_pressed("ui_menu_right"): if get_current_tab() < get_tab_count() - 1: set_current_tab(get_current_tab() + 1) 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 close_menu(): %BombComponents.hide() hide() get_tree().paused = false func get_player(): return Global.player ### Bombs ### 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(): self.get_player().BombScene = preload("res://Scenes/Entities/Bombs/Bomb__Normal.tscn") func _on_button_bomb_breakables_pressed(): self.get_player().BombScene = preload("res://Scenes/Entities/Bombs/Bomb__Breakables.tscn") func _on_bomb_power_item_selected(index): var power = int($Bombs/Panel/HBoxContainer/VBoxContainer2/BombPower.get_item_text(index)) self.get_player().bomb_power = power func _on_bomb_components_multi_selected(_index, _selected): 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() ### Character ### func _ready_character(): ## Set $Main/$Main to current character ## TODO ## Add Slots to $Collaborations character_empty_slot = $Character/Panel/HBoxContainer/Collaborations/TextureButton.duplicate() $Character/Panel/HBoxContainer/Collaborations.remove_child($Character/Panel/HBoxContainer/Collaborations/TextureButton) var base_slot = character_empty_slot.duplicate() for idx in range(Global.collaboration_slots): var slot: TextureButton = base_slot.duplicate() slot.name = "Slot" + str(idx) if Global.selected_collaborations.has(idx): slot.modulate = Color(1, 1, 1, 1) slot.texture_normal = PlaceholderTexture2D.new() slot.texture_normal = load("res://.godot/imported/UsadaPekora_Full.png-de55b1ee87c19101262c28a2200b6697.ctex") $Character/Panel/HBoxContainer/Collaborations.add_child(slot) focused_tab_elements[1] = $Character/Panel/HBoxContainer/Collaborations.get_child(0) ## Set $Preview/$Collaboration to empty? to all? to first slot? ## TODO ### System ### func _ready_system(): AudioServer.set_bus_volume_db(self.audio_bus, linear_to_db(0)) $System/Panel/VBoxContainer2/SliderVolume.value = db_to_linear(AudioServer.get_bus_volume_db(self.audio_bus)) func _on_slider_volume_value_changed(value): AudioServer.set_bus_volume_db(self.audio_bus, linear_to_db(value)) func quit_game(): get_tree().quit() func _on_button_resume_pressed(): self.close_menu() func _on_button_quit_pressed(): self.quit_game()