Add the pressAction method in TouchUtil and use it everywhere it's useful
This commit is contained in:
@@ -319,7 +319,7 @@ class ControlsSchemeMenu extends MusicBeatSubState
|
||||
|
||||
handleDrag();
|
||||
|
||||
if (TouchUtil.justPressed && TouchUtil.overlapsComplex(itemNavHitbox))
|
||||
if (TouchUtil.pressAction(itemNavHitbox))
|
||||
{
|
||||
hitboxShowcases.members[currentIndex].onPress();
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class SchemeMenuButton extends FlxSpriteGroup
|
||||
{
|
||||
super.update(elapsed);
|
||||
|
||||
if (!busy && (TouchUtil.justPressed && TouchUtil.overlapsComplex(this) && !SwipeUtil.swipeAny))
|
||||
if (!busy && (TouchUtil.pressAction(this) && !SwipeUtil.swipeAny))
|
||||
{
|
||||
busy = true;
|
||||
|
||||
|
||||
@@ -266,7 +266,7 @@ class GameOverSubState extends MusicBeatSubState
|
||||
//
|
||||
|
||||
// Restart the level when pressing the assigned key.
|
||||
if ((controls.ACCEPT #if mobile || (TouchUtil.justPressed && !TouchUtil.overlaps(backButton) && canInput) #end)
|
||||
if ((controls.ACCEPT #if mobile || (TouchUtil.pressAction() && !TouchUtil.overlaps(backButton) && canInput) #end)
|
||||
&& blueballed
|
||||
&& !mustNotExit)
|
||||
{
|
||||
|
||||
@@ -64,8 +64,8 @@ class GitarooPause extends MusicBeatState
|
||||
#if mobile
|
||||
function checkSelectionPress():Bool
|
||||
{
|
||||
var buttonOverlapCheck:Bool = replaySelect ? TouchUtil.overlapsComplex(replayButton) : TouchUtil.overlapsComplex(cancelButton);
|
||||
return buttonOverlapCheck && TouchUtil.justPressed && !SwipeUtil.swipeAny;
|
||||
var buttonAcceptCheck:Bool = replaySelect ? TouchUtil.pressAction(replayButton) : TouchUtil.pressAction(cancelButton);
|
||||
return buttonAcceptCheck && !SwipeUtil.swipeAny;
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
@@ -434,11 +434,11 @@ class PauseSubState extends MusicBeatSubState
|
||||
changeSelection(1);
|
||||
}
|
||||
|
||||
if (TouchUtil.justReleased && !SwipeUtil.swipeAny && !justOpened)
|
||||
if (!SwipeUtil.swipeAny && !justOpened)
|
||||
{
|
||||
for (i in 0...menuEntryText.members.length)
|
||||
{
|
||||
if (!TouchUtil.overlaps(menuEntryText.members[i], camera)) continue;
|
||||
if (!TouchUtil.pressAction(menuEntryText.members[i], camera, false)) continue;
|
||||
|
||||
if (i == currentEntry)
|
||||
{
|
||||
|
||||
@@ -1006,7 +1006,7 @@ class PlayState extends MusicBeatSubState
|
||||
var androidPause:Bool = false;
|
||||
// So the player wouldn't miss when pressing the pause utton
|
||||
#if mobile
|
||||
pauseButtonCheck = TouchUtil.overlapsComplex(pauseButton) && TouchUtil.justPressed;
|
||||
pauseButtonCheck = TouchUtil.pressAction(pauseButton);
|
||||
#end
|
||||
|
||||
#if android
|
||||
@@ -2991,7 +2991,7 @@ class PlayState extends MusicBeatSubState
|
||||
#end
|
||||
|
||||
#if mobile
|
||||
pauseButtonCheck = TouchUtil.overlapsComplex(pauseButton) && TouchUtil.justPressed;
|
||||
pauseButtonCheck = TouchUtil.pressAction(pauseButton);
|
||||
#end
|
||||
|
||||
if (currentConversation != null)
|
||||
|
||||
@@ -509,8 +509,7 @@ class ResultState extends MusicBeatSubState
|
||||
bgFlash.visible = true;
|
||||
FlxTween.tween(bgFlash, {alpha: 0}, 5 / 24);
|
||||
// NOTE: Only divide if totalNotes > 0 to prevent divide-by-zero errors.
|
||||
var clearPercentFloat = params.scoreData.tallies.totalNotes == 0 ? 0.0 : (params.scoreData.tallies.sick +
|
||||
params.scoreData.tallies.good
|
||||
var clearPercentFloat = params.scoreData.tallies.totalNotes == 0 ? 0.0 : (params.scoreData.tallies.sick + params.scoreData.tallies.good
|
||||
- params.scoreData.tallies.missed) / params.scoreData.tallies.totalNotes * 100;
|
||||
clearPercentTarget = Math.floor(clearPercentFloat);
|
||||
// Prevent off-by-one errors.
|
||||
@@ -861,7 +860,7 @@ class ResultState extends MusicBeatSubState
|
||||
}
|
||||
}
|
||||
|
||||
if (controls.PAUSE || controls.ACCEPT #if mobile || TouchUtil.justPressed #end)
|
||||
if (controls.PAUSE || controls.ACCEPT #if mobile || TouchUtil.pressAction() #end)
|
||||
{
|
||||
if (_parentState is funkin.ui.debug.results.ResultsDebugSubState)
|
||||
{
|
||||
|
||||
@@ -781,7 +781,7 @@ class CharSelectSubState extends MusicBeatSubState
|
||||
}
|
||||
}
|
||||
|
||||
if (TouchUtil.justReleased && TouchUtil.overlaps(charHitbox))
|
||||
if (TouchUtil.pressAction(charHitbox, null, false))
|
||||
{
|
||||
mobileAccept = true;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ class CharacterUnlockState extends MusicBeatState
|
||||
{
|
||||
super.update(elapsed);
|
||||
|
||||
if (controls.ACCEPT || controls.BACK #if mobile || TouchUtil.justPressed #end && !busy)
|
||||
if (controls.ACCEPT || controls.BACK #if mobile || TouchUtil.pressAction() #end && !busy)
|
||||
{
|
||||
busy = true;
|
||||
startClose();
|
||||
|
||||
@@ -356,7 +356,7 @@ class LatencyState extends MusicBeatSubState
|
||||
handleSelectionInput(multiply);
|
||||
#end
|
||||
|
||||
if (controls.BACK #if mobile || (TouchUtil.overlapsComplex(helpText) && TouchUtil.justPressed) #end)
|
||||
if (controls.BACK #if mobile || (TouchUtil.pressAction(helpText)) #end)
|
||||
{
|
||||
// close();
|
||||
cleanup();
|
||||
|
||||
@@ -78,25 +78,25 @@ class CapsuleOptionsMenu extends FlxSpriteGroup
|
||||
if (!busy)
|
||||
{
|
||||
@:privateAccess
|
||||
if (parent.controls.BACK #if mobile || TouchUtil.overlapsComplex(parent.backButton) && TouchUtil.justPressed #end)
|
||||
if (parent.controls.BACK #if mobile || TouchUtil.pressAction(parent.backButton) #end)
|
||||
{
|
||||
close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (parent.getControls().UI_LEFT_P #if mobile || TouchUtil.overlapsComplex(leftArrow) && TouchUtil.justPressed #end)
|
||||
if (parent.getControls().UI_LEFT_P #if mobile || TouchUtil.pressAction(leftArrow) #end)
|
||||
{
|
||||
currentInstrumentalIndex = (currentInstrumentalIndex + 1) % instrumentalIds.length;
|
||||
changedInst = true;
|
||||
}
|
||||
if (parent.getControls().UI_RIGHT_P #if mobile || TouchUtil.overlapsComplex(rightArrow) && TouchUtil.justPressed #end)
|
||||
if (parent.getControls().UI_RIGHT_P #if mobile || TouchUtil.pressAction(rightArrow) #end)
|
||||
{
|
||||
currentInstrumentalIndex = (currentInstrumentalIndex - 1 + instrumentalIds.length) % instrumentalIds.length;
|
||||
changedInst = true;
|
||||
}
|
||||
if (parent.getControls()
|
||||
.ACCEPT #if mobile
|
||||
|| ((TouchUtil.overlapsComplex(currentInstrumental) && TouchUtil.justPressed)
|
||||
|| ((TouchUtil.pressAction(currentInstrumental))
|
||||
&& !(TouchUtil.overlapsComplex(leftArrow) || TouchUtil.overlapsComplex(rightArrow))) #end)
|
||||
{
|
||||
busy = true;
|
||||
@@ -112,9 +112,9 @@ class CapsuleOptionsMenu extends FlxSpriteGroup
|
||||
if (currentInstrumental.text == '') currentInstrumental.text = 'Default';
|
||||
}
|
||||
|
||||
if (parent.getControls().ACCEPT #if mobile
|
||||
|| TouchUtil.overlapsComplex(currentInstrumental)
|
||||
&& TouchUtil.justPressed
|
||||
if (parent.getControls()
|
||||
.ACCEPT #if mobile
|
||||
|| TouchUtil.pressAction(currentInstrumental)
|
||||
&& !TouchUtil.overlapsComplex(leftArrow)
|
||||
&& !TouchUtil.overlapsComplex(rightArrow) #end)
|
||||
{
|
||||
|
||||
@@ -1430,7 +1430,7 @@ class FreeplayState extends MusicBeatSubState
|
||||
#end // ^<-- FEATURE_DEBUG_FUNCTIONS
|
||||
|
||||
if ((controls.FREEPLAY_CHAR_SELECT #if FEATURE_TOUCH_CONTROLS
|
||||
|| (TouchUtil.overlaps(djHitbox, funnyCam) && TouchUtil.justReleased && !SwipeUtil.swipeAny) #end)
|
||||
|| (TouchUtil.pressAction(djHitbox, funnyCam, false) && !SwipeUtil.swipeAny) #end)
|
||||
&& !busy)
|
||||
{
|
||||
tryOpenCharSelect();
|
||||
@@ -1575,11 +1575,9 @@ class FreeplayState extends MusicBeatSubState
|
||||
function handleDifficultySwitch():Void
|
||||
{
|
||||
#if FEATURE_TOUCH_CONTROLS
|
||||
final leftPressed:Bool = controls.UI_LEFT_P
|
||||
|| (diffSelLeft != null && TouchUtil.overlaps(diffSelLeft, funnyCam) && TouchUtil.justReleased);
|
||||
final leftPressed:Bool = controls.UI_LEFT_P || (diffSelLeft != null && TouchUtil.pressAction(diffSelLeft, funnyCam, false));
|
||||
|
||||
final rightPressed:Bool = controls.UI_RIGHT_P
|
||||
|| (diffSelRight != null && TouchUtil.overlaps(diffSelRight, funnyCam) && TouchUtil.justReleased);
|
||||
final rightPressed:Bool = controls.UI_RIGHT_P || (diffSelRight != null && TouchUtil.pressAction(diffSelRight, funnyCam, false));
|
||||
#else
|
||||
final leftPressed:Bool = controls.UI_LEFT_P;
|
||||
final rightPressed:Bool = controls.UI_RIGHT_P;
|
||||
@@ -1604,7 +1602,7 @@ class FreeplayState extends MusicBeatSubState
|
||||
private function handleTouchCapsuleClick():Void
|
||||
{
|
||||
if (diffSelRight == null) return;
|
||||
if (TouchUtil.justReleased && !TouchUtil.overlaps(diffSelRight, funnyCam) && TouchUtil.touch.ticksDeltaSincePress < 200)
|
||||
if (TouchUtil.pressAction() && !TouchUtil.overlaps(diffSelRight, funnyCam))
|
||||
{
|
||||
curSelected = Math.round(curSelectedFloat);
|
||||
|
||||
@@ -1628,7 +1626,7 @@ class FreeplayState extends MusicBeatSubState
|
||||
}
|
||||
}
|
||||
|
||||
if (TouchUtil.justPressed)
|
||||
if (TouchUtil.pressAction())
|
||||
{
|
||||
final selected = grpCapsules.members[curSelected].theActualHitbox;
|
||||
_pressedOn = selected != null && TouchUtil.overlaps(selected, funnyCam);
|
||||
@@ -2033,8 +2031,8 @@ class FreeplayState extends MusicBeatSubState
|
||||
|
||||
var songScore:Null<SaveScoreData> = Save.instance.getSongScore(daSong.data.id, currentDifficulty, currentVariation);
|
||||
intendedScore = songScore?.score ?? 0;
|
||||
intendedCompletion = songScore == null ? 0.0 : Math.max(0, ((songScore.tallies.sick +
|
||||
songScore.tallies.good - songScore.tallies.missed) / songScore.tallies.totalNotes));
|
||||
intendedCompletion = songScore == null ? 0.0 : Math.max(0,
|
||||
((songScore.tallies.sick + songScore.tallies.good - songScore.tallies.missed) / songScore.tallies.totalNotes));
|
||||
rememberedDifficulty = currentDifficulty;
|
||||
grpCapsules.members[curSelected].refreshDisplay((prepForNewRank == true) ? false : true);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ class LetterSort extends FlxSpriteGroup
|
||||
|
||||
if (inputEnabled)
|
||||
{
|
||||
if (TouchUtil.justReleased && TouchUtil.touch.ticksDeltaSincePress < 200)
|
||||
if (TouchUtil.pressAction())
|
||||
{
|
||||
for (index => letter in letterHitboxes)
|
||||
{
|
||||
|
||||
@@ -369,12 +369,12 @@ class StoryMenuState extends MusicBeatState
|
||||
#end
|
||||
|
||||
// TODO: Querying UI_RIGHT_P (justPressed) after UI_RIGHT always returns false. Fix it!
|
||||
if (controls.UI_RIGHT_P || SwipeUtil.swipeRight || (TouchUtil.overlaps(rightDifficultyArrow) && TouchUtil.justPressed))
|
||||
if (controls.UI_RIGHT_P || SwipeUtil.swipeRight || (TouchUtil.pressAction(rightDifficultyArrow, null, false)))
|
||||
{
|
||||
changeDifficulty(1);
|
||||
}
|
||||
|
||||
if (controls.UI_LEFT_P || SwipeUtil.swipeLeft || (TouchUtil.overlaps(leftDifficultyArrow) && TouchUtil.justPressed))
|
||||
if (controls.UI_LEFT_P || SwipeUtil.swipeLeft || (TouchUtil.pressAction(leftDifficultyArrow, null, false)))
|
||||
{
|
||||
changeDifficulty(-1);
|
||||
}
|
||||
|
||||
@@ -128,6 +128,32 @@ class TouchUtil
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper function to check if the selection is pressed using touch.
|
||||
*
|
||||
* @param object The optional FlxBasic to check for overlap.
|
||||
* @param camera Optional camera for the overlap check. Defaults to all cameras of the object.
|
||||
* @param useOverlapsComplex If true and atleast the object is not null, the function will use complex overlaps method.
|
||||
*/
|
||||
public static function pressAction(?object:FlxBasic, ?camera:FlxCamera, useOverlapsComplex:Bool = true):Bool
|
||||
{
|
||||
#if FEATURE_TOUCH_CONTROLS
|
||||
if (TouchUtil.touch == null || (TouchUtil.touch != null && TouchUtil.touch.ticksDeltaSincePress > 200)) return false;
|
||||
|
||||
if (object == null && camera == null)
|
||||
{
|
||||
return justReleased;
|
||||
}
|
||||
else if (object != null)
|
||||
{
|
||||
final overlapsObject:Bool = useOverlapsComplex ? overlapsComplex(cast(object, FlxObject), camera) : overlaps(object, camera);
|
||||
return justReleased && overlapsObject;
|
||||
}
|
||||
#end
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// weird mix between "looks weird" and "looks neat" but i'll keep it for now -Zack
|
||||
|
||||
@:noCompletion
|
||||
|
||||
Reference in New Issue
Block a user