Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

Commit

Permalink
preferences state headers
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed Jan 22, 2024
1 parent d15307f commit 727f26d
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 87 deletions.
Binary file added assets/preload/images/options/spray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 24 additions & 6 deletions source/funkin/Preferences.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ class Preferences {
preferences = SaveData.getSave('preferences');
prefsLabels = new Map<String, String>();

// Miscellaneous
addPref('naughty', 'naughtyness', true);
/****/addHeader("GAMEPLAY");/****/

// Gameplay
addPref('botplay', 'botplay mode', false);
addPref('practice', 'practice mode', false);
addPref('downscroll', 'downscroll', false);
Expand All @@ -38,14 +36,16 @@ class Preferences {
addPref('use-const-speed', 'use constant speed', false);
addPref('const-speed', 'constant speed', 1.0);

// UI
/****/addHeader("UI");/****/

addPref('framerate', 'framerate', 60);
addPref('fps-counter', 'fps counter', true);
addPref('vanilla-ui', 'vanilla ui', false);
addPref('flashing-light', 'flashing lights', true);
addPref('camera-zoom', 'camera zooms', true);

// Performance
/****/addHeader("PERFORMANCE");/****/

addPref('antialiasing', 'antialiasing', true);
#if desktop
addPref('resolution', 'resolution', {array:resolutions, value: "1280x720"});
Expand All @@ -55,15 +55,33 @@ class Preferences {
addPref('preload', 'preload at start', true);
#end

/****/addHeader("MISCELLANEOUS");/****/

addPref('naughty', 'naughtyness', true);

SaveData.flushData();
fixOldPrefs();
}

private static var curHeader:String;
public static var headers:Array<String> = [];
public static var headerContents:Map<String, Array<String>> = [];

static function addHeader(name:String) {
if (name != curHeader) {
curHeader = name;
headerContents.set(name, []);
headers.push(name);
}
}

public static function addPref(id:String, label:String, defaultValue:Dynamic):Void {
id = id.toLowerCase().trim();
prefsArray.push(id);

prefsArray.push(id);
prefsLabels.set(id, label);
headerContents.get(curHeader).push(id);

if (Reflect.hasField(defaultValue, "array")) arrayPrefs.set(id, defaultValue);
if (!preferences.exists(id)) preferences.set(id, defaultValue);
}
Expand Down
12 changes: 11 additions & 1 deletion source/funkin/graphics/FlxFunkText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ class FlxFunkText extends FlxSpriteExt {
if (size != null) this.size = size;
}

// Helper function from scripts
public function setStyle(type:String, ?values:Array<Dynamic>):TextStyle {
if (values == null) values = [];
return style = switch(type.toLowerCase().trim()) {
case "outline": OUTLINE(values[0], values[1], values[2]);
case "shadow": SHADOW(values[0], values[1]);
default: NONE;
}
}

public var style(default, set):TextStyle = NONE;
inline function set_style(?value:TextStyle):TextStyle {
return style = (value != null) ? switch (value) {
Expand All @@ -195,7 +205,7 @@ class FlxFunkText extends FlxSpriteExt {
size *= sizeMult();

color = col;
final qualityDiv = (1 / quality) * CoolUtil.DOUBLE_PI;
final qualityDiv = CoolUtil.DOUBLE_PI / quality;
for (i in 0...quality) {
final rads = i * qualityDiv;
offset.set(point.x, point.y);
Expand Down
5 changes: 4 additions & 1 deletion source/funkin/states/options/ControlsState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import funkin.states.options.items.ControlItem;
import flixel.input.gamepad.FlxGamepad;
import funkin.substates.PromptSubstate;

// TODO: Clean this shit up!!!

class ControlsState extends MusicBeatState {
var controlItems:FlxTypedGroup<ControlItem>;
var menuItems:FlxTypedGroup<Alphabet>;
Expand Down Expand Up @@ -36,7 +38,8 @@ class ControlsState extends MusicBeatState {
menuCam = new FlxCamera();
FlxG.cameras.add(menuCam);
FlxG.cameras.setDefaultDrawTarget(menuCam, true);
camFollow = new FlxObject(FlxG.width/2, 0);
camFollow = new FlxObject(FlxG.width * .5, 0);
add(camFollow);

final bg:FunkinSprite = new FunkinSprite('menuBGBlue', [0,0], [0,0]);
bg.setScale(1.1, false);
Expand Down
135 changes: 86 additions & 49 deletions source/funkin/states/options/PreferencesState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,123 @@ import funkin.states.options.items.PrefItem;
class PreferencesState extends MusicBeatState {
var curSelected:Int = 0;
var prefItems:Array<PrefItem> = [];
var camFollow:FlxObject;

override function create():Void {
persistentUpdate = true;
persistentDraw = true;
persistentUpdate = persistentDraw = true;

final bg:FunkinSprite = new FunkinSprite('menuBGBlue');
bg.setGraphicSize(Std.int(bg.width * 1.1));
camFollow = new FlxObject(FlxG.width * .5, 0);
FlxG.camera.follow(camFollow, null, 0.16);
add(camFollow);

var bg:FunkinSprite = new FunkinSprite('menuBGBlue');
bg.scrollFactor.set();
bg.setScale(1.1);
bg.screenCenter();
add(bg);

final prefsArray:Array<String> = Preferences.prefsArray;
for (i in 0...prefsArray.length) {
final pref:String = prefsArray[i];
final prefLabel = Preferences.getLabel(pref);
final item:PrefItem = new PrefItem(pref, prefLabel);
item.targetY = (i + (prefsArray.length * 0.1))*125;
item.y = item.targetY;
item.ID = i;

add(item);
prefItems.push(item);
var id:Int = 0;
var y:Float = 0;

for (header in Preferences.headers) {
var back = new FlxSprite(0, y - 10).makeGraphic(1, 1, FlxColor.BLACK);
back.antialiasing = false;
back.scale.set(FlxG.width, 85);
back.updateHitbox();
back.alpha = 0.4;
add(back);

var title = new Alphabet(FlxG.width * .5, y, switch (header) {
case "GAMEPLAY": FlxG.random.bool(5) ? "GAYPLAY" : header;
default: header;
});
title.alignment = CENTER;
add(title);

y += 40;

for (pref in Preferences.headerContents.get(header)) {
var label = Preferences.getLabel(pref);
var item = new PrefItem(pref, label);
item.ID = id;
prefItems.push(item);
add(item);

item.y = y;

id++;
y += 125;
}

y += 90;
}

changeSelection();
FlxG.camera.focusOn(camFollow.getPosition());
super.create();
}

var curItem:PrefItem;

function changeSelection(change:Int = 0):Void {
curSelected = FlxMath.wrap(curSelected + change, 0, prefItems.length - 1);
if (change != 0) CoolUtil.playSound('scrollMenu');

for (item in prefItems) {
item.targetY = (item.ID - curSelected + (prefItems.length * 0.1)) * 125;
item.selected = false;
if (curSelected == item.ID) {
item.selected = true;
camFollow.y = item.y + FlxG.height * .25;
curItem = item;
}
}
}

function selectPref() {
final leftP = getKey('UI_LEFT-P');
final rightP = getKey('UI_RIGHT-P');
final accepted = getKey('ACCEPT-P');
final leftP:Bool = getKey('UI_LEFT-P');
final rightP:Bool = getKey('UI_RIGHT-P');
final accepted:Bool = getKey('ACCEPT-P');

if (accepted || leftP || rightP) {
for (item in prefItems) {
if (item.ID == curSelected) {
switch (item.type) {
case BOOL:
if (accepted) {
switch(item.itemPref) {
case 'naughty': if (!item.prefValue) CoolUtil.playSound('chart/naughty_on'); // Tankman easteregg
case 'antialiasing': FlxSprite.defaultAntialiasing = !item.prefValue;
}
item.setValue(!item.prefValue);
}

case NUMBER:
var mult:Float = (FlxG.keys.pressed.SHIFT) ? 5 : 1;
switch(item.itemPref) {
case 'const-speed': mult *= 0.1;
default:
}
if (leftP || rightP) {
if (leftP) item.setValue(item.prefValue - mult);
if (rightP) item.setValue(item.prefValue + mult);
}

case ARRAY:
if (leftP || rightP) {
if (leftP) item.setValue(item.array[FlxMath.wrap(item.getArrIndex()-1, 0, item.array.length - 1)]);
if (rightP) item.setValue(item.array[FlxMath.wrap(item.getArrIndex()+1, 0, item.array.length - 1)]);
}
}
break;
if (curItem != null) {
switch (curItem.type) {
case BOOL: handleBool(curItem, accepted, leftP, rightP);
case NUMBER: handleNumber(curItem, accepted, leftP, rightP);
case ARRAY: handleArray(curItem, accepted, leftP, rightP);
}
}
}
}

function handleBool(item:PrefItem, accepted:Bool, leftP:Bool, rightP:Bool) {
if (accepted) {
switch(item.itemPref) {
case 'naughty': if (!item.prefValue) CoolUtil.playSound('chart/naughty_on'); // Tankman easteregg
case 'antialiasing': FlxSprite.defaultAntialiasing = !item.prefValue;
}
item.setValue(!item.prefValue);
}
}

function handleNumber(item:PrefItem, accepted:Bool, leftP:Bool, rightP:Bool) {
var mult:Float = (FlxG.keys.pressed.SHIFT) ? 5 : 1;
switch(item.itemPref) {
case 'const-speed': mult *= 0.1;
default:
}
if (leftP || rightP) {
if (leftP) item.setValue(item.prefValue - mult);
if (rightP) item.setValue(item.prefValue + mult);
}
}

function handleArray(item:PrefItem, accepted:Bool, leftP:Bool, rightP:Bool) {
if (leftP || rightP) {
if (leftP) item.setValue(item.array[FlxMath.wrap(item.getArrIndex()-1, 0, item.array.length - 1)]);
if (rightP) item.setValue(item.array[FlxMath.wrap(item.getArrIndex()+1, 0, item.array.length - 1)]);
}
}

var hitBack:Bool = false;

override function update(elapsed:Float):Void {
Expand Down
3 changes: 0 additions & 3 deletions source/funkin/states/options/items/PrefItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class PrefItem extends FlxSpriteGroup {
public var stringID:String = '';

public var itemPref:String = 'lmao';
public var targetY:Float = 0;
public var selected:Bool = false;

public var prefValue:Dynamic;
Expand Down Expand Up @@ -119,7 +118,5 @@ class PrefItem extends FlxSpriteGroup {
settingTxt.color = FlxColor.WHITE;
settingTxt.alpha = 0.6;
}

y = CoolUtil.coolLerp(y, targetY, 0.16);
}
}
5 changes: 2 additions & 3 deletions source/funkin/substates/GitarooPauseSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GitarooPauseSubState extends MusicBeatSubstate {
public function new():Void {
super();

if (FlxG.sound.music != null){
if (FlxG.sound.music != null) {
FlxG.sound.music.stop();
}

Expand All @@ -33,8 +33,7 @@ class GitarooPauseSubState extends MusicBeatSubstate {
add(cancelButton);

changeThing();

cameras = [FlxG.cameras.list[FlxG.cameras.list.length - 1]];
camera = CoolUtil.getTopCam();
}

override function update(elapsed:Float):Void {
Expand Down
31 changes: 22 additions & 9 deletions source/funkin/util/CoolUtil.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package funkin.util;

import openfl.geom.Matrix;
import flixel.util.typeLimit.OneOfTwo;
import flixel.system.FlxAssets.FlxSoundAsset;
#if cpp
import cpp.vm.Gc;
Expand Down Expand Up @@ -88,14 +90,17 @@ class CoolUtil {

inline public static function gc(major:Bool = false) {
#if desktop
#if hl
Gc.blocking(true);
Gc.major();
Gc.blocking(false);
#else
Gc.run(major);
#if cpp if (major) Gc.compact(); #end
#end
#if hl
Gc.blocking(true);
Gc.major();
Gc.blocking(false);
#else
Gc.run(major);
#if cpp
if (major)
Gc.compact();
#end
#end
#end
}

Expand Down Expand Up @@ -156,6 +161,14 @@ class CoolUtil {
return #if FAST_MATH FlxMath.fastCos(radians); #else Math.cos(radians); #end
}

public static inline function sinAngle(angle:Float) {
return sin(angle * TO_RADS);
}

public static inline function cosAngle(angle:Float) {
return cos(angle * TO_RADS);
}

public static inline function positionInCenter(object:FlxObject, object2:FlxObject, setToPosition:Bool = false) {
object.x = (object2.width - object.width) * .5;
object.y = (object2.height - object.height) * .5;
Expand All @@ -180,7 +193,7 @@ class CoolUtil {
}

public static inline function translateWithAngle(object:FlxObject, x:Float = 0.0, y:Float = 0.0, angle:Float = 0.0) {
final rads:Float = angle * TO_RADS;
var rads:Float = angle * TO_RADS;
translateWithTrig(object, x, y, sin(rads), cos(rads));
}

Expand Down
Loading

0 comments on commit 727f26d

Please sign in to comment.