Skip to content

Commit db44097

Browse files
author
Liam Sherwin
committed
Updated UIPanel to extend UIBase for settings support
1 parent 72a7296 commit db44097

File tree

15 files changed

+346
-77
lines changed

15 files changed

+346
-77
lines changed

components/ClientComponentSettings/ClientComponentSettings.gd

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ class_name ClientComponentSettings extends PanelContainer
99
@export var _settings_module_container: VBoxContainer
1010

1111
## The current component
12-
var _component: ClientComponent = null
12+
var _component: Object = null
1313

1414

1515
## Sets the component
16-
func set_component(component: ClientComponent) -> void:
16+
func set_component(component: Object) -> void:
1717
for old_module: ClientClassSettingsModule in _settings_module_container.get_children():
1818
old_module.queue_free()
1919
_settings_module_container.remove_child(old_module)
2020

21+
if not (component is ClientComponent or component is UIBase):
22+
_component = null
23+
return
24+
2125
_component = component
2226
if not is_instance_valid(component):
2327
return

components/PlaybackColumn/PlaybackColumn.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func set_component(component: EngineComponent, no_remove: bool = false) -> void:
103103

104104
_set_disalbed(component == null)
105105
title_button.text = component.get_name()
106+
title_button.tooltip_text = component.get_name()
106107

107108
if not no_remove and _trigger_block:
108109
_trigger_block.reset_column(_column)
@@ -148,6 +149,7 @@ func set_row_name(row: int, p_name: String) -> void:
148149
## Resets this PlaybackColumn
149150
func reset() -> void:
150151
title_button.set_text("Empty")
152+
title_button.set_tooltip_text("")
151153
slider.set_editable(false)
152154
_component = null
153155

@@ -170,6 +172,7 @@ func _set_disalbed(disabled: bool) -> void:
170172
## Emitted when the component's name is changed
171173
func _on_component_name_changed(new_name: String) -> void:
172174
title_button.set_text(new_name)
175+
title_button.set_tooltip_text(new_name)
173176

174177

175178
## Called when the Title Button is pressed

components/UIPanel/EditControls.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ icon = ExtResource("1_x4jel")
3030

3131
[node name="Settings" type="Button" parent="HBoxContainer"]
3232
layout_mode = 2
33-
disabled = true
3433
icon = ExtResource("2_1xcge")
3534

3635
[node name="Close" type="Button" parent="HBoxContainer"]

core/components/containers/DataContainer.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func _store_item(p_item: ContainerItem, no_signal: bool = false) -> bool:
128128
_items.append(p_item)
129129
_fixture.get_or_add(p_item.get_fixture(), {}).get_or_add(p_item.get_zone(), {})[p_item.get_parameter()] = p_item
130130

131-
#ComponentDB.register_component(p_item)
131+
ComponentDB.register_component(p_item)
132132
p_item.delete_requested.connect(_erase_item.bind(p_item))
133133

134134
if not no_signal:
@@ -157,7 +157,7 @@ func _erase_item(p_item: ContainerItem, no_signal: bool = false) -> bool:
157157

158158
_items.erase(p_item)
159159
_fixture[p_item.get_fixture()][p_item.get_zone()].erase(p_item.get_parameter())
160-
160+
161161
if not no_signal:
162162
items_erased.emit([p_item])
163163

core/global/ComponentDB.gd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ func get_component(uuid: String) -> EngineComponent:
9595

9696

9797
## Use this method if you need to call a function once a component is added to the engine. This will only be called once
98-
func request_component(uuid: String, callback) -> void:
98+
func request_component(uuid: String, callback: Callable) -> void:
99+
if not uuid:
100+
return
101+
99102
if uuid in components:
100103
callback.call(components[uuid])
101104

panels/ComponentControlMethodPicker/ComponentControlMethodPicker.gd

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,19 @@ func set_component(component: EngineComponent) -> void:
3333
_list.add_item(control_name)
3434

3535

36-
## Called when the confirm button is pressed
37-
func _on_confirm_pressed() -> void:
36+
## Confirms the current selection
37+
func _confirm_selection() -> void:
3838
var selected: int = _list.get_selected_items()[0]
3939
var control_name: String = _controls.keys()[selected - 1] if selected else ""
4040

4141
method_chosen.emit(control_name)
42+
43+
44+
## Called when the confirm button is pressed
45+
func _on_confirm_pressed() -> void:
46+
_confirm_selection()
47+
48+
49+
## Called when an item is dubble clicked in the tree
50+
func _on_list_item_activated(index: int) -> void:
51+
_confirm_selection()

panels/ComponentControlMethodPicker/ComponentControlMethodPicker.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ size_flags_horizontal = 3
7575
text = "Confirm"
7676
icon = ExtResource("5_uhjji")
7777

78+
[connection signal="item_activated" from="VBoxContainer/HBoxContainer/PanelContainer/VBoxContainer/List" to="." method="_on_list_item_activated"]
7879
[connection signal="pressed" from="VBoxContainer/PanelContainer/HBoxContainer/Confirm" to="." method="_on_confirm_pressed"]

panels/Playbacks/Playbacks.gd

Lines changed: 93 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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
1620
enum 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
2030
var _trigger_block: TriggerBlock
2131

22-
## Default number of columns to show
23-
var _default_columns: int = 10
24-
2532
## All UI columns
2633
var _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
2942
var _mode: Mode = Mode.ASIGN
3043

@@ -39,20 +52,13 @@ var _trigger_block_connections: Dictionary[String, Callable] = {
3952

4053
## Load Default Columns
4154
func _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
93127
func _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
127196
func _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
139208
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+
}
144213

145214

146215
## Loads this from a dict
147216
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)

panels/Playbacks/Playbacks.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ icon = ExtResource("8_5st74")
8080

8181
[node name="EditControls" parent="VBoxContainer/PanelContainer3/HBoxContainer" instance=ExtResource("6_ms2qx")]
8282
layout_mode = 2
83-
show_settings = false
8483

8584
[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer"]
8685
layout_mode = 2

panels/UIPanelSettings/Shortcuts.gd

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ func set_panel(panel: UIPanel) -> void:
4848

4949
## Sets the current button
5050
func set_buton(button: Button) -> void:
51+
if not _button_items.has_left(button):
52+
return
53+
54+
var button_item: TreeItem = _button_items.left(button)
55+
button_item.select(0)
56+
_button_tree.scroll_to_item(button_item)
57+
5158
_selected_button = button
5259
_add_action_button.set_disabled(false)
5360

@@ -62,7 +69,7 @@ func set_buton(button: Button) -> void:
6269

6370
## Loads and displays all buttons from the UIPanel
6471
func _load_buttons() -> void:
65-
for button in _panel.buttons:
72+
for button in _panel.get_buttons():
6673
var item: TreeItem = _button_tree.create_item()
6774

6875
item.set_text(0, button.get_name())

0 commit comments

Comments
 (0)