v0.3.4: fixed some slider oddities

This commit is contained in:
Evan Debenham 2016-02-03 16:09:36 -05:00
parent 71c16e5e8c
commit 5d4d0bf138
2 changed files with 23 additions and 14 deletions

View File

@ -23,11 +23,12 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Chrome; import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.input.Touchscreen; import com.watabou.input.Touchscreen;
import com.watabou.noosa.*; import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.ui.Component; import com.watabou.noosa.ui.Component;
import com.watabou.utils.Callback;
import com.watabou.utils.GameMath; import com.watabou.utils.GameMath;
import com.watabou.utils.Point;
import com.watabou.utils.PointF; import com.watabou.utils.PointF;
public abstract class OptionSlider extends Component { public abstract class OptionSlider extends Component {
@ -101,8 +102,11 @@ public abstract class OptionSlider extends Component {
sliderNode.size(5, 9); sliderNode.size(5, 9);
touchArea = new TouchArea(0, 0, 0, 0){ touchArea = new TouchArea(0, 0, 0, 0){
boolean pressed = false;
@Override @Override
protected void onTouchDown(Touchscreen.Touch touch) { protected void onTouchDown(Touchscreen.Touch touch) {
pressed = true;
PointF p = camera().screenToCamera((int) touch.current.x, (int) touch.current.y); PointF p = camera().screenToCamera((int) touch.current.x, (int) touch.current.y);
sliderNode.x = GameMath.gate(sliderBG.x-2, p.x, sliderBG.x+sliderBG.width()-2); sliderNode.x = GameMath.gate(sliderBG.x-2, p.x, sliderBG.x+sliderBG.width()-2);
sliderNode.brightness(1.5f); sliderNode.brightness(1.5f);
@ -110,20 +114,25 @@ public abstract class OptionSlider extends Component {
@Override @Override
protected void onDrag(Touchscreen.Touch touch) { protected void onDrag(Touchscreen.Touch touch) {
if (pressed) {
PointF p = camera().screenToCamera((int) touch.current.x, (int) touch.current.y); PointF p = camera().screenToCamera((int) touch.current.x, (int) touch.current.y);
sliderNode.x = GameMath.gate(sliderBG.x-2, p.x, sliderBG.x+sliderBG.width()-2); sliderNode.x = GameMath.gate(sliderBG.x - 2, p.x, sliderBG.x + sliderBG.width() - 2);
}
} }
@Override @Override
protected void onTouchUp(Touchscreen.Touch touch) { protected void onTouchUp(Touchscreen.Touch touch) {
if (pressed) {
PointF p = camera().screenToCamera((int) touch.current.x, (int) touch.current.y); PointF p = camera().screenToCamera((int) touch.current.x, (int) touch.current.y);
sliderNode.x = GameMath.gate(sliderBG.x-2, p.x, sliderBG.x+sliderBG.width()-2); sliderNode.x = GameMath.gate(sliderBG.x - 2, p.x, sliderBG.x + sliderBG.width() - 2);
sliderNode.resetColor(); sliderNode.resetColor();
//sets the selected value //sets the selected value
selectedVal = minVal + Math.round(sliderNode.x/tickDist); selectedVal = minVal + Math.round(sliderNode.x / tickDist);
sliderNode.x = (int)(x + tickDist*(selectedVal-minVal)); sliderNode.x = (int) (x + tickDist * (selectedVal - minVal));
onChange(); onChange();
pressed = false;
}
} }
}; };
add(touchArea); add(touchArea);

View File

@ -20,12 +20,12 @@
*/ */
package com.shatteredpixel.shatteredpixeldungeon.ui; package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.input.Touchscreen.Touch; import com.watabou.input.Touchscreen.Touch;
import com.watabou.noosa.Camera; import com.watabou.noosa.Camera;
import com.watabou.noosa.ColorBlock; import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.TouchArea; import com.watabou.noosa.TouchArea;
import com.watabou.noosa.ui.Component; import com.watabou.noosa.ui.Component;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.utils.Point; import com.watabou.utils.Point;
import com.watabou.utils.PointF; import com.watabou.utils.PointF;
@ -116,7 +116,7 @@ public class ScrollPane extends Component {
} }
@Override @Override
protected void onClick( Touch touch ) { protected void onTouchUp( Touch touch ) {
if (dragging) { if (dragging) {
dragging = false; dragging = false;