game_menu_utils_jni.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**************************************************************************/
  2. /* game_menu_utils_jni.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_menu_utils_jni.h"
  31. #ifdef TOOLS_ENABLED
  32. #include "editor/editor_interface.h"
  33. #include "editor/editor_node.h"
  34. #include "editor/plugins/game_view_plugin.h"
  35. static GameViewPlugin *_get_game_view_plugin() {
  36. ERR_FAIL_NULL_V(EditorNode::get_singleton(), nullptr);
  37. ERR_FAIL_NULL_V(EditorNode::get_singleton()->get_editor_main_screen(), nullptr);
  38. return Object::cast_to<GameViewPlugin>(EditorNode::get_singleton()->get_editor_main_screen()->get_plugin_by_name("Game"));
  39. }
  40. #endif
  41. extern "C" {
  42. JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_setSuspend(JNIEnv *env, jclass clazz, jboolean enabled) {
  43. #ifdef TOOLS_ENABLED
  44. GameViewPlugin *game_view_plugin = _get_game_view_plugin();
  45. if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) {
  46. game_view_plugin->get_debugger()->set_suspend(enabled);
  47. }
  48. #endif
  49. }
  50. JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_nextFrame(JNIEnv *env, jclass clazz) {
  51. #ifdef TOOLS_ENABLED
  52. GameViewPlugin *game_view_plugin = _get_game_view_plugin();
  53. if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) {
  54. game_view_plugin->get_debugger()->next_frame();
  55. }
  56. #endif
  57. }
  58. JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_setNodeType(JNIEnv *env, jclass clazz, jint type) {
  59. #ifdef TOOLS_ENABLED
  60. GameViewPlugin *game_view_plugin = _get_game_view_plugin();
  61. if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) {
  62. game_view_plugin->get_debugger()->set_node_type(type);
  63. }
  64. #endif
  65. }
  66. JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_setSelectMode(JNIEnv *env, jclass clazz, jint mode) {
  67. #ifdef TOOLS_ENABLED
  68. GameViewPlugin *game_view_plugin = _get_game_view_plugin();
  69. if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) {
  70. game_view_plugin->get_debugger()->set_select_mode(mode);
  71. }
  72. #endif
  73. }
  74. JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_setSelectionVisible(JNIEnv *env, jclass clazz, jboolean visible) {
  75. #ifdef TOOLS_ENABLED
  76. GameViewPlugin *game_view_plugin = _get_game_view_plugin();
  77. if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) {
  78. game_view_plugin->get_debugger()->set_selection_visible(visible);
  79. }
  80. #endif
  81. }
  82. JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_setCameraOverride(JNIEnv *env, jclass clazz, jboolean enabled) {
  83. #ifdef TOOLS_ENABLED
  84. GameViewPlugin *game_view_plugin = _get_game_view_plugin();
  85. if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) {
  86. game_view_plugin->get_debugger()->set_camera_override(enabled);
  87. }
  88. #endif
  89. }
  90. JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_setCameraManipulateMode(JNIEnv *env, jclass clazz, jint mode) {
  91. #ifdef TOOLS_ENABLED
  92. GameViewPlugin *game_view_plugin = _get_game_view_plugin();
  93. if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) {
  94. game_view_plugin->get_debugger()->set_camera_manipulate_mode(static_cast<EditorDebuggerNode::CameraOverride>(mode));
  95. }
  96. #endif
  97. }
  98. JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_resetCamera2DPosition(JNIEnv *env, jclass clazz) {
  99. #ifdef TOOLS_ENABLED
  100. GameViewPlugin *game_view_plugin = _get_game_view_plugin();
  101. if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) {
  102. game_view_plugin->get_debugger()->reset_camera_2d_position();
  103. }
  104. #endif
  105. }
  106. JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_resetCamera3DPosition(JNIEnv *env, jclass clazz) {
  107. #ifdef TOOLS_ENABLED
  108. GameViewPlugin *game_view_plugin = _get_game_view_plugin();
  109. if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) {
  110. game_view_plugin->get_debugger()->reset_camera_3d_position();
  111. }
  112. #endif
  113. }
  114. JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_playMainScene(JNIEnv *env, jclass clazz) {
  115. #ifdef TOOLS_ENABLED
  116. if (EditorInterface::get_singleton()) {
  117. EditorInterface::get_singleton()->play_main_scene();
  118. }
  119. #endif
  120. }
  121. }