Skip to content

Commit

Permalink
Update PreferencesMenu.hx
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed May 25, 2024
1 parent dd6d12d commit b75f6e5
Showing 1 changed file with 79 additions and 53 deletions.
132 changes: 79 additions & 53 deletions source/funkin/ui/options/PreferencesMenu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
Expand All @@ -124,7 +140,7 @@ class PreferencesMenu extends Page
}

var selectedPref:PreferenceItem = prefs.members[curSelected];
selectedPref.handleInput(elapsed);
selectedPref?.handleInput(elapsed);
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
function set_currentValue(value:Bool):Bool
{
super(x, y);
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;
}

frames = Paths.getSparrowAtlas('checkboxThingie');
animation.addByPrefix('static', 'Check Box unselected', 24, false);
animation.addByPrefix('checked', 'Check Box selecting animation', 24, false);
var checkBox:FlxSprite;
var preferenceText:AtlasText;

setGraphicSize(Std.int(width * 0.7));
updateHitbox();
public function new(name:String, description:String, defaultValue:Bool, onChange:Bool->Void)
{
super();

this.currentValue = defaultValue;
}
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);

override function update(elapsed:Float)
{
super.update(elapsed);
this.preferenceText = new AtlasText(120, 30, '$name', AtlasFont.BOLD);
add(this.preferenceText);

switch (animation.curAnim.name)
{
case 'static':
offset.set();
case 'checked':
offset.set(17, 70);
}
this.name = name;
this.description = description;
this.onChange = onChange;
this.currentValue = defaultValue;
}

function set_currentValue(value:Bool):Bool
public override function handleInput(elapsed:Float):Void
{
if (value)
if (PlayerSettings.player1.controls.ACCEPT)
{
animation.play('checked', true);
currentValue = !currentValue;
}
else
{
animation.play('static');
}

return currentValue = value;
}
}

0 comments on commit b75f6e5

Please sign in to comment.