mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-11-05 06:14:36 +00:00
143 lines
4 KiB
Haxe
143 lines
4 KiB
Haxe
package funkin.ui;
|
|
|
|
import flixel.FlxCamera;
|
|
import flixel.FlxObject;
|
|
import flixel.FlxSprite;
|
|
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
|
|
import funkin.ui.AtlasText.AtlasFont;
|
|
import funkin.ui.OptionsState.Page;
|
|
import funkin.ui.TextMenuList.TextMenuItem;
|
|
|
|
class PreferencesMenu extends Page
|
|
{
|
|
var items:TextMenuList;
|
|
var preferenceItems:FlxTypedSpriteGroup<FlxSprite>;
|
|
|
|
var menuCamera:FlxCamera;
|
|
var camFollow:FlxObject;
|
|
|
|
public function new()
|
|
{
|
|
super();
|
|
|
|
menuCamera = new SwagCamera();
|
|
FlxG.cameras.add(menuCamera, false);
|
|
menuCamera.bgColor = 0x0;
|
|
camera = menuCamera;
|
|
|
|
add(items = new TextMenuList());
|
|
add(preferenceItems = new FlxTypedSpriteGroup<FlxSprite>());
|
|
|
|
createPrefItems();
|
|
|
|
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;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Create the menu items for each of the preferences.
|
|
*/
|
|
function createPrefItems():Void
|
|
{
|
|
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);
|
|
}
|
|
|
|
function createPrefItemCheckbox(prefName:String, prefDesc:String, onChange:Bool->Void, defaultValue:Bool):Void
|
|
{
|
|
var checkbox:CheckboxPreferenceItem = new CheckboxPreferenceItem(0, 120 * (items.length - 1 + 1), defaultValue);
|
|
|
|
items.createItem(120, (120 * items.length) + 30, prefName, AtlasFont.BOLD, function() {
|
|
var value = !checkbox.currentValue;
|
|
onChange(value);
|
|
checkbox.currentValue = value;
|
|
});
|
|
|
|
preferenceItems.add(checkbox);
|
|
}
|
|
|
|
override function update(elapsed:Float)
|
|
{
|
|
super.update(elapsed);
|
|
|
|
// Indent the selected item.
|
|
// TODO: Only do this on menu change?
|
|
items.forEach(function(daItem:TextMenuItem) {
|
|
if (items.selectedItem == daItem) daItem.x = 150;
|
|
else
|
|
daItem.x = 120;
|
|
});
|
|
}
|
|
}
|
|
|
|
class CheckboxPreferenceItem extends FlxSprite
|
|
{
|
|
public var currentValue(default, set):Bool;
|
|
|
|
public function new(x:Float, y:Float, defaultValue:Bool = false)
|
|
{
|
|
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();
|
|
|
|
this.currentValue = defaultValue;
|
|
}
|
|
|
|
override function update(elapsed:Float)
|
|
{
|
|
super.update(elapsed);
|
|
|
|
switch (animation.curAnim.name)
|
|
{
|
|
case 'static':
|
|
offset.set();
|
|
case 'checked':
|
|
offset.set(17, 70);
|
|
}
|
|
}
|
|
|
|
function set_currentValue(value:Bool):Bool
|
|
{
|
|
if (value)
|
|
{
|
|
animation.play('checked', true);
|
|
}
|
|
else
|
|
{
|
|
animation.play('static');
|
|
}
|
|
|
|
return currentValue = value;
|
|
}
|
|
}
|