game_view_plugin.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. /**************************************************************************/
  2. /* game_view_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 "game_view_plugin.h"
  31. #include "core/debugger/debugger_marshalls.h"
  32. #include "editor/editor_main_screen.h"
  33. #include "editor/editor_node.h"
  34. #include "editor/editor_settings.h"
  35. #include "editor/themes/editor_scale.h"
  36. #include "scene/gui/button.h"
  37. #include "scene/gui/menu_button.h"
  38. #include "scene/gui/panel.h"
  39. #include "scene/gui/separator.h"
  40. void GameViewDebugger::_session_started(Ref<EditorDebuggerSession> p_session) {
  41. Array setup_data;
  42. Dictionary settings;
  43. settings["editors/panning/2d_editor_panning_scheme"] = EDITOR_GET("editors/panning/2d_editor_panning_scheme");
  44. settings["editors/panning/simple_panning"] = EDITOR_GET("editors/panning/simple_panning");
  45. settings["editors/panning/warped_mouse_panning"] = EDITOR_GET("editors/panning/warped_mouse_panning");
  46. settings["editors/panning/2d_editor_pan_speed"] = EDITOR_GET("editors/panning/2d_editor_pan_speed");
  47. settings["canvas_item_editor/pan_view"] = DebuggerMarshalls::serialize_key_shortcut(ED_GET_SHORTCUT("canvas_item_editor/pan_view"));
  48. setup_data.append(settings);
  49. p_session->send_message("scene:runtime_node_select_setup", setup_data);
  50. Array type;
  51. type.append(node_type);
  52. p_session->send_message("scene:runtime_node_select_set_type", type);
  53. Array visible;
  54. visible.append(selection_visible);
  55. p_session->send_message("scene:runtime_node_select_set_visible", visible);
  56. Array mode;
  57. mode.append(select_mode);
  58. p_session->send_message("scene:runtime_node_select_set_mode", mode);
  59. emit_signal(SNAME("session_started"));
  60. }
  61. void GameViewDebugger::_session_stopped() {
  62. emit_signal(SNAME("session_stopped"));
  63. }
  64. void GameViewDebugger::set_suspend(bool p_enabled) {
  65. Array message;
  66. message.append(p_enabled);
  67. for (Ref<EditorDebuggerSession> &I : sessions) {
  68. if (I->is_active()) {
  69. I->send_message("scene:suspend_changed", message);
  70. }
  71. }
  72. }
  73. void GameViewDebugger::next_frame() {
  74. for (Ref<EditorDebuggerSession> &I : sessions) {
  75. if (I->is_active()) {
  76. I->send_message("scene:next_frame", Array());
  77. }
  78. }
  79. }
  80. void GameViewDebugger::set_node_type(int p_type) {
  81. node_type = p_type;
  82. Array message;
  83. message.append(p_type);
  84. for (Ref<EditorDebuggerSession> &I : sessions) {
  85. if (I->is_active()) {
  86. I->send_message("scene:runtime_node_select_set_type", message);
  87. }
  88. }
  89. }
  90. void GameViewDebugger::set_selection_visible(bool p_visible) {
  91. selection_visible = p_visible;
  92. Array message;
  93. message.append(p_visible);
  94. for (Ref<EditorDebuggerSession> &I : sessions) {
  95. if (I->is_active()) {
  96. I->send_message("scene:runtime_node_select_set_visible", message);
  97. }
  98. }
  99. }
  100. void GameViewDebugger::set_select_mode(int p_mode) {
  101. select_mode = p_mode;
  102. Array message;
  103. message.append(p_mode);
  104. for (Ref<EditorDebuggerSession> &I : sessions) {
  105. if (I->is_active()) {
  106. I->send_message("scene:runtime_node_select_set_mode", message);
  107. }
  108. }
  109. }
  110. void GameViewDebugger::set_camera_override(bool p_enabled) {
  111. EditorDebuggerNode::get_singleton()->set_camera_override(p_enabled ? camera_override_mode : EditorDebuggerNode::OVERRIDE_NONE);
  112. }
  113. void GameViewDebugger::set_camera_manipulate_mode(EditorDebuggerNode::CameraOverride p_mode) {
  114. camera_override_mode = p_mode;
  115. if (EditorDebuggerNode::get_singleton()->get_camera_override() != EditorDebuggerNode::OVERRIDE_NONE) {
  116. set_camera_override(true);
  117. }
  118. }
  119. void GameViewDebugger::reset_camera_2d_position() {
  120. for (Ref<EditorDebuggerSession> &I : sessions) {
  121. if (I->is_active()) {
  122. I->send_message("scene:runtime_node_select_reset_camera_2d", Array());
  123. }
  124. }
  125. }
  126. void GameViewDebugger::reset_camera_3d_position() {
  127. for (Ref<EditorDebuggerSession> &I : sessions) {
  128. if (I->is_active()) {
  129. I->send_message("scene:runtime_node_select_reset_camera_3d", Array());
  130. }
  131. }
  132. }
  133. void GameViewDebugger::setup_session(int p_session_id) {
  134. Ref<EditorDebuggerSession> session = get_session(p_session_id);
  135. ERR_FAIL_COND(session.is_null());
  136. sessions.append(session);
  137. session->connect("started", callable_mp(this, &GameViewDebugger::_session_started).bind(session));
  138. session->connect("stopped", callable_mp(this, &GameViewDebugger::_session_stopped));
  139. }
  140. void GameViewDebugger::_bind_methods() {
  141. ADD_SIGNAL(MethodInfo("session_started"));
  142. ADD_SIGNAL(MethodInfo("session_stopped"));
  143. }
  144. ///////
  145. void GameView::_sessions_changed() {
  146. // The debugger session's `session_started/stopped` signal can be unreliable, so count it manually.
  147. active_sessions = 0;
  148. Array sessions = debugger->get_sessions();
  149. for (int i = 0; i < sessions.size(); i++) {
  150. if (Object::cast_to<EditorDebuggerSession>(sessions[i])->is_active()) {
  151. active_sessions++;
  152. }
  153. }
  154. _update_debugger_buttons();
  155. }
  156. void GameView::_update_debugger_buttons() {
  157. bool empty = active_sessions == 0;
  158. suspend_button->set_disabled(empty);
  159. camera_override_button->set_disabled(empty);
  160. PopupMenu *menu = camera_override_menu->get_popup();
  161. bool disable_camera_reset = empty || !camera_override_button->is_pressed() || !menu->is_item_checked(menu->get_item_index(CAMERA_MODE_INGAME));
  162. menu->set_item_disabled(CAMERA_RESET_2D, disable_camera_reset);
  163. menu->set_item_disabled(CAMERA_RESET_3D, disable_camera_reset);
  164. if (empty) {
  165. suspend_button->set_pressed(false);
  166. camera_override_button->set_pressed(false);
  167. }
  168. next_frame_button->set_disabled(!suspend_button->is_pressed());
  169. }
  170. void GameView::_suspend_button_toggled(bool p_pressed) {
  171. _update_debugger_buttons();
  172. debugger->set_suspend(p_pressed);
  173. }
  174. void GameView::_node_type_pressed(int p_option) {
  175. RuntimeNodeSelect::NodeType type = (RuntimeNodeSelect::NodeType)p_option;
  176. for (int i = 0; i < RuntimeNodeSelect::NODE_TYPE_MAX; i++) {
  177. node_type_button[i]->set_pressed_no_signal(i == type);
  178. }
  179. _update_debugger_buttons();
  180. debugger->set_node_type(type);
  181. }
  182. void GameView::_select_mode_pressed(int p_option) {
  183. RuntimeNodeSelect::SelectMode mode = (RuntimeNodeSelect::SelectMode)p_option;
  184. for (int i = 0; i < RuntimeNodeSelect::SELECT_MODE_MAX; i++) {
  185. select_mode_button[i]->set_pressed_no_signal(i == mode);
  186. }
  187. debugger->set_select_mode(mode);
  188. }
  189. void GameView::_hide_selection_toggled(bool p_pressed) {
  190. hide_selection->set_button_icon(get_editor_theme_icon(p_pressed ? SNAME("GuiVisibilityHidden") : SNAME("GuiVisibilityVisible")));
  191. debugger->set_selection_visible(!p_pressed);
  192. }
  193. void GameView::_camera_override_button_toggled(bool p_pressed) {
  194. _update_debugger_buttons();
  195. debugger->set_camera_override(p_pressed);
  196. }
  197. void GameView::_camera_override_menu_id_pressed(int p_id) {
  198. PopupMenu *menu = camera_override_menu->get_popup();
  199. if (p_id != CAMERA_RESET_2D && p_id != CAMERA_RESET_3D) {
  200. for (int i = 0; i < menu->get_item_count(); i++) {
  201. menu->set_item_checked(i, false);
  202. }
  203. }
  204. switch (p_id) {
  205. case CAMERA_RESET_2D: {
  206. debugger->reset_camera_2d_position();
  207. } break;
  208. case CAMERA_RESET_3D: {
  209. debugger->reset_camera_3d_position();
  210. } break;
  211. case CAMERA_MODE_INGAME: {
  212. debugger->set_camera_manipulate_mode(EditorDebuggerNode::OVERRIDE_INGAME);
  213. menu->set_item_checked(menu->get_item_index(p_id), true);
  214. _update_debugger_buttons();
  215. } break;
  216. case CAMERA_MODE_EDITORS: {
  217. debugger->set_camera_manipulate_mode(EditorDebuggerNode::OVERRIDE_EDITORS);
  218. menu->set_item_checked(menu->get_item_index(p_id), true);
  219. _update_debugger_buttons();
  220. } break;
  221. }
  222. }
  223. void GameView::_notification(int p_what) {
  224. switch (p_what) {
  225. case NOTIFICATION_THEME_CHANGED: {
  226. suspend_button->set_button_icon(get_editor_theme_icon(SNAME("Pause")));
  227. next_frame_button->set_button_icon(get_editor_theme_icon(SNAME("NextFrame")));
  228. node_type_button[RuntimeNodeSelect::NODE_TYPE_NONE]->set_button_icon(get_editor_theme_icon(SNAME("InputEventJoypadMotion")));
  229. node_type_button[RuntimeNodeSelect::NODE_TYPE_2D]->set_button_icon(get_editor_theme_icon(SNAME("2DNodes")));
  230. #ifndef _3D_DISABLED
  231. node_type_button[RuntimeNodeSelect::NODE_TYPE_3D]->set_button_icon(get_editor_theme_icon(SNAME("Node3D")));
  232. #endif // _3D_DISABLED
  233. select_mode_button[RuntimeNodeSelect::SELECT_MODE_SINGLE]->set_button_icon(get_editor_theme_icon(SNAME("ToolSelect")));
  234. select_mode_button[RuntimeNodeSelect::SELECT_MODE_LIST]->set_button_icon(get_editor_theme_icon(SNAME("ListSelect")));
  235. hide_selection->set_button_icon(get_editor_theme_icon(hide_selection->is_pressed() ? SNAME("GuiVisibilityHidden") : SNAME("GuiVisibilityVisible")));
  236. camera_override_button->set_button_icon(get_editor_theme_icon(SNAME("Camera")));
  237. camera_override_menu->set_button_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
  238. } break;
  239. }
  240. }
  241. void GameView::set_state(const Dictionary &p_state) {
  242. if (p_state.has("hide_selection")) {
  243. hide_selection->set_pressed(p_state["hide_selection"]);
  244. _hide_selection_toggled(hide_selection->is_pressed());
  245. }
  246. if (p_state.has("select_mode")) {
  247. _select_mode_pressed(p_state["select_mode"]);
  248. }
  249. if (p_state.has("camera_override_mode")) {
  250. _camera_override_menu_id_pressed(p_state["camera_override_mode"]);
  251. }
  252. }
  253. Dictionary GameView::get_state() const {
  254. Dictionary d;
  255. d["hide_selection"] = hide_selection->is_pressed();
  256. for (int i = 0; i < RuntimeNodeSelect::SELECT_MODE_MAX; i++) {
  257. if (select_mode_button[i]->is_pressed()) {
  258. d["select_mode"] = i;
  259. break;
  260. }
  261. }
  262. PopupMenu *menu = camera_override_menu->get_popup();
  263. for (int i = CAMERA_MODE_INGAME; i < CAMERA_MODE_EDITORS + 1; i++) {
  264. if (menu->is_item_checked(menu->get_item_index(i))) {
  265. d["camera_override_mode"] = i;
  266. break;
  267. }
  268. }
  269. return d;
  270. }
  271. GameView::GameView(Ref<GameViewDebugger> p_debugger) {
  272. debugger = p_debugger;
  273. // Add some margin to the sides for better aesthetics.
  274. // This prevents the first button's hover/pressed effect from "touching" the panel's border,
  275. // which looks ugly.
  276. MarginContainer *toolbar_margin = memnew(MarginContainer);
  277. toolbar_margin->add_theme_constant_override("margin_left", 4 * EDSCALE);
  278. toolbar_margin->add_theme_constant_override("margin_right", 4 * EDSCALE);
  279. add_child(toolbar_margin);
  280. HBoxContainer *main_menu_hbox = memnew(HBoxContainer);
  281. toolbar_margin->add_child(main_menu_hbox);
  282. suspend_button = memnew(Button);
  283. main_menu_hbox->add_child(suspend_button);
  284. suspend_button->set_toggle_mode(true);
  285. suspend_button->set_theme_type_variation("FlatButton");
  286. suspend_button->connect(SceneStringName(toggled), callable_mp(this, &GameView::_suspend_button_toggled));
  287. suspend_button->set_tooltip_text(TTR("Suspend"));
  288. next_frame_button = memnew(Button);
  289. main_menu_hbox->add_child(next_frame_button);
  290. next_frame_button->set_theme_type_variation("FlatButton");
  291. next_frame_button->connect(SceneStringName(pressed), callable_mp(*debugger, &GameViewDebugger::next_frame));
  292. next_frame_button->set_tooltip_text(TTR("Next Frame"));
  293. main_menu_hbox->add_child(memnew(VSeparator));
  294. node_type_button[RuntimeNodeSelect::NODE_TYPE_NONE] = memnew(Button);
  295. main_menu_hbox->add_child(node_type_button[RuntimeNodeSelect::NODE_TYPE_NONE]);
  296. node_type_button[RuntimeNodeSelect::NODE_TYPE_NONE]->set_text(TTR("Input"));
  297. node_type_button[RuntimeNodeSelect::NODE_TYPE_NONE]->set_toggle_mode(true);
  298. node_type_button[RuntimeNodeSelect::NODE_TYPE_NONE]->set_pressed(true);
  299. node_type_button[RuntimeNodeSelect::NODE_TYPE_NONE]->set_theme_type_variation("FlatButton");
  300. node_type_button[RuntimeNodeSelect::NODE_TYPE_NONE]->connect(SceneStringName(pressed), callable_mp(this, &GameView::_node_type_pressed).bind(RuntimeNodeSelect::NODE_TYPE_NONE));
  301. node_type_button[RuntimeNodeSelect::NODE_TYPE_NONE]->set_tooltip_text(TTR("Allow game input."));
  302. node_type_button[RuntimeNodeSelect::NODE_TYPE_2D] = memnew(Button);
  303. main_menu_hbox->add_child(node_type_button[RuntimeNodeSelect::NODE_TYPE_2D]);
  304. node_type_button[RuntimeNodeSelect::NODE_TYPE_2D]->set_text(TTR("2D"));
  305. node_type_button[RuntimeNodeSelect::NODE_TYPE_2D]->set_toggle_mode(true);
  306. node_type_button[RuntimeNodeSelect::NODE_TYPE_2D]->set_theme_type_variation("FlatButton");
  307. node_type_button[RuntimeNodeSelect::NODE_TYPE_2D]->connect(SceneStringName(pressed), callable_mp(this, &GameView::_node_type_pressed).bind(RuntimeNodeSelect::NODE_TYPE_2D));
  308. node_type_button[RuntimeNodeSelect::NODE_TYPE_2D]->set_tooltip_text(TTR("Disable game input and allow to select Node2Ds, Controls, and manipulate the 2D camera."));
  309. #ifndef _3D_DISABLED
  310. node_type_button[RuntimeNodeSelect::NODE_TYPE_3D] = memnew(Button);
  311. main_menu_hbox->add_child(node_type_button[RuntimeNodeSelect::NODE_TYPE_3D]);
  312. node_type_button[RuntimeNodeSelect::NODE_TYPE_3D]->set_text(TTR("3D"));
  313. node_type_button[RuntimeNodeSelect::NODE_TYPE_3D]->set_toggle_mode(true);
  314. node_type_button[RuntimeNodeSelect::NODE_TYPE_3D]->set_theme_type_variation("FlatButton");
  315. node_type_button[RuntimeNodeSelect::NODE_TYPE_3D]->connect(SceneStringName(pressed), callable_mp(this, &GameView::_node_type_pressed).bind(RuntimeNodeSelect::NODE_TYPE_3D));
  316. node_type_button[RuntimeNodeSelect::NODE_TYPE_3D]->set_tooltip_text(TTR("Disable game input and allow to select Node3Ds and manipulate the 3D camera."));
  317. #endif // _3D_DISABLED
  318. main_menu_hbox->add_child(memnew(VSeparator));
  319. hide_selection = memnew(Button);
  320. main_menu_hbox->add_child(hide_selection);
  321. hide_selection->set_toggle_mode(true);
  322. hide_selection->set_theme_type_variation("FlatButton");
  323. hide_selection->connect(SceneStringName(toggled), callable_mp(this, &GameView::_hide_selection_toggled));
  324. hide_selection->set_tooltip_text(TTR("Toggle Selection Visibility"));
  325. main_menu_hbox->add_child(memnew(VSeparator));
  326. select_mode_button[RuntimeNodeSelect::SELECT_MODE_SINGLE] = memnew(Button);
  327. main_menu_hbox->add_child(select_mode_button[RuntimeNodeSelect::SELECT_MODE_SINGLE]);
  328. select_mode_button[RuntimeNodeSelect::SELECT_MODE_SINGLE]->set_toggle_mode(true);
  329. select_mode_button[RuntimeNodeSelect::SELECT_MODE_SINGLE]->set_pressed(true);
  330. select_mode_button[RuntimeNodeSelect::SELECT_MODE_SINGLE]->set_theme_type_variation("FlatButton");
  331. select_mode_button[RuntimeNodeSelect::SELECT_MODE_SINGLE]->connect(SceneStringName(pressed), callable_mp(this, &GameView::_select_mode_pressed).bind(RuntimeNodeSelect::SELECT_MODE_SINGLE));
  332. select_mode_button[RuntimeNodeSelect::SELECT_MODE_SINGLE]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_select", TTR("Select Mode"), Key::Q));
  333. select_mode_button[RuntimeNodeSelect::SELECT_MODE_SINGLE]->set_shortcut_context(this);
  334. select_mode_button[RuntimeNodeSelect::SELECT_MODE_SINGLE]->set_tooltip_text(keycode_get_string((Key)KeyModifierMask::CMD_OR_CTRL) + TTR("Alt+RMB: Show list of all nodes at position clicked."));
  335. select_mode_button[RuntimeNodeSelect::SELECT_MODE_LIST] = memnew(Button);
  336. main_menu_hbox->add_child(select_mode_button[RuntimeNodeSelect::SELECT_MODE_LIST]);
  337. select_mode_button[RuntimeNodeSelect::SELECT_MODE_LIST]->set_toggle_mode(true);
  338. select_mode_button[RuntimeNodeSelect::SELECT_MODE_LIST]->set_theme_type_variation("FlatButton");
  339. select_mode_button[RuntimeNodeSelect::SELECT_MODE_LIST]->connect(SceneStringName(pressed), callable_mp(this, &GameView::_select_mode_pressed).bind(RuntimeNodeSelect::SELECT_MODE_LIST));
  340. select_mode_button[RuntimeNodeSelect::SELECT_MODE_LIST]->set_tooltip_text(TTR("Show list of selectable nodes at position clicked."));
  341. main_menu_hbox->add_child(memnew(VSeparator));
  342. camera_override_button = memnew(Button);
  343. main_menu_hbox->add_child(camera_override_button);
  344. camera_override_button->set_toggle_mode(true);
  345. camera_override_button->set_theme_type_variation("FlatButton");
  346. camera_override_button->connect(SceneStringName(toggled), callable_mp(this, &GameView::_camera_override_button_toggled));
  347. camera_override_button->set_tooltip_text(TTR("Override the in-game camera."));
  348. camera_override_menu = memnew(MenuButton);
  349. main_menu_hbox->add_child(camera_override_menu);
  350. camera_override_menu->set_flat(false);
  351. camera_override_menu->set_theme_type_variation("FlatMenuButton");
  352. camera_override_menu->set_h_size_flags(SIZE_SHRINK_END);
  353. camera_override_menu->set_tooltip_text(TTR("Camera Override Options"));
  354. PopupMenu *menu = camera_override_menu->get_popup();
  355. menu->connect(SceneStringName(id_pressed), callable_mp(this, &GameView::_camera_override_menu_id_pressed));
  356. menu->add_item(TTR("Reset 2D Camera"), CAMERA_RESET_2D);
  357. menu->add_item(TTR("Reset 3D Camera"), CAMERA_RESET_3D);
  358. menu->add_separator();
  359. menu->add_radio_check_item(TTR("Manipulate In-Game"), CAMERA_MODE_INGAME);
  360. menu->set_item_checked(menu->get_item_index(CAMERA_MODE_INGAME), true);
  361. menu->add_radio_check_item(TTR("Manipulate From Editors"), CAMERA_MODE_EDITORS);
  362. _update_debugger_buttons();
  363. panel = memnew(Panel);
  364. add_child(panel);
  365. panel->set_theme_type_variation("GamePanel");
  366. panel->set_v_size_flags(SIZE_EXPAND_FILL);
  367. p_debugger->connect("session_started", callable_mp(this, &GameView::_sessions_changed));
  368. p_debugger->connect("session_stopped", callable_mp(this, &GameView::_sessions_changed));
  369. }
  370. ///////
  371. void GameViewPlugin::make_visible(bool p_visible) {
  372. game_view->set_visible(p_visible);
  373. }
  374. void GameViewPlugin::set_state(const Dictionary &p_state) {
  375. game_view->set_state(p_state);
  376. }
  377. Dictionary GameViewPlugin::get_state() const {
  378. return game_view->get_state();
  379. }
  380. void GameViewPlugin::_notification(int p_what) {
  381. switch (p_what) {
  382. case NOTIFICATION_ENTER_TREE: {
  383. add_debugger_plugin(debugger);
  384. } break;
  385. case NOTIFICATION_EXIT_TREE: {
  386. remove_debugger_plugin(debugger);
  387. } break;
  388. }
  389. }
  390. GameViewPlugin::GameViewPlugin() {
  391. debugger.instantiate();
  392. game_view = memnew(GameView(debugger));
  393. game_view->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  394. EditorNode::get_singleton()->get_editor_main_screen()->get_control()->add_child(game_view);
  395. game_view->hide();
  396. }
  397. GameViewPlugin::~GameViewPlugin() {
  398. }