1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-27 17:33:03 +00:00
Funkin/source/ui/PreferencesMenu.hx

172 lines
3.7 KiB
Haxe
Raw Normal View History

2021-03-27 00:09:04 +00:00
package ui;
import flixel.FlxG;
2021-03-27 01:22:07 +00:00
import flixel.FlxSprite;
import flixel.group.FlxGroup;
import flixel.util.FlxColor;
2021-03-27 00:09:04 +00:00
import ui.AtlasText.AtlasFont;
2021-03-27 01:22:07 +00:00
import ui.TextMenuList.TextMenuItem;
2021-03-27 00:09:04 +00:00
class PreferencesMenu extends ui.OptionsState.Page
{
public static var preferences:Map<String, Dynamic> = new Map();
var items:TextMenuList;
2021-03-27 01:33:16 +00:00
var checkboxes:Array<CheckboxThingie> = [];
2021-03-27 01:22:07 +00:00
2021-03-27 00:09:04 +00:00
public function new()
{
super();
add(items = new TextMenuList());
createPrefItem('naughtyness', 'censor-naughty', false);
createPrefItem('downscroll', 'downscroll', false);
2021-03-27 01:22:07 +00:00
createPrefItem('flashing menu', 'flashing-menu', true);
2021-03-27 01:28:04 +00:00
createPrefItem('Camera Zooming on Beat', 'camera-zoom', true);
2021-03-31 03:51:17 +00:00
createPrefItem('FPS Counter', 'fps-counter', true);
2021-03-27 01:28:04 +00:00
}
public static function getPref(pref:String):Dynamic
{
return preferences.get(pref);
2021-03-27 01:22:07 +00:00
}
public static function initPrefs():Void
{
preferenceCheck('censor-naughty', false);
2021-03-31 17:08:55 +00:00
preferenceCheck('downscroll', false);
2021-03-27 01:22:07 +00:00
preferenceCheck('flashing-menu', true);
2021-03-27 01:28:04 +00:00
preferenceCheck('camera-zoom', true);
2021-03-31 03:51:17 +00:00
preferenceCheck('fps-counter', true);
if (!getPref('fps-counter'))
FlxG.stage.removeChild(Main.fpsCounter);
2021-03-27 00:09:04 +00:00
}
private function createPrefItem(prefName:String, prefString:String, prefValue:Dynamic):Void
{
2021-03-31 04:01:18 +00:00
items.createItem(120, (120 * items.length) + 30, prefName, AtlasFont.Bold, function()
2021-03-27 00:09:04 +00:00
{
preferenceCheck(prefString, prefValue);
switch (Type.typeof(prefValue).getName())
{
case 'TBool':
prefToggle(prefString);
default:
trace('swag');
}
});
2021-03-27 01:22:07 +00:00
switch (Type.typeof(prefValue).getName())
{
case 'TBool':
createCheckbox(prefString);
default:
trace('swag');
}
2021-03-27 00:09:04 +00:00
trace(Type.typeof(prefValue).getName());
}
2021-03-27 01:22:07 +00:00
function createCheckbox(prefString:String)
{
2021-03-31 04:01:18 +00:00
var checkbox:CheckboxThingie = new CheckboxThingie(0, 120 * (items.length - 1), preferences.get(prefString));
2021-03-27 01:33:16 +00:00
checkboxes.push(checkbox);
2021-03-27 01:22:07 +00:00
add(checkbox);
}
2021-03-27 00:09:04 +00: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-27 01:33:16 +00:00
checkboxes[items.selectedIndex].daValue = daSwap;
2021-03-27 00:09:04 +00:00
trace('toggled? ' + preferences.get(prefName));
2021-03-31 03:51:17 +00:00
if (prefName == 'fps-counter')
{
if (getPref('fps-counter'))
FlxG.stage.addChild(Main.fpsCounter);
else
FlxG.stage.removeChild(Main.fpsCounter);
}
2021-03-27 00:09:04 +00:00
}
override function update(elapsed:Float)
{
super.update(elapsed);
2021-03-31 04:01:18 +00:00
items.forEach(function(daItem:TextMenuItem)
{
if (items.selectedItem == daItem)
daItem.x = 150;
else
daItem.x = 120;
});
2021-03-27 00:09:04 +00:00
}
2021-03-27 01:22:07 +00:00
private static function preferenceCheck(prefString:String, prefValue:Dynamic):Void
2021-03-27 00:09:04 +00:00
{
if (preferences.get(prefString) == null)
{
preferences.set(prefString, prefValue);
trace('set preference!');
}
else
{
trace('found preference: ' + preferences.get(prefString));
}
}
}
2021-03-27 01:22:07 +00:00
class CheckboxThingie extends FlxSprite
{
2021-03-28 03:01:53 +00:00
public var daValue(default, set):Bool;
2021-03-27 01:22:07 +00:00
public function new(x:Float, y:Float, daValue:Bool = false)
{
super(x, y);
2021-03-28 03:01:53 +00: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-27 01:22:07 +00:00
this.daValue = daValue;
}
2021-03-27 01:33:16 +00:00
override function update(elapsed:Float)
{
super.update(elapsed);
2021-03-28 03:01:53 +00:00
switch (animation.curAnim.name)
{
case 'static':
offset.set();
case 'checked':
offset.set(17, 70);
}
2021-03-27 01:33:16 +00:00
}
2021-03-27 01:22:07 +00:00
function set_daValue(value:Bool):Bool
{
if (value)
2021-03-28 03:01:53 +00:00
animation.play('checked', true);
2021-03-27 01:22:07 +00:00
else
2021-03-28 03:01:53 +00:00
animation.play('static');
2021-03-27 01:22:07 +00:00
return value;
}
}