multi_node_edit.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*************************************************************************/
  2. /* multi_node_edit.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "multi_node_edit.h"
  30. #include "editor_node.h"
  31. bool MultiNodeEdit::_set(const StringName& p_name, const Variant& p_value){
  32. Node *es = EditorNode::get_singleton()->get_edited_scene();
  33. if (!es)
  34. return false;
  35. String name = p_name;
  36. if (name=="scripts") { // script set is intercepted at object level (check Variant Object::get() ) ,so use a different name
  37. name="script";
  38. }
  39. UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
  40. ur->create_action(TTR("MultiNode Set")+" "+String(name));
  41. for (const List<NodePath>::Element *E=nodes.front();E;E=E->next()) {
  42. if (!es->has_node(E->get()))
  43. continue;
  44. Node*n=es->get_node(E->get());
  45. if (!n)
  46. continue;
  47. if (p_value.get_type() == Variant::NODE_PATH) {
  48. Node *tonode = n->get_node(p_value);
  49. NodePath p_path = n->get_path_to(tonode);
  50. ur->add_do_property(n,name,p_path);
  51. } else {
  52. ur->add_do_property(n,name,p_value);
  53. }
  54. ur->add_undo_property(n,name,n->get(name));
  55. }
  56. ur->add_do_method(EditorNode::get_singleton()->get_property_editor(),"refresh");
  57. ur->add_undo_method(EditorNode::get_singleton()->get_property_editor(),"refresh");
  58. ur->commit_action();
  59. return true;
  60. }
  61. bool MultiNodeEdit::_get(const StringName& p_name,Variant &r_ret) const {
  62. Node *es = EditorNode::get_singleton()->get_edited_scene();
  63. if (!es)
  64. return false;
  65. String name=p_name;
  66. if (name=="scripts") { // script set is intercepted at object level (check Variant Object::get() ) ,so use a different name
  67. name="script";
  68. }
  69. for (const List<NodePath>::Element *E=nodes.front();E;E=E->next()) {
  70. if (!es->has_node(E->get()))
  71. continue;
  72. const Node*n=es->get_node(E->get());
  73. if (!n)
  74. continue;
  75. bool found;
  76. r_ret=n->get(name,&found);
  77. if (found)
  78. return true;
  79. }
  80. return false;
  81. }
  82. void MultiNodeEdit::_get_property_list( List<PropertyInfo> *p_list) const{
  83. HashMap<String,PLData> usage;
  84. Node *es = EditorNode::get_singleton()->get_edited_scene();
  85. if (!es)
  86. return;
  87. int nc=0;
  88. List<PLData*> datas;
  89. for (const List<NodePath>::Element *E=nodes.front();E;E=E->next()) {
  90. if (!es->has_node(E->get()))
  91. continue;
  92. Node*n=es->get_node(E->get());
  93. if (!n)
  94. continue;
  95. List<PropertyInfo> plist;
  96. n->get_property_list(&plist,true);
  97. for(List<PropertyInfo>::Element *F=plist.front();F;F=F->next()) {
  98. if (F->get().name=="script")
  99. continue; //added later manually, since this is intercepted before being set (check Variant Object::get() )
  100. if (!usage.has(F->get().name)) {
  101. PLData pld;
  102. pld.uses=0;
  103. pld.info=F->get();
  104. usage[F->get().name]=pld;
  105. datas.push_back(usage.getptr(F->get().name));
  106. }
  107. usage[F->get().name].uses++;
  108. }
  109. nc++;
  110. }
  111. for (List<PLData*>::Element *E=datas.front();E;E=E->next()) {
  112. if (nc==E->get()->uses) {
  113. p_list->push_back(E->get()->info);
  114. }
  115. }
  116. p_list->push_back(PropertyInfo(Variant::OBJECT,"scripts",PROPERTY_HINT_RESOURCE_TYPE,"Script"));
  117. }
  118. void MultiNodeEdit::clear_nodes() {
  119. nodes.clear();
  120. }
  121. void MultiNodeEdit::add_node(const NodePath& p_node){
  122. nodes.push_back(p_node);
  123. }
  124. MultiNodeEdit::MultiNodeEdit()
  125. {
  126. }