Kade-Engine/source/OptionsMenu.hx
2021-05-16 14:28:50 -05:00

258 lines
7.8 KiB
Haxe

package;
import openfl.Lib;
import Options;
import Controls.Control;
import flash.text.TextField;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.addons.display.FlxGridOverlay;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.input.keyboard.FlxKey;
import flixel.math.FlxMath;
import flixel.text.FlxText;
import flixel.util.FlxColor;
import lime.utils.Assets;
class OptionsMenu extends MusicBeatState
{
var selector:FlxText;
var curSelected:Int = 0;
var options:Array<OptionCatagory> = [
new OptionCatagory("Gameplay", [
new DFJKOption(controls),
new DownscrollOption("Change the layout of the strumline."),
new GhostTapOption("Ghost Tapping is when you tap a direction and it doesn't give you a miss."),
new Judgement("Customize your Hit Timings (LEFT or RIGHT)"),
#if desktop
new FPSCapOption("Cap your FPS (Left for -10, Right for +10. SHIFT to go faster)"),
#end
new ScrollSpeedOption("Change your scroll speed (Left for -0.1, right for +0.1. If it's at 1, it will be chart dependent)"),
new AccuracyDOption("Change how accuracy is calculated. (Accurate = Simple, Complex = Milisecond Based)"),
new ResetButtonOption("Enable and disable pressing R to gameover."),
// new OffsetMenu("Get a note offset based off of your inputs!"),
new CustomizeGameplay("Drag'n'Drop Gameplay Modules around to your preference")
]),
new OptionCatagory("Appearance", [
#if desktop
new DistractionsAndEffectsOption("Toggle stage distractions that can hinder your gameplay."),
new RainbowFPSOption("Make the FPS Counter Rainbow (Only works with the FPS Counter toggled on and Flashing Lights toggled off)"),
new AccuracyOption("Display accuracy information."),
new NPSDisplayOption("Shows your current Notes Per Second."),
new SongPositionOption("Show the songs current position (as a bar)"),
#else
new DistractionsAndEffectsOption("Toggle stage distractions that can hinder your gameplay.")
#end
]),
new OptionCatagory("Misc", [
#if desktop
new FPSOption("Toggle the FPS Counter"),
new ReplayOption("View replays"),
#end
new FlashingLightsOption("Toggle flashing lights that can cause epileptic seizures and strain."),
new WatermarkOption("Enable and disable all watermarks from the engine."),
new BotPlay("Showcase your charts and mods with autoplay.")
])
];
private var currentDescription:String = "";
private var grpControls:FlxTypedGroup<Alphabet>;
public static var versionShit:FlxText;
var currentSelectedCat:OptionCatagory;
override function create()
{
var menuBG:FlxSprite = new FlxSprite().loadGraphic(Paths.image("menuDesat"));
menuBG.color = 0xFFea71fd;
menuBG.setGraphicSize(Std.int(menuBG.width * 1.1));
menuBG.updateHitbox();
menuBG.screenCenter();
menuBG.antialiasing = true;
add(menuBG);
grpControls = new FlxTypedGroup<Alphabet>();
add(grpControls);
for (i in 0...options.length)
{
var controlLabel:Alphabet = new Alphabet(0, (70 * i) + 30, options[i].getName(), true, false);
controlLabel.isMenuItem = true;
controlLabel.targetY = i;
grpControls.add(controlLabel);
// DONT PUT X IN THE FIRST PARAMETER OF new ALPHABET() !!
}
currentDescription = "none";
versionShit = new FlxText(5, FlxG.height - 18, 0, "Offset (Left, Right): " + FlxG.save.data.offset + " - Description - " + currentDescription, 12);
versionShit.scrollFactor.set();
versionShit.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
add(versionShit);
super.create();
}
var isCat:Bool = false;
override function update(elapsed:Float)
{
super.update(elapsed);
if (controls.BACK && !isCat)
FlxG.switchState(new MainMenuState());
else if (controls.BACK)
{
isCat = false;
grpControls.clear();
for (i in 0...options.length)
{
var controlLabel:Alphabet = new Alphabet(0, (70 * i) + 30, options[i].getName(), true, false);
controlLabel.isMenuItem = true;
controlLabel.targetY = i;
grpControls.add(controlLabel);
// DONT PUT X IN THE FIRST PARAMETER OF new ALPHABET() !!
}
curSelected = 0;
}
if (controls.UP_P)
changeSelection(-1);
if (controls.DOWN_P)
changeSelection(1);
if (isCat)
{
if (currentSelectedCat.getOptions()[curSelected].getAccept())
{
if (FlxG.keys.pressed.SHIFT)
{
if (FlxG.keys.pressed.RIGHT)
currentSelectedCat.getOptions()[curSelected].right();
if (FlxG.keys.pressed.LEFT)
currentSelectedCat.getOptions()[curSelected].left();
}
else
{
if (FlxG.keys.justPressed.RIGHT)
currentSelectedCat.getOptions()[curSelected].right();
if (FlxG.keys.justPressed.LEFT)
currentSelectedCat.getOptions()[curSelected].left();
}
}
else
{
if (FlxG.keys.pressed.SHIFT)
{
if (FlxG.keys.justPressed.RIGHT)
FlxG.save.data.offset += 0.1;
else if (FlxG.keys.justPressed.LEFT)
FlxG.save.data.offset -= 0.1;
}
else if (FlxG.keys.pressed.RIGHT)
FlxG.save.data.offset += 0.1;
else if (FlxG.keys.pressed.LEFT)
FlxG.save.data.offset -= 0.1;
versionShit.text = "Offset (Left, Right, Shift for slow): " + HelperFunctions.truncateFloat(FlxG.save.data.offset,2) + " - Description - " + currentDescription;
}
}
else
{
if (FlxG.keys.pressed.SHIFT)
{
if (FlxG.keys.justPressed.RIGHT)
FlxG.save.data.offset += 0.1;
else if (FlxG.keys.justPressed.LEFT)
FlxG.save.data.offset -= 0.1;
}
else if (FlxG.keys.pressed.RIGHT)
FlxG.save.data.offset += 0.1;
else if (FlxG.keys.pressed.LEFT)
FlxG.save.data.offset -= 0.1;
versionShit.text = "Offset (Left, Right, Shift for slow): " + HelperFunctions.truncateFloat(FlxG.save.data.offset,2) + " - Description - " + currentDescription;
}
if (controls.RESET)
FlxG.save.data.offset = 0;
if (controls.ACCEPT)
{
if (isCat)
{
if (currentSelectedCat.getOptions()[curSelected].press()) {
grpControls.remove(grpControls.members[curSelected]);
var ctrl:Alphabet = new Alphabet(0, (70 * curSelected) + 30, currentSelectedCat.getOptions()[curSelected].getDisplay(), true, false);
ctrl.isMenuItem = true;
grpControls.add(ctrl);
}
}
else
{
currentSelectedCat = options[curSelected];
isCat = true;
grpControls.clear();
for (i in 0...currentSelectedCat.getOptions().length)
{
var controlLabel:Alphabet = new Alphabet(0, (70 * i) + 30, currentSelectedCat.getOptions()[i].getDisplay(), true, false);
controlLabel.isMenuItem = true;
controlLabel.targetY = i;
grpControls.add(controlLabel);
// DONT PUT X IN THE FIRST PARAMETER OF new ALPHABET() !!
}
curSelected = 0;
}
}
FlxG.save.flush();
}
var isSettingControl:Bool = false;
function changeSelection(change:Int = 0)
{
#if !switch
// NGio.logEvent("Fresh");
#end
FlxG.sound.play(Paths.sound("scrollMenu"), 0.4);
curSelected += change;
if (curSelected < 0)
curSelected = grpControls.length - 1;
if (curSelected >= grpControls.length)
curSelected = 0;
if (isCat)
currentDescription = currentSelectedCat.getOptions()[curSelected].getDescription();
else
currentDescription = "Please select a category";
versionShit.text = "Offset (Left, Right, Shift for slow): " + HelperFunctions.truncateFloat(FlxG.save.data.offset,2) + " - Description - " + currentDescription;
// selector.y = (70 * curSelected) + 30;
var bullShit:Int = 0;
for (item in grpControls.members)
{
item.targetY = bullShit - curSelected;
bullShit++;
item.alpha = 0.6;
// item.setGraphicSize(Std.int(item.width * 0.8));
if (item.targetY == 0)
{
item.alpha = 1;
// item.setGraphicSize(Std.int(item.width));
}
}
}
}