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

@ -4,12 +4,16 @@ extends PanelContainer
# UI dock for the Weapon Creator plugin
# Provides tabs for weapons and bullets, with creation dialogs and logs
const WeaponCreatorSettings = preload("res://addons/weapon_creator/WeaponCreatorSettings.gd")
const SETTINGS_PATH = "user://weapon_creator_settings.tres"
signal create_weapon_requested(weapon_data: Dictionary)
signal create_bullet_requested(bullet_data: Dictionary)
signal create_item_requested(item_data: Dictionary)
# UI elements
var clear_button: Button
var options_button: Button
var log_output: RichTextLabel
var weapon_viewer: PanelContainer
var bullet_viewer: PanelContainer
@ -18,11 +22,22 @@ var tab_container: TabContainer
var _is_creating: bool = false
var _editor_interface: EditorInterface
var settings: Resource
func setup(editor_interface: EditorInterface) -> void:
_editor_interface = editor_interface
if ResourceLoader.exists(SETTINGS_PATH):
settings = ResourceLoader.load(SETTINGS_PATH)
if not settings:
settings = WeaponCreatorSettings.new()
func _ready() -> void:
if not settings:
if ResourceLoader.exists(SETTINGS_PATH):
settings = ResourceLoader.load(SETTINGS_PATH)
if not settings:
settings = WeaponCreatorSettings.new()
_build_ui()
func _build_ui() -> void:
@ -50,11 +65,33 @@ func _build_ui() -> void:
log_vbox.add_theme_constant_override("separation", 4)
hsplit.add_child(log_vbox)
# Tab Container for Weapons and Bullets (right side)
# Right side container with tabs and options button
var right_vbox = VBoxContainer.new()
right_vbox.custom_minimum_size = Vector2(300, 0)
right_vbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL
right_vbox.add_theme_constant_override("separation", 4)
hsplit.add_child(right_vbox)
# Header row with options button aligned to right
var header_hbox = HBoxContainer.new()
header_hbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL
right_vbox.add_child(header_hbox)
# Spacer to push options button to the right
var spacer = Control.new()
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
header_hbox.add_child(spacer)
options_button = Button.new()
options_button.text = "⚙ Settings"
options_button.pressed.connect(_on_options_pressed)
header_hbox.add_child(options_button)
# Tab Container for Weapons and Bullets
tab_container = TabContainer.new()
tab_container.custom_minimum_size = Vector2(300, 0)
tab_container.size_flags_horizontal = Control.SIZE_EXPAND_FILL
hsplit.add_child(tab_container)
tab_container.size_flags_vertical = Control.SIZE_EXPAND_FILL
right_vbox.add_child(tab_container)
# Weapon Viewer Tab
var weapon_viewer_script = load("res://addons/weapon_creator/WeaponViewer.gd")
@ -131,6 +168,29 @@ func _on_weapon_data_confirmed(weapon_data: Dictionary) -> void:
func _on_clear_button_pressed() -> void:
log_output.clear()
func _on_options_pressed() -> void:
var settings_dialog_script = load("res://addons/weapon_creator/SettingsDialog.gd")
var settings_dialog = Window.new()
settings_dialog.set_script(settings_dialog_script)
settings_dialog.setup(_editor_interface)
add_child(settings_dialog)
settings_dialog.popup_centered()
# Reload settings after dialog closes
settings_dialog.tree_exited.connect(func():
if ResourceLoader.exists(SETTINGS_PATH):
settings = ResourceLoader.load(SETTINGS_PATH)
if not settings:
settings = WeaponCreatorSettings.new()
# Refresh all viewers to pick up new settings
if weapon_viewer:
weapon_viewer.call("refresh_weapons")
if bullet_viewer:
bullet_viewer.call("refresh_bullets")
if item_viewer:
item_viewer.call("refresh_items")
)
func _on_weapon_deleted(weapon_name: String, weapon_path: String, item_path: String) -> void:
pass