2022-03-08 03:13:53 -05:00
|
|
|
package funkin.ui;
|
2021-03-26 20:09:04 -04:00
|
|
|
|
2021-04-04 13:17:46 -04:00
|
|
|
import flixel.FlxCamera;
|
|
|
|
import flixel.FlxObject;
|
2021-03-26 21:22:07 -04:00
|
|
|
import flixel.FlxSprite;
|
2022-03-08 03:13:53 -05:00
|
|
|
import funkin.ui.AtlasText.AtlasFont;
|
|
|
|
import funkin.ui.OptionsState.Page;
|
2022-04-18 19:36:09 -04:00
|
|
|
import funkin.ui.TextMenuList.TextMenuItem;
|
2021-03-26 20:09:04 -04:00
|
|
|
|
2022-03-08 03:13:53 -05:00
|
|
|
class PreferencesMenu extends Page
|
2021-03-26 20:09:04 -04:00
|
|
|
{
|
|
|
|
public static var preferences:Map<String, Dynamic> = new Map();
|
|
|
|
|
|
|
|
var items:TextMenuList;
|
|
|
|
|
2021-03-26 21:33:16 -04:00
|
|
|
var checkboxes:Array<CheckboxThingie> = [];
|
2021-04-04 13:17:46 -04:00
|
|
|
var menuCamera:FlxCamera;
|
|
|
|
var camFollow:FlxObject;
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2021-03-26 20:09:04 -04:00
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
2021-04-04 13:17:46 -04:00
|
|
|
|
2021-05-06 08:08:51 -04:00
|
|
|
menuCamera = new SwagCamera();
|
2021-04-04 13:17:46 -04:00
|
|
|
FlxG.cameras.add(menuCamera, false);
|
|
|
|
menuCamera.bgColor = 0x0;
|
|
|
|
camera = menuCamera;
|
|
|
|
|
2021-03-26 20:09:04 -04:00
|
|
|
add(items = new TextMenuList());
|
|
|
|
|
2021-04-18 05:25:44 -04:00
|
|
|
createPrefItem('naughtyness', 'censor-naughty', true);
|
2021-03-26 20:09:04 -04:00
|
|
|
createPrefItem('downscroll', 'downscroll', false);
|
2021-03-26 21:22:07 -04:00
|
|
|
createPrefItem('flashing menu', 'flashing-menu', true);
|
2021-03-26 21:28:04 -04:00
|
|
|
createPrefItem('Camera Zooming on Beat', 'camera-zoom', true);
|
2021-03-30 23:51:17 -04:00
|
|
|
createPrefItem('FPS Counter', 'fps-counter', true);
|
2021-04-04 20:37:23 -04:00
|
|
|
createPrefItem('Auto Pause', 'auto-pause', false);
|
2021-04-04 13:17:46 -04:00
|
|
|
|
|
|
|
camFollow = new FlxObject(FlxG.width / 2, 0, 140, 70);
|
|
|
|
if (items != null)
|
|
|
|
camFollow.y = items.selectedItem.y;
|
|
|
|
|
|
|
|
menuCamera.follow(camFollow, null, 0.06);
|
|
|
|
var margin = 160;
|
|
|
|
menuCamera.deadzone.set(0, margin, menuCamera.width, 40);
|
|
|
|
menuCamera.minScrollY = 0;
|
|
|
|
|
|
|
|
items.onChange.add(function(selected)
|
|
|
|
{
|
|
|
|
camFollow.y = selected.y;
|
|
|
|
});
|
2021-03-26 21:28:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getPref(pref:String):Dynamic
|
|
|
|
{
|
|
|
|
return preferences.get(pref);
|
2021-03-26 21:22:07 -04:00
|
|
|
}
|
|
|
|
|
2021-04-06 12:27:07 -04:00
|
|
|
// easy shorthand?
|
|
|
|
public static function setPref(pref:String, value:Dynamic):Void
|
|
|
|
{
|
|
|
|
preferences.set(pref, value);
|
|
|
|
}
|
|
|
|
|
2021-03-26 21:22:07 -04:00
|
|
|
public static function initPrefs():Void
|
|
|
|
{
|
2021-04-18 05:25:44 -04:00
|
|
|
preferenceCheck('censor-naughty', true);
|
2021-03-31 13:08:55 -04:00
|
|
|
preferenceCheck('downscroll', false);
|
2021-03-26 21:22:07 -04:00
|
|
|
preferenceCheck('flashing-menu', true);
|
2021-03-26 21:28:04 -04:00
|
|
|
preferenceCheck('camera-zoom', true);
|
2021-03-30 23:51:17 -04:00
|
|
|
preferenceCheck('fps-counter', true);
|
2021-04-04 20:37:23 -04:00
|
|
|
preferenceCheck('auto-pause', false);
|
2021-04-06 12:27:07 -04:00
|
|
|
preferenceCheck('master-volume', 1);
|
|
|
|
|
|
|
|
#if muted
|
|
|
|
setPref('master-volume', 0);
|
|
|
|
FlxG.sound.muted = true;
|
|
|
|
#end
|
2021-03-30 23:51:17 -04:00
|
|
|
|
|
|
|
if (!getPref('fps-counter'))
|
|
|
|
FlxG.stage.removeChild(Main.fpsCounter);
|
2021-04-04 20:37:23 -04:00
|
|
|
|
|
|
|
FlxG.autoPause = getPref('auto-pause');
|
2021-03-26 20:09:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private function createPrefItem(prefName:String, prefString:String, prefValue:Dynamic):Void
|
|
|
|
{
|
2022-04-18 19:36:09 -04:00
|
|
|
items.createItem(120, (120 * items.length) + 30, prefName, AtlasFont.BOLD, function()
|
2021-03-26 20:09:04 -04:00
|
|
|
{
|
|
|
|
preferenceCheck(prefString, prefValue);
|
|
|
|
|
|
|
|
switch (Type.typeof(prefValue).getName())
|
|
|
|
{
|
|
|
|
case 'TBool':
|
|
|
|
prefToggle(prefString);
|
|
|
|
|
|
|
|
default:
|
|
|
|
trace('swag');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-26 21:22:07 -04:00
|
|
|
switch (Type.typeof(prefValue).getName())
|
|
|
|
{
|
|
|
|
case 'TBool':
|
|
|
|
createCheckbox(prefString);
|
|
|
|
|
|
|
|
default:
|
|
|
|
trace('swag');
|
|
|
|
}
|
|
|
|
|
2021-03-26 20:09:04 -04:00
|
|
|
trace(Type.typeof(prefValue).getName());
|
|
|
|
}
|
|
|
|
|
2021-03-26 21:22:07 -04:00
|
|
|
function createCheckbox(prefString:String)
|
|
|
|
{
|
2021-03-31 00:01:18 -04:00
|
|
|
var checkbox:CheckboxThingie = new CheckboxThingie(0, 120 * (items.length - 1), preferences.get(prefString));
|
2021-03-26 21:33:16 -04:00
|
|
|
checkboxes.push(checkbox);
|
2021-03-26 21:22:07 -04:00
|
|
|
add(checkbox);
|
|
|
|
}
|
|
|
|
|
2021-03-26 20:09:04 -04:00
|
|
|
/**
|
|
|
|
* Assumes that the preference has already been checked/set?
|
|
|
|
*/
|
|
|
|
private function prefToggle(prefName:String)
|
|
|
|
{
|
|
|
|
var daSwap:Bool = preferences.get(prefName);
|
|
|
|
daSwap = !daSwap;
|
|
|
|
preferences.set(prefName, daSwap);
|
2021-03-26 21:33:16 -04:00
|
|
|
checkboxes[items.selectedIndex].daValue = daSwap;
|
2021-03-26 20:09:04 -04:00
|
|
|
trace('toggled? ' + preferences.get(prefName));
|
2021-03-30 23:51:17 -04:00
|
|
|
|
2021-04-04 20:37:23 -04:00
|
|
|
switch (prefName)
|
2021-03-30 23:51:17 -04:00
|
|
|
{
|
2021-04-04 20:37:23 -04:00
|
|
|
case 'fps-counter':
|
|
|
|
if (getPref('fps-counter'))
|
|
|
|
FlxG.stage.addChild(Main.fpsCounter);
|
|
|
|
else
|
|
|
|
FlxG.stage.removeChild(Main.fpsCounter);
|
|
|
|
case 'auto-pause':
|
|
|
|
FlxG.autoPause = getPref('auto-pause');
|
2021-03-30 23:51:17 -04:00
|
|
|
}
|
2021-04-04 20:37:23 -04:00
|
|
|
|
|
|
|
if (prefName == 'fps-counter') {}
|
2021-03-26 20:09:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
2021-03-31 00:01:18 -04:00
|
|
|
|
2021-05-06 08:08:51 -04:00
|
|
|
// menuCamera.followLerp = CoolUtil.camLerpShit(0.05);
|
2021-04-04 13:17:46 -04:00
|
|
|
|
2021-03-31 00:01:18 -04:00
|
|
|
items.forEach(function(daItem:TextMenuItem)
|
|
|
|
{
|
|
|
|
if (items.selectedItem == daItem)
|
|
|
|
daItem.x = 150;
|
|
|
|
else
|
|
|
|
daItem.x = 120;
|
|
|
|
});
|
2021-03-26 20:09:04 -04:00
|
|
|
}
|
|
|
|
|
2022-04-18 19:36:09 -04:00
|
|
|
private static function preferenceCheck(prefString:String, defaultValue:Dynamic):Void
|
2021-03-26 20:09:04 -04:00
|
|
|
{
|
|
|
|
if (preferences.get(prefString) == null)
|
|
|
|
{
|
2022-04-18 19:36:09 -04:00
|
|
|
// Set the value to default.
|
|
|
|
preferences.set(prefString, defaultValue);
|
|
|
|
trace('Set preference to default: ${prefString} = ${defaultValue}');
|
2021-03-26 20:09:04 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-18 19:36:09 -04:00
|
|
|
trace('Found preference: ${prefString} = ${preferences.get(prefString)}');
|
2021-03-26 20:09:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
|
|
|
class CheckboxThingie extends FlxSprite
|
|
|
|
{
|
2021-03-27 23:01:53 -04:00
|
|
|
public var daValue(default, set):Bool;
|
2021-03-26 21:22:07 -04:00
|
|
|
|
|
|
|
public function new(x:Float, y:Float, daValue:Bool = false)
|
|
|
|
{
|
|
|
|
super(x, y);
|
|
|
|
|
2021-03-27 23:01:53 -04:00
|
|
|
frames = Paths.getSparrowAtlas('checkboxThingie');
|
|
|
|
animation.addByPrefix('static', 'Check Box unselected', 24, false);
|
|
|
|
animation.addByPrefix('checked', 'Check Box selecting animation', 24, false);
|
|
|
|
|
|
|
|
antialiasing = true;
|
|
|
|
|
|
|
|
setGraphicSize(Std.int(width * 0.7));
|
|
|
|
updateHitbox();
|
|
|
|
|
2021-03-26 21:22:07 -04:00
|
|
|
this.daValue = daValue;
|
|
|
|
}
|
|
|
|
|
2021-03-26 21:33:16 -04:00
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
2021-03-27 23:01:53 -04:00
|
|
|
|
|
|
|
switch (animation.curAnim.name)
|
|
|
|
{
|
|
|
|
case 'static':
|
|
|
|
offset.set();
|
|
|
|
case 'checked':
|
|
|
|
offset.set(17, 70);
|
|
|
|
}
|
2021-03-26 21:33:16 -04:00
|
|
|
}
|
|
|
|
|
2021-03-26 21:22:07 -04:00
|
|
|
function set_daValue(value:Bool):Bool
|
|
|
|
{
|
|
|
|
if (value)
|
2021-03-27 23:01:53 -04:00
|
|
|
animation.play('checked', true);
|
2021-03-26 21:22:07 -04:00
|
|
|
else
|
2021-03-27 23:01:53 -04:00
|
|
|
animation.play('static');
|
2021-03-26 21:22:07 -04:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|