game_menu_utils_jni.cpp 6.6 KB

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