mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-20 12:33:14 +00:00
Lazy load the preferences dialog
Speeds up the initial loading time of Pixelorama. It's now almost as fast as 0.x on my computer (a bit more than 2 seconds). Lazy loading the preferences dialog also drastically reduces memory usage and node count (when preferences have not been opened), from 150MB, 13634 objects and 3680 nodes, to 94MB, 8207 objects and 1823 nodes. This essentially cuts the initial node count to half!
This commit is contained in:
parent
8c9a01feae
commit
b620cf2a9e
4 changed files with 148 additions and 93 deletions
|
@ -629,8 +629,6 @@ var cel_button_scene: PackedScene = load("res://src/UI/Timeline/CelButton.tscn")
|
|||
@onready var save_sprites_dialog: FileDialog = control.find_child("SaveSprite")
|
||||
## Dialog used to export images. It has the [param ExportDialog.gd] script attached.
|
||||
@onready var export_dialog: AcceptDialog = control.find_child("ExportDialog")
|
||||
## The preferences dialog. It has the [param PreferencesDialog.gd] script attached.
|
||||
@onready var preferences_dialog: AcceptDialog = control.find_child("PreferencesDialog")
|
||||
## An error dialog to show errors.
|
||||
@onready var error_dialog: AcceptDialog = control.find_child("ErrorDialog")
|
||||
|
||||
|
@ -680,6 +678,12 @@ func _ready() -> void:
|
|||
|
||||
await get_tree().process_frame
|
||||
project_switched.emit()
|
||||
# Load preferences from the config file
|
||||
for pref in config_cache.get_section_keys("preferences"):
|
||||
if get(pref) == null:
|
||||
continue
|
||||
var value = config_cache.get_value("preferences", pref)
|
||||
set(pref, value)
|
||||
|
||||
|
||||
func _initialize_keychain() -> void:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=16 format=3 uid="uid://dbylw5k04ulp8"]
|
||||
[gd_scene load_steps=15 format=3 uid="uid://dbylw5k04ulp8"]
|
||||
|
||||
[ext_resource type="Theme" uid="uid://cngbvfpwjoimv" path="res://assets/themes/dark/theme.tres" id="1"]
|
||||
[ext_resource type="Script" path="res://src/Main.gd" id="2"]
|
||||
|
@ -13,7 +13,6 @@
|
|||
[ext_resource type="PackedScene" uid="uid://c0nuukjakmai2" path="res://src/UI/Dialogs/TileModeOffsetsDialog.tscn" id="14"]
|
||||
[ext_resource type="Script" path="res://src/HandleExtensions.gd" id="15_v0k2h"]
|
||||
[ext_resource type="PackedScene" uid="uid://clbjfkdupw52l" path="res://src/UI/Timeline/CelProperties.tscn" id="17_ucs64"]
|
||||
[ext_resource type="PackedScene" uid="uid://b3hkjj3s6pe4x" path="res://src/Preferences/PreferencesDialog.tscn" id="32"]
|
||||
[ext_resource type="PackedScene" uid="uid://clgu8wb5o6oup" path="res://src/UI/Dialogs/ExportDialog.tscn" id="39"]
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
|
@ -54,8 +53,6 @@ mouse_filter = 2
|
|||
|
||||
[node name="ExportDialog" parent="Dialogs" instance=ExtResource("39")]
|
||||
|
||||
[node name="PreferencesDialog" parent="Dialogs" instance=ExtResource("32")]
|
||||
|
||||
[node name="UnsavedCanvasDialog" type="ConfirmationDialog" parent="Dialogs"]
|
||||
title = "Unsaved Image"
|
||||
exclusive = false
|
||||
|
|
|
@ -2,17 +2,22 @@ extends AcceptDialog
|
|||
|
||||
var preferences: Array[Preference] = [
|
||||
Preference.new(
|
||||
"open_last_project", "Startup/StartupContainer/OpenLastProject", "button_pressed"
|
||||
"open_last_project", "Startup/StartupContainer/OpenLastProject", "button_pressed", false
|
||||
),
|
||||
Preference.new(
|
||||
"quit_confirmation", "Startup/StartupContainer/QuitConfirmation", "button_pressed"
|
||||
"quit_confirmation", "Startup/StartupContainer/QuitConfirmation", "button_pressed", false
|
||||
),
|
||||
Preference.new("ffmpeg_path", "Startup/StartupContainer/FFMPEGPath", "text"),
|
||||
Preference.new("shrink", "%ShrinkSlider", "value"),
|
||||
Preference.new("font_size", "Interface/InterfaceOptions/FontSizeSlider", "value"),
|
||||
Preference.new("dim_on_popup", "Interface/InterfaceOptions/DimCheckBox", "button_pressed"),
|
||||
Preference.new("ffmpeg_path", "Startup/StartupContainer/FFMPEGPath", "text", ""),
|
||||
Preference.new("shrink", "%ShrinkSlider", "value", 1.0),
|
||||
Preference.new("font_size", "Interface/InterfaceOptions/FontSizeSlider", "value", 16),
|
||||
Preference.new(
|
||||
"use_native_file_dialogs", "Interface/InterfaceOptions/NativeFileDialogs", "button_pressed"
|
||||
"dim_on_popup", "Interface/InterfaceOptions/DimCheckBox", "button_pressed", true
|
||||
),
|
||||
Preference.new(
|
||||
"use_native_file_dialogs",
|
||||
"Interface/InterfaceOptions/NativeFileDialogs",
|
||||
"button_pressed",
|
||||
false
|
||||
),
|
||||
Preference.new(
|
||||
"single_window_mode",
|
||||
|
@ -21,97 +26,166 @@ var preferences: Array[Preference] = [
|
|||
true,
|
||||
true
|
||||
),
|
||||
Preference.new("icon_color_from", "Interface/ButtonOptions/IconColorOptionButton", "selected"),
|
||||
Preference.new("custom_icon_color", "Interface/ButtonOptions/IconColorButton", "color"),
|
||||
Preference.new("left_tool_color", "Interface/ButtonOptions/LeftToolColorButton", "color"),
|
||||
Preference.new("right_tool_color", "Interface/ButtonOptions/RightToolColorButton", "color"),
|
||||
Preference.new(
|
||||
"tool_button_size", "Interface/ButtonOptions/ToolButtonSizeOptionButton", "selected"
|
||||
"icon_color_from",
|
||||
"Interface/ButtonOptions/IconColorOptionButton",
|
||||
"selected",
|
||||
Global.ColorFrom.THEME
|
||||
),
|
||||
Preference.new(
|
||||
"show_left_tool_icon", "Cursors/CursorsContainer/LeftToolIconCheckbox", "button_pressed"
|
||||
"custom_icon_color", "Interface/ButtonOptions/IconColorButton", "color", Color.GRAY
|
||||
),
|
||||
Preference.new(
|
||||
"show_right_tool_icon", "Cursors/CursorsContainer/RightToolIconCheckbox", "button_pressed"
|
||||
"left_tool_color", "Interface/ButtonOptions/LeftToolColorButton", "color", Color("0086cf")
|
||||
),
|
||||
Preference.new(
|
||||
"right_tool_color", "Interface/ButtonOptions/RightToolColorButton", "color", Color("fd6d14")
|
||||
),
|
||||
Preference.new(
|
||||
"tool_button_size",
|
||||
"Interface/ButtonOptions/ToolButtonSizeOptionButton",
|
||||
"selected",
|
||||
Global.ButtonSize.SMALL
|
||||
),
|
||||
Preference.new(
|
||||
"show_left_tool_icon",
|
||||
"Cursors/CursorsContainer/LeftToolIconCheckbox",
|
||||
"button_pressed",
|
||||
true
|
||||
),
|
||||
Preference.new(
|
||||
"show_right_tool_icon",
|
||||
"Cursors/CursorsContainer/RightToolIconCheckbox",
|
||||
"button_pressed",
|
||||
true
|
||||
),
|
||||
Preference.new(
|
||||
"left_square_indicator_visible",
|
||||
"Cursors/CursorsContainer/LeftIndicatorCheckbox",
|
||||
"button_pressed"
|
||||
"button_pressed",
|
||||
true
|
||||
),
|
||||
Preference.new(
|
||||
"right_square_indicator_visible",
|
||||
"Cursors/CursorsContainer/RightIndicatorCheckbox",
|
||||
"button_pressed"
|
||||
"button_pressed",
|
||||
true
|
||||
),
|
||||
Preference.new(
|
||||
"native_cursors", "Cursors/CursorsContainer/NativeCursorsCheckbox", "button_pressed"
|
||||
"native_cursors", "Cursors/CursorsContainer/NativeCursorsCheckbox", "button_pressed", false
|
||||
),
|
||||
Preference.new(
|
||||
"cross_cursor", "Cursors/CursorsContainer/CrossCursorCheckbox", "button_pressed"
|
||||
"cross_cursor", "Cursors/CursorsContainer/CrossCursorCheckbox", "button_pressed", true
|
||||
),
|
||||
Preference.new("autosave_interval", "Backup/AutosaveContainer/AutosaveInterval", "value"),
|
||||
Preference.new("enable_autosave", "Backup/AutosaveContainer/EnableAutosave", "button_pressed"),
|
||||
Preference.new("default_width", "Image/ImageOptions/ImageDefaultWidth", "value"),
|
||||
Preference.new("default_height", "Image/ImageOptions/ImageDefaultHeight", "value"),
|
||||
Preference.new("default_fill_color", "Image/ImageOptions/DefaultFillColor", "color"),
|
||||
Preference.new("smooth_zoom", "Canvas/ZoomOptions/SmoothZoom", "button_pressed"),
|
||||
Preference.new("integer_zoom", "Canvas/ZoomOptions/IntegerZoom", "button_pressed"),
|
||||
Preference.new("snapping_distance", "Canvas/SnappingOptions/DistanceValue", "value"),
|
||||
Preference.new("grid_type", "Canvas/GridOptions/GridType", "selected"),
|
||||
Preference.new("grid_size", "Canvas/GridOptions/GridSizeValue", "value"),
|
||||
Preference.new("isometric_grid_size", "Canvas/GridOptions/IsometricGridSizeValue", "value"),
|
||||
Preference.new("grid_offset", "Canvas/GridOptions/GridOffsetValue", "value"),
|
||||
Preference.new("autosave_interval", "Backup/AutosaveContainer/AutosaveInterval", "value", 1.0),
|
||||
Preference.new(
|
||||
"grid_draw_over_tile_mode", "Canvas/GridOptions/GridDrawOverTileMode", "button_pressed"
|
||||
"enable_autosave", "Backup/AutosaveContainer/EnableAutosave", "button_pressed", true
|
||||
),
|
||||
Preference.new("grid_color", "Canvas/GridOptions/GridColor", "color"),
|
||||
Preference.new("pixel_grid_show_at_zoom", "Canvas/PixelGridOptions/ShowAtZoom", "value"),
|
||||
Preference.new("pixel_grid_color", "Canvas/PixelGridOptions/GridColor", "color"),
|
||||
Preference.new("guide_color", "Canvas/GuideOptions/GuideColor", "color"),
|
||||
Preference.new("checker_size", "Canvas/CheckerOptions/CheckerSizeValue", "value"),
|
||||
Preference.new("checker_color_1", "Canvas/CheckerOptions/CheckerColor1", "color"),
|
||||
Preference.new("checker_color_2", "Canvas/CheckerOptions/CheckerColor2", "color"),
|
||||
Preference.new("default_width", "Image/ImageOptions/ImageDefaultWidth", "value", 64),
|
||||
Preference.new("default_height", "Image/ImageOptions/ImageDefaultHeight", "value", 64),
|
||||
Preference.new("default_fill_color", "Image/ImageOptions/DefaultFillColor", "color", Color(0)),
|
||||
Preference.new("smooth_zoom", "Canvas/ZoomOptions/SmoothZoom", "button_pressed", true),
|
||||
Preference.new("integer_zoom", "Canvas/ZoomOptions/IntegerZoom", "button_pressed", false),
|
||||
Preference.new("snapping_distance", "Canvas/SnappingOptions/DistanceValue", "value", 32.0),
|
||||
Preference.new(
|
||||
"checker_follow_movement", "Canvas/CheckerOptions/CheckerFollowMovement", "button_pressed"
|
||||
"grid_type", "Canvas/GridOptions/GridType", "selected", Global.GridTypes.CARTESIAN
|
||||
),
|
||||
Preference.new("grid_size", "Canvas/GridOptions/GridSizeValue", "value", Vector2i(2, 2)),
|
||||
Preference.new(
|
||||
"isometric_grid_size", "Canvas/GridOptions/IsometricGridSizeValue", "value", Vector2i(16, 8)
|
||||
),
|
||||
Preference.new("grid_offset", "Canvas/GridOptions/GridOffsetValue", "value", Vector2i.ZERO),
|
||||
Preference.new(
|
||||
"grid_draw_over_tile_mode",
|
||||
"Canvas/GridOptions/GridDrawOverTileMode",
|
||||
"button_pressed",
|
||||
false
|
||||
),
|
||||
Preference.new("grid_color", "Canvas/GridOptions/GridColor", "color", Color.BLACK),
|
||||
Preference.new(
|
||||
"pixel_grid_show_at_zoom", "Canvas/PixelGridOptions/ShowAtZoom", "value", 1500.0
|
||||
),
|
||||
Preference.new(
|
||||
"checker_follow_scale", "Canvas/CheckerOptions/CheckerFollowScale", "button_pressed"
|
||||
"pixel_grid_color", "Canvas/PixelGridOptions/GridColor", "color", Color("21212191")
|
||||
),
|
||||
Preference.new("guide_color", "Canvas/GuideOptions/GuideColor", "color", Color.PURPLE),
|
||||
Preference.new("checker_size", "Canvas/CheckerOptions/CheckerSizeValue", "value", 10),
|
||||
Preference.new(
|
||||
"checker_color_1",
|
||||
"Canvas/CheckerOptions/CheckerColor1",
|
||||
"color",
|
||||
Color(0.47, 0.47, 0.47, 1)
|
||||
),
|
||||
Preference.new(
|
||||
"checker_color_2",
|
||||
"Canvas/CheckerOptions/CheckerColor2",
|
||||
"color",
|
||||
Color(0.34, 0.35, 0.34, 1)
|
||||
),
|
||||
Preference.new(
|
||||
"checker_follow_movement",
|
||||
"Canvas/CheckerOptions/CheckerFollowMovement",
|
||||
"button_pressed",
|
||||
false
|
||||
),
|
||||
Preference.new(
|
||||
"checker_follow_scale", "Canvas/CheckerOptions/CheckerFollowScale", "button_pressed", false
|
||||
),
|
||||
Preference.new("tilemode_opacity", "Canvas/CheckerOptions/TileModeOpacity", "value", 1.0),
|
||||
Preference.new(
|
||||
"clear_color_from",
|
||||
"Canvas/BackgroundOptions/ColorOptionButton",
|
||||
"selected",
|
||||
Global.ColorFrom.THEME
|
||||
),
|
||||
Preference.new(
|
||||
"modulate_clear_color", "Canvas/BackgroundOptions/BackgroundColor", "color", Color.GRAY
|
||||
),
|
||||
Preference.new("tilemode_opacity", "Canvas/CheckerOptions/TileModeOpacity", "value"),
|
||||
Preference.new("clear_color_from", "Canvas/BackgroundOptions/ColorOptionButton", "selected"),
|
||||
Preference.new("modulate_clear_color", "Canvas/BackgroundOptions/BackgroundColor", "color"),
|
||||
Preference.new(
|
||||
"select_layer_on_button_click",
|
||||
"Timeline/TimelineOptions/SelectLayerOnButton",
|
||||
"button_pressed"
|
||||
"button_pressed",
|
||||
false
|
||||
),
|
||||
Preference.new(
|
||||
"onion_skinning_past_color", "Timeline/TimelineOptions/OnionSkinningPastColor", "color"
|
||||
"onion_skinning_past_color",
|
||||
"Timeline/TimelineOptions/OnionSkinningPastColor",
|
||||
"color",
|
||||
Color.RED
|
||||
),
|
||||
Preference.new(
|
||||
"onion_skinning_future_color", "Timeline/TimelineOptions/OnionSkinningFutureColor", "color"
|
||||
"onion_skinning_future_color",
|
||||
"Timeline/TimelineOptions/OnionSkinningFutureColor",
|
||||
"color",
|
||||
Color.BLUE
|
||||
),
|
||||
Preference.new(
|
||||
"selection_animated_borders", "Selection/SelectionOptions/Animate", "button_pressed"
|
||||
"selection_animated_borders", "Selection/SelectionOptions/Animate", "button_pressed", true
|
||||
),
|
||||
Preference.new("selection_border_color_1", "Selection/SelectionOptions/BorderColor1", "color"),
|
||||
Preference.new("selection_border_color_2", "Selection/SelectionOptions/BorderColor2", "color"),
|
||||
Preference.new("fps_limit", "Performance/PerformanceContainer/SetFPSLimit", "value"),
|
||||
Preference.new(
|
||||
"pause_when_unfocused", "Performance/PerformanceContainer/PauseAppFocus", "button_pressed"
|
||||
"selection_border_color_1", "Selection/SelectionOptions/BorderColor1", "color", Color.WHITE
|
||||
),
|
||||
Preference.new(
|
||||
"selection_border_color_2", "Selection/SelectionOptions/BorderColor2", "color", Color.BLACK
|
||||
),
|
||||
Preference.new("fps_limit", "Performance/PerformanceContainer/SetFPSLimit", "value", 0),
|
||||
Preference.new(
|
||||
"pause_when_unfocused",
|
||||
"Performance/PerformanceContainer/PauseAppFocus",
|
||||
"button_pressed",
|
||||
true
|
||||
),
|
||||
Preference.new(
|
||||
"window_transparency",
|
||||
"Performance/PerformanceContainer/WindowTransparency",
|
||||
"button_pressed",
|
||||
true,
|
||||
false
|
||||
false,
|
||||
true
|
||||
),
|
||||
# Preference.new(
|
||||
# "renderer", "Drivers/DriversContainer/Renderer", "selected", true, OS.VIDEO_DRIVER_GLES2
|
||||
# "renderer", "Drivers/DriversContainer/Renderer", "selected", OS.VIDEO_DRIVER_GLES2, true
|
||||
# ),
|
||||
Preference.new("tablet_driver", "Drivers/DriversContainer/TabletDriver", "selected", true, 0)
|
||||
Preference.new("tablet_driver", "Drivers/DriversContainer/TabletDriver", "selected", 0, true)
|
||||
]
|
||||
|
||||
var content_list := []
|
||||
|
@ -135,15 +209,15 @@ class Preference:
|
|||
var prop_name: String
|
||||
var node_path: String
|
||||
var value_type: String
|
||||
var require_restart := false
|
||||
var default_value
|
||||
var require_restart := false
|
||||
|
||||
func _init(
|
||||
_prop_name: String,
|
||||
_node_path: String,
|
||||
_value_type: String,
|
||||
_require_restart := false,
|
||||
_default_value = null
|
||||
_default_value = null,
|
||||
_require_restart := false
|
||||
) -> void:
|
||||
prop_name = _prop_name
|
||||
node_path = _node_path
|
||||
|
@ -241,34 +315,13 @@ func _ready() -> void:
|
|||
_on_Preference_value_changed.bind(pref, restore_default_button)
|
||||
)
|
||||
|
||||
var global_value = Global.get(pref.prop_name)
|
||||
if Global.config_cache.has_section_key("preferences", pref.prop_name):
|
||||
var value = Global.config_cache.get_value("preferences", pref.prop_name)
|
||||
Global.set(pref.prop_name, value)
|
||||
node.set(pref.value_type, value)
|
||||
global_value = Global.get(pref.prop_name)
|
||||
|
||||
# This is needed because color_changed doesn't fire if the color changes in code
|
||||
if typeof(value) == TYPE_VECTOR2 or typeof(value) == TYPE_COLOR:
|
||||
preference_update(pref.require_restart)
|
||||
if typeof(global_value) == TYPE_VECTOR2I:
|
||||
disable_restore_default_button(
|
||||
restore_default_button, global_value == pref.default_value
|
||||
)
|
||||
else:
|
||||
disable_restore_default_button(
|
||||
restore_default_button, global_value.is_equal_approx(pref.default_value)
|
||||
)
|
||||
elif pref.value_type == "selected":
|
||||
preference_update(pref.require_restart)
|
||||
disable_restore_default_button(
|
||||
restore_default_button, global_value == pref.default_value
|
||||
)
|
||||
else:
|
||||
node.set(pref.value_type, global_value)
|
||||
disable_restore_default_button(
|
||||
restore_default_button, global_value == pref.default_value
|
||||
)
|
||||
var value = Global.get(pref.prop_name)
|
||||
node.set(pref.value_type, value)
|
||||
var is_default: bool = value == pref.default_value
|
||||
# This is needed because color_changed doesn't fire if the color changes in code
|
||||
if typeof(value) == TYPE_VECTOR2 or typeof(value) == TYPE_COLOR:
|
||||
is_default = value.is_equal_approx(pref.default_value)
|
||||
disable_restore_default_button(restore_default_button, is_default)
|
||||
|
||||
|
||||
func _on_Preference_value_changed(value, pref: Preference, button: RestoreDefaultButton) -> void:
|
||||
|
|
|
@ -15,6 +15,7 @@ var zen_mode := false
|
|||
|
||||
# Dialogs
|
||||
var new_image_dialog := Dialog.new("res://src/UI/Dialogs/CreateNewImage.tscn")
|
||||
var preferences_dialog := Dialog.new("res://src/Preferences/PreferencesDialog.tscn")
|
||||
var offset_image_dialog := Dialog.new("res://src/UI/Dialogs/ImageEffects/OffsetImage.tscn")
|
||||
var scale_image_dialog := Dialog.new("res://src/UI/Dialogs/ImageEffects/ScaleImage.tscn")
|
||||
var resize_canvas_dialog := Dialog.new("res://src/UI/Dialogs/ImageEffects/ResizeCanvas.tscn")
|
||||
|
@ -528,7 +529,7 @@ func edit_menu_id_pressed(id: int) -> void:
|
|||
Global.EditMenu.NEW_BRUSH:
|
||||
Global.canvas.selection.new_brush()
|
||||
Global.EditMenu.PREFERENCES:
|
||||
_popup_dialog(Global.preferences_dialog)
|
||||
preferences_dialog.popup()
|
||||
_:
|
||||
_handle_metadata(id, edit_menu)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue