cirnogodot/addons/weapon_creator/WeaponCreatorDock.gd

156 lines
4.9 KiB
GDScript

@tool
extends PanelContainer
# UI dock for the Weapon Creator plugin
# Provides a button to open the creation dialog and displays creation logs
signal create_weapon_requested(weapon_data: Dictionary)
# UI elements
var open_dialog_button: Button
var clear_button: Button
var log_output: RichTextLabel
var weapon_viewer: PanelContainer
var _is_creating: bool = false
var _editor_interface: EditorInterface
func setup(editor_interface: EditorInterface) -> void:
_editor_interface = editor_interface
func _ready() -> void:
_build_ui()
func _build_ui() -> void:
# Main margin container
var margin = MarginContainer.new()
margin.add_theme_constant_override("margin_left", 8)
margin.add_theme_constant_override("margin_top", 8)
margin.add_theme_constant_override("margin_right", 8)
margin.add_theme_constant_override("margin_bottom", 8)
add_child(margin)
# Main vbox
var vbox = VBoxContainer.new()
vbox.add_theme_constant_override("separation", 8)
margin.add_child(vbox)
# Title
var title = Label.new()
title.text = "3D Weapon Creator"
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
vbox.add_child(title)
vbox.add_child(HSeparator.new())
# Buttons
var button_hbox = HBoxContainer.new()
button_hbox.alignment = BoxContainer.ALIGNMENT_CENTER
button_hbox.add_theme_constant_override("separation", 8)
vbox.add_child(button_hbox)
open_dialog_button = Button.new()
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.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)
button_hbox.add_child(clear_button)
vbox.add_child(HSeparator.new())
# Horizontal split container for weapon viewer and log
var hsplit = HSplitContainer.new()
hsplit.size_flags_vertical = Control.SIZE_EXPAND_FILL
vbox.add_child(hsplit)
# Log section (left side)
var log_vbox = VBoxContainer.new()
log_vbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL
log_vbox.add_theme_constant_override("separation", 4)
hsplit.add_child(log_vbox)
# Weapon Viewer (right side)
var weapon_viewer_script = load("res://addons/weapon_creator/WeaponViewer.gd")
weapon_viewer = PanelContainer.new()
weapon_viewer.set_script(weapon_viewer_script)
weapon_viewer.custom_minimum_size = Vector2(300, 0)
weapon_viewer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
# 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)
var log_scroll = ScrollContainer.new()
log_scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
log_vbox.add_child(log_scroll)
log_output = RichTextLabel.new()
log_output.bbcode_enabled = true
log_output.scroll_following = true
log_output.size_flags_horizontal = Control.SIZE_EXPAND_FILL
log_output.size_flags_vertical = Control.SIZE_EXPAND_FILL
log_scroll.add_child(log_output)
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)
# Add to scene tree first
get_tree().root.add_child(dialog)
# 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
if _is_creating:
return
_is_creating = true
open_dialog_button.disabled = true
log_output.clear()
# Emit signal to plugin
create_weapon_requested.emit(weapon_data)
func _on_clear_button_pressed() -> void:
log_output.clear()
func add_log(message: String, color: Color = Color.WHITE) -> void:
# Add colored message to log output
log_output.append_text("[color=#" + color.to_html(false) + "]" + message + "[/color]\n")
func set_creation_complete() -> void:
# Re-enable the create button after creation is complete
_is_creating = false
open_dialog_button.disabled = false
# Refresh weapon viewer to show newly created weapon
if weapon_viewer:
weapon_viewer.call("refresh_weapons")