path_3d_editor_plugin.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**************************************************************************/
  2. /* path_3d_editor_plugin.h */
  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. #ifndef PATH_3D_EDITOR_PLUGIN_H
  31. #define PATH_3D_EDITOR_PLUGIN_H
  32. #include "editor/editor_plugin.h"
  33. #include "editor/plugins/node_3d_editor_gizmos.h"
  34. #include "scene/3d/camera_3d.h"
  35. #include "scene/3d/path_3d.h"
  36. #include "scene/gui/separator.h"
  37. class MenuButton;
  38. class Path3DGizmo : public EditorNode3DGizmo {
  39. GDCLASS(Path3DGizmo, EditorNode3DGizmo);
  40. Path3D *path = nullptr;
  41. mutable Vector3 original;
  42. mutable float orig_in_length;
  43. mutable float orig_out_length;
  44. public:
  45. virtual String get_handle_name(int p_id, bool p_secondary) const override;
  46. virtual Variant get_handle_value(int p_id, bool p_secondary) const override;
  47. virtual void set_handle(int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) override;
  48. virtual void commit_handle(int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel = false) override;
  49. virtual void redraw() override;
  50. Path3DGizmo(Path3D *p_path = nullptr);
  51. };
  52. class Path3DGizmoPlugin : public EditorNode3DGizmoPlugin {
  53. GDCLASS(Path3DGizmoPlugin, EditorNode3DGizmoPlugin);
  54. protected:
  55. Ref<EditorNode3DGizmo> create_gizmo(Node3D *p_spatial) override;
  56. public:
  57. String get_gizmo_name() const override;
  58. int get_priority() const override;
  59. Path3DGizmoPlugin();
  60. };
  61. class Path3DEditorPlugin : public EditorPlugin {
  62. GDCLASS(Path3DEditorPlugin, EditorPlugin);
  63. Separator *sep = nullptr;
  64. Button *curve_create = nullptr;
  65. Button *curve_edit = nullptr;
  66. Button *curve_del = nullptr;
  67. Button *curve_close = nullptr;
  68. MenuButton *handle_menu = nullptr;
  69. Path3D *path = nullptr;
  70. void _update_theme();
  71. void _mode_changed(int p_idx);
  72. void _close_curve();
  73. void _handle_option_pressed(int p_option);
  74. bool handle_clicked = false;
  75. bool mirror_handle_angle;
  76. bool mirror_handle_length;
  77. enum HandleOption {
  78. HANDLE_OPTION_ANGLE,
  79. HANDLE_OPTION_LENGTH
  80. };
  81. protected:
  82. void _notification(int p_what);
  83. static void _bind_methods();
  84. public:
  85. Path3D *get_edited_path() { return path; }
  86. static Path3DEditorPlugin *singleton;
  87. virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override;
  88. virtual String get_name() const override { return "Path3D"; }
  89. bool has_main_screen() const override { return false; }
  90. virtual void edit(Object *p_object) override;
  91. virtual bool handles(Object *p_object) const override;
  92. virtual void make_visible(bool p_visible) override;
  93. bool mirror_angle_enabled() { return mirror_handle_angle; }
  94. bool mirror_length_enabled() { return mirror_handle_length; }
  95. bool is_handle_clicked() { return handle_clicked; }
  96. void set_handle_clicked(bool clicked) { handle_clicked = clicked; }
  97. Path3DEditorPlugin();
  98. ~Path3DEditorPlugin();
  99. };
  100. #endif // PATH_3D_EDITOR_PLUGIN_H