mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:45:33 +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 bullets from the Resources/Bullets folders in a grid format
|
||||
# Shows sprite and name, with tooltip showing resource path
|
||||
|
|
@ -9,44 +9,19 @@ signal duplicate_bullet_requested(bullet_data: Dictionary)
|
|||
signal bullet_deleted(bullet_name: String, bullet_path: String)
|
||||
signal bullet_duplication_started(bullet_name: String, is_3d: bool)
|
||||
|
||||
var _editor_interface: EditorInterface
|
||||
var _grid_container: HFlowContainer
|
||||
var _show_2d_checkbox: CheckBox
|
||||
var _show_3d_checkbox: CheckBox
|
||||
var _dock: PanelContainer
|
||||
|
||||
const SETTING_SHOW_2D = "weapon_creator/bullet_filter_show_2d"
|
||||
const SETTING_SHOW_3D = "weapon_creator/bullet_filter_show_3d"
|
||||
|
||||
func setup(editor_interface: EditorInterface, dock: PanelContainer = null) -> void:
|
||||
_editor_interface = editor_interface
|
||||
_dock = dock
|
||||
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_bullets()
|
||||
func _supports_2d_3d_filter() -> bool:
|
||||
return true
|
||||
|
||||
func _ready() -> void:
|
||||
_build_ui()
|
||||
refresh_bullets()
|
||||
func _get_filter_setting_2d_key() -> String:
|
||||
return SETTING_SHOW_2D
|
||||
|
||||
func _build_ui() -> void:
|
||||
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)
|
||||
|
||||
var vbox = VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 8)
|
||||
margin.add_child(vbox)
|
||||
|
||||
# Header with title, filters, and buttons
|
||||
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_bullet_pressed.bind(false))
|
||||
|
|
@ -56,53 +31,12 @@ func _build_ui() -> void:
|
|||
create_3d_button.text = "Create (3D)"
|
||||
create_3d_button.pressed.connect(_on_create_bullet_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_bullets)
|
||||
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)
|
||||
|
||||
_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_bullets() -> void:
|
||||
if not _grid_container:
|
||||
return
|
||||
func refresh() -> void:
|
||||
_clear_grid()
|
||||
|
||||
# Clear existing items
|
||||
for child in _grid_container.get_children():
|
||||
child.queue_free()
|
||||
|
||||
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 bullet_count = 0
|
||||
|
||||
|
|
@ -302,9 +236,8 @@ func _duplicate_bullet(bullet_resource: Resource, is_3d: bool) -> void:
|
|||
var bullet_name = bullet_resource.resource_path.get_file().get_basename()
|
||||
var dimension = "3D" if is_3d else "2D"
|
||||
|
||||
if _dock:
|
||||
_dock.call("add_log", "=== Duplicating Bullet (" + dimension + ") ===", Color.CYAN)
|
||||
_dock.call("add_log", "Source: " + bullet_name, Color.CYAN)
|
||||
_log_to_dock("=== Duplicating Bullet (" + dimension + ") ===", Color.CYAN)
|
||||
_log_to_dock("Source: " + bullet_name, Color.CYAN)
|
||||
|
||||
bullet_duplication_started.emit(bullet_name, is_3d)
|
||||
|
||||
|
|
@ -325,7 +258,7 @@ func _duplicate_bullet(bullet_resource: Resource, is_3d: bool) -> void:
|
|||
|
||||
func _on_duplicate_bullet_confirmed(bullet_data: Dictionary) -> void:
|
||||
duplicate_bullet_requested.emit(bullet_data)
|
||||
get_tree().create_timer(0.5).timeout.connect(refresh_bullets)
|
||||
get_tree().create_timer(0.5).timeout.connect(refresh)
|
||||
|
||||
func _copy_bullet_resource_path(bullet_resource: Resource) -> void:
|
||||
if bullet_resource and bullet_resource.resource_path:
|
||||
|
|
@ -378,12 +311,11 @@ func _perform_delete(bullet_resource: Resource, dialog: ConfirmationDialog) -> v
|
|||
if deleted_success:
|
||||
bullet_deleted.emit(bullet_name, bullet_path)
|
||||
|
||||
if _dock:
|
||||
_dock.call("add_log", "=== Bullet Deleted ===", Color.ORANGE)
|
||||
_dock.call("add_log", "Bullet: " + bullet_name, Color.ORANGE)
|
||||
_dock.call("add_log", "✓ Deleted BulletResource: " + bullet_path, Color.GREEN)
|
||||
_log_to_dock("=== Bullet Deleted ===", Color.ORANGE)
|
||||
_log_to_dock("Bullet: " + bullet_name, Color.ORANGE)
|
||||
_log_to_dock("✓ Deleted BulletResource: " + bullet_path, Color.GREEN)
|
||||
|
||||
refresh_bullets()
|
||||
refresh()
|
||||
|
||||
func _on_create_bullet_pressed(is_3d: bool) -> void:
|
||||
_open_bullet_dialog(is_3d, {})
|
||||
|
|
@ -399,30 +331,3 @@ func _open_bullet_dialog(is_3d: bool, prefill_data: Dictionary = {}) -> void:
|
|||
dialog.call_deferred("connect", "bullet_data_confirmed", _on_duplicate_bullet_confirmed)
|
||||
dialog.call_deferred("popup_centered")
|
||||
|
||||
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)
|
||||
|
||||
func _on_filter_changed(_toggled: bool) -> void:
|
||||
_save_filter_settings()
|
||||
refresh_bullets()
|
||||
|
||||
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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue