Number type options + Framerate option (#180)

This commit is contained in:
bctix
2023-07-10 15:12:42 +02:00
committed by GitHub
parent 3daab89d13
commit d66c7749e0
6 changed files with 92 additions and 2 deletions
+1
View File
@@ -2,6 +2,7 @@
<!-- TEMPLATE FOR CUSTOM OPTIONS!!! -->
<menu name="Mod Options" desc="Modify mod options here">
<checkbox id="checkboxExample" name="Checkbox example" />
<number id="numberExample" name="Number example" min="0" max="10" change="1"/>
<choice id="choiceExample" name="Choice Example">
<value name="Disabled" value="disabled" />
<value name="This Only" value="thisonly" />
+10
View File
@@ -1,5 +1,6 @@
package funkin.options;
import funkin.backend.system.framerate.Framerate;
import funkin.options.type.Checkbox;
import haxe.xml.Access;
import flixel.tweens.FlxTween;
@@ -48,6 +49,8 @@ class OptionsMenu extends TreeMenu {
bg.antialiasing = true;
add(bg);
Framerate.offset.y = 60;
main = new OptionsScreen("Options", "Select a category to continue.", [for(o in mainOptions) new TextOption(o.name, o.desc, function() {
if (o.substate != null) {
persistentUpdate = false;
@@ -111,6 +114,13 @@ class OptionsMenu extends TreeMenu {
continue;
}
options.push(new Checkbox(name, desc, node.att.id, FlxG.save.data));
case "number":
if (!node.has.id) {
Logs.trace("A number option requires an \"id\" for option saving.", WARNING);
continue;
}
options.push(new NumOption(name, desc, Std.parseFloat(node.att.min), Std.parseFloat(node.att.max), Std.parseFloat(node.att.change), node.att.id, null, FlxG.save.data));
case "menu":
options.push(new TextOption(name + " >", desc, function() {
optionsTree.add(new OptionsScreen(name, desc, parseOptionsFromXML(node)));
+4
View File
@@ -45,6 +45,10 @@ class OptionsScreen extends FlxTypedSpriteGroup<OptionType> {
members[curSelected].selected = true;
if (controls.ACCEPT || FlxG.mouse.justReleased)
members[curSelected].onSelect();
if (controls.LEFT_P)
members[curSelected].onChangeSelection(-1);
if (controls.RIGHT_P)
members[curSelected].onChangeSelection(1);
}
if (controls.BACK || FlxG.mouse.justReleasedRight)
close();
@@ -3,6 +3,14 @@ package funkin.options.categories;
class AppearanceOptions extends OptionsScreen {
public override function new() {
super("Appearance", "Change Appearance options such as Flashing menus...");
add(new NumOption(
"Framerate",
"Pretty self explanitory isn't it?",
30, // minimum
240, // maximum
10, // change
"framerate", // save name or smth
__changeFPS)); // callback
add(new Checkbox(
"Antialiasing",
"If unchecked, will disable antialiasing on every sprite. Can boost performances at the cost of sharper, more pixely sprites",
@@ -32,4 +40,13 @@ class AppearanceOptions extends OptionsScreen {
"If checked, switching windows will pause the game",
"autoPause"));
}
private function __changeFPS(change:Float)
{
// if statement cause of the flixel warning
if(FlxG.updateFramerate < Std.int(change))
FlxG.drawFramerate = FlxG.updateFramerate = Std.int(change);
else
FlxG.updateFramerate = FlxG.drawFramerate = Std.int(change);
}
}
+58
View File
@@ -0,0 +1,58 @@
package funkin.options.type;
import flixel.effects.FlxFlicker;
class NumOption extends OptionType {
public var selectCallback:Float->Void;
private var __text:Alphabet;
private var __number:Alphabet;
public var min:Float;
public var max:Float;
public var currentSelection:Float;
public var changeVal:Float;
var optionName:String;
public var parent:Dynamic;
public var text(get, set):String;
private function get_text() {return __text.text;}
private function set_text(v:String) {return __text.text = v;}
public function new(text:String, desc:String, min:Float, max:Float, changeVal:Float, optionName:String, ?selectCallback:Float->Void = null, ?parent:Dynamic) {
super(desc);
this.selectCallback = selectCallback;
this.min = min;
this.max = max;
if (parent == null)
parent = Options;
this.parent = parent;
if(Reflect.field(parent, optionName) != null)
this.currentSelection = Reflect.field(parent, optionName);
this.changeVal = changeVal;
this.optionName = optionName;
add(__text = new Alphabet(100, 20, text, true));
add(__number = new Alphabet(__text.width + 120, -30, ': $currentSelection', false));
}
public override function draw() {
super.draw();
}
public override function onChangeSelection(change:Float):Void
{
if(currentSelection <= min && change == -1 || currentSelection >= max && change == 1 ) return;
currentSelection += change*changeVal;
__number.text = ': $currentSelection';
Reflect.setField(parent, optionName, currentSelection);
if(selectCallback != null)
selectCallback(currentSelection);
}
}
+2 -2
View File
@@ -16,9 +16,9 @@ class OptionType extends FlxSpriteGroup {
private function get_controls() {return PlayerSettings.solo.controls;}
public function onSelect() {
public function onSelect() {}
}
public function onChangeSelection(change:Float) {}
public override function update(elapsed:Float) {
super.update(elapsed);