Added autocomplete
This commit is contained in:
+1
-1
@@ -113,7 +113,7 @@
|
||||
|
||||
<!-- Fixes thing with macros -->
|
||||
<define name="HL" if="hl"/>
|
||||
<define name="SYS" if="desktop"/>
|
||||
<define name="SYS" if="desktop || hl"/>
|
||||
|
||||
<!-- Comment this out to disable Discord RPC !-->
|
||||
<define name="DISCORD_RPC" unless="web || hl || neko"/>
|
||||
|
||||
@@ -42,6 +42,7 @@ class ScriptsMacro {
|
||||
Compiler.addGlobalMetadata('haxe.xml', '@:build(hscript.UsingHandler.build())');
|
||||
Compiler.addGlobalMetadata('haxe.CallStack', '@:build(hscript.UsingHandler.build())');
|
||||
#if HL HashLinkFixer.init(); #end
|
||||
// Todo rewrite this to use if(Context.defined(""))
|
||||
}
|
||||
}
|
||||
#end
|
||||
@@ -158,7 +158,7 @@ class CharterStrumlineScreen extends UISubstateWindow {
|
||||
|
||||
class CharacterButton extends UIButton {
|
||||
public var charIcon:HealthIcon;
|
||||
public var textBox:UITextBox;
|
||||
public var textBox:UIAutoCompleteTextBox;
|
||||
public var deleteButton:UIButton;
|
||||
public var deleteIcon:FlxSprite;
|
||||
|
||||
@@ -174,7 +174,8 @@ class CharacterButton extends UIButton {
|
||||
|
||||
members.push(charIcon);
|
||||
|
||||
members.push(textBox = new UITextBox(charIcon.x + charIcon.width + 16, bHeight/2 - (32/2), char, 115));
|
||||
members.push(textBox = new UIAutoCompleteTextBox(charIcon.x + charIcon.width + 16, bHeight/2 - (32/2), char, 115));
|
||||
textBox.suggestItems = Character.getList(false);
|
||||
textBox.antialiasing = true;
|
||||
textBox.onChange = function(char:String) {
|
||||
char = Character.getIconFromCharName(char);
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package funkin.editors.ui;
|
||||
|
||||
import flixel.math.FlxPoint;
|
||||
import lime.ui.KeyModifier;
|
||||
import lime.ui.KeyCode;
|
||||
import openfl.desktop.Clipboard;
|
||||
import openfl.geom.Rectangle;
|
||||
|
||||
class UIAutoCompleteTextBox extends UITextBox {
|
||||
public var suggestionText:UIText;
|
||||
|
||||
public var suggestItems(default, set):Array<String> = [];
|
||||
var suggestIndex = 0;
|
||||
|
||||
public function new(x:Float, y:Float, text:String = "", width:Int = 320, height:Int = 32, multiline:Bool = false) {
|
||||
super(x, y, text, width, height, multiline);
|
||||
|
||||
suggestionText = new UIText(0, 0, width, "");
|
||||
suggestionText.color = 0xFF888888;
|
||||
suggestionText.visible = false;
|
||||
members.insert(members.indexOf(label), suggestionText);
|
||||
}
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
|
||||
var selected = selectable && focused;
|
||||
|
||||
suggestionText.exists = selected;
|
||||
|
||||
suggestionText.follow(label, 0, 0);
|
||||
}
|
||||
|
||||
public override function onKeyDown(e:KeyCode, modifier:KeyModifier) {
|
||||
super.onKeyDown(e, modifier);
|
||||
switch(e) {
|
||||
//case RETURN:
|
||||
// focused = false;
|
||||
case TAB:
|
||||
if(_suggestions.length > 0) {
|
||||
label.text = suggestionText.text;
|
||||
position = label.text.length;
|
||||
updateSuggestion(true);
|
||||
}
|
||||
case BACKSPACE:
|
||||
updateSuggestion(true);
|
||||
case UP:
|
||||
suggestIndex--;
|
||||
updateSuggestion(false);
|
||||
case DOWN:
|
||||
suggestIndex++;
|
||||
updateSuggestion(false);
|
||||
default:
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
|
||||
var _suggestions:Array<String> = [];
|
||||
|
||||
public function updateSuggestion(refreshSuggestions:Bool = true) {
|
||||
if(refreshSuggestions) {
|
||||
var text = label.text;
|
||||
_suggestions = [];
|
||||
if(text.length > 0) {
|
||||
for(i in suggestItems) if(!_suggestions.contains(i) && i.startsWith(text)) _suggestions.push(i);
|
||||
//for(i in suggestItems) if(!_suggestions.contains(i) && i.contains(text)) _suggestions.push(i);
|
||||
_suggestions.remove(text);
|
||||
}
|
||||
}
|
||||
|
||||
if(suggestionText.visible = (_suggestions.length != 0)) {
|
||||
if(suggestIndex >= _suggestions.length)
|
||||
suggestIndex = 0;
|
||||
suggestIndex = FlxMath.wrap(suggestIndex, 0, _suggestions.length - 1);
|
||||
|
||||
suggestionText.text = _suggestions[suggestIndex];
|
||||
}
|
||||
}
|
||||
|
||||
public override function onTextInput(text:String):Void {
|
||||
super.onTextInput(text);
|
||||
|
||||
updateSuggestion();
|
||||
}
|
||||
|
||||
public override function onTextEdit(text:String, start:Int, end:Int):Void {
|
||||
super.onTextEdit(text, start, end);
|
||||
|
||||
updateSuggestion();
|
||||
}
|
||||
|
||||
function set_suggestItems(v:Array<String>) {
|
||||
suggestItems = v;
|
||||
updateSuggestion();
|
||||
return v;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user