2016-06-18 20:46:12 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* multi_node_edit.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 20:16:55 +08:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 20:46:12 +08:00
|
|
|
/*************************************************************************/
|
2019-01-01 19:53:14 +08:00
|
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
2016-06-18 20:46:12 +08:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 07:50:27 +08:00
|
|
|
|
2015-08-25 11:08:45 +08:00
|
|
|
#include "multi_node_edit.h"
|
2017-01-16 15:04:19 +08:00
|
|
|
|
2018-09-23 04:31:56 +08:00
|
|
|
#include "core/math/math_fieldwise.h"
|
2017-03-05 23:44:50 +08:00
|
|
|
#include "editor_node.h"
|
2015-08-25 11:08:45 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
bool MultiNodeEdit::_set(const StringName &p_name, const Variant &p_value) {
|
2017-03-02 17:42:05 +08:00
|
|
|
return _set_impl(p_name, p_value, "");
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
bool MultiNodeEdit::_set_impl(const StringName &p_name, const Variant &p_value, const String &p_field) {
|
2015-08-25 11:08:45 +08:00
|
|
|
Node *es = EditorNode::get_singleton()->get_edited_scene();
|
|
|
|
if (!es)
|
|
|
|
return false;
|
|
|
|
|
2016-06-19 21:12:35 +08:00
|
|
|
String name = p_name;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
if (name == "scripts") { // script set is intercepted at object level (check Variant Object::get() ) ,so use a different name
|
|
|
|
name = "script";
|
2016-06-19 21:12:35 +08:00
|
|
|
}
|
|
|
|
|
2019-06-26 21:08:25 +08:00
|
|
|
UndoRedo *ur = EditorNode::get_undo_redo();
|
2015-08-25 11:08:45 +08:00
|
|
|
|
2018-11-19 08:43:22 +08:00
|
|
|
ur->create_action(TTR("MultiNode Set") + " " + String(name), UndoRedo::MERGE_ENDS);
|
2017-03-05 23:44:50 +08:00
|
|
|
for (const List<NodePath>::Element *E = nodes.front(); E; E = E->next()) {
|
2015-08-25 11:08:45 +08:00
|
|
|
|
|
|
|
if (!es->has_node(E->get()))
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
Node *n = es->get_node(E->get());
|
2015-08-25 11:08:45 +08:00
|
|
|
if (!n)
|
|
|
|
continue;
|
|
|
|
|
2016-10-04 21:49:11 +08:00
|
|
|
if (p_value.get_type() == Variant::NODE_PATH) {
|
|
|
|
Node *tonode = n->get_node(p_value);
|
|
|
|
NodePath p_path = n->get_path_to(tonode);
|
2017-03-05 23:44:50 +08:00
|
|
|
ur->add_do_property(n, name, p_path);
|
2016-10-04 21:49:11 +08:00
|
|
|
} else {
|
2017-03-02 17:42:05 +08:00
|
|
|
Variant new_value;
|
2017-03-05 23:44:50 +08:00
|
|
|
if (p_field == "") {
|
2017-03-02 17:42:05 +08:00
|
|
|
// whole value
|
2017-03-05 23:44:50 +08:00
|
|
|
new_value = p_value;
|
2017-03-02 17:42:05 +08:00
|
|
|
} else {
|
|
|
|
// only one field
|
2017-03-05 23:44:50 +08:00
|
|
|
new_value = fieldwise_assign(n->get(name), p_value, p_field);
|
2017-03-02 17:42:05 +08:00
|
|
|
}
|
2017-03-05 23:44:50 +08:00
|
|
|
ur->add_do_property(n, name, new_value);
|
2016-10-04 21:49:11 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
ur->add_undo_property(n, name, n->get(name));
|
2015-08-25 11:08:45 +08:00
|
|
|
}
|
2018-05-16 04:12:35 +08:00
|
|
|
ur->add_do_method(EditorNode::get_singleton()->get_inspector(), "refresh");
|
|
|
|
ur->add_undo_method(EditorNode::get_singleton()->get_inspector(), "refresh");
|
2015-08-25 11:08:45 +08:00
|
|
|
|
|
|
|
ur->commit_action();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
bool MultiNodeEdit::_get(const StringName &p_name, Variant &r_ret) const {
|
2015-08-25 11:08:45 +08:00
|
|
|
Node *es = EditorNode::get_singleton()->get_edited_scene();
|
|
|
|
if (!es)
|
|
|
|
return false;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
String name = p_name;
|
|
|
|
if (name == "scripts") { // script set is intercepted at object level (check Variant Object::get() ) ,so use a different name
|
|
|
|
name = "script";
|
2016-06-19 21:12:35 +08:00
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
for (const List<NodePath>::Element *E = nodes.front(); E; E = E->next()) {
|
2015-08-25 11:08:45 +08:00
|
|
|
|
|
|
|
if (!es->has_node(E->get()))
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
const Node *n = es->get_node(E->get());
|
2015-08-25 11:08:45 +08:00
|
|
|
if (!n)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bool found;
|
2017-03-05 23:44:50 +08:00
|
|
|
r_ret = n->get(name, &found);
|
2015-08-25 11:08:45 +08:00
|
|
|
if (found)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void MultiNodeEdit::_get_property_list(List<PropertyInfo> *p_list) const {
|
|
|
|
HashMap<String, PLData> usage;
|
2015-08-25 11:08:45 +08:00
|
|
|
|
|
|
|
Node *es = EditorNode::get_singleton()->get_edited_scene();
|
|
|
|
if (!es)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
int nc = 0;
|
2015-08-25 11:08:45 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
List<PLData *> datas;
|
2015-08-25 11:08:45 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
for (const List<NodePath>::Element *E = nodes.front(); E; E = E->next()) {
|
2015-08-25 11:08:45 +08:00
|
|
|
|
|
|
|
if (!es->has_node(E->get()))
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
Node *n = es->get_node(E->get());
|
2015-08-25 11:08:45 +08:00
|
|
|
if (!n)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
List<PropertyInfo> plist;
|
2017-03-05 23:44:50 +08:00
|
|
|
n->get_property_list(&plist, true);
|
2015-08-25 11:08:45 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
for (List<PropertyInfo>::Element *F = plist.front(); F; F = F->next()) {
|
2015-08-25 11:08:45 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
if (F->get().name == "script")
|
2016-06-19 21:12:35 +08:00
|
|
|
continue; //added later manually, since this is intercepted before being set (check Variant Object::get() )
|
2015-08-25 11:08:45 +08:00
|
|
|
if (!usage.has(F->get().name)) {
|
|
|
|
PLData pld;
|
2017-03-05 23:44:50 +08:00
|
|
|
pld.uses = 0;
|
|
|
|
pld.info = F->get();
|
|
|
|
usage[F->get().name] = pld;
|
2015-08-25 11:08:45 +08:00
|
|
|
datas.push_back(usage.getptr(F->get().name));
|
|
|
|
}
|
|
|
|
|
2019-07-06 04:30:01 +08:00
|
|
|
// Make sure only properties with the same exact PropertyInfo data will appear
|
|
|
|
if (usage[F->get().name].info == F->get())
|
|
|
|
usage[F->get().name].uses++;
|
2015-08-25 11:08:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
nc++;
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
for (List<PLData *>::Element *E = datas.front(); E; E = E->next()) {
|
2015-08-25 11:08:45 +08:00
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
if (nc == E->get()->uses) {
|
2015-08-25 11:08:45 +08:00
|
|
|
p_list->push_back(E->get()->info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
p_list->push_back(PropertyInfo(Variant::OBJECT, "scripts", PROPERTY_HINT_RESOURCE_TYPE, "Script"));
|
2015-08-25 11:08:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiNodeEdit::clear_nodes() {
|
|
|
|
nodes.clear();
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
void MultiNodeEdit::add_node(const NodePath &p_node) {
|
2015-08-25 11:08:45 +08:00
|
|
|
nodes.push_back(p_node);
|
|
|
|
}
|
|
|
|
|
2019-11-10 16:37:51 +08:00
|
|
|
int MultiNodeEdit::get_node_count() const {
|
|
|
|
return nodes.size();
|
|
|
|
}
|
2017-03-02 17:42:05 +08:00
|
|
|
|
2019-11-10 16:37:51 +08:00
|
|
|
NodePath MultiNodeEdit::get_node(int p_index) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_index, nodes.size(), NodePath());
|
|
|
|
return nodes[p_index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void MultiNodeEdit::set_property_field(const StringName &p_property, const Variant &p_value, const String &p_field) {
|
2017-03-02 17:42:05 +08:00
|
|
|
_set_impl(p_property, p_value, p_field);
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:44:50 +08:00
|
|
|
MultiNodeEdit::MultiNodeEdit() {
|
2015-08-25 11:08:45 +08:00
|
|
|
}
|