Implement button index support for the in-game menu buttons.

This commit is contained in:
Relintai 2020-10-19 13:09:08 +02:00
parent 901c275912
commit 9a07052455
2 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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