-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_process_inspector.gd
More file actions
87 lines (71 loc) · 4.09 KB
/
Copy pathnode_process_inspector.gd
File metadata and controls
87 lines (71 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@tool
extends EditorInspectorPlugin
# Рисует чекбокс "Process Enabled / Process Disabled" в самом верху Inspector для
# любой Node - аналог enabled/SetActive из Unity.
#
# Работает и для одной ноды, и для мульти-выделения (MultiNodeEdit): переключение
# применяется ко всем выбранным узлам сразу, одним undo-действием.
#
# ВКЛ -> process_mode = INHERIT, physics_interpolation_mode = INHERIT, visible = true
# ВЫКЛ -> process_mode = DISABLED, physics_interpolation_mode = OFF, visible = false
#
# visible трогается только у нод, где оно есть (CanvasItem / Node3D).
const TOOLTIP_TEXT := "ВЫКЛ = process_mode Disabled + physics interpolation Off + узел скрыт (visible = false).\nВКЛ = process_mode Inherit + physics interpolation Inherit + узел виден (visible = true).\nПри мульти-выделении применяется ко всем выбранным узлам. Дочерние узлы со значением Inherit наследуют состояние родителя."
# EditorUndoRedoManager, передаётся из plugin.gd (у EditorInspectorPlugin нет get_undo_redo()).
var undo_redo: EditorUndoRedoManager
func _can_handle(object: Object) -> bool:
# Одна нода или синтетический объект мульти-выделения.
return object is Node or object.get_class() == "MultiNodeEdit"
func _parse_begin(object: Object) -> void:
var nodes := _collect_nodes(object)
if nodes.is_empty():
return
var check := CheckBox.new()
check.tooltip_text = TOOLTIP_TEXT
# Состояние берётся по первой ноде (для смешанного выделения это лишь старт).
check.button_pressed = nodes[0].process_mode != Node.PROCESS_MODE_DISABLED
_update_text(check, nodes.size())
check.toggled.connect(_on_toggled.bind(check, nodes))
add_custom_control(check)
func _on_toggled(pressed: bool, check: CheckBox, nodes: Array) -> void:
var process_new := Node.PROCESS_MODE_INHERIT if pressed else Node.PROCESS_MODE_DISABLED
var interp_new := Node.PHYSICS_INTERPOLATION_MODE_INHERIT if pressed else Node.PHYSICS_INTERPOLATION_MODE_OFF
if not _anything_changes(nodes, process_new, interp_new, pressed):
_update_text(check, nodes.size())
return
undo_redo.create_action("Toggle Process Mode")
for node in nodes:
undo_redo.add_do_property(node, "process_mode", process_new)
undo_redo.add_undo_property(node, "process_mode", node.process_mode)
undo_redo.add_do_property(node, "physics_interpolation_mode", interp_new)
undo_redo.add_undo_property(node, "physics_interpolation_mode", node.physics_interpolation_mode)
if _has_visible(node):
undo_redo.add_do_property(node, "visible", pressed)
undo_redo.add_undo_property(node, "visible", node.visible)
undo_redo.commit_action()
_update_text(check, nodes.size())
# --- helpers ----------------------------------------------------------------
func _collect_nodes(object: Object) -> Array:
var result: Array = []
if object is Node:
result.append(object)
elif object.get_class() == "MultiNodeEdit":
# MultiNodeEdit не отдаёт свои ноды напрямую - читаем текущее выделение редактора.
for n in EditorInterface.get_selection().get_selected_nodes():
result.append(n)
return result
func _has_visible(node: Node) -> bool:
# Только CanvasItem / Node3D имеют "visible".
return node is CanvasItem or node is Node3D
func _anything_changes(nodes: Array, process_new: int, interp_new: int, pressed: bool) -> bool:
for node in nodes:
if node.process_mode != process_new:
return true
if node.physics_interpolation_mode != interp_new:
return true
if _has_visible(node) and node.visible != pressed:
return true
return false
func _update_text(check: CheckBox, count: int) -> void:
var base := "Process Enabled" if check.button_pressed else "Process Disabled"
check.text = base if count <= 1 else "%s (%d)" % [base, count]