game_view_plugin.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**************************************************************************/
  2. /* game_view_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 GAME_VIEW_PLUGIN_H
  31. #define GAME_VIEW_PLUGIN_H
  32. #include "editor/debugger/editor_debugger_node.h"
  33. #include "editor/plugins/editor_debugger_plugin.h"
  34. #include "editor/plugins/editor_plugin.h"
  35. #include "scene/debugger/scene_debugger.h"
  36. #include "scene/gui/box_container.h"
  37. class GameViewDebugger : public EditorDebuggerPlugin {
  38. GDCLASS(GameViewDebugger, EditorDebuggerPlugin);
  39. private:
  40. Vector<Ref<EditorDebuggerSession>> sessions;
  41. int node_type = RuntimeNodeSelect::NODE_TYPE_NONE;
  42. bool selection_visible = true;
  43. int select_mode = RuntimeNodeSelect::SELECT_MODE_SINGLE;
  44. EditorDebuggerNode::CameraOverride camera_override_mode = EditorDebuggerNode::OVERRIDE_INGAME;
  45. void _session_started(Ref<EditorDebuggerSession> p_session);
  46. void _session_stopped();
  47. protected:
  48. static void _bind_methods();
  49. public:
  50. void set_suspend(bool p_enabled);
  51. void next_frame();
  52. void set_node_type(int p_type);
  53. void set_select_mode(int p_mode);
  54. void set_selection_visible(bool p_visible);
  55. void set_camera_override(bool p_enabled);
  56. void set_camera_manipulate_mode(EditorDebuggerNode::CameraOverride p_mode);
  57. void reset_camera_2d_position();
  58. void reset_camera_3d_position();
  59. virtual void setup_session(int p_session_id) override;
  60. GameViewDebugger() {}
  61. };
  62. class GameView : public VBoxContainer {
  63. GDCLASS(GameView, VBoxContainer);
  64. enum {
  65. CAMERA_RESET_2D,
  66. CAMERA_RESET_3D,
  67. CAMERA_MODE_INGAME,
  68. CAMERA_MODE_EDITORS,
  69. };
  70. Ref<GameViewDebugger> debugger;
  71. int active_sessions = 0;
  72. Button *suspend_button = nullptr;
  73. Button *next_frame_button = nullptr;
  74. Button *node_type_button[RuntimeNodeSelect::NODE_TYPE_MAX];
  75. Button *select_mode_button[RuntimeNodeSelect::SELECT_MODE_MAX];
  76. Button *hide_selection = nullptr;
  77. Button *camera_override_button = nullptr;
  78. MenuButton *camera_override_menu = nullptr;
  79. Panel *panel = nullptr;
  80. void _sessions_changed();
  81. void _update_debugger_buttons();
  82. void _suspend_button_toggled(bool p_pressed);
  83. void _node_type_pressed(int p_option);
  84. void _select_mode_pressed(int p_option);
  85. void _hide_selection_toggled(bool p_pressed);
  86. void _camera_override_button_toggled(bool p_pressed);
  87. void _camera_override_menu_id_pressed(int p_id);
  88. protected:
  89. void _notification(int p_what);
  90. public:
  91. void set_state(const Dictionary &p_state);
  92. Dictionary get_state() const;
  93. GameView(Ref<GameViewDebugger> p_debugger);
  94. };
  95. class GameViewPlugin : public EditorPlugin {
  96. GDCLASS(GameViewPlugin, EditorPlugin);
  97. GameView *game_view = nullptr;
  98. Ref<GameViewDebugger> debugger;
  99. protected:
  100. void _notification(int p_what);
  101. public:
  102. virtual String get_name() const override { return "Game"; }
  103. bool has_main_screen() const override { return true; }
  104. virtual void edit(Object *p_object) override {}
  105. virtual bool handles(Object *p_object) const override { return false; }
  106. virtual void make_visible(bool p_visible) override;
  107. virtual void set_state(const Dictionary &p_state) override;
  108. virtual Dictionary get_state() const override;
  109. GameViewPlugin();
  110. ~GameViewPlugin();
  111. };
  112. #endif // GAME_VIEW_PLUGIN_H