Skip to content

Commit 69d13ff

Browse files
committed
Adjustable notification volume
1 parent fe4d68b commit 69d13ff

File tree

5 files changed

+142
-6
lines changed

5 files changed

+142
-6
lines changed

src/Client/ConfigWindow.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ public class ConfigWindow {
371371
private JRadioButton audioPanelOverrideAudioSettingOffButton;
372372
private JCheckBox audioPanelFixSpiderWebDummySoundCheckbox;
373373
private JCheckBox audioPanelFixSfxDelayCheckbox;
374+
private JSlider audioPanelNotifVolumeSlider;
374375
private JCheckBox soundEffectAdvanceCheckbox;
375376
private JCheckBox soundEffectAnvilCheckbox;
376377
private JCheckBox soundEffectChiselCheckbox;
@@ -3210,6 +3211,43 @@ public void actionPerformed(ActionEvent e) {
32103211
"Fixes a bug where sound effects were delayed by a significant amount.");
32113212
SearchUtils.addSearchMetadata(audioPanelFixSfxDelayCheckbox, CommonMetadata.SFX.getText());
32123213

3214+
JPanel audioPanelNotifVolumePanel = new JPanel();
3215+
audioPanel.add(audioPanelNotifVolumePanel);
3216+
audioPanelNotifVolumePanel.setLayout(
3217+
new BoxLayout(audioPanelNotifVolumePanel, BoxLayout.Y_AXIS));
3218+
audioPanelNotifVolumePanel.setAlignmentX(Component.LEFT_ALIGNMENT);
3219+
audioPanelNotifVolumePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, osScaleMul(10), 0));
3220+
3221+
JLabel audioPanelNotifVolumeLabel =
3222+
new JLabel(Launcher.binaryPrefix + "RSC+ notifications volume");
3223+
audioPanelNotifVolumeLabel.setToolTipText(
3224+
"Sets the volume for the " + Launcher.binaryPrefix + "RSC+ notification sounds");
3225+
audioPanelNotifVolumePanel.add(audioPanelNotifVolumeLabel);
3226+
audioPanelNotifVolumeLabel.setAlignmentY(1.0f);
3227+
SearchUtils.addSearchMetadata(audioPanelNotifVolumeLabel, CommonMetadata.ALERT.getText());
3228+
3229+
audioPanelNotifVolumePanel.add(Box.createRigidArea(osScaleMul(new Dimension(0, 5))));
3230+
3231+
audioPanelNotifVolumeSlider = new JSlider();
3232+
3233+
audioPanelNotifVolumePanel.add(audioPanelNotifVolumeSlider);
3234+
audioPanelNotifVolumeSlider.setAlignmentX(Component.LEFT_ALIGNMENT);
3235+
audioPanelNotifVolumeSlider.setMaximumSize(osScaleMul(new Dimension(350, 55)));
3236+
audioPanelNotifVolumeSlider.setMinorTickSpacing(5);
3237+
audioPanelNotifVolumeSlider.setMajorTickSpacing(10);
3238+
audioPanelNotifVolumeSlider.setMinimum(0);
3239+
audioPanelNotifVolumeSlider.setMaximum(100);
3240+
audioPanelNotifVolumeSlider.setPaintTicks(true);
3241+
3242+
Hashtable<Integer, JLabel> audioPanelNotifVolumeTable = new Hashtable<Integer, JLabel>();
3243+
audioPanelNotifVolumeTable.put(new Integer(0), new JLabel("0"));
3244+
audioPanelNotifVolumeTable.put(new Integer(25), new JLabel("25"));
3245+
audioPanelNotifVolumeTable.put(new Integer(50), new JLabel("50"));
3246+
audioPanelNotifVolumeTable.put(new Integer(75), new JLabel("75"));
3247+
audioPanelNotifVolumeTable.put(new Integer(100), new JLabel("100"));
3248+
audioPanelNotifVolumeSlider.setLabelTable(audioPanelNotifVolumeTable);
3249+
audioPanelNotifVolumeSlider.setPaintLabels(true);
3250+
32133251
addSettingsHeader(audioPanel, "Toggle individual sound effects");
32143252

32153253
JPanel audioPanelEnableAllSfxPanel = new JPanel();
@@ -3768,8 +3806,12 @@ public void actionPerformed(ActionEvent e) {
37683806
notificationPanelNotifSoundsPanel.setLayout(
37693807
new BoxLayout(notificationPanelNotifSoundsPanel, BoxLayout.Y_AXIS));
37703808
notificationPanelNotifSoundsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
3809+
SearchUtils.addSearchMetadata(
3810+
notificationPanelNotifSoundsPanel, CommonMetadata.ALERT.getText());
37713811
notificationPanelNotifSoundsCheckbox =
3772-
addCheckbox("Enable notification sounds", notificationPanelNotifSoundsPanel);
3812+
addCheckbox(
3813+
"Enable notification sounds (adjust volume in Audio settings)",
3814+
notificationPanelNotifSoundsPanel);
37733815
notificationPanelNotifSoundsCheckbox.setBorder(
37743816
BorderFactory.createEmptyBorder(0, 0, osScaleMul(7), 0));
37753817
notificationPanelNotifSoundsCheckbox.setToolTipText(
@@ -3995,6 +4037,8 @@ public void actionPerformed(ActionEvent e) {
39954037
addCheckbox("Mute the alert sound even if it's an important message", notificationPanel);
39964038
notificationPanelMuteImportantMessageSoundsCheckbox.setToolTipText(
39974039
"Muting for Important Messages (defined in text fields above)");
4040+
SearchUtils.addSearchMetadata(
4041+
notificationPanelMuteImportantMessageSoundsCheckbox, CommonMetadata.ALERT.getText());
39984042

39994043
addPanelBottomGlue(notificationPanel);
40004044

@@ -5330,7 +5374,8 @@ private enum CommonMetadata {
53305374
COLOUR("colours", "colors", "coloured", "colored"),
53315375
PVP("pvp", "pk"),
53325376
PM("private", "messages", "pms", "dms", "msgs"),
5333-
DIR("folders", "dirs", "directory", "directories", "files");
5377+
DIR("folders", "dirs", "directory", "directories", "files"),
5378+
ALERT("alerts", "dings", "notifications");
53345379

53355380
public final String text;
53365381

@@ -6487,6 +6532,7 @@ private void executeSynchronizeGuiValues() {
64876532
audioPanelFixSpiderWebDummySoundCheckbox.setSelected(
64886533
Settings.SOUND_EFFECT_COMBAT1.get(Settings.currentProfile));
64896534
audioPanelFixSfxDelayCheckbox.setSelected(Settings.FIX_SFX_DELAY.get(Settings.currentProfile));
6535+
audioPanelNotifVolumeSlider.setValue(Settings.NOTIF_VOLUME.get(Settings.currentProfile));
64906536
soundEffectAdvanceCheckbox.setSelected(
64916537
Settings.SOUND_EFFECT_ADVANCE.get(Settings.currentProfile));
64926538
soundEffectAnvilCheckbox.setSelected(Settings.SOUND_EFFECT_ANVIL.get(Settings.currentProfile));
@@ -6960,6 +7006,7 @@ private void saveSettings() {
69607006
Settings.SOUND_EFFECT_COMBAT1.put(
69617007
Settings.currentProfile, audioPanelFixSpiderWebDummySoundCheckbox.isSelected());
69627008
Settings.FIX_SFX_DELAY.put(Settings.currentProfile, audioPanelFixSfxDelayCheckbox.isSelected());
7009+
Settings.NOTIF_VOLUME.put(Settings.currentProfile, audioPanelNotifVolumeSlider.getValue());
69637010
Settings.SOUND_EFFECT_ADVANCE.put(
69647011
Settings.currentProfile, soundEffectAdvanceCheckbox.isSelected());
69657012
Settings.SOUND_EFFECT_ANVIL.put(Settings.currentProfile, soundEffectAnvilCheckbox.isSelected());
@@ -7278,6 +7325,7 @@ private void applySettings() {
72787325
Item.patchItemCommands();
72797326
GameApplet.syncFontSetting();
72807327
SoundEffects.adjustMudClientSfxVolume();
7328+
SoundEffects.adjustNotificationsVolume();
72817329
});
72827330
}
72837331

src/Client/NotificationsHandler.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,14 @@ public void run() {
655655
private static Clip notificationSoundClip;
656656
private static Clip sadNotificationSoundClip;
657657

658+
public static Clip getNotificationSoundClip() {
659+
return notificationSoundClip;
660+
}
661+
662+
public static Clip getSadNotificationSoundClip() {
663+
return sadNotificationSoundClip;
664+
}
665+
658666
public static void loadNotificationSound() {
659667
try {
660668
notificationAudioIn =

src/Client/Settings.java

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public class Settings {
187187
public static HashMap<String, Boolean> OVERRIDE_AUDIO_SETTING_SETTING_ON =
188188
new HashMap<String, Boolean>();
189189
public static HashMap<String, Boolean> FIX_SFX_DELAY = new HashMap<String, Boolean>();
190+
public static HashMap<String, Integer> NOTIF_VOLUME = new HashMap<String, Integer>();
190191
public static HashMap<String, Boolean> SOUND_EFFECT_COMBAT1 = new HashMap<String, Boolean>();
191192
public static HashMap<String, Boolean> SOUND_EFFECT_ADVANCE = new HashMap<String, Boolean>();
192193
public static HashMap<String, Boolean> SOUND_EFFECT_ANVIL = new HashMap<String, Boolean>();
@@ -1230,6 +1231,15 @@ public static void definePresets(Properties props) {
12301231
FIX_SFX_DELAY.put(
12311232
"custom", getPropBoolean(props, "fix_sfx_delay", FIX_SFX_DELAY.get("default")));
12321233

1234+
NOTIF_VOLUME.put("vanilla", 100);
1235+
NOTIF_VOLUME.put("vanilla_resizable", 100);
1236+
NOTIF_VOLUME.put("lite", 100);
1237+
NOTIF_VOLUME.put("default", 100);
1238+
NOTIF_VOLUME.put("heavy", 100);
1239+
NOTIF_VOLUME.put("all", 100);
1240+
NOTIF_VOLUME.put("custom", 100);
1241+
NOTIF_VOLUME.put("custom", getPropInt(props, "notif_volume", NOTIF_VOLUME.get("default")));
1242+
12331243
SOUND_EFFECT_ADVANCE.put("vanilla", true);
12341244
SOUND_EFFECT_ADVANCE.put("vanilla_resizable", true);
12351245
SOUND_EFFECT_ADVANCE.put("lite", true);
@@ -2648,6 +2658,14 @@ public static void sanitizeSettings() {
26482658
foundInvalidSetting = true;
26492659
}
26502660

2661+
if (NOTIF_VOLUME.get("custom") < 0) {
2662+
NOTIF_VOLUME.put("custom", 0);
2663+
foundInvalidSetting = true;
2664+
} else if (NOTIF_VOLUME.get("custom") > 100) {
2665+
NOTIF_VOLUME.put("custom", 100);
2666+
foundInvalidSetting = true;
2667+
}
2668+
26512669
if (VIEW_DISTANCE.get("custom") < 2300) {
26522670
VIEW_DISTANCE.put("custom", 2300);
26532671
foundInvalidSetting = true;
@@ -3795,6 +3813,7 @@ public static synchronized void save(String preset) {
37953813
Boolean.toString(OVERRIDE_AUDIO_SETTING_SETTING_ON.get(preset)));
37963814
props.setProperty("sound_effect_combat1", Boolean.toString(SOUND_EFFECT_COMBAT1.get(preset)));
37973815
props.setProperty("fix_sfx_delay", Boolean.toString(FIX_SFX_DELAY.get(preset)));
3816+
props.setProperty("notif_volume", Integer.toString(NOTIF_VOLUME.get(preset)));
37983817
props.setProperty("sound_effect_advance", Boolean.toString(SOUND_EFFECT_ADVANCE.get(preset)));
37993818
props.setProperty("sound_effect_anvil", Boolean.toString(SOUND_EFFECT_ANVIL.get(preset)));
38003819
props.setProperty("sound_effect_chisel", Boolean.toString(SOUND_EFFECT_CHISEL.get(preset)));
@@ -4887,6 +4906,26 @@ public static void setClientFoV(String fovValue) {
48874906
}
48884907

48894908
public static void setSfxVolume(String volumeLevel) {
4909+
setVolume(
4910+
SFX_VOLUME,
4911+
volumeLevel,
4912+
true,
4913+
"@cya@Volume of sound effects was changed to " + volumeLevel + "%");
4914+
}
4915+
4916+
public static void setNotifVolume(String volumeLevel) {
4917+
setVolume(
4918+
NOTIF_VOLUME,
4919+
volumeLevel,
4920+
false,
4921+
"@cya@Volume of notifications was changed to " + volumeLevel + "%");
4922+
}
4923+
4924+
private static void setVolume(
4925+
HashMap<String, Integer> volumeSetting,
4926+
String volumeLevel,
4927+
boolean forMudClient,
4928+
String successMessage) {
48904929
String outOfBoundsMessage =
48914930
"@whi@Please use an @lre@integer@whi@ between 0 and 100 (default = 100)";
48924931

@@ -4899,10 +4938,15 @@ public static void setSfxVolume(String volumeLevel) {
48994938
return;
49004939
}
49014940

4902-
SFX_VOLUME.put(currentProfile, newVolume);
4903-
SoundEffects.adjustMudClientSfxVolume();
4904-
Client.displayMessage(
4905-
"@cya@Volume of sound effects was changed to " + volumeLevel + "%", Client.CHAT_NONE);
4941+
volumeSetting.put(currentProfile, newVolume);
4942+
4943+
if (forMudClient) {
4944+
SoundEffects.adjustMudClientSfxVolume();
4945+
} else {
4946+
SoundEffects.adjustNotificationsVolume();
4947+
}
4948+
4949+
Client.displayMessage(successMessage, Client.CHAT_NONE);
49064950

49074951
Launcher.getConfigWindow().synchronizeGuiValues();
49084952
} catch (Exception e) {

src/Game/Client.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ public static void update() {
958958
// Set the mudclient volume
959959
if (!customSfxVolumeSet) {
960960
SoundEffects.adjustMudClientSfxVolume();
961+
SoundEffects.adjustNotificationsVolume();
961962
customSfxVolumeSet = true;
962963
}
963964

@@ -2183,6 +2184,11 @@ private static String processClientCommand(String line) {
21832184
Settings.setSfxVolume(commandArray[1]);
21842185
}
21852186
break;
2187+
case "notif_volume":
2188+
if (commandArray.length > 1) {
2189+
Settings.setNotifVolume(commandArray[1]);
2190+
}
2191+
break;
21862192
case "overlayfont":
21872193
if (commandArray.length > 1) {
21882194
Settings.setOverlayFontStyle(commandArray[1]);

src/Game/SoundEffects.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import Client.Launcher;
44
import Client.Logger;
5+
import Client.NotificationsHandler;
56
import Client.Settings;
67
import java.io.BufferedInputStream;
78
import java.io.IOException;
9+
import javax.sound.sampled.Clip;
810
import javax.sound.sampled.FloatControl;
911
import javax.sound.sampled.SourceDataLine;
1012
import javax.sound.sampled.UnsupportedAudioFileException;
@@ -219,4 +221,32 @@ public static void adjustSfxVolume(SourceDataLine sourceDataLine) {
219221
e.printStackTrace();
220222
}
221223
}
224+
225+
public static void adjustNotificationsVolume() {
226+
Clip notifClip = NotificationsHandler.getNotificationSoundClip();
227+
Clip sadNotifClip = NotificationsHandler.getSadNotificationSoundClip();
228+
229+
if (notifClip == null || sadNotifClip == null) {
230+
return;
231+
}
232+
233+
FloatControl notifControl = (FloatControl) notifClip.getControl(FloatControl.Type.MASTER_GAIN);
234+
FloatControl sadNotifControl =
235+
(FloatControl) sadNotifClip.getControl(FloatControl.Type.MASTER_GAIN);
236+
237+
adjustClipVolume(notifControl);
238+
adjustClipVolume(sadNotifControl);
239+
}
240+
241+
private static void adjustClipVolume(FloatControl gainControl) {
242+
try {
243+
float volumePercent = Settings.NOTIF_VOLUME.get(Settings.currentProfile);
244+
float volumeInDecibels = 20f * (float) Math.log10(volumePercent / 100f);
245+
246+
gainControl.setValue(volumeInDecibels);
247+
} catch (Exception e) {
248+
Logger.Error("Error adjusting the notifications volume");
249+
e.printStackTrace();
250+
}
251+
}
222252
}

0 commit comments

Comments
 (0)