add game menu
This commit was merged in pull request #19.
This commit is contained in:
50
core/game_menu/game_menu_tab.gd
Normal file
50
core/game_menu/game_menu_tab.gd
Normal file
@@ -0,0 +1,50 @@
|
||||
@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 select_without_animation():
|
||||
is_selected = true
|
||||
texture.position.y = -bob_height
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user