music: remove volume slider granularity
this interface was entirely rewritten
This commit is contained in:
@@ -83,16 +83,6 @@ public final class ScriptID
|
||||
@ScriptArguments(integer = 2)
|
||||
public static final int MESSAGE_LAYER_CLOSE = 299;
|
||||
|
||||
/**
|
||||
* Sets the background for sound option bars
|
||||
* <ul>
|
||||
* <li> int Value of the slider (0-4) </li>
|
||||
* <li> int (WidgetID) * 5, segments of the slider </li>
|
||||
* </ul>
|
||||
*/
|
||||
@ScriptArguments(integer = 6)
|
||||
public static final int OPTIONS_ALLSOUNDS = 358;
|
||||
|
||||
/**
|
||||
* Readies the chatbox panel for things like the chatbox input
|
||||
* Inverse of MESSAGE_LAYER_CLOSE
|
||||
|
||||
@@ -533,9 +533,6 @@ public enum WidgetInfo
|
||||
SEED_VAULT_INVENTORY_ITEMS_CONTAINER(WidgetID.SEED_VAULT_INVENTORY_GROUP_ID, WidgetID.SeedVault.INVENTORY_ITEM_CONTAINER),
|
||||
|
||||
OPTIONS_CAMERA_ZOOM_SLIDER_HANDLE(WidgetID.OPTIONS_GROUP_ID, WidgetID.Options.CAMERA_ZOOM_SLIDER_HANDLE),
|
||||
OPTIONS_MUSIC_SLIDER(WidgetID.OPTIONS_GROUP_ID, WidgetID.Options.MUSIC_SLIDER),
|
||||
OPTIONS_SOUND_EFFECT_SLIDER(WidgetID.OPTIONS_GROUP_ID, WidgetID.Options.SOUND_EFFECT_SLIDER),
|
||||
OPTIONS_AREA_SOUND_SLIDER(WidgetID.OPTIONS_GROUP_ID, WidgetID.Options.AREA_SOUND_SLIDER),
|
||||
|
||||
ACHIEVEMENT_DIARY_CONTAINER(WidgetID.ACHIEVEMENT_DIARY_GROUP_ID, WidgetID.AchievementDiary.CONTAINER),
|
||||
|
||||
|
||||
@@ -32,14 +32,10 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.ToIntFunction;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
@@ -49,18 +45,13 @@ import net.runelite.api.ScriptID;
|
||||
import net.runelite.api.SoundEffectID;
|
||||
import net.runelite.api.SpriteID;
|
||||
import net.runelite.api.VarClientInt;
|
||||
import net.runelite.api.VarPlayer;
|
||||
import net.runelite.api.events.AreaSoundEffectPlayed;
|
||||
import net.runelite.api.events.BeforeRender;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.ScriptCallbackEvent;
|
||||
import net.runelite.api.events.SoundEffectPlayed;
|
||||
import net.runelite.api.events.VarClientIntChanged;
|
||||
import net.runelite.api.events.VolumeChanged;
|
||||
import net.runelite.api.events.WidgetLoaded;
|
||||
import net.runelite.api.widgets.JavaScriptCallback;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetConfig;
|
||||
import net.runelite.api.widgets.WidgetID;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.api.widgets.WidgetPositionMode;
|
||||
@@ -68,13 +59,10 @@ import net.runelite.api.widgets.WidgetType;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.events.ConfigChanged;
|
||||
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
||||
import net.runelite.client.game.chatbox.ChatboxTextInput;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.ui.overlay.tooltip.Tooltip;
|
||||
import net.runelite.client.ui.overlay.tooltip.TooltipManager;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Music",
|
||||
@@ -129,9 +117,6 @@ public class MusicPlugin extends Plugin
|
||||
@Inject
|
||||
private ChatboxPanelManager chatboxPanelManager;
|
||||
|
||||
@Inject
|
||||
private TooltipManager tooltipManager;
|
||||
|
||||
private ChatboxTextInput searchInput;
|
||||
|
||||
private Widget musicSearchButton;
|
||||
@@ -141,16 +126,12 @@ public class MusicPlugin extends Plugin
|
||||
|
||||
private MusicState currentMusicFilter = MusicState.ALL;
|
||||
|
||||
private MusicSlider hoveredSlider;
|
||||
|
||||
@Override
|
||||
protected void startUp()
|
||||
{
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
addMusicButtons();
|
||||
applyMusicVolumeConfig();
|
||||
updateMusicOptions();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -164,8 +145,6 @@ public class MusicPlugin extends Plugin
|
||||
}
|
||||
|
||||
tracks = null;
|
||||
hoveredSlider = null;
|
||||
clientThread.invoke(this::teardownMusicOptions);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -196,10 +175,6 @@ public class MusicPlugin extends Plugin
|
||||
currentMusicFilter = MusicState.ALL;
|
||||
addMusicButtons();
|
||||
}
|
||||
if (widgetLoaded.getGroupId() == WidgetID.OPTIONS_GROUP_ID)
|
||||
{
|
||||
updateMusicOptions();
|
||||
}
|
||||
}
|
||||
|
||||
private void addMusicButtons()
|
||||
@@ -250,44 +225,6 @@ public class MusicPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onVolumeChanged(VolumeChanged volumeChanged)
|
||||
{
|
||||
applyMusicVolumeConfig();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onConfigChanged(ConfigChanged configChanged)
|
||||
{
|
||||
if (configChanged.getGroup().equals("music"))
|
||||
{
|
||||
clientThread.invokeLater(this::applyMusicVolumeConfig);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyMusicVolumeConfig()
|
||||
{
|
||||
int musicVolume = musicConfig.getMusicVolume();
|
||||
if (musicVolume > 0)
|
||||
{
|
||||
client.setMusicVolume(musicVolume - 1);
|
||||
}
|
||||
|
||||
int soundEffectVolume = musicConfig.getSoundEffectVolume();
|
||||
if (soundEffectVolume > 0)
|
||||
{
|
||||
client.setSoundEffectVolume(soundEffectVolume - 1);
|
||||
}
|
||||
|
||||
int areaSoundEffectVolume = musicConfig.getAreaSoundEffectVolume();
|
||||
if (areaSoundEffectVolume > 0)
|
||||
{
|
||||
client.setAreaSoundEffectVolume(areaSoundEffectVolume - 1);
|
||||
}
|
||||
|
||||
updateMusicOptions();
|
||||
}
|
||||
|
||||
private boolean isOnMusicTab()
|
||||
{
|
||||
return client.getVar(VarClientInt.INVENTORY_TAB) == 13;
|
||||
@@ -413,221 +350,6 @@ public class MusicPlugin extends Plugin
|
||||
private final int spriteID;
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
private enum MusicSlider
|
||||
{
|
||||
MUSIC("Music", WidgetInfo.OPTIONS_MUSIC_SLIDER, VarPlayer.MUSIC_VOLUME, MusicConfig::getMusicVolume, MusicConfig::setMusicVolume, 255),
|
||||
AREA("Area Sounds", WidgetInfo.OPTIONS_AREA_SOUND_SLIDER, VarPlayer.AREA_EFFECT_VOLUME, MusicConfig::getAreaSoundEffectVolume, MusicConfig::setAreaSoundEffectVolume, 127),
|
||||
EFFECT("Sound Effects", WidgetInfo.OPTIONS_SOUND_EFFECT_SLIDER, VarPlayer.SOUND_EFFECT_VOLUME, MusicConfig::getSoundEffectVolume, MusicConfig::setSoundEffectVolume, 127);
|
||||
|
||||
private final String name;
|
||||
private final WidgetInfo widgetID;
|
||||
private final VarPlayer var;
|
||||
private final ToIntFunction<MusicConfig> getter;
|
||||
private final BiConsumer<MusicConfig, Integer> setter;
|
||||
private final int max;
|
||||
|
||||
@Setter
|
||||
private Widget handle;
|
||||
|
||||
@Setter
|
||||
private Widget track;
|
||||
|
||||
private static int PADDING = 8;
|
||||
|
||||
private int getX()
|
||||
{
|
||||
return getTrack().getRelativeX() + PADDING;
|
||||
}
|
||||
|
||||
private int getWidth()
|
||||
{
|
||||
return getTrack().getWidth() - (PADDING * 2) - handle.getWidth();
|
||||
}
|
||||
|
||||
private int getValue(final MusicConfig config, final Client client)
|
||||
{
|
||||
int value = getter.applyAsInt(config) - 1;
|
||||
if (value <= -1)
|
||||
{
|
||||
// Use the vanilla value
|
||||
value = ((4 - client.getVar(var)) * max) / 4;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private void teardownMusicOptions()
|
||||
{
|
||||
for (MusicSlider slider : MusicSlider.values())
|
||||
{
|
||||
Widget icon = client.getWidget(slider.getWidgetID());
|
||||
if (icon == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (slider.getHandle() != null)
|
||||
{
|
||||
{
|
||||
Widget handle = slider.getHandle();
|
||||
Widget parent = handle.getParent();
|
||||
if (parent == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Widget[] siblings = parent.getChildren();
|
||||
if (siblings == null || handle.getIndex() >= siblings.length || siblings[handle.getIndex()] != handle)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
siblings[slider.getTrack().getIndex()] = null;
|
||||
siblings[handle.getIndex()] = null;
|
||||
}
|
||||
}
|
||||
|
||||
Object[] init = icon.getOnLoadListener();
|
||||
init[1] = slider.getWidgetID().getId();
|
||||
|
||||
// Readd the var transmit triggers and rerun options_allsounds
|
||||
client.runScript(init);
|
||||
slider.setHandle(null);
|
||||
slider.setTrack(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMusicOptions()
|
||||
{
|
||||
for (MusicSlider slider : MusicSlider.values())
|
||||
{
|
||||
Widget icon = client.getWidget(slider.getWidgetID());
|
||||
// VolumeChanged can trigger us before the sliders interface is fully valid, so
|
||||
// we check if the width is set before we copy it to all of our widgets
|
||||
if (icon == null || icon.getWidth() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Widget handle = slider.getHandle();
|
||||
if (handle != null)
|
||||
{
|
||||
Widget parent = handle.getParent();
|
||||
if (parent == null)
|
||||
{
|
||||
handle = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Widget[] siblings = parent.getChildren();
|
||||
if (siblings == null || handle.getIndex() >= siblings.length || siblings[handle.getIndex()] != handle)
|
||||
{
|
||||
handle = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (handle == null)
|
||||
{
|
||||
Object[] init = icon.getOnLoadListener();
|
||||
icon.setVarTransmitTrigger((int[]) null);
|
||||
|
||||
Widget track = icon.getParent().createChild(-1, WidgetType.TEXT);
|
||||
slider.setTrack(track);
|
||||
handle = icon.getParent().createChild(-1, WidgetType.GRAPHIC);
|
||||
slider.setHandle(handle);
|
||||
|
||||
{
|
||||
// First widget of the track
|
||||
int wid = (Integer) init[2];
|
||||
Widget w = client.getWidget(WidgetInfo.TO_GROUP(wid), WidgetInfo.TO_CHILD(wid));
|
||||
|
||||
track.setOriginalX(w.getRelativeX());
|
||||
track.setOriginalY(w.getRelativeY());
|
||||
}
|
||||
{
|
||||
// Last widget of the track
|
||||
int wid = (Integer) init[6];
|
||||
Widget w = client.getWidget(WidgetInfo.TO_GROUP(wid), WidgetInfo.TO_CHILD(wid));
|
||||
|
||||
track.setOriginalWidth((w.getRelativeX() + w.getWidth()) - track.getOriginalX());
|
||||
}
|
||||
|
||||
track.setOriginalHeight(16);
|
||||
track.setNoClickThrough(true);
|
||||
track.revalidate();
|
||||
|
||||
handle.setSpriteId(SpriteID.OPTIONS_ZOOM_SLIDER_THUMB);
|
||||
handle.setOriginalWidth(16);
|
||||
handle.setOriginalHeight(16);
|
||||
handle.setClickMask(WidgetConfig.DRAG);
|
||||
handle.revalidate();
|
||||
|
||||
handle.setOnMouseRepeatListener((JavaScriptCallback) ev -> hoveredSlider = slider);
|
||||
handle.setHasListener(true);
|
||||
|
||||
JavaScriptCallback move = ev ->
|
||||
{
|
||||
int newVal = ((ev.getMouseX() - MusicSlider.PADDING - (slider.getHandle().getWidth() / 2)) * slider.getMax())
|
||||
/ slider.getWidth();
|
||||
if (newVal < 0)
|
||||
{
|
||||
newVal = 0;
|
||||
}
|
||||
if (newVal > slider.getMax())
|
||||
{
|
||||
newVal = slider.getMax();
|
||||
}
|
||||
|
||||
// We store +1 so we can tell the difference between 0 and muted
|
||||
slider.getSetter().accept(musicConfig, newVal + 1);
|
||||
applyMusicVolumeConfig();
|
||||
};
|
||||
|
||||
track.setOnClickListener(move);
|
||||
track.setOnHoldListener(move);
|
||||
track.setOnReleaseListener(move);
|
||||
track.setHasListener(true);
|
||||
|
||||
client.runScript(ScriptID.OPTIONS_ALLSOUNDS, -1, init[2], init[3], init[4], init[5], init[6]);
|
||||
}
|
||||
|
||||
final int value = slider.getValue(musicConfig, client);
|
||||
final int newX = ((value * slider.getWidth()) / slider.getMax()) + slider.getX();
|
||||
slider.getHandle().setOriginalX(newX);
|
||||
slider.getHandle().setOriginalY(slider.getTrack().getOriginalY());
|
||||
slider.getHandle().revalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onBeforeRender(final BeforeRender event)
|
||||
{
|
||||
// Tooltips are auto-cleared before each render frame; create a new updated one for this frame
|
||||
if (hoveredSlider != null)
|
||||
{
|
||||
final int value = hoveredSlider.getValue(musicConfig, client);
|
||||
final int percent = (int) Math.round((value * 100.0 / hoveredSlider.getMax()));
|
||||
|
||||
tooltipManager.add(new Tooltip(hoveredSlider.getName() + ": " + percent + "%"));
|
||||
hoveredSlider = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onScriptCallbackEvent(ScriptCallbackEvent ev)
|
||||
{
|
||||
switch (ev.getEventName())
|
||||
{
|
||||
case "optionsAllSounds":
|
||||
// We have to override this script because it gets invoked periodically from the server
|
||||
client.getIntStack()[client.getIntStackSize() - 1] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onAreaSoundEffectPlayed(AreaSoundEffectPlayed areaSoundEffectPlayed)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user