Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/run/game_view_plugin.h
9900 views
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
31
#pragma once
32
33
#include "editor/debugger/editor_debugger_node.h"
34
#include "editor/debugger/editor_debugger_plugin.h"
35
#include "editor/editor_main_screen.h"
36
#include "editor/plugins/editor_plugin.h"
37
#include "scene/debugger/scene_debugger.h"
38
#include "scene/gui/box_container.h"
39
40
class EmbeddedProcessBase;
41
class VSeparator;
42
class WindowWrapper;
43
class ScriptEditorDebugger;
44
45
class GameViewDebugger : public EditorDebuggerPlugin {
46
GDCLASS(GameViewDebugger, EditorDebuggerPlugin);
47
48
private:
49
Vector<Ref<EditorDebuggerSession>> sessions;
50
51
bool is_feature_enabled = true;
52
int node_type = RuntimeNodeSelect::NODE_TYPE_NONE;
53
bool selection_visible = true;
54
int select_mode = RuntimeNodeSelect::SELECT_MODE_SINGLE;
55
bool mute_audio = false;
56
EditorDebuggerNode::CameraOverride camera_override_mode = EditorDebuggerNode::OVERRIDE_INGAME;
57
58
void _session_started(Ref<EditorDebuggerSession> p_session);
59
void _session_stopped();
60
61
void _feature_profile_changed();
62
63
struct ScreenshotCB {
64
Callable cb;
65
Rect2i rect;
66
};
67
68
int64_t scr_rq_id = 0;
69
HashMap<uint64_t, ScreenshotCB> screenshot_callbacks;
70
71
bool _msg_get_screenshot(const Array &p_args);
72
73
protected:
74
static void _bind_methods();
75
76
public:
77
virtual bool capture(const String &p_message, const Array &p_data, int p_session) override;
78
virtual bool has_capture(const String &p_capture) const override;
79
80
bool add_screenshot_callback(const Callable &p_callaback, const Rect2i &p_rect);
81
82
void set_suspend(bool p_enabled);
83
void next_frame();
84
85
void set_node_type(int p_type);
86
void set_select_mode(int p_mode);
87
88
void set_selection_visible(bool p_visible);
89
90
void set_debug_mute_audio(bool p_enabled);
91
92
void set_camera_override(bool p_enabled);
93
void set_camera_manipulate_mode(EditorDebuggerNode::CameraOverride p_mode);
94
95
void reset_camera_2d_position();
96
void reset_camera_3d_position();
97
98
virtual void setup_session(int p_session_id) override;
99
100
GameViewDebugger();
101
};
102
103
class GameView : public VBoxContainer {
104
GDCLASS(GameView, VBoxContainer);
105
106
enum {
107
CAMERA_RESET_2D,
108
CAMERA_RESET_3D,
109
CAMERA_MODE_INGAME,
110
CAMERA_MODE_EDITORS,
111
EMBED_RUN_GAME_EMBEDDED,
112
EMBED_MAKE_FLOATING_ON_PLAY,
113
};
114
115
enum EmbedSizeMode {
116
SIZE_MODE_FIXED,
117
SIZE_MODE_KEEP_ASPECT,
118
SIZE_MODE_STRETCH,
119
};
120
121
enum EmbedAvailability {
122
EMBED_AVAILABLE,
123
EMBED_NOT_AVAILABLE_FEATURE_NOT_SUPPORTED,
124
EMBED_NOT_AVAILABLE_MINIMIZED,
125
EMBED_NOT_AVAILABLE_MAXIMIZED,
126
EMBED_NOT_AVAILABLE_FULLSCREEN,
127
EMBED_NOT_AVAILABLE_SINGLE_WINDOW_MODE,
128
EMBED_NOT_AVAILABLE_PROJECT_DISPLAY_DRIVER,
129
};
130
131
inline static GameView *singleton = nullptr;
132
133
Ref<GameViewDebugger> debugger;
134
WindowWrapper *window_wrapper = nullptr;
135
136
bool is_feature_enabled = true;
137
int active_sessions = 0;
138
int screen_index_before_start = -1;
139
ScriptEditorDebugger *embedded_script_debugger = nullptr;
140
141
bool embed_on_play = true;
142
bool make_floating_on_play = true;
143
EmbedSizeMode embed_size_mode = SIZE_MODE_FIXED;
144
bool paused = false;
145
Size2 size_paused;
146
147
Rect2i floating_window_rect;
148
int floating_window_screen = -1;
149
150
bool debug_mute_audio = false;
151
152
Button *suspend_button = nullptr;
153
Button *next_frame_button = nullptr;
154
155
Button *node_type_button[RuntimeNodeSelect::NODE_TYPE_MAX];
156
Button *select_mode_button[RuntimeNodeSelect::SELECT_MODE_MAX];
157
158
Button *hide_selection = nullptr;
159
160
Button *debug_mute_audio_button = nullptr;
161
162
Button *camera_override_button = nullptr;
163
MenuButton *camera_override_menu = nullptr;
164
165
VSeparator *embedding_separator = nullptr;
166
Button *fixed_size_button = nullptr;
167
Button *keep_aspect_button = nullptr;
168
Button *stretch_button = nullptr;
169
MenuButton *embed_options_menu = nullptr;
170
Label *game_size_label = nullptr;
171
Panel *panel = nullptr;
172
EmbeddedProcessBase *embedded_process = nullptr;
173
Label *state_label = nullptr;
174
175
void _sessions_changed();
176
177
void _update_debugger_buttons();
178
179
void _handle_shortcut_requested(int p_embed_action);
180
void _toggle_suspend_button();
181
void _suspend_button_toggled(bool p_pressed);
182
183
void _node_type_pressed(int p_option);
184
void _select_mode_pressed(int p_option);
185
void _embed_options_menu_menu_id_pressed(int p_id);
186
void _size_mode_button_pressed(int size_mode);
187
188
void _play_pressed();
189
static void _instance_starting_static(int p_idx, List<String> &r_arguments);
190
void _instance_starting(int p_idx, List<String> &r_arguments);
191
static bool _instance_rq_screenshot_static(const Callable &p_callback);
192
bool _instance_rq_screenshot(const Callable &p_callback);
193
void _stop_pressed();
194
void _embedding_completed();
195
void _embedding_failed();
196
void _embedded_process_updated();
197
void _embedded_process_focused();
198
void _editor_or_project_settings_changed();
199
200
EmbedAvailability _get_embed_available();
201
void _update_ui();
202
void _update_embed_menu_options();
203
void _update_embed_window_size();
204
void _update_arguments_for_instance(int p_idx, List<String> &r_arguments);
205
void _show_update_window_wrapper();
206
207
void _hide_selection_toggled(bool p_pressed);
208
209
void _debug_mute_audio_button_pressed();
210
211
void _camera_override_button_toggled(bool p_pressed);
212
void _camera_override_menu_id_pressed(int p_id);
213
214
void _window_close_request();
215
void _update_floating_window_settings();
216
void _attach_script_debugger();
217
void _detach_script_debugger();
218
void _remote_window_title_changed(String title);
219
220
void _debugger_breaked(bool p_breaked, bool p_can_debug);
221
222
void _feature_profile_changed();
223
224
protected:
225
void _notification(int p_what);
226
227
public:
228
void set_state(const Dictionary &p_state);
229
Dictionary get_state() const;
230
231
void set_window_layout(Ref<ConfigFile> p_layout);
232
void get_window_layout(Ref<ConfigFile> p_layout);
233
234
GameView(Ref<GameViewDebugger> p_debugger, EmbeddedProcessBase *p_embedded_process, WindowWrapper *p_wrapper);
235
};
236
237
class GameViewPluginBase : public EditorPlugin {
238
GDCLASS(GameViewPluginBase, EditorPlugin);
239
240
#ifndef ANDROID_ENABLED
241
GameView *game_view = nullptr;
242
WindowWrapper *window_wrapper = nullptr;
243
#endif // ANDROID_ENABLED
244
245
Ref<GameViewDebugger> debugger;
246
247
String last_editor;
248
249
#ifndef ANDROID_ENABLED
250
void _window_visibility_changed(bool p_visible);
251
#endif // ANDROID_ENABLED
252
void _save_last_editor(const String &p_editor);
253
void _focus_another_editor();
254
bool _is_window_wrapper_enabled() const;
255
256
protected:
257
void _notification(int p_what);
258
#ifndef ANDROID_ENABLED
259
void setup(Ref<GameViewDebugger> p_debugger, EmbeddedProcessBase *p_embedded_process);
260
#endif
261
262
public:
263
virtual String get_plugin_name() const override { return TTRC("Game"); }
264
bool has_main_screen() const override { return true; }
265
virtual void edit(Object *p_object) override {}
266
virtual bool handles(Object *p_object) const override { return false; }
267
virtual void selected_notify() override;
268
269
Ref<GameViewDebugger> get_debugger() const { return debugger; }
270
271
#ifndef ANDROID_ENABLED
272
virtual void make_visible(bool p_visible) override;
273
274
virtual void set_window_layout(Ref<ConfigFile> p_layout) override;
275
virtual void get_window_layout(Ref<ConfigFile> p_layout) override;
276
#endif // ANDROID_ENABLED
277
GameViewPluginBase();
278
};
279
280
class GameViewPlugin : public GameViewPluginBase {
281
GDCLASS(GameViewPlugin, GameViewPluginBase);
282
283
public:
284
GameViewPlugin();
285
};
286
287