@@ -5,6 +5,10 @@ class_name UIPlaybacks extends UIPanel
55## Ui panel for controling scenes, with sliders and extra buttons
66
77
8+ ## Emitted when the visable colum count is changed
9+ signal columns_changed (columns : int )
10+
11+
812## The NewPlaybackRowComponent container for columns
913@export var _container : HBoxContainer
1014
@@ -15,16 +19,25 @@ class_name UIPlaybacks extends UIPanel
1519## Mode Enum
1620enum Mode {ASIGN , DELETE , EDIT }
1721
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+
1828
1929## The function group
2030var _trigger_block : TriggerBlock
2131
22- ## Default number of columns to show
23- var _default_columns : int = 10
24-
2532## All UI columns
2633var _columns : Dictionary [int , PlaybackColumn ]
2734
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+
2841## The current mode
2942var _mode : Mode = Mode .ASIGN
3043
@@ -39,20 +52,13 @@ var _trigger_block_connections: Dictionary[String, Callable] = {
3952
4053## Load Default Columns
4154func _ready () -> void :
55+ _set_class_name ("UIPlaybacks" )
4256 set_edit_mode_disabled (true )
4357
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 )
5662
5763
5864## Sets the trigger block
@@ -89,6 +95,34 @@ func set_mode(p_mode: Mode) -> void:
8995 column .set_mode (_mode )
9096
9197
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+
92126## Called when editmode state is changed
93127func _edit_mode_toggled (state : bool ) -> void :
94128 if not _trigger_block :
@@ -123,6 +157,41 @@ func _rename_trigger(row: int, column: int, name: String) -> void:
123157 _columns [column ].set_row_name (row , "" )
124158
125159
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+
126195## Called when a control is pressed when in Mode.EDIT
127196func _on_column_control_pressed_edit_mode (control : Control ) -> void :
128197 if control is Button :
@@ -137,13 +206,16 @@ func _on_object_picker_button_object_selected(object: EngineComponent) -> void:
137206
138207## Saves this into a dict
139208func _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+ }
144213
145214
146215## Loads this from a dict
147216func _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