summaryrefslogtreecommitdiff
path: root/tools/editor/multi_node_edit.cpp
blob: b5bae82ae038cbf785a95b1abb731418d31d3e60 (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "multi_node_edit.h"
#include "editor_node.h"

bool MultiNodeEdit::_set(const StringName& p_name, const Variant& p_value){

	Node *es = EditorNode::get_singleton()->get_edited_scene();
	if (!es)
		return false;

	UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();

	ur->create_action(TTR("MultiNode Set")+" "+String(p_name));
	for (const List<NodePath>::Element *E=nodes.front();E;E=E->next()) {

		if (!es->has_node(E->get()))
			continue;

		Node*n=es->get_node(E->get());
		if (!n)
			continue;

		ur->add_do_property(n,p_name,p_value);
		ur->add_undo_property(n,p_name,n->get(p_name));

	}

	ur->commit_action();
	return true;
}

bool MultiNodeEdit::_get(const StringName& p_name,Variant &r_ret) const {

	Node *es = EditorNode::get_singleton()->get_edited_scene();
	if (!es)
		return false;

	for (const List<NodePath>::Element *E=nodes.front();E;E=E->next()) {

		if (!es->has_node(E->get()))
			continue;

		const Node*n=es->get_node(E->get());
		if (!n)
			continue;

		bool found;
		r_ret=n->get(p_name,&found);
		if (found)
			return true;

	}

	return false;
}

void MultiNodeEdit::_get_property_list( List<PropertyInfo> *p_list) const{

	HashMap<String,PLData> usage;

	Node *es = EditorNode::get_singleton()->get_edited_scene();
	if (!es)
		return;

	int nc=0;

	List<PLData*> datas;

	for (const List<NodePath>::Element *E=nodes.front();E;E=E->next()) {

		if (!es->has_node(E->get()))
			continue;

		Node*n=es->get_node(E->get());
		if (!n)
			continue;

		List<PropertyInfo> plist;
		n->get_property_list(&plist,true);

		for(List<PropertyInfo>::Element *F=plist.front();F;F=F->next()) {

			if (!usage.has(F->get().name)) {
				PLData pld;
				pld.uses=0;
				pld.info=F->get();
				usage[F->get().name]=pld;
				datas.push_back(usage.getptr(F->get().name));
			}

			usage[F->get().name].uses++;
		}

		nc++;
	}

	for (List<PLData*>::Element *E=datas.front();E;E=E->next()) {

		if (nc==E->get()->uses) {
			p_list->push_back(E->get()->info);
		}
	}


}

void MultiNodeEdit::clear_nodes() {

	nodes.clear();
}

void MultiNodeEdit::add_node(const NodePath& p_node){

	nodes.push_back(p_node);
}

MultiNodeEdit::MultiNodeEdit()
{
}