reparent_dialog.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*************************************************************************/
  2. /* reparent_dialog.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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/print_string.h"
  32. #include "scene/gui/box_container.h"
  33. #include "scene/gui/label.h"
  34. void ReparentDialog::_notification(int p_what) {
  35. if (p_what == NOTIFICATION_ENTER_TREE) {
  36. connect("confirmed", this, "_reparent");
  37. }
  38. if (p_what == NOTIFICATION_EXIT_TREE) {
  39. disconnect("confirmed", this, "_reparent");
  40. }
  41. if (p_what == NOTIFICATION_DRAW) {
  42. //RID ci = get_canvas_item();
  43. //get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
  44. }
  45. }
  46. void ReparentDialog::_cancel() {
  47. hide();
  48. }
  49. void ReparentDialog::_reparent() {
  50. if (tree->get_selected()) {
  51. emit_signal("reparent", tree->get_selected()->get_path(), keep_transform->is_pressed());
  52. hide();
  53. }
  54. }
  55. void ReparentDialog::set_current(const Set<Node *> &p_selection) {
  56. tree->set_marked(p_selection, false, false);
  57. //tree->set_selected(p_node->get_parent());
  58. }
  59. void ReparentDialog::_bind_methods() {
  60. ClassDB::bind_method("_reparent", &ReparentDialog::_reparent);
  61. ClassDB::bind_method("_cancel", &ReparentDialog::_cancel);
  62. ADD_SIGNAL(MethodInfo("reparent", PropertyInfo(Variant::NODE_PATH, "path"), PropertyInfo(Variant::BOOL, "keep_global_xform")));
  63. }
  64. ReparentDialog::ReparentDialog() {
  65. set_title(TTR("Reparent Node"));
  66. VBoxContainer *vbc = memnew(VBoxContainer);
  67. add_child(vbc);
  68. //set_child_rect(vbc);
  69. tree = memnew(SceneTreeEditor(false));
  70. tree->set_show_enabled_subscene(true);
  71. vbc->add_margin_child(TTR("Reparent Location (Select new Parent):"), tree, true);
  72. tree->get_scene_tree()->connect("item_activated", this, "_reparent");
  73. //Label *label = memnew( Label );
  74. //label->set_position( Point2( 15,8) );
  75. //label->set_text("Reparent Location (Select new Parent):");
  76. keep_transform = memnew(CheckBox);
  77. keep_transform->set_text(TTR("Keep Global Transform"));
  78. keep_transform->set_pressed(true);
  79. vbc->add_child(keep_transform);
  80. //vbc->add_margin_child("Options:",node_only);
  81. //cancel->connect("pressed", this,"_cancel");
  82. get_ok()->set_text(TTR("Reparent"));
  83. }
  84. ReparentDialog::~ReparentDialog() {
  85. }