diff --git a/source/Main.hx b/source/Main.hx index afb0c20a29..287ab6739d 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -2,7 +2,6 @@ package; import flixel.FlxGame; import flixel.FlxState; -import funkin.Preferences; import funkin.util.logging.CrashHandler; import funkin.ui.debug.MemoryCounter; import funkin.save.Save; @@ -31,6 +30,12 @@ class Main extends Sprite var gameHeight:Int = 720; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom). var initialState:Class = funkin.InitState; // The FlxState the game starts with. var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions. + #if web + var framerate:Int = 60; // How many frames per second the game should run at. + #else + // TODO: This should probably be in the options menu? + var framerate:Int = 144; // How many frames per second the game should run at. + #end var skipSplash:Bool = true; // Whether to skip the flixel splash screen that appears in release mode. var startFullscreen:Bool = false; // Whether to start the game in fullscreen on desktop targets @@ -106,7 +111,7 @@ class Main extends Sprite // George recommends binding the save before FlxGame is created. Save.load(); - var game:FlxGame = new FlxGame(gameWidth, gameHeight, initialState, Preferences.framerate, Preferences.framerate, skipSplash, startFullscreen); + var game:FlxGame = new FlxGame(gameWidth, gameHeight, initialState, framerate, framerate, skipSplash, startFullscreen); // FlxG.game._customSoundTray wants just the class, it calls new from // create() in there, which gets called when it's added to stage diff --git a/source/funkin/Preferences.hx b/source/funkin/Preferences.hx index 7a322283dd..b2050c6a24 100644 --- a/source/funkin/Preferences.hx +++ b/source/funkin/Preferences.hx @@ -7,35 +7,6 @@ import funkin.save.Save; */ class Preferences { - /** - * FPS - * @default `60` - */ - public static var framerate(get, set):Int; - - static function get_framerate():Int - { - #if web - return 60; - #else - return Save?.instance?.options?.framerate ?? 60; - #end - } - - static function set_framerate(value:Int):Int - { - #if web - return 60; - #else - var save:Save = Save.instance; - save.options.framerate = value; - save.flush(); - FlxG.updateFramerate = value; - FlxG.drawFramerate = value; - return value; - #end - } - /** * Whether some particularly fowl language is displayed. * @default `true` diff --git a/source/funkin/save/Save.hx b/source/funkin/save/Save.hx index 04636cb583..2900ce2be6 100644 --- a/source/funkin/save/Save.hx +++ b/source/funkin/save/Save.hx @@ -89,7 +89,6 @@ class Save options: { // Reasonable defaults. - framerate: 60, naughtyness: true, downscroll: false, flashingLights: true, @@ -1056,12 +1055,6 @@ typedef SaveScoreTallyData = */ typedef SaveDataOptions = { - /** - * FPS - * @default `60` - */ - var framerate:Int; - /** * Whether some particularly fowl language is displayed. * @default `true` diff --git a/source/funkin/ui/AtlasText.hx b/source/funkin/ui/AtlasText.hx index ef74abc1e2..186d87c2a1 100644 --- a/source/funkin/ui/AtlasText.hx +++ b/source/funkin/ui/AtlasText.hx @@ -152,32 +152,6 @@ class AtlasText extends FlxTypedSpriteGroup } } - public function getWidth():Int - { - var width = 0; - for (char in this.text.split("")) - { - switch (char) - { - case " ": - { - width += 40; - } - case "\n": - {} - case char: - { - var sprite = new AtlasChar(atlas, char); - sprite.revive(); - sprite.char = char; - sprite.alpha = 1; - width += Std.int(sprite.width); - } - } - } - return width; - } - override function toString() { return "InputItem, " + FlxStringUtil.getDebugString([ diff --git a/source/funkin/ui/options/PreferencesMenu.hx b/source/funkin/ui/options/PreferencesMenu.hx index b9685b1988..c68d0fb623 100644 --- a/source/funkin/ui/options/PreferencesMenu.hx +++ b/source/funkin/ui/options/PreferencesMenu.hx @@ -6,8 +6,6 @@ import flixel.FlxSprite; import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup; import funkin.ui.AtlasText.AtlasFont; import funkin.ui.options.OptionsState.Page; -import funkin.ui.options.items.CheckboxPreferenceItem; -import funkin.ui.options.items.NumberPreferenceItem; import funkin.graphics.FunkinCamera; import funkin.ui.TextMenuList.TextMenuItem; @@ -50,11 +48,6 @@ class PreferencesMenu extends Page */ function createPrefItems():Void { - #if !web - createPrefItemNumber('FPS', 'The framerate that the game is running on', function(value:Float) { - Preferences.framerate = Std.int(value); - }, Preferences.framerate, 60, 360, 1, 0); - #end createPrefItemCheckbox('Naughtyness', 'Toggle displaying raunchy content', function(value:Bool):Void { Preferences.naughtyness = value; }, Preferences.naughtyness); @@ -75,54 +68,75 @@ class PreferencesMenu extends Page }, Preferences.autoPause); } - override function update(elapsed:Float):Void + function createPrefItemCheckbox(prefName:String, prefDesc:String, onChange:Bool->Void, defaultValue:Bool):Void + { + var checkbox:CheckboxPreferenceItem = new CheckboxPreferenceItem(0, 120 * (items.length - 1 + 1), defaultValue); + + items.createItem(120, (120 * items.length) + 30, prefName, AtlasFont.BOLD, function() { + var value = !checkbox.currentValue; + onChange(value); + checkbox.currentValue = value; + }); + + preferenceItems.add(checkbox); + } + + override function update(elapsed:Float) { super.update(elapsed); // Indent the selected item. // TODO: Only do this on menu change? items.forEach(function(daItem:TextMenuItem) { - var thyOffset:Int = 0; - if (Std.isOfType(daItem, NumberPreferenceItem)) thyOffset = cast(daItem, NumberPreferenceItem).lefthandText.getWidth(); - - // Very messy but it works - if (thyOffset == 0) - { - if (items.selectedItem == daItem) thyOffset += 150; - else - thyOffset += 120; - } - else if (items.selectedItem == daItem) - { - thyOffset += 70; - } + if (items.selectedItem == daItem) daItem.x = 150; else - { - thyOffset += 25; - } - - daItem.x = thyOffset; + daItem.x = 120; }); } +} - function createPrefItemCheckbox(prefName:String, prefDesc:String, onChange:Bool->Void, defaultValue:Bool):Void +class CheckboxPreferenceItem extends FlxSprite +{ + public var currentValue(default, set):Bool; + + public function new(x:Float, y:Float, defaultValue:Bool = false) { - var checkbox:CheckboxPreferenceItem = new CheckboxPreferenceItem(0, 120 * (items.length - 1 + 1), defaultValue); + super(x, y); - items.createItem(120, (120 * items.length) + 30, prefName, AtlasFont.BOLD, function() { - var value = !checkbox.currentValue; - onChange(value); - checkbox.currentValue = value; - }); + frames = Paths.getSparrowAtlas('checkboxThingie'); + animation.addByPrefix('static', 'Check Box unselected', 24, false); + animation.addByPrefix('checked', 'Check Box selecting animation', 24, false); - preferenceItems.add(checkbox); + setGraphicSize(Std.int(width * 0.7)); + updateHitbox(); + + this.currentValue = defaultValue; + } + + override function update(elapsed:Float) + { + super.update(elapsed); + + switch (animation.curAnim.name) + { + case 'static': + offset.set(); + case 'checked': + offset.set(17, 70); + } } - function createPrefItemNumber(prefName:String, prefDesc:String, onChange:Float->Void, defaultValue:Float, min:Float, max:Float, step:Float, - precision:Int):Void + function set_currentValue(value:Bool):Bool { - var item = new NumberPreferenceItem(145, (120 * items.length) + 30, prefName, defaultValue, min, max, step, precision, onChange); - items.addItem(prefName, item); - preferenceItems.add(item.lefthandText); + if (value) + { + animation.play('checked', true); + } + else + { + animation.play('static'); + } + + return currentValue = value; } } diff --git a/source/funkin/ui/options/items/CheckboxPreferenceItem.hx b/source/funkin/ui/options/items/CheckboxPreferenceItem.hx deleted file mode 100644 index 88c4fb6b00..0000000000 --- a/source/funkin/ui/options/items/CheckboxPreferenceItem.hx +++ /dev/null @@ -1,49 +0,0 @@ -package funkin.ui.options.items; - -import flixel.FlxSprite.FlxSprite; - -class CheckboxPreferenceItem extends FlxSprite -{ - public var currentValue(default, set):Bool; - - public function new(x:Float, y:Float, defaultValue:Bool = false) - { - super(x, y); - - frames = Paths.getSparrowAtlas('checkboxThingie'); - animation.addByPrefix('static', 'Check Box unselected', 24, false); - animation.addByPrefix('checked', 'Check Box selecting animation', 24, false); - - setGraphicSize(Std.int(width * 0.7)); - updateHitbox(); - - this.currentValue = defaultValue; - } - - override function update(elapsed:Float) - { - super.update(elapsed); - - switch (animation.curAnim.name) - { - case 'static': - offset.set(); - case 'checked': - offset.set(17, 70); - } - } - - function set_currentValue(value:Bool):Bool - { - if (value) - { - animation.play('checked', true); - } - else - { - animation.play('static'); - } - - return currentValue = value; - } -} diff --git a/source/funkin/ui/options/items/NumberPreferenceItem.hx b/source/funkin/ui/options/items/NumberPreferenceItem.hx deleted file mode 100644 index 795b6c9942..0000000000 --- a/source/funkin/ui/options/items/NumberPreferenceItem.hx +++ /dev/null @@ -1,107 +0,0 @@ -package funkin.ui.options.items; - -import funkin.ui.TextMenuList; -import funkin.ui.AtlasText; -import funkin.input.Controls; - -/** - * Preference item that allows the player to pick a value between min and max - */ -class NumberPreferenceItem extends TextMenuItem -{ - function controls():Controls - { - return PlayerSettings.player1.controls; - } - - public var lefthandText:AtlasText; - - public var currentValue:Float; - public var min:Float; - public var max:Float; - public var step:Float; - public var precision:Int; - public var onChangeCallback:NullVoid>; - - public function new(x:Float, y:Float, name:String, defaultValue:Float, min:Float, max:Float, step:Float, precision:Int, ?callback:Float->Void):Void - { - super(x, y, name, function() { - callback(this.currentValue); - }); - lefthandText = new AtlasText(20, y, formatted(defaultValue), AtlasFont.DEFAULT); - - updateHitbox(); - - this.currentValue = defaultValue; - this.min = min; - this.max = max; - this.step = step; - this.precision = precision; - this.onChangeCallback = callback; - } - - static final HOLD_DELAY:Float = 0.5; // seconds - static final CHANGE_RATE:Float = 0.02; // seconds - - var holdDelayTimer:Float = HOLD_DELAY; // seconds - var changeRateTimer:Float = 0.0; // seconds - - override function update(elapsed:Float):Void - { - super.update(elapsed); - - // var fancyTextFancyColor:Color; - if (selected) - { - holdDelayTimer -= elapsed; - if (holdDelayTimer <= 0.0) - { - changeRateTimer -= elapsed; - } - - var jpLeft:Bool = controls().UI_LEFT_P; - var jpRight:Bool = controls().UI_RIGHT_P; - - if (jpLeft || jpRight) - { - holdDelayTimer = HOLD_DELAY; - changeRateTimer = 0.0; - } - - var shouldDecrease:Bool = jpLeft; - var shouldIncrease:Bool = jpRight; - - if (controls().UI_LEFT && holdDelayTimer <= 0.0 && changeRateTimer <= 0.0) - { - shouldDecrease = true; - changeRateTimer = CHANGE_RATE; - } - else if (controls().UI_RIGHT && holdDelayTimer <= 0.0 && changeRateTimer <= 0.0) - { - shouldIncrease = true; - changeRateTimer = CHANGE_RATE; - } - - if (shouldDecrease) currentValue -= step; - else if (shouldIncrease) currentValue += step; - currentValue = currentValue.clamp(min, max); - if (onChangeCallback != null && (shouldIncrease || shouldDecrease)) - { - onChangeCallback(currentValue); - } - } - - lefthandText.text = formatted(currentValue); - } - - function formatted(value:Float):String - { - return '${toFixed(value)}'; - } - - function toFixed(value:Float):Float - { - var multiplier:Float = Math.pow(10, precision); - return Math.floor(value * multiplier) / multiplier; - } -}