From e0fe7cb1ebed863111b7fffca389e9e603b47e3c Mon Sep 17 00:00:00 2001 From: lemz Date: Sat, 25 May 2024 01:11:34 +0200 Subject: [PATCH 01/13] add fps option --- source/Main.hx | 9 +- source/funkin/Preferences.hx | 29 +++ source/funkin/save/Save.hx | 10 +- source/funkin/ui/options/PreferencesMenu.hx | 211 ++++++++++++++++---- 4 files changed, 207 insertions(+), 52 deletions(-) diff --git a/source/Main.hx b/source/Main.hx index add5bbc67..8105e6c4f 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -2,6 +2,7 @@ package; import flixel.FlxGame; import flixel.FlxState; +import funkin.Preferences; import funkin.util.logging.CrashHandler; import funkin.ui.debug.MemoryCounter; import funkin.save.Save; @@ -22,12 +23,6 @@ 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 @@ -103,7 +98,7 @@ class Main extends Sprite // George recommends binding the save before FlxGame is created. Save.load(); - var game:FlxGame = new FlxGame(gameWidth, gameHeight, initialState, framerate, framerate, skipSplash, startFullscreen); + var game:FlxGame = new FlxGame(gameWidth, gameHeight, initialState, Preferences.framerate, Preferences.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 b2050c6a2..7a322283d 100644 --- a/source/funkin/Preferences.hx +++ b/source/funkin/Preferences.hx @@ -7,6 +7,35 @@ 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 acbe59edd..3600e9741 100644 --- a/source/funkin/save/Save.hx +++ b/source/funkin/save/Save.hx @@ -53,7 +53,8 @@ class Save public function new(?data:RawSaveData) { if (data == null) this.data = Save.getDefault(); - else this.data = data; + else + this.data = data; } public static function getDefault():RawSaveData @@ -80,6 +81,7 @@ class Save options: { // Reasonable defaults. + framerate: 60, naughtyness: true, downscroll: false, flashingLights: true, @@ -835,6 +837,12 @@ 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/options/PreferencesMenu.hx b/source/funkin/ui/options/PreferencesMenu.hx index 783aef0ba..cf7296584 100644 --- a/source/funkin/ui/options/PreferencesMenu.hx +++ b/source/funkin/ui/options/PreferencesMenu.hx @@ -3,16 +3,16 @@ package funkin.ui.options; import flixel.FlxCamera; import flixel.FlxObject; import flixel.FlxSprite; +import flixel.math.FlxMath; import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup; import funkin.ui.AtlasText.AtlasFont; import funkin.ui.options.OptionsState.Page; import funkin.graphics.FunkinCamera; -import funkin.ui.TextMenuList.TextMenuItem; class PreferencesMenu extends Page { - var items:TextMenuList; - var preferenceItems:FlxTypedSpriteGroup; + var curSelected:Int = 0; + var prefs:FlxTypedSpriteGroup; var menuCamera:FlxCamera; var camFollow:FlxObject; @@ -26,22 +26,27 @@ class PreferencesMenu extends Page menuCamera.bgColor = 0x0; camera = menuCamera; - add(items = new TextMenuList()); - add(preferenceItems = new FlxTypedSpriteGroup()); + prefs = new FlxTypedSpriteGroup(); + add(prefs); createPrefItems(); camFollow = new FlxObject(FlxG.width / 2, 0, 140, 70); - if (items != null) camFollow.y = items.selectedItem.y; menuCamera.follow(camFollow, null, 0.06); var margin = 160; menuCamera.deadzone.set(0, margin, menuCamera.width, 40); menuCamera.minScrollY = 0; - items.onChange.add(function(selected) { - camFollow.y = selected.y; - }); + changeSelection(0); + } + + function addPref(pref:PreferenceItem):Void + { + pref.x = 0; + pref.y = 120 * prefs.length; + pref.ID = prefs.length; + prefs.add(pref); } /** @@ -49,50 +54,168 @@ class PreferencesMenu extends Page */ function createPrefItems():Void { - createPrefItemCheckbox('Naughtyness', 'Toggle displaying raunchy content', function(value:Bool):Void { - Preferences.naughtyness = value; - }, Preferences.naughtyness); - createPrefItemCheckbox('Downscroll', 'Enable to make notes move downwards', function(value:Bool):Void { - Preferences.downscroll = value; - }, Preferences.downscroll); - createPrefItemCheckbox('Flashing Lights', 'Disable to dampen flashing effects', function(value:Bool):Void { - Preferences.flashingLights = value; - }, Preferences.flashingLights); - createPrefItemCheckbox('Camera Zooming on Beat', 'Disable to stop the camera bouncing to the song', function(value:Bool):Void { - Preferences.zoomCamera = value; - }, Preferences.zoomCamera); - createPrefItemCheckbox('Debug Display', 'Enable to show FPS and other debug stats', function(value:Bool):Void { - Preferences.debugDisplay = value; - }, Preferences.debugDisplay); - createPrefItemCheckbox('Auto Pause', 'Automatically pause the game when it loses focus', function(value:Bool):Void { - Preferences.autoPause = value; - }, Preferences.autoPause); + #if !web + var pref:NumberedPreferenceItem = new NumberedPreferenceItem("FPS", "The framerate that the game is running on", Preferences.framerate, + function(value:Float):Void { + Preferences.framerate = Std.int(value); + }); + pref.minValue = 60; + pref.maxValue = 360; + pref.changeRate = 1; + pref.changeSpeed = 0.05; + addPref(pref); + #end + + // TODO: add these back + // createPrefItemCheckbox('Naughtyness', 'Toggle displaying raunchy content', function(value:Bool):Void { + // Preferences.naughtyness = value; + // }, Preferences.naughtyness); + // createPrefItemCheckbox('Downscroll', 'Enable to make notes move downwards', function(value:Bool):Void { + // Preferences.downscroll = value; + // }, Preferences.downscroll); + // createPrefItemCheckbox('Flashing Lights', 'Disable to dampen flashing effects', function(value:Bool):Void { + // Preferences.flashingLights = value; + // }, Preferences.flashingLights); + // createPrefItemCheckbox('Camera Zooming on Beat', 'Disable to stop the camera bouncing to the song', function(value:Bool):Void { + // Preferences.zoomCamera = value; + // }, Preferences.zoomCamera); + // createPrefItemCheckbox('Debug Display', 'Enable to show FPS and other debug stats', function(value:Bool):Void { + // Preferences.debugDisplay = value; + // }, Preferences.debugDisplay); + // createPrefItemCheckbox('Auto Pause', 'Automatically pause the game when it loses focus', function(value:Bool):Void { + // Preferences.autoPause = value; + // }, Preferences.autoPause); } - function createPrefItemCheckbox(prefName:String, prefDesc:String, onChange:Bool->Void, defaultValue:Bool):Void + function changeSelection(change:Int):Void { - var checkbox:CheckboxPreferenceItem = new CheckboxPreferenceItem(0, 120 * (items.length - 1 + 1), defaultValue); + curSelected += change; + if (curSelected < 0) + { + curSelected = prefs.length - 1; + } + else if (curSelected >= prefs.length) + { + curSelected = 0; + } - items.createItem(120, (120 * items.length) + 30, prefName, AtlasFont.BOLD, function() { - var value = !checkbox.currentValue; - onChange(value); - checkbox.currentValue = value; - }); - - preferenceItems.add(checkbox); + for (pref in prefs) + { + pref.x = 0; + if (pref.ID == curSelected) + { + pref.x = 20; + camFollow.y = pref.y; + } + } } - override function update(elapsed:Float) + override function update(elapsed:Float):Void { super.update(elapsed); - // Indent the selected item. - // TODO: Only do this on menu change? - items.forEach(function(daItem:TextMenuItem) { - if (items.selectedItem == daItem) daItem.x = 150; - else - daItem.x = 120; - }); + if (controls.UI_DOWN_P) + { + changeSelection(1); + } + else if (controls.UI_UP_P) + { + changeSelection(-1); + } + + var selectedPref:PreferenceItem = prefs.members[curSelected]; + selectedPref.handleInput(elapsed); + } +} + +class PreferenceItem extends FlxTypedSpriteGroup +{ + public var name:String = ""; + public var description:String = ""; + + public function handleInput(deltaTime:Float):Void {} +} + +class NumberedPreferenceItem extends PreferenceItem +{ + public var onChange:Float->Void; + public var changeRate:Float = 1.0; + public var changeSpeed:Float = 0.1; + + public var minValue(default, set):Null; + + function set_minValue(value:Float):Float + { + minValue = value; + currentValue = currentValue; + return value; + } + + public var maxValue(default, set):Null; + + function set_maxValue(value:Float):Float + { + maxValue = value; + currentValue = currentValue; + return value; + } + + public var currentValue(default, set):Float; + + function set_currentValue(value:Float):Float + { + currentValue = FlxMath.bound(value, minValue, maxValue); + onChange(currentValue); + updateText(); + return currentValue; + } + + var valueText:AtlasText; + var preferenceText:AtlasText; + + public function new(name:String, description:String, defaultValue:Float, onChange:Float->Void) + { + super(); + + this.valueText = new AtlasText(0, 0, '$defaultValue', AtlasFont.DEFAULT); + add(this.valueText); + + this.preferenceText = new AtlasText(this.valueText.width + 30, 0, '$name', AtlasFont.BOLD); + add(this.preferenceText); + + this.name = name; + this.description = description; + this.onChange = onChange; + this.currentValue = defaultValue; + } + + var timeToWait:Float = 0; + + public override function handleInput(deltaTime:Float):Void + { + timeToWait -= deltaTime; + + if (timeToWait > 0) + { + return; + } + + if (PlayerSettings.player1.controls.UI_RIGHT) + { + currentValue += changeRate; + timeToWait = changeSpeed; + } + else if (PlayerSettings.player1.controls.UI_LEFT) + { + currentValue -= changeRate; + timeToWait = changeSpeed; + } + } + + function updateText():Void + { + valueText.text = '$currentValue'; + preferenceText.x = valueText.width + 30; } } From dd6d12de2340563bcbe254b36977d119085a06aa Mon Sep 17 00:00:00 2001 From: lemz Date: Sat, 25 May 2024 01:20:10 +0200 Subject: [PATCH 02/13] rename vars --- source/funkin/ui/options/PreferencesMenu.hx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/funkin/ui/options/PreferencesMenu.hx b/source/funkin/ui/options/PreferencesMenu.hx index cf7296584..87917ad70 100644 --- a/source/funkin/ui/options/PreferencesMenu.hx +++ b/source/funkin/ui/options/PreferencesMenu.hx @@ -62,7 +62,7 @@ class PreferencesMenu extends Page pref.minValue = 60; pref.maxValue = 360; pref.changeRate = 1; - pref.changeSpeed = 0.05; + pref.changeDelay = 0.05; addPref(pref); #end @@ -133,14 +133,14 @@ class PreferenceItem extends FlxTypedSpriteGroup public var name:String = ""; public var description:String = ""; - public function handleInput(deltaTime:Float):Void {} + public function handleInput(elapsed:Float):Void {} } class NumberedPreferenceItem extends PreferenceItem { public var onChange:Float->Void; public var changeRate:Float = 1.0; - public var changeSpeed:Float = 0.1; + public var changeDelay:Float = 0.1; public var minValue(default, set):Null; @@ -191,9 +191,9 @@ class NumberedPreferenceItem extends PreferenceItem var timeToWait:Float = 0; - public override function handleInput(deltaTime:Float):Void + public override function handleInput(elapsed:Float):Void { - timeToWait -= deltaTime; + timeToWait -= elapsed; if (timeToWait > 0) { @@ -203,12 +203,12 @@ class NumberedPreferenceItem extends PreferenceItem if (PlayerSettings.player1.controls.UI_RIGHT) { currentValue += changeRate; - timeToWait = changeSpeed; + timeToWait = changeDelay; } else if (PlayerSettings.player1.controls.UI_LEFT) { currentValue -= changeRate; - timeToWait = changeSpeed; + timeToWait = changeDelay; } } From b75f6e58532534dd94cef1c93c24270e1f56425e Mon Sep 17 00:00:00 2001 From: lemz Date: Sat, 25 May 2024 02:19:11 +0200 Subject: [PATCH 03/13] Update PreferencesMenu.hx --- source/funkin/ui/options/PreferencesMenu.hx | 136 ++++++++++++-------- 1 file changed, 81 insertions(+), 55 deletions(-) diff --git a/source/funkin/ui/options/PreferencesMenu.hx b/source/funkin/ui/options/PreferencesMenu.hx index 87917ad70..acbb57525 100644 --- a/source/funkin/ui/options/PreferencesMenu.hx +++ b/source/funkin/ui/options/PreferencesMenu.hx @@ -66,25 +66,41 @@ class PreferencesMenu extends Page addPref(pref); #end - // TODO: add these back - // createPrefItemCheckbox('Naughtyness', 'Toggle displaying raunchy content', function(value:Bool):Void { - // Preferences.naughtyness = value; - // }, Preferences.naughtyness); - // createPrefItemCheckbox('Downscroll', 'Enable to make notes move downwards', function(value:Bool):Void { - // Preferences.downscroll = value; - // }, Preferences.downscroll); - // createPrefItemCheckbox('Flashing Lights', 'Disable to dampen flashing effects', function(value:Bool):Void { - // Preferences.flashingLights = value; - // }, Preferences.flashingLights); - // createPrefItemCheckbox('Camera Zooming on Beat', 'Disable to stop the camera bouncing to the song', function(value:Bool):Void { - // Preferences.zoomCamera = value; - // }, Preferences.zoomCamera); - // createPrefItemCheckbox('Debug Display', 'Enable to show FPS and other debug stats', function(value:Bool):Void { - // Preferences.debugDisplay = value; - // }, Preferences.debugDisplay); - // createPrefItemCheckbox('Auto Pause', 'Automatically pause the game when it loses focus', function(value:Bool):Void { - // Preferences.autoPause = value; - // }, Preferences.autoPause); + var pref:CheckboxPreferenceItem = new CheckboxPreferenceItem('Naughtyness', 'Toggle displaying raunchy content', Preferences.naughtyness, + function(value:Bool):Void { + Preferences.naughtyness = value; + }); + addPref(pref); + + var pref:CheckboxPreferenceItem = new CheckboxPreferenceItem('Downscroll', 'Enable to make notes move downwards', Preferences.downscroll, + function(value:Bool):Void { + Preferences.downscroll = value; + }); + addPref(pref); + + var pref:CheckboxPreferenceItem = new CheckboxPreferenceItem('Flashing Lights', 'Disable to dampen flashing effects', Preferences.flashingLights, + function(value:Bool):Void { + Preferences.flashingLights = value; + }); + addPref(pref); + + var pref:CheckboxPreferenceItem = new CheckboxPreferenceItem('Camera Zooming on Beat', 'Disable to stop the camera bouncing to the song', + Preferences.zoomCamera, function(value:Bool):Void { + Preferences.zoomCamera = value; + }); + addPref(pref); + + var pref:CheckboxPreferenceItem = new CheckboxPreferenceItem('Debug Display', 'Enable to show FPS and other debug stats', Preferences.debugDisplay, + function(value:Bool):Void { + Preferences.debugDisplay = value; + }); + addPref(pref); + + var pref:CheckboxPreferenceItem = new CheckboxPreferenceItem('Auto Pause', 'Automatically pause the game when it loses focus', Preferences.autoPause, + function(value:Bool):Void { + Preferences.autoPause = value; + }); + addPref(pref); } function changeSelection(change:Int):Void @@ -104,7 +120,7 @@ class PreferencesMenu extends Page pref.x = 0; if (pref.ID == curSelected) { - pref.x = 20; + pref.x = 30; camFollow.y = pref.y; } } @@ -124,7 +140,7 @@ class PreferencesMenu extends Page } var selectedPref:PreferenceItem = prefs.members[curSelected]; - selectedPref.handleInput(elapsed); + selectedPref?.handleInput(elapsed); } } @@ -177,10 +193,10 @@ class NumberedPreferenceItem extends PreferenceItem { super(); - this.valueText = new AtlasText(0, 0, '$defaultValue', AtlasFont.DEFAULT); + this.valueText = new AtlasText(20, 30, '$defaultValue', AtlasFont.DEFAULT); add(this.valueText); - this.preferenceText = new AtlasText(this.valueText.width + 30, 0, '$name', AtlasFont.BOLD); + this.preferenceText = new AtlasText(this.valueText.x + this.valueText.width + 30, 30, '$name', AtlasFont.BOLD); add(this.preferenceText); this.name = name; @@ -215,52 +231,62 @@ class NumberedPreferenceItem extends PreferenceItem function updateText():Void { valueText.text = '$currentValue'; - preferenceText.x = valueText.width + 30; + preferenceText.x = valueText.x + valueText.width + 30; } } -class CheckboxPreferenceItem extends FlxSprite +class CheckboxPreferenceItem extends PreferenceItem { + public var onChange:Bool->Void; + 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); + checkBox.animation.play('checked', true); + checkBox.offset.set(17, 70); } else { - animation.play('static'); + checkBox.animation.play('static'); + checkBox.offset.set(); } + currentValue = value; + onChange(value); + return value; + } - return currentValue = value; + var checkBox:FlxSprite; + var preferenceText:AtlasText; + + public function new(name:String, description:String, defaultValue:Bool, onChange:Bool->Void) + { + super(); + + this.checkBox = new FlxSprite(); + this.checkBox.frames = Paths.getSparrowAtlas('checkboxThingie'); + this.checkBox.animation.addByPrefix('static', 'Check Box unselected', 24, false); + this.checkBox.animation.addByPrefix('checked', 'Check Box selecting animation', 24, false); + this.checkBox.setGraphicSize(Std.int(this.checkBox.width * 0.7)); + this.checkBox.updateHitbox(); + add(this.checkBox); + + this.preferenceText = new AtlasText(120, 30, '$name', AtlasFont.BOLD); + add(this.preferenceText); + + this.name = name; + this.description = description; + this.onChange = onChange; + this.currentValue = defaultValue; + } + + public override function handleInput(elapsed:Float):Void + { + if (PlayerSettings.player1.controls.ACCEPT) + { + currentValue = !currentValue; + } } } From 814d72cb3f241c61896adda8e6f84435ff056f4a Mon Sep 17 00:00:00 2001 From: lemz Date: Sat, 25 May 2024 03:06:27 +0200 Subject: [PATCH 04/13] sounds --- source/funkin/ui/options/PreferencesMenu.hx | 28 ++++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/source/funkin/ui/options/PreferencesMenu.hx b/source/funkin/ui/options/PreferencesMenu.hx index acbb57525..75bc0fdb3 100644 --- a/source/funkin/ui/options/PreferencesMenu.hx +++ b/source/funkin/ui/options/PreferencesMenu.hx @@ -4,13 +4,20 @@ import flixel.FlxCamera; import flixel.FlxObject; import flixel.FlxSprite; import flixel.math.FlxMath; +import flixel.effects.FlxFlicker; import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup; import funkin.ui.AtlasText.AtlasFont; import funkin.ui.options.OptionsState.Page; import funkin.graphics.FunkinCamera; +import funkin.audio.FunkinSound; class PreferencesMenu extends Page { + /** + * Wether you can selected a different option + */ + public static var allowScrolling:Bool = true; + var curSelected:Int = 0; var prefs:FlxTypedSpriteGroup; @@ -130,12 +137,14 @@ class PreferencesMenu extends Page { super.update(elapsed); - if (controls.UI_DOWN_P) + if (controls.UI_DOWN_P && allowScrolling) { + FunkinSound.playOnce(Paths.sound('scrollMenu')); changeSelection(1); } - else if (controls.UI_UP_P) + else if (controls.UI_UP_P && allowScrolling) { + FunkinSound.playOnce(Paths.sound('scrollMenu')); changeSelection(-1); } @@ -220,11 +229,13 @@ class NumberedPreferenceItem extends PreferenceItem { currentValue += changeRate; timeToWait = changeDelay; + // FunkinSound.playOnce(Paths.sound('scrollMenu')); } else if (PlayerSettings.player1.controls.UI_LEFT) { currentValue -= changeRate; timeToWait = changeDelay; + // FunkinSound.playOnce(Paths.sound('scrollMenu')); } } @@ -282,11 +293,20 @@ class CheckboxPreferenceItem extends PreferenceItem this.currentValue = defaultValue; } + var isAccepting:Bool = false; + public override function handleInput(elapsed:Float):Void { - if (PlayerSettings.player1.controls.ACCEPT) + if (PlayerSettings.player1.controls.ACCEPT && !isAccepting) { - currentValue = !currentValue; + isAccepting = true; + PreferencesMenu.allowScrolling = false; + FunkinSound.playOnce(Paths.sound('confirmMenu')); + FlxFlicker.flicker(preferenceText, 1, 0.06, true, false, function(_) { + isAccepting = false; + PreferencesMenu.allowScrolling = true; + currentValue = !currentValue; + }); } } } From 267fd0eadcaceedc69bae06bf3d3344f4251bfdc Mon Sep 17 00:00:00 2001 From: lemz Date: Sat, 25 May 2024 16:30:08 +0200 Subject: [PATCH 05/13] alpha stuff and correct text positioning --- source/funkin/ui/options/PreferencesMenu.hx | 42 +++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/source/funkin/ui/options/PreferencesMenu.hx b/source/funkin/ui/options/PreferencesMenu.hx index 75bc0fdb3..4e9e0bca8 100644 --- a/source/funkin/ui/options/PreferencesMenu.hx +++ b/source/funkin/ui/options/PreferencesMenu.hx @@ -124,12 +124,15 @@ class PreferencesMenu extends Page for (pref in prefs) { - pref.x = 0; if (pref.ID == curSelected) { - pref.x = 30; + pref.onSelect(true); camFollow.y = pref.y; } + else + { + pref.onSelect(false); + } } } @@ -159,6 +162,8 @@ class PreferenceItem extends FlxTypedSpriteGroup public var description:String = ""; public function handleInput(elapsed:Float):Void {} + + public function onSelect(isSelected:Bool):Void {} } class NumberedPreferenceItem extends PreferenceItem @@ -239,10 +244,27 @@ class NumberedPreferenceItem extends PreferenceItem } } + var isSelected:Bool = false; + + public override function onSelect(isSelected:Bool):Void + { + this.isSelected = isSelected; + if (isSelected) + { + preferenceText.x = valueText.x + valueText.width + 60; + preferenceText.alpha = 1.0; + } + else + { + preferenceText.x = valueText.x + valueText.width + 30; + preferenceText.alpha = 0.6; + } + } + function updateText():Void { valueText.text = '$currentValue'; - preferenceText.x = valueText.x + valueText.width + 30; + preferenceText.x = valueText.x + valueText.width + (isSelected ? 60 : 30); } } @@ -309,4 +331,18 @@ class CheckboxPreferenceItem extends PreferenceItem }); } } + + public override function onSelect(isSelected:Bool):Void + { + if (isSelected) + { + preferenceText.x = 150; + preferenceText.alpha = 1.0; + } + else + { + preferenceText.alpha = 0.6; + preferenceText.x = 120; + } + } } From 4a531888b550f10564f058b8d2155645d33a7867 Mon Sep 17 00:00:00 2001 From: lemz Date: Thu, 30 May 2024 00:22:10 +0200 Subject: [PATCH 06/13] Update PreferencesMenu.hx --- source/funkin/ui/options/PreferencesMenu.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/funkin/ui/options/PreferencesMenu.hx b/source/funkin/ui/options/PreferencesMenu.hx index 4e9e0bca8..205ef1809 100644 --- a/source/funkin/ui/options/PreferencesMenu.hx +++ b/source/funkin/ui/options/PreferencesMenu.hx @@ -14,7 +14,7 @@ import funkin.audio.FunkinSound; class PreferencesMenu extends Page { /** - * Wether you can selected a different option + * Wether you can select a different option */ public static var allowScrolling:Bool = true; From 3b3b9d97ba08d8e315df0bcd755d79d1e6e27a81 Mon Sep 17 00:00:00 2001 From: lemz Date: Sun, 23 Jun 2024 21:03:30 +0200 Subject: [PATCH 07/13] use different implementation --- source/funkin/ui/AtlasText.hx | 26 ++ source/funkin/ui/options/PreferencesMenu.hx | 371 ++++-------------- .../options/items/CheckboxPreferenceItem.hx | 49 +++ .../ui/options/items/NumberPreferenceItem.hx | 107 +++++ 4 files changed, 258 insertions(+), 295 deletions(-) create mode 100644 source/funkin/ui/options/items/CheckboxPreferenceItem.hx create mode 100644 source/funkin/ui/options/items/NumberPreferenceItem.hx diff --git a/source/funkin/ui/AtlasText.hx b/source/funkin/ui/AtlasText.hx index 186d87c2a..ef74abc1e 100644 --- a/source/funkin/ui/AtlasText.hx +++ b/source/funkin/ui/AtlasText.hx @@ -152,6 +152,32 @@ 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 205ef1809..d03fe9073 100644 --- a/source/funkin/ui/options/PreferencesMenu.hx +++ b/source/funkin/ui/options/PreferencesMenu.hx @@ -3,23 +3,18 @@ package funkin.ui.options; import flixel.FlxCamera; import flixel.FlxObject; import flixel.FlxSprite; -import flixel.math.FlxMath; -import flixel.effects.FlxFlicker; 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.audio.FunkinSound; +import funkin.ui.TextMenuList.TextMenuItem; class PreferencesMenu extends Page { - /** - * Wether you can select a different option - */ - public static var allowScrolling:Bool = true; - - var curSelected:Int = 0; - var prefs:FlxTypedSpriteGroup; + var items:TextMenuList; + var preferenceItems:FlxTypedSpriteGroup; var menuCamera:FlxCamera; var camFollow:FlxObject; @@ -33,27 +28,22 @@ class PreferencesMenu extends Page menuCamera.bgColor = 0x0; camera = menuCamera; - prefs = new FlxTypedSpriteGroup(); - add(prefs); + add(items = new TextMenuList()); + add(preferenceItems = new FlxTypedSpriteGroup()); createPrefItems(); camFollow = new FlxObject(FlxG.width / 2, 0, 140, 70); + if (items != null) camFollow.y = items.selectedItem.y; menuCamera.follow(camFollow, null, 0.06); var margin = 160; menuCamera.deadzone.set(0, margin, menuCamera.width, 40); menuCamera.minScrollY = 0; - changeSelection(0); - } - - function addPref(pref:PreferenceItem):Void - { - pref.x = 0; - pref.y = 120 * prefs.length; - pref.ID = prefs.length; - prefs.add(pref); + items.onChange.add(function(selected) { + camFollow.y = selected.y; + }); } /** @@ -62,287 +52,78 @@ class PreferencesMenu extends Page function createPrefItems():Void { #if !web - var pref:NumberedPreferenceItem = new NumberedPreferenceItem("FPS", "The framerate that the game is running on", Preferences.framerate, - function(value:Float):Void { - Preferences.framerate = Std.int(value); - }); - pref.minValue = 60; - pref.maxValue = 360; - pref.changeRate = 1; - pref.changeDelay = 0.05; - addPref(pref); + 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 - - var pref:CheckboxPreferenceItem = new CheckboxPreferenceItem('Naughtyness', 'Toggle displaying raunchy content', Preferences.naughtyness, - function(value:Bool):Void { - Preferences.naughtyness = value; - }); - addPref(pref); - - var pref:CheckboxPreferenceItem = new CheckboxPreferenceItem('Downscroll', 'Enable to make notes move downwards', Preferences.downscroll, - function(value:Bool):Void { - Preferences.downscroll = value; - }); - addPref(pref); - - var pref:CheckboxPreferenceItem = new CheckboxPreferenceItem('Flashing Lights', 'Disable to dampen flashing effects', Preferences.flashingLights, - function(value:Bool):Void { - Preferences.flashingLights = value; - }); - addPref(pref); - - var pref:CheckboxPreferenceItem = new CheckboxPreferenceItem('Camera Zooming on Beat', 'Disable to stop the camera bouncing to the song', - Preferences.zoomCamera, function(value:Bool):Void { - Preferences.zoomCamera = value; - }); - addPref(pref); - - var pref:CheckboxPreferenceItem = new CheckboxPreferenceItem('Debug Display', 'Enable to show FPS and other debug stats', Preferences.debugDisplay, - function(value:Bool):Void { - Preferences.debugDisplay = value; - }); - addPref(pref); - - var pref:CheckboxPreferenceItem = new CheckboxPreferenceItem('Auto Pause', 'Automatically pause the game when it loses focus', Preferences.autoPause, - function(value:Bool):Void { - Preferences.autoPause = value; - }); - addPref(pref); - } - - function changeSelection(change:Int):Void - { - curSelected += change; - if (curSelected < 0) - { - curSelected = prefs.length - 1; - } - else if (curSelected >= prefs.length) - { - curSelected = 0; - } - - for (pref in prefs) - { - if (pref.ID == curSelected) - { - pref.onSelect(true); - camFollow.y = pref.y; - } - else - { - pref.onSelect(false); - } - } + createPrefItemCheckbox('Naughtyness', 'Toggle displaying raunchy content', function(value:Bool):Void { + Preferences.naughtyness = value; + }, Preferences.naughtyness); + createPrefItemCheckbox('Downscroll', 'Enable to make notes move downwards', function(value:Bool):Void { + Preferences.downscroll = value; + }, Preferences.downscroll); + createPrefItemCheckbox('Flashing Lights', 'Disable to dampen flashing effects', function(value:Bool):Void { + Preferences.flashingLights = value; + }, Preferences.flashingLights); + createPrefItemCheckbox('Camera Zooming on Beat', 'Disable to stop the camera bouncing to the song', function(value:Bool):Void { + Preferences.zoomCamera = value; + }, Preferences.zoomCamera); + createPrefItemCheckbox('Debug Display', 'Enable to show FPS and other debug stats', function(value:Bool):Void { + Preferences.debugDisplay = value; + }, Preferences.debugDisplay); + createPrefItemCheckbox('Auto Pause', 'Automatically pause the game when it loses focus', function(value:Bool):Void { + Preferences.autoPause = value; + }, Preferences.autoPause); } override function update(elapsed:Float):Void { super.update(elapsed); - if (controls.UI_DOWN_P && allowScrolling) - { - FunkinSound.playOnce(Paths.sound('scrollMenu')); - changeSelection(1); - } - else if (controls.UI_UP_P && allowScrolling) - { - FunkinSound.playOnce(Paths.sound('scrollMenu')); - changeSelection(-1); - } + // 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(); - var selectedPref:PreferenceItem = prefs.members[curSelected]; - selectedPref?.handleInput(elapsed); - } -} - -class PreferenceItem extends FlxTypedSpriteGroup -{ - public var name:String = ""; - public var description:String = ""; - - public function handleInput(elapsed:Float):Void {} - - public function onSelect(isSelected:Bool):Void {} -} - -class NumberedPreferenceItem extends PreferenceItem -{ - public var onChange:Float->Void; - public var changeRate:Float = 1.0; - public var changeDelay:Float = 0.1; - - public var minValue(default, set):Null; - - function set_minValue(value:Float):Float - { - minValue = value; - currentValue = currentValue; - return value; - } - - public var maxValue(default, set):Null; - - function set_maxValue(value:Float):Float - { - maxValue = value; - currentValue = currentValue; - return value; - } - - public var currentValue(default, set):Float; - - function set_currentValue(value:Float):Float - { - currentValue = FlxMath.bound(value, minValue, maxValue); - onChange(currentValue); - updateText(); - return currentValue; - } - - var valueText:AtlasText; - var preferenceText:AtlasText; - - public function new(name:String, description:String, defaultValue:Float, onChange:Float->Void) - { - super(); - - this.valueText = new AtlasText(20, 30, '$defaultValue', AtlasFont.DEFAULT); - add(this.valueText); - - this.preferenceText = new AtlasText(this.valueText.x + this.valueText.width + 30, 30, '$name', AtlasFont.BOLD); - add(this.preferenceText); - - this.name = name; - this.description = description; - this.onChange = onChange; - this.currentValue = defaultValue; - } - - var timeToWait:Float = 0; - - public override function handleInput(elapsed:Float):Void - { - timeToWait -= elapsed; - - if (timeToWait > 0) - { - return; - } - - if (PlayerSettings.player1.controls.UI_RIGHT) - { - currentValue += changeRate; - timeToWait = changeDelay; - // FunkinSound.playOnce(Paths.sound('scrollMenu')); - } - else if (PlayerSettings.player1.controls.UI_LEFT) - { - currentValue -= changeRate; - timeToWait = changeDelay; - // FunkinSound.playOnce(Paths.sound('scrollMenu')); - } - } - - var isSelected:Bool = false; - - public override function onSelect(isSelected:Bool):Void - { - this.isSelected = isSelected; - if (isSelected) - { - preferenceText.x = valueText.x + valueText.width + 60; - preferenceText.alpha = 1.0; - } - else - { - preferenceText.x = valueText.x + valueText.width + 30; - preferenceText.alpha = 0.6; - } - } - - function updateText():Void - { - valueText.text = '$currentValue'; - preferenceText.x = valueText.x + valueText.width + (isSelected ? 60 : 30); - } -} - -class CheckboxPreferenceItem extends PreferenceItem -{ - public var onChange:Bool->Void; - - public var currentValue(default, set):Bool; - - function set_currentValue(value:Bool):Bool - { - if (value) - { - checkBox.animation.play('checked', true); - checkBox.offset.set(17, 70); - } - else - { - checkBox.animation.play('static'); - checkBox.offset.set(); - } - currentValue = value; - onChange(value); - return value; - } - - var checkBox:FlxSprite; - var preferenceText:AtlasText; - - public function new(name:String, description:String, defaultValue:Bool, onChange:Bool->Void) - { - super(); - - this.checkBox = new FlxSprite(); - this.checkBox.frames = Paths.getSparrowAtlas('checkboxThingie'); - this.checkBox.animation.addByPrefix('static', 'Check Box unselected', 24, false); - this.checkBox.animation.addByPrefix('checked', 'Check Box selecting animation', 24, false); - this.checkBox.setGraphicSize(Std.int(this.checkBox.width * 0.7)); - this.checkBox.updateHitbox(); - add(this.checkBox); - - this.preferenceText = new AtlasText(120, 30, '$name', AtlasFont.BOLD); - add(this.preferenceText); - - this.name = name; - this.description = description; - this.onChange = onChange; - this.currentValue = defaultValue; - } - - var isAccepting:Bool = false; - - public override function handleInput(elapsed:Float):Void - { - if (PlayerSettings.player1.controls.ACCEPT && !isAccepting) - { - isAccepting = true; - PreferencesMenu.allowScrolling = false; - FunkinSound.playOnce(Paths.sound('confirmMenu')); - FlxFlicker.flicker(preferenceText, 1, 0.06, true, false, function(_) { - isAccepting = false; - PreferencesMenu.allowScrolling = true; - currentValue = !currentValue; - }); - } - } - - public override function onSelect(isSelected:Bool):Void - { - if (isSelected) - { - preferenceText.x = 150; - preferenceText.alpha = 1.0; - } - else - { - preferenceText.alpha = 0.6; - preferenceText.x = 120; - } + // Very messy but it works + if (thyOffset == 0) + { + if (items.selectedItem == daItem) thyOffset += 150; + else + thyOffset += 120; + } + else if (items.selectedItem == daItem) + { + thyOffset += 70; + } + else + { + thyOffset += 25; + } + + daItem.x = thyOffset; + }); + } + + 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); + } + + function createPrefItemNumber(prefName:String, prefDesc:String, onChange:Float->Void, defaultValue:Float, min:Float, max:Float, step:Float, + precision:Int):Void + { + var item = new NumberPreferenceItem(145, (120 * items.length) + 30, prefName, defaultValue, min, max, step, precision, onChange); + items.addItem(prefName, item); + preferenceItems.add(item.lefthandText); } } diff --git a/source/funkin/ui/options/items/CheckboxPreferenceItem.hx b/source/funkin/ui/options/items/CheckboxPreferenceItem.hx new file mode 100644 index 000000000..88c4fb6b0 --- /dev/null +++ b/source/funkin/ui/options/items/CheckboxPreferenceItem.hx @@ -0,0 +1,49 @@ +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 new file mode 100644 index 000000000..795b6c994 --- /dev/null +++ b/source/funkin/ui/options/items/NumberPreferenceItem.hx @@ -0,0 +1,107 @@ +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; + } +} From f3e04114ebd7418bee7eeada80a57704a13a3cbb Mon Sep 17 00:00:00 2001 From: lemz Date: Tue, 25 Jun 2024 17:05:15 +0200 Subject: [PATCH 08/13] use new offsets --- source/funkin/ui/options/PreferencesMenu.hx | 23 ++++++++++--------- .../ui/options/items/NumberPreferenceItem.hx | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/source/funkin/ui/options/PreferencesMenu.hx b/source/funkin/ui/options/PreferencesMenu.hx index d03fe9073..d004a46c7 100644 --- a/source/funkin/ui/options/PreferencesMenu.hx +++ b/source/funkin/ui/options/PreferencesMenu.hx @@ -84,22 +84,23 @@ class PreferencesMenu extends Page // 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(); + // Initializing thy text width (if thou text present) + var thyTextWidth:Int = 0; + if (Std.isOfType(daItem, NumberPreferenceItem)) thyTextWidth = cast(daItem, NumberPreferenceItem).lefthandText.getWidth(); - // Very messy but it works - if (thyOffset == 0) + if (thyTextWidth != 0) { - if (items.selectedItem == daItem) thyOffset += 150; - else - thyOffset += 120; + // Magic number because of the weird offset thats being added by default + thyOffset += thyTextWidth - 75; } - else if (items.selectedItem == daItem) + + if (items.selectedItem == daItem) { - thyOffset += 70; + thyOffset += 150; } else { - thyOffset += 25; + thyOffset += 120; } daItem.x = thyOffset; @@ -110,7 +111,7 @@ class PreferencesMenu extends Page { var checkbox:CheckboxPreferenceItem = new CheckboxPreferenceItem(0, 120 * (items.length - 1 + 1), defaultValue); - items.createItem(120, (120 * items.length) + 30, prefName, AtlasFont.BOLD, function() { + items.createItem(0, (120 * items.length) + 30, prefName, AtlasFont.BOLD, function() { var value = !checkbox.currentValue; onChange(value); checkbox.currentValue = value; @@ -122,7 +123,7 @@ class PreferencesMenu extends Page function createPrefItemNumber(prefName:String, prefDesc:String, onChange:Float->Void, defaultValue:Float, min:Float, max:Float, step:Float, precision:Int):Void { - var item = new NumberPreferenceItem(145, (120 * items.length) + 30, prefName, defaultValue, min, max, step, precision, onChange); + var item = new NumberPreferenceItem(0, (120 * items.length) + 30, prefName, defaultValue, min, max, step, precision, onChange); items.addItem(prefName, item); preferenceItems.add(item.lefthandText); } diff --git a/source/funkin/ui/options/items/NumberPreferenceItem.hx b/source/funkin/ui/options/items/NumberPreferenceItem.hx index 795b6c994..eeea3112e 100644 --- a/source/funkin/ui/options/items/NumberPreferenceItem.hx +++ b/source/funkin/ui/options/items/NumberPreferenceItem.hx @@ -28,7 +28,7 @@ class NumberPreferenceItem extends TextMenuItem super(x, y, name, function() { callback(this.currentValue); }); - lefthandText = new AtlasText(20, y, formatted(defaultValue), AtlasFont.DEFAULT); + lefthandText = new AtlasText(15, y, formatted(defaultValue), AtlasFont.DEFAULT); updateHitbox(); From 927e37b35bda92888f0c0b47256884a0285cadd3 Mon Sep 17 00:00:00 2001 From: lemz Date: Tue, 2 Jul 2024 17:18:46 +0200 Subject: [PATCH 09/13] use new numberpreferenceitem --- source/funkin/ui/options/PreferencesMenu.hx | 8 +-- .../ui/options/items/NumberPreferenceItem.hx | 55 ++++++++++++++----- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/source/funkin/ui/options/PreferencesMenu.hx b/source/funkin/ui/options/PreferencesMenu.hx index d004a46c7..80dad0241 100644 --- a/source/funkin/ui/options/PreferencesMenu.hx +++ b/source/funkin/ui/options/PreferencesMenu.hx @@ -54,7 +54,7 @@ class PreferencesMenu extends Page #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); + }, null, Preferences.framerate, 60, 360, 1, 0); #end createPrefItemCheckbox('Naughtyness', 'Toggle displaying raunchy content', function(value:Bool):Void { Preferences.naughtyness = value; @@ -120,10 +120,10 @@ class PreferencesMenu extends Page preferenceItems.add(checkbox); } - function createPrefItemNumber(prefName:String, prefDesc:String, onChange:Float->Void, defaultValue:Float, min:Float, max:Float, step:Float, - precision:Int):Void + function createPrefItemNumber(prefName:String, prefDesc:String, onChange:Float->Void, ?valueFormatter:Float->String, defaultValue:Int, min:Int, max:Int, + step:Float = 0.1, precision:Int):Void { - var item = new NumberPreferenceItem(0, (120 * items.length) + 30, prefName, defaultValue, min, max, step, precision, onChange); + var item = new NumberPreferenceItem(0, (120 * items.length) + 30, prefName, defaultValue, min, max, step, precision, onChange, valueFormatter); items.addItem(prefName, item); preferenceItems.add(item.lefthandText); } diff --git a/source/funkin/ui/options/items/NumberPreferenceItem.hx b/source/funkin/ui/options/items/NumberPreferenceItem.hx index eeea3112e..f3cd3cd46 100644 --- a/source/funkin/ui/options/items/NumberPreferenceItem.hx +++ b/source/funkin/ui/options/items/NumberPreferenceItem.hx @@ -14,16 +14,35 @@ class NumberPreferenceItem extends TextMenuItem return PlayerSettings.player1.controls; } + // Widgets public var lefthandText:AtlasText; + // Constants + static final HOLD_DELAY:Float = 0.3; // seconds + static final CHANGE_RATE:Float = 0.08; // seconds + + // Constructor-initialized variables 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 var valueFormatter:NullString>; - public function new(x:Float, y:Float, name:String, defaultValue:Float, min:Float, max:Float, step:Float, precision:Int, ?callback:Float->Void):Void + // Variables + var holdDelayTimer:Float = HOLD_DELAY; // seconds + var changeRateTimer:Float = 0.0; // seconds + + /** + * @param min Minimum value (example: 0) + * @param max Maximum value (example: 100) + * @param step The value to increment/decrement by (example: 10) + * @param callback Will get called every time the user changes the setting; use this to apply/save the setting. + * @param valueFormatter Will get called every time the game needs to display the float value; use this to change how the displayed string looks + */ + public function new(x:Float, y:Float, name:String, defaultValue:Float, min:Float, max:Float, step:Float, precision:Int, ?callback:Float->Void, + ?valueFormatter:Float->String):Void { super(x, y, name, function() { callback(this.currentValue); @@ -38,14 +57,9 @@ class NumberPreferenceItem extends TextMenuItem this.step = step; this.precision = precision; this.onChangeCallback = callback; + this.valueFormatter = valueFormatter; } - 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); @@ -82,21 +96,36 @@ class NumberPreferenceItem extends TextMenuItem changeRateTimer = CHANGE_RATE; } - if (shouldDecrease) currentValue -= step; - else if (shouldIncrease) currentValue += step; - currentValue = currentValue.clamp(min, max); - if (onChangeCallback != null && (shouldIncrease || shouldDecrease)) + // Actually increasing/decreasing the value + if (shouldDecrease) { - onChangeCallback(currentValue); + var isBelowMin:Bool = currentValue - step < min; + currentValue = (currentValue - step).clamp(min, max); + if (onChangeCallback != null && !isBelowMin) onChangeCallback(currentValue); + } + else if (shouldIncrease) + { + var isAboveMax:Bool = currentValue + step > max; + currentValue = (currentValue + step).clamp(min, max); + if (onChangeCallback != null && !isAboveMax) onChangeCallback(currentValue); } } lefthandText.text = formatted(currentValue); } + /** Turns the float into a string */ function formatted(value:Float):String { - return '${toFixed(value)}'; + var float:Float = toFixed(value); + if (valueFormatter != null) + { + return valueFormatter(float); + } + else + { + return '${float}'; + } } function toFixed(value:Float):Float From 80fc0cd526d9dc22fe7c6afd141ee5c6814a3b84 Mon Sep 17 00:00:00 2001 From: lemz Date: Tue, 17 Sep 2024 00:16:27 +0200 Subject: [PATCH 10/13] Update Preferences.hx --- source/funkin/Preferences.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/funkin/Preferences.hx b/source/funkin/Preferences.hx index 7a322283d..25bc32163 100644 --- a/source/funkin/Preferences.hx +++ b/source/funkin/Preferences.hx @@ -15,7 +15,7 @@ class Preferences static function get_framerate():Int { - #if web + #if (web || CHEEMS) return 60; #else return Save?.instance?.options?.framerate ?? 60; @@ -24,7 +24,7 @@ class Preferences static function set_framerate(value:Int):Int { - #if web + #if (web || CHEEMS) return 60; #else var save:Save = Save.instance; From 224d930ae6e7b41f8c79b19f842a9175374f87c9 Mon Sep 17 00:00:00 2001 From: lemz Date: Tue, 17 Sep 2024 00:17:56 +0200 Subject: [PATCH 11/13] Update PreferencesMenu.hx --- source/funkin/ui/options/PreferencesMenu.hx | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/funkin/ui/options/PreferencesMenu.hx b/source/funkin/ui/options/PreferencesMenu.hx index ca18c45be..adbe1d356 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; import funkin.audio.FunkinSound; From 19e6029fb27ef0c52aeb632d8c0ce941cd133623 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Wed, 18 Sep 2024 03:13:10 -0400 Subject: [PATCH 12/13] Fix some compilation errors --- source/funkin/play/PlayState.hx | 1 - source/funkin/play/components/PopUpStuff.hx | 9 --------- source/funkin/ui/debug/anim/DebugBoundingState.hx | 2 +- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index a25d3b231..1c82eb6b1 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -3046,7 +3046,6 @@ class PlayState extends MusicBeatSubState GameOverSubState.reset(); PauseSubState.reset(); Countdown.reset(); - PopUpStuff.reset(); // Clear the static reference to this state. instance = null; diff --git a/source/funkin/play/components/PopUpStuff.hx b/source/funkin/play/components/PopUpStuff.hx index e5e9b4681..a02291e4e 100644 --- a/source/funkin/play/components/PopUpStuff.hx +++ b/source/funkin/play/components/PopUpStuff.hx @@ -125,13 +125,4 @@ class PopUpStuff extends FlxTypedGroup daLoop++; } } - - /** - * Reset the popup configuration to the default. - */ - public static function reset() - { - noteStyle = NoteStyleRegistry.instance.fetchDefault(); - isPixel = false; - } } diff --git a/source/funkin/ui/debug/anim/DebugBoundingState.hx b/source/funkin/ui/debug/anim/DebugBoundingState.hx index 19391f8d9..d2a27999f 100644 --- a/source/funkin/ui/debug/anim/DebugBoundingState.hx +++ b/source/funkin/ui/debug/anim/DebugBoundingState.hx @@ -77,7 +77,7 @@ class DebugBoundingState extends FlxState { // get the screen position, according to the HUD camera, temp default to FlxG.camera juuust in case? var hudMousePos:FlxPoint = FlxG.mouse.getScreenPosition(hudCam ?? FlxG.camera); - return Screen.instance.hasSolidComponentUnderPoint(hudMousePos.x, hudMousePos.y) || FlxG.mouse.overlaps(animDropDownMenu, hudCam); + return Screen.instance.hasSolidComponentUnderPoint(hudMousePos.x, hudMousePos.y); } override function create() From 7b7d5deed5e56613b5ba10f2e2ad7dfe393a1a42 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Wed, 18 Sep 2024 03:13:21 -0400 Subject: [PATCH 13/13] Tweaks to framerate preference --- source/funkin/Preferences.hx | 4 ++-- source/funkin/ui/options/PreferencesMenu.hx | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/source/funkin/Preferences.hx b/source/funkin/Preferences.hx index 1eac9f47f..648880ad4 100644 --- a/source/funkin/Preferences.hx +++ b/source/funkin/Preferences.hx @@ -15,7 +15,7 @@ class Preferences static function get_framerate():Int { - #if (web || CHEEMS) + #if web return 60; #else return Save?.instance?.options?.framerate ?? 60; @@ -24,7 +24,7 @@ class Preferences static function set_framerate(value:Int):Int { - #if (web || CHEEMS) + #if web return 60; #else var save:Save = Save.instance; diff --git a/source/funkin/ui/options/PreferencesMenu.hx b/source/funkin/ui/options/PreferencesMenu.hx index adbe1d356..fb4980762 100644 --- a/source/funkin/ui/options/PreferencesMenu.hx +++ b/source/funkin/ui/options/PreferencesMenu.hx @@ -54,11 +54,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); - }, null, Preferences.framerate, 60, 360, 1, 0); - #end createPrefItemCheckbox('Naughtyness', 'Toggle displaying raunchy content', function(value:Bool):Void { Preferences.naughtyness = value; }, Preferences.naughtyness); @@ -82,6 +77,10 @@ class PreferencesMenu extends Page createPrefItemCheckbox('Unlocked Framerate', 'Enable to unlock the framerate', function(value:Bool):Void { Preferences.unlockedFramerate = value; }, Preferences.unlockedFramerate); + #else + createPrefItemNumber('FPS', 'The maximum framerate that the game targets', function(value:Float) { + Preferences.framerate = Std.int(value); + }, null, Preferences.framerate, 30, 300, 5, 0); #end }