Skip to content

Commit

Permalink
seperate prefs menu
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesisfeline committed Nov 8, 2023
1 parent 81c738b commit c6d3282
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 21 deletions.
8 changes: 7 additions & 1 deletion source/options/BaseOptionsMenu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ class BaseOptionsMenu extends MusicBeatSubstate
#end

bg = new FlxSprite().loadGraphic(Paths.image('menuDesat'));
bg.color = 0xFFea71fd;
bg.color = 0xffc05ecf;
bg.screenCenter();
bg.antialiasing = ClientPrefs.data.antialiasing;
add(bg);

var grid:FlxBackdrop = new FlxBackdrop(FlxGridOverlay.createGrid(80, 80, 160, 160, true, 0x33FFFFFF, 0x0));
grid.velocity.set(40, 40);
grid.alpha = 0;
FlxTween.tween(grid, {alpha: 1}, 0.5, {ease: FlxEase.quadOut});
add(grid);

// avoids lagspikes while scrolling through menus!
grpOptions = new FlxTypedGroup<Alphabet>();
add(grpOptions);
Expand Down
12 changes: 4 additions & 8 deletions source/options/OptionsState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import backend.StageData;

class OptionsState extends MusicBeatState
{
var options:Array<String> = ['Note Colors', 'Controls', 'Adjust Delay and Combo', 'Graphics', 'Visuals and UI', 'Gameplay'];
var options:Array<String> = ['Note Colors', 'Controls', 'Offseting', 'Preferences'];
private var grpOptions:FlxTypedGroup<Alphabet>;
private static var curSelected:Int = 0;
public static var menuBG:FlxSprite;
Expand All @@ -17,13 +17,9 @@ class OptionsState extends MusicBeatState
openSubState(new options.NotesSubState());
case 'Controls':
openSubState(new options.ControlsSubState());
case 'Graphics':
openSubState(new options.GraphicsSettingsSubState());
case 'Visuals and UI':
openSubState(new options.VisualsUISubState());
case 'Gameplay':
openSubState(new options.GameplaySettingsSubState());
case 'Adjust Delay and Combo':
case 'Preferences':
MusicBeatState.switchState(new options.PrefsMenu());
case 'Offseting':
MusicBeatState.switchState(new options.NoteOffsetState());
}
}
Expand Down
120 changes: 120 additions & 0 deletions source/options/PrefsMenu.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package options;

import states.MainMenuState;
import backend.StageData;

class PrefsMenu extends MusicBeatState
{
var options:Array<String> = ['Graphics', 'Visuals and UI', 'Gameplay'];
private var grpOptions:FlxTypedGroup<Alphabet>;
private static var curSelected:Int = 0;
public static var menuBG:FlxSprite;
public static var onPlayState:Bool = false;

function openSelectedSubstate(label:String) {
switch(label) {
case 'Graphics':
openSubState(new options.GraphicsSettingsSubState());
case 'Visuals and UI':
openSubState(new options.VisualsUISubState());
case 'Gameplay':
openSubState(new options.GameplaySettingsSubState());
}
}

var selectorLeft:Alphabet;
var selectorRight:Alphabet;

override function create() {
#if desktop
DiscordClient.changePresence("Preferences Menu", null);
#end

var bg:FlxSprite = new FlxSprite().loadGraphic(Paths.image('menuDesat'));
bg.antialiasing = ClientPrefs.data.antialiasing;
bg.color = 0xFFea71fd;
bg.updateHitbox();

bg.screenCenter();
add(bg);

var grid:FlxBackdrop = new FlxBackdrop(FlxGridOverlay.createGrid(80, 80, 160, 160, true, 0x33FFFFFF, 0x0));
grid.velocity.set(40, 40);
grid.alpha = 0;
FlxTween.tween(grid, {alpha: 1}, 0.5, {ease: FlxEase.quadOut});
add(grid);

grpOptions = new FlxTypedGroup<Alphabet>();
add(grpOptions);

for (i in 0...options.length)
{
var optionText:Alphabet = new Alphabet(0, 0, options[i], true);
optionText.screenCenter();
optionText.y += (100 * (i - (options.length / 2))) + 50;
grpOptions.add(optionText);
}

selectorLeft = new Alphabet(0, 0, '>', true);
add(selectorLeft);
selectorRight = new Alphabet(0, 0, '<', true);
add(selectorRight);

changeSelection();
ClientPrefs.saveSettings();

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'));
MusicBeatState.switchState(new OptionsState());
}
else if (controls.ACCEPT) openSelectedSubstate(options[curSelected]);
}

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'));
}

override function destroy()
{
ClientPrefs.loadPrefs();
super.destroy();
}
}
18 changes: 6 additions & 12 deletions source/psychlua/FunkinLua.hx
Original file line number Diff line number Diff line change
Expand Up @@ -420,31 +420,25 @@ class FunkinLua {
luaTrace('removeLuaScript: Script $luaFile isn\'t running!', false, false, FlxColor.RED);
return false;
});
Lua_helper.add_callback(lua, "removeHScript", function(hscriptFile:String, ?ignoreAlreadyRunning:Bool = false)
{
Lua_helper.add_callback(lua, "removeHScript", function(hscriptFile:String, ?ignoreAlreadyRunning:Bool = false){
#if HSCRIPT_ALLOWED
var foundScript:String = findScript(hscriptFile, '.hx');

if (foundScript != null)
{
if (!ignoreAlreadyRunning)
for (script in game.hscriptArray)
if (script.origin == foundScript)
{
if(foundScript != null){
if(!ignoreAlreadyRunning)
for(script in game.hscriptArray)
if(script.origin == foundScript){
trace('Closing script: ' + script.origin);
game.hscriptArray.remove(script);
script.destroy();
return true;
}
}

luaTrace('removeHScript: Script $hscriptFile isn\'t running!', false, false, FlxColor.RED);
#else
luaTrace('removeHScript: HScript is not supported on this platform!', false, false, FlxColor.RED);
#end

return false;
});
});

Lua_helper.add_callback(lua, "pcUserName", function() { // i love danger :D
return Sys.environment()["USERNAME"];
Expand Down

0 comments on commit c6d3282

Please sign in to comment.