use new decorator syntax
This commit is contained in:
parent
2383b5f026
commit
ac5787e2fb
@ -3,6 +3,7 @@ package game.ui.console;
|
|||||||
import game.ui.text.TextFormats;
|
import game.ui.text.TextFormats;
|
||||||
import assets.Fonts;
|
import assets.Fonts;
|
||||||
import openfl.Lib;
|
import openfl.Lib;
|
||||||
|
import engine.ui.UIPane.PaneLayout;
|
||||||
import openfl.events.Event;
|
import openfl.events.Event;
|
||||||
import openfl.text.TextFieldAutoSize;
|
import openfl.text.TextFieldAutoSize;
|
||||||
import openfl.text.TextField;
|
import openfl.text.TextField;
|
||||||
@ -17,27 +18,43 @@ import engine.typedefs.console.CCmd;
|
|||||||
import game.ui.console.elements.ConsoleInput;
|
import game.ui.console.elements.ConsoleInput;
|
||||||
import engine.ui.UIPane;
|
import engine.ui.UIPane;
|
||||||
|
|
||||||
|
|
||||||
class Console extends Sprite {
|
class Console extends Sprite {
|
||||||
public var textFormat:TextFormat;
|
public var textFormat:TextFormat;
|
||||||
public var cOut:TextField;
|
public var cOut:TextField;
|
||||||
public var cIn:TextField;
|
public var cIn:TextField;
|
||||||
public var cInput:ConsoleInput;
|
public var cInput:ConsoleInput;
|
||||||
public var cAutoComp:TextField;
|
public var cAutoComp:TextField;
|
||||||
|
|
||||||
public static var consoleInstance:Console;
|
public static var consoleInstance:Console;
|
||||||
|
@:convar({
|
||||||
|
name: "mat_consolebg",
|
||||||
|
type: "CString",
|
||||||
|
value: "0x222222",
|
||||||
|
help: "console background color",
|
||||||
|
callback: () -> {
|
||||||
|
if (Console.consoleInstance != null){
|
||||||
|
Console.consoleInstance.cOut.backgroundColor = Std.parseInt(Console.consoleInstance.cvar_mat_consolebg.value);
|
||||||
|
Console.consoleInstance.cIn.backgroundColor = Std.parseInt(Console.consoleInstance.cvar_mat_consolebg.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
public static var scvar_mat_consolebg:CVar;
|
||||||
|
|
||||||
public var cvar_mat_consolebg:CVar;
|
public var cvar_mat_consolebg:CVar;
|
||||||
|
|
||||||
public var ccmd_visible:CCmd = ConVar.registerCCmd("toggleconsole", (cArgs:Array<String>) -> {
|
public var ccmd_visible:CCmd = ConVar.registerCCmd("toggleconsole", (cArgs:Array<String>) -> {
|
||||||
toggle();
|
toggle();
|
||||||
});
|
});
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
cvar_mat_consolebg = scvar_mat_consolebg;
|
||||||
consoleInstance = this;
|
consoleInstance = this;
|
||||||
|
|
||||||
|
var consolePane = new UIPane("yeeto", {width: 800, height: 600, minWidth: 400, minHeight: 300, maxWidth: 1200, maxHeight: 800});
|
||||||
|
|
||||||
var consolePane:UIPane = new UIPane("yeeto",{width:800, height:600});
|
consolePane.layout = VERTICAL;
|
||||||
|
|
||||||
this.addChild(consolePane.sprite);
|
|
||||||
consolePane.layout = VERTICAL;
|
consolePane.layout = VERTICAL;
|
||||||
|
|
||||||
// graphics.beginFill(0x555555);
|
// graphics.beginFill(0x555555);
|
||||||
@ -50,33 +67,33 @@ class Console extends Sprite{
|
|||||||
cInput.y = 600 - cInput.height - 12;
|
cInput.y = 600 - cInput.height - 12;
|
||||||
cInput.x = 12;
|
cInput.x = 12;
|
||||||
|
|
||||||
cvar_mat_consolebg = ConVar.registerCVar("mat_consolebg",CString,"0x222222",null,"console background color", ()->{
|
|
||||||
cOut.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
|
||||||
cIn.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
|
||||||
},false,false,0,0,false);
|
|
||||||
|
|
||||||
cOut = new TextField();
|
cOut = new TextField();
|
||||||
cAutoComp = new TextField();
|
cAutoComp = new TextField();
|
||||||
|
|
||||||
drawFields(cOut, cAutoComp);
|
drawFields(cOut, cAutoComp);
|
||||||
|
|
||||||
|
|
||||||
cOut.addEventListener(Event.CHANGE, onOutputTextChange);
|
cOut.addEventListener(Event.CHANGE, onOutputTextChange);
|
||||||
cIn.addEventListener(Event.CHANGE, onInputTextChange);
|
cIn.addEventListener(Event.CHANGE, onInputTextChange);
|
||||||
this.addChild(cOut);
|
this.addChild(cOut);
|
||||||
this.addChild(cInput);
|
this.addChild(cInput);
|
||||||
this.addChild(cAutoComp);
|
this.addChild(cAutoComp);
|
||||||
ConVar.registerCCmd("echo", (args:Array<String>) -> { Console.devMsg(args.join(" ").split('"').join(""));});
|
ConVar.registerCCmd("echo", (args:Array<String>) -> {
|
||||||
ConVar.registerCCmd("quit", (args:Array<String>) -> { Lib.application.window.close();});
|
Console.devMsg(args.join(" ").split('"').join(""));
|
||||||
|
});
|
||||||
|
ConVar.registerCCmd("quit", (args:Array<String>) -> {
|
||||||
|
Lib.application.window.close();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
public function drawFields(cOut:TextField, cAutoComp:TextField){
|
|
||||||
|
|
||||||
|
public function drawFields(cOut:TextField, cAutoComp:TextField) {
|
||||||
cOut.text = "hConsole Initialized\n";
|
cOut.text = "hConsole Initialized\n";
|
||||||
cOut.defaultTextFormat = TextFormats.getFormats().cOutputFmt;
|
cOut.defaultTextFormat = TextFormats.getFormats().cOutputFmt;
|
||||||
cOut.wordWrap = true;
|
cOut.wordWrap = true;
|
||||||
// cOut.autoSize = TextFieldAutoSize.LEFT;
|
// cOut.autoSize = TextFieldAutoSize.LEFT;
|
||||||
cOut.multiline = true;
|
cOut.multiline = true;
|
||||||
cOut.background = true;
|
cOut.background = true;
|
||||||
|
trace(cvar_mat_consolebg);
|
||||||
cOut.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
cOut.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
||||||
cOut.width = 800 - 24;
|
cOut.width = 800 - 24;
|
||||||
cOut.height = 600 - cIn.height - 38;
|
cOut.height = 600 - cIn.height - 38;
|
||||||
@ -99,7 +116,6 @@ class Console extends Sprite{
|
|||||||
cAutoComp.y = 600;
|
cAutoComp.y = 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function parseCmd(cmd:String, bNoHist:Bool = false) {
|
public function parseCmd(cmd:String, bNoHist:Bool = false) {
|
||||||
if (!bNoHist)
|
if (!bNoHist)
|
||||||
history.push(cmd);
|
history.push(cmd);
|
||||||
@ -117,7 +133,6 @@ class Console extends Sprite{
|
|||||||
if (endQuoteIndex == 0) {
|
if (endQuoteIndex == 0) {
|
||||||
cmd += '"';
|
cmd += '"';
|
||||||
endQuoteIndex = cmd.length;
|
endQuoteIndex = cmd.length;
|
||||||
|
|
||||||
}
|
}
|
||||||
// push quote content
|
// push quote content
|
||||||
subStrings.push(cmd.substring(startQuoteIndex, endQuoteIndex));
|
subStrings.push(cmd.substring(startQuoteIndex, endQuoteIndex));
|
||||||
@ -135,9 +150,7 @@ class Console extends Sprite{
|
|||||||
if (str != "")
|
if (str != "")
|
||||||
newSubStrings.push(str);
|
newSubStrings.push(str);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
}
|
|
||||||
else{
|
|
||||||
newSubStrings.push(subString);
|
newSubStrings.push(subString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,6 +172,7 @@ class Console extends Sprite{
|
|||||||
trace(commands);
|
trace(commands);
|
||||||
execCommands(commands);
|
execCommands(commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execCommands(commands:Array<Array<String>>) {
|
public function execCommands(commands:Array<Array<String>>) {
|
||||||
for (command in commands) {
|
for (command in commands) {
|
||||||
// Store command name, value and args
|
// Store command name, value and args
|
||||||
@ -174,8 +188,7 @@ class Console extends Sprite{
|
|||||||
// No params after the cmd, print help string
|
// No params after the cmd, print help string
|
||||||
devMsg(cv.name + " - " + cv.helpString);
|
devMsg(cv.name + " - " + cv.helpString);
|
||||||
devMsg(cv.name + " = " + cv.value);
|
devMsg(cv.name + " = " + cv.value);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
// Check for convar type and set value accordingly
|
// Check for convar type and set value accordingly
|
||||||
switch (cv.type) {
|
switch (cv.type) {
|
||||||
case CInt:
|
case CInt:
|
||||||
@ -189,8 +202,7 @@ class Console extends Sprite{
|
|||||||
cValue = cValue.toLowerCase();
|
cValue = cValue.toLowerCase();
|
||||||
if (cValue == "1" || cValue == "true") {
|
if (cValue == "1" || cValue == "true") {
|
||||||
ConVar.setCVar(cName, true);
|
ConVar.setCVar(cName, true);
|
||||||
}
|
} else if (cValue == "0" || cValue == "false") {
|
||||||
else if(cValue == "0" || cValue == "false"){
|
|
||||||
ConVar.setCVar(cName, false);
|
ConVar.setCVar(cName, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -198,9 +210,7 @@ class Console extends Sprite{
|
|||||||
ConVar.setCVar(cName, cValue);
|
ConVar.setCVar(cName, cValue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// convar is actually a command, run it.
|
// convar is actually a command, run it.
|
||||||
else if (ConVar.isCmd(cName)) {
|
else if (ConVar.isCmd(cName)) {
|
||||||
@ -212,6 +222,7 @@ class Console extends Sprite{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function submitInput() {
|
public function submitInput() {
|
||||||
cOut.appendText(">" + cInput.getText() + "\n");
|
cOut.appendText(">" + cInput.getText() + "\n");
|
||||||
parseCmd(cInput.getText());
|
parseCmd(cInput.getText());
|
||||||
@ -220,9 +231,11 @@ class Console extends Sprite{
|
|||||||
cOut.scrollV = cOut.maxScrollV;
|
cOut.scrollV = cOut.maxScrollV;
|
||||||
histSelect = -1;
|
histSelect = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onOutputTextChange(e:Event) {
|
public function onOutputTextChange(e:Event) {
|
||||||
cOut.scrollV = cOut.maxScrollV;
|
cOut.scrollV = cOut.maxScrollV;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onInputTextChange(e:Event) {
|
public function onInputTextChange(e:Event) {
|
||||||
if (cInput.getText() != "") {
|
if (cInput.getText() != "") {
|
||||||
cAutoComp.text = "";
|
cAutoComp.text = "";
|
||||||
@ -231,36 +244,35 @@ class Console extends Sprite{
|
|||||||
trace(string);
|
trace(string);
|
||||||
}
|
}
|
||||||
cAutoComp.visible = true;
|
cAutoComp.visible = true;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
cAutoComp.visible = false;
|
cAutoComp.visible = false;
|
||||||
autocompleteList = history;
|
autocompleteList = history;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function toggle():Void
|
|
||||||
{
|
public static function toggle():Void {
|
||||||
consoleInstance.visible = !consoleInstance.visible;
|
consoleInstance.visible = !consoleInstance.visible;
|
||||||
if (!consoleInstance.visible) {
|
if (!consoleInstance.visible) {
|
||||||
if (Lib.current.stage.focus == consoleInstance.cIn) {
|
if (Lib.current.stage.focus == consoleInstance.cIn) {
|
||||||
Lib.current.stage.focus = null;
|
Lib.current.stage.focus = null;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
Lib.current.stage.focus = consoleInstance.cIn;
|
Lib.current.stage.focus = consoleInstance.cIn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function devMsg(msg:String):Void
|
|
||||||
{
|
public static function devMsg(msg:String):Void {
|
||||||
consoleInstance.cOut.appendText(msg + "\n");
|
consoleInstance.cOut.appendText(msg + "\n");
|
||||||
consoleInstance.cOut.scrollV = consoleInstance.cOut.maxScrollV;
|
consoleInstance.cOut.scrollV = consoleInstance.cOut.maxScrollV;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static var history:Array<String> = [];
|
public static var history:Array<String> = [];
|
||||||
public static var histSelect:Int = -1;
|
public static var histSelect:Int = -1;
|
||||||
public static var tmpInput:String = "";
|
public static var tmpInput:String = "";
|
||||||
public static var autocompleteList:Array<String> = [];
|
public static var autocompleteList:Array<String> = [];
|
||||||
public static var compSelect:Int = -1;
|
public static var compSelect:Int = -1;
|
||||||
public static function getCompList():Array<String>
|
|
||||||
{
|
public static function getCompList():Array<String> {
|
||||||
// Split words
|
// Split words
|
||||||
var inp:Array<String> = consoleInstance.cInput.getText().split(" ");
|
var inp:Array<String> = consoleInstance.cInput.getText().split(" ");
|
||||||
var inpStripped:Array<String> = [
|
var inpStripped:Array<String> = [
|
||||||
@ -271,15 +283,15 @@ class Console extends Sprite{
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
// Stop if input is empty
|
// Stop if input is empty
|
||||||
if(inp.length == 0) return [];
|
if (inp.length == 0)
|
||||||
|
return [];
|
||||||
|
|
||||||
var cVars:Array<String> = ConVar.getCVarNames();
|
var cVars:Array<String> = ConVar.getCVarNames();
|
||||||
var cVarFiltered:Array<String> = [];
|
var cVarFiltered:Array<String> = [];
|
||||||
// Loop through convars
|
// Loop through convars
|
||||||
for (cVar in cVars) {
|
for (cVar in cVars) {
|
||||||
// if there's one word just check if the convar starts with the input string
|
// if there's one word just check if the convar starts with the input string
|
||||||
if(inp.length == 1)
|
if (inp.length == 1) {
|
||||||
{
|
|
||||||
// Check if the cvar starts with the input
|
// Check if the cvar starts with the input
|
||||||
if (cVar.indexOf(inp[0]) == 0) {
|
if (cVar.indexOf(inp[0]) == 0) {
|
||||||
cVarFiltered.push(cVar);
|
cVarFiltered.push(cVar);
|
||||||
@ -292,8 +304,7 @@ class Console extends Sprite{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Multiple words, check for cvars that contain all of them
|
// Multiple words, check for cvars that contain all of them
|
||||||
else if(inpStripped.length > 1)
|
else if (inpStripped.length > 1) {
|
||||||
{
|
|
||||||
var bWordNotPresent:Bool = false;
|
var bWordNotPresent:Bool = false;
|
||||||
for (word in inpStripped) {
|
for (word in inpStripped) {
|
||||||
if (cVar.indexOf(word) == -1) {
|
if (cVar.indexOf(word) == -1) {
|
||||||
@ -306,12 +317,13 @@ class Console extends Sprite{
|
|||||||
}
|
}
|
||||||
return cVarFiltered;
|
return cVarFiltered;
|
||||||
}
|
}
|
||||||
public static function histPrev():Void
|
|
||||||
{
|
public static function histPrev():Void {
|
||||||
// Only complete if input field is empty or scrolling through hist
|
// Only complete if input field is empty or scrolling through hist
|
||||||
if (consoleInstance.cInput.getText() == "" || histSelect != -1) {
|
if (consoleInstance.cInput.getText() == "" || histSelect != -1) {
|
||||||
// Store current input in tmpInput
|
// Store current input in tmpInput
|
||||||
if(histSelect == -1) tmpInput = consoleInstance.cInput.getText();
|
if (histSelect == -1)
|
||||||
|
tmpInput = consoleInstance.cInput.getText();
|
||||||
// Only go through history if history is not empty
|
// Only go through history if history is not empty
|
||||||
if (history.length != 0) {
|
if (history.length != 0) {
|
||||||
// Check if currently selecting a history entry
|
// Check if currently selecting a history entry
|
||||||
@ -326,8 +338,7 @@ class Console extends Sprite{
|
|||||||
if (histSelect != -1) {
|
if (histSelect != -1) {
|
||||||
// Put correct history entry in the input field
|
// Put correct history entry in the input field
|
||||||
consoleInstance.cInput.setText(history[histSelect]);
|
consoleInstance.cInput.setText(history[histSelect]);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
// Restore tmp input
|
// Restore tmp input
|
||||||
consoleInstance.cInput.setText(tmpInput);
|
consoleInstance.cInput.setText(tmpInput);
|
||||||
}
|
}
|
||||||
@ -342,27 +353,21 @@ class Console extends Sprite{
|
|||||||
else {
|
else {
|
||||||
if (autocompleteList.length == 0) {
|
if (autocompleteList.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
// Check if currently selecting an autocomplete entry
|
// Check if currently selecting an autocomplete entry
|
||||||
if(compSelect > -1){
|
if (compSelect > -1) {}
|
||||||
|
|
||||||
}
|
|
||||||
// Not currently selecting an autocomplete entry
|
// Not currently selecting an autocomplete entry
|
||||||
else{
|
else {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function histNext():Void {
|
||||||
}
|
|
||||||
}
|
|
||||||
public static function histNext():Void
|
|
||||||
{
|
|
||||||
// Only complete if input field is empty or scrolling through hist
|
// Only complete if input field is empty or scrolling through hist
|
||||||
if (consoleInstance.cIn.text == "" || histSelect != -1) {
|
if (consoleInstance.cIn.text == "" || histSelect != -1) {
|
||||||
// Store current input in tmpInput
|
// Store current input in tmpInput
|
||||||
if(histSelect == -1) tmpInput = consoleInstance.cIn.text;
|
if (histSelect == -1)
|
||||||
|
tmpInput = consoleInstance.cIn.text;
|
||||||
// Only go through history if history is not empty
|
// Only go through history if history is not empty
|
||||||
if (history.length != 0) {
|
if (history.length != 0) {
|
||||||
// Check if currently selecting a history entry
|
// Check if currently selecting a history entry
|
||||||
@ -377,8 +382,7 @@ class Console extends Sprite{
|
|||||||
if (histSelect != -1) {
|
if (histSelect != -1) {
|
||||||
// Put correct history entry in the input field
|
// Put correct history entry in the input field
|
||||||
consoleInstance.cIn.text = history[histSelect];
|
consoleInstance.cIn.text = history[histSelect];
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
// Restore tmp input
|
// Restore tmp input
|
||||||
consoleInstance.cIn.text = tmpInput;
|
consoleInstance.cIn.text = tmpInput;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user