-
Notifications
You must be signed in to change notification settings - Fork 10
/
Slider.gd
39 lines (31 loc) · 886 Bytes
/
Slider.gd
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
tool
extends HBoxContainer
signal value_changed(value)
export(String) var text = "Slider" setget set_text
export(float) var min_value = 0 setget set_min_value
export(float) var max_value = 1 setget set_max_value
export(float) var value = 0 setget set_value
func _ready():
set_text(text)
set_min_value(min_value)
set_max_value(max_value)
set_value(value)
func set_text(string):
text = string
if has_node("Name"):
$Name.text = text + ": "
func set_value(val):
value = val
if has_node("HSlider"):
$HSlider.value = value
func set_min_value(val):
min_value = min(val, max_value)
if has_node("HSlider"):
$HSlider.min_value = min_value
func set_max_value(val):
max_value = max(val, min_value)
if has_node("HSlider"):
$HSlider.max_value = max_value
func _on_HSlider_value_changed(value):
emit_signal("value_changed", value)
$Value.text = str(stepify(value, 0.01))