-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathbinding.gd
84 lines (64 loc) · 1.94 KB
/
binding.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
static func create(obj: Object, var_name: String, control: Control) -> BindingBase:
if control is CheckBox:
return CheckBoxBinding.new(obj, var_name, control as CheckBox)
if control is Range:
return RangeBinding.new(obj, var_name, control as Range)
if control is OptionButton:
return OptionBinding.new(obj, var_name, control as OptionButton)
push_error("Cannot find binding type")
return null
class BindingBase:
var _var_name := ""
var _obj: Object
var _updating_ui := false
func update_ui():
push_error("Unimplemented")
class CheckBoxBinding extends BindingBase:
var _control : CheckBox
func _init(obj: Object, var_name: String, cb: CheckBox):
_var_name = var_name
_obj = obj
_control = cb
_control.toggled.connect(_on_gui_toggle)
func _on_gui_toggle(enabled: bool):
if _updating_ui:
return
_obj.set(_var_name, enabled)
func update_ui():
var v : bool = _obj.get(_var_name)
_updating_ui = true
_control.button_pressed = v
_updating_ui = false
class RangeBinding extends BindingBase:
var _control : Range
func _init(obj: Object, var_name: String, r: Range):
_var_name = var_name
_obj = obj
_control = r
_control.value_changed.connect(_on_range_value_changed)
func _on_range_value_changed(new_value: float):
if _updating_ui:
return
_obj.set(_var_name, new_value)
func update_ui():
var v : float = _obj.get(_var_name)
_updating_ui = true
_control.value = v
_updating_ui = false
class OptionBinding extends BindingBase:
var _control : OptionButton
func _init(obj: Object, var_name: String, ob: OptionButton):
_var_name = var_name
_obj = obj
_control = ob
_control.get_popup().id_pressed.connect(_on_gui_option_selected)
func _on_gui_option_selected(option: int):
if _updating_ui:
return
_obj.set(_var_name, option)
func update_ui():
var v : int = _obj.get(_var_name)
_updating_ui = true
var i := _control.get_item_index(v)
_control.select(i)
_updating_ui = false