reparent_dialog.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*************************************************************************/
  2. /* reparent_dialog.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 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 "reparent_dialog.h"
  30. #include "scene/gui/label.h"
  31. #include "scene/gui/box_container.h"
  32. #include "print_string.h"
  33. void ReparentDialog::_notification(int p_what) {
  34. if (p_what==NOTIFICATION_ENTER_SCENE) {
  35. connect("confirmed", this,"_reparent");
  36. }
  37. if (p_what==NOTIFICATION_DRAW) {
  38. //RID ci = get_canvas_item();
  39. //get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
  40. }
  41. }
  42. void ReparentDialog::_cancel() {
  43. hide();
  44. }
  45. void ReparentDialog::_reparent() {
  46. if (tree->get_selected()) {
  47. emit_signal("reparent",tree->get_selected()->get_path(),node_only->is_pressed());
  48. hide();
  49. }
  50. }
  51. void ReparentDialog::set_current(const Set<Node*>& p_selection) {
  52. tree->set_marked(p_selection,false,false);
  53. //tree->set_selected(p_node->get_parent());
  54. }
  55. void ReparentDialog::_bind_methods() {
  56. ObjectTypeDB::bind_method("_reparent",&ReparentDialog::_reparent);
  57. ObjectTypeDB::bind_method("_cancel",&ReparentDialog::_cancel);
  58. ADD_SIGNAL( MethodInfo("reparent",PropertyInfo(Variant::NODE_PATH,"path"),PropertyInfo(Variant::BOOL,"only_node")));
  59. }
  60. ReparentDialog::ReparentDialog() {
  61. set_title("Reparent Node");
  62. VBoxContainer *vbc = memnew( VBoxContainer );
  63. add_child(vbc);
  64. set_child_rect(vbc);
  65. tree = memnew( SceneTreeEditor(false) );
  66. vbc->add_margin_child("Reparent Location (Select new Parent):",tree,true);
  67. //Label *label = memnew( Label );
  68. //label->set_pos( Point2( 15,8) );
  69. //label->set_text("Reparent Location (Select new Parent):");
  70. node_only = memnew( CheckButton );
  71. add_child(node_only);
  72. node_only->hide();
  73. //vbc->add_margin_child("Options:",node_only);;
  74. //cancel->connect("pressed", this,"_cancel");
  75. get_ok()->set_text("Reparent");
  76. }
  77. ReparentDialog::~ReparentDialog()
  78. {
  79. }