reparent_dialog.cpp 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "scene/gui/box_container.h"
  33. #include "scene/gui/label.h"
  34. #include "scene/gui/tree.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(p_node->get_parent());
  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. //set_child_rect(vbc);
  67. tree = memnew(SceneTreeEditor(false));
  68. tree->set_show_enabled_subscene(true);
  69. tree->get_scene_tree()->connect("item_activated", callable_mp(this, &ReparentDialog::_reparent));
  70. vbc->add_margin_child(TTR("Select new parent:"), tree, true);
  71. keep_transform = memnew(CheckBox);
  72. keep_transform->set_text(TTR("Keep Global Transform"));
  73. keep_transform->set_pressed(true);
  74. vbc->add_child(keep_transform);
  75. //vbc->add_margin_child("Options:",node_only);
  76. //cancel->connect("pressed", this,"_cancel");
  77. set_ok_button_text(TTR("Reparent"));
  78. }
  79. ReparentDialog::~ReparentDialog() {
  80. }