summaryrefslogtreecommitdiff
path: root/ui/mobile/button.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-12-28 15:08:23 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-12-28 15:08:23 +0100
commit474ef692613f298ab05bbb65ad85625f178b63cc (patch)
treed069e587c8d731ea8191ee0318abc85694c04351 /ui/mobile/button.gd
parentd572bc0a27b05c6632ba76bd630c7c4fd8f0ae5d (diff)
next commit
Diffstat (limited to 'ui/mobile/button.gd')
-rw-r--r--ui/mobile/button.gd45
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)