mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-18 21:23:46 +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
|
|
@ -1,5 +1,5 @@
|
|||
@tool
|
||||
extends Window
|
||||
extends BaseCreatorDialog
|
||||
|
||||
# Popup window for configuring bullet parameters before creation
|
||||
|
||||
|
|
@ -19,91 +19,71 @@ var life_time_field: SpinBox
|
|||
var graze_value_field: SpinBox
|
||||
var destruction_particles_picker: EditorResourcePicker
|
||||
|
||||
# Buttons
|
||||
var create_button: Button
|
||||
var cancel_button: Button
|
||||
|
||||
# Mode and prefill data
|
||||
# Mode
|
||||
var is_3d_mode: bool = true
|
||||
var prefill_data: Dictionary = {}
|
||||
var _ui_built: bool = false
|
||||
var editor_interface: EditorInterface
|
||||
var _setup_called: bool = false
|
||||
|
||||
func setup(editor_iface: EditorInterface, is_3d: bool = true, prefill: Dictionary = {}) -> void:
|
||||
editor_interface = editor_iface
|
||||
# Public method with custom signature - calls base setup internally
|
||||
func setup_bullet(editor_iface: EditorInterface, is_3d: bool = true, prefill: Dictionary = {}) -> void:
|
||||
is_3d_mode = is_3d
|
||||
prefill_data = prefill
|
||||
|
||||
var mode_text = "3D" if is_3d_mode else "2D"
|
||||
var action_text = "Duplicate" if not prefill_data.is_empty() else "Create New"
|
||||
title = action_text + " Bullet (" + mode_text + ")"
|
||||
|
||||
if _ui_built:
|
||||
if prefill_data.is_empty():
|
||||
_set_default_values()
|
||||
else:
|
||||
_apply_prefill_data()
|
||||
_setup_called = true
|
||||
# Call parent setup with standard signature
|
||||
setup(editor_iface, prefill)
|
||||
|
||||
func _custom_setup() -> void:
|
||||
# Called by parent setup() - use for any additional initialization
|
||||
pass
|
||||
|
||||
func _ready() -> void:
|
||||
var mode_text = "3D" if is_3d_mode else "2D"
|
||||
var action_text = "Duplicate" if not prefill_data.is_empty() else "Create New"
|
||||
title = action_text + " Bullet (" + mode_text + ")"
|
||||
size = Vector2i(750, 750)
|
||||
# Wait for setup to be called if it hasn't been yet
|
||||
if not _setup_called:
|
||||
await get_tree().process_frame
|
||||
super._ready()
|
||||
|
||||
func _configure_window() -> void:
|
||||
size = settings.get("bullet_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 _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 main_vbox = VBoxContainer.new()
|
||||
main_vbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
main_vbox.add_theme_constant_override("separation", 12)
|
||||
scroll.add_child(main_vbox)
|
||||
|
||||
_build_basic_section(main_vbox)
|
||||
_build_stats_section(main_vbox)
|
||||
|
||||
vbox.add_child(HSeparator.new())
|
||||
|
||||
func _update_title() -> void:
|
||||
var mode_text = "3D" if is_3d_mode else "2D"
|
||||
var action_text = "Duplicate" if not prefill_data.is_empty() else "Create New"
|
||||
title = action_text + " Bullet (" + mode_text + ")"
|
||||
|
||||
func _get_saved_position() -> Vector2i:
|
||||
if settings:
|
||||
var pos = settings.get("bullet_dialog_position")
|
||||
return pos if pos else Vector2i.ZERO
|
||||
return Vector2i.ZERO
|
||||
|
||||
func _save_dialog_size() -> void:
|
||||
if settings:
|
||||
settings.set("bullet_dialog_size", size)
|
||||
settings.call("save_settings")
|
||||
|
||||
func _save_dialog_position() -> void:
|
||||
if settings:
|
||||
settings.set("bullet_dialog_position", position)
|
||||
settings.call("save_settings")
|
||||
|
||||
func _build_content(container: VBoxContainer) -> void:
|
||||
_build_basic_section(container)
|
||||
_build_stats_section(container)
|
||||
|
||||
func _build_buttons(vbox: VBoxContainer) -> void:
|
||||
var button_hbox = HBoxContainer.new()
|
||||
button_hbox.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
button_hbox.add_theme_constant_override("separation", 8)
|
||||
vbox.add_child(button_hbox)
|
||||
|
||||
cancel_button = Button.new()
|
||||
var cancel_button = Button.new()
|
||||
cancel_button.text = "Cancel"
|
||||
cancel_button.custom_minimum_size = Vector2(100, 0)
|
||||
cancel_button.pressed.connect(_on_cancel_pressed)
|
||||
button_hbox.add_child(cancel_button)
|
||||
|
||||
create_button = Button.new()
|
||||
var create_button = Button.new()
|
||||
create_button.text = "Create Bullet"
|
||||
create_button.custom_minimum_size = Vector2(150, 0)
|
||||
create_button.pressed.connect(_on_create_pressed)
|
||||
|
|
@ -351,12 +331,14 @@ func _on_create_pressed() -> void:
|
|||
"destruction_particles_scene": destruction_particles_picker.edited_resource
|
||||
}
|
||||
|
||||
_save_dialog_size()
|
||||
bullet_data_confirmed.emit(bullet_data)
|
||||
|
||||
hide()
|
||||
queue_free()
|
||||
|
||||
func _on_cancel_pressed() -> void:
|
||||
_save_dialog_size()
|
||||
hide()
|
||||
queue_free()
|
||||
|
||||
|
|
@ -369,9 +351,7 @@ func _validate_inputs() -> bool:
|
|||
if is_3d_mode and not bullet_name.ends_with("_3D"):
|
||||
bullet_name += "_3D"
|
||||
|
||||
var bullets_dir = "res://Resources/Bullets/"
|
||||
if is_3d_mode:
|
||||
bullets_dir += "3D/"
|
||||
var bullets_dir = settings.get("bullets_3d_dir") if is_3d_mode else settings.get("bullets_dir")
|
||||
|
||||
var bullet_path = bullets_dir + bullet_name + ".tres"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue