preference toggling

This commit is contained in:
Cameron Taylor 2021-03-26 20:09:04 -04:00
parent 27c410cb9d
commit b470cfc83a
9 changed files with 93 additions and 256 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
export/
.vscode/
APIStuff.hx
.DS_STORE

View file

@ -2,7 +2,6 @@
"lineEnds": {
"leftCurly": "both",
"rightCurly": "both",
"emptyCurly": "break",
"objectLiteralCurly": {
"leftCurly": "after"
}

View file

@ -1,132 +0,0 @@
package;
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_old extends MusicBeatState
{
var selector:FlxText;
var curSelected:Int = 0;
var controlsStrings:Array<String> = [];
private var grpControls:FlxTypedGroup<Alphabet>;
override function create()
{
var menuBG:FlxSprite = new FlxSprite().loadGraphic(Paths.image('menuDesat'));
controlsStrings = CoolUtil.coolTextFile(Paths.txt('controls'));
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...controlsStrings.length)
{
if (controlsStrings[i].indexOf('set') != -1)
{
var controlLabel:Alphabet = new Alphabet(0, (70 * i) + 30, controlsStrings[i].substring(3) + ': ' + controlsStrings[i + 1], true, false);
controlLabel.isMenuItem = true;
controlLabel.targetY = i;
grpControls.add(controlLabel);
}
// DONT PUT X IN THE FIRST PARAMETER OF new ALPHABET() !!
}
*/
super.create();
openSubState(new OptionsSubState());
}
override function update(elapsed:Float)
{
super.update(elapsed);
/*
if (controls.ACCEPT)
{
changeBinding();
}
if (isSettingControl)
waitingInput();
else
{
if (controls.BACK)
FlxG.switchState(new MainMenuState());
if (controls.UP_P)
changeSelection(-1);
if (controls.DOWN_P)
changeSelection(1);
}
*/
}
function waitingInput():Void
{
if (FlxG.keys.getIsDown().length > 0)
{
// PlayerSettings.player1.controls.replaceBinding(Control.LEFT, Keys, FlxG.keys.getIsDown()[0].ID, null);
}
// PlayerSettings.player1.controls.replaceBinding(Control)
}
var isSettingControl:Bool = false;
function changeBinding():Void
{
if (!isSettingControl)
{
isSettingControl = true;
}
}
function changeSelection(change:Int = 0)
{
NGio.logEvent('Fresh');
FlxG.sound.play(Paths.sound('scrollMenu'), 0.4);
curSelected += change;
if (curSelected < 0)
curSelected = grpControls.length - 1;
if (curSelected >= grpControls.length)
curSelected = 0;
// 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));
}
}
}
}

View file

@ -1,92 +0,0 @@
package;
import Controls.Control;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.text.FlxText;
import flixel.util.FlxColor;
import polymod.Polymod;
#if desktop
import sys.FileSystem;
#end
class OptionsSubState extends MusicBeatSubstate
{
var textMenuItems:Array<String> = ['Master Volume', 'Sound Volume', 'Controls', 'Colors', 'Back'];
var selector:FlxSprite;
var curSelected:Int = 0;
var grpOptionsTexts:FlxTypedGroup<FlxText>;
// public static var isDownscroll:Bool = false;
public function new()
{
super();
#if desktop
textMenuItems.push('Mods');
#end
grpOptionsTexts = new FlxTypedGroup<FlxText>();
add(grpOptionsTexts);
selector = new FlxSprite().makeGraphic(5, 5, FlxColor.RED);
add(selector);
for (i in 0...textMenuItems.length)
{
var optionText:FlxText = new FlxText(20, 20 + (i * 50), 0, textMenuItems[i], 32);
optionText.ID = i;
grpOptionsTexts.add(optionText);
}
}
override function update(elapsed:Float)
{
super.update(elapsed);
if (controls.UI_UP_P)
curSelected -= 1;
if (controls.UI_DOWN_P)
curSelected += 1;
if (curSelected < 0)
curSelected = textMenuItems.length - 1;
if (curSelected >= textMenuItems.length)
curSelected = 0;
grpOptionsTexts.forEach(function(txt:FlxText)
{
txt.color = FlxColor.WHITE;
if (txt.ID == curSelected)
txt.color = FlxColor.YELLOW;
});
if (controls.BACK)
FlxG.switchState(new MainMenuState());
if (controls.ACCEPT)
{
switch (textMenuItems[curSelected])
{
case "Colors":
FlxG.state.closeSubState();
case "Controls":
FlxG.state.closeSubState();
FlxG.state.openSubState(new ControlsSubState());
case "Mods":
FlxG.state.closeSubState();
// FlxG.state.openSubState(new ModdingSubstate());
case "Back":
FlxG.switchState(new MainMenuState());
}
}
}
}

View file

@ -1163,9 +1163,7 @@ class PlayState extends MusicBeatState
{
swagNote.x += FlxG.width / 2; // general offset
}
else
{
}
else {}
}
daBeats += 1;
}

View file

@ -63,7 +63,7 @@ class TitleState extends MusicBeatState
PlayerSettings.init();
Highscore.load();
#if newgrounds
#if ng
NGio.init();
#end
@ -297,7 +297,7 @@ class TitleState extends MusicBeatState
transitioning = true;
// FlxG.sound.music.stop();
#if newgrounds
#if ng
if (!OutdatedSubState.leftState)
{
NGio.checkVersion(function(version)

View file

@ -12,7 +12,7 @@ import flixel.util.FlxSignal;
class OptionsState extends MusicBeatState
{
var pages = new Map<PageName, Page>();
var currentName:PageName = #if newgrounds Options #else Controls #end;
var currentName:PageName = Options;
var currentPage(get, never):Page;
inline function get_currentPage()
@ -29,6 +29,7 @@ class OptionsState extends MusicBeatState
add(menuBG);
var options = addPage(Options, new OptionsMenu(false));
var preferences = addPage(Preferences, new PreferencesMenu());
var controls = addPage(Controls, new ControlsMenu());
var colors = addPage(Colors, new ColorsMenu());
@ -41,6 +42,7 @@ class OptionsState extends MusicBeatState
options.onExit.add(exitToMainMenu);
controls.onExit.add(switchPage.bind(Options));
colors.onExit.add(switchPage.bind(Options));
preferences.onExit.add(switchPage.bind(Options));
#if cpp
mods.onExit.add(switchPage.bind(Options));
@ -172,6 +174,7 @@ class OptionsMenu extends Page
super();
add(items = new TextMenuList());
createItem('preferences', function() switchPage(Preferences));
createItem("controls", function() switchPage(Controls));
createItem('colors', function() switchPage(Colors));
#if cpp
@ -276,4 +279,5 @@ enum PageName
Controls;
Colors;
Mods;
Preferences;
}

View file

@ -0,0 +1,68 @@
package ui;
import flixel.FlxG;
import ui.AtlasText.AtlasFont;
class PreferencesMenu extends ui.OptionsState.Page
{
public static var preferences:Map<String, Dynamic> = new Map();
var items:TextMenuList;
public function new()
{
super();
add(items = new TextMenuList());
createPrefItem('naughtyness', 'censor-naughty', false);
createPrefItem('downscroll', 'downscroll', false);
}
private function createPrefItem(prefName:String, prefString:String, prefValue:Dynamic):Void
{
items.createItem(100, 100 * items.length, prefName, AtlasFont.Bold, function()
{
preferenceCheck(prefString, prefValue);
switch (Type.typeof(prefValue).getName())
{
case 'TBool':
prefToggle(prefString);
default:
trace('swag');
}
});
trace(Type.typeof(prefValue).getName());
}
/**
* 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);
trace('toggled? ' + preferences.get(prefName));
}
override function update(elapsed:Float)
{
super.update(elapsed);
}
private function preferenceCheck(prefString:String, prefValue:Dynamic):Void
{
if (preferences.get(prefString) == null)
{
preferences.set(prefString, prefValue);
trace('set preference!');
}
else
{
trace('found preference: ' + preferences.get(prefString));
}
}
}

View file

@ -1,9 +0,0 @@
package ui;
class SettingsMenu extends ui.OptionsState.Page
{
public function new()
{
super();
}
}