Refactor creator dialogs to use centralized settings management and improve UI state handling

This commit is contained in:
MaddoScientisto 2026-02-08 20:33:52 +01:00
commit 99281deef4
12 changed files with 510 additions and 242 deletions

View file

@ -1,16 +1,11 @@
@tool
extends Window
extends BaseCreatorDialog
# Dialog for creating new items
# Provides input fields for all item properties
signal item_data_confirmed(item_data: Dictionary)
# Editor reference
var editor_interface: EditorInterface
var prefill_data: Dictionary = {}
var _ui_built: bool = false
# UI elements
var _item_name_edit: LineEdit
var _item_key_edit: LineEdit
@ -46,72 +41,35 @@ const ITEM_TYPE_NAMES = [
"KeyItem"
]
func setup(editor_iface: EditorInterface, prefill: Dictionary = {}) -> void:
editor_interface = editor_iface
prefill_data = prefill
var action_text = "Duplicate" if not prefill_data.is_empty() else "Create New"
title = action_text + " Item"
if _ui_built:
if prefill_data.is_empty():
_set_default_values()
else:
_apply_prefill_data()
func _ready() -> void:
var action_text = "Duplicate" if not prefill_data.is_empty() else "Create New"
title = action_text + " Item"
size = Vector2i(750, 850)
func _configure_window() -> void:
size = settings.get("item_dialog_size") if settings else Vector2i(750, 850)
transient = false
exclusive = false
unresizable = false
close_requested.connect(_on_cancel_pressed)
position = (DisplayServer.screen_get_size() - size) / 2
_build_ui()
_ui_built = true
if prefill_data.is_empty():
_set_default_values()
else:
_apply_prefill_data()
func _set_default_values() -> void:
pass
func _update_title() -> void:
var action_text = "Duplicate" if not prefill_data.is_empty() else "Create New"
title = action_text + " Item"
func _build_ui() -> void:
var margin = MarginContainer.new()
margin.set_anchors_preset(Control.PRESET_FULL_RECT)
margin.add_theme_constant_override("margin_left", 12)
margin.add_theme_constant_override("margin_top", 12)
margin.add_theme_constant_override("margin_right", 12)
margin.add_theme_constant_override("margin_bottom", 12)
add_child(margin)
var vbox = VBoxContainer.new()
vbox.add_theme_constant_override("separation", 8)
margin.add_child(vbox)
var scroll = ScrollContainer.new()
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
vbox.add_child(scroll)
var content_vbox = VBoxContainer.new()
content_vbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL
content_vbox.add_theme_constant_override("separation", 12)
scroll.add_child(content_vbox)
_build_content(content_vbox)
vbox.add_child(HSeparator.new())
_build_buttons(vbox)
func _get_saved_position() -> Vector2i:
if settings:
var pos = settings.get("item_dialog_position")
return pos if pos else Vector2i.ZERO
return Vector2i.ZERO
func _save_dialog_size() -> void:
if settings:
settings.set("item_dialog_size", size)
settings.call("save_settings")
func _save_dialog_position() -> void:
if settings:
settings.set("item_dialog_position", position)
settings.call("save_settings")
func _build_content(container: VBoxContainer) -> void:
_build_basic_info_section(container)
_build_properties_section(container)
func _build_buttons(parent: VBoxContainer) -> void:
var button_hbox = HBoxContainer.new()
@ -131,7 +89,7 @@ func _build_buttons(parent: VBoxContainer) -> void:
create_button.pressed.connect(_on_create_pressed)
button_hbox.add_child(create_button)
func _build_content(content_vbox: VBoxContainer) -> void:
func _build_basic_info_section(content_vbox: VBoxContainer) -> void:
# Basic Info Section
content_vbox.add_child(_create_section_label("Basic Information"))
@ -204,7 +162,8 @@ func _build_content(content_vbox: VBoxContainer) -> void:
_sprite_preview.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL
_sprite_preview.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
preview_container.add_child(_sprite_preview)
func _build_properties_section(content_vbox: VBoxContainer) -> void:
content_vbox.add_child(HSeparator.new())
# Properties Section
@ -342,10 +301,12 @@ func _on_create_pressed() -> void:
"selectable": _selectable_check.button_pressed
}
_save_dialog_size()
item_data_confirmed.emit(item_data)
queue_free()
func _on_cancel_pressed() -> void:
_save_dialog_size()
queue_free()
func _show_error(message: String) -> void: