small refactor

This commit is contained in:
MachineMuse 2015-08-29 09:25:51 -06:00
parent c9c47b6f44
commit 88e8237cb7
3 changed files with 22 additions and 35 deletions

View file

@ -27,15 +27,16 @@ class ClickableSlider(val pos: MusePoint2D, val width: Double, val name: String)
Math.abs(position.y + 12 - y) < 4
}
var value: Double = 0
var valueInternal: Double = 0
def value = valueInternal
def setValueByX(x: Double) {
val v = (x - pos.x) / width + 0.5
value = MuseMathUtils.clampDouble(v, 0, 1)
valueInternal = MuseMathUtils.clampDouble(v, 0, 1)
}
def setValue(v: Double) {
value = v
valueInternal = v
}
}

View file

@ -1,32 +0,0 @@
package net.machinemuse.general.gui.clickable;
import net.machinemuse.numina.geometry.MusePoint2D;
import net.minecraft.nbt.NBTTagCompound;
public class ClickableTinkerSlider extends ClickableSlider {
public NBTTagCompound moduleTag;
public ClickableTinkerSlider(MusePoint2D topmiddle, double width, NBTTagCompound moduleTag, String name) {
super(topmiddle, width, name);
this.moduleTag = moduleTag;
}
@Override
public double value() {
double val = 0;
if (moduleTag.hasKey(name())) {
val = moduleTag.getDouble(name());
}
return val;
}
public void moveSlider(double x, double y) {
double xval = position.x() - x;
double xratio = 0.5 - (xval / width());
xratio = Math.max(Math.min(xratio, 1.0), 0.0); // Clamp
moduleTag.setDouble(name(), xratio);
}
}

View file

@ -0,0 +1,18 @@
package net.machinemuse.general.gui.clickable
import net.machinemuse.numina.general.MuseMathUtils
import net.machinemuse.numina.geometry.MusePoint2D
import net.minecraft.nbt.NBTTagCompound
class ClickableTinkerSlider(topmiddle: MusePoint2D, width: Double, val moduleTag: NBTTagCompound, name: String) extends ClickableSlider(topmiddle, width, name) {
override def value: Double = {
if(moduleTag.hasKey(name)) moduleTag.getDouble(name) else 0
}
def moveSlider(x: Double, y: Double) {
val xval: Double = position.x - x
val xratio: Double = MuseMathUtils.clampDouble(0.5 - (xval / width), 0, 1)
moduleTag.setDouble(name, xratio)
}
}