metronome: add independent volume configuration

This commit is contained in:
Matthew Kramer
2020-05-21 15:44:21 -04:00
committed by GitHub
parent aea258fb5c
commit a01a2483f7
2 changed files with 40 additions and 14 deletions

View File

@@ -27,7 +27,6 @@ package net.runelite.client.plugins.metronome;
import com.google.inject.Provides; import com.google.inject.Provides;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.api.SoundEffectVolume;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.SoundEffectID; import net.runelite.api.SoundEffectID;
import net.runelite.api.events.GameTick; import net.runelite.api.events.GameTick;
@@ -69,14 +68,23 @@ public class MetronomePlugin extends Plugin
if (++tickCounter % config.tickCount() == 0) if (++tickCounter % config.tickCount() == 0)
{ {
if (config.enableTock() && shouldTock) // As playSoundEffect only uses the volume argument when the in-game volume isn't muted, sound effect volume
// needs to be set to the value desired for ticks or tocks and afterwards reset to the previous value.
int previousVolume = client.getSoundEffectVolume();
if (shouldTock && config.tockVolume() > 0)
{ {
client.playSoundEffect(SoundEffectID.GE_DECREMENT_PLOP, SoundEffectVolume.MEDIUM_HIGH); client.setSoundEffectVolume(config.tockVolume());
client.playSoundEffect(SoundEffectID.GE_DECREMENT_PLOP, config.tockVolume());
} }
else else if (config.tickVolume() > 0)
{ {
client.playSoundEffect(SoundEffectID.GE_INCREMENT_PLOP, SoundEffectVolume.MEDIUM_HIGH); client.setSoundEffectVolume(config.tickVolume());
client.playSoundEffect(SoundEffectID.GE_INCREMENT_PLOP, config.tickVolume());
} }
client.setSoundEffectVolume(previousVolume);
shouldTock = !shouldTock; shouldTock = !shouldTock;
} }
} }

View File

@@ -28,29 +28,47 @@ package net.runelite.client.plugins.metronome;
import net.runelite.client.config.Config; import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem; import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Range;
import net.runelite.api.SoundEffectVolume;
@ConfigGroup("metronome") @ConfigGroup("metronome")
public interface MetronomePluginConfiguration extends Config public interface MetronomePluginConfiguration extends Config
{ {
int VOLUME_MAX = SoundEffectVolume.HIGH;
@ConfigItem( @ConfigItem(
keyName = "tickCount", keyName = "tickCount",
name = "Tick count", name = "Tick count",
description = "Configures the tick on which a sound will be played", description = "Configures the tick on which a sound will be played."
position = 2
) )
default int tickCount() default int tickCount()
{ {
return 1; return 1;
} }
@ConfigItem( @Range(
keyName = "enableTock", max = VOLUME_MAX
name = "Enable tock (alternating) sound",
description = "Toggles whether to play two alternating sounds",
position = 3
) )
default boolean enableTock() @ConfigItem(
keyName = "tickVolume",
name = "Tick volume",
description = "Configures the volume of the tick sound. A value of 0 will disable tick sounds."
)
default int tickVolume()
{ {
return false; return SoundEffectVolume.MEDIUM_HIGH;
}
@Range(
max = VOLUME_MAX
)
@ConfigItem(
keyName = "tockVolume",
name = "Tock volume",
description = "Configures the volume of the tock sound. A value of 0 will disable tock sounds."
)
default int tockVolume()
{
return SoundEffectVolume.MUTED;
} }
} }