diff options
Diffstat (limited to 'ui/mobile/button.gd')
-rw-r--r-- | ui/mobile/button.gd | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/ui/mobile/button.gd b/ui/mobile/button.gd new file mode 100644 index 0000000..2e3653c --- /dev/null +++ b/ui/mobile/button.gd @@ -0,0 +1,45 @@ +@tool +extends Panel + + +@export var texture: Texture2D: + set(value): + texture = value + $TouchScreenButton.texture_normal = value + _on_resized() + +@export var label: String: + set(value): + label = value + $Label.text = value + +@export var action: StringName = "": + set(value): + action = value + $TouchScreenButton.action = value + + +func _ready() -> void: + _on_resized() + + +func _on_resized() -> void: + $TouchScreenButton.shape.size = size + + var texture_size := Vector2.ZERO + if texture: + texture_size = texture.get_size() + + $TouchScreenButton.position = Vector2( + (size.x - texture_size.x) / 2, + (size.y - texture_size.y) / 2 + ) + + $Label.size = size + + +func _on_touch_screen_button_pressed() -> void: + modulate = Color(0.5, 0.5, 0.5, 1.0) + +func _on_touch_screen_button_released() -> void: + modulate = Color(1.0, 1.0, 1.0, 1.0) |