package game.ui; import openfl.events.Event; import openfl.text.TextFieldAutoSize; import openfl.text.TextField; import openfl.display.Sprite; import openfl.Assets; import openfl.text.TextFormat; import openfl.text.TextFieldType; class Console extends Sprite{ public var textFormat:TextFormat; public var cOut:TextField; public var cIn:TextField; public static var consoleIndex:Console; public function new(){ super(); consoleIndex = this; graphics.beginFill(0x111111); graphics.drawRect(0,0,800,600); textFormat = new TextFormat(Assets.getFont("fonts/Terminus.ttf").fontName, 24, 0x00ff00); cIn = new TextField(); cIn.type = TextFieldType.INPUT; cIn.text = "b"; cIn.multiline = false; //cIn.autoSize = TextFieldAutoSize.LEFT; cIn.width = 800-24; cIn.height = 32; cIn.background = true; cIn.backgroundColor = 0x000000; cIn.selectable = true; cIn.setTextFormat(textFormat); cIn.y = 600-cIn.height-12; cIn.x = 12; cOut = new TextField(); cOut.text = "hConsole Initialized\n"; cOut.setTextFormat(textFormat); //cOut.autoSize = TextFieldAutoSize.LEFT; cOut.multiline = true; cOut.background = true; cOut.backgroundColor = 0x000000; cOut.width = 800 - 24; cOut.height = 600 - cIn.height - 38; cOut.y = 12; cOut.x = 12; cOut.addEventListener(Event.CHANGE, onOutputTextChange); //cOut.addEventListener() this.addChild(cOut); this.addChild(cIn); } public function parseCmd(cmd:String){ var parts:Array = cmd.split(" "); } public function submitInput(){ parseCmd(cIn.text); cOut.appendText(">"+cIn.text+"\n"); cIn.text = ""; cOut.scrollV = cOut.maxScrollV; } public function onOutputTextChange(e:Event){ cOut.scrollV = cOut.maxScrollV; } public function devMsg(msg:String):Void { cOut.appendText(msg+"\n"); } }