|
32 | 32 |
|
33 | 33 | #include "core/config/project_settings.h" |
34 | 34 | #include "core/debugger/debugger_marshalls.h" |
| 35 | +#include "core/debugger/engine_debugger.h" |
35 | 36 | #include "core/string/translation_server.h" |
36 | 37 | #include "editor/debugger/editor_debugger_node.h" |
37 | 38 | #include "editor/debugger/script_editor_debugger.h" |
@@ -225,6 +226,61 @@ void GameViewDebugger::_bind_methods() { |
225 | 226 | ADD_SIGNAL(MethodInfo("session_stopped")); |
226 | 227 | } |
227 | 228 |
|
| 229 | +bool GameViewDebugger::add_screenshot_callback(const Callable &p_callaback, const Rect2i &p_rect) { |
| 230 | + bool found = false; |
| 231 | + for (Ref<EditorDebuggerSession> &I : sessions) { |
| 232 | + if (I->is_active()) { |
| 233 | + ScreenshotCB sd; |
| 234 | + sd.cb = p_callaback; |
| 235 | + sd.rect = p_rect; |
| 236 | + screenshot_callbacks[scr_rq_id] = sd; |
| 237 | + |
| 238 | + Array arr; |
| 239 | + arr.append(scr_rq_id); |
| 240 | + I->send_message("scene:rq_screenshot", arr); |
| 241 | + scr_rq_id++; |
| 242 | + found = true; |
| 243 | + } |
| 244 | + } |
| 245 | + return found; |
| 246 | +} |
| 247 | + |
| 248 | +bool GameViewDebugger::_msg_get_screenshot(const Array &p_args) { |
| 249 | + ERR_FAIL_COND_V_MSG(p_args.size() != 4, false, "get_screenshot: invalid number of arguments"); |
| 250 | + |
| 251 | + int64_t id = p_args[0]; |
| 252 | + int64_t w = p_args[1]; |
| 253 | + int64_t h = p_args[2]; |
| 254 | + const String &path = p_args[3]; |
| 255 | + |
| 256 | + if (screenshot_callbacks.has(id)) { |
| 257 | + if (screenshot_callbacks[id].cb.is_valid()) { |
| 258 | + screenshot_callbacks[id].cb.call(w, h, path, screenshot_callbacks[id].rect); |
| 259 | + } |
| 260 | + screenshot_callbacks.erase(id); |
| 261 | + } |
| 262 | + return true; |
| 263 | +} |
| 264 | + |
| 265 | +bool GameViewDebugger::capture(const String &p_message, const Array &p_data, int p_session) { |
| 266 | + Ref<EditorDebuggerSession> session = get_session(p_session); |
| 267 | + ERR_FAIL_COND_V(session.is_null(), true); |
| 268 | + |
| 269 | + if (p_message == "game_view:get_screenshot") { |
| 270 | + return _msg_get_screenshot(p_data); |
| 271 | + } else { |
| 272 | + // Any other messages with this prefix should be ignored. |
| 273 | + WARN_PRINT("GameViewDebugger unknown message: " + p_message); |
| 274 | + return false; |
| 275 | + } |
| 276 | + |
| 277 | + return true; |
| 278 | +} |
| 279 | + |
| 280 | +bool GameViewDebugger::has_capture(const String &p_capture) const { |
| 281 | + return p_capture == "game_view"; |
| 282 | +} |
| 283 | + |
228 | 284 | GameViewDebugger::GameViewDebugger() { |
229 | 285 | EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &GameViewDebugger::_feature_profile_changed)); |
230 | 286 | } |
@@ -280,6 +336,23 @@ void GameView::_instance_starting(int p_idx, List<String> &r_arguments) { |
280 | 336 | _update_arguments_for_instance(p_idx, r_arguments); |
281 | 337 | } |
282 | 338 |
|
| 339 | +bool GameView::_instance_rq_screenshot_static(const Callable &p_callback) { |
| 340 | + ERR_FAIL_NULL_V(singleton, false); |
| 341 | + return singleton->_instance_rq_screenshot(p_callback); |
| 342 | +} |
| 343 | + |
| 344 | +bool GameView::_instance_rq_screenshot(const Callable &p_callback) { |
| 345 | + if (debugger.is_null() || window_wrapper->get_window_enabled() || !embedded_process || !embedded_process->is_embedding_completed()) { |
| 346 | + return false; |
| 347 | + } |
| 348 | + Rect2 r = embedded_process->get_adjusted_embedded_window_rect(embedded_process->get_rect()); |
| 349 | + r.position += embedded_process->get_global_position(); |
| 350 | +#ifndef MACOS_ENABLED |
| 351 | + r.position -= embedded_process->get_window()->get_position(); |
| 352 | +#endif |
| 353 | + return debugger->add_screenshot_callback(p_callback, r); |
| 354 | +} |
| 355 | + |
283 | 356 | void GameView::_show_update_window_wrapper() { |
284 | 357 | EditorRun::WindowPlacement placement = EditorRun::get_window_placement(); |
285 | 358 | Point2 position = floating_window_rect.position; |
@@ -749,6 +822,7 @@ void GameView::_notification(int p_what) { |
749 | 822 | EditorRunBar::get_singleton()->connect("play_pressed", callable_mp(this, &GameView::_play_pressed)); |
750 | 823 | EditorRunBar::get_singleton()->connect("stop_pressed", callable_mp(this, &GameView::_stop_pressed)); |
751 | 824 | EditorRun::instance_starting_callback = _instance_starting_static; |
| 825 | + EditorRun::instance_rq_screenshot_callback = _instance_rq_screenshot_static; |
752 | 826 |
|
753 | 827 | // Listen for project settings changes to update the window size and aspect ratio. |
754 | 828 | ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &GameView::_editor_or_project_settings_changed)); |
|
0 commit comments