-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27bf88c
commit 488fc68
Showing
5 changed files
with
366 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package funkin.ui.options; | ||
|
||
// Add enums for use with `EnumPreferenceItem` here! | ||
/* Example: | ||
class MyOptionEnum | ||
{ | ||
public static inline var YuhUh = "true"; // "true" is the value's ID | ||
public static inline var NuhUh = "false"; | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package funkin.ui.options.items; | ||
|
||
import funkin.ui.TextMenuList; | ||
import funkin.ui.AtlasText; | ||
import funkin.input.Controls; | ||
import funkin.ui.options.MenuItemEnums; | ||
import haxe.EnumTools; | ||
|
||
/** | ||
* Preference item that allows the player to pick a value from an enum (list of values) | ||
*/ | ||
class EnumPreferenceItem extends TextMenuItem | ||
{ | ||
function controls():Controls | ||
{ | ||
return PlayerSettings.player1.controls; | ||
} | ||
|
||
public var lefthandText:AtlasText; | ||
|
||
public var currentValue:String; | ||
public var onChangeCallback:Null<String->Void>; | ||
public var map:Map<String, String>; | ||
public var keys:Array<String> = []; | ||
|
||
var index = 0; | ||
|
||
public function new(x:Float, y:Float, name:String, map:Map<String, String>, defaultValue:String, ?callback:String->Void) | ||
{ | ||
super(x, y, name, function() { | ||
callback(this.currentValue); | ||
}); | ||
|
||
updateHitbox(); | ||
|
||
this.map = map; | ||
this.currentValue = defaultValue; | ||
this.onChangeCallback = callback; | ||
|
||
var i:Int = 0; | ||
for (key in map.keys()) | ||
{ | ||
this.keys.push(key); | ||
if (this.currentValue == key) index = i; | ||
i += 1; | ||
} | ||
|
||
lefthandText = new AtlasText(15, y, formatted(defaultValue), AtlasFont.DEFAULT); | ||
} | ||
|
||
override function update(elapsed:Float):Void | ||
{ | ||
super.update(elapsed); | ||
|
||
// var fancyTextFancyColor:Color; | ||
if (selected) | ||
{ | ||
var shouldDecrease:Bool = controls().UI_LEFT_P; | ||
var shouldIncrease:Bool = controls().UI_RIGHT_P; | ||
|
||
if (shouldDecrease) index -= 1; | ||
if (shouldIncrease) index += 1; | ||
|
||
if (index > keys.length - 1) index = 0; | ||
if (index < 0) index = keys.length - 1; | ||
|
||
currentValue = keys[index]; | ||
if (onChangeCallback != null && (shouldIncrease || shouldDecrease)) | ||
{ | ||
onChangeCallback(currentValue); | ||
} | ||
} | ||
|
||
lefthandText.text = formatted(currentValue); | ||
} | ||
|
||
function formatted(value:String):String | ||
{ | ||
// FIXME: Can't add arrows around the text because the font doesn't support < > | ||
// var leftArrow:String = selected ? '<' : ''; | ||
// var rightArrow:String = selected ? '>' : ''; | ||
return '${map.get(value) ?? value}'; | ||
} | ||
} |
Oops, something went wrong.