123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- #include "multi_node_edit.h"
- #include "core/math/math_fieldwise.h"
- #include "editor_node.h"
- bool MultiNodeEdit::_set(const StringName &p_name, const Variant &p_value) {
- return _set_impl(p_name, p_value, "");
- }
- bool MultiNodeEdit::_set_impl(const StringName &p_name, const Variant &p_value, const String &p_field) {
- Node *es = EditorNode::get_singleton()->get_edited_scene();
- if (!es)
- return false;
- String name = p_name;
- if (name == "scripts") {
- name = "script";
- }
- UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
- ur->create_action(TTR("MultiNode Set") + " " + String(name), UndoRedo::MERGE_ENDS);
- 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;
- if (p_value.get_type() == Variant::NODE_PATH) {
- Node *tonode = n->get_node(p_value);
- NodePath p_path = n->get_path_to(tonode);
- ur->add_do_property(n, name, p_path);
- } else {
- Variant new_value;
- if (p_field == "") {
-
- new_value = p_value;
- } else {
-
- new_value = fieldwise_assign(n->get(name), p_value, p_field);
- }
- ur->add_do_property(n, name, new_value);
- }
- ur->add_undo_property(n, name, n->get(name));
- }
- ur->add_do_method(EditorNode::get_singleton()->get_inspector(), "refresh");
- ur->add_undo_method(EditorNode::get_singleton()->get_inspector(), "refresh");
- 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;
- String name = p_name;
- if (name == "scripts") {
- name = "script";
- }
- 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(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 (F->get().name == "script")
- continue;
- 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);
- }
- }
- p_list->push_back(PropertyInfo(Variant::OBJECT, "scripts", PROPERTY_HINT_RESOURCE_TYPE, "Script"));
- }
- void MultiNodeEdit::clear_nodes() {
- nodes.clear();
- }
- void MultiNodeEdit::add_node(const NodePath &p_node) {
- nodes.push_back(p_node);
- }
- void MultiNodeEdit::set_property_field(const StringName &p_property, const Variant &p_value, const String &p_field) {
- _set_impl(p_property, p_value, p_field);
- }
- MultiNodeEdit::MultiNodeEdit() {
- }
|