@tool

extends PanelContainer


@export var texture_state0: Texture2D:
    set(val):
        texture_state0 = val
        if is_inside_tree():
            $state.set_texture(val)


@export var texture_state1: Texture2D:
    set(val):
        texture_state1 = val
        if is_inside_tree():
            $state.set_texture(val)


@export var text: String = '':
    set(val):
        text = val
        if is_inside_tree():
            $button.set_text(val)
    get: return $button.get_text()


@export var pressed: bool = false:
    set(val):
        pressed = val
        if is_inside_tree():
            $button.set_pressed(val)
    get: return $button.is_pressed()


@export var toggle_mode: bool = false:
    set(val):
        if is_inside_tree():
            $button.set_toggle_mode(val)
    get: return $button.is_toggle_mode()


func _enter_tree() -> void:
    var tst = texture_state1 if $button.pressed else texture_state0
    $state.set_texture(tst)
    $button.set_text(text)
    $button.set_pressed(pressed)
    $button.set_toggle_mode(toggle_mode)


func set_text        (val: String): $button.set_text(val)
func set_pressed     (val: bool):   $button.set_pressed(val)


func set_toggle_mode (val: bool):
    if is_inside_tree():
        $button.set_toggle_mode(val)


func get_text():       return $button.get_text()
func is_pressed():     return $button.is_pressed()
func is_toggle_mode(): return $button.is_toggle_mode()


func _on_button_toggled(val: bool):
    if val: $state.set_texture(texture_state1)
    else:   $state.set_texture(texture_state0)


func button_connect(button_signal: String, proc: Callable):
    $button.connect(button_signal, proc)


func _on_button_mouse_entered():
    emit_signal('mouse_entered')
