camera_3d_editor_plugin.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**************************************************************************/
  2. /* camera_3d_editor_plugin.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 "camera_3d_editor_plugin.h"
  31. #include "editor/editor_node.h"
  32. #include "node_3d_editor_plugin.h"
  33. void Camera3DEditor::_node_removed(Node *p_node) {
  34. if (p_node == node) {
  35. node = nullptr;
  36. Node3DEditor::get_singleton()->set_custom_camera(nullptr);
  37. hide();
  38. }
  39. }
  40. void Camera3DEditor::_pressed() {
  41. Node *sn = (node && preview->is_pressed()) ? node : nullptr;
  42. Node3DEditor::get_singleton()->set_custom_camera(sn);
  43. }
  44. void Camera3DEditor::_bind_methods() {
  45. }
  46. void Camera3DEditor::edit(Node *p_camera) {
  47. node = p_camera;
  48. if (!node) {
  49. preview->set_pressed(false);
  50. Node3DEditor::get_singleton()->set_custom_camera(nullptr);
  51. } else {
  52. if (preview->is_pressed()) {
  53. Node3DEditor::get_singleton()->set_custom_camera(p_camera);
  54. } else {
  55. Node3DEditor::get_singleton()->set_custom_camera(nullptr);
  56. }
  57. }
  58. }
  59. Camera3DEditor::Camera3DEditor() {
  60. preview = memnew(Button);
  61. add_child(preview);
  62. preview->set_text(TTR("Preview"));
  63. preview->set_toggle_mode(true);
  64. preview->set_anchor(SIDE_LEFT, Control::ANCHOR_END);
  65. preview->set_anchor(SIDE_RIGHT, Control::ANCHOR_END);
  66. preview->set_offset(SIDE_LEFT, -60);
  67. preview->set_offset(SIDE_RIGHT, 0);
  68. preview->set_offset(SIDE_TOP, 0);
  69. preview->set_offset(SIDE_BOTTOM, 10);
  70. preview->connect(SceneStringName(pressed), callable_mp(this, &Camera3DEditor::_pressed));
  71. }
  72. void Camera3DEditorPlugin::edit(Object *p_object) {
  73. Node3DEditor::get_singleton()->set_can_preview(Object::cast_to<Camera3D>(p_object));
  74. //camera_editor->edit(Object::cast_to<Node>(p_object));
  75. }
  76. bool Camera3DEditorPlugin::handles(Object *p_object) const {
  77. return p_object->is_class("Camera3D");
  78. }
  79. void Camera3DEditorPlugin::make_visible(bool p_visible) {
  80. if (p_visible) {
  81. //Node3DEditor::get_singleton()->set_can_preview(Object::cast_to<Camera3D>(p_object));
  82. } else {
  83. Node3DEditor::get_singleton()->set_can_preview(nullptr);
  84. }
  85. }
  86. Camera3DEditorPlugin::Camera3DEditorPlugin() {
  87. /* camera_editor = memnew( CameraEditor );
  88. EditorNode::get_singleton()->get_main_screen_control()->add_child(camera_editor);
  89. camera_editor->set_anchor(SIDE_LEFT,Control::ANCHOR_END);
  90. camera_editor->set_anchor(SIDE_RIGHT,Control::ANCHOR_END);
  91. camera_editor->set_offset(SIDE_LEFT,60);
  92. camera_editor->set_offset(SIDE_RIGHT,0);
  93. camera_editor->set_offset(SIDE_TOP,0);
  94. camera_editor->set_offset(SIDE_BOTTOM,10);
  95. camera_editor->hide();
  96. */
  97. }
  98. Camera3DEditorPlugin::~Camera3DEditorPlugin() {
  99. }