From 9a070524559048b9efbb0eb8f81911a1a4bd4a9a Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 19 Oct 2020 13:09:08 +0200 Subject: [PATCH] Implement button index support for the in-game menu buttons. --- game/scripts/game_modules/ui_window_module.gd | 2 +- game/ui/buttons/Buttons.gd | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/game/scripts/game_modules/ui_window_module.gd b/game/scripts/game_modules/ui_window_module.gd index 7272dadf..43a7e66a 100644 --- a/game/scripts/game_modules/ui_window_module.gd +++ b/game/scripts/game_modules/ui_window_module.gd @@ -13,7 +13,7 @@ func on_request_instance(what : int, node : Node) -> void: node.windows.add_child(sc) if add_button: - var b = node.buttons.add_image_button(opener_button_texture, 0) + var b = node.buttons.add_image_button(opener_button_texture, index) b.connect("toggled", sc, "_on_button_toggled") sc.opener_button = b diff --git a/game/ui/buttons/Buttons.gd b/game/ui/buttons/Buttons.gd index d0dc4e70..f69ae563 100644 --- a/game/ui/buttons/Buttons.gd +++ b/game/ui/buttons/Buttons.gd @@ -39,12 +39,20 @@ func _ready(): func add_image_button(texture : Texture, index : int = -1) -> Button: var button : Button = image_button.instance() as Button + button.set_meta("button_index", index) + button.get_child(0).texture = texture add_child(button) - if index != -1: - move_child(button, index) + for ch in get_children(): + var button_index : int = get_child_count() + + if ch.has_meta("button_index"): + button_index = ch.get_meta("button_index") + + if button_index != -1: + move_child(ch, button_index) return button