refactoring console ui
This commit is contained in:
parent
be0c83e766
commit
7fa7ece574
@ -8,23 +8,22 @@
|
|||||||
<!-- output -->
|
<!-- output -->
|
||||||
<app main="Main" file="hgame" path="bin" />
|
<app main="Main" file="hgame" path="bin" />
|
||||||
|
|
||||||
<!-- <window background="#FFFFFF" fps="60" /> -->
|
<window background="#FFFFFF" fps="60" />
|
||||||
<window background="null" color-depth="32" fps="60" />
|
<!--<window width="320" height="480" unless="mobile" />-->
|
||||||
<window width="320" height="480" unless="mobile" />
|
<window width="1280" height="960" unless="mobile || html5" />
|
||||||
<window orientation="landscape" vsync="false" antialiasing="0" if="cpp" />
|
<window orientation="landscape" vsync="false" antialiasing="0" if="cpp" />
|
||||||
|
|
||||||
<!-- classpath, haxe libs -->
|
<!-- classpath, haxe libs -->
|
||||||
<source path="src" />
|
<source path="src" />
|
||||||
<assets path="res/textures" rename="textures" />
|
<assets path="./res/textures" rename="textures" />
|
||||||
<assets path="res/fonts" rename="fonts" />
|
<assets path="./res/fonts" rename="fonts" />
|
||||||
<assets path="res/data" rename="data"/>
|
<assets path="./res/data" rename="data"/>
|
||||||
<haxelib name="openfl" />
|
<haxelib name="openfl" />
|
||||||
<haxelib name="actuate" />
|
<haxelib name="actuate" />
|
||||||
<!-- assets -->
|
<!-- assets -->
|
||||||
<icon path="assets/openfl.svg" />
|
<!--<icon path="assets/openfl.svg" /> -->
|
||||||
<!-- <assets path="assets/img" rename="img" /> -->
|
<!-- <assets path="assets/img" rename="img" /> -->
|
||||||
|
|
||||||
<!-- optimize output
|
<!-- optimize output
|
||||||
<haxeflag name="-dce full" /> -->
|
<haxeflag name="-dce full" /> -->
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
9
hGameTest/res/assets.manifest.json
Normal file
9
hGameTest/res/assets.manifest.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"datascheme": "assetmanifest",
|
||||||
|
"version": "1.0",
|
||||||
|
"type": "manifestmanifest",
|
||||||
|
"files": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,17 +1,25 @@
|
|||||||
import openfl.display.Sprite;
|
import openfl.display.Sprite;
|
||||||
import openfl.display.Stage;
|
import openfl.display.Stage;
|
||||||
import openfl.events.Event;
|
import openfl.events.Event;
|
||||||
|
import assets.Scanner;
|
||||||
|
import openfl.utils.AssetManifest;
|
||||||
|
|
||||||
|
|
||||||
class App extends Sprite {
|
class App extends Sprite {
|
||||||
|
|
||||||
|
|
||||||
public function new () {
|
public function new () {
|
||||||
|
|
||||||
super ();
|
super ();
|
||||||
var game:Game = new Game(stage);
|
Scanner.scanTextureDir();
|
||||||
game.onInit();
|
trace("k");
|
||||||
stage.addEventListener(Event.ENTER_FRAME, game.onEnterFrame);
|
#if buildhxml
|
||||||
|
var manifest = new AssetManifest ();
|
||||||
|
|
||||||
|
|
||||||
|
#end
|
||||||
|
//var game:Game = new Game(stage);
|
||||||
|
//game.onInit();
|
||||||
|
//stage.addEventListener(Event.ENTER_FRAME, game.onEnterFrame);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import assets.Scanner;
|
||||||
import game.video.Mode;
|
import game.video.Mode;
|
||||||
import openfl.events.KeyboardEvent;
|
import openfl.events.KeyboardEvent;
|
||||||
import openfl.display.Sprite;
|
import openfl.display.Sprite;
|
||||||
@ -16,16 +17,21 @@ class Main extends Sprite {
|
|||||||
}
|
}
|
||||||
private function onInit(e:Event)
|
private function onInit(e:Event)
|
||||||
{
|
{
|
||||||
|
//Scanner.scanTextureDir();
|
||||||
|
trace("heyy");
|
||||||
stage.frameRate = 1000;
|
stage.frameRate = 1000;
|
||||||
var game:Game = new Game(stage);
|
var game:Game = new Game(stage);
|
||||||
|
trace("kokk");
|
||||||
stage.addEventListener(Event.ENTER_FRAME, game.onEnterFrame);
|
stage.addEventListener(Event.ENTER_FRAME, game.onEnterFrame);
|
||||||
stage.addEventListener(KeyboardEvent.KEY_DOWN,Input.onKeyIsDown);
|
stage.addEventListener(KeyboardEvent.KEY_DOWN,Input.onKeyIsDown);
|
||||||
stage.addEventListener(KeyboardEvent.KEY_UP,Input.onKeyIsUp);
|
stage.addEventListener(KeyboardEvent.KEY_UP,Input.onKeyIsUp);
|
||||||
stage.addEventListener(Event.RESIZE,onResize);
|
stage.addEventListener(Event.RESIZE,onResize);
|
||||||
game.onInit();
|
game.onInit();
|
||||||
Mode.setVideoMode(800, 600);
|
|
||||||
|
//Mode.setVideoMode(1280, 960);
|
||||||
}
|
}
|
||||||
private function onResize (event:Event):Void {
|
private function onResize (event:Event):Void {
|
||||||
|
trace("yeet");
|
||||||
//Here we can do shit with window scaling
|
//Here we can do shit with window scaling
|
||||||
//stage.stageWidth;
|
//stage.stageWidth;
|
||||||
//stage.stageHeight;
|
//stage.stageHeight;
|
||||||
|
|||||||
8
hGameTest/src/assets/Fonts.hx
Normal file
8
hGameTest/src/assets/Fonts.hx
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package assets;
|
||||||
|
|
||||||
|
import openfl.text.Font;
|
||||||
|
import openfl.Assets;
|
||||||
|
|
||||||
|
class Fonts{
|
||||||
|
//public static var terminus:Font = Assets.getFont("fonts/Terminus.ttf");
|
||||||
|
}
|
||||||
@ -31,7 +31,7 @@ class HTex{
|
|||||||
var tileNames:Array<String> = td.tilesetGeneric.tiles;
|
var tileNames:Array<String> = td.tilesetGeneric.tiles;
|
||||||
var atlas:TextureAtlas = new TextureAtlas(Assets.getBitmapData(baseTexturePath),width,height);
|
var atlas:TextureAtlas = new TextureAtlas(Assets.getBitmapData(baseTexturePath),width,height);
|
||||||
var tileSetGeneric = new TilesetGeneric(td.texName, atlas, tileNames);
|
var tileSetGeneric = new TilesetGeneric(td.texName, atlas, tileNames);
|
||||||
trace(tileSetGeneric);
|
//trace(tileSetGeneric);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,28 +1,14 @@
|
|||||||
package game;
|
package game;
|
||||||
|
|
||||||
import engine.typedefs.CCmd;
|
|
||||||
import engine.enums.CVarFlag;
|
|
||||||
import engine.enums.CVarType;
|
|
||||||
import engine.typedefs.CVar;
|
import engine.typedefs.CVar;
|
||||||
import openfl.display.DisplayObject;
|
|
||||||
import game.ui.Console;
|
|
||||||
import game.entities.Player;
|
import game.entities.Player;
|
||||||
import assets.tilesets.TilesetGeneric;
|
|
||||||
import assets.tilesets.Tileset;
|
|
||||||
import openfl.display.Bitmap;
|
|
||||||
import openfl.display.Stage;
|
import openfl.display.Stage;
|
||||||
import openfl.display.Bitmap;
|
|
||||||
import openfl.display.BitmapData;
|
|
||||||
import openfl.display.Sprite;
|
import openfl.display.Sprite;
|
||||||
import openfl.ui.Keyboard;
|
|
||||||
import openfl.events.Event;
|
import openfl.events.Event;
|
||||||
import openfl.Assets;
|
|
||||||
import openfl.display.DisplayObject;
|
|
||||||
import assets.Scanner;
|
import assets.Scanner;
|
||||||
import assets.HTex;
|
import assets.HTex;
|
||||||
import openfl.Lib;
|
|
||||||
import openfl.display.StageDisplayState;
|
|
||||||
import game.ui.ConVar;
|
import game.ui.ConVar;
|
||||||
|
import game.ui.console.Console;
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
@ -31,21 +17,26 @@ class Game
|
|||||||
public var uiLayer:Sprite;
|
public var uiLayer:Sprite;
|
||||||
public function new(_stage:Stage){
|
public function new(_stage:Stage){
|
||||||
stage = _stage;
|
stage = _stage;
|
||||||
|
/*
|
||||||
Scanner.scanTextureDir();
|
Scanner.scanTextureDir();
|
||||||
for(tex in Scanner.textures){
|
for(tex in Scanner.textures){
|
||||||
HTex.createTextureObjectFromJSON(tex);
|
HTex.createTextureObjectFromJSON(tex);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
gameLayer = new Sprite();
|
gameLayer = new Sprite();
|
||||||
uiLayer = new Sprite();
|
uiLayer = new Sprite();
|
||||||
|
|
||||||
|
|
||||||
trace("wattafak");
|
trace("wattafak");
|
||||||
}
|
}
|
||||||
public var player:Player;
|
public var player:Player;
|
||||||
public var console:Console = new game.ui.Console();
|
public var console:Console = new Console();
|
||||||
|
public function loadData():Void
|
||||||
|
{
|
||||||
|
new game.ui.text.TextFormats();
|
||||||
|
|
||||||
|
}
|
||||||
public function onInit():Void
|
public function onInit():Void
|
||||||
{
|
{
|
||||||
|
|
||||||
gameLayer = new Sprite();
|
gameLayer = new Sprite();
|
||||||
uiLayer = new Sprite();
|
uiLayer = new Sprite();
|
||||||
stage.addChild(gameLayer);
|
stage.addChild(gameLayer);
|
||||||
@ -53,10 +44,10 @@ class Game
|
|||||||
//player.graphics.lineStyle(2,0xFF0000);
|
//player.graphics.lineStyle(2,0xFF0000);
|
||||||
//player.graphics.drawRect(0,0,16,16);
|
//player.graphics.drawRect(0,0,16,16);
|
||||||
// var bitmapData:BitmapData = Assets.getBitmapData("textures/sprites/character.png");
|
// var bitmapData:BitmapData = Assets.getBitmapData("textures/sprites/character.png");
|
||||||
player = new Player();
|
//player = new Player();
|
||||||
gameLayer.addChild(player.sprite);
|
//gameLayer.addChild(player.sprite);
|
||||||
uiLayer.addChild(console);
|
uiLayer.addChild(console);
|
||||||
var cvar:CVar = ConVar.registerCVar("cl_kankerlow", CInt, 10, FCVAR_ARCHIVE, "is de speler een kankerlow?",null,false,false,0,0,false);
|
var cvar_cl_kankerlow:CVar = ConVar.registerCVar("cl_kankerlow", CInt, 10, FCVAR_ARCHIVE, "is de speler een kankerlow?",null,false,false,0,0,false);
|
||||||
//var sheet:SpriteSheet = new SpriteSheet(sheetData);
|
//var sheet:SpriteSheet = new SpriteSheet(sheetData);
|
||||||
//var playerBitmap:Bitmap = new Bitmap(Tileset.tilesetMap["testsheet"].tileMap["testTile5"]);
|
//var playerBitmap:Bitmap = new Bitmap(Tileset.tilesetMap["testsheet"].tileMap["testTile5"]);
|
||||||
//var someotherbitmap:Bitmap = new Bitmap(Tileset.tilesetMap["testsheet"].tileMap["testTile3"]);
|
//var someotherbitmap:Bitmap = new Bitmap(Tileset.tilesetMap["testsheet"].tileMap["testTile3"]);
|
||||||
@ -68,8 +59,5 @@ class Game
|
|||||||
public function onEnterFrame(e:Event):Void
|
public function onEnterFrame(e:Event):Void
|
||||||
{
|
{
|
||||||
Input.onEnterFrame();
|
Input.onEnterFrame();
|
||||||
|
|
||||||
//player.x++;
|
|
||||||
//player.y++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,7 +2,7 @@ package game;
|
|||||||
|
|
||||||
import engine.enums.CVarFlag;
|
import engine.enums.CVarFlag;
|
||||||
import engine.typedefs.CCmd;
|
import engine.typedefs.CCmd;
|
||||||
import game.ui.Console;
|
import game.ui.console.Console;
|
||||||
import game.video.Mode;
|
import game.video.Mode;
|
||||||
import openfl.events.KeyboardEvent;
|
import openfl.events.KeyboardEvent;
|
||||||
import openfl.ui.Keyboard in Kb;
|
import openfl.ui.Keyboard in Kb;
|
||||||
@ -13,30 +13,13 @@ import game.ui.ConVar;
|
|||||||
|
|
||||||
|
|
||||||
class Input{
|
class Input{
|
||||||
public static var keys:Array<Bool> = [];
|
public static var keys:Map<Int,Bool> = [];
|
||||||
public static var keysLast:Array<Bool> = [];
|
public static var keysLast:Map<Int,Bool> = [];
|
||||||
public static var bindMap:Map<String, String> = [];
|
public static var bindMap:Map<String, String> = [];
|
||||||
//public static var bind:CVar = Convar.registerCVar("bind",CVarType.cCmd, null, ()->{
|
//public static var bind:CVar = Convar.registerCVar("bind",CVarType.cCmd, null, ()->{
|
||||||
//
|
//
|
||||||
//});
|
//});
|
||||||
public static var debugKeys = ConVar.registerCVar("cl_debuginput", CInt, 0, null, "print debug messages related to input to console", null, false, true, 0, 0, false);
|
public static var cv_debugKeys = ConVar.registerCVar("cl_debuginput", CInt, 0, null, "print debug messages related to input to console", null, false, true, 0, 0, false);
|
||||||
public static var keyCodeMap:Map<String, Int> = [
|
|
||||||
"HOME" => Kb.HOME, "END" => Kb.END, "INSERT" => Kb.INSERT, "DELETE" => Kb.DELETE, "PGUP" => Kb.PAGE_UP, "PGDN" => Kb.PAGE_DOWN,
|
|
||||||
"ESC" => Kb.ESCAPE, "F1" => Kb.F1, "F2" => Kb.F2, "F3" => Kb.F3, "F4" => Kb.F4, "F5" => Kb.F5,
|
|
||||||
"F6" => Kb.F6, "F7" => Kb.F7, "F8" => Kb.F8, "F9" => Kb.F9, "F10" => Kb.F10, "F11" => Kb.F11,
|
|
||||||
"F12" => Kb.F12,
|
|
||||||
"~" => Kb.BACKQUOTE, "1" => Kb.NUMBER_1, "2" => Kb.NUMBER_2, "3" => Kb.NUMBER_3, "4" => Kb.NUMBER_4, "5" => Kb.NUMBER_5,
|
|
||||||
"6" => Kb.NUMBER_6, "7" => Kb.NUMBER_7, "8" => Kb.NUMBER_8, "9" => Kb.NUMBER_9, "0" => Kb.NUMBER_0,
|
|
||||||
"TAB" => Kb.TAB, "Q" => Kb.Q, "W" => Kb.W, "E" => Kb.E, "R" => Kb.R, "T" => Kb.T,
|
|
||||||
"Y" => Kb.Y, "U" => Kb.U, "I" => Kb.I, "O" => Kb.O, "P" => Kb.P, "[" => Kb.LEFTBRACKET,
|
|
||||||
"]" => Kb.RIGHTBRACKET, "\\" => Kb.BACKSLASH,
|
|
||||||
"CAPSLOCK" => Kb.CAPS_LOCK, "A" => Kb.A, "S" => Kb.S, "D" => Kb.D, "F" => Kb.F, "G" => Kb.G,
|
|
||||||
"H" => Kb.H, "J" => Kb.J, "K" => Kb.K, "L" => Kb.L, "SEMICOLON" => Kb.SEMICOLON, "'" => Kb.QUOTE,
|
|
||||||
"ENTER" => Kb.ENTER,
|
|
||||||
"SHIFT" => Kb.SHIFT, "Z" => Kb.Z, "X" => Kb.X, "C" => Kb.C, "V" => Kb.V, "B" => Kb.B,
|
|
||||||
"N" => Kb.N, "M" => Kb.M, "COMMA" => Kb.COMMA, "PERIOD" => Kb.PERIOD, "/" => Kb.SLASH ,
|
|
||||||
"CTRL" => Kb.CONTROL, "ALT" => Kb.ALTERNATE
|
|
||||||
];
|
|
||||||
public static var keyNameMap:Map<Int, String> = [
|
public static var keyNameMap:Map<Int, String> = [
|
||||||
Kb.HOME => "HOME", Kb.END => "END", Kb.INSERT => "INSERT", Kb.DELETE => "DELETE", Kb.PAGE_UP => "PGUP", Kb.PAGE_DOWN => "PGDN",
|
Kb.HOME => "HOME", Kb.END => "END", Kb.INSERT => "INSERT", Kb.DELETE => "DELETE", Kb.PAGE_UP => "PGUP", Kb.PAGE_DOWN => "PGDN",
|
||||||
Kb.ESCAPE => "ESC", Kb.F1 => "F1", Kb.F2 => "F2", Kb.F3 => "F3", Kb.F4 => "F4", Kb.F5 => "F5",
|
Kb.ESCAPE => "ESC", Kb.F1 => "F1", Kb.F2 => "F2", Kb.F3 => "F3", Kb.F4 => "F4", Kb.F5 => "F5",
|
||||||
@ -52,14 +35,28 @@ class Input{
|
|||||||
Kb.M => "M", Kb.COMMA => "COMMA",Kb.PERIOD => "PERIOD", Kb.SLASH => "/" ,
|
Kb.M => "M", Kb.COMMA => "COMMA",Kb.PERIOD => "PERIOD", Kb.SLASH => "/" ,
|
||||||
Kb.CONTROL => "CTRL", Kb.ALTERNATE =>"ALT"
|
Kb.CONTROL => "CTRL", Kb.ALTERNATE =>"ALT"
|
||||||
];
|
];
|
||||||
|
public static var keyCodeMap:Map<String, Int> = [
|
||||||
|
for(key in keyNameMap.keys()){
|
||||||
|
keyNameMap[key] => key;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
public static var cCmdGetKeyCode = ConVar.registerCCmd("getkey", (cArgs:Array<String>) -> {
|
||||||
|
var keycode:Int = keyCodeMap[cArgs[0]];
|
||||||
|
if(cArgs != null)
|
||||||
|
Console.devMsg(Std.string(keycode));
|
||||||
|
});
|
||||||
public static function onKeyIsDown(e:KeyboardEvent){
|
public static function onKeyIsDown(e:KeyboardEvent){
|
||||||
keys[e.charCode] = true;
|
if(!keys[e.keyCode]){
|
||||||
var key:String = keyNameMap[e.charCode];
|
if(cv_debugKeys.value > 0)
|
||||||
if(debugKeys.value > 0) Console.devMsg(""+key);
|
Console.devMsg("triggered key: "+keyNameMap[e.keyCode]);
|
||||||
|
}
|
||||||
|
keys[e.keyCode] = true;
|
||||||
|
var key:String = keyNameMap[e.keyCode];
|
||||||
|
if(cv_debugKeys.value > 0) Console.devMsg(""+key);
|
||||||
|
|
||||||
}
|
}
|
||||||
public static function onKeyIsUp(e:KeyboardEvent){
|
public static function onKeyIsUp(e:KeyboardEvent){
|
||||||
keys[e.charCode] = false;
|
keys[e.keyCode] = false;
|
||||||
}
|
}
|
||||||
public static function resolveKeyName(key:Int):String
|
public static function resolveKeyName(key:Int):String
|
||||||
{
|
{
|
||||||
@ -85,27 +82,24 @@ class Input{
|
|||||||
{
|
{
|
||||||
if( keys[Kb.BACKQUOTE]){
|
if( keys[Kb.BACKQUOTE]){
|
||||||
//Console.toggle();
|
//Console.toggle();
|
||||||
if(debugKeys.value > 0) Console.devMsg("toggle console");
|
if(cv_debugKeys.value > 0) Console.devMsg("toggle console");
|
||||||
|
|
||||||
}
|
}
|
||||||
if( keys[Kb.ALTERNATE] && keys[Kb.ENTER] && !keysLast[Kb.ALTERNATE] && !keysLast[Kb.ENTER] ){
|
if( keys[Kb.ALTERNATE] && keys[Kb.ENTER] && !keysLast[Kb.ALTERNATE] && !keysLast[Kb.ENTER] ){
|
||||||
Mode.switchFsMode();
|
Mode.switchFsMode();
|
||||||
}
|
}
|
||||||
|
// Console Input field is in focus
|
||||||
if ( keys[Kb.ENTER] && !keysLast[Kb.ENTER] && !keysLast[Kb.ALTERNATE]){
|
if(Lib.current.stage.focus == Console.consoleInstance.cIn){
|
||||||
if(Lib.current.stage.focus == Console.consoleInstance.cIn){
|
if ( keys[Kb.ENTER] && !keysLast[Kb.ENTER] && !keysLast[Kb.ALTERNATE]){
|
||||||
Console.consoleInstance.submitInput();
|
Console.consoleInstance.submitInput();
|
||||||
}
|
}
|
||||||
|
if (keys[Kb.UP] && !keysLast[Kb.UP]){
|
||||||
|
Console.histPrev();
|
||||||
|
}
|
||||||
|
if (keys[Kb.DOWN] && !keysLast[Kb.DOWN]){
|
||||||
|
Console.histNext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
keysLast = keys.copy();
|
keysLast = keys.copy();
|
||||||
//Console.devMsg("key array length:"+keys.length);
|
|
||||||
//for(i in 0...keys.length-1){
|
|
||||||
// keysLast[i] = keys[i];
|
|
||||||
//}
|
|
||||||
//trace("enter pressed: " + keys[Kb.ENTER] + "enter pressed last: " + keysLast[Kb.ENTER]);
|
|
||||||
//trace(keysLast[Kb.ENTER]);
|
|
||||||
//keysLast = keys;
|
|
||||||
//trace(keys[Kb.ENTER]);
|
|
||||||
//trace(keysLast[Kb.ENTER]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5,6 +5,7 @@ import engine.typedefs.CVar;
|
|||||||
import engine.typedefs.CCmd;
|
import engine.typedefs.CCmd;
|
||||||
import engine.enums.CVarType;
|
import engine.enums.CVarType;
|
||||||
import engine.enums.CVarFlag;
|
import engine.enums.CVarFlag;
|
||||||
|
import game.ui.console.Console;
|
||||||
|
|
||||||
|
|
||||||
class ConVar{
|
class ConVar{
|
||||||
@ -70,7 +71,7 @@ class ConVar{
|
|||||||
if(cv.bMax && _value > cv.fMax) _value = cv.fMax;
|
if(cv.bMax && _value > cv.fMax) _value = cv.fMax;
|
||||||
if(cv.bMin && _value < cv.fMin) _value = cv.fMin;
|
if(cv.bMin && _value < cv.fMin) _value = cv.fMin;
|
||||||
case CBool:
|
case CBool:
|
||||||
if(Std.is(_value, String)){
|
if(Std.isOfType(_value, String)){
|
||||||
var v:String = _value;
|
var v:String = _value;
|
||||||
_value = v.toLowerCase();
|
_value = v.toLowerCase();
|
||||||
if(_value == "true" || _value == "1"){
|
if(_value == "true" || _value == "1"){
|
||||||
@ -80,7 +81,7 @@ class ConVar{
|
|||||||
_value = false;
|
_value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(Std.is(_value, Int) || Std.is(_value, Float)){
|
else if(Std.isOfType(_value, Int) || Std.isOfType(_value, Float)){
|
||||||
if(_value %2 == 0){
|
if(_value %2 == 0){
|
||||||
_value = false;
|
_value = false;
|
||||||
}
|
}
|
||||||
@ -88,7 +89,7 @@ class ConVar{
|
|||||||
_value = true;
|
_value = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(Std.is(_value, Bool)){
|
else if(Std.isOfType(_value, Bool)){
|
||||||
//do nothing
|
//do nothing
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@ -99,6 +100,7 @@ class ConVar{
|
|||||||
|
|
||||||
}
|
}
|
||||||
cv.value = _value;
|
cv.value = _value;
|
||||||
|
cv.callback();
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@ -118,7 +120,8 @@ class ConVar{
|
|||||||
CCmdMap[_name].callback(_args);
|
CCmdMap[_name].callback(_args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static var cmdList:CCmd = ConVar.registerCCmd("list", (cArgs:Array<String>)->{
|
public static inline function getCVarNames():Array<String>
|
||||||
|
{
|
||||||
var keys:Array<String> = [
|
var keys:Array<String> = [
|
||||||
for(iterator in [CCmdMap.keys(),CVarMap.keys()]){
|
for(iterator in [CCmdMap.keys(),CVarMap.keys()]){
|
||||||
for(key in iterator){
|
for(key in iterator){
|
||||||
@ -138,6 +141,10 @@ class ConVar{
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
public static var cmdList:CCmd = ConVar.registerCCmd("list", (cArgs:Array<String>)->{
|
||||||
|
var keys:Array<String> = getCVarNames();
|
||||||
for(key in keys){
|
for(key in keys){
|
||||||
if(CVarMap[key] != null){
|
if(CVarMap[key] != null){
|
||||||
Console.devMsg(key+" "+CVarMap[key].value);
|
Console.devMsg(key+" "+CVarMap[key].value);
|
||||||
|
|||||||
@ -1,188 +0,0 @@
|
|||||||
package game.ui;
|
|
||||||
|
|
||||||
import openfl.Lib;
|
|
||||||
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;
|
|
||||||
import engine.typedefs.CVar;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Console extends Sprite{
|
|
||||||
|
|
||||||
public var textFormat:TextFormat;
|
|
||||||
public var cOut:TextField;
|
|
||||||
public var cIn:TextField;
|
|
||||||
public static var consoleInstance:Console;
|
|
||||||
public function new(){
|
|
||||||
super();
|
|
||||||
|
|
||||||
consoleInstance = 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 = '';
|
|
||||||
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.wordWrap = true;
|
|
||||||
//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);
|
|
||||||
//ConVar.registerCVar("echo", CVarType.CCmd, null, devMsg())
|
|
||||||
ConVar.registerCCmd("echo", (args:Array<String>) -> { Console.devMsg(args.join(" ").split('"').join(""));});
|
|
||||||
ConVar.registerCCmd("quit", (args:Array<String>) -> { Lib.application.window.close();});
|
|
||||||
}
|
|
||||||
public function parseCmd(cmd:String){
|
|
||||||
cmd = cmd.split(";").join(" ; ");
|
|
||||||
var subStrings = [];
|
|
||||||
var startQuoteIndex:Int = cmd.indexOf('"');
|
|
||||||
var endQuoteIndex:Int;
|
|
||||||
if(startQuoteIndex != -1){
|
|
||||||
while((startQuoteIndex = cmd.indexOf('"')) > -1){
|
|
||||||
//push start of the cmd up until the quotes start
|
|
||||||
subStrings.push(cmd.substring(0,startQuoteIndex));
|
|
||||||
//find next quote
|
|
||||||
endQuoteIndex = cmd.indexOf('"',startQuoteIndex+1)+1;
|
|
||||||
if(endQuoteIndex == 0){
|
|
||||||
cmd+='"';
|
|
||||||
endQuoteIndex = cmd.length;
|
|
||||||
|
|
||||||
}
|
|
||||||
//push quote content
|
|
||||||
subStrings.push(cmd.substring(startQuoteIndex,endQuoteIndex));
|
|
||||||
cmd = cmd.substr(endQuoteIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
subStrings.push(cmd);
|
|
||||||
//Split args
|
|
||||||
var newSubStrings = [];
|
|
||||||
for(subString in subStrings){
|
|
||||||
if(subString.indexOf('"') == -1){
|
|
||||||
// split spaced args
|
|
||||||
for(str in subString.split(" ")){
|
|
||||||
//we want to discard empty strings
|
|
||||||
if(str != "")
|
|
||||||
newSubStrings.push(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
newSubStrings.push(subString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var commands = [];
|
|
||||||
//split off additional commands
|
|
||||||
while(newSubStrings.length > 0){
|
|
||||||
for(i in 0...newSubStrings.length){
|
|
||||||
if(newSubStrings[i] == ";"){
|
|
||||||
commands.push(newSubStrings.splice(0,i));
|
|
||||||
newSubStrings.shift();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(newSubStrings.length-1 == i){
|
|
||||||
commands.push(newSubStrings);
|
|
||||||
newSubStrings = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trace(commands);
|
|
||||||
execCommands(commands);
|
|
||||||
}
|
|
||||||
public function execCommands(commands:Array<Array<String>>){
|
|
||||||
for(command in commands){
|
|
||||||
var cName:String = command[0];
|
|
||||||
var cValue:String = command[1];
|
|
||||||
var cArgs:Array<String> = command.slice(1);
|
|
||||||
if(ConVar.isCVar(cName)){
|
|
||||||
var cv:CVar = ConVar.getCVar(command[0]);
|
|
||||||
if(command.length == 1){
|
|
||||||
devMsg(cv.name+" - "+cv.helpString);
|
|
||||||
devMsg(cv.name+" = "+cv.value);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
switch(cv.type){
|
|
||||||
case CInt:
|
|
||||||
ConVar.setCVar(cName,Std.parseInt(cValue));
|
|
||||||
trace(cValue);
|
|
||||||
break;
|
|
||||||
case CFloat:
|
|
||||||
ConVar.setCVar(cName,Std.parseFloat(cValue));
|
|
||||||
break;
|
|
||||||
case CBool:
|
|
||||||
cValue = cValue.toLowerCase();
|
|
||||||
if(cValue == "1" || cValue == "true"){
|
|
||||||
ConVar.setCVar(cName,true);
|
|
||||||
}
|
|
||||||
else if(cValue == "0" || cValue == "false"){
|
|
||||||
ConVar.setCVar(cName,false);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CString:
|
|
||||||
ConVar.setCVar(cName,cValue);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(ConVar.isCmd(cName)){
|
|
||||||
ConVar.runCmd(cName,cArgs);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
devMsg("unkown command: "+command[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public function submitInput(){
|
|
||||||
cOut.appendText(">"+cIn.text+"\n");
|
|
||||||
parseCmd(cIn.text);
|
|
||||||
cIn.text = "";
|
|
||||||
cOut.scrollV = cOut.maxScrollV;
|
|
||||||
}
|
|
||||||
public function onOutputTextChange(e:Event){
|
|
||||||
cOut.scrollV = cOut.maxScrollV;
|
|
||||||
}
|
|
||||||
public static function toggle():Void
|
|
||||||
{
|
|
||||||
consoleInstance.visible = !consoleInstance.visible;
|
|
||||||
}
|
|
||||||
public static function devMsg(msg:String):Void
|
|
||||||
{
|
|
||||||
consoleInstance.cOut.appendText(msg+"\n");
|
|
||||||
consoleInstance.cOut.scrollV = consoleInstance.cOut.maxScrollV;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
27
hGameTest/src/game/ui/UIContianer.hx
Normal file
27
hGameTest/src/game/ui/UIContianer.hx
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package game.ui;
|
||||||
|
|
||||||
|
import openfl.geom.Point;
|
||||||
|
import openfl.display.Sprite;
|
||||||
|
|
||||||
|
|
||||||
|
class UIContianer extends Sprite{
|
||||||
|
public static var UIDrawList:Array<UIElement>=[];
|
||||||
|
public var anchor:Point;
|
||||||
|
public function new(panchor,scale){
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
public function onResize(){
|
||||||
|
|
||||||
|
}
|
||||||
|
public function hide(){
|
||||||
|
|
||||||
|
}
|
||||||
|
public function show(){
|
||||||
|
|
||||||
|
}
|
||||||
|
public function getParent()
|
||||||
|
{
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
12
hGameTest/src/game/ui/UIElement.hx
Normal file
12
hGameTest/src/game/ui/UIElement.hx
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package game.ui;
|
||||||
|
|
||||||
|
import openfl.geom.Point;
|
||||||
|
import openfl.display.Sprite;
|
||||||
|
|
||||||
|
class UIElement extends Sprite
|
||||||
|
{
|
||||||
|
public function new(){
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
hGameTest/src/game/ui/UIPane.hx
Normal file
15
hGameTest/src/game/ui/UIPane.hx
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package game.ui;
|
||||||
|
|
||||||
|
class UIPane{
|
||||||
|
public static var paneList:Array<UIPane>=[];
|
||||||
|
public var x:Int;
|
||||||
|
public var y:Int;
|
||||||
|
public var width:Int;
|
||||||
|
public var height:Int;
|
||||||
|
public var parent:UIPane;
|
||||||
|
|
||||||
|
public function new(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
363
hGameTest/src/game/ui/console/Console.hx
Normal file
363
hGameTest/src/game/ui/console/Console.hx
Normal file
@ -0,0 +1,363 @@
|
|||||||
|
package game.ui.console;
|
||||||
|
|
||||||
|
import engine.enums.CVarFlag;
|
||||||
|
import game.ui.text.TextFormats;
|
||||||
|
import assets.Fonts;
|
||||||
|
import openfl.Lib;
|
||||||
|
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;
|
||||||
|
import engine.typedefs.CVar;
|
||||||
|
import game.ui.ConVar;
|
||||||
|
import engine.typedefs.CCmd;
|
||||||
|
import game.ui.console.elements.ConsoleInput;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Console extends Sprite{
|
||||||
|
public var textFormat:TextFormat;
|
||||||
|
public var cOut:TextField;
|
||||||
|
public var cIn:TextField;
|
||||||
|
public var cInput:ConsoleInput;
|
||||||
|
public var cAutoComp:TextField;
|
||||||
|
public static var consoleInstance:Console;
|
||||||
|
public var cvar_mat_consolebg:CVar;
|
||||||
|
public function new(){
|
||||||
|
super();
|
||||||
|
|
||||||
|
consoleInstance = this;
|
||||||
|
|
||||||
|
|
||||||
|
graphics.beginFill(0x555555);
|
||||||
|
graphics.drawRect(0,0,800,600);
|
||||||
|
|
||||||
|
cInput = new ConsoleInput();
|
||||||
|
cIn = cInput.tf;
|
||||||
|
|
||||||
|
//cIn.setTextFormat(textFormat);
|
||||||
|
cInput.y = 600-cInput.height-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.text = "hConsole Initialized\n";
|
||||||
|
cOut.defaultTextFormat = TextFormats.getFormats().cOutputFmt;
|
||||||
|
cOut.wordWrap = true;
|
||||||
|
//cOut.autoSize = TextFieldAutoSize.LEFT;
|
||||||
|
cOut.multiline = true;
|
||||||
|
cOut.background = true;
|
||||||
|
cOut.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
||||||
|
cOut.width = 800 - 24;
|
||||||
|
cOut.height = 600 - cIn.height - 38;
|
||||||
|
cOut.y = 12;
|
||||||
|
cOut.x = 12;
|
||||||
|
|
||||||
|
cAutoComp = new TextField();
|
||||||
|
cAutoComp.text = "";
|
||||||
|
cAutoComp.defaultTextFormat = TextFormats.getFormats().cInputFmt;
|
||||||
|
cAutoComp.wordWrap = false;
|
||||||
|
cAutoComp.multiline = true;
|
||||||
|
cAutoComp.background = true;
|
||||||
|
cAutoComp.backgroundColor = 0x11111100;
|
||||||
|
cAutoComp.border = true;
|
||||||
|
cAutoComp.borderColor = 0x55555500;
|
||||||
|
cAutoComp.selectable = false;
|
||||||
|
cAutoComp.width = 400;
|
||||||
|
cAutoComp.height = 32*5;
|
||||||
|
cAutoComp.visible = false;
|
||||||
|
cAutoComp.x = 0;
|
||||||
|
cAutoComp.y = 600;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cOut.addEventListener(Event.CHANGE, onOutputTextChange);
|
||||||
|
cIn.addEventListener(Event.CHANGE, onInputTextChange);
|
||||||
|
//cOut.addEventListener()
|
||||||
|
this.addChild(cOut);
|
||||||
|
this.addChild(cInput);
|
||||||
|
this.addChild(cAutoComp);
|
||||||
|
//ConVar.registerCVar("echo", CVarType.CCmd, null, devMsg())
|
||||||
|
ConVar.registerCCmd("echo", (args:Array<String>) -> { Console.devMsg(args.join(" ").split('"').join(""));});
|
||||||
|
ConVar.registerCCmd("quit", (args:Array<String>) -> { Lib.application.window.close();});
|
||||||
|
}
|
||||||
|
public function parseCmd(cmd:String){
|
||||||
|
history.push(cmd);
|
||||||
|
cmd = cmd.split(";").join(" ; ");
|
||||||
|
var subStrings = [];
|
||||||
|
var startQuoteIndex:Int = cmd.indexOf('"');
|
||||||
|
var endQuoteIndex:Int;
|
||||||
|
if(startQuoteIndex != -1){
|
||||||
|
while((startQuoteIndex = cmd.indexOf('"')) > -1){
|
||||||
|
//push start of the cmd up until the quotes start
|
||||||
|
subStrings.push(cmd.substring(0,startQuoteIndex));
|
||||||
|
//find next quote
|
||||||
|
endQuoteIndex = cmd.indexOf('"',startQuoteIndex+1)+1;
|
||||||
|
if(endQuoteIndex == 0){
|
||||||
|
cmd+='"';
|
||||||
|
endQuoteIndex = cmd.length;
|
||||||
|
|
||||||
|
}
|
||||||
|
//push quote content
|
||||||
|
subStrings.push(cmd.substring(startQuoteIndex,endQuoteIndex));
|
||||||
|
cmd = cmd.substr(endQuoteIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subStrings.push(cmd);
|
||||||
|
//Split args
|
||||||
|
var newSubStrings = [];
|
||||||
|
for(subString in subStrings){
|
||||||
|
if(subString.indexOf('"') == -1){
|
||||||
|
// split spaced args
|
||||||
|
for(str in subString.split(" ")){
|
||||||
|
//we want to discard empty strings
|
||||||
|
if(str != "")
|
||||||
|
newSubStrings.push(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
newSubStrings.push(subString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var commands = [];
|
||||||
|
//split off additional commands
|
||||||
|
while(newSubStrings.length > 0){
|
||||||
|
for(i in 0...newSubStrings.length){
|
||||||
|
if(newSubStrings[i] == ";"){
|
||||||
|
commands.push(newSubStrings.splice(0,i));
|
||||||
|
newSubStrings.shift();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(newSubStrings.length-1 == i){
|
||||||
|
commands.push(newSubStrings);
|
||||||
|
newSubStrings = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(commands);
|
||||||
|
execCommands(commands);
|
||||||
|
}
|
||||||
|
public function execCommands(commands:Array<Array<String>>){
|
||||||
|
for(command in commands){
|
||||||
|
var cName:String = command[0];
|
||||||
|
var cValue:String = command[1];
|
||||||
|
var cArgs:Array<String> = command.slice(1);
|
||||||
|
if(ConVar.isCVar(cName)){
|
||||||
|
var cv:CVar = ConVar.getCVar(command[0]);
|
||||||
|
if(command.length == 1){
|
||||||
|
devMsg(cv.name+" - "+cv.helpString);
|
||||||
|
devMsg(cv.name+" = "+cv.value);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
switch(cv.type){
|
||||||
|
case CInt:
|
||||||
|
ConVar.setCVar(cName,Std.parseInt(cValue));
|
||||||
|
trace(cValue);
|
||||||
|
break;
|
||||||
|
case CFloat:
|
||||||
|
ConVar.setCVar(cName,Std.parseFloat(cValue));
|
||||||
|
break;
|
||||||
|
case CBool:
|
||||||
|
cValue = cValue.toLowerCase();
|
||||||
|
if(cValue == "1" || cValue == "true"){
|
||||||
|
ConVar.setCVar(cName,true);
|
||||||
|
}
|
||||||
|
else if(cValue == "0" || cValue == "false"){
|
||||||
|
ConVar.setCVar(cName,false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CString:
|
||||||
|
ConVar.setCVar(cName,cValue);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(ConVar.isCmd(cName)){
|
||||||
|
ConVar.runCmd(cName,cArgs);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
devMsg("unkown command: "+command[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function submitInput(){
|
||||||
|
cOut.appendText(">"+cIn.text+"\n");
|
||||||
|
parseCmd(cIn.text);
|
||||||
|
cIn.text = "";
|
||||||
|
cAutoComp.visible = false;
|
||||||
|
cOut.scrollV = cOut.maxScrollV;
|
||||||
|
histSelect = -1;
|
||||||
|
}
|
||||||
|
public function onOutputTextChange(e:Event){
|
||||||
|
cOut.scrollV = cOut.maxScrollV;
|
||||||
|
}
|
||||||
|
public function onInputTextChange(e:Event){
|
||||||
|
if(cIn.text != ""){
|
||||||
|
cAutoComp.text = "";
|
||||||
|
for(string in (autocompleteList = getCompList())){
|
||||||
|
cAutoComp.text += string+"\n";
|
||||||
|
trace(string);
|
||||||
|
}
|
||||||
|
cAutoComp.visible = true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
cAutoComp.visible = false;
|
||||||
|
autocompleteList = history;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static function toggle():Void
|
||||||
|
{
|
||||||
|
consoleInstance.visible = !consoleInstance.visible;
|
||||||
|
}
|
||||||
|
public static function devMsg(msg:String):Void
|
||||||
|
{
|
||||||
|
consoleInstance.cOut.appendText(msg+"\n");
|
||||||
|
consoleInstance.cOut.scrollV = consoleInstance.cOut.maxScrollV;
|
||||||
|
}
|
||||||
|
public static var history:Array<String> = [];
|
||||||
|
public static var histSelect:Int = -1;
|
||||||
|
public static var tmpInput:String = "";
|
||||||
|
public static var autocompleteList:Array<String> = [];
|
||||||
|
public static var compSelect:Int = -1;
|
||||||
|
public static function getCompList():Array<String>
|
||||||
|
{
|
||||||
|
// Split words
|
||||||
|
var inp:Array<String> = consoleInstance.cIn.text.split(" ");
|
||||||
|
var inpStripped:Array<String> = [
|
||||||
|
for(word in inp){
|
||||||
|
if(word != "" && word != " "){
|
||||||
|
word;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
// Stop if input is empty
|
||||||
|
if(inp.length == 0) return [];
|
||||||
|
|
||||||
|
var cVars:Array<String> = ConVar.getCVarNames();
|
||||||
|
var cVarFiltered:Array<String> = [];
|
||||||
|
// Loop through convars
|
||||||
|
for(cVar in cVars){
|
||||||
|
//if there's one word just check if the convar starts with the input string
|
||||||
|
if(inp.length == 1)
|
||||||
|
{
|
||||||
|
// Check if the cvar starts with the input
|
||||||
|
if(cVar.indexOf(inp[0]) == 0){
|
||||||
|
cVarFiltered.push(cVar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// User pressed space at least once but entered no other words. Check if first word occurs at any position
|
||||||
|
else if(inpStripped.length == 1 && inp.length > 1){
|
||||||
|
if(cVar.indexOf(inp[0]) > -1){
|
||||||
|
cVarFiltered.push(cVar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Multiple words, check for cvars that contain all of them
|
||||||
|
else if(inpStripped.length > 1)
|
||||||
|
{
|
||||||
|
var bWordNotPresent:Bool = false;
|
||||||
|
for(word in inpStripped){
|
||||||
|
if(cVar.indexOf(word) == -1){
|
||||||
|
bWordNotPresent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!bWordNotPresent)
|
||||||
|
cVarFiltered.push(cVar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cVarFiltered;
|
||||||
|
}
|
||||||
|
public static function histPrev():Void
|
||||||
|
{
|
||||||
|
// Only complete if input field is empty or scrolling through hist
|
||||||
|
if(consoleInstance.cIn.text == "" || histSelect != -1){
|
||||||
|
// Store current input in tmpInput
|
||||||
|
if(histSelect == -1) tmpInput = consoleInstance.cIn.text;
|
||||||
|
// Only go through history if history is not empty
|
||||||
|
if(history.length != 0){
|
||||||
|
// Check if currently selecting a history entry
|
||||||
|
if(histSelect >= 0){
|
||||||
|
histSelect--;
|
||||||
|
}
|
||||||
|
// Not currently selecting a history entry
|
||||||
|
else{
|
||||||
|
// Put selector to the newest
|
||||||
|
histSelect = history.length -1;
|
||||||
|
}
|
||||||
|
if(histSelect != -1){
|
||||||
|
// Put correct history entry in the input field
|
||||||
|
consoleInstance.cIn.text = history[histSelect];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// Restore tmp input
|
||||||
|
consoleInstance.cIn.text = tmpInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// History is empty
|
||||||
|
else{
|
||||||
|
// Do nothing
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Now we need to descend through the autocomplete list
|
||||||
|
else{
|
||||||
|
if(autocompleteList.length == 0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// Check if currently selecting an autocomplete entry
|
||||||
|
if(compSelect > -1){
|
||||||
|
|
||||||
|
}
|
||||||
|
// Not currently selecting an autocomplete entry
|
||||||
|
else{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static function histNext():Void
|
||||||
|
{
|
||||||
|
// Only complete if input field is empty or scrolling through hist
|
||||||
|
if(consoleInstance.cIn.text == "" || histSelect != -1){
|
||||||
|
// Store current input in tmpInput
|
||||||
|
if(histSelect == -1) tmpInput = consoleInstance.cIn.text;
|
||||||
|
// Only go through history if history is not empty
|
||||||
|
if(history.length != 0){
|
||||||
|
// Check if currently selecting a history entry
|
||||||
|
if(histSelect < history.length -1){
|
||||||
|
histSelect++;
|
||||||
|
}
|
||||||
|
// Otherwise wrap around
|
||||||
|
else{
|
||||||
|
// Put selector to no selection
|
||||||
|
histSelect = -1;
|
||||||
|
}
|
||||||
|
if(histSelect != -1){
|
||||||
|
// Put correct history entry in the input field
|
||||||
|
consoleInstance.cIn.text = history[histSelect];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// Restore tmp input
|
||||||
|
consoleInstance.cIn.text = tmpInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// History is empty
|
||||||
|
else{
|
||||||
|
// Do nothing
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
hGameTest/src/game/ui/console/elements/ConsoleInput.hx
Normal file
51
hGameTest/src/game/ui/console/elements/ConsoleInput.hx
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package game.ui.console.elements;
|
||||||
|
|
||||||
|
import openfl.events.Event;
|
||||||
|
import openfl.display.Sprite;
|
||||||
|
import openfl.text.TextField;
|
||||||
|
import openfl.text.TextFieldType;
|
||||||
|
import openfl.text.TextFormat;
|
||||||
|
import openfl.Assets;
|
||||||
|
import game.ui.text.TextFormats;
|
||||||
|
|
||||||
|
class ConsoleInput extends Sprite
|
||||||
|
{
|
||||||
|
public var tf:TextField;
|
||||||
|
public function new(){
|
||||||
|
super();
|
||||||
|
tf = new TextField();
|
||||||
|
tf.defaultTextFormat = TextFormats.getFormats().cInputFmt;
|
||||||
|
tf.text = "";
|
||||||
|
//tf.setTextFormat(new TextFormat(Assets.getFont("fonts/Terminus.ttf").fontName, 24, 0x00ff00));
|
||||||
|
trace(tf.getTextFormat().color);
|
||||||
|
trace(tf.getTextFormat().font);
|
||||||
|
tf.type = TextFieldType.INPUT;
|
||||||
|
tf.multiline = false;
|
||||||
|
//tf.autoSize = TextFieldAutoSize.LEFT;
|
||||||
|
tf.width = 800-24;
|
||||||
|
tf.height = tf.textHeight+2;
|
||||||
|
tf.background = true;
|
||||||
|
tf.backgroundColor = 0x222222;
|
||||||
|
tf.selectable = true;
|
||||||
|
this.addChild(tf);
|
||||||
|
this.addEventListener(Event.RESIZE,onResize);
|
||||||
|
tf.addEventListener(Event.CHANGE, onTextChange);
|
||||||
|
}
|
||||||
|
public function onResize(e:Event){
|
||||||
|
tf.width = this.width;
|
||||||
|
}
|
||||||
|
public function onTextChange(e:Event){
|
||||||
|
|
||||||
|
}
|
||||||
|
public function clearText(){
|
||||||
|
tf.text = "";
|
||||||
|
}
|
||||||
|
public function getText():String
|
||||||
|
{
|
||||||
|
return tf.text;
|
||||||
|
}
|
||||||
|
public function setText(t:String){
|
||||||
|
tf.text = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
24
hGameTest/src/game/ui/text/TextFormats.hx
Normal file
24
hGameTest/src/game/ui/text/TextFormats.hx
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package game.ui.text;
|
||||||
|
|
||||||
|
|
||||||
|
import openfl.text.TextFormat;
|
||||||
|
import openfl.Assets;
|
||||||
|
import assets.Fonts;
|
||||||
|
|
||||||
|
class TextFormats{
|
||||||
|
public static var formats:TextFormats;
|
||||||
|
public var cInputFmt:TextFormat;
|
||||||
|
public var cOutputFmt:TextFormat;
|
||||||
|
public function new(){
|
||||||
|
cInputFmt = new TextFormat(Assets.getFont("fonts/Terminus.ttf").fontName, 24, 0xffffff);
|
||||||
|
cOutputFmt = new TextFormat(Assets.getFont("fonts/Terminus.ttf").fontName, 24, 0xffffff);
|
||||||
|
}
|
||||||
|
public static function getFormats():TextFormats
|
||||||
|
{
|
||||||
|
if(formats == null){
|
||||||
|
formats = new TextFormats();
|
||||||
|
}
|
||||||
|
return formats;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user