attempt to fix stuff not updating

This commit is contained in:
yugecin 2016-12-11 16:32:21 +01:00
parent 98e9b5c210
commit 6660f127f9
2 changed files with 32 additions and 30 deletions

View File

@ -47,6 +47,7 @@ import org.lwjgl.input.Keyboard;
import org.newdawn.slick.GameContainer; import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException; import org.newdawn.slick.SlickException;
import org.newdawn.slick.openal.SoundStore;
import org.newdawn.slick.util.ClasspathLocation; import org.newdawn.slick.util.ClasspathLocation;
import org.newdawn.slick.util.FileSystemLocation; import org.newdawn.slick.util.FileSystemLocation;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
@ -56,13 +57,8 @@ import com.sun.jna.platform.win32.Advapi32Util;
import com.sun.jna.platform.win32.Win32Exception; import com.sun.jna.platform.win32.Win32Exception;
import com.sun.jna.platform.win32.WinReg; import com.sun.jna.platform.win32.WinReg;
import yugecin.opsudance.*; import yugecin.opsudance.*;
import yugecin.opsudance.movers.CubicBezierMover;
import yugecin.opsudance.movers.QuadraticBezierMover;
import yugecin.opsudance.movers.factories.AutoMoverFactory;
import yugecin.opsudance.movers.factories.QuadraticBezierMoverFactory; import yugecin.opsudance.movers.factories.QuadraticBezierMoverFactory;
import yugecin.opsudance.movers.slidermovers.DefaultSliderMoverController; import yugecin.opsudance.movers.slidermovers.DefaultSliderMoverController;
import yugecin.opsudance.spinners.Spinner;
import yugecin.opsudance.ui.SBOverlay;
/** /**
* Handles all user options. * Handles all user options.
@ -449,16 +445,16 @@ public class Options {
LOAD_VERBOSE ("Show Detailed Loading Progress", "LoadVerbose", "Display more specific loading information in the splash screen.", false), LOAD_VERBOSE ("Show Detailed Loading Progress", "LoadVerbose", "Display more specific loading information in the splash screen.", false),
MASTER_VOLUME ("Master Volume", "VolumeUniversal", "Global volume level.", 35, 0, 100) { MASTER_VOLUME ("Master Volume", "VolumeUniversal", "Global volume level.", 35, 0, 100) {
@Override @Override
public void drag(GameContainer container, int d) { public void setValue(int value) {
super.drag(container, d); super.setValue(value);
container.setMusicVolume(getMasterVolume() * getMusicVolume()); SoundStore.get().setMusicVolume(getMasterVolume() * getMusicVolume());
} }
}, },
MUSIC_VOLUME ("Music Volume", "VolumeMusic", "Volume of music.", 80, 0, 100) { MUSIC_VOLUME ("Music Volume", "VolumeMusic", "Volume of music.", 80, 0, 100) {
@Override @Override
public void drag(GameContainer container, int d) { public void setValue(int value) {
super.drag(container, d); super.setValue(value);
container.setMusicVolume(getMasterVolume() * getMusicVolume()); SoundStore.get().setMusicVolume(getMasterVolume() * getMusicVolume());
} }
}, },
SAMPLE_VOLUME_OVERRIDE ("Sample volume override", "BMSampleOverride", "Override beatmap hitsound volume", 100, 0, 100) { SAMPLE_VOLUME_OVERRIDE ("Sample volume override", "BMSampleOverride", "Override beatmap hitsound volume", 100, 0, 100) {
@ -1084,19 +1080,6 @@ public class Options {
*/ */
public void clickListItem(int index) { } public void clickListItem(int index) { }
/**
* Processes a mouse drag action (via override).
* <p>
* By default, only if this is a numeric option, the {@code val} field
* will be shifted by {@code d} within the given bounds.
* @param container the game container
* @param d the dragged distance (modified by multiplier)
*/
public void drag(GameContainer container, int d) { // TODO rename this
if (type == OptionType.NUMERIC)
val = Utils.clamp(val + d, min, max);
}
/** /**
* Returns the string to write to the configuration file (via override). * Returns the string to write to the configuration file (via override).
* <p> * <p>

View File

@ -70,6 +70,9 @@ public class OptionsOverlay {
private boolean keyEntryLeft; private boolean keyEntryLeft;
private boolean keyEntryRight; private boolean keyEntryRight;
private int prevMouseX;
private int prevMouseY;
public OptionsOverlay(Parent parent, OptionTab[] tabs, int defaultSelectedTabIndex, GameContainer container) { public OptionsOverlay(Parent parent, OptionTab[] tabs, int defaultSelectedTabIndex, GameContainer container) {
this.parent = parent; this.parent = parent;
this.container = container; this.container = container;
@ -324,14 +327,15 @@ public class OptionsOverlay {
} }
public void update(int delta, int mouseX, int mouseY) { public void update(int delta, int mouseX, int mouseY) {
if (mouseX - prevMouseX == 0 && mouseY - prevMouseY == 0) {
return;
}
prevMouseX = mouseX;
prevMouseY = mouseY;
updateHoverOption(mouseX, mouseY); updateHoverOption(mouseX, mouseY);
UI.getBackButton().hoverUpdate(delta, mouseX, mouseY); UI.getBackButton().hoverUpdate(delta, mouseX, mouseY);
if (isAdjustingSlider) { if (isAdjustingSlider) {
int min = selectedOption.getMinValue(); updateSliderOption(mouseX, mouseY);
int max = selectedOption.getMaxValue();
int value = min + (int) ((float) (max - min) * (mouseX - sliderOptionStartX) / (sliderOptionLength));
selectedOption.setValue(Utils.clamp(value, min, max));
selectedOption.drag(container, 0);
} else if (isListOptionOpen) { } else if (isListOptionOpen) {
if (listStartX <= mouseX && mouseX < listStartX + listWidth && listStartY <= mouseY && mouseY < listStartY + listHeight) { if (listStartX <= mouseX && mouseX < listStartX + listWidth && listStartY <= mouseY && mouseY < listStartY + listHeight) {
listHoverIndex = (mouseY - listStartY) / optionHeight; listHoverIndex = (mouseY - listStartY) / optionHeight;
@ -366,6 +370,9 @@ public class OptionsOverlay {
isListOptionOpen = true; isListOptionOpen = true;
} else if (selectedOption.getType() == OptionType.NUMERIC) { } else if (selectedOption.getType() == OptionType.NUMERIC) {
isAdjustingSlider = sliderOptionStartX <= x && x < sliderOptionStartX + sliderOptionLength; isAdjustingSlider = sliderOptionStartX <= x && x < sliderOptionStartX + sliderOptionLength;
if (isAdjustingSlider) {
updateSliderOption(x, y);
}
} else if (selectedOption == GameOption.KEY_LEFT) { } else if (selectedOption == GameOption.KEY_LEFT) {
keyEntryLeft = true; keyEntryLeft = true;
} else if (selectedOption == GameOption.KEY_RIGHT) { } else if (selectedOption == GameOption.KEY_RIGHT) {
@ -380,6 +387,9 @@ public class OptionsOverlay {
public void mouseReleased(int button, int x, int y) { public void mouseReleased(int button, int x, int y) {
selectedOption = null; selectedOption = null;
if (isAdjustingSlider) {
parent.onSaveOption(hoverOption);
}
isAdjustingSlider = false; isAdjustingSlider = false;
sliderOptionLength = 0; sliderOptionLength = 0;
@ -389,7 +399,9 @@ public class OptionsOverlay {
} }
if (hoverOption != null) { if (hoverOption != null) {
if (hoverOption.getType() != OptionType.NUMERIC) {
parent.onSaveOption(hoverOption); parent.onSaveOption(hoverOption);
}
if (hoverOption.getType() == OptionType.BOOLEAN) { if (hoverOption.getType() == OptionType.BOOLEAN) {
hoverOption.click(container); hoverOption.click(container);
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
@ -450,6 +462,13 @@ public class OptionsOverlay {
return false; return false;
} }
private void updateSliderOption(int mouseX, int mouseY) {
int min = selectedOption.getMinValue();
int max = selectedOption.getMaxValue();
int value = min + (int) ((float) (max - min) * (mouseX - sliderOptionStartX) / (sliderOptionLength));
selectedOption.setValue(Utils.clamp(value, min, max));
}
private void updateHoverOption(int mouseX, int mouseY) { private void updateHoverOption(int mouseX, int mouseY) {
if (isListOptionOpen || keyEntryLeft || keyEntryRight) { if (isListOptionOpen || keyEntryLeft || keyEntryRight) {
return; return;