camera_3d_editor_plugin.cpp 4.5 KB

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