mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-20 20:53:47 +00:00
Add enemy creation and viewer functionality with filtering options
This commit is contained in:
parent
e735060f93
commit
18683c0680
32 changed files with 1009 additions and 411 deletions
|
|
@ -1,5 +1,5 @@
|
|||
@tool
|
||||
extends PanelContainer
|
||||
extends BaseViewer
|
||||
|
||||
# Displays all weapons from the ItemsDatabase in a grid format
|
||||
# Shows sprite and name, with tooltip showing resource path
|
||||
|
|
@ -10,49 +10,21 @@ signal duplicate_weapon_requested(weapon_data: Dictionary)
|
|||
signal weapon_deleted(weapon_name: String, weapon_path: String, item_path: String)
|
||||
signal weapon_duplication_started(weapon_name: String, is_3d: bool)
|
||||
|
||||
var _editor_interface: EditorInterface
|
||||
var _grid_container: HFlowContainer
|
||||
var _items_database_path := "res://Resources/ItemsDatabase.tres"
|
||||
var _show_2d_checkbox: CheckBox
|
||||
var _show_3d_checkbox: CheckBox
|
||||
var _dock: PanelContainer # Reference to the dock for logging
|
||||
|
||||
const SETTING_SHOW_2D = "weapon_creator/filter_show_2d"
|
||||
const SETTING_SHOW_3D = "weapon_creator/filter_show_3d"
|
||||
|
||||
func setup(editor_interface: EditorInterface, dock: PanelContainer = null) -> void:
|
||||
_editor_interface = editor_interface
|
||||
_dock = dock
|
||||
# Load saved filter settings after editor interface is available
|
||||
if _show_2d_checkbox:
|
||||
_show_2d_checkbox.button_pressed = _load_filter_setting(SETTING_SHOW_2D, true)
|
||||
if _show_3d_checkbox:
|
||||
_show_3d_checkbox.button_pressed = _load_filter_setting(SETTING_SHOW_3D, true)
|
||||
# Refresh to apply loaded filter settings
|
||||
refresh_weapons()
|
||||
func _supports_2d_3d_filter() -> bool:
|
||||
return true
|
||||
|
||||
func _ready() -> void:
|
||||
_build_ui()
|
||||
refresh_weapons()
|
||||
func _get_filter_setting_2d_key() -> String:
|
||||
return SETTING_SHOW_2D
|
||||
|
||||
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)
|
||||
|
||||
# Header with title and refresh button
|
||||
var header_hbox = HBoxContainer.new()
|
||||
vbox.add_child(header_hbox)
|
||||
|
||||
func _get_filter_setting_3d_key() -> String:
|
||||
return SETTING_SHOW_3D
|
||||
|
||||
func _build_header_buttons(header_hbox: HBoxContainer) -> void:
|
||||
var create_2d_button = Button.new()
|
||||
create_2d_button.text = "Create (2D)"
|
||||
create_2d_button.pressed.connect(_on_create_weapon_pressed.bind(false))
|
||||
|
|
@ -62,51 +34,9 @@ func _build_ui() -> void:
|
|||
create_3d_button.text = "Create (3D)"
|
||||
create_3d_button.pressed.connect(_on_create_weapon_pressed.bind(true))
|
||||
header_hbox.add_child(create_3d_button)
|
||||
|
||||
# Spacer
|
||||
var spacer = Control.new()
|
||||
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
header_hbox.add_child(spacer)
|
||||
|
||||
_show_2d_checkbox = CheckBox.new()
|
||||
_show_2d_checkbox.text = "2D"
|
||||
_show_2d_checkbox.button_pressed = true
|
||||
_show_2d_checkbox.toggled.connect(_on_filter_changed)
|
||||
header_hbox.add_child(_show_2d_checkbox)
|
||||
|
||||
_show_3d_checkbox = CheckBox.new()
|
||||
_show_3d_checkbox.text = "3D"
|
||||
_show_3d_checkbox.button_pressed = true
|
||||
_show_3d_checkbox.toggled.connect(_on_filter_changed)
|
||||
header_hbox.add_child(_show_3d_checkbox)
|
||||
|
||||
var refresh_button = Button.new()
|
||||
refresh_button.text = "Refresh"
|
||||
refresh_button.pressed.connect(refresh_weapons)
|
||||
header_hbox.add_child(refresh_button)
|
||||
|
||||
vbox.add_child(HSeparator.new())
|
||||
|
||||
# Scroll container for grid
|
||||
var scroll = ScrollContainer.new()
|
||||
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
vbox.add_child(scroll)
|
||||
|
||||
# Flow container for responsive wrapping
|
||||
_grid_container = HFlowContainer.new()
|
||||
_grid_container.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
_grid_container.add_theme_constant_override("h_separation", 8)
|
||||
_grid_container.add_theme_constant_override("v_separation", 8)
|
||||
scroll.add_child(_grid_container)
|
||||
|
||||
func refresh_weapons() -> void:
|
||||
if not _grid_container:
|
||||
return
|
||||
|
||||
# Clear existing items
|
||||
for child in _grid_container.get_children():
|
||||
child.queue_free()
|
||||
func refresh() -> void:
|
||||
_clear_grid()
|
||||
|
||||
# Load ItemsDatabase
|
||||
if not ResourceLoader.exists(_items_database_path):
|
||||
|
|
@ -124,8 +54,8 @@ func refresh_weapons() -> void:
|
|||
return
|
||||
|
||||
# Filter for weapons only (items with WeaponData3D or WeaponData)
|
||||
var show_2d = _show_2d_checkbox == null or _show_2d_checkbox.button_pressed
|
||||
var show_3d = _show_3d_checkbox == null or _show_3d_checkbox.button_pressed
|
||||
var show_2d = _should_show_2d()
|
||||
var show_3d = _should_show_3d()
|
||||
|
||||
var weapon_count = 0
|
||||
for loot_item in loot_items:
|
||||
|
|
@ -143,25 +73,6 @@ func refresh_weapons() -> void:
|
|||
if weapon_count == 0:
|
||||
_add_error_label("No weapons found in database")
|
||||
|
||||
func _on_filter_changed(_toggled: bool) -> void:
|
||||
_save_filter_settings()
|
||||
refresh_weapons()
|
||||
|
||||
func _load_filter_setting(key: String, default_value: bool) -> bool:
|
||||
if not _editor_interface:
|
||||
return default_value
|
||||
var editor_settings = _editor_interface.get_editor_settings()
|
||||
if editor_settings and editor_settings.has_setting(key):
|
||||
return editor_settings.get_setting(key)
|
||||
return default_value
|
||||
|
||||
func _save_filter_settings() -> void:
|
||||
if not _editor_interface:
|
||||
return
|
||||
var editor_settings = _editor_interface.get_editor_settings()
|
||||
if editor_settings:
|
||||
editor_settings.set_setting(SETTING_SHOW_2D, _show_2d_checkbox.button_pressed)
|
||||
editor_settings.set_setting(SETTING_SHOW_3D, _show_3d_checkbox.button_pressed)
|
||||
|
||||
func _create_weapon_tile(loot_item: Resource, weapon_data: Resource, is_3d: bool) -> void:
|
||||
var panel = PanelContainer.new()
|
||||
|
|
@ -336,10 +247,9 @@ func _duplicate_weapon(loot_item: Resource, weapon_data: Resource, is_3d: bool)
|
|||
var dimension = "3D" if is_3d else "2D"
|
||||
|
||||
# Log to dock
|
||||
if _dock:
|
||||
_dock.call("add_log", "=== Duplicating Weapon (" + dimension + ") ===", Color.CYAN)
|
||||
_dock.call("add_log", "Source: " + weapon_name, Color.CYAN)
|
||||
_dock.call("add_log", "Opening creation dialog with prefilled data...", Color.CYAN)
|
||||
_log_to_dock("=== Duplicating Weapon (" + dimension + ") ===", Color.CYAN)
|
||||
_log_to_dock("Source: " + weapon_name, Color.CYAN)
|
||||
_log_to_dock("Opening creation dialog with prefilled data...", Color.CYAN)
|
||||
|
||||
# Also log to Godot console
|
||||
print("Duplicating weapon (", dimension, "): ", weapon_name)
|
||||
|
|
@ -397,7 +307,7 @@ func _on_duplicate_weapon_confirmed(weapon_data: Dictionary) -> void:
|
|||
# Forward the weapon data to be created
|
||||
duplicate_weapon_requested.emit(weapon_data)
|
||||
# Refresh after a short delay to allow file system to update
|
||||
get_tree().create_timer(0.5).timeout.connect(refresh_weapons)
|
||||
get_tree().create_timer(0.5).timeout.connect(refresh)
|
||||
|
||||
func _copy_weapon_resource_path(weapon_data: Resource) -> void:
|
||||
if weapon_data and weapon_data.resource_path:
|
||||
|
|
@ -494,21 +404,13 @@ func _perform_delete(loot_item: Resource, weapon_data: Resource, dialog: Confirm
|
|||
weapon_deleted.emit(weapon_name, weapon_path, loot_item_path)
|
||||
|
||||
# Log to dock
|
||||
if _dock:
|
||||
_dock.call("add_log", "=== Weapon Deleted ===", Color.ORANGE)
|
||||
_dock.call("add_log", "Weapon: " + weapon_name, Color.ORANGE)
|
||||
_dock.call("add_log", "✓ Deleted WeaponResource: " + weapon_path, Color.GREEN)
|
||||
_dock.call("add_log", "✓ Deleted LootItem: " + loot_item_path, Color.GREEN)
|
||||
_dock.call("add_log", "✓ Removed from ItemsDatabase", Color.GREEN)
|
||||
_log_to_dock("=== Weapon Deleted ===", Color.ORANGE)
|
||||
_log_to_dock("Weapon: " + weapon_name, Color.ORANGE)
|
||||
_log_to_dock("✓ Deleted WeaponResource: " + weapon_path, Color.GREEN)
|
||||
_log_to_dock("✓ Deleted LootItem: " + loot_item_path, Color.GREEN)
|
||||
_log_to_dock("✓ Removed from ItemsDatabase", Color.GREEN)
|
||||
|
||||
refresh_weapons()
|
||||
|
||||
func _add_error_label(error_message: String) -> void:
|
||||
var label = Label.new()
|
||||
label.text = error_message
|
||||
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
label.modulate = Color.ORANGE_RED
|
||||
_grid_container.add_child(label)
|
||||
refresh()
|
||||
|
||||
func _on_create_weapon_pressed(is_3d: bool) -> void:
|
||||
if not _editor_interface:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue