@@ -5,6 +5,10 @@ class_name UIPlaybacks extends UIPanel
5
5
## Ui panel for controling scenes, with sliders and extra buttons
6
6
7
7
8
+ ## Emitted when the visable colum count is changed
9
+ signal columns_changed (columns : int )
10
+
11
+
8
12
## The NewPlaybackRowComponent container for columns
9
13
@export var _container : HBoxContainer
10
14
@@ -15,16 +19,25 @@ class_name UIPlaybacks extends UIPanel
15
19
## Mode Enum
16
20
enum Mode {ASIGN , DELETE , EDIT }
17
21
22
+ ## Default number of columns to show
23
+ const _default_columns : int = 10
24
+
25
+ ## Dialog text for changeing column count
26
+ const _change_column_count_text : String = "Are you sure you want to change the column count to: $columns? This may be destructive."
27
+
18
28
19
29
## The function group
20
30
var _trigger_block : TriggerBlock
21
31
22
- ## Default number of columns to show
23
- var _default_columns : int = 10
24
-
25
32
## All UI columns
26
33
var _columns : Dictionary [int , PlaybackColumn ]
27
34
35
+ ## Flag for if columns have been loaded from _load()
36
+ var _columns_set_from_load : bool = false
37
+
38
+ ## Total number of columns to show, defaults to _default_columns
39
+ var _visable_columns : int = _default_columns
40
+
28
41
## The current mode
29
42
var _mode : Mode = Mode .ASIGN
30
43
@@ -39,20 +52,13 @@ var _trigger_block_connections: Dictionary[String, Callable] = {
39
52
40
53
## Load Default Columns
41
54
func _ready () -> void :
55
+ _set_class_name ("UIPlaybacks" )
42
56
set_edit_mode_disabled (true )
43
57
44
- for column : int in range (0 , _default_columns + 1 ):
45
- var new_column : PlaybackColumn = load ("res://components/PlaybackColumn/PlaybackColumn.tscn" ).instantiate ()
46
-
47
- new_column .set_column (column )
48
- new_column .control_pressed_edit_mode .connect (_on_column_control_pressed_edit_mode )
49
-
50
- _columns [column ] = new_column
51
- _container .add_child (new_column )
52
-
53
- for button : Button in new_column .get_buttons ():
54
- if button :
55
- buttons .append (button )
58
+ register_setting_int ("columns" , set_columns_ui , get_columns , columns_changed , 0 , 100 )
59
+
60
+ if not _columns_set_from_load :
61
+ _set_columns (_visable_columns )
56
62
57
63
58
64
## Sets the trigger block
@@ -89,6 +95,34 @@ func set_mode(p_mode: Mode) -> void:
89
95
column .set_mode (_mode )
90
96
91
97
98
+ ## Sets the number of columns to show
99
+ func set_columns (p_column : int ) -> bool :
100
+ if p_column == _visable_columns :
101
+ return false
102
+
103
+ _visable_columns = p_column
104
+ _set_columns (_visable_columns )
105
+ columns_changed .emit (_visable_columns )
106
+
107
+ return true
108
+
109
+
110
+ ## Sets the number of columns to show. But showing a confirmation dialog box first
111
+ func set_columns_ui (p_columns : int ) -> bool :
112
+ if p_columns == _visable_columns :
113
+ return false
114
+
115
+ Interface .show_confirmation_dialog (_change_column_count_text .replace ("$columns" , str (p_columns )), self ).then (func () -> void :
116
+ set_columns (p_columns )
117
+ )
118
+ return true
119
+
120
+
121
+ ## Gets the current number of columns
122
+ func get_columns () -> int :
123
+ return _visable_columns
124
+
125
+
92
126
## Called when editmode state is changed
93
127
func _edit_mode_toggled (state : bool ) -> void :
94
128
if not _trigger_block :
@@ -123,6 +157,41 @@ func _rename_trigger(row: int, column: int, name: String) -> void:
123
157
_columns [column ].set_row_name (row , "" )
124
158
125
159
160
+ ## Loads the default number of columns
161
+ func _set_columns (p_columns : int ) -> void :
162
+ if p_columns > _columns .size ():
163
+ for column : int in range (_columns .size (), p_columns ):
164
+ var new_column : PlaybackColumn = load ("res://components/PlaybackColumn/PlaybackColumn.tscn" ).instantiate ()
165
+
166
+ new_column .set_column (column )
167
+ new_column .set_trigger_block (_trigger_block )
168
+ new_column .set_edit_mode (_edit_mode )
169
+ new_column .set_mode (_mode )
170
+ new_column .control_pressed_edit_mode .connect (_on_column_control_pressed_edit_mode )
171
+
172
+ _columns [column ] = new_column
173
+ _container .add_child (new_column )
174
+
175
+ for button : Button in new_column .get_buttons ():
176
+ if button :
177
+ add_button (button )
178
+
179
+ elif p_columns < _columns .size ():
180
+ var columns : Dictionary [int , PlaybackColumn ] = _columns .duplicate ()
181
+
182
+ for column : int in range (p_columns , _columns .size ()):
183
+ var column_item : PlaybackColumn = columns [column ]
184
+ _columns .erase (column )
185
+
186
+ for button : Button in column_item .get_buttons ():
187
+ if button :
188
+ remove_all_button_actions (button )
189
+ remove_button (button )
190
+
191
+ _container .remove_child (column_item )
192
+ column_item .queue_free ()
193
+
194
+
126
195
## Called when a control is pressed when in Mode.EDIT
127
196
func _on_column_control_pressed_edit_mode (control : Control ) -> void :
128
197
if control is Button :
@@ -137,13 +206,16 @@ func _on_object_picker_button_object_selected(object: EngineComponent) -> void:
137
206
138
207
## Saves this into a dict
139
208
func _save () -> Dictionary :
140
- if _trigger_block :
141
- return { "uuid " : _trigger_block .uuid }
142
- else :
143
- return { }
209
+ return {
210
+ "trigger_block " : _trigger_block .uuid if _trigger_block else "" ,
211
+ "columns" : _visable_columns ,
212
+ }
144
213
145
214
146
215
## Loads this from a dict
147
216
func _load (saved_data : Dictionary ) -> void :
148
- if saved_data .get ("uuid" ) is String :
149
- _object_picker_button .look_for (saved_data .uuid )
217
+ _object_picker_button .look_for (type_convert (saved_data .get ("trigger_block" , "" ), TYPE_STRING ))
218
+ _visable_columns = type_convert (saved_data .get ("columns" , _visable_columns ), TYPE_INT )
219
+
220
+ _columns_set_from_load = true
221
+ _set_columns (_visable_columns )
0 commit comments