47 lines
1.1 KiB
GDScript
47 lines
1.1 KiB
GDScript
@tool
|
|
extends Control
|
|
|
|
class_name GameMenuTab
|
|
|
|
signal on_tab_selected(index: int)
|
|
|
|
@export var bob_height: float = 100
|
|
@export var duration: float = 0.5
|
|
@export var index: int = 0
|
|
@export var image: Texture:
|
|
set(value):
|
|
image = value
|
|
if is_inside_tree() and has_node("%Texture"):
|
|
$%Texture.texture = image
|
|
|
|
@onready var texture: TextureRect = $%Texture
|
|
|
|
var is_selected: bool = false
|
|
var hover_tween: Tween
|
|
|
|
func _ready():
|
|
if image != null and has_node("%Texture"):
|
|
$%Texture.texture = image
|
|
|
|
func _on_gui_input(event: InputEvent) -> void:
|
|
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
|
on_tab_selected.emit(index)
|
|
|
|
func select():
|
|
is_selected = true
|
|
_move_up()
|
|
|
|
func deselect():
|
|
is_selected = false
|
|
_move_down()
|
|
|
|
func _move_up():
|
|
if hover_tween: hover_tween.kill()
|
|
hover_tween = create_tween()
|
|
hover_tween.tween_property(texture, "position:y", -bob_height, duration).set_trans(Tween.TRANS_SINE)
|
|
|
|
func _move_down():
|
|
if hover_tween: hover_tween.kill()
|
|
var exit_tween = create_tween()
|
|
exit_tween.tween_property(texture, "position:y", 0, duration).set_trans(Tween.TRANS_QUAD)
|