2023-11-07 09:04:22 +00:00
|
|
|
package funkin.ui.options;
|
2021-03-27 00:09:04 +00:00
|
|
|
|
2021-04-04 17:17:46 +00:00
|
|
|
import flixel.FlxCamera;
|
|
|
|
import flixel.FlxObject;
|
2021-03-27 01:22:07 +00:00
|
|
|
import flixel.FlxSprite;
|
2024-05-24 23:11:34 +00:00
|
|
|
import flixel.math.FlxMath;
|
2023-10-17 04:38:28 +00:00
|
|
|
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
|
2022-03-08 08:13:53 +00:00
|
|
|
import funkin.ui.AtlasText.AtlasFont;
|
2023-11-07 09:04:22 +00:00
|
|
|
import funkin.ui.options.OptionsState.Page;
|
2024-02-13 06:38:11 +00:00
|
|
|
import funkin.graphics.FunkinCamera;
|
2021-03-27 00:09:04 +00:00
|
|
|
|
2022-03-08 08:13:53 +00:00
|
|
|
class PreferencesMenu extends Page
|
2021-03-27 00:09:04 +00:00
|
|
|
{
|
2024-05-24 23:11:34 +00:00
|
|
|
var curSelected:Int = 0;
|
|
|
|
var prefs:FlxTypedSpriteGroup<PreferenceItem>;
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
var menuCamera:FlxCamera;
|
|
|
|
var camFollow:FlxObject;
|
|
|
|
|
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
2024-04-10 18:45:07 +00:00
|
|
|
menuCamera = new FunkinCamera('prefMenu');
|
2023-01-23 03:25:45 +00:00
|
|
|
FlxG.cameras.add(menuCamera, false);
|
|
|
|
menuCamera.bgColor = 0x0;
|
|
|
|
camera = menuCamera;
|
|
|
|
|
2024-05-24 23:11:34 +00:00
|
|
|
prefs = new FlxTypedSpriteGroup<PreferenceItem>();
|
|
|
|
add(prefs);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-10-17 04:38:28 +00:00
|
|
|
createPrefItems();
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
camFollow = new FlxObject(FlxG.width / 2, 0, 140, 70);
|
|
|
|
|
|
|
|
menuCamera.follow(camFollow, null, 0.06);
|
|
|
|
var margin = 160;
|
|
|
|
menuCamera.deadzone.set(0, margin, menuCamera.width, 40);
|
|
|
|
menuCamera.minScrollY = 0;
|
|
|
|
|
2024-05-24 23:11:34 +00:00
|
|
|
changeSelection(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addPref(pref:PreferenceItem):Void
|
|
|
|
{
|
|
|
|
pref.x = 0;
|
|
|
|
pref.y = 120 * prefs.length;
|
|
|
|
pref.ID = prefs.length;
|
|
|
|
prefs.add(pref);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 04:38:28 +00:00
|
|
|
/**
|
|
|
|
* Create the menu items for each of the preferences.
|
|
|
|
*/
|
|
|
|
function createPrefItems():Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2024-05-24 23:11:34 +00:00
|
|
|
#if !web
|
|
|
|
var pref:NumberedPreferenceItem = new NumberedPreferenceItem("FPS", "The framerate that the game is running on", Preferences.framerate,
|
|
|
|
function(value:Float):Void {
|
|
|
|
Preferences.framerate = Std.int(value);
|
|
|
|
});
|
|
|
|
pref.minValue = 60;
|
|
|
|
pref.maxValue = 360;
|
|
|
|
pref.changeRate = 1;
|
2024-05-24 23:20:10 +00:00
|
|
|
pref.changeDelay = 0.05;
|
2024-05-24 23:11:34 +00:00
|
|
|
addPref(pref);
|
|
|
|
#end
|
|
|
|
|
|
|
|
// TODO: add these back
|
|
|
|
// createPrefItemCheckbox('Naughtyness', 'Toggle displaying raunchy content', function(value:Bool):Void {
|
|
|
|
// Preferences.naughtyness = value;
|
|
|
|
// }, Preferences.naughtyness);
|
|
|
|
// createPrefItemCheckbox('Downscroll', 'Enable to make notes move downwards', function(value:Bool):Void {
|
|
|
|
// Preferences.downscroll = value;
|
|
|
|
// }, Preferences.downscroll);
|
|
|
|
// createPrefItemCheckbox('Flashing Lights', 'Disable to dampen flashing effects', function(value:Bool):Void {
|
|
|
|
// Preferences.flashingLights = value;
|
|
|
|
// }, Preferences.flashingLights);
|
|
|
|
// createPrefItemCheckbox('Camera Zooming on Beat', 'Disable to stop the camera bouncing to the song', function(value:Bool):Void {
|
|
|
|
// Preferences.zoomCamera = value;
|
|
|
|
// }, Preferences.zoomCamera);
|
|
|
|
// createPrefItemCheckbox('Debug Display', 'Enable to show FPS and other debug stats', function(value:Bool):Void {
|
|
|
|
// Preferences.debugDisplay = value;
|
|
|
|
// }, Preferences.debugDisplay);
|
|
|
|
// createPrefItemCheckbox('Auto Pause', 'Automatically pause the game when it loses focus', function(value:Bool):Void {
|
|
|
|
// Preferences.autoPause = value;
|
|
|
|
// }, Preferences.autoPause);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2024-05-24 23:11:34 +00:00
|
|
|
function changeSelection(change:Int):Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2024-05-24 23:11:34 +00:00
|
|
|
curSelected += change;
|
|
|
|
if (curSelected < 0)
|
|
|
|
{
|
|
|
|
curSelected = prefs.length - 1;
|
|
|
|
}
|
|
|
|
else if (curSelected >= prefs.length)
|
|
|
|
{
|
|
|
|
curSelected = 0;
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2024-05-24 23:11:34 +00:00
|
|
|
for (pref in prefs)
|
|
|
|
{
|
|
|
|
pref.x = 0;
|
|
|
|
if (pref.ID == curSelected)
|
|
|
|
{
|
|
|
|
pref.x = 20;
|
|
|
|
camFollow.y = pref.y;
|
|
|
|
}
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2024-05-24 23:11:34 +00:00
|
|
|
override function update(elapsed:Float):Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
super.update(elapsed);
|
|
|
|
|
2024-05-24 23:11:34 +00:00
|
|
|
if (controls.UI_DOWN_P)
|
|
|
|
{
|
|
|
|
changeSelection(1);
|
|
|
|
}
|
|
|
|
else if (controls.UI_UP_P)
|
|
|
|
{
|
|
|
|
changeSelection(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
var selectedPref:PreferenceItem = prefs.members[curSelected];
|
|
|
|
selectedPref.handleInput(elapsed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class PreferenceItem extends FlxTypedSpriteGroup<FlxSprite>
|
|
|
|
{
|
|
|
|
public var name:String = "";
|
|
|
|
public var description:String = "";
|
|
|
|
|
2024-05-24 23:20:10 +00:00
|
|
|
public function handleInput(elapsed:Float):Void {}
|
2024-05-24 23:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class NumberedPreferenceItem extends PreferenceItem
|
|
|
|
{
|
|
|
|
public var onChange:Float->Void;
|
|
|
|
public var changeRate:Float = 1.0;
|
2024-05-24 23:20:10 +00:00
|
|
|
public var changeDelay:Float = 0.1;
|
2024-05-24 23:11:34 +00:00
|
|
|
|
|
|
|
public var minValue(default, set):Null<Float>;
|
|
|
|
|
|
|
|
function set_minValue(value:Float):Float
|
|
|
|
{
|
|
|
|
minValue = value;
|
|
|
|
currentValue = currentValue;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public var maxValue(default, set):Null<Float>;
|
|
|
|
|
|
|
|
function set_maxValue(value:Float):Float
|
|
|
|
{
|
|
|
|
maxValue = value;
|
|
|
|
currentValue = currentValue;
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public var currentValue(default, set):Float;
|
|
|
|
|
|
|
|
function set_currentValue(value:Float):Float
|
|
|
|
{
|
|
|
|
currentValue = FlxMath.bound(value, minValue, maxValue);
|
|
|
|
onChange(currentValue);
|
|
|
|
updateText();
|
|
|
|
return currentValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var valueText:AtlasText;
|
|
|
|
var preferenceText:AtlasText;
|
|
|
|
|
|
|
|
public function new(name:String, description:String, defaultValue:Float, onChange:Float->Void)
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.valueText = new AtlasText(0, 0, '$defaultValue', AtlasFont.DEFAULT);
|
|
|
|
add(this.valueText);
|
|
|
|
|
|
|
|
this.preferenceText = new AtlasText(this.valueText.width + 30, 0, '$name', AtlasFont.BOLD);
|
|
|
|
add(this.preferenceText);
|
|
|
|
|
|
|
|
this.name = name;
|
|
|
|
this.description = description;
|
|
|
|
this.onChange = onChange;
|
|
|
|
this.currentValue = defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var timeToWait:Float = 0;
|
|
|
|
|
2024-05-24 23:20:10 +00:00
|
|
|
public override function handleInput(elapsed:Float):Void
|
2024-05-24 23:11:34 +00:00
|
|
|
{
|
2024-05-24 23:20:10 +00:00
|
|
|
timeToWait -= elapsed;
|
2024-05-24 23:11:34 +00:00
|
|
|
|
|
|
|
if (timeToWait > 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PlayerSettings.player1.controls.UI_RIGHT)
|
|
|
|
{
|
|
|
|
currentValue += changeRate;
|
2024-05-24 23:20:10 +00:00
|
|
|
timeToWait = changeDelay;
|
2024-05-24 23:11:34 +00:00
|
|
|
}
|
|
|
|
else if (PlayerSettings.player1.controls.UI_LEFT)
|
|
|
|
{
|
|
|
|
currentValue -= changeRate;
|
2024-05-24 23:20:10 +00:00
|
|
|
timeToWait = changeDelay;
|
2024-05-24 23:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateText():Void
|
|
|
|
{
|
|
|
|
valueText.text = '$currentValue';
|
|
|
|
preferenceText.x = valueText.width + 30;
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
2021-03-27 00:09:04 +00:00
|
|
|
}
|
2021-03-27 01:22:07 +00:00
|
|
|
|
2023-10-17 04:38:28 +00:00
|
|
|
class CheckboxPreferenceItem extends FlxSprite
|
2021-03-27 01:22:07 +00:00
|
|
|
{
|
2023-10-17 04:38:28 +00:00
|
|
|
public var currentValue(default, set):Bool;
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-10-17 04:38:28 +00:00
|
|
|
public function new(x:Float, y:Float, defaultValue:Bool = false)
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
super(x, y);
|
|
|
|
|
|
|
|
frames = Paths.getSparrowAtlas('checkboxThingie');
|
|
|
|
animation.addByPrefix('static', 'Check Box unselected', 24, false);
|
|
|
|
animation.addByPrefix('checked', 'Check Box selecting animation', 24, false);
|
|
|
|
|
|
|
|
setGraphicSize(Std.int(width * 0.7));
|
|
|
|
updateHitbox();
|
|
|
|
|
2023-10-17 04:38:28 +00:00
|
|
|
this.currentValue = defaultValue;
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
|
|
|
|
|
|
|
switch (animation.curAnim.name)
|
|
|
|
{
|
|
|
|
case 'static':
|
|
|
|
offset.set();
|
|
|
|
case 'checked':
|
|
|
|
offset.set(17, 70);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-17 04:38:28 +00:00
|
|
|
function set_currentValue(value:Bool):Bool
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2023-10-17 04:38:28 +00:00
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
animation.play('checked', true);
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
else
|
2023-10-17 04:38:28 +00:00
|
|
|
{
|
2023-01-23 03:25:45 +00:00
|
|
|
animation.play('static');
|
2023-10-17 04:38:28 +00:00
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-10-17 04:38:28 +00:00
|
|
|
return currentValue = value;
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
2021-03-27 01:22:07 +00:00
|
|
|
}
|