Skip to content
Draft
Show file tree
Hide file tree
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
51 changes: 51 additions & 0 deletions source/funkin/Preferences.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ package funkin;
import funkin.mobile.ui.FunkinHitbox;
import funkin.mobile.util.InAppPurchasesUtil;
#end
import funkin.play.components.ScrollSpeedChanger.ScrollSpeedMode;
import funkin.save.Save;
import funkin.util.WindowUtil;
import funkin.util.HapticUtil.HapticsMode;
import funkin.ui.debug.FunkinDebugDisplay.DebugDisplayMode;
import flixel.math.FlxMath;

/**
* A core class which provides a store of user-configurable, globally relevant values.
Expand Down Expand Up @@ -306,6 +308,55 @@ class Preferences
return value;
}

/**
* The scroll speed value set by the player.
* This is only used with the `ScrollSpeedMode.STATIC` and `ScrollSpeedMode.ADAPTIVE`.
*
* @default `Constants.DEFAULT_SCROLLSPEED`
*/
public static var scrollSpeed(get, set):Float;

static function get_scrollSpeed():Float
{
return Save?.instance?.options?.scrollSpeed ?? Constants.DEFAULT_SCROLLSPEED;
}

static function set_scrollSpeed(value:Float):Float
{
value = FlxMath.roundDecimal(value, 2);
var save:Save = Save.instance;
save.options.scrollSpeed = value;
save.flush();
return value;
}

/**
* If enabled, controls how the song's scroll speed is applied based on the selected mode.
*
* @default `ScrollSpeedMode.OFF`
*/
public static var scrollSpeedMode(get, set):ScrollSpeedMode;

static function get_scrollSpeedMode():ScrollSpeedMode
{
var value = Save?.instance?.options?.scrollSpeedMode ?? "Off";

return switch (value)
{
case "Static": ScrollSpeedMode.STATIC;
case "Adaptive": ScrollSpeedMode.ADAPTIVE;
default: ScrollSpeedMode.OFF;
};
}

static function set_scrollSpeedMode(value:ScrollSpeedMode):ScrollSpeedMode
{
var save:Save = Save.instance;
save.options.scrollSpeedMode = value.getName();
save.flush();
return value;
}

/**
* If enabled, the game will utilize VSync (or adaptive VSync) on startup.
* @default `OFF`
Expand Down
40 changes: 40 additions & 0 deletions source/funkin/input/Controls.hx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Controls extends FlxActionSet
var _back = new FunkinAction(Action.BACK);
var _pause = new FunkinAction(Action.PAUSE);
var _reset = new FunkinAction(Action.RESET);
var _scroll_speed_increase_speed = new FunkinAction(Action.SCROLL_SPEED_INCREASE_SPEED);
var _scroll_speed_decrease_speed = new FunkinAction(Action.SCROLL_SPEED_DECREASE_SPEED);
#if FEATURE_SCREENSHOTS
var _window_screenshot = new FunkinAction(Action.WINDOW_SCREENSHOT);
#end
Expand Down Expand Up @@ -242,6 +244,16 @@ class Controls extends FlxActionSet
inline function get_RESET()
return _reset.check();

public var SCROLL_SPEED_INCREASE_SPEED(get, never):Bool;

inline function get_SCROLL_SPEED_INCREASE_SPEED()
return _scroll_speed_increase_speed.check();

public var SCROLL_SPEED_DECREASE_SPEED(get, never):Bool;

inline function get_SCROLL_SPEED_DECREASE_SPEED()
return _scroll_speed_decrease_speed.check();

public var WINDOW_FULLSCREEN(get, never):Bool;

inline function get_WINDOW_FULLSCREEN()
Expand Down Expand Up @@ -346,6 +358,8 @@ class Controls extends FlxActionSet
add(_back);
add(_pause);
add(_reset);
add(_scroll_speed_increase_speed);
add(_scroll_speed_decrease_speed);
#if FEATURE_SCREENSHOTS add(_window_screenshot); #end
add(_window_fullscreen);
add(_freeplay_favorite);
Expand Down Expand Up @@ -475,6 +489,8 @@ class Controls extends FlxActionSet
case BACK: _back;
case PAUSE: _pause;
case RESET: _reset;
case SCROLL_SPEED_INCREASE_SPEED: _scroll_speed_increase_speed;
case SCROLL_SPEED_DECREASE_SPEED: _scroll_speed_decrease_speed;
#if FEATURE_SCREENSHOTS case WINDOW_SCREENSHOT: _window_screenshot; #end
case WINDOW_FULLSCREEN: _window_fullscreen;
case FREEPLAY_FAVORITE: _freeplay_favorite;
Expand Down Expand Up @@ -549,6 +565,10 @@ class Controls extends FlxActionSet
func(_pause, JUST_PRESSED);
case RESET:
func(_reset, JUST_PRESSED);
case SCROLL_SPEED_INCREASE_SPEED:
func(_scroll_speed_increase_speed, JUST_PRESSED);
case SCROLL_SPEED_DECREASE_SPEED:
func(_scroll_speed_decrease_speed, JUST_PRESSED);
#if FEATURE_SCREENSHOTS
case WINDOW_SCREENSHOT:
func(_window_screenshot, JUST_PRESSED);
Expand Down Expand Up @@ -786,6 +806,8 @@ class Controls extends FlxActionSet
bindKeys(Control.BACK, getDefaultKeybinds(scheme, Control.BACK));
bindKeys(Control.PAUSE, getDefaultKeybinds(scheme, Control.PAUSE));
bindKeys(Control.RESET, getDefaultKeybinds(scheme, Control.RESET));
bindKeys(Control.SCROLL_SPEED_INCREASE_SPEED, getDefaultKeybinds(scheme, Control.SCROLL_SPEED_INCREASE_SPEED));
bindKeys(Control.SCROLL_SPEED_DECREASE_SPEED, getDefaultKeybinds(scheme, Control.SCROLL_SPEED_DECREASE_SPEED));
#if FEATURE_SCREENSHOTS
bindKeys(Control.WINDOW_SCREENSHOT, getDefaultKeybinds(scheme, Control.WINDOW_SCREENSHOT));
#end
Expand Down Expand Up @@ -831,6 +853,8 @@ class Controls extends FlxActionSet
case Control.BACK: return [X, BACKSPACE, ESCAPE];
case Control.PAUSE: return [P, ENTER, ESCAPE];
case Control.RESET: return [R];
case Control.SCROLL_SPEED_INCREASE_SPEED: return [FIVE, NUMPADFIVE];
case Control.SCROLL_SPEED_DECREASE_SPEED: return [FOUR, NUMPADFOUR];
case Control.WINDOW_FULLSCREEN: return [F11]; // We use F for other things LOL.
#if FEATURE_SCREENSHOTS case Control.WINDOW_SCREENSHOT: return [F3]; #end
case Control.FREEPLAY_FAVORITE: return [F]; // Favorite a song on the menu
Expand Down Expand Up @@ -863,6 +887,8 @@ class Controls extends FlxActionSet
case Control.BACK: return [H, X];
case Control.PAUSE: return [ONE];
case Control.RESET: return [R];
case Control.SCROLL_SPEED_INCREASE_SPEED: return [FIVE, NUMPADFIVE];
case Control.SCROLL_SPEED_DECREASE_SPEED: return [FOUR, NUMPADFOUR];
#if FEATURE_SCREENSHOTS case Control.WINDOW_SCREENSHOT: return [F3]; #end
case Control.WINDOW_FULLSCREEN: return [F11];
case Control.FREEPLAY_FAVORITE: return [F]; // Favorite a song on the menu
Expand Down Expand Up @@ -895,6 +921,8 @@ class Controls extends FlxActionSet
case Control.BACK: return [ESCAPE];
case Control.PAUSE: return [ONE];
case Control.RESET: return [R];
case Control.SCROLL_SPEED_INCREASE_SPEED: return [FIVE, NUMPADFIVE];
case Control.SCROLL_SPEED_DECREASE_SPEED: return [FOUR, NUMPADFOUR];
#if FEATURE_SCREENSHOTS case Control.WINDOW_SCREENSHOT: return []; #end
case Control.WINDOW_FULLSCREEN: return [];
case Control.FREEPLAY_FAVORITE: return [];
Expand Down Expand Up @@ -987,6 +1015,8 @@ class Controls extends FlxActionSet
Control.NOTE_RIGHT => getDefaultGamepadBinds(Control.NOTE_RIGHT),
Control.PAUSE => getDefaultGamepadBinds(Control.PAUSE),
Control.RESET => getDefaultGamepadBinds(Control.RESET),
Control.SCROLL_SPEED_INCREASE_SPEED => getDefaultGamepadBinds(Control.SCROLL_SPEED_INCREASE_SPEED),
Control.SCROLL_SPEED_DECREASE_SPEED => getDefaultGamepadBinds(Control.SCROLL_SPEED_DECREASE_SPEED),
Control.WINDOW_FULLSCREEN => getDefaultGamepadBinds(Control.WINDOW_FULLSCREEN),
#if FEATURE_SCREENSHOTS
Control.WINDOW_SCREENSHOT => getDefaultGamepadBinds(Control.WINDOW_SCREENSHOT),
Expand Down Expand Up @@ -1042,6 +1072,10 @@ class Controls extends FlxActionSet
return [START];
case Control.RESET:
return [FlxGamepadInputID.BACK]; // Back (i.e. Select)
case Control.SCROLL_SPEED_INCREASE_SPEED:
[];
case Control.SCROLL_SPEED_DECREASE_SPEED:
[];
case Control.WINDOW_FULLSCREEN:
[];
#if FEATURE_SCREENSHOTS
Expand Down Expand Up @@ -1479,6 +1513,9 @@ enum Control
ACCEPT;
BACK;
PAUSE;
// SCROLL SPEED
SCROLL_SPEED_INCREASE_SPEED;
SCROLL_SPEED_DECREASE_SPEED;
// CUTSCENE
CUTSCENE_ADVANCE;
// FREEPLAY
Expand Down Expand Up @@ -1534,6 +1571,9 @@ enum abstract Action(String) to String from String
var BACK = "back";
var PAUSE = "pause";
var RESET = "reset";
// SCROLL SPEED
var SCROLL_SPEED_INCREASE_SPEED = "scroll_speed_increase_speed";
var SCROLL_SPEED_DECREASE_SPEED = "scroll_speed_decrease_speed";
// WINDOW
var WINDOW_FULLSCREEN = "window_fullscreen";
#if FEATURE_SCREENSHOTS
Expand Down
73 changes: 72 additions & 1 deletion source/funkin/play/PauseSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import funkin.ui.FullScreenScaleMode;
import funkin.ui.transition.stickers.StickerSubState;
import funkin.util.SwipeUtil;
import funkin.util.TouchUtil;
import funkin.util.InputUtil;
import funkin.util.InputUtil.InputUtil.format;
import funkin.input.Controls.Control;
#if FEATURE_MOBILE_ADVERTISEMENTS
import funkin.mobile.util.AdMobUtil;
#end
Expand Down Expand Up @@ -198,6 +201,16 @@ class PauseSubState extends MusicBeatSubState
*/
var metadataArtist:FlxText;

/**
* A text object that displays the current scroll speed based on the `ScrollSpeedMode`.
*/
var scrollSpeedText:FlxText;

/**
* A text object that displays information about changing scroll speed.
*/
var scrollSpeedInfo:FlxText;

/**
* A text object that displays the current global offset.
*/
Expand Down Expand Up @@ -450,9 +463,38 @@ class PauseSubState extends MusicBeatSubState
offsetTextInfo.setFormat(Paths.font('vcr.ttf'), 16, FlxColor.WHITE, FlxTextAlign.RIGHT);
offsetTextInfo.scrollFactor.set(0, 0);

offsetText.y = FlxG.height - (offsetText.height + offsetText.height + 40);
offsetText.y = FlxG.height - (offsetText.height * 2 + 40);
offsetTextInfo.y = offsetText.y + offsetText.height + 4;

if (Preferences.scrollSpeedMode != OFF) {
var inputIncr = PlayerSettings.player1.controls.getInputsFor(Control.SCROLL_SPEED_INCREASE_SPEED, Keys)[0];
var inputDecr = PlayerSettings.player1.controls.getInputsFor(Control.SCROLL_SPEED_DECREASE_SPEED, Keys)[0];
scrollSpeedInfo = new FlxText(20, metadataSong.y, (camera.width + 10) - Math.max(40, FullScreenScaleMode.gameNotchSize.x),
'Press ${InputUtil.format(inputIncr, Keys)}/${InputUtil.format(inputDecr, Keys)},\nto change the scroll speed.');
scrollSpeedInfo.setFormat('VCR OSD Mono', 16, FlxColor.WHITE, FlxTextAlign.RIGHT);
scrollSpeedInfo.scrollFactor.set(0, 0);

scrollSpeedText = new FlxText(20, metadataSong.y, (camera.width + 10) - Math.max(40, FullScreenScaleMode.gameNotchSize.x));
scrollSpeedText.text = switch (Preferences.scrollSpeedMode)
{
case STATIC: 'Static Scroll Speed: ${Preferences.scrollSpeed ?? 0}';
case ADAPTIVE: 'Current Scroll Speed: ${PlayState.instance.playerStrumline.scrollSpeed ?? 0}\nSet Scroll Speed: ${Preferences.scrollSpeed ?? 0}';
default: '';
}
scrollSpeedText.setFormat('VCR OSD Mono', 16, FlxColor.WHITE, FlxTextAlign.RIGHT);
scrollSpeedText.scrollFactor.set(0, 0);

scrollSpeedInfo.y = offsetText.y - scrollSpeedInfo.height - 12;
scrollSpeedText.y = scrollSpeedInfo.y - scrollSpeedText.height - 4;

#if !mobile
metadata.add(scrollSpeedText);
metadata.add(scrollSpeedInfo);
#end

scrollSpeedText.alpha = scrollSpeedInfo.alpha = 0;
}

#if !mobile
metadata.add(offsetText);
metadata.add(offsetTextInfo);
Expand Down Expand Up @@ -639,6 +681,8 @@ class PauseSubState extends MusicBeatSubState
changeSelection(1);
}

if (Preferences.scrollSpeedMode != OFF) handleScrollSpeedChange();

#if FEATURE_TOUCH_CONTROLS
if (!SwipeUtil.justSwipedAny && !justOpened && currentMenuEntries.length > 0)
{
Expand Down Expand Up @@ -684,6 +728,33 @@ class PauseSubState extends MusicBeatSubState
#end
}

function handleScrollSpeedChange()
{
if (PlayState.instance == null) return;

if (controls.SCROLL_SPEED_INCREASE_SPEED)
{
changeScrollSpeed(0.1);
}
if (controls.SCROLL_SPEED_DECREASE_SPEED)
{
changeScrollSpeed(-0.1);
}
}

function changeScrollSpeed(change:Float = 0)
{
PlayState.instance.scrollSpeedChanger.updateSpeed(change);
PlayState.instance.changeScrollSpeed(change);

scrollSpeedText.text = switch (Preferences.scrollSpeedMode)
{
case STATIC: 'Static Scroll Speed: ${Preferences.scrollSpeed ?? 0}';
case ADAPTIVE: 'Current Scroll Speed: ${PlayState.instance.playerStrumline.scrollSpeed ?? 0}\nSet Scroll Speed: ${Preferences.scrollSpeed ?? 0}';
default: '';
}
}

/**
* Move the current selection up or down.
* @param change The amount to change the selection by, with sign indicating direction.
Expand Down
Loading