Compare commits
4 Commits
changes_la
...
aids
| Author | SHA1 | Date | |
|---|---|---|---|
| 24432f1b91 | |||
| 07fa2e7868 | |||
| 4fe14e341c | |||
| c3ac30208b |
@@ -1,4 +1,4 @@
|
|||||||
package game.ui;
|
package engine;
|
||||||
|
|
||||||
|
|
||||||
typedef CVar = {
|
typedef CVar = {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package game.ui;
|
package engine;
|
||||||
|
|
||||||
enum CVarType {
|
enum CVarType {
|
||||||
CInt;
|
CInt;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package game.ui;
|
package engine;
|
||||||
|
|
||||||
import haxe.Constraints.Function;
|
import haxe.Constraints.Function;
|
||||||
import engine.typedefs.CVar;
|
import engine.typedefs.CVar;
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package game;
|
|
||||||
|
|
||||||
class Bind{
|
|
||||||
public var key:Int;
|
|
||||||
public var action:String;
|
|
||||||
public function new(key:Int, action:String){
|
|
||||||
this.key = key;
|
|
||||||
this.action = action;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,7 @@ import openfl.display.Sprite;
|
|||||||
import openfl.events.Event;
|
import openfl.events.Event;
|
||||||
import assets.Scanner;
|
import assets.Scanner;
|
||||||
import assets.HTex;
|
import assets.HTex;
|
||||||
import game.ui.ConVar;
|
import engine.ConVar;
|
||||||
import game.ui.console.Console;
|
import game.ui.console.Console;
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
@@ -41,20 +41,9 @@ class Game
|
|||||||
uiLayer = new Sprite();
|
uiLayer = new Sprite();
|
||||||
stage.addChild(gameLayer);
|
stage.addChild(gameLayer);
|
||||||
stage.addChild(uiLayer);
|
stage.addChild(uiLayer);
|
||||||
//player.graphics.lineStyle(2,0xFF0000);
|
|
||||||
//player.graphics.drawRect(0,0,16,16);
|
|
||||||
// var bitmapData:BitmapData = Assets.getBitmapData("textures/sprites/character.png");
|
|
||||||
//player = new Player();
|
|
||||||
//gameLayer.addChild(player.sprite);
|
|
||||||
uiLayer.addChild(console);
|
uiLayer.addChild(console);
|
||||||
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 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 playerBitmap:Bitmap = new Bitmap(Tileset.tilesetMap["testsheet"].tileMap["testTile5"]);
|
|
||||||
//var someotherbitmap:Bitmap = new Bitmap(Tileset.tilesetMap["testsheet"].tileMap["testTile3"]);
|
|
||||||
//playerBitmap.scaleX = playerBitmap.scaleY = 10;
|
|
||||||
//player.addChild(playerBitmap);
|
|
||||||
//TextureData.parseConfig();
|
|
||||||
//Sys.
|
|
||||||
}
|
}
|
||||||
public function onEnterFrame(e:Event):Void
|
public function onEnterFrame(e:Event):Void
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package game;
|
package game;
|
||||||
|
|
||||||
|
import openfl.text.TextField;
|
||||||
import engine.enums.CVarFlag;
|
import engine.enums.CVarFlag;
|
||||||
import engine.typedefs.CCmd;
|
import engine.typedefs.CCmd;
|
||||||
import game.ui.console.Console;
|
import game.ui.console.Console;
|
||||||
@@ -9,16 +10,12 @@ import openfl.ui.Keyboard in Kb;
|
|||||||
import openfl.Lib;
|
import openfl.Lib;
|
||||||
import engine.enums.CVarType;
|
import engine.enums.CVarType;
|
||||||
import engine.typedefs.CVar;
|
import engine.typedefs.CVar;
|
||||||
import game.ui.ConVar;
|
import engine.ConVar;
|
||||||
|
|
||||||
|
|
||||||
class Input{
|
class Input{
|
||||||
public static var keys:Map<Int,Bool> = [];
|
public static var keys:Map<Int,Bool> = [];
|
||||||
public static var keysLast:Map<Int,Bool> = [];
|
public static var keysLast:Map<Int,Bool> = [];
|
||||||
public static var bindMap:Map<String, String> = [];
|
public static var bindMap:Map<String, String> = ["~" => "toggleconsole", "\\" => "toggleconsole", "1" => "echo kak", "2" => "+attack"];
|
||||||
//public static var bind:CVar = Convar.registerCVar("bind",CVarType.cCmd, null, ()->{
|
|
||||||
//
|
|
||||||
//});
|
|
||||||
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 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 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",
|
||||||
@@ -46,9 +43,14 @@ class Input{
|
|||||||
Console.devMsg(Std.string(keycode));
|
Console.devMsg(Std.string(keycode));
|
||||||
});
|
});
|
||||||
public static function onKeyIsDown(e:KeyboardEvent){
|
public static function onKeyIsDown(e:KeyboardEvent){
|
||||||
|
if(!Std.isOfType(Lib.current.stage.focus,TextField)){
|
||||||
|
Console.consoleInstance.parseCmd(bindMap[keyNameMap[e.keyCode]]);
|
||||||
|
}
|
||||||
if(!keys[e.keyCode]){
|
if(!keys[e.keyCode]){
|
||||||
if(cv_debugKeys.value > 0)
|
if(cv_debugKeys.value == 1)
|
||||||
Console.devMsg("triggered key: "+keyNameMap[e.keyCode]);
|
Console.devMsg("triggered key: "+keyNameMap[e.keyCode]);
|
||||||
|
else if(cv_debugKeys.value > 1 )
|
||||||
|
Console.devMsg(""+e.keyCode);
|
||||||
}
|
}
|
||||||
keys[e.keyCode] = true;
|
keys[e.keyCode] = true;
|
||||||
var key:String = keyNameMap[e.keyCode];
|
var key:String = keyNameMap[e.keyCode];
|
||||||
@@ -56,27 +58,40 @@ class Input{
|
|||||||
|
|
||||||
}
|
}
|
||||||
public static function onKeyIsUp(e:KeyboardEvent){
|
public static function onKeyIsUp(e:KeyboardEvent){
|
||||||
|
if(!Std.isOfType(Lib.current.stage.focus,TextField)){
|
||||||
|
if(bindMap[keyNameMap[e.keyCode]].indexOf("+") == 0){
|
||||||
|
Console.consoleInstance.parseCmd(StringTools.replace(bindMap[keyNameMap[e.keyCode]],"+","-"));
|
||||||
|
}
|
||||||
|
}
|
||||||
keys[e.keyCode] = false;
|
keys[e.keyCode] = false;
|
||||||
}
|
}
|
||||||
public static function resolveKeyName(key:Int):String
|
// public static function resolveKeyName(key:Int):String
|
||||||
{
|
|
||||||
return keyNameMap[key];
|
|
||||||
}
|
|
||||||
// public static function bind(input:Dynamic, action:String):Void
|
|
||||||
// {
|
// {
|
||||||
// var key:Int;
|
// return keyNameMap[key];
|
||||||
// if(Std.is(input,Int)){
|
|
||||||
// key = input;
|
|
||||||
// }
|
|
||||||
// else if(Std.is(input, String)){
|
|
||||||
// var value:String = input;
|
|
||||||
// key = keyCodeMap[value.toUpperCase()];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
public static function bindKey(input:String, action:String):Void
|
||||||
|
{
|
||||||
|
bindMap[input] = action;
|
||||||
|
}
|
||||||
private static var bind:CCmd = ConVar.registerCCmd("bind", (cArgs:Array<String>)->{
|
private static var bind:CCmd = ConVar.registerCCmd("bind", (cArgs:Array<String>)->{
|
||||||
|
cArgs[0] = cArgs[0].toUpperCase();
|
||||||
ConVar.runCmd("echo",cArgs);
|
if(cArgs.length == 2){
|
||||||
|
if(keyCodeMap[cArgs[0]]!= null) {
|
||||||
|
if(cArgs[1].indexOf('"') == 0 && cArgs[1].lastIndexOf('"') == cArgs[1].length-1){
|
||||||
|
bindKey(cArgs[0], cArgs[1].substring(1,cArgs[1].length-1));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
bindKey(cArgs[0], cArgs[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(cArgs.length == 1){
|
||||||
|
Console.devMsg(bindMap[cArgs[0]]);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Console.devMsg("usage: bind <key> <command>");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
public static function onEnterFrame()
|
public static function onEnterFrame()
|
||||||
{
|
{
|
||||||
@@ -99,6 +114,12 @@ class Input{
|
|||||||
if (keys[Kb.DOWN] && !keysLast[Kb.DOWN]){
|
if (keys[Kb.DOWN] && !keysLast[Kb.DOWN]){
|
||||||
Console.histNext();
|
Console.histNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(Console.consoleInstance.visible){
|
||||||
|
if (keys[Kb.ESCAPE]){
|
||||||
|
Console.toggle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
keysLast = keys.copy();
|
keysLast = keys.copy();
|
||||||
}
|
}
|
||||||
|
|||||||
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package game.ui.console;
|
package game.ui.console;
|
||||||
|
|
||||||
|
import engine.enums.CVarFlag;
|
||||||
|
import game.ui.text.TextFormats;
|
||||||
import assets.Fonts;
|
import assets.Fonts;
|
||||||
import openfl.Lib;
|
import openfl.Lib;
|
||||||
import openfl.events.Event;
|
import openfl.events.Event;
|
||||||
@@ -9,15 +11,10 @@ import openfl.display.Sprite;
|
|||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import openfl.text.TextFormat;
|
import openfl.text.TextFormat;
|
||||||
import openfl.text.TextFieldType;
|
import openfl.text.TextFieldType;
|
||||||
// Engine Imports
|
|
||||||
import engine.enums.CVarFlag;
|
|
||||||
import engine.typedefs.CVar;
|
import engine.typedefs.CVar;
|
||||||
|
import engine.ConVar;
|
||||||
import engine.typedefs.CCmd;
|
import engine.typedefs.CCmd;
|
||||||
// Game imports
|
|
||||||
import game.ui.ConVar;
|
|
||||||
import game.ui.text.TextFormats;
|
|
||||||
import game.ui.console.elements.ConsoleInput;
|
import game.ui.console.elements.ConsoleInput;
|
||||||
import game.ui.UIPane;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -29,25 +26,16 @@ class Console extends Sprite{
|
|||||||
public var cAutoComp:TextField;
|
public var cAutoComp:TextField;
|
||||||
public static var consoleInstance:Console;
|
public static var consoleInstance:Console;
|
||||||
public var cvar_mat_consolebg:CVar;
|
public var cvar_mat_consolebg:CVar;
|
||||||
|
public var cCmd_visible:CCmd = ConVar.registerCCmd("toggleconsole",(cArgs:Array<String>)->{
|
||||||
|
toggle();
|
||||||
|
});
|
||||||
public function new(){
|
public function new(){
|
||||||
super();
|
super();
|
||||||
|
|
||||||
consoleInstance = this;
|
consoleInstance = this;
|
||||||
|
|
||||||
var consolePane:UIPane = new UIPane("console pane",{width: 800, height: 600});
|
|
||||||
var topBar:UIPane = new UIPane("top bar", {width: 800, height: 32});
|
graphics.beginFill(0x555555);
|
||||||
var bottomBar:UIPane = new UIPane("input bar", {width: 800, height: 32});
|
|
||||||
var outputPane:UIPane = new UIPane("output pane", {width: 800, height: 1});
|
|
||||||
outputPane.dimensions.expandBehavior = STRETCH;
|
|
||||||
bottomBar.align = END;
|
|
||||||
outputPane.align = END;
|
|
||||||
consolePane.layout = VERTICAL;
|
|
||||||
topBar.align = START;
|
|
||||||
consolePane.addChild(topBar);
|
|
||||||
consolePane.addChild(bottomBar);
|
|
||||||
consolePane.addChild(outputPane);
|
|
||||||
addChild(consolePane.sprite);
|
|
||||||
//graphics.beginFill(0x555555);
|
|
||||||
graphics.drawRect(0,0,800,600);
|
graphics.drawRect(0,0,800,600);
|
||||||
|
|
||||||
cInput = new ConsoleInput();
|
cInput = new ConsoleInput();
|
||||||
@@ -70,14 +58,11 @@ class Console extends Sprite{
|
|||||||
cOut.multiline = true;
|
cOut.multiline = true;
|
||||||
cOut.background = true;
|
cOut.background = true;
|
||||||
cOut.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
cOut.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
||||||
cOut.width = outputPane.dimensions.width;
|
cOut.width = 800 - 24;
|
||||||
cOut.height = outputPane.dimensions.height;
|
cOut.height = 600 - cIn.height - 38;
|
||||||
cOut.y = 0;
|
cOut.y = 12;
|
||||||
cOut.x = 0;
|
cOut.x = 12;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cAutoComp = new TextField();
|
cAutoComp = new TextField();
|
||||||
cAutoComp.text = "";
|
cAutoComp.text = "";
|
||||||
cAutoComp.defaultTextFormat = TextFormats.getFormats().cInputFmt;
|
cAutoComp.defaultTextFormat = TextFormats.getFormats().cInputFmt;
|
||||||
@@ -99,15 +84,17 @@ class Console extends Sprite{
|
|||||||
cOut.addEventListener(Event.CHANGE, onOutputTextChange);
|
cOut.addEventListener(Event.CHANGE, onOutputTextChange);
|
||||||
cIn.addEventListener(Event.CHANGE, onInputTextChange);
|
cIn.addEventListener(Event.CHANGE, onInputTextChange);
|
||||||
//cOut.addEventListener()
|
//cOut.addEventListener()
|
||||||
outputPane.sprite.addChild(cOut);
|
this.addChild(cOut);
|
||||||
this.addChild(cInput);
|
this.addChild(cInput);
|
||||||
this.addChild(cAutoComp);
|
this.addChild(cAutoComp);
|
||||||
//ConVar.registerCVar("echo", CVarType.CCmd, null, devMsg())
|
//ConVar.registerCVar("echo", CVarType.CCmd, null, devMsg())
|
||||||
ConVar.registerCCmd("echo", (args:Array<String>) -> { Console.devMsg(args.join(" ").split('"').join(""));});
|
ConVar.registerCCmd("echo", (args:Array<String>) -> { Console.devMsg(args.join(" ").split('"').join(""));});
|
||||||
ConVar.registerCCmd("quit", (args:Array<String>) -> { Lib.application.window.close();});
|
ConVar.registerCCmd("quit", (args:Array<String>) -> { Lib.application.window.close();});
|
||||||
}
|
}
|
||||||
public function parseCmd(cmd:String){
|
public function parseCmd(cmd:String, bNoHist:Bool = false){
|
||||||
history.push(cmd);
|
if(!bNoHist)
|
||||||
|
history.push(cmd);
|
||||||
|
|
||||||
cmd = cmd.split(";").join(" ; ");
|
cmd = cmd.split(";").join(" ; ");
|
||||||
var subStrings = [];
|
var subStrings = [];
|
||||||
var startQuoteIndex:Int = cmd.indexOf('"');
|
var startQuoteIndex:Int = cmd.indexOf('"');
|
||||||
@@ -236,6 +223,14 @@ class Console extends Sprite{
|
|||||||
public static function toggle():Void
|
public static function toggle():Void
|
||||||
{
|
{
|
||||||
consoleInstance.visible = !consoleInstance.visible;
|
consoleInstance.visible = !consoleInstance.visible;
|
||||||
|
if(!consoleInstance.visible){
|
||||||
|
if(Lib.current.stage.focus == consoleInstance.cIn){
|
||||||
|
Lib.current.stage.focus = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Lib.current.stage.focus = consoleInstance.cIn;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static function devMsg(msg:String):Void
|
public static function devMsg(msg:String):Void
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package game.video;
|
package game.video;
|
||||||
|
|
||||||
import game.ui.ConVar;
|
import engine.ConVar;
|
||||||
import openfl.Lib;
|
import openfl.Lib;
|
||||||
import openfl.display.StageDisplayState;
|
import openfl.display.StageDisplayState;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user