Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions flixel/addons/ui/FlxSlider.hx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class FlxSlider extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else Flx
*/
public var varString(default, set):String;

/**
Whether the slider is currently being dragged
**/
public var dragging:Bool = false;

/**
* The dragable area for the handle. Is configured automatically.
*/
Expand Down Expand Up @@ -154,11 +159,6 @@ class FlxSlider extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else Flx
*/
var _lastPos:Float;

/**
* Helper variable to avoid the clickSound playing every frame.
*/
var _justClicked:Bool = false;

/**
* Helper variable to avoid the hoverSound playing every frame.
*/
Expand Down Expand Up @@ -294,23 +294,17 @@ class FlxSlider extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else Flx

_justHovered = true;

if (FlxG.mouse.pressed)
if (FlxG.mouse.justPressed)
{
handle.x = mousePosition.x;
updateValue();

dragging = true;

#if FLX_SOUND_SYSTEM
if (clickSound != null && !_justClicked)
if (clickSound != null)
{
FlxG.sound.play(clickSound);
_justClicked = true;
}
#end
}
if (!FlxG.mouse.pressed)
{
_justClicked = false;
}
}
else
{
Expand All @@ -322,9 +316,13 @@ class FlxSlider extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else Flx
_justHovered = false;
}

// Update the target value whenever the slider is being used
if ((FlxG.mouse.pressed) && (FlxMath.pointInFlxRect(mousePosition.x, mousePosition.y, _bounds)))
if (dragging)
{
if (FlxG.mouse.pressed)
handle.x = mousePosition.x;
else
dragging = false;

updateValue();
}

Expand Down Expand Up @@ -356,9 +354,11 @@ class FlxSlider extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else Flx
{
if (_lastPos != relativePos)
{
value = (relativePos * (maxValue - minValue)) + minValue;

if ((setVariable) && (varString != null))
{
Reflect.setProperty(_object, varString, (relativePos * (maxValue - minValue)) + minValue);
Reflect.setProperty(_object, varString, value);
}

_lastPos = relativePos;
Expand Down Expand Up @@ -467,6 +467,11 @@ class FlxSlider extends #if (flixel < version("5.7.0")) FlxSpriteGroup #else Flx
{
pos = 1;
}
// Relative position can't be smaller than 0
else if (pos < 0)
{
pos = 0;
}

return pos;
}
Expand Down