Skip to content

Commit f7dfd64

Browse files
committed
Merge pull request #104409 from syntaxerror247/mute-game
Add support for `Mute Game` toggle in the Android Editor
2 parents 1d664d9 + afe68f6 commit f7dfd64

File tree

10 files changed

+96
-1
lines changed

10 files changed

+96
-1
lines changed

platform/android/game_menu_utils_jni.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,13 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_playMainSc
133133
}
134134
#endif
135135
}
136+
137+
JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_setDebugMuteAudio(JNIEnv *env, jclass clazz, jboolean enabled) {
138+
#ifdef TOOLS_ENABLED
139+
GameViewPlugin *game_view_plugin = _get_game_view_plugin();
140+
if (game_view_plugin != nullptr && game_view_plugin->get_debugger().is_valid()) {
141+
game_view_plugin->get_debugger()->set_debug_mute_audio(enabled);
142+
}
143+
#endif
144+
}
136145
}

platform/android/game_menu_utils_jni.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_setCameraM
4343
JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_resetCamera2DPosition(JNIEnv *env, jclass clazz);
4444
JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_resetCamera3DPosition(JNIEnv *env, jclass clazz);
4545
JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_playMainScene(JNIEnv *env, jclass clazz);
46+
JNIEXPORT void JNICALL Java_org_godotengine_godot_utils_GameMenuUtils_setDebugMuteAudio(JNIEnv *env, jclass clazz, jboolean enabled);
4647
}

platform/android/java/editor/src/main/java/org/godotengine/editor/BaseGodotEditor.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ import android.content.ComponentName
3737
import android.content.Context
3838
import android.content.Intent
3939
import android.content.pm.PackageManager
40-
import android.os.*
40+
import android.os.Build
41+
import android.os.Bundle
42+
import android.os.Debug
43+
import android.os.Environment
44+
import android.os.Process
4145
import android.preference.PreferenceManager
4246
import android.util.Log
4347
import android.view.View
@@ -138,6 +142,7 @@ abstract class BaseGodotEditor : GodotActivity(), GameMenuFragment.GameMenuListe
138142
internal const val GAME_MENU_ACTION_RESET_CAMERA_2D_POSITION = "resetCamera2DPosition"
139143
internal const val GAME_MENU_ACTION_RESET_CAMERA_3D_POSITION = "resetCamera3DPosition"
140144
internal const val GAME_MENU_ACTION_EMBED_GAME_ON_PLAY = "embedGameOnPlay"
145+
internal const val GAME_MENU_ACTION_SET_DEBUG_MUTE_AUDIO = "setDebugMuteAudio"
141146

142147
private const val GAME_WORKSPACE = "Game"
143148

@@ -753,6 +758,10 @@ abstract class BaseGodotEditor : GodotActivity(), GameMenuFragment.GameMenuListe
753758
val embedded = actionData.getBoolean(KEY_GAME_MENU_ACTION_PARAM1)
754759
embedGameOnPlay(embedded)
755760
}
761+
GAME_MENU_ACTION_SET_DEBUG_MUTE_AUDIO -> {
762+
val enabled = actionData.getBoolean(KEY_GAME_MENU_ACTION_PARAM1)
763+
muteAudio(enabled)
764+
}
756765
}
757766
}
758767

@@ -816,6 +825,13 @@ abstract class BaseGodotEditor : GodotActivity(), GameMenuFragment.GameMenuListe
816825
}
817826
}
818827

828+
override fun muteAudio(enabled: Boolean) {
829+
gameMenuState.putBoolean(GAME_MENU_ACTION_SET_DEBUG_MUTE_AUDIO, enabled)
830+
godot?.runOnRenderThread {
831+
GameMenuUtils.setDebugMuteAudio(enabled)
832+
}
833+
}
834+
819835
override fun embedGameOnPlay(embedded: Boolean) {
820836
gameMenuState.putBoolean(GAME_MENU_ACTION_EMBED_GAME_ON_PLAY, embedded)
821837
godot?.runOnRenderThread {

platform/android/java/editor/src/main/java/org/godotengine/editor/GodotGame.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ open class GodotGame : BaseGodotGame() {
206206
editorMessageDispatcher.dispatchGameMenuAction(EDITOR_MAIN_INFO, actionBundle)
207207
}
208208

209+
override fun muteAudio(enabled: Boolean) {
210+
val actionBundle = Bundle().apply {
211+
putString(KEY_GAME_MENU_ACTION, GAME_MENU_ACTION_SET_DEBUG_MUTE_AUDIO)
212+
putBoolean(KEY_GAME_MENU_ACTION_PARAM1, enabled)
213+
}
214+
editorMessageDispatcher.dispatchGameMenuAction(EDITOR_MAIN_INFO, actionBundle)
215+
}
216+
209217
override fun embedGameOnPlay(embedded: Boolean) {
210218
val actionBundle = Bundle().apply {
211219
putString(KEY_GAME_MENU_ACTION, GAME_MENU_ACTION_EMBED_GAME_ON_PLAY)

platform/android/java/editor/src/main/java/org/godotengine/editor/embed/GameMenuFragment.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
101101
fun reset2DCamera()
102102
fun reset3DCamera()
103103
fun manipulateCamera(mode: CameraMode)
104+
fun muteAudio(enabled: Boolean)
104105

105106
fun isGameEmbeddingSupported(): Boolean
106107
fun embedGameOnPlay(embedded: Boolean)
@@ -148,6 +149,9 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
148149
private val listSelectButton: RadioButton? by lazy {
149150
view?.findViewById(R.id.game_menu_list_select_button)
150151
}
152+
private val audioMuteButton: View? by lazy {
153+
view?.findViewById(R.id.game_menu_audio_mute_button)
154+
}
151155
private val optionsButton: View? by lazy {
152156
view?.findViewById(R.id.game_menu_options_button)
153157
}
@@ -319,6 +323,13 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
319323
}
320324
}
321325
}
326+
audioMuteButton?.apply{
327+
setOnClickListener {
328+
val isActivated = !it.isActivated
329+
menuListener?.muteAudio(isActivated)
330+
it.isActivated = isActivated
331+
}
332+
}
322333
optionsButton?.setOnClickListener {
323334
popupMenu.show()
324335
}
@@ -351,6 +362,8 @@ class GameMenuFragment : Fragment(), PopupMenu.OnMenuItemClickListener {
351362
toolSelectButton?.isChecked = selectMode == GameMenuListener.SelectMode.SINGLE
352363
listSelectButton?.isChecked = selectMode == GameMenuListener.SelectMode.LIST
353364

365+
audioMuteButton?.isActivated = gameMenuState.getBoolean(BaseGodotEditor.GAME_MENU_ACTION_SET_DEBUG_MUTE_AUDIO, false)
366+
354367
popupMenu.menu.apply {
355368
if (menuListener?.isGameEmbeddingSupported() == false) {
356369
setGroupEnabled(R.id.group_menu_embed_options, false)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="16dp"
3+
android:height="16dp"
4+
android:viewportWidth="2.4"
5+
android:viewportHeight="2.4">
6+
7+
<path
8+
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"
9+
android:fillColor="@color/game_menu_icons_color_state"/>
10+
<path
11+
android:strokeWidth=".165"
12+
android:strokeLineCap="round"
13+
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"
14+
android:strokeColor="@color/game_menu_icons_color_state"/>
15+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:drawable="@drawable/audio_player_muted" android:state_activated="true" />
4+
<item android:drawable="@drawable/audio_player" />
5+
</selector>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="16dp"
3+
android:height="16dp"
4+
android:viewportWidth="2.4"
5+
android:viewportHeight="2.4">
6+
7+
<path
8+
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"
9+
android:fillColor="@color/game_menu_icons_color_state"/>
10+
<path
11+
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"
12+
android:fillColor="@color/game_menu_icons_color_state"/>
13+
<path
14+
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"
15+
android:fillColor="#fc7f7f"/>
16+
</vector>

platform/android/java/editor/src/main/res/layout/game_menu_fragment_layout.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@
128128
android:drawableStart="@drawable/list_select"
129129
android:padding="15dp" />
130130
</RadioGroup>
131+
132+
<ImageButton
133+
android:id="@+id/game_menu_audio_mute_button"
134+
style="?android:attr/borderlessButtonStyle"
135+
android:layout_width="48dp"
136+
android:layout_height="48dp"
137+
android:background="@drawable/game_menu_button_bg"
138+
android:src="@drawable/audio_player_icon_selector" />
139+
131140
</LinearLayout>
132141
</HorizontalScrollView>
133142

platform/android/java/lib/src/org/godotengine/godot/utils/GameMenuUtils.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ object GameMenuUtils {
9090
@JvmStatic
9191
external fun playMainScene()
9292

93+
@JvmStatic
94+
external fun setDebugMuteAudio(enabled: Boolean)
95+
9396
/**
9497
* Returns [GameEmbedMode] stored in the editor settings.
9598
*

0 commit comments

Comments
 (0)