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 "editor/gui/scene_tree_editor.h"
  32. #include "scene/gui/box_container.h"
  33. #include "scene/gui/check_box.h"
  34. void ReparentDialog::_notification(int p_what) {
  35. switch (p_what) {
  36. case NOTIFICATION_ENTER_TREE: {
  37. connect(SceneStringName(confirmed), callable_mp(this, &ReparentDialog::_reparent));
  38. } break;
  39. case NOTIFICATION_EXIT_TREE: {
  40. disconnect(SceneStringName(confirmed), callable_mp(this, &ReparentDialog::_reparent));
  41. } break;
  42. }
  43. }
  44. void ReparentDialog::_cancel() {
  45. hide();
  46. }
  47. void ReparentDialog::_reparent() {
  48. if (tree->get_selected()) {
  49. emit_signal(SNAME("reparent"), tree->get_selected()->get_path(), keep_transform->is_pressed());
  50. hide();
  51. }
  52. }
  53. void ReparentDialog::set_current(const HashSet<Node *> &p_selection) {
  54. tree->set_marked(p_selection, false, false);
  55. tree->set_selected(nullptr);
  56. }
  57. void ReparentDialog::_bind_methods() {
  58. ClassDB::bind_method("_cancel", &ReparentDialog::_cancel);
  59. ADD_SIGNAL(MethodInfo("reparent", PropertyInfo(Variant::NODE_PATH, "path"), PropertyInfo(Variant::BOOL, "keep_global_xform")));
  60. }
  61. ReparentDialog::ReparentDialog() {
  62. set_title(TTR("Reparent Node"));
  63. VBoxContainer *vbc = memnew(VBoxContainer);
  64. add_child(vbc);
  65. tree = memnew(SceneTreeEditor(false));
  66. tree->set_update_when_invisible(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. }