mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-14 17:43:47 +00:00
Refactor creator dialogs to use centralized settings management and improve UI state handling
This commit is contained in:
parent
5a8ccbe51b
commit
99281deef4
12 changed files with 510 additions and 242 deletions
|
|
@ -5,32 +5,83 @@ extends Window
|
|||
# Base class for all creator dialogs
|
||||
# Ensures consistent initialization and UI building patterns
|
||||
|
||||
const WeaponCreatorSettings = preload("res://addons/weapon_creator/WeaponCreatorSettings.gd")
|
||||
const SETTINGS_PATH = "user://weapon_creator_settings.tres"
|
||||
|
||||
signal data_confirmed(data: Dictionary)
|
||||
|
||||
var editor_interface: EditorInterface
|
||||
var prefill_data: Dictionary = {}
|
||||
var _ui_built: bool = false
|
||||
var settings: Resource
|
||||
|
||||
# Base setup - override _custom_setup() in derived classes for additional initialization
|
||||
func setup(editor_iface: EditorInterface, prefill: Dictionary = {}) -> void:
|
||||
editor_interface = editor_iface
|
||||
prefill_data = prefill
|
||||
|
||||
if ResourceLoader.exists(SETTINGS_PATH):
|
||||
settings = ResourceLoader.load(SETTINGS_PATH)
|
||||
if not settings:
|
||||
settings = WeaponCreatorSettings.new()
|
||||
|
||||
_custom_setup()
|
||||
_update_title()
|
||||
|
||||
if _ui_built:
|
||||
_apply_data()
|
||||
|
||||
# Override this in derived classes for custom initialization
|
||||
func _custom_setup() -> void:
|
||||
pass
|
||||
|
||||
func _ready() -> void:
|
||||
if not settings:
|
||||
if ResourceLoader.exists(SETTINGS_PATH):
|
||||
settings = ResourceLoader.load(SETTINGS_PATH)
|
||||
if not settings:
|
||||
settings = WeaponCreatorSettings.new()
|
||||
|
||||
_configure_window()
|
||||
_update_title()
|
||||
|
||||
close_requested.connect(_on_cancel_pressed)
|
||||
position = (DisplayServer.screen_get_size() - size) / 2
|
||||
close_requested.connect(_on_window_close_requested)
|
||||
|
||||
_build_ui()
|
||||
_ui_built = true
|
||||
|
||||
_apply_data()
|
||||
|
||||
# Restore position after UI is built, or center if no saved position
|
||||
_restore_or_center_position()
|
||||
|
||||
func _restore_or_center_position() -> void:
|
||||
var saved_pos = _get_saved_position()
|
||||
if saved_pos != Vector2i.ZERO:
|
||||
position = saved_pos
|
||||
else:
|
||||
# Use popup_centered_clamped to properly center on the current screen
|
||||
popup_centered_clamped(size, 0.75)
|
||||
|
||||
func _get_saved_position() -> Vector2i:
|
||||
# Override in derived classes to return their specific saved position
|
||||
return Vector2i.ZERO
|
||||
|
||||
func _on_window_close_requested() -> void:
|
||||
_save_dialog_size_and_position()
|
||||
_on_cancel_pressed()
|
||||
|
||||
func _save_dialog_size_and_position() -> void:
|
||||
_save_dialog_size()
|
||||
_save_dialog_position()
|
||||
|
||||
func _save_dialog_size() -> void:
|
||||
# Override in derived classes to save their specific dialog size
|
||||
pass
|
||||
|
||||
func _save_dialog_position() -> void:
|
||||
# Override in derived classes to save their specific dialog position
|
||||
pass
|
||||
|
||||
func _configure_window() -> void:
|
||||
size = Vector2i(750, 850)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue