Skip to content

Commit

Permalink
Add an option to disable sound effects during gameplay only.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
  • Loading branch information
itdelatrisu committed Apr 21, 2018
1 parent e4e571b commit 019f577
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
12 changes: 8 additions & 4 deletions src/itdelatrisu/opsu/GameData.java
Original file line number Diff line number Diff line change
Expand Up @@ -1397,8 +1397,10 @@ private void incrementComboStreak() {
* Resets the combo streak to zero.
*/
private void resetComboStreak() {
if (combo > 20 && !(GameMod.RELAX.isActive() || GameMod.AUTOPILOT.isActive()))
SoundController.playSound(SoundEffect.COMBOBREAK);
if (combo > 20 && !(GameMod.RELAX.isActive() || GameMod.AUTOPILOT.isActive())) {
if (!Options.isGameplaySoundDisabled())
SoundController.playSound(SoundEffect.COMBOBREAK);
}
combo = 0;
if (GameMod.SUDDEN_DEATH.isActive())
health.setHealth(0f);
Expand Down Expand Up @@ -1482,11 +1484,13 @@ public void sendSpinnerSpinResult(int result) {
switch (result) {
case HIT_SPINNERSPIN:
hitValue = 100;
SoundController.playSound(SoundEffect.SPINNERSPIN);
if (!Options.isGameplaySoundDisabled())
SoundController.playSound(SoundEffect.SPINNERSPIN);
break;
case HIT_SPINNERBONUS:
hitValue = 1100;
SoundController.playSound(SoundEffect.SPINNERBONUS);
if (!Options.isGameplaySoundDisabled())
SoundController.playSound(SoundEffect.SPINNERBONUS);
break;
default:
return;
Expand Down
3 changes: 2 additions & 1 deletion src/itdelatrisu/opsu/objects/Spinner.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ private int hitResult() {
float ratio = rotations / rotationsNeeded;
if (ratio >= 1.0f || GameMod.AUTO.isActive() || GameMod.AUTOPILOT.isActive() || GameMod.SPUN_OUT.isActive()) {
result = GameData.HIT_300;
SoundController.playSound(SoundEffect.SPINNEROSU);
if (!Options.isGameplaySoundDisabled())
SoundController.playSound(SoundEffect.SPINNEROSU);
} else if (ratio >= 0.9f)
result = GameData.HIT_100;
else if (ratio >= 0.75f)
Expand Down
1 change: 1 addition & 0 deletions src/itdelatrisu/opsu/options/OptionGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class OptionGroup {
GameOption.MUSIC_VOLUME,
GameOption.EFFECT_VOLUME,
GameOption.HITSOUND_VOLUME,
GameOption.DISABLE_GAMEPLAY_SOUNDS,
GameOption.DISABLE_SOUNDS,
}),
new OptionGroup("OFFSET ADJUSTMENT", new GameOption[] {
Expand Down
7 changes: 7 additions & 0 deletions src/itdelatrisu/opsu/options/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ public void setValue(int value) {
@Override
public String getValueString() { return String.format("%dms", val); }
},
DISABLE_GAMEPLAY_SOUNDS ("Disable sound effects in gameplay", "DisableGameplaySound", "Mute all sound effects during gameplay only.", false),
DISABLE_SOUNDS ("Disable all sound effects", "DisableSound", "May resolve Linux sound driver issues.\nRequires a restart.", false) {
@Override
public boolean isRestartRequired() { return true; }
Expand Down Expand Up @@ -1246,6 +1247,12 @@ public static void setDisplayMode(Container app) {
*/
public static int getCheckpoint() { return GameOption.CHECKPOINT.getIntegerValue() * 1000; }

/**
* Returns whether or not sound effects are disabled during gameplay.
* @return true if disabled
*/
public static boolean isGameplaySoundDisabled() { return GameOption.DISABLE_GAMEPLAY_SOUNDS.getBooleanValue(); }

/**
* Returns whether or not all sound effects are disabled.
* @return true if disabled
Expand Down
29 changes: 19 additions & 10 deletions src/itdelatrisu/opsu/states/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,13 @@ else if (breakIndex > 1) {
if (data.getHealthPercent() >= 50) {
GameImage.SECTION_PASS.getImage().drawCentered(width / 2f, height / 2f);
if (!breakSound) {
SoundController.playSound(SoundEffect.SECTIONPASS);
playSoundEffect(SoundEffect.SECTIONPASS);
breakSound = true;
}
} else {
GameImage.SECTION_FAIL.getImage().drawCentered(width / 2f, height / 2f);
if (!breakSound) {
SoundController.playSound(SoundEffect.SECTIONFAIL);
playSoundEffect(SoundEffect.SECTIONFAIL);
breakSound = true;
}
}
Expand Down Expand Up @@ -630,28 +630,28 @@ else if (breakIndex > 1) {
if (timeDiff >= 1500 * speedModifier) {
GameImage.COUNTDOWN_READY.getImage().drawCentered(width / 2, height / 2);
if (!countdownReadySound) {
SoundController.playSound(SoundEffect.READY);
playSoundEffect(SoundEffect.READY);
countdownReadySound = true;
}
}
if (timeDiff < 2000 * speedModifier) {
GameImage.COUNTDOWN_3.getImage().draw(0, 0);
if (!countdown3Sound) {
SoundController.playSound(SoundEffect.COUNT3);
playSoundEffect(SoundEffect.COUNT3);
countdown3Sound = true;
}
}
if (timeDiff < 1500 * speedModifier) {
GameImage.COUNTDOWN_2.getImage().draw(width - GameImage.COUNTDOWN_2.getImage().getWidth(), 0);
if (!countdown2Sound) {
SoundController.playSound(SoundEffect.COUNT2);
playSoundEffect(SoundEffect.COUNT2);
countdown2Sound = true;
}
}
if (timeDiff < 1000 * speedModifier) {
GameImage.COUNTDOWN_1.getImage().drawCentered(width / 2, height / 2);
if (!countdown1Sound) {
SoundController.playSound(SoundEffect.COUNT1);
playSoundEffect(SoundEffect.COUNT1);
countdown1Sound = true;
}
}
Expand All @@ -660,7 +660,7 @@ else if (breakIndex > 1) {
go.setAlpha((timeDiff < 0) ? 1 - (timeDiff / speedModifier / -500f) : 1);
go.drawCentered(width / 2, height / 2);
if (!countdownGoSound) {
SoundController.playSound(SoundEffect.GO);
playSoundEffect(SoundEffect.GO);
countdownGoSound = true;
}
}
Expand Down Expand Up @@ -1236,7 +1236,7 @@ else if (key == Options.getGameKeyRight())

int position = (pauseTime > -1) ? pauseTime : trackPosition;
if (Options.setCheckpoint(position / 1000)) {
SoundController.playSound(SoundEffect.MENUCLICK);
playSoundEffect(SoundEffect.MENUCLICK);
UI.getNotificationManager().sendBarNotification("Checkpoint saved.");
}
}
Expand All @@ -1257,7 +1257,7 @@ else if (key == Options.getGameKeyRight())
leadInTime = 0;
MusicController.resume();
}
SoundController.playSound(SoundEffect.MENUHIT);
playSoundEffect(SoundEffect.MENUHIT);
UI.getNotificationManager().sendBarNotification("Checkpoint loaded.");

// skip to checkpoint
Expand Down Expand Up @@ -1915,7 +1915,7 @@ private synchronized boolean skipIntro() {
replayX = (int) skipButton.getX();
replayY = (int) skipButton.getY();
}
SoundController.playSound(SoundEffect.MENUHIT);
playSoundEffect(SoundEffect.MENUHIT);
return true;
}
return false;
Expand Down Expand Up @@ -2464,4 +2464,13 @@ private void adjustLocalMusicOffset(int sign) {
BeatmapDB.updateLocalOffset(beatmap);
}
}

/**
* Plays a sound, unless gameplay sounds are disabled.
* @param s the sound effect
*/
private void playSoundEffect(SoundEffect s) {
if (!Options.isGameplaySoundDisabled())
SoundController.playSound(s);
}
}
6 changes: 4 additions & 2 deletions src/itdelatrisu/opsu/states/GamePauseMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ else if (key == Options.getGameKeyRight())
UI.getCursor().reset();
game.enterState(Opsu.STATE_SONGMENU, new EasedFadeOutTransition(), new FadeInTransition());
} else {
SoundController.playSound(SoundEffect.MENUBACK);
if (!Options.isGameplaySoundDisabled())
SoundController.playSound(SoundEffect.MENUBACK);
gameState.setPlayState(Game.PlayState.NORMAL);
game.enterState(Opsu.STATE_GAME);
}
Expand Down Expand Up @@ -160,7 +161,8 @@ public void mousePressed(int button, int x, int y) {

boolean loseState = (gameState.getPlayState() == Game.PlayState.LOSE);
if (continueButton.contains(x, y) && !loseState) {
SoundController.playSound(SoundEffect.MENUBACK);
if (!Options.isGameplaySoundDisabled())
SoundController.playSound(SoundEffect.MENUBACK);
gameState.setPlayState(Game.PlayState.NORMAL);
game.enterState(Opsu.STATE_GAME);
} else if (retryButton.contains(x, y)) {
Expand Down

0 comments on commit 019f577

Please sign in to comment.