music: don't restart when rendrawing tli

the client now synchronizes the music volume with what is stored in the
var during toplevel_redraw, so if music was muted according to vanilla
it would stop music playback even if we were setting it higher.
This commit is contained in:
Max Weber
2021-06-30 07:08:22 -06:00
committed by Abex
parent 81eb06138d
commit 4f24bce080

View File

@@ -188,8 +188,11 @@ public class MusicPlugin extends Plugin
channels = new Channel[]{musicChannel, effectChannel, areaChannel}; channels = new Channel[]{musicChannel, effectChannel, areaChannel};
addMusicButtons(); addMusicButtons();
updateMusicOptions(); if (musicConfig.granularSliders())
resetSettingsWindow(); {
updateMusicOptions();
resetSettingsWindow();
}
}); });
} }
@@ -581,7 +584,11 @@ public class MusicPlugin extends Plugin
// emulate [proc,settings_update_icon] // emulate [proc,settings_update_icon]
boolean unmuted = val != 0; boolean unmuted = val != 0;
icon.getChild(1).setHidden(unmuted); Widget strikethrough = icon.getChild(1);
if (strikethrough != null)
{
strikethrough.setHidden(unmuted);
}
icon.setAction(0, unmuted ? "Mute" : "Unmute"); icon.setAction(0, unmuted ? "Mute" : "Unmute");
// Set name + no tooltip; we have our own for ops // Set name + no tooltip; we have our own for ops
icon.setName(channel.getName()); icon.setName(channel.getName());
@@ -743,6 +750,16 @@ public class MusicPlugin extends Plugin
s.update(); s.update();
s.getChannel().setWindowSlider(s); s.getChannel().setWindowSlider(s);
} }
if (ev.getScriptId() == ScriptID.TOPLEVEL_REDRAW && musicConfig.granularSliders())
{
// we have to set the var to our value so toplevel_redraw doesn't try to set
// the volume to what vanilla has stored
for (Channel c : channels)
{
c.updateVar();
}
}
} }
private class Channel private class Channel
@@ -788,12 +805,12 @@ public class MusicPlugin extends Plugin
// the varps are known by the engine and it requires they are stored so // the varps are known by the engine and it requires they are stored so
// 0 = max and 4 = muted // 0 = max and 4 = muted
int raw = 4 - client.getVar(var); int raw = client.getVar(var);
if (raw == 0) if (raw == 0)
{ {
raw = -(4 - client.getVar(mutedVar)); raw = -client.getVar(mutedVar);
} }
value = ((raw * max) / 4); value = raw * this.max / 100;
// readd our 1 offset for unknown's place // readd our 1 offset for unknown's place
value += value < 0 ? -1 : 1; value += value < 0 ? -1 : 1;
@@ -842,6 +859,12 @@ public class MusicPlugin extends Plugin
windowSlider.update(); windowSlider.update();
} }
} }
public void updateVar()
{
int val = getValue();
client.getVarps()[this.var.getId()] = val * 100 / this.max;
}
public void shutDown() public void shutDown()
{ {
@@ -851,9 +874,7 @@ public class MusicPlugin extends Plugin
windowSlider.shutDown(); windowSlider.shutDown();
} }
int raw = 4 - client.getVar(var); volumeChanger.accept(client.getVar(var) * this.max / 100);
int value = ((raw * max) / 4);
volumeChanger.accept(value);
} }
} }