This repository has been archived on 2024-07-02. You can view files and clone it, but cannot push or open issues or pull requests.
HoppyEaster/Scripts/UI/MenuButton.gd

38 lines
1 KiB
GDScript

extends TextureButton
@export var text : String = "Sample Text"
@export var pointer_margin_from_center : int = 100
@export var leftPointer : Sprite2D
@export var rightPointer : Sprite2D
@export var textBox : RichTextLabel
# Engine Callbacks
func _ready():
textBox.parse_bbcode("[center] %s [/center]" % [text])
pass
func _process(_delta):
handle_hover_and_focus()
handle_x_position()
func handle_hover_and_focus() -> void:
if has_focus():
leftPointer.visible = true
rightPointer.visible = true
elif is_hovered():
leftPointer.visible = true
leftPointer.modulate.a = 0.5
rightPointer.visible = true
rightPointer.modulate.a = 0.5
else:
leftPointer.visible = false
leftPointer.modulate.a = 1
rightPointer.visible = false
rightPointer.modulate.a = 1
pass
func handle_x_position() -> void:
var center_x = get_parent().position.x + (get_parent().size.x / 2.0)
leftPointer.global_position.x = center_x - pointer_margin_from_center
rightPointer.global_position.x = center_x + pointer_margin_from_center
pass