package options;
#if desktop
import Discord.DiscordClient;
#end
import flash.text.TextField;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.addons.display.FlxGridOverlay;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.math.FlxMath;
import flixel.text.FlxText;
import flixel.util.FlxColor;
import lime.utils.Assets;
import flixel.FlxSubState;
import flash.text.TextField;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.util.FlxSave;
import haxe.Json;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxTimer;
import flixel.input.keyboard.FlxKey;
import flixel.graphics.FlxGraphic;
import Controls;
using StringTools;
class OptionsState extends MusicBeatState
{
var options:Array<String> = ['Controls', 'Setup Combo And Milliseconds', 'Grafika', 'Visuals And UI Interface', 'Gameplay'];
private var grpOptions:FlxTypedGroup<Alphabet>;
private static var curSelected:Int = 0;
public static var menuBG:FlxSprite;
function openSelectedSubstate(label:String) {
switch(label) {
case 'Controls':
#if android
removeVirtualPad();
#end
openSubState(new options.ControlsSubState());
case 'Graphic':
#if android
removeVirtualPad();
#end
openSubState(new options.GraphicsSettingsSubState());
case 'Visuals And UI Interface':
#if android
removeVirtualPad();
#end
openSubState(new options.VisualsUISubState());
case 'Gameplay':
#if android
removeVirtualPad();
#end
openSubState(new options.GameplaySettingsSubState());
case 'Setup Combo And Milliseconds':
LoadingState.loadAndSwitchState(new options.NoteOffsetState());
}
}
var selectorLeft:Alphabet;
var selectorRight:Alphabet;
override function create() {
#if desktop
DiscordClient.changePresence("Options Menu", null);
#end
var bg:FlxSprite = new FlxSprite().loadGraphic(Paths.image('menuDesat'));
bg.color = 0xFFA500;
bg.updateHitbox();
bg.screenCenter();
bg.antialiasing = ClientPrefs.globalAntialiasing;
add(bg);
grpOptions = new FlxTypedGroup<Alphabet>();
add(grpOptions);
for (i in 0...options.length)
{
var optionText:Alphabet = new Alphabet(0, 0, options[i], true, false);
optionText.screenCenter();
optionText.y += (100 * (i - (options.length / 2))) + 50;
grpOptions.add(optionText);
}
selectorLeft = new Alphabet(0, 0, '>', true, false);
add(selectorLeft);
selectorRight = new Alphabet(0, 0, '<', true, false);
add(selectorRight);
#if android
var tipText:FlxText = new FlxText(10, FlxG.height - 24, 0, 'Press C To Customize Android Controls.', 16);
tipText.setFormat(Paths.font('vcr.ttf'), 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
tipText.borderSize = 2.4;
tipText.scrollFactor.set();
add(tipText);
#end
changeSelection();
ClientPrefs.saveSettings();
#if android
addVirtualPad(UP_DOWN, A_B_C);
#end
super.create();
}
override function closeSubState() {
super.closeSubState();
ClientPrefs.saveSettings();
}
override function update(elapsed:Float) {
super.update(elapsed);
if (controls.UI_UP_P) {
changeSelection(-1);
}
if (controls.UI_DOWN_P) {
changeSelection(1);
}
if (controls.BACK) {
FlxG.sound.play(Paths.sound('cancelMenu'));
if (PauseSubState.wasinsongbeforethenwenttooptions) {
MusicBeatState.switchState(new PlayState());
PauseSubState.wasinsongbeforethenwenttooptions = false;
} else {
MusicBeatState.switchState(new MainMenuState());
}
}
if (controls.ACCEPT) {
openSelectedSubstate(options[curSelected]);
}
#if android
if (virtualPad.buttonC.justPressed) {
#if android
removeVirtualPad();
#end
openSubState(new android.AndroidControlsSubState());
}
#end
}
function changeSelection(change:Int = 0) {
curSelected += change;
if (curSelected < 0)
curSelected = options.length - 1;
if (curSelected >= options.length)
curSelected = 0;
var bullShit:Int = 0;
for (item in grpOptions.members) {
item.targetY = bullShit - curSelected;
bullShit++;
item.alpha = 0.6;
if (item.targetY == 0) {
item.alpha = 1;
selectorLeft.x = item.x - 63;
selectorLeft.y = item.y;
selectorRight.x = item.x + item.width + 15;
selectorRight.y = item.y;
}
}
FlxG.sound.play(Paths.sound('scrollMenu'));
}
}