diff options
| author | metamuffin <metamuffin@disroot.org> | 2025-12-07 16:23:32 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2025-12-07 16:30:27 +0100 |
| commit | 6310495c850a3c759fe994660eb945bfddfd39b1 (patch) | |
| tree | 0d1dba34ef91eadb2432817d6bc5c6aad9c01cf0 /client | |
| parent | d5c8ed97c7f3510ab90c3f9bd4042d70175cacfb (diff) | |
| download | hurrycurry-6310495c850a3c759fe994660eb945bfddfd39b1.tar hurrycurry-6310495c850a3c759fe994660eb945bfddfd39b1.tar.bz2 hurrycurry-6310495c850a3c759fe994660eb945bfddfd39b1.tar.zst | |
Fix updating inconsistent button disable in lobby overlay + bot reset button toggles on/off
Diffstat (limited to 'client')
| -rw-r--r-- | client/global.gd | 4 | ||||
| -rw-r--r-- | client/gui/menus/menu.gd | 37 | ||||
| -rw-r--r-- | client/gui/overlays/lobby/lobby.gd | 12 |
3 files changed, 34 insertions, 19 deletions
diff --git a/client/global.gd b/client/global.gd index 123f55de..91696d34 100644 --- a/client/global.gd +++ b/client/global.gd @@ -110,10 +110,6 @@ static func angle_closest_quarter(current, target) -> float: else: target -= PI / 2 return target -func find_menu(node: Node) -> Menu: - if node is Menu: return node - else: return find_menu(node.get_parent()) - func language_list(): var a = TranslationServer.get_loaded_locales() a.sort() diff --git a/client/gui/menus/menu.gd b/client/gui/menus/menu.gd index 00edd272..ddf16395 100644 --- a/client/gui/menus/menu.gd +++ b/client/gui/menus/menu.gd @@ -32,6 +32,7 @@ var parent_menu: Menu = null var previous_path = null # : String var open_since = 0 var exiting := false +var disabled := false func _ready(): open_since = Time.get_ticks_msec() @@ -62,7 +63,7 @@ var covered := false func submenu(path: String, data_ = null): var prev_focus = Global.focused_node if popup != null: return - _disable_recursive(self, true) + disabled = true; _update_disabled(self) covered = true await _menu_cover(true) popup = load(path).instantiate() @@ -75,19 +76,29 @@ func submenu(path: String, data_ = null): await _menu_cover(false) Global.focused_menu = self _menu_music() - _disable_recursive(self, false) + disabled = false; _update_disabled(self) if prev_focus != null: prev_focus.grab_focus() -func _disable_recursive(node: Node, state: bool): - if node is BaseButton: - var was_disabled: bool = state and node.disabled - if was_disabled: node.add_to_group("was_disabled") - node.disabled = state or node.is_in_group("was_disabled") - if not was_disabled: node.remove_from_group("was_disabled") - for c in node.get_children(): _disable_recursive(c, state) +func _update_disabled(node: Node): + if node is BaseButton: _update_button_disabled(node) + for c in node.get_children(): _update_disabled(c) + +func _update_button_disabled(node: BaseButton): + if disabled: + if node.disabled: node.add_to_group("disabled") + else: node.remove_from_group("disabled") + node.disabled = true + else: + node.disabled = node.is_in_group("disabled") + node.remove_from_group("disabled") + +func set_disabled(node: BaseButton, state: bool): + if state: node.add_to_group("disabled") + else: node.remove_from_group("disabled") + node.disabled = state or disabled func exit(): - _disable_recursive(self, true) + disabled = true; _update_disabled(self) if transition and transition.fading: push_error("menu exit() called twice") return @@ -108,7 +119,7 @@ func replace_menu(path: String, data_ = null, prev_path = null): # prev_path: St print("Replace menu: ", path) exiting = true if popup != null: await popup.exit() - _disable_recursive(self, true) + disabled = true; _update_disabled(self) await _menu_exit() var new_menu: Menu = load(path).instantiate() new_menu.data = data_ @@ -163,3 +174,7 @@ func exit_maybe() -> void: if time - open_since < 100: return Sound.play_click() exit() + +static func get_parent_menu(node: Node) -> Menu: + if node is Menu: return node + else: return Menu.get_parent_menu(node.get_parent()) diff --git a/client/gui/overlays/lobby/lobby.gd b/client/gui/overlays/lobby/lobby.gd index 954ae069..e632a1e7 100644 --- a/client/gui/overlays/lobby/lobby.gd +++ b/client/gui/overlays/lobby/lobby.gd @@ -30,6 +30,7 @@ var bot_inc_buttons := {} var bot_dec_buttons := {} @onready var game: Game = $"../../Game" # TODO +@onready var game_menu: Menu = Menu.get_parent_menu(self) @onready var player_container = $PlayerList/VBoxContainer/Players @onready var map_name_label = $Sidebar/Bottom/MarginContainer/VBoxContainer/HBoxContainer/Map/Name @@ -67,6 +68,7 @@ func initialize(): b.text = "%s (%d)" % [m[1]["name"], m[1]["players"]] b.pressed.connect(select_map.bind(i)) b.focus_entered.connect(select_map.bind(i)) + game_menu.set_disabled(b, false) map_list_container.add_child(b) i += 1 select_map(0) @@ -96,7 +98,7 @@ func initialize(): h.add_child(reset) h.add_child(add) bot_settings.add_child(h) - + func select_map(i: int): if i >= map_count: return @@ -118,14 +120,16 @@ func decrease_bot_count(algo_id: String): update_bot_reset_text(algo_id) func reset_bot_count(algo_id: String): - bot_counts[algo_id] = 0 + if bot_counts[algo_id] == 0: bot_counts[algo_id] = 1 + else: bot_counts[algo_id] = 0 update_bot_reset_text(algo_id) func update_bot_reset_text(algo_id: String): var display_name: String = tr("s.bot.%s" % algo_id) bot_reset_buttons[algo_id].text = "%s (%d)" % [display_name, bot_counts[algo_id]] - bot_inc_buttons[algo_id].disabled = not bot_counts[algo_id] < MAX_BOT_COUNT_PER_TYPE - bot_dec_buttons[algo_id].disabled = not bot_counts[algo_id] > 0 + game_menu.set_disabled(bot_reset_buttons[algo_id], false) + game_menu.set_disabled(bot_inc_buttons[algo_id], not bot_counts[algo_id] < MAX_BOT_COUNT_PER_TYPE) + game_menu.set_disabled(bot_dec_buttons[algo_id], not bot_counts[algo_id] > 0) func update_players(player_list: Dictionary): for i in player_container.get_children(): |