reparent_dialog.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**************************************************************************/
  2. /* reparent_dialog.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "reparent_dialog.h"
  31. #include "core/string/print_string.h"
  32. #include "editor/gui/scene_tree_editor.h"
  33. #include "scene/gui/box_container.h"
  34. #include "scene/gui/check_box.h"
  35. void ReparentDialog::_notification(int p_what) {
  36. switch (p_what) {
  37. case NOTIFICATION_ENTER_TREE: {
  38. connect("confirmed", callable_mp(this, &ReparentDialog::_reparent));
  39. } break;
  40. case NOTIFICATION_EXIT_TREE: {
  41. disconnect("confirmed", callable_mp(this, &ReparentDialog::_reparent));
  42. } break;
  43. }
  44. }
  45. void ReparentDialog::_cancel() {
  46. hide();
  47. }
  48. void ReparentDialog::_reparent() {
  49. if (tree->get_selected()) {
  50. emit_signal(SNAME("reparent"), tree->get_selected()->get_path(), keep_transform->is_pressed());
  51. hide();
  52. }
  53. }
  54. void ReparentDialog::set_current(const HashSet<Node *> &p_selection) {
  55. tree->set_marked(p_selection, false, false);
  56. tree->set_selected(nullptr);
  57. }
  58. void ReparentDialog::_bind_methods() {
  59. ClassDB::bind_method("_cancel", &ReparentDialog::_cancel);
  60. ADD_SIGNAL(MethodInfo("reparent", PropertyInfo(Variant::NODE_PATH, "path"), PropertyInfo(Variant::BOOL, "keep_global_xform")));
  61. }
  62. ReparentDialog::ReparentDialog() {
  63. set_title(TTR("Reparent Node"));
  64. VBoxContainer *vbc = memnew(VBoxContainer);
  65. add_child(vbc);
  66. tree = memnew(SceneTreeEditor(false));
  67. tree->set_show_enabled_subscene(true);
  68. tree->get_scene_tree()->connect("item_activated", callable_mp(this, &ReparentDialog::_reparent));
  69. vbc->add_margin_child(TTR("Select new parent:"), tree, true);
  70. keep_transform = memnew(CheckBox);
  71. keep_transform->set_text(TTR("Keep Global Transform"));
  72. keep_transform->set_pressed(true);
  73. vbc->add_child(keep_transform);
  74. set_ok_button_text(TTR("Reparent"));
  75. }
  76. ReparentDialog::~ReparentDialog() {
  77. }