52 lines
1.4 KiB
GDScript
52 lines
1.4 KiB
GDScript
extends Control
|
|
|
|
@export var border_size:int = 1
|
|
|
|
@export var font: Font
|
|
@export var text: String = ""
|
|
@export var text_size:int = 8
|
|
|
|
signal clicked
|
|
|
|
var background: ColorRect
|
|
var hoverColor: ColorRect
|
|
var textLabel: Label
|
|
func _ready():
|
|
hoverColor = $HoverColor
|
|
hoverColor.visible = false
|
|
background = $BackingBorder/Background
|
|
textLabel = $Text
|
|
|
|
textLabel.text = text
|
|
textLabel.add_theme_font_override("font", font)
|
|
textLabel.add_theme_font_size_override("font_size", int(text_size * Global.menuScale))
|
|
|
|
setupSize.call_deferred()
|
|
|
|
func setupSize():
|
|
background.position.x = border_size
|
|
background.position.y = border_size
|
|
background.size.x = background.size.x - border_size * 2
|
|
background.size.y = background.size.y - border_size * 2
|
|
|
|
func _on_resized() -> void:
|
|
gotResized.call_deferred()
|
|
|
|
func gotResized():
|
|
textLabel.add_theme_font_size_override("font_size", int(text_size * Global.menuScale))
|
|
|
|
func _on_hit_area_mouse_entered() -> void:
|
|
hoverColor.visible = true
|
|
|
|
func _on_hit_area_mouse_exited() -> void:
|
|
hoverColor.visible = false
|
|
|
|
var pressedLastEvent = false
|
|
func _on_hit_area_gui_input(event: InputEvent) -> void:
|
|
if event is InputEventMouseButton:
|
|
if event.button_index == 1 and event.pressed and not pressedLastEvent:
|
|
pressedLastEvent = true
|
|
Global.clickSound.play()
|
|
clicked.emit()
|
|
elif not event.pressed and pressedLastEvent:
|
|
pressedLastEvent = false
|