-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Array option type * Prevent nulls * add display options * change xml structure
- Loading branch information
Showing
3 changed files
with
97 additions
and
3 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
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,77 @@ | ||
package funkin.options.type; | ||
|
||
import flixel.effects.FlxFlicker; | ||
|
||
class ArrayOption extends OptionType { | ||
public var selectCallback:String->Void; | ||
|
||
private var __text:Alphabet; | ||
private var __selectiontext:Alphabet; | ||
|
||
public var options:Array<Dynamic>; | ||
public var displayOptions:Array<String>; | ||
|
||
public var currentSelection:Int; | ||
|
||
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, options:Array<Dynamic>, displayOptions:Array<String>, optionName:String, ?selectCallback:String->Void = null, ?parent:Dynamic) { | ||
super(desc); | ||
this.selectCallback = selectCallback; | ||
this.displayOptions = displayOptions; | ||
this.options = options; | ||
if (parent == null) | ||
parent = Options; | ||
|
||
this.parent = parent; | ||
|
||
if(Reflect.field(parent, optionName) != null) | ||
{ | ||
if(options.indexOf(Reflect.field(parent, optionName)) != -1) | ||
this.currentSelection = options.indexOf(Reflect.field(parent, optionName)); | ||
else | ||
this.currentSelection = 0; | ||
} | ||
|
||
|
||
this.optionName = optionName; | ||
|
||
add(__text = new Alphabet(100, 20, text, true)); | ||
add(__selectiontext = new Alphabet(__text.width + 120, -30, formatTextOption(), false)); | ||
} | ||
|
||
public override function draw() { | ||
super.draw(); | ||
} | ||
|
||
public override function onChangeSelection(change:Float):Void | ||
{ | ||
if(currentSelection <= 0 && change == -1 || currentSelection >= options.length - 1 && change == 1 ) return; | ||
currentSelection += Math.round(change); | ||
__selectiontext.text = formatTextOption(); | ||
Reflect.setField(parent, optionName, options[currentSelection]); | ||
if(selectCallback != null) | ||
selectCallback(options[currentSelection]); | ||
} | ||
|
||
private function formatTextOption() { | ||
var currentOptionString = ": "; | ||
if((currentSelection > 0)) | ||
currentOptionString += "< "; | ||
else | ||
currentOptionString += " "; | ||
|
||
currentOptionString += displayOptions[currentSelection]; | ||
|
||
if(!(currentSelection >= options.length - 1)) | ||
currentOptionString += " >"; | ||
|
||
return currentOptionString; | ||
} | ||
} |