OK I finally got it working
BUT I feel like it gotta be easier way. Here's what I did:
My child tree:
-Panel
--TextureButton
My basic steps:
-Add_child to gridContainer
-Create ID for each child
-Create function to change texture_normal.jpg based on ID
-When pressed, it first resets every child to normal texture.jpg (via a chain of 2 signals)
-Then the function to change texture_normal kicks in.
gridContainer:
extends GridContainer
@onready var item = preload("res://Slot.tscn")
@onready var _normal = preload("res://icon.jpg")
var inventorySize = 3
func _ready():
for i in inventorySize:
var itemTemp = item.instantiate()
add_child(itemTemp)
itemTemp.name = "itemTemp" + str(i)
itemTemp.gui_input.connect(self.reset_texture)
func reset_texture():
for i in get_children():
i.get_node("Icon").texture_normal = _normal
TextureButton:
extends TextureButton
signal gui
@onready var _pressed = preload("res://icon1.jpg")
func _on_pressed():
emit_signal("gui")
if get_parent().name == "itemTemp0":
texture_normal = _pressed
elif get_parent().name == "itemTemp1":
texture_normal = _pressed
elif get_parent().name == "itemTemp2":
texture_normal = _pressed
Panel:
extends Panel
func _ready():
$Icon.gui.connect(self.emitsig)
func emitsig():
emit_signal("gui_input")
Anyone knows a better way to do this? 😆
ps. I use changing texture_normal.jpg since I read you can't change the button states of TextureButton(?)