diff --git a/platform/android/editor/game_menu_utils_jni.cpp b/platform/android/editor/game_menu_utils_jni.cpp index 0049ee94e1a..98442b59a41 100644 --- a/platform/android/editor/game_menu_utils_jni.cpp +++ b/platform/android/editor/game_menu_utils_jni.cpp @@ -142,4 +142,22 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_set } #endif } + +JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_resetTimeScale(JNIEnv *env, jclass clazz) { +#ifdef TOOLS_ENABLED + GameViewPlugin *game_view_plugin = _get_game_view_plugin(); + if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) { + game_view_plugin->get_debugger()->reset_time_scale(); + } +#endif +} + +JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_setTimeScale(JNIEnv *env, jclass clazz, jdouble scale) { +#ifdef TOOLS_ENABLED + GameViewPlugin *game_view_plugin = _get_game_view_plugin(); + if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) { + game_view_plugin->get_debugger()->set_time_scale(scale); + } +#endif +} } diff --git a/platform/android/editor/game_menu_utils_jni.h b/platform/android/editor/game_menu_utils_jni.h index 2140672e60a..61129365cd3 100644 --- a/platform/android/editor/game_menu_utils_jni.h +++ b/platform/android/editor/game_menu_utils_jni.h @@ -44,4 +44,6 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_res JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_resetCamera3DPosition(JNIEnv *env, jclass clazz); JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_playMainScene(JNIEnv *env, jclass clazz); JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_setDebugMuteAudio(JNIEnv *env, jclass clazz, jboolean enabled); +JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_resetTimeScale(JNIEnv *env, jclass clazz); +JNIEXPORT void JNICALL Java_org_godotengine_godot_editor_utils_GameMenuUtils_setTimeScale(JNIEnv *env, jclass clazz, jdouble scale); } diff --git a/platform/android/java/editor/src/main/java/org/godotengine/editor/BaseGodotEditor.kt b/platform/android/java/editor/src/main/java/org/godotengine/editor/BaseGodotEditor.kt index 934c4827ae6..88174cbdc16 100644 --- a/platform/android/java/editor/src/main/java/org/godotengine/editor/BaseGodotEditor.kt +++ b/platform/android/java/editor/src/main/java/org/godotengine/editor/BaseGodotEditor.kt @@ -150,6 +150,8 @@ abstract class BaseGodotEditor : GodotActivity(), GameMenuFragment.GameMenuListe internal const val GAME_MENU_ACTION_RESET_CAMERA_3D_POSITION = "resetCamera3DPosition" internal const val GAME_MENU_ACTION_EMBED_GAME_ON_PLAY = "embedGameOnPlay" internal const val GAME_MENU_ACTION_SET_DEBUG_MUTE_AUDIO = "setDebugMuteAudio" + internal const val GAME_MENU_ACTION_RESET_TIME_SCALE = "resetTimeScale" + internal const val GAME_MENU_ACTION_SET_TIME_SCALE = "setTimeScale" private const val GAME_WORKSPACE = "Game" @@ -839,6 +841,13 @@ abstract class BaseGodotEditor : GodotActivity(), GameMenuFragment.GameMenuListe val enabled = actionData.getBoolean(KEY_GAME_MENU_ACTION_PARAM1) muteAudio(enabled) } + GAME_MENU_ACTION_RESET_TIME_SCALE -> { + resetTimeScale() + } + GAME_MENU_ACTION_SET_TIME_SCALE -> { + val scale = actionData.getDouble(KEY_GAME_MENU_ACTION_PARAM1) + setTimeScale(scale) + } } } @@ -909,6 +918,20 @@ abstract class BaseGodotEditor : GodotActivity(), GameMenuFragment.GameMenuListe } } + override fun resetTimeScale() { + gameMenuState.putDouble(GAME_MENU_ACTION_SET_TIME_SCALE, 1.0) + godot?.runOnRenderThread { + GameMenuUtils.resetTimeScale() + } + } + + override fun setTimeScale(scale: Double) { + gameMenuState.putDouble(GAME_MENU_ACTION_SET_TIME_SCALE, scale) + godot?.runOnRenderThread { + GameMenuUtils.setTimeScale(scale) + } + } + override fun embedGameOnPlay(embedded: Boolean) { gameMenuState.putBoolean(GAME_MENU_ACTION_EMBED_GAME_ON_PLAY, embedded) godot?.runOnRenderThread { diff --git a/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotGame.kt b/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotGame.kt index eb167be42b2..066e88ea6a2 100644 --- a/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotGame.kt +++ b/platform/android/java/editor/src/main/java/org/godotengine/editor/GodotGame.kt @@ -230,6 +230,21 @@ open class GodotGame : BaseGodotGame() { editorMessageDispatcher.dispatchGameMenuAction(EDITOR_MAIN_INFO, actionBundle) } + override fun resetTimeScale() { + val actionBundle = Bundle().apply { + putString(KEY_GAME_MENU_ACTION, GAME_MENU_ACTION_RESET_TIME_SCALE) + } + editorMessageDispatcher.dispatchGameMenuAction(EDITOR_MAIN_INFO, actionBundle) + } + + override fun setTimeScale(scale: Double) { + val actionBundle = Bundle().apply { + putString(KEY_GAME_MENU_ACTION, GAME_MENU_ACTION_SET_TIME_SCALE) + putDouble(KEY_GAME_MENU_ACTION_PARAM1, scale) + } + editorMessageDispatcher.dispatchGameMenuAction(EDITOR_MAIN_INFO, actionBundle) + } + override fun embedGameOnPlay(embedded: Boolean) { val actionBundle = Bundle().apply { putString(KEY_GAME_MENU_ACTION, GAME_MENU_ACTION_EMBED_GAME_ON_PLAY) diff --git a/platform/android/java/editor/src/main/java/org/godotengine/editor/embed/GameMenuFragment.kt b/platform/android/java/editor/src/main/java/org/godotengine/editor/embed/GameMenuFragment.kt index c4f11245082..715f0508774 100644 --- a/platform/android/java/editor/src/main/java/org/godotengine/editor/embed/GameMenuFragment.kt +++ b/platform/android/java/editor/src/main/java/org/godotengine/editor/embed/GameMenuFragment.kt @@ -38,6 +38,7 @@ import android.view.LayoutInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup +import android.widget.Button import android.widget.PopupMenu import android.widget.RadioButton import androidx.core.content.edit @@ -102,6 +103,8 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener { fun reset3DCamera() fun manipulateCamera(mode: CameraMode) fun muteAudio(enabled: Boolean) + fun resetTimeScale() + fun setTimeScale(scale: Double) fun isGameEmbeddingSupported(): Boolean fun embedGameOnPlay(embedded: Boolean) @@ -131,6 +134,12 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener { private val nextFrameButton: View? by lazy { view?.findViewById(R.id.game_menu_next_frame_button) } + private val setTimeScaleButton: Button? by lazy { + view?.findViewById