mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #104409 from syntaxerror247/mute-game
Add support for `Mute Game` toggle in the Android Editor
This commit is contained in:
commit
f7dfd64cc0
10 changed files with 96 additions and 1 deletions
|
@ -133,4 +133,13 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_playMainSc
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_setDebugMuteAudio(JNIEnv *env, jclass clazz, jboolean enabled) {
|
||||
#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_debug_mute_audio(enabled);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,4 +43,5 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_setCameraM
|
|||
JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_resetCamera2DPosition(JNIEnv *env, jclass clazz);
|
||||
JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_resetCamera3DPosition(JNIEnv *env, jclass clazz);
|
||||
JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_playMainScene(JNIEnv *env, jclass clazz);
|
||||
JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_setDebugMuteAudio(JNIEnv *env, jclass clazz, jboolean enabled);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,11 @@ import android.content.ComponentName
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.*
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Debug
|
||||
import android.os.Environment
|
||||
import android.os.Process
|
||||
import android.preference.PreferenceManager
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
|
@ -138,6 +142,7 @@ abstract class BaseGodotEditor : GodotActivity(), GameMenuFragment.GameMenuListe
|
|||
internal const val GAME_MENU_ACTION_RESET_CAMERA_2D_POSITION = "resetCamera2DPosition"
|
||||
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"
|
||||
|
||||
private const val GAME_WORKSPACE = "Game"
|
||||
|
||||
|
@ -753,6 +758,10 @@ abstract class BaseGodotEditor : GodotActivity(), GameMenuFragment.GameMenuListe
|
|||
val embedded = actionData.getBoolean(KEY_GAME_MENU_ACTION_PARAM1)
|
||||
embedGameOnPlay(embedded)
|
||||
}
|
||||
GAME_MENU_ACTION_SET_DEBUG_MUTE_AUDIO -> {
|
||||
val enabled = actionData.getBoolean(KEY_GAME_MENU_ACTION_PARAM1)
|
||||
muteAudio(enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -816,6 +825,13 @@ abstract class BaseGodotEditor : GodotActivity(), GameMenuFragment.GameMenuListe
|
|||
}
|
||||
}
|
||||
|
||||
override fun muteAudio(enabled: Boolean) {
|
||||
gameMenuState.putBoolean(GAME_MENU_ACTION_SET_DEBUG_MUTE_AUDIO, enabled)
|
||||
godot?.runOnRenderThread {
|
||||
GameMenuUtils.setDebugMuteAudio(enabled)
|
||||
}
|
||||
}
|
||||
|
||||
override fun embedGameOnPlay(embedded: Boolean) {
|
||||
gameMenuState.putBoolean(GAME_MENU_ACTION_EMBED_GAME_ON_PLAY, embedded)
|
||||
godot?.runOnRenderThread {
|
||||
|
|
|
@ -206,6 +206,14 @@ open class GodotGame : BaseGodotGame() {
|
|||
editorMessageDispatcher.dispatchGameMenuAction(EDITOR_MAIN_INFO, actionBundle)
|
||||
}
|
||||
|
||||
override fun muteAudio(enabled: Boolean) {
|
||||
val actionBundle = Bundle().apply {
|
||||
putString(KEY_GAME_MENU_ACTION, GAME_MENU_ACTION_SET_DEBUG_MUTE_AUDIO)
|
||||
putBoolean(KEY_GAME_MENU_ACTION_PARAM1, enabled)
|
||||
}
|
||||
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)
|
||||
|
|
|
@ -101,6 +101,7 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
|
|||
fun reset2DCamera()
|
||||
fun reset3DCamera()
|
||||
fun manipulateCamera(mode: CameraMode)
|
||||
fun muteAudio(enabled: Boolean)
|
||||
|
||||
fun isGameEmbeddingSupported(): Boolean
|
||||
fun embedGameOnPlay(embedded: Boolean)
|
||||
|
@ -148,6 +149,9 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
|
|||
private val listSelectButton: RadioButton? by lazy {
|
||||
view?.findViewById(R.id.game_menu_list_select_button)
|
||||
}
|
||||
private val audioMuteButton: View? by lazy {
|
||||
view?.findViewById(R.id.game_menu_audio_mute_button)
|
||||
}
|
||||
private val optionsButton: View? by lazy {
|
||||
view?.findViewById(R.id.game_menu_options_button)
|
||||
}
|
||||
|
@ -319,6 +323,13 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
audioMuteButton?.apply{
|
||||
setOnClickListener {
|
||||
val isActivated = !it.isActivated
|
||||
menuListener?.muteAudio(isActivated)
|
||||
it.isActivated = isActivated
|
||||
}
|
||||
}
|
||||
optionsButton?.setOnClickListener {
|
||||
popupMenu.show()
|
||||
}
|
||||
|
@ -351,6 +362,8 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
|
|||
toolSelectButton?.isChecked = selectMode == GameMenuListener.SelectMode.SINGLE
|
||||
listSelectButton?.isChecked = selectMode == GameMenuListener.SelectMode.LIST
|
||||
|
||||
audioMuteButton?.isActivated = gameMenuState.getBoolean(BaseGodotEditor.GAME_MENU_ACTION_SET_DEBUG_MUTE_AUDIO, false)
|
||||
|
||||
popupMenu.menu.apply {
|
||||
if (menuListener?.isGameEmbeddingSupported() == false) {
|
||||
setGroupEnabled(R.id.group_menu_embed_options, false)
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="16dp"
|
||||
android:height="16dp"
|
||||
android:viewportWidth="2.4"
|
||||
android:viewportHeight="2.4">
|
||||
|
||||
<path
|
||||
android:pathData="M1.252 0.15 a0.1 0.1 0 0 0-0.082 0.03 L0.6 0.75 H0.318C0.225 0.75 0.15 0.817 0.15 0.9 v0.6c0 0.083 0.075 0.15 0.168 0.15H0.6l0.57 0.57 c0.066 0.067 0.18 0.02 0.18-0.074V0.256A0.106 0.106 0 0 0 1.252 0.15"
|
||||
android:fillColor="@color/game_menu_icons_color_state"/>
|
||||
<path
|
||||
android:strokeWidth=".165"
|
||||
android:strokeLineCap="round"
|
||||
android:pathData="M1.575 0.675 c0.45 0.525 0 1.05 0 1.05m0.3-1.35c0.675 0.825 0 1.65 0 1.65"
|
||||
android:strokeColor="@color/game_menu_icons_color_state"/>
|
||||
</vector>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/audio_player_muted" android:state_activated="true" />
|
||||
<item android:drawable="@drawable/audio_player" />
|
||||
</selector>
|
|
@ -0,0 +1,16 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="16dp"
|
||||
android:height="16dp"
|
||||
android:viewportWidth="2.4"
|
||||
android:viewportHeight="2.4">
|
||||
|
||||
<path
|
||||
android:pathData="M 1.2518555 0.15 A 0.1 0.1 0 0 0 1.1701172 0.17988281 L 0.6 0.75 L 0.31787109 0.75 C 0.22487119 0.75 0.15 0.81700008 0.15 0.9 L 0.15 1.5 C 0.15 1.5424221 0.16969512 1.5805593 0.20126953 1.6078125 L 1.35 0.45527344 L 1.35 0.25605469 A 0.106 0.106 0 0 0 1.2518555 0.15 z M 1.35 1.6438477 L 0.97236328 2.0223633 L 1.1701172 2.2201172 C 1.2361171 2.2871171 1.35 2.239996 1.35 2.1459961 L 1.35 1.6438477 z"
|
||||
android:fillColor="@color/game_menu_icons_color_state"/>
|
||||
<path
|
||||
android:pathData="M 2.1984375 0.79306641 L 2.0660156 0.92578125 C 2.1142629 1.1320246 2.0935608 1.3239034 2.0487305 1.4882812 C 1.9692536 1.7796963 1.8105469 1.9725586 1.8105469 1.9725586 A 0.0825 0.0825 0 0 0 1.8222656 2.0879883 A 0.0825 0.0825 0 0 0 1.9394531 2.0780273 C 1.9394531 2.0780273 2.1176607 1.8586814 2.2069336 1.5313477 C 2.2638362 1.3227069 2.2834498 1.0648044 2.1984375 0.79306641 z M 1.8539062 1.1384766 L 1.6790039 1.3136719 C 1.6747238 1.3346601 1.6697313 1.3550615 1.6640625 1.3749023 C 1.6131343 1.5531513 1.5117188 1.6719727 1.5117187 1.6719727 A 0.0825 0.0825 0 0 0 1.5213867 1.7871094 A 0.0825 0.0825 0 0 0 1.6368164 1.7791992 C 1.6368164 1.7791992 1.7606941 1.6355198 1.8222656 1.4200195 C 1.8460259 1.3368593 1.8597024 1.2410136 1.8539062 1.1384766 z"
|
||||
android:fillColor="@color/game_menu_icons_color_state"/>
|
||||
<path
|
||||
android:pathData="M0.08295 2.0529 2.0502 0.07965 2.31705 0.34725 0.34965 2.32035ZM-1.2804596 3.0939027 3.0879072-1.2877874Z"
|
||||
android:fillColor="#fc7f7f"/>
|
||||
</vector>
|
|
@ -128,6 +128,15 @@
|
|||
android:drawableStart="@drawable/list_select"
|
||||
android:padding="15dp" />
|
||||
</RadioGroup>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/game_menu_audio_mute_button"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:background="@drawable/game_menu_button_bg"
|
||||
android:src="@drawable/audio_player_icon_selector" />
|
||||
|
||||
</LinearLayout>
|
||||
</HorizontalScrollView>
|
||||
|
||||
|
|
|
@ -90,6 +90,9 @@ object GameMenuUtils {
|
|||
@JvmStatic
|
||||
external fun playMainScene()
|
||||
|
||||
@JvmStatic
|
||||
external fun setDebugMuteAudio(enabled: Boolean)
|
||||
|
||||
/**
|
||||
* Returns [GameEmbedMode] stored in the editor settings.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue