mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-14 16:03:46 +00:00
Enhance weapon creation dialog with 2D/3D mode support and prefill functionality
This commit is contained in:
parent
b5a1c8c759
commit
c78fa8aa45
4 changed files with 425 additions and 53 deletions
|
|
@ -1,4 +1,4 @@
|
|||
@tool
|
||||
@tool
|
||||
extends Window
|
||||
|
||||
# Popup window for configuring weapon parameters before creation
|
||||
|
|
@ -40,15 +40,37 @@ var random_spread_field: SpinBox
|
|||
var create_button: Button
|
||||
var cancel_button: Button
|
||||
|
||||
func setup(editor_iface: EditorInterface) -> void:
|
||||
# Mode and prefill data
|
||||
var is_3d_mode: bool = true
|
||||
var prefill_data: Dictionary = {}
|
||||
var _ui_built: bool = false
|
||||
|
||||
func setup(editor_iface: EditorInterface, is_3d: bool = true, prefill: Dictionary = {}) -> void:
|
||||
editor_interface = editor_iface
|
||||
is_3d_mode = is_3d
|
||||
prefill_data = prefill
|
||||
|
||||
# Update title based on mode and prefill status
|
||||
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 + " Weapon (" + mode_text + ")"
|
||||
|
||||
# If sprite picker already exists, ensure it has editor context
|
||||
if sprite_picker:
|
||||
_setup_sprite_picker()
|
||||
|
||||
# If UI is already built (setup called after _ready), apply prefill data now
|
||||
if _ui_built:
|
||||
if prefill_data.is_empty():
|
||||
_set_default_values()
|
||||
else:
|
||||
_apply_prefill_data()
|
||||
|
||||
func _ready() -> void:
|
||||
# Window configuration
|
||||
title = "Create New Weapon"
|
||||
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 + " Weapon (" + mode_text + ")"
|
||||
size = Vector2i(750, 950)
|
||||
transient = true
|
||||
exclusive = true
|
||||
|
|
@ -60,7 +82,14 @@ func _ready() -> void:
|
|||
position = (DisplayServer.screen_get_size() - size) / 2
|
||||
|
||||
_build_ui()
|
||||
_set_default_values()
|
||||
_ui_built = true
|
||||
|
||||
# Apply prefill data if provided, otherwise use defaults
|
||||
# Note: this might be overridden by setup() if called via call_deferred
|
||||
if prefill_data.is_empty():
|
||||
_set_default_values()
|
||||
else:
|
||||
_apply_prefill_data()
|
||||
|
||||
func _build_ui() -> void:
|
||||
# Main margin container
|
||||
|
|
@ -326,8 +355,9 @@ func _set_default_values() -> void:
|
|||
short_name_field.text = "NW-1"
|
||||
description_field.text = "A new weapon for testing"
|
||||
|
||||
# Select default bullet (simple_ice_bullet)
|
||||
_select_bullet_by_path("res://Resources/Bullets/simple_ice_bullet.tres")
|
||||
# Select default bullet based on mode
|
||||
var default_bullet = "res://Resources/Bullets/3D/icicle_repeater_bullets_3D.tres" if is_3d_mode else "res://Resources/Bullets/simple_ice_bullet.tres"
|
||||
_select_bullet_by_path(default_bullet)
|
||||
|
||||
# Weapon stats defaults
|
||||
priority_field.value = 10
|
||||
|
|
@ -343,8 +373,11 @@ func _set_default_values() -> void:
|
|||
random_spread_field.value = 0.0
|
||||
|
||||
func _populate_bullet_dropdown() -> void:
|
||||
# Get all bullet resources from the Bullets folder
|
||||
# Get all bullet resources from the appropriate Bullets folder
|
||||
var bullets_dir = "res://Resources/Bullets/"
|
||||
if is_3d_mode:
|
||||
bullets_dir += "3D/"
|
||||
|
||||
var dir = DirAccess.open(bullets_dir)
|
||||
|
||||
if dir == null:
|
||||
|
|
@ -410,6 +443,7 @@ func _on_create_pressed() -> void:
|
|||
"weapon_description": description_field.text,
|
||||
"sprite_resource": sprite_resource,
|
||||
"default_bullet_path": bullet_path_field.text,
|
||||
"is_3d": is_3d_mode,
|
||||
"priority": int(priority_field.value),
|
||||
"ammo_per_shot": int(ammo_per_shot_field.value),
|
||||
"rate_of_fire": rate_of_fire_field.value,
|
||||
|
|
@ -451,6 +485,19 @@ func _validate_inputs() -> bool:
|
|||
if not key.to_upper() == key:
|
||||
_show_warning("Item key should be uppercase")
|
||||
|
||||
# Check if resources already exist
|
||||
var dimension_suffix = "_3D" if is_3d_mode else "_2D"
|
||||
var weapon_resource_path: String = "res://Resources/Weapons/" + key + dimension_suffix + ".tres"
|
||||
var item_resource_path: String = "res://Resources/Items/" + key + "_Item" + dimension_suffix + ".tres"
|
||||
|
||||
if ResourceLoader.exists(weapon_resource_path):
|
||||
_show_error("Weapon resource already exists at:\n" + weapon_resource_path + "\n\nPlease choose a different item key.")
|
||||
return false
|
||||
|
||||
if ResourceLoader.exists(item_resource_path):
|
||||
_show_error("Item resource already exists at:\n" + item_resource_path + "\n\nPlease choose a different item key.")
|
||||
return false
|
||||
|
||||
# Check bullet path
|
||||
if not ResourceLoader.exists(bullet_path_field.text):
|
||||
_show_error("Bullet resource does not exist at: " + bullet_path_field.text)
|
||||
|
|
@ -472,3 +519,45 @@ func _show_warning(message: String) -> void:
|
|||
add_child(dialog)
|
||||
dialog.popup_centered()
|
||||
|
||||
func _apply_prefill_data() -> void:
|
||||
# Apply prefilled data from duplicating an existing weapon
|
||||
if prefill_data.has("weapon_name"):
|
||||
weapon_name_field.text = prefill_data["weapon_name"]
|
||||
if prefill_data.has("item_key"):
|
||||
item_key_field.text = prefill_data["item_key"]
|
||||
if prefill_data.has("ammo_key"):
|
||||
ammo_key_field.text = prefill_data["ammo_key"]
|
||||
if prefill_data.has("short_name"):
|
||||
short_name_field.text = prefill_data["short_name"]
|
||||
if prefill_data.has("description"):
|
||||
description_field.text = prefill_data["description"]
|
||||
if prefill_data.has("sprite_resource") and prefill_data["sprite_resource"] != null:
|
||||
sprite_resource = prefill_data["sprite_resource"]
|
||||
sprite_preview.texture = sprite_resource
|
||||
sprite_picker.edited_resource = sprite_resource
|
||||
if prefill_data.has("bullet_path"):
|
||||
_select_bullet_by_path(prefill_data["bullet_path"])
|
||||
|
||||
# Apply weapon stats
|
||||
if prefill_data.has("priority"):
|
||||
priority_field.value = prefill_data["priority"]
|
||||
if prefill_data.has("ammo_per_shot"):
|
||||
ammo_per_shot_field.value = prefill_data["ammo_per_shot"]
|
||||
if prefill_data.has("rate_of_fire"):
|
||||
rate_of_fire_field.value = prefill_data["rate_of_fire"]
|
||||
if prefill_data.has("bullet_capacity"):
|
||||
bullet_capacity_field.value = prefill_data["bullet_capacity"]
|
||||
if prefill_data.has("reload_time"):
|
||||
reload_time_field.value = prefill_data["reload_time"]
|
||||
if prefill_data.has("infinite_ammo"):
|
||||
infinite_ammo_check.button_pressed = prefill_data["infinite_ammo"]
|
||||
if prefill_data.has("recharge_time"):
|
||||
recharge_time_field.value = prefill_data["recharge_time"]
|
||||
if prefill_data.has("recharge_amount"):
|
||||
recharge_amount_field.value = prefill_data["recharge_amount"]
|
||||
if prefill_data.has("bullets_per_shot"):
|
||||
bullets_per_shot_field.value = prefill_data["bullets_per_shot"]
|
||||
if prefill_data.has("spread_angle"):
|
||||
spread_angle_field.value = prefill_data["spread_angle"]
|
||||
if prefill_data.has("random_spread"):
|
||||
random_spread_field.value = prefill_data["random_spread"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue