Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/run/game_view_plugin.h
21151 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/runtime_node_select.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
bool selection_avoid_locked = false;
59
bool selection_prefer_group = false;
60
61
void _session_started(Ref<EditorDebuggerSession> p_session);
62
void _session_stopped();
63
64
void _feature_profile_changed();
65
66
struct ScreenshotCB {
67
Callable cb;
68
Rect2i rect;
69
};
70
71
int64_t scr_rq_id = 0;
72
HashMap<uint64_t, ScreenshotCB> screenshot_callbacks;
73
74
bool _msg_get_screenshot(const Array &p_args);
75
76
protected:
77
static void _bind_methods();
78
79
public:
80
virtual bool capture(const String &p_message, const Array &p_data, int p_session) override;
81
virtual bool has_capture(const String &p_capture) const override;
82
83
bool add_screenshot_callback(const Callable &p_callaback, const Rect2i &p_rect);
84
85
void set_suspend(bool p_enabled);
86
void next_frame();
87
88
void set_time_scale(double p_scale);
89
void reset_time_scale();
90
91
void set_node_type(int p_type);
92
void set_select_mode(int p_mode);
93
94
void set_selection_visible(bool p_visible);
95
96
void set_selection_avoid_locked(bool p_enabled);
97
void set_selection_prefer_group(bool p_enabled);
98
99
void set_debug_mute_audio(bool p_enabled);
100
101
void set_camera_override(bool p_enabled);
102
void set_camera_manipulate_mode(EditorDebuggerNode::CameraOverride p_mode);
103
104
void reset_camera_2d_position();
105
void reset_camera_3d_position();
106
107
virtual void setup_session(int p_session_id) override;
108
109
GameViewDebugger();
110
};
111
112
class GameView : public VBoxContainer {
113
GDCLASS(GameView, VBoxContainer);
114
115
enum {
116
CAMERA_RESET_2D,
117
CAMERA_RESET_3D,
118
CAMERA_MODE_INGAME,
119
CAMERA_MODE_EDITORS,
120
EMBED_RUN_GAME_EMBEDDED,
121
EMBED_MAKE_FLOATING_ON_PLAY,
122
SELECTION_AVOID_LOCKED,
123
SELECTION_PREFER_GROUP,
124
};
125
126
enum EmbedSizeMode {
127
SIZE_MODE_FIXED,
128
SIZE_MODE_KEEP_ASPECT,
129
SIZE_MODE_STRETCH,
130
};
131
132
enum EmbedAvailability {
133
EMBED_AVAILABLE,
134
EMBED_NOT_AVAILABLE_FEATURE_NOT_SUPPORTED,
135
EMBED_NOT_AVAILABLE_MINIMIZED,
136
EMBED_NOT_AVAILABLE_MAXIMIZED,
137
EMBED_NOT_AVAILABLE_FULLSCREEN,
138
EMBED_NOT_AVAILABLE_SINGLE_WINDOW_MODE,
139
EMBED_NOT_AVAILABLE_PROJECT_DISPLAY_DRIVER,
140
EMBED_NOT_AVAILABLE_HEADLESS,
141
};
142
143
inline static GameView *singleton = nullptr;
144
145
Ref<GameViewDebugger> debugger;
146
WindowWrapper *window_wrapper = nullptr;
147
148
bool is_feature_enabled = true;
149
int active_sessions = 0;
150
int screen_index_before_start = -1;
151
ScriptEditorDebugger *embedded_script_debugger = nullptr;
152
153
bool embed_on_play = true;
154
bool make_floating_on_play = true;
155
EmbedSizeMode embed_size_mode = SIZE_MODE_FIXED;
156
bool paused = false;
157
Size2 size_paused;
158
159
Rect2i floating_window_rect;
160
int floating_window_screen = -1;
161
162
bool debug_mute_audio = false;
163
164
bool selection_avoid_locked = false;
165
bool selection_prefer_group = false;
166
167
Button *suspend_button = nullptr;
168
Button *next_frame_button = nullptr;
169
170
Button *node_type_button[RuntimeNodeSelect::NODE_TYPE_MAX];
171
Button *select_mode_button[RuntimeNodeSelect::SELECT_MODE_MAX];
172
173
Button *hide_selection = nullptr;
174
MenuButton *selection_options_menu = nullptr;
175
176
Button *debug_mute_audio_button = nullptr;
177
178
Button *camera_override_button = nullptr;
179
MenuButton *camera_override_menu = nullptr;
180
181
HBoxContainer *embedding_hb = nullptr;
182
MenuButton *embed_options_menu = nullptr;
183
Label *game_size_label = nullptr;
184
Panel *panel = nullptr;
185
EmbeddedProcessBase *embedded_process = nullptr;
186
Label *state_label = nullptr;
187
188
int const DEFAULT_TIME_SCALE_INDEX = 5;
189
Array time_scale_range = { 0.0625f, 0.125f, 0.25f, 0.5f, 0.75f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f, 4.0f, 8.0f, 16.0f };
190
Array time_scale_label = { "1/16", "1/8", "1/4", "1/2", "3/4", "1.0", "1.25", "1.5", "1.75", "2.0", "4.0", "8.0", "16.0" };
191
int time_scale_index = DEFAULT_TIME_SCALE_INDEX;
192
193
MenuButton *speed_state_button = nullptr;
194
Button *reset_speed_button = nullptr;
195
196
void _sessions_changed();
197
198
void _update_debugger_buttons();
199
200
void _handle_shortcut_requested(int p_embed_action);
201
void _toggle_suspend_button();
202
void _suspend_button_toggled(bool p_pressed);
203
204
void _node_type_pressed(int p_option);
205
void _select_mode_pressed(int p_option);
206
void _selection_options_menu_id_pressed(int p_id);
207
void _embed_options_menu_menu_id_pressed(int p_id);
208
209
void _reset_time_scales();
210
void _speed_state_menu_pressed(int p_id);
211
void _update_speed_buttons();
212
void _update_speed_state_color();
213
void _update_speed_state_size();
214
215
void _play_pressed();
216
static void _instance_starting_static(int p_idx, List<String> &r_arguments);
217
void _instance_starting(int p_idx, List<String> &r_arguments);
218
static bool _instance_rq_screenshot_static(const Callable &p_callback);
219
bool _instance_rq_screenshot(const Callable &p_callback);
220
void _stop_pressed();
221
void _embedding_completed();
222
void _embedding_failed();
223
void _embedded_process_updated();
224
void _embedded_process_focused();
225
void _editor_or_project_settings_changed();
226
227
EmbedAvailability _get_embed_available();
228
void _update_ui();
229
void _update_embed_menu_options();
230
void _update_embed_window_size();
231
void _update_arguments_for_instance(int p_idx, List<String> &r_arguments);
232
void _show_update_window_wrapper();
233
234
void _hide_selection_toggled(bool p_pressed);
235
236
void _debug_mute_audio_button_pressed();
237
238
void _camera_override_button_toggled(bool p_pressed);
239
void _camera_override_menu_id_pressed(int p_id);
240
241
void _window_close_request();
242
void _update_floating_window_settings();
243
void _attach_script_debugger();
244
void _detach_script_debugger();
245
void _remote_window_title_changed(String title);
246
247
void _debugger_breaked(bool p_breaked, bool p_can_debug);
248
249
void _feature_profile_changed();
250
251
protected:
252
void _notification(int p_what);
253
254
public:
255
void set_state(const Dictionary &p_state);
256
Dictionary get_state() const;
257
258
void set_window_layout(Ref<ConfigFile> p_layout);
259
void get_window_layout(Ref<ConfigFile> p_layout);
260
261
GameView(Ref<GameViewDebugger> p_debugger, EmbeddedProcessBase *p_embedded_process, WindowWrapper *p_wrapper);
262
};
263
264
class GameViewPluginBase : public EditorPlugin {
265
GDCLASS(GameViewPluginBase, EditorPlugin);
266
267
#ifndef ANDROID_ENABLED
268
GameView *game_view = nullptr;
269
WindowWrapper *window_wrapper = nullptr;
270
#endif // ANDROID_ENABLED
271
272
Ref<GameViewDebugger> debugger;
273
274
String last_editor;
275
276
#ifndef ANDROID_ENABLED
277
void _window_visibility_changed(bool p_visible);
278
#endif // ANDROID_ENABLED
279
void _save_last_editor(const String &p_editor);
280
void _focus_another_editor();
281
bool _is_window_wrapper_enabled() const;
282
283
protected:
284
void _notification(int p_what);
285
#ifndef ANDROID_ENABLED
286
void setup(Ref<GameViewDebugger> p_debugger, EmbeddedProcessBase *p_embedded_process);
287
#endif
288
289
public:
290
virtual String get_plugin_name() const override { return TTRC("Game"); }
291
bool has_main_screen() const override { return true; }
292
virtual void edit(Object *p_object) override {}
293
virtual bool handles(Object *p_object) const override { return false; }
294
virtual void selected_notify() override;
295
296
Ref<GameViewDebugger> get_debugger() const { return debugger; }
297
298
#ifndef ANDROID_ENABLED
299
virtual void make_visible(bool p_visible) override;
300
301
virtual void set_window_layout(Ref<ConfigFile> p_layout) override;
302
virtual void get_window_layout(Ref<ConfigFile> p_layout) override;
303
#endif // ANDROID_ENABLED
304
GameViewPluginBase();
305
};
306
307
class GameViewPlugin : public GameViewPluginBase {
308
GDCLASS(GameViewPlugin, GameViewPluginBase);
309
310
public:
311
GameViewPlugin();
312
};
313
314