]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
Add cli opt for music vol affected by master vol
authorStephen Seo <seo.disparate@gmail.com>
Thu, 1 Feb 2024 07:54:34 +0000 (16:54 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 1 Feb 2024 07:54:34 +0000 (16:54 +0900)
src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientConfig.java
src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java

index 216b2b20062cbc93c5f8210b412710855ccaf34a..cfd736163ebd65c30c33f7ed287861c9894ac141 100644 (file)
@@ -29,6 +29,7 @@ public class ClientConfig {
     public final ModConfigSpec.ConfigValue<List<? extends String>> battleMusicList;
     public final ModConfigSpec.ConfigValue<List<? extends String>> sillyMusicList;
     public final ModConfigSpec.DoubleValue sillyMusicThreshold;
+    public final ModConfigSpec.BooleanValue volumeAffectedByMasterVolume;
     public final ModConfigSpec.BooleanValue volumeAffectedByMusicVolume;
     public final ModConfigSpec.DoubleValue musicVolume;
 
@@ -55,6 +56,11 @@ public class ClientConfig {
                 .translation(TurnBasedMinecraftMod.MODID + ".clientconfig.silly_percentage")
                 .defineInRange("sillyMusicThreshold", 0.4, 0.0, 1.0);
 
+        this.volumeAffectedByMasterVolume = builder.comment(
+                "If \"true\", music volume will be affected by global Master volume setting")
+            .translation(TurnBasedMinecraftMod.MODID + ".clientconfig.volume_affected_by_master")
+            .define("volumeAffectedByMasterVolume", true);
+
         this.volumeAffectedByMusicVolume = builder.comment(
                 "If \"true\", music volume will be affected by global Music volume setting")
             .translation(TurnBasedMinecraftMod.MODID + ".clientconfig.volume_affected_by_volume")
@@ -75,6 +81,7 @@ public class ClientConfig {
         private EditBox battleListEditBox = null;
         private EditBox sillyListEditBox = null;
         private SliderPercentage sillyMusicThresholdSlider = null;
+        private Checkbox affectedByMasterVolCheckbox = null;
         private Checkbox affectedByMusicVolCheckbox = null;
         private SliderPercentage volumeSlider = null;
 
@@ -167,6 +174,29 @@ public class ClientConfig {
 
             top_offset += widget_height;
 
+            addRenderableWidget(
+                new StringWidget(this.width / 2 - widget_width + widget_x_offset, top_offset,
+                    widget_width, widget_height, Component.literal("Affected by Master Vol.")
+                    .setStyle(Style.EMPTY.withColor(TextColor.fromRgb(0XFFFFFFFF)).withHoverEvent(
+                        new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(
+                            "If enabled, volume is affected by global master volume.")))), font));
+            if (affectedByMasterVolCheckbox == null) {
+                affectedByMasterVolCheckbox = Checkbox.builder(Component.literal(""), font)
+                    .pos(this.width / 2 + widget_x_offset, top_offset).build();
+            } else {
+                affectedByMasterVolCheckbox.setPosition(this.width / 2 + widget_x_offset,
+                    top_offset);
+            }
+            if ((CLIENT.volumeAffectedByMasterVolume.get() &&
+                !affectedByMasterVolCheckbox.selected()) ||
+                (!CLIENT.volumeAffectedByMasterVolume.get() &&
+                    affectedByMasterVolCheckbox.selected())) {
+                affectedByMasterVolCheckbox.onPress();
+            }
+            addRenderableWidget(affectedByMasterVolCheckbox);
+
+            top_offset += widget_height;
+
             addRenderableWidget(
                 new StringWidget(this.width / 2 - widget_width + widget_x_offset, top_offset,
                     widget_width, widget_height, Component.literal("Affected by Music Vol.")
@@ -241,6 +271,8 @@ public class ClientConfig {
 
             CLIENT.sillyMusicThreshold.set(sillyMusicThresholdSlider.percentage);
 
+            CLIENT.volumeAffectedByMasterVolume.set(affectedByMasterVolCheckbox.selected());
+
             CLIENT.volumeAffectedByMusicVolume.set(affectedByMusicVolCheckbox.selected());
 
             CLIENT.musicVolume.set(volumeSlider.percentage);
index 03d572fb4bf891a65a3dc09e7185eb74fff6b426..6b0f621a8dc46734fafa9bfe018a31281d6f359a 100644 (file)
@@ -94,21 +94,27 @@ public class ClientProxy extends CommonProxy {
     @Override
     public void playBattleMusic() {
         Options gs = Minecraft.getInstance().options;
+        float volume = ClientConfig.CLIENT.musicVolume.get().floatValue();
+        if (ClientConfig.CLIENT.volumeAffectedByMasterVolume.get()) {
+            volume *= gs.getSoundSourceVolume(SoundSource.MASTER);
+        }
         if (ClientConfig.CLIENT.volumeAffectedByMusicVolume.get()) {
-            battleMusic.playBattle(gs.getSoundSourceVolume(SoundSource.MUSIC) * gs.getSoundSourceVolume(SoundSource.MASTER) * ClientConfig.CLIENT.musicVolume.get().floatValue());
-        } else {
-            battleMusic.playBattle(gs.getSoundSourceVolume(SoundSource.MASTER) * ClientConfig.CLIENT.musicVolume.get().floatValue());
+            volume *= gs.getSoundSourceVolume(SoundSource.MUSIC);
         }
+        battleMusic.playBattle(volume);
     }
 
     @Override
     public void playSillyMusic() {
         Options gs = Minecraft.getInstance().options;
+        float volume = ClientConfig.CLIENT.musicVolume.get().floatValue();
+        if (ClientConfig.CLIENT.volumeAffectedByMasterVolume.get()) {
+            volume *= gs.getSoundSourceVolume(SoundSource.MASTER);
+        }
         if (ClientConfig.CLIENT.volumeAffectedByMusicVolume.get()) {
-            battleMusic.playSilly(gs.getSoundSourceVolume(SoundSource.MUSIC) * gs.getSoundSourceVolume(SoundSource.MASTER) * ClientConfig.CLIENT.musicVolume.get().floatValue());
-        } else {
-            battleMusic.playSilly(gs.getSoundSourceVolume(SoundSource.MASTER) * ClientConfig.CLIENT.musicVolume.get().floatValue());
+            volume *= gs.getSoundSourceVolume(SoundSource.MUSIC);
         }
+        battleMusic.playSilly(volume);
     }
 
     @Override