1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Change the selected UI layout every time it changes

This way, Pixelorama remembers the changes users make to the UI, without them having to go to Window, Manage Layouts and clicking on Edit, which was an unintuitive and slow way. Needs testing because bugs may linger.

This commit also adds a new `save_on_change` variable and a `save` method on layout.gd of the dockable_container plugin. Perhaps I should also add this upstream as well.

I also need to add a way to create new layouts based off the default ones (which are permanently stored within Pixelorama's pck file and cannot be modified), so users will always have the option to resort to the default layouts.
This commit is contained in:
Emmanouil Papadeas 2024-02-02 02:31:29 +02:00
parent da0066259e
commit 534a7fd356
9 changed files with 35 additions and 9 deletions

View file

@ -24,7 +24,7 @@ Files extracted from source:
## godot-dockable-container ## godot-dockable-container
- Upstream: https://github.com/gilzoide/godot-dockable-container - Upstream: https://github.com/gilzoide/godot-dockable-container
- Version: [274ea7264440003071bcd024f31e130c984df3c6](https://github.com/gilzoide/godot-dockable-container/pull/27/commits/274ea7264440003071bcd024f31e130c984df3c6) (PR #27) - Version: Based on [274ea7264440003071bcd024f31e130c984df3c6](https://github.com/gilzoide/godot-dockable-container/pull/27/commits/274ea7264440003071bcd024f31e130c984df3c6) (PR #27), but with changes in layout.gd that add a `save_on_change` variable and a `save()` method.
- License: [CC0-1.0](https://github.com/gilzoide/godot-dockable-container/blob/main/LICENSE) - License: [CC0-1.0](https://github.com/gilzoide/godot-dockable-container/blob/main/LICENSE)
## SmartSlicer ## SmartSlicer

View file

@ -23,6 +23,15 @@ enum { MARGIN_LEFT, MARGIN_RIGHT, MARGIN_TOP, MARGIN_BOTTOM, MARGIN_CENTER }
if value != _hidden_tabs: if value != _hidden_tabs:
_hidden_tabs = value _hidden_tabs = value
changed.emit() changed.emit()
@export var save_on_change := false:
set(value):
save_on_change = value
if value:
if not changed.is_connected(save):
changed.connect(save)
else:
if changed.is_connected(save):
changed.disconnect(save)
var _changed_signal_queued := false var _changed_signal_queued := false
var _first_leaf: DockableLayoutPanel var _first_leaf: DockableLayoutPanel
@ -61,6 +70,12 @@ func get_names() -> PackedStringArray:
return _root.get_names() return _root.get_names()
func save(path := resource_path) -> void:
if path.is_empty():
return
ResourceSaver.save(self, path)
## Add missing nodes on first leaf and remove nodes outside indices from leaves. ## Add missing nodes on first leaf and remove nodes outside indices from leaves.
## ##
## _leaf_by_node_name = { ## _leaf_by_node_name = {

View file

@ -165,7 +165,7 @@ first = SubResource("Resource_atmme")
second = SubResource("Resource_2qk0j") second = SubResource("Resource_2qk0j")
[resource] [resource]
resource_name = "Layout" resource_name = "Default"
script = ExtResource("3_bjjec") script = ExtResource("3_bjjec")
root = SubResource("Resource_msuil") root = SubResource("Resource_msuil")
hidden_tabs = { hidden_tabs = {
@ -176,3 +176,4 @@ hidden_tabs = {
"Reference Images": true, "Reference Images": true,
"Second Canvas": true "Second Canvas": true
} }
save_on_change = false

View file

@ -137,7 +137,7 @@ first = SubResource("Resource_otntk")
second = SubResource("Resource_1xpva") second = SubResource("Resource_1xpva")
[resource] [resource]
resource_name = "Layout" resource_name = "Tallscreen"
script = ExtResource("3_ox7l5") script = ExtResource("3_ox7l5")
root = SubResource("Resource_6dytr") root = SubResource("Resource_6dytr")
hidden_tabs = { hidden_tabs = {
@ -145,3 +145,4 @@ hidden_tabs = {
"Recorder": true, "Recorder": true,
"Second Canvas": true "Second Canvas": true
} }
save_on_change = false

View file

@ -105,13 +105,14 @@ func _handle_layout_files() -> void:
if files.size() == 0: if files.size() == 0:
for layout in Global.default_layouts: for layout in Global.default_layouts:
var file_name := layout.resource_path.get_basename().get_file() + ".tres" var file_name := layout.resource_path.get_basename().get_file() + ".tres"
print(Global.LAYOUT_DIR.path_join(file_name))
ResourceSaver.save(layout, Global.LAYOUT_DIR.path_join(file_name)) ResourceSaver.save(layout, Global.LAYOUT_DIR.path_join(file_name))
files = dir.get_files() files = dir.get_files()
for file in files: for file in files:
var layout := ResourceLoader.load(Global.LAYOUT_DIR.path_join(file)) var layout := ResourceLoader.load(Global.LAYOUT_DIR.path_join(file))
if layout is DockableLayout: if layout is DockableLayout:
Global.layouts.append(layout) Global.layouts.append(layout)
# Save the layout every time it changes
layout.save_on_change = true
func _setup_application_window_size() -> void: func _setup_application_window_size() -> void:

View file

@ -63,8 +63,10 @@ func _on_DeleteLayout_pressed() -> void:
func _on_LayoutSettings_confirmed() -> void: func _on_LayoutSettings_confirmed() -> void:
var file_name := layout_name.text + ".tres" var file_name := layout_name.text + ".tres"
var path := "user://layouts/".path_join(file_name) var path := Global.LAYOUT_DIR.path_join(file_name)
var layout: DockableLayout = Global.control.main_ui.layout var layout: DockableLayout = Global.control.main_ui.layout.clone()
layout.resource_name = layout_name.text
layout.resource_path = path
var err := ResourceSaver.save(layout, path) var err := ResourceSaver.save(layout, path)
if err != OK: if err != OK:
print(err) print(err)
@ -80,6 +82,9 @@ func _on_LayoutSettings_confirmed() -> void:
) )
else: else:
Global.layouts.append(layout) Global.layouts.append(layout)
# Save the layout every time it changes
layout.save_on_change = true
Global.control.main_ui.layout = layout
layout_list.add_item(layout_name.text) layout_list.add_item(layout_name.text)
Global.top_menu_container.populate_layouts_submenu() Global.top_menu_container.populate_layouts_submenu()
var n: int = Global.top_menu_container.layouts_submenu.get_item_count() var n: int = Global.top_menu_container.layouts_submenu.get_item_count()
@ -87,10 +92,10 @@ func _on_LayoutSettings_confirmed() -> void:
func delete_layout_file(file_name: String) -> void: func delete_layout_file(file_name: String) -> void:
var dir := DirAccess.open("user://layouts/") var dir := DirAccess.open(Global.LAYOUT_DIR)
if not is_instance_valid(dir): if not is_instance_valid(dir):
return return
dir.remove("user://layouts/".path_join(file_name)) dir.remove(Global.LAYOUT_DIR.path_join(file_name))
func _on_DeleteConfirmation_confirmed() -> void: func _on_DeleteConfirmation_confirmed() -> void:

View file

@ -16,6 +16,7 @@ resource_name = "Layout"
script = ExtResource("3") script = ExtResource("3")
root = SubResource("1") root = SubResource("1")
hidden_tabs = {} hidden_tabs = {}
save_on_change = false
[node name="ManageLayouts" type="AcceptDialog"] [node name="ManageLayouts" type="AcceptDialog"]
title = "Manage Layouts" title = "Manage Layouts"

View file

@ -555,7 +555,7 @@ func set_layout(id: int) -> void:
if id >= Global.layouts.size(): if id >= Global.layouts.size():
id = 0 id = 0
selected_layout = id selected_layout = id
main_ui.layout = Global.layouts[id].clone() main_ui.layout = Global.layouts[id]
for i in Global.layouts.size(): for i in Global.layouts.size():
var offset := i + 1 var offset := i + 1
layouts_submenu.set_item_checked(offset, offset == (id + 1)) layouts_submenu.set_item_checked(offset, offset == (id + 1))

View file

@ -204,6 +204,7 @@ hidden_tabs = {
"Recorder": true, "Recorder": true,
"Second Canvas": true "Second Canvas": true
} }
save_on_change = false
[sub_resource type="ShaderMaterial" id="2"] [sub_resource type="ShaderMaterial" id="2"]
shader = ExtResource("9") shader = ExtResource("9")
@ -253,6 +254,7 @@ script = ExtResource("35")
tabs_visible = false tabs_visible = false
tabs_visible_if_more_than_one = true tabs_visible_if_more_than_one = true
layout = SubResource("Resource_b6o2t") layout = SubResource("Resource_b6o2t")
clone_layout_on_ready = false
[node name="Tools" parent="DockableContainer" instance=ExtResource("1")] [node name="Tools" parent="DockableContainer" instance=ExtResource("1")]
layout_mode = 2 layout_mode = 2