godot-plateformer/addons/reedscene/act/StateQuickConfigPanel.gd

90 lines
2.2 KiB
GDScript3
Raw Normal View History

2026-01-04 21:21:01 +08:00
@tool
extends PanelContainer
2026-01-05 11:39:42 +08:00
@onready var vbc_spawn_slot_root: VBoxContainer = %VBC_SpawnSlotRoot
@onready var b_insert: Button = %B_Insert
@onready var b_remove: Button = %B_Remove
@onready var b_add: Button = %B_Add
@onready var rtl_context: RichTextLabel = %RTL_Context
const DEFAULT_CONTEXT: Dictionary = {
"default": "Press insert to generate a act.",
"removerr": "Act need at least on single act.",
"adderr": "Single act count cannot over the count of props.",
"inserterr": "Insert act with empty slot."
}
2026-01-04 21:21:01 +08:00
var _inited: bool = false
var _max_length: int = -1
## 默认的Slot
const SLOT: PackedScene = preload("res://addons/reedscene/act/StateDrapSlot.tscn")
func _ready() -> void:
if not Engine.is_editor_hint():
return
# 连接按钮
2026-01-05 11:39:42 +08:00
b_add.pressed.connect(_on_add_pressed)
b_remove.pressed.connect(_on_remove_pressed)
b_insert.pressed.connect(_on_insert_pressed)
2026-01-04 21:21:01 +08:00
# 初始保证至少有一个 Slot
2026-01-05 11:39:42 +08:00
if vbc_spawn_slot_root.get_child_count() == 0:
2026-01-04 21:21:01 +08:00
_add_slot()
2026-01-05 11:39:42 +08:00
_update_b_remove_state()
2026-01-04 21:21:01 +08:00
func init(info:Dictionary) -> void:
_inited = true
if info.has("size"):
self._max_length = info.get("size") as int
func _on_add_pressed() -> void:
_add_slot()
func _on_remove_pressed() -> void:
_remove_slot()
2026-01-05 11:39:42 +08:00
func _on_insert_pressed() -> void:
_insert_act()
## 插入一個根據當前的條目生成的Act
func _insert_act()-> void:
var slots = vbc_spawn_slot_root.get_children()
for s in slots:
var vs = s as StateDrapSlot
if not vs:
continue ##後續要有報錯Message
## 添加一個Slot不能超過當前Scene的最大prop數量
2026-01-04 21:21:01 +08:00
func _add_slot() -> void:
2026-01-05 11:39:42 +08:00
if vbc_spawn_slot_root.get_child_count() >= _max_length:
2026-01-04 21:21:01 +08:00
return
var slot := SLOT.instantiate()
2026-01-05 11:39:42 +08:00
vbc_spawn_slot_root.add_child(slot)
2026-01-04 21:21:01 +08:00
slot.owner = get_tree().edited_scene_root # 编辑器可保存
2026-01-05 11:39:42 +08:00
slot.init(vbc_spawn_slot_root.get_children().size())
2026-01-04 21:21:01 +08:00
2026-01-05 11:39:42 +08:00
_update_b_remove_state()
2026-01-04 21:21:01 +08:00
2026-01-05 11:39:42 +08:00
## 移除一個Slot最少不能為0
2026-01-04 21:21:01 +08:00
func _remove_slot() -> void:
2026-01-05 11:39:42 +08:00
var count := vbc_spawn_slot_root.get_child_count()
2026-01-04 21:21:01 +08:00
if count <= 1:
return
2026-01-05 11:39:42 +08:00
var last := vbc_spawn_slot_root.get_child(count - 1)
2026-01-04 21:21:01 +08:00
last.queue_free()
2026-01-05 11:39:42 +08:00
_update_b_remove_state()
2026-01-04 21:21:01 +08:00
2026-01-05 11:39:42 +08:00
func _update_b_remove_state() -> void:
b_remove.disabled = vbc_spawn_slot_root.get_child_count() <= 1