Complete Slider and Mouse Control on Sliders
This commit is contained in:
@@ -99,7 +99,7 @@ class Slider extends FlxSprite {
|
||||
|
||||
if (showSlider) {
|
||||
_frame.prepareMatrix(_matrix, ANGLE_0, __flipX != camera.flipX, __flipY != camera.flipY);
|
||||
prepareDrawMatrix(camera, -_frame.sourceSize.x * 0.5 + __valueWidth, -(_frame.sourceSize.y - barHeight) * 0.5);
|
||||
prepareDrawMatrix(camera, -_frame.sourceSize.x * 0.5 + (__flipX ? barWidth - __valueWidth : __valueWidth), -(_frame.sourceSize.y - barHeight) * 0.5);
|
||||
forceDrawFrame(camera, _frame);
|
||||
}
|
||||
}
|
||||
@@ -151,11 +151,11 @@ class Slider extends FlxSprite {
|
||||
anim = getBarAnim(1, true);
|
||||
frame = frames.frames[anim.frames[__frameTime % anim.numFrames]];
|
||||
|
||||
if (!flip != !__flipX) __barClipRect.set(0, 0, __valueWidth - x, frame.sourceSize.y);
|
||||
else __barClipRect.set(__cornerWidth - __valueWidth + x, 0, __valueWidth - x, frame.sourceSize.y);
|
||||
if (flip) __barClipRect.set(__cornerWidth - __valueWidth + x, 0, __valueWidth - x, frame.sourceSize.y);
|
||||
else __barClipRect.set(0, 0, __valueWidth - x, frame.sourceSize.y);
|
||||
__barFrame = frame.clipTo(__barClipRect, __barFrame);
|
||||
__barFrame.prepareMatrix(_matrix, ANGLE_0, flip != camera.flipX, __flipY != camera.flipY);
|
||||
prepareDrawMatrix(camera, x, 0);
|
||||
__barFrame.prepareMatrix(_matrix, ANGLE_0, flip != __flipX != camera.flipX, __flipY != camera.flipY);
|
||||
prepareDrawMatrix(camera, __flipX ? barWidth - x - frame.sourceSize.x : x, 0);
|
||||
forceDrawFrame(camera, __barFrame);
|
||||
}
|
||||
|
||||
@@ -163,11 +163,11 @@ class Slider extends FlxSprite {
|
||||
anim = getBarAnim(1, false);
|
||||
frame = frames.frames[anim.frames[__frameTime % anim.numFrames]];
|
||||
|
||||
if (flip != __flipX) __barClipRect.set(0, 0, __cornerWidth - __valueWidth + x, frame.sourceSize.y);
|
||||
if (flip) __barClipRect.set(0, 0, __cornerWidth - __valueWidth + x, frame.sourceSize.y);
|
||||
else __barClipRect.set(__valueWidth - x, 0, __cornerWidth - __valueWidth + x, frame.sourceSize.y);
|
||||
__barFrame = frame.clipTo(__barClipRect, __barFrame);
|
||||
__barFrame.prepareMatrix(_matrix, ANGLE_0, flip != camera.flipX, __flipY != camera.flipY);
|
||||
prepareDrawMatrix(camera, x, 0);
|
||||
__barFrame.prepareMatrix(_matrix, ANGLE_0, flip != __flipX != camera.flipX, __flipY != camera.flipY);
|
||||
prepareDrawMatrix(camera, __flipX ? barWidth - x - frame.sourceSize.x : x, 0);
|
||||
forceDrawFrame(camera, __barFrame);
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ class Slider extends FlxSprite {
|
||||
__barFrame = frame.clipTo(__barClipRect, __barFrame);
|
||||
__barFrame.prepareMatrix(_matrix, ANGLE_0, __flipX != camera.flipX, __flipY != camera.flipY);
|
||||
_matrix.scale(s, 1);
|
||||
prepareDrawMatrix(camera, x, 0);
|
||||
prepareDrawMatrix(camera, __flipX ? barWidth - x - width : x, 0);
|
||||
forceDrawFrame(camera, __barFrame);
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ class Slider extends FlxSprite {
|
||||
__barFrame = frame.clipTo(__barClipRect, __barFrame);
|
||||
__barFrame.prepareMatrix(_matrix, ANGLE_0, __flipX != camera.flipX, __flipY != camera.flipY);
|
||||
_matrix.scale(s, 1);
|
||||
prepareDrawMatrix(camera, x, 0);
|
||||
prepareDrawMatrix(camera, __flipX ? barWidth - x - width : x, 0);
|
||||
forceDrawFrame(camera, __barFrame);
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ class Slider extends FlxSprite {
|
||||
__barClipRect.set(offset, 0, __valueWidth - x, frame.sourceSize.y);
|
||||
__barFrame = frame.clipTo(__barClipRect, __barFrame);
|
||||
__barFrame.prepareMatrix(_matrix, ANGLE_0, __flipX != camera.flipX, __flipY != camera.flipY);
|
||||
prepareDrawMatrix(camera, x, 0);
|
||||
prepareDrawMatrix(camera, __flipX ? barWidth - x - width : x, 0);
|
||||
forceDrawFrame(camera, __barFrame);
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ class Slider extends FlxSprite {
|
||||
__barClipRect.set(__valueWidth - x + offset, 0, __segmentWidth - offset - __valueWidth + x, frame.sourceSize.y);
|
||||
__barFrame = frame.clipTo(__barClipRect, __barFrame);
|
||||
__barFrame.prepareMatrix(_matrix, ANGLE_0, __flipX != camera.flipX, __flipY != camera.flipY);
|
||||
prepareDrawMatrix(camera, x, 0);
|
||||
prepareDrawMatrix(camera, __flipX ? barWidth - x - width : x, 0);
|
||||
forceDrawFrame(camera, __barFrame);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,10 +93,20 @@ class TreeMenuScreen extends FlxSpriteGroup {
|
||||
|
||||
if (inputEnabled) {
|
||||
for (basic in turboBasics) basic.update(elapsed);
|
||||
changeSelection((upTurboControl.activated ? -1 : 0) + (downTurboControl.activated ? 1 : 0) - FlxG.mouse.wheel);
|
||||
|
||||
var change = (upTurboControl.activated ? -1 : 0) + (downTurboControl.activated ? 1 : 0) - FlxG.mouse.wheel, mouseControl = false;
|
||||
if (FlxG.mouse.justPressed) {
|
||||
for (i in CoolUtil.maxInt(curSelected - 3, 0)...CoolUtil.minInt(curSelected + 4, length))
|
||||
if (i != curSelected && members[i] != null && mouseOverlaps(members[i])) {
|
||||
change = i - curSelected;
|
||||
mouseControl = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
changeSelection(change);
|
||||
|
||||
if (length > 0 && curOption != null) {
|
||||
if (controls.ACCEPT || (FlxG.mouse.justPressed && FlxG.mouse.overlaps(members[curSelected]))) curOption.select();
|
||||
if (controls.ACCEPT || (!mouseControl && FlxG.mouse.justPressed && mouseOverlaps(members[curSelected]))) curOption.select();
|
||||
if (curFloatOption != null) {
|
||||
if (controls.LEFT) curFloatOption.changeValue(-elapsed);
|
||||
if (controls.RIGHT) curFloatOption.changeValue(elapsed);
|
||||
@@ -172,9 +182,11 @@ class TreeMenuScreen extends FlxSpriteGroup {
|
||||
if (parent != null) parent.updateDesc(customTxt);
|
||||
}
|
||||
|
||||
function mouseOverlaps(sprite:FlxSprite):Bool
|
||||
return sprite.overlapsPoint(FlxG.mouse.getPosition(@:privateAccess flixel.input.FlxPointer._cachedPoint), true);
|
||||
|
||||
override function destroy() {
|
||||
super.destroy();
|
||||
|
||||
for (basic in turboBasics) basic.destroy();
|
||||
}
|
||||
}
|
||||
@@ -16,16 +16,20 @@ class SliderOption extends TextOption implements ITreeFloatOption {
|
||||
public var optionName:String;
|
||||
|
||||
public var slider:Slider;
|
||||
public var dynamicWidth:Bool;
|
||||
|
||||
var __mouseControl:Bool;
|
||||
|
||||
function getValue():Float return (currentValue - min) / (max - min);
|
||||
|
||||
override function set_text(v:String) {
|
||||
super.set_text(v);
|
||||
slider.x = __text.x + __text.width + 30;
|
||||
if (dynamicWidth) slider.barWidth = 1100 - __text.width;
|
||||
return v;
|
||||
}
|
||||
|
||||
public function new(text:String, desc:String, min:Float, max:Float, step:Float, ?segments:Int, optionName:String, barWidth = 600.0,
|
||||
public function new(text:String, desc:String, min:Float, max:Float, step:Float, ?segments:Int, optionName:String, barWidth = -1,
|
||||
?changedCallback:Float->Void = null, ?parent:Dynamic)
|
||||
{
|
||||
this.changedCallback = changedCallback;
|
||||
@@ -37,7 +41,7 @@ class SliderOption extends TextOption implements ITreeFloatOption {
|
||||
|
||||
if (Reflect.field(parent, optionName) != null) currentValue = Reflect.field(parent, optionName);
|
||||
|
||||
slider = new Slider(12, 0, getValue(), barWidth, segments);
|
||||
slider = new Slider(12, 0, getValue(), (dynamicWidth = barWidth < 0) ? 600 : barWidth, segments);
|
||||
slider.scale.set(0.75, 0.75);
|
||||
slider.updateHitbox();
|
||||
|
||||
@@ -47,7 +51,22 @@ class SliderOption extends TextOption implements ITreeFloatOption {
|
||||
}
|
||||
|
||||
override function update(elapsed:Float) {
|
||||
slider.selected = selected && !locked;
|
||||
if (slider.selected = selected && !locked) {
|
||||
if (__mouseControl && FlxG.mouse.justReleased) __mouseControl = false;
|
||||
else if (FlxG.mouse.justPressed) __mouseControl = slider.overlapsPoint(FlxG.mouse.getPosition(@:privateAccess flixel.input.FlxPointer._cachedPoint), true);
|
||||
|
||||
if (__mouseControl) {
|
||||
var p = @:privateAccess flixel.input.FlxPointer._cachedPoint;
|
||||
if (!FlxG.mouse.justPressed) FlxG.mouse.getPosition(p);
|
||||
p.subtractPoint(camera.scroll);
|
||||
|
||||
slider.getScreenPosition(_point, camera);
|
||||
changeValue((FlxMath.remapToRange(p.x - _point.x, 0, slider.width, min, max) - currentValue) / step);
|
||||
}
|
||||
}
|
||||
else
|
||||
__mouseControl = false;
|
||||
|
||||
slider.value = getValue();
|
||||
//__text.x = slider.x + slider.width + 30;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user