diff --git a/src/main/java/me/zeroeightsix/kami/gui/kami/component/SettingsPanel.java b/src/main/java/me/zeroeightsix/kami/gui/kami/component/SettingsPanel.java index 7c39277a..ac2005f8 100644 --- a/src/main/java/me/zeroeightsix/kami/gui/kami/component/SettingsPanel.java +++ b/src/main/java/me/zeroeightsix/kami/gui/kami/component/SettingsPanel.java @@ -81,17 +81,26 @@ public class SettingsPanel extends OrganisedContainer { if (numberSetting.getMin() != null) slider.setMin(numberSetting.getMin().doubleValue()); addChild(slider); } else { - Slider slider = new Slider(numberSetting.getValue().doubleValue(), numberSetting.getMin().doubleValue(), numberSetting.getMax().doubleValue(), Slider.getDefaultStep(numberSetting.getMin().doubleValue(), numberSetting.getMax().doubleValue()), name, setting instanceof IntegerSetting); + // Terrible terrible bug fix. + // I know, these parseDoubles look awful, but any conversions I tried here would end up with weird floating point conversion errors. + // This is really the easiest solution.. + double value = Double.parseDouble(numberSetting.getValue().toString()); + double min = Double.parseDouble(numberSetting.getMin().toString()); + double max = Double.parseDouble(numberSetting.getMax().toString()); + Slider slider = new Slider( + value, min, max, + Slider.getDefaultStep(min, max), + name, + setting instanceof IntegerSetting); slider.addPoof(new Slider.SliderPoof() { @Override public void execute(Slider component, SliderPoofInfo info) { if (setting instanceof IntegerSetting) - setting.setValue(new Integer((int) info.getNewValue())); + setting.setValue((int) info.getNewValue()); else if (setting instanceof FloatSetting) - setting.setValue(new Float(info.getNewValue())); + setting.setValue((float) info.getNewValue()); else if (setting instanceof DoubleSetting) setting.setValue(info.getNewValue()); - setModule(module); } }); addChild(slider); diff --git a/src/main/java/me/zeroeightsix/kami/gui/kami/theme/kami/RootSliderUI.java b/src/main/java/me/zeroeightsix/kami/gui/kami/theme/kami/RootSliderUI.java index a0d62d15..a25f002b 100644 --- a/src/main/java/me/zeroeightsix/kami/gui/kami/theme/kami/RootSliderUI.java +++ b/src/main/java/me/zeroeightsix/kami/gui/kami/theme/kami/RootSliderUI.java @@ -21,7 +21,8 @@ public class RootSliderUI extends AbstractComponentUI { glColor4f(1,0.33f,0.33f,component.getOpacity()); glLineWidth(2.5f); int height = component.getHeight(); - double w = component.getWidth() * (component.getValue() / component.getMaximum()); + double value = component.getValue(); + double w = component.getWidth() * ((value - component.getMinimum()) / (component.getMaximum() - component.getMinimum())); float downscale = 1.1f; glBegin(GL_LINES); { @@ -37,11 +38,7 @@ public class RootSliderUI extends AbstractComponentUI { glColor3f(1,0.33f,0.33f); RenderHelper.drawCircle((int)w,height/downscale,2f); - String s = ""; - if (Math.floor(component.getValue())==component.getValue()) - s += (int) component.getValue(); - else - s += component.getValue(); + String s = value + ""; if (component.isPressed()){ w -= smallFontRenderer.getStringWidth(s)/2; w = Math.max(0,Math.min(w, component.getWidth()-smallFontRenderer.getStringWidth(s))); diff --git a/src/main/java/me/zeroeightsix/kami/gui/rgui/component/use/Slider.java b/src/main/java/me/zeroeightsix/kami/gui/rgui/component/use/Slider.java index 748ee7d2..e4795d01 100644 --- a/src/main/java/me/zeroeightsix/kami/gui/rgui/component/use/Slider.java +++ b/src/main/java/me/zeroeightsix/kami/gui/rgui/component/use/Slider.java @@ -102,7 +102,8 @@ public class Slider extends AbstractComponent { public void setValue(double value) { SliderPoof.SliderPoofInfo info = new SliderPoof.SliderPoofInfo(this.value, value); callPoof(SliderPoof.class, info); - this.value = integer ? (int) info.getNewValue() : info.getNewValue(); + double newValue = info.getNewValue(); + this.value = integer ? (int) newValue : newValue; } public static abstract class SliderPoof extends Poof {