summaryrefslogtreecommitdiff
path: root/ui/mobile/button.gd
blob: 2e3653cea1ae4aa25ce43536c23a3e08e04a38e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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)