Enhance weapon creation dialog with 2D/3D mode support and prefill functionality

This commit is contained in:
MaddoScientisto 2026-02-08 16:44:38 +01:00
commit c78fa8aa45
4 changed files with 425 additions and 53 deletions

View file

@ -50,11 +50,17 @@ func _build_ui() -> void:
vbox.add_child(button_hbox)
open_dialog_button = Button.new()
open_dialog_button.text = "Create New Weapon"
open_dialog_button.text = "Create Weapon (2D)"
open_dialog_button.custom_minimum_size = Vector2(150, 0)
open_dialog_button.pressed.connect(_on_open_dialog_pressed)
open_dialog_button.pressed.connect(_on_open_dialog_pressed.bind(false))
button_hbox.add_child(open_dialog_button)
var open_dialog_button_3d = Button.new()
open_dialog_button_3d.text = "Create Weapon (3D)"
open_dialog_button_3d.custom_minimum_size = Vector2(150, 0)
open_dialog_button_3d.pressed.connect(_on_open_dialog_pressed.bind(true))
button_hbox.add_child(open_dialog_button_3d)
clear_button = Button.new()
clear_button.text = "Clear Log"
clear_button.pressed.connect(_on_clear_button_pressed)
@ -79,10 +85,14 @@ func _build_ui() -> void:
weapon_viewer.set_script(weapon_viewer_script)
weapon_viewer.custom_minimum_size = Vector2(300, 0)
weapon_viewer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
if _editor_interface:
weapon_viewer.call("setup", _editor_interface)
# Connect duplicate weapon signal
weapon_viewer.duplicate_weapon_requested.connect(_on_weapon_data_confirmed)
hsplit.add_child(weapon_viewer)
# Setup after adding to scene tree
if _editor_interface:
weapon_viewer.setup(_editor_interface)
var log_label = Label.new()
log_label.text = "Output Log:"
log_vbox.add_child(log_label)
@ -98,22 +108,24 @@ func _build_ui() -> void:
log_output.size_flags_vertical = Control.SIZE_EXPAND_FILL
log_scroll.add_child(log_output)
func _on_open_dialog_pressed() -> void:
func _on_open_dialog_pressed(is_3d: bool) -> void:
# Open the weapon creation dialog window
var dialog_script = load("res://addons/weapon_creator/WeaponCreatorDialog.gd")
var dialog = Window.new()
dialog.set_script(dialog_script)
# Setup editor interface
if _editor_interface:
dialog.call("setup", _editor_interface)
# Connect to the confirmation signal
dialog.weapon_data_confirmed.connect(_on_weapon_data_confirmed)
# Add to scene tree and show
# Add to scene tree first
get_tree().root.add_child(dialog)
dialog.popup_centered()
# Setup editor interface and mode using call_deferred to ensure script is ready
if _editor_interface:
dialog.call_deferred("setup", _editor_interface, is_3d)
# Connect to the confirmation signal using call_deferred
dialog.call_deferred("connect", "weapon_data_confirmed", _on_weapon_data_confirmed)
# Show the dialog
dialog.call_deferred("popup_centered")
func _on_weapon_data_confirmed(weapon_data: Dictionary) -> void:
# Receive weapon data from dialog and forward to plugin