2023-11-07 04:04:22 -05:00
|
|
|
package funkin.ui.options;
|
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;
|
2023-10-17 00:38:28 -04:00
|
|
|
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
|
2022-03-08 03:13:53 -05:00
|
|
|
import funkin.ui.AtlasText.AtlasFont;
|
2023-11-07 04:04:22 -05:00
|
|
|
import funkin.ui.options.OptionsState.Page;
|
2024-02-13 01:38:11 -05:00
|
|
|
import funkin.graphics.FunkinCamera;
|
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
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
var items:TextMenuList;
|
2023-10-17 00:38:28 -04:00
|
|
|
var preferenceItems:FlxTypedSpriteGroup<FlxSprite>;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
|
|
|
var menuCamera:FlxCamera;
|
|
|
|
var camFollow:FlxObject;
|
|
|
|
|
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
2024-02-13 01:38:11 -05:00
|
|
|
menuCamera = new FunkinCamera();
|
2023-01-22 22:25:45 -05:00
|
|
|
FlxG.cameras.add(menuCamera, false);
|
|
|
|
menuCamera.bgColor = 0x0;
|
|
|
|
camera = menuCamera;
|
|
|
|
|
|
|
|
add(items = new TextMenuList());
|
2023-10-17 00:38:28 -04:00
|
|
|
add(preferenceItems = new FlxTypedSpriteGroup<FlxSprite>());
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-10-17 00:38:28 -04:00
|
|
|
createPrefItems();
|
2023-01-22 22:25:45 -05: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;
|
|
|
|
|
2023-06-08 16:30:45 -04:00
|
|
|
items.onChange.add(function(selected) {
|
2023-01-22 22:25:45 -05:00
|
|
|
camFollow.y = selected.y;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-10-17 00:38:28 -04:00
|
|
|
/**
|
|
|
|
* Create the menu items for each of the preferences.
|
|
|
|
*/
|
|
|
|
function createPrefItems():Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-10-17 00:38:28 -04:00
|
|
|
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-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
2023-10-17 00:38:28 -04:00
|
|
|
function createPrefItemCheckbox(prefName:String, prefDesc:String, onChange:Bool->Void, defaultValue:Bool):Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-10-17 00:38:28 -04:00
|
|
|
var checkbox:CheckboxPreferenceItem = new CheckboxPreferenceItem(0, 120 * (items.length - 1 + 1), defaultValue);
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-06-08 16:30:45 -04:00
|
|
|
items.createItem(120, (120 * items.length) + 30, prefName, AtlasFont.BOLD, function() {
|
2023-10-17 00:38:28 -04:00
|
|
|
var value = !checkbox.currentValue;
|
|
|
|
onChange(value);
|
|
|
|
checkbox.currentValue = value;
|
2023-01-22 22:25:45 -05:00
|
|
|
});
|
|
|
|
|
2023-10-17 00:38:28 -04:00
|
|
|
preferenceItems.add(checkbox);
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
|
|
|
|
2023-10-17 00:38:28 -04:00
|
|
|
// Indent the selected item.
|
|
|
|
// TODO: Only do this on menu change?
|
2023-06-08 16:30:45 -04:00
|
|
|
items.forEach(function(daItem:TextMenuItem) {
|
2023-01-22 22:25:45 -05:00
|
|
|
if (items.selectedItem == daItem) daItem.x = 150;
|
|
|
|
else
|
|
|
|
daItem.x = 120;
|
|
|
|
});
|
|
|
|
}
|
2021-03-26 20:09:04 -04:00
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
|
2023-10-17 00:38:28 -04:00
|
|
|
class CheckboxPreferenceItem extends FlxSprite
|
2021-03-26 21:22:07 -04:00
|
|
|
{
|
2023-10-17 00:38:28 -04:00
|
|
|
public var currentValue(default, set):Bool;
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-10-17 00:38:28 -04:00
|
|
|
public function new(x:Float, y:Float, defaultValue:Bool = false)
|
2023-01-22 22:25:45 -05: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 00:38:28 -04:00
|
|
|
this.currentValue = defaultValue;
|
2023-01-22 22:25:45 -05: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 00:38:28 -04:00
|
|
|
function set_currentValue(value:Bool):Bool
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-10-17 00:38:28 -04:00
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
animation.play('checked', true);
|
|
|
|
}
|
2023-01-22 22:25:45 -05:00
|
|
|
else
|
2023-10-17 00:38:28 -04:00
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
animation.play('static');
|
2023-10-17 00:38:28 -04:00
|
|
|
}
|
2023-01-22 22:25:45 -05:00
|
|
|
|
2023-10-17 00:38:28 -04:00
|
|
|
return currentValue = value;
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
2021-03-26 21:22:07 -04:00
|
|
|
}
|