Compare commits
23
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0e4109bde | ||
|
|
7fa7ece574 | ||
|
|
be0c83e766 | ||
|
|
4f4cca4109 | ||
|
|
7e3369d128 | ||
|
|
33e5a67e4d | ||
|
|
75d8032b5d | ||
|
|
013a27d0b3 | ||
|
|
8adb6bbaef | ||
|
|
5723371944 | ||
|
|
4272c12ec1 | ||
|
|
923ac33302 | ||
|
|
bc1a251842 | ||
|
|
8973b65954 | ||
|
|
132a9d63c0 | ||
|
|
fbc3be26e4 | ||
|
|
56d4651228 | ||
|
|
570816c0b5 | ||
|
|
90d44a1376 | ||
|
|
9a585cf24b | ||
|
|
728ab76571 | ||
|
|
a96e97f2a0 | ||
|
|
8204c6b556 |
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "4.3.6",
|
|
||||||
"resolveLibs": "scoped"
|
|
||||||
}
|
|
||||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>test</title>
|
<title>nigger</title>
|
||||||
<link rel="shortcut icon" type="image/png" href="./favicon.png">
|
<link rel="shortcut icon" type="image/png" href="./favicon.png">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
# @install: lix --silent download "haxelib:/actuate#1.9.0" into actuate/1.9.0/haxelib
|
|
||||||
-cp ${HAXE_LIBCACHE}/actuate/1.9.0/haxelib/src
|
|
||||||
-D actuate=1.9.0
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
# @install: lix --silent download "haxelib:/hxcpp-debug-server#1.2.4" into hxcpp-debug-server/1.2.4/haxelib
|
|
||||||
-cp ${HAXE_LIBCACHE}/hxcpp-debug-server/1.2.4/haxelib/
|
|
||||||
-D hxcpp-debug-server=1.2.4
|
|
||||||
--macro hxcpp.debug.jsonrpc.Macro.injectServer()
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
# @install: lix --silent download "haxelib:/lime#8.2.2" into lime/8.2.2/haxelib
|
|
||||||
# @run: haxelib run-dir lime "${HAXE_LIBCACHE}/lime/8.2.2/haxelib"
|
|
||||||
-cp ${HAXE_LIBCACHE}/lime/8.2.2/haxelib/src
|
|
||||||
-D lime=8.2.2
|
|
||||||
--macro lime._internal.macros.DefineMacro.run()
|
|
||||||
-lib ndll:${HAXE_LIBCACHE}/lime/8.2.2/haxelib/ndll/
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
# @install: lix --silent download "haxelib:/openfl#9.4.1" into openfl/9.4.1/haxelib
|
|
||||||
# @run: haxelib run-dir openfl "${HAXE_LIBCACHE}/openfl/9.4.1/haxelib"
|
|
||||||
-cp ${HAXE_LIBCACHE}/openfl/9.4.1/haxelib/src
|
|
||||||
-D openfl=9.4.1
|
|
||||||
--macro openfl.utils._internal.ExtraParamsMacro.include()
|
|
||||||
Generated
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "test",
|
"name": "nigger",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "test",
|
"name": "nigger",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"config": {
|
"config": {
|
||||||
|
|||||||
@@ -15,10 +15,6 @@
|
|||||||
|
|
||||||
<!-- classpath, haxe libs -->
|
<!-- classpath, haxe libs -->
|
||||||
<source path="src" />
|
<source path="src" />
|
||||||
|
|
||||||
<!-- Macro configuration -->
|
|
||||||
<haxeflag name="--macro" value="addGlobalMetadata('', '@:build(engine.macros.ConVarDecorators.build())')" />
|
|
||||||
|
|
||||||
<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"/>
|
||||||
@@ -28,6 +24,6 @@
|
|||||||
<!--<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>
|
||||||
@@ -18,16 +18,20 @@ class Main extends Sprite {
|
|||||||
private function onInit(e:Event)
|
private function onInit(e:Event)
|
||||||
{
|
{
|
||||||
//Scanner.scanTextureDir();
|
//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(1280, 960);
|
//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;
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
package engine;
|
|
||||||
|
|
||||||
import game.video.Mode;
|
|
||||||
import haxe.macro.Expr.Field;
|
|
||||||
import engine.typedefs.console.CVar;
|
|
||||||
import engine.typedefs.console.CCmd;
|
|
||||||
import engine.enums.console.CVarType;
|
|
||||||
import engine.enums.console.CVarFlag;
|
|
||||||
import engine.macros.ConVarDecorators;
|
|
||||||
import game.ui.console.Console;
|
|
||||||
|
|
||||||
@:keep
|
|
||||||
// @:build(engine.macros.CCmdDecorator.build()) // No longer needed because we added the build macro to the project.xml
|
|
||||||
class ConVars_Engine {
|
|
||||||
|
|
||||||
@:concmd("list")
|
|
||||||
public static function listCommands(args:Array<String>) {
|
|
||||||
var CVarMap:Map<String, CVar> = ConVar.getCVarMap();
|
|
||||||
var keys:Array<String> = ConVar.getCVarNames();
|
|
||||||
for(key in keys){
|
|
||||||
if(CVarMap[key] != null){
|
|
||||||
Console.devMsg(key+" "+ CVarMap[key].value);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
Console.devMsg(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@:concmd("test")
|
|
||||||
public static function testCommand() {
|
|
||||||
// Command implementation
|
|
||||||
trace("Test Output");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package engine;
|
|
||||||
|
|
||||||
import game.ui.console.Console;
|
|
||||||
import Sys;
|
|
||||||
|
|
||||||
#if sys
|
|
||||||
class HProfiler{
|
|
||||||
public static var profilerList:Array<HProfiler> = [];
|
|
||||||
public static var profilerMap:Map<String, HProfiler> = [];
|
|
||||||
private var tStart:Float;
|
|
||||||
private var tEnd:Float;
|
|
||||||
public var tDelta:Float;
|
|
||||||
private var name:String;
|
|
||||||
private function new(_name:String){
|
|
||||||
name = _name;
|
|
||||||
profilerMap[_name] = this;
|
|
||||||
}
|
|
||||||
public function start(){
|
|
||||||
tStart = Sys.time() * 1000.0;
|
|
||||||
}
|
|
||||||
public function stop(){
|
|
||||||
tEnd = Sys.time() * 1000.0;
|
|
||||||
tDelta = (tEnd-tStart);
|
|
||||||
}
|
|
||||||
//public static var
|
|
||||||
public static function startProfiling(name:String):Void
|
|
||||||
{
|
|
||||||
if(profilerMap[name] == null)
|
|
||||||
profilerList.push(new HProfiler(name));
|
|
||||||
profilerMap[name].start();
|
|
||||||
}
|
|
||||||
public static function stopProfiling(name:String):Void
|
|
||||||
{
|
|
||||||
profilerMap[name].stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static var ccmd_debug_tracetimes = ConVar.registerCCmd("debug_tracetimes", (args:Array<String>) -> {
|
|
||||||
for(profiler in profilerList){
|
|
||||||
Console.devMsg(profiler.name + ": " + profiler.tDelta + "ms");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
class HProfiler{
|
|
||||||
public static function startProfiling(name:String):Void{}
|
|
||||||
public static function stopProfiling(name:String):Void{}
|
|
||||||
}
|
|
||||||
#end
|
|
||||||
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
package engine.enums.console;
|
package engine.enums;
|
||||||
|
|
||||||
enum CVarFlag{
|
enum CVarFlag{
|
||||||
FCVAR_NONE;
|
|
||||||
FCVAR_ARCHIVE;
|
FCVAR_ARCHIVE;
|
||||||
FCVAR_CHEAT;
|
FCVAR_CHEAT;
|
||||||
FVCAR_REPLICATED;
|
FVCAR_REPLICATED;
|
||||||
+1
-2
@@ -1,9 +1,8 @@
|
|||||||
package engine.enums.console;
|
package engine.enums;
|
||||||
|
|
||||||
enum CVarType {
|
enum CVarType {
|
||||||
CInt;
|
CInt;
|
||||||
CFloat;
|
CFloat;
|
||||||
CString;
|
CString;
|
||||||
CBool;
|
CBool;
|
||||||
//CCmd;
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package engine.geom;
|
|
||||||
|
|
||||||
|
|
||||||
typedef P2d = {
|
|
||||||
x:Float,
|
|
||||||
y:Float
|
|
||||||
}
|
|
||||||
@@ -1,268 +0,0 @@
|
|||||||
package engine.macros;
|
|
||||||
|
|
||||||
#if macro
|
|
||||||
import haxe.macro.Expr;
|
|
||||||
import haxe.macro.Context;
|
|
||||||
import haxe.macro.Type;
|
|
||||||
import haxe.macro.Expr.Field;
|
|
||||||
import haxe.macro.Expr.Function;
|
|
||||||
import haxe.macro.Expr.Access;
|
|
||||||
|
|
||||||
private typedef CVarMetadata = {
|
|
||||||
name:Expr,
|
|
||||||
type:String,
|
|
||||||
value:Expr,
|
|
||||||
flags:Expr,
|
|
||||||
help:Expr,
|
|
||||||
?callback:Expr
|
|
||||||
}
|
|
||||||
|
|
||||||
class ConVarDecorators {
|
|
||||||
static function extractCVarMetadata(params:Array<Expr>):CVarMetadata {
|
|
||||||
if (params == null || params.length == 0) return null;
|
|
||||||
|
|
||||||
var metadata:CVarMetadata = {
|
|
||||||
name: macro "",
|
|
||||||
type: "CString",
|
|
||||||
value: macro 0,
|
|
||||||
flags: macro "FCVAR_NONE",
|
|
||||||
help: macro "",
|
|
||||||
callback: macro null
|
|
||||||
};
|
|
||||||
|
|
||||||
switch (params[0].expr) {
|
|
||||||
case EObjectDecl(fields):
|
|
||||||
var fieldMap = [
|
|
||||||
"name" => function(expr) metadata.name = expr,
|
|
||||||
"type" => function(expr) metadata.type = switch (expr.expr) {
|
|
||||||
case EConst(CString(s)): s;
|
|
||||||
case _: "CString";
|
|
||||||
},
|
|
||||||
"value" => function(expr) metadata.value = expr,
|
|
||||||
"flags" => function(expr) metadata.flags = expr,
|
|
||||||
"help" => function(expr) metadata.help = expr,
|
|
||||||
"callback" => function(expr) metadata.callback = expr
|
|
||||||
];
|
|
||||||
|
|
||||||
for (field in fields) {
|
|
||||||
if (fieldMap.exists(field.field)) {
|
|
||||||
fieldMap[field.field](field.expr);
|
|
||||||
} else {
|
|
||||||
Context.error("Unexpected field: " + field.field, field.expr.pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
return metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process command fields
|
|
||||||
private static function processCommandField(field:Field, cmdMeta:MetadataEntry, extraFields:Array<Field>):Void {
|
|
||||||
if (!isFieldKind(field, "FFun")) {
|
|
||||||
Context.error("The @:concmd metadata can only be applied to functions", field.pos);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var pos = Context.currentPos();
|
|
||||||
var functionReference = getFunctionFromField(field);
|
|
||||||
if (functionReference == null) return;
|
|
||||||
|
|
||||||
var name = cmdMeta.params.length > 0 ? getStringFromExpr(cmdMeta.params[0]) ?? field.name : field.name;
|
|
||||||
var functionExpression = macro function(args:Array<String>) ${functionReference.expr};
|
|
||||||
|
|
||||||
var initExpr = macro {
|
|
||||||
var cmd = engine.ConVar.registerCCmd($v{name}, $functionExpression);
|
|
||||||
cmd;
|
|
||||||
};
|
|
||||||
|
|
||||||
var initName = "__init__cmd_" + name;
|
|
||||||
extraFields.push(createStaticInitField(initName, initExpr, pos));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process convar fields
|
|
||||||
private static function processConVarField(field:Field, cvarMeta:MetadataEntry, extraFields:Array<Field>):Void {
|
|
||||||
if (!isFieldKind(field, "FVar")) {
|
|
||||||
Context.error("The @:convar metadata can only be applied to variables", field.pos);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var pos = Context.currentPos();
|
|
||||||
var meta = extractCVarMetadata(cvarMeta.params);
|
|
||||||
if (meta == null) {
|
|
||||||
Context.error("Metadata extraction failed for field: " + field.name, field.pos);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var cvarName = getStringFromMetaExpr(meta.name) ?? field.name;
|
|
||||||
var fieldName = field.name;
|
|
||||||
var isStatic = hasAccess(field, AStatic);
|
|
||||||
|
|
||||||
var varType = getVarType(field);
|
|
||||||
|
|
||||||
if (isStatic) {
|
|
||||||
// Handle static fields
|
|
||||||
var staticInitExpr = macro {
|
|
||||||
var cvar = $i{fieldName} = engine.ConVar.registerCVar(
|
|
||||||
${meta.name},
|
|
||||||
${Context.parse('engine.enums.console.CVarType.' + meta.type, pos)},
|
|
||||||
${meta.value},
|
|
||||||
${Context.parse('engine.enums.console.CVarFlag.' + switch (meta.flags.expr) {
|
|
||||||
case EConst(CString(s)): s;
|
|
||||||
case _: "FCVAR_NONE";
|
|
||||||
}, pos)},
|
|
||||||
${meta.help},
|
|
||||||
${meta.callback ?? macro null}
|
|
||||||
);
|
|
||||||
trace($v{"Registered CVar: "} + $e{meta.name});
|
|
||||||
cvar;
|
|
||||||
};
|
|
||||||
|
|
||||||
extraFields.push(createStaticInitField("__init__" + cvarName, staticInitExpr, pos));
|
|
||||||
} else {
|
|
||||||
// Handle instance fields
|
|
||||||
updateFieldInitialValue(field, macro null);
|
|
||||||
|
|
||||||
var instanceInitializerExpression = macro {
|
|
||||||
if (Reflect.field(this, $v{fieldName}) == null) {
|
|
||||||
Reflect.setField(this, $v{fieldName}, engine.ConVar.registerCVar(
|
|
||||||
${meta.name},
|
|
||||||
${Context.parse('engine.enums.console.CVarType.' + meta.type, pos)},
|
|
||||||
${meta.value},
|
|
||||||
${Context.parse('engine.enums.console.CVarFlag.' + switch (meta.flags.expr) {
|
|
||||||
case EConst(CString(s)): s;
|
|
||||||
case _: "FCVAR_NONE";
|
|
||||||
}, pos)},
|
|
||||||
${meta.help},
|
|
||||||
${meta.callback ?? macro null}
|
|
||||||
));
|
|
||||||
trace($v{"Registered CVar: "} + $e{meta.name});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ensureConstructorWithInit(extraFields, instanceInitializerExpression, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map to check field kinds
|
|
||||||
private static final fieldKindMap:Map<String, haxe.macro.FieldType->Bool> = [
|
|
||||||
"FFun" => function(ft) return switch(ft) { case FFun(_): true; case _: false; },
|
|
||||||
"FVar" => function(ft) return switch(ft) { case FVar(_, _): true; case _: false; },
|
|
||||||
"FProp" => function(ft) return switch(ft) { case FProp(_, _, _, _): true; case _: false; }
|
|
||||||
];
|
|
||||||
|
|
||||||
// Utility functions
|
|
||||||
private static function isFieldKind(field:Field, kind:String):Bool {
|
|
||||||
return fieldKindMap.exists(kind) ? fieldKindMap.get(kind)(field.kind) : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function getFunctionFromField(field:Field):Function {
|
|
||||||
return switch (field.kind) {
|
|
||||||
case FFun(f): f;
|
|
||||||
case _: null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function getVarType(field:Field):ComplexType {
|
|
||||||
return switch (field.kind) {
|
|
||||||
case FVar(t, _): t;
|
|
||||||
case _: null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function updateFieldInitialValue(field:Field, expr:Expr):Void {
|
|
||||||
switch (field.kind) {
|
|
||||||
case FVar(t, _): field.kind = FVar(t, expr);
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function getStringFromExpr(expr:Expr):String {
|
|
||||||
return switch (expr.expr) {
|
|
||||||
case EConst(CString(s)): s;
|
|
||||||
case _: null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function getStringFromMetaExpr(expr:Expr):String {
|
|
||||||
return switch (expr.expr) {
|
|
||||||
case EConst(CString(s)): s;
|
|
||||||
case _: null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function hasAccess(field:Field, access:Access):Bool {
|
|
||||||
return field.access != null && field.access.indexOf(access) >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function createStaticInitField(name:String, initExpr:Expr, pos:Position):Field {
|
|
||||||
return {
|
|
||||||
name: name,
|
|
||||||
access: [AStatic],
|
|
||||||
kind: FVar(null, initExpr),
|
|
||||||
pos: pos,
|
|
||||||
doc: null,
|
|
||||||
meta: [{ name: ":keep", params: [], pos: pos }]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function ensureConstructorWithInit(fields:Array<Field>, initExpr:Expr, pos:Position):Void {
|
|
||||||
var cls = Context.getLocalClass().get();
|
|
||||||
var hasSuperClass = cls.superClass != null;
|
|
||||||
|
|
||||||
var constructor = Lambda.find(fields, function(f) return f.name == "new");
|
|
||||||
if (constructor == null) {
|
|
||||||
constructor = {
|
|
||||||
name: "new",
|
|
||||||
access: [APublic],
|
|
||||||
kind: FFun({
|
|
||||||
args: [],
|
|
||||||
expr: if (hasSuperClass) macro {
|
|
||||||
super();
|
|
||||||
$initExpr;
|
|
||||||
} else macro {
|
|
||||||
$initExpr;
|
|
||||||
},
|
|
||||||
ret: null
|
|
||||||
}),
|
|
||||||
pos: pos,
|
|
||||||
meta: []
|
|
||||||
};
|
|
||||||
fields.push(constructor);
|
|
||||||
} else {
|
|
||||||
switch (constructor.kind) {
|
|
||||||
case FFun(f):
|
|
||||||
switch(f.expr.expr) {
|
|
||||||
case EBlock(exprs):
|
|
||||||
exprs.push(initExpr);
|
|
||||||
case _:
|
|
||||||
f.expr = macro {
|
|
||||||
${f.expr};
|
|
||||||
$initExpr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case _:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static macro function build():Array<Field> {
|
|
||||||
var fields = Context.getBuildFields();
|
|
||||||
var extraFields:Array<Field> = [];
|
|
||||||
|
|
||||||
for (field in fields) {
|
|
||||||
if (field.meta == null) continue;
|
|
||||||
|
|
||||||
var cmdMeta = Lambda.find(field.meta, function(m) return m.name == ":concmd");
|
|
||||||
var cvarMeta = Lambda.find(field.meta, function(m) return m.name == ":convar");
|
|
||||||
|
|
||||||
if (cmdMeta != null) {
|
|
||||||
processCommandField(field, cmdMeta, extraFields);
|
|
||||||
} else if (cvarMeta != null && cvarMeta.params.length > 0) {
|
|
||||||
processConVarField(field, cvarMeta, extraFields);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return fields.concat(extraFields);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#end
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package engine.tools;
|
|
||||||
|
|
||||||
import lime.ui.WindowAttributes;
|
|
||||||
import openfl.Lib;
|
|
||||||
import openfl.display.Sprite;
|
|
||||||
import openfl.display.Window;
|
|
||||||
|
|
||||||
class HWindow extends Sprite{
|
|
||||||
public var window:Window;
|
|
||||||
public var attribs:WindowAttributes;
|
|
||||||
public static var windows:Array<Window> = [];
|
|
||||||
public function new(){
|
|
||||||
super();
|
|
||||||
window = Lib.application.createWindow(attribs);
|
|
||||||
windows.push(window);
|
|
||||||
}
|
|
||||||
public function initStage(spr:Sprite){
|
|
||||||
window.stage.addChild(this);
|
|
||||||
}
|
|
||||||
public function close(){
|
|
||||||
window.close();
|
|
||||||
}
|
|
||||||
public static function createEditorWindow()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
//public function open()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
package engine.tools.ui;
|
|
||||||
|
|
||||||
import game.ui.text.TextFormats;
|
|
||||||
import openfl.text.TextFormat;
|
|
||||||
import openfl.text.TextField;
|
|
||||||
import engine.ui.UIPane;
|
|
||||||
import lime.app.Event;
|
|
||||||
import openfl.display.Sprite;
|
|
||||||
import openfl.Lib;
|
|
||||||
import lime.ui.Window;
|
|
||||||
import engine.ConVar;
|
|
||||||
import game.ui.console.Console;
|
|
||||||
//import Lib.application.
|
|
||||||
|
|
||||||
|
|
||||||
typedef UINode = {
|
|
||||||
object:UIPane,
|
|
||||||
?children:Array<UINode>
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class UITool{
|
|
||||||
public static var ccmd_dev_uitool = ConVar.registerCCmd("dev_uitool", (args:Array<String>) -> { open();});
|
|
||||||
public static var uiEditorWindow:openfl.display.Window;
|
|
||||||
public static var uiEditorSprite:Sprite;
|
|
||||||
private static var tf:TextField;
|
|
||||||
public static function spawnUIEditorWindow(){
|
|
||||||
var secondWindow = Lib.application.createWindow({title: "UI Outliner"});
|
|
||||||
if(uiEditorSprite == null){
|
|
||||||
uiEditorSprite = new Sprite();
|
|
||||||
uiEditorSprite.graphics.beginFill(0x00ff00);
|
|
||||||
uiEditorSprite.graphics.drawRect(0,0,1280,960);
|
|
||||||
}
|
|
||||||
secondWindow.stage.addChild(uiEditorSprite);
|
|
||||||
uiEditorWindow = secondWindow;
|
|
||||||
secondWindow.onClose.add(()->{
|
|
||||||
uiEditorWindow = null;
|
|
||||||
});
|
|
||||||
tf = new TextField();
|
|
||||||
TextFormats.getFormats();
|
|
||||||
var tformat = TextFormats.formats.cInputFmt;
|
|
||||||
tf.setTextFormat(tformat);
|
|
||||||
tf.autoSize = LEFT;
|
|
||||||
uiEditorSprite.addChild(tf);
|
|
||||||
update([]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static var ccmd_dev_uitool_refresh = ConVar.registerCCmd("dev_uitool_refresh", update);
|
|
||||||
|
|
||||||
public static var uiNodes:Map<UIPane, UINode> = [];
|
|
||||||
public static var rootNodes:Array<UINode> = [];
|
|
||||||
public static function collect(){
|
|
||||||
for(pane in UIPane.panelist){
|
|
||||||
var node:UINode = null;
|
|
||||||
if(uiNodes[pane] == null){
|
|
||||||
node = {
|
|
||||||
object: pane,
|
|
||||||
children: []
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
node = uiNodes[pane];
|
|
||||||
}
|
|
||||||
var parentNode:UINode = null;
|
|
||||||
if(uiNodes[pane.parent] == null){
|
|
||||||
parentNode = {
|
|
||||||
object:pane.parent,
|
|
||||||
children: []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
parentNode = uiNodes[pane.parent];
|
|
||||||
}
|
|
||||||
parentNode.children.push(node);
|
|
||||||
if(pane.parent == null){
|
|
||||||
rootNodes.push(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static function update(args:Array<String>){
|
|
||||||
tf.text = "";
|
|
||||||
for(pane in UIPane.panelist){
|
|
||||||
//check if pane is toplevel
|
|
||||||
Console.devMsg("Pane: "+ pane.name);
|
|
||||||
//Get all Root UI Panes
|
|
||||||
if(pane.parent == null) {
|
|
||||||
tf.appendText("-");
|
|
||||||
tf.appendText(pane.name+"\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function open(){
|
|
||||||
if(uiEditorWindow == null){
|
|
||||||
spawnUIEditorWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
public static function close(){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
package engine.typedefs.console;
|
package engine.typedefs;
|
||||||
|
|
||||||
import engine.typedefs.console.CVar;
|
import engine.typedefs.CVar;
|
||||||
|
|
||||||
|
|
||||||
typedef CCmd = {
|
typedef CCmd = {
|
||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
package engine.typedefs.console;
|
package engine.typedefs;
|
||||||
|
|
||||||
import engine.enums.console.CVarType;
|
import engine.enums.CVarType;
|
||||||
import engine.enums.console.CVarFlag;
|
import engine.enums.CVarFlag;
|
||||||
|
|
||||||
typedef CVar = {
|
typedef CVar = {
|
||||||
var name:String;
|
var name:String;
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package engine.ui;
|
|
||||||
|
|
||||||
import engine.geom.Geom.P2d;
|
|
||||||
import engine.ui.UIPane.PaneDimensions;
|
|
||||||
import openfl.display.DisplayObject;
|
|
||||||
|
|
||||||
class UIElement extends UIPane
|
|
||||||
{
|
|
||||||
public var dispObj:DisplayObject;
|
|
||||||
public var padding:P2d;
|
|
||||||
public function new(_name:String, _dimensions:PaneDimensions, _displayObject:DisplayObject)
|
|
||||||
{
|
|
||||||
super(_name, _dimensions);
|
|
||||||
dispObj = _displayObject;
|
|
||||||
sprite.addChild(dispObj);
|
|
||||||
}
|
|
||||||
override public function onResize(){
|
|
||||||
super.onResize();
|
|
||||||
resizeDisplayObject();
|
|
||||||
}
|
|
||||||
public function resizeDisplayObject(){
|
|
||||||
if(padding == null)
|
|
||||||
padding = {x:0,y:0};
|
|
||||||
dispObj.width = this.dimensions.width - padding.x;
|
|
||||||
dispObj.height = this.dimensions.height - padding.y;
|
|
||||||
dispObj.x = padding.x / 2;
|
|
||||||
dispObj.y = padding.y / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,334 +0,0 @@
|
|||||||
package engine.ui;
|
|
||||||
|
|
||||||
// __ __ _____ ______
|
|
||||||
// | | | | / ___ \ | ____|
|
|
||||||
// | |____| | | / _\_| | |____
|
|
||||||
// | ____ | | | |_ \ | ____|
|
|
||||||
// | | | | | \__/ | | |____
|
|
||||||
// |__| |__| \______/ |______|
|
|
||||||
|
|
||||||
/*
|
|
||||||
/ file: UIPane.hx
|
|
||||||
/ author: and.schaafsma@gmail.com
|
|
||||||
/ purpose: Class for resizable and scalable UI Panels
|
|
||||||
/ My hope is that this code is so awful I'm never allowed to write UI code again.
|
|
||||||
*/
|
|
||||||
import game.ui.console.Console;
|
|
||||||
import openfl.display.Sprite;
|
|
||||||
import openfl.display.BitmapData;
|
|
||||||
import openfl.display.DisplayObject;
|
|
||||||
import openfl.text.TextField;
|
|
||||||
import engine.ConVar;
|
|
||||||
import engine.geom.Geom.P2d;
|
|
||||||
|
|
||||||
enum abstract PaneLayout(Int) {
|
|
||||||
var HORIZONTAL = 0;
|
|
||||||
var VERTICAL = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum PaneAnchor {
|
|
||||||
LEFT;
|
|
||||||
TOPLEFT;
|
|
||||||
TOP;
|
|
||||||
TOPRIGHT;
|
|
||||||
RIGHT;
|
|
||||||
BOTTOMLEFT;
|
|
||||||
BOTTOM;
|
|
||||||
BOTTOMRIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum ExpandBehavior {
|
|
||||||
// ABSOLUTE;
|
|
||||||
FACTOR(f:Float);
|
|
||||||
// CONTENT;
|
|
||||||
STRETCH;
|
|
||||||
// FILL;
|
|
||||||
// FIT;
|
|
||||||
NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum PaneAlign {
|
|
||||||
START;
|
|
||||||
END;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef PaneDimensions = {
|
|
||||||
var width:Float;
|
|
||||||
var height:Float;
|
|
||||||
@:optional var expandBehavior:ExpandBehavior;
|
|
||||||
@:optional var minWidth:Float;
|
|
||||||
@:optional var minHeight:Float;
|
|
||||||
@:optional var maxWidth:Float;
|
|
||||||
@:optional var maxHeight:Float;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef PaneProps = {
|
|
||||||
dimensions:PaneDimensions,
|
|
||||||
layout:PaneLayout
|
|
||||||
}
|
|
||||||
|
|
||||||
class UIPane {
|
|
||||||
public var name:String;
|
|
||||||
public var sprite:Sprite;
|
|
||||||
public var x(get, set):Float;
|
|
||||||
public var y(get, set):Float;
|
|
||||||
|
|
||||||
function get_x() {
|
|
||||||
return sprite.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
function set_x(x) {
|
|
||||||
return sprite.x = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_y() {
|
|
||||||
return sprite.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
function set_y(y) {
|
|
||||||
return sprite.y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public var dimensions:PaneDimensions;
|
|
||||||
public var width(get, set):Float;
|
|
||||||
|
|
||||||
function get_width() {
|
|
||||||
return dimensions.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
function set_width(width) {
|
|
||||||
dimensions.width = width;
|
|
||||||
onResize();
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public var height(get, set):Float;
|
|
||||||
|
|
||||||
function get_height() {
|
|
||||||
return dimensions.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
function set_height(height) {
|
|
||||||
dimensions.height = height;
|
|
||||||
onResize();
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public var layout:PaneLayout;
|
|
||||||
public var autoArrange:Bool = true;
|
|
||||||
public var autoArrangeChildren = true;
|
|
||||||
public var expand:Bool;
|
|
||||||
public var children:Array<UIPane> = [];
|
|
||||||
public var parent:UIPane = null;
|
|
||||||
public var align:PaneAlign = START;
|
|
||||||
public var maskSprite:Sprite;
|
|
||||||
|
|
||||||
public static var panelist:Array<UIPane> = [];
|
|
||||||
|
|
||||||
public function new(_name:String, _dimensions:PaneDimensions) {
|
|
||||||
// Set name
|
|
||||||
name = _name;
|
|
||||||
// Set dimensions
|
|
||||||
if (_dimensions != null) {
|
|
||||||
dimensions = _dimensions;
|
|
||||||
} else {
|
|
||||||
dimensions = {
|
|
||||||
width: 0,
|
|
||||||
height: 0,
|
|
||||||
minWidth: 0,
|
|
||||||
minHeight: 0,
|
|
||||||
maxWidth: 0,
|
|
||||||
maxHeight: 0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (name == null || name == "") {
|
|
||||||
Console.devMsg("UI Pane name init error");
|
|
||||||
}
|
|
||||||
// Initialize Sprite
|
|
||||||
initSprite();
|
|
||||||
// Draw debug pane for visualizing
|
|
||||||
drawDebugPane();
|
|
||||||
panelist.push(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static var ccmd_ui_redraw = ConVar.registerCCmd("ui_redraw", (args:Array<String>) -> {
|
|
||||||
redrawUIPanes();
|
|
||||||
});
|
|
||||||
|
|
||||||
public static function redrawUIPanes() {
|
|
||||||
for (pane in panelist) {
|
|
||||||
pane.redraw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAnchorOffset(anchor:PaneAnchor):P2d {
|
|
||||||
switch (anchor) {
|
|
||||||
case LEFT:
|
|
||||||
return {x: 0, y: (height / 2)};
|
|
||||||
case TOPLEFT:
|
|
||||||
return {x: 0, y: 0};
|
|
||||||
case TOP:
|
|
||||||
return {x: width / 2, y: 0};
|
|
||||||
case TOPRIGHT:
|
|
||||||
return {x: width, y: 0};
|
|
||||||
case RIGHT:
|
|
||||||
return {x: width, y: height / 2}
|
|
||||||
case BOTTOMRIGHT:
|
|
||||||
return {x: width, y: height};
|
|
||||||
case BOTTOM:
|
|
||||||
return {x: width / 2, y: height};
|
|
||||||
case BOTTOMLEFT:
|
|
||||||
return {x: 0, y: height};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function initSprite():Void {
|
|
||||||
// Construct Sprite object
|
|
||||||
sprite = new Sprite();
|
|
||||||
|
|
||||||
// Draw mask
|
|
||||||
maskSprite = new Sprite();
|
|
||||||
drawMask();
|
|
||||||
sprite.addChild(maskSprite);
|
|
||||||
sprite.mask = maskSprite;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function drawMask():Void {
|
|
||||||
maskSprite.graphics.clear();
|
|
||||||
maskSprite.graphics.beginFill(0xffffff);
|
|
||||||
maskSprite.graphics.drawRect(0, 0, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function drawDebugPane() {
|
|
||||||
// Clear graphics
|
|
||||||
sprite.graphics.clear();
|
|
||||||
// Create objects we need to draw.
|
|
||||||
var label:TextField = new TextField();
|
|
||||||
var bmp = new BitmapData(Std.int(width), Std.int(height), true, 0x00000000);
|
|
||||||
// Set textfield text to the panel name
|
|
||||||
label.text = name;
|
|
||||||
// Draw textfield to bitmap
|
|
||||||
bmp.draw(label);
|
|
||||||
// Draw graphics
|
|
||||||
sprite.graphics.beginFill(Std.int(Math.random() * 0xffffff), 0.5);
|
|
||||||
sprite.graphics.drawRect(0, 0, dimensions.width, dimensions.height);
|
|
||||||
sprite.graphics.beginBitmapFill(bmp, null);
|
|
||||||
sprite.graphics.drawRect(0, 0, dimensions.width, dimensions.height);
|
|
||||||
// Visualize Anchor Points
|
|
||||||
if (false) {
|
|
||||||
sprite.graphics.beginFill(Std.int(Math.random() * 0xffffff), 0.5);
|
|
||||||
sprite.graphics.drawCircle(getAnchorOffset(TOPLEFT).x, getAnchorOffset(TOPLEFT).y, 5);
|
|
||||||
sprite.graphics.drawCircle(getAnchorOffset(TOP).x, getAnchorOffset(TOP).y, 5);
|
|
||||||
sprite.graphics.drawCircle(getAnchorOffset(TOPRIGHT).x, getAnchorOffset(TOPRIGHT).y, 5);
|
|
||||||
sprite.graphics.drawCircle(getAnchorOffset(RIGHT).x, getAnchorOffset(RIGHT).y, 5);
|
|
||||||
sprite.graphics.drawCircle(getAnchorOffset(BOTTOMRIGHT).x, getAnchorOffset(BOTTOMRIGHT).y, 5);
|
|
||||||
sprite.graphics.drawCircle(getAnchorOffset(BOTTOM).x, getAnchorOffset(BOTTOM).y, 5);
|
|
||||||
sprite.graphics.drawCircle(getAnchorOffset(BOTTOMLEFT).x, getAnchorOffset(BOTTOMLEFT).y, 5);
|
|
||||||
sprite.graphics.drawCircle(getAnchorOffset(LEFT).x, getAnchorOffset(LEFT).y, 5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public var endOffset:Float = 0;
|
|
||||||
public var startOffset:Float = 0;
|
|
||||||
|
|
||||||
public function addChild(child:UIPane) {
|
|
||||||
if (child.parent != null)
|
|
||||||
throw "Attempting to attach child UIPane that already has a parent";
|
|
||||||
children.push(child);
|
|
||||||
sprite.addChild(child.sprite);
|
|
||||||
child.parent = this;
|
|
||||||
if (child.autoArrange && autoArrangeChildren) {
|
|
||||||
arrangeChild(child);
|
|
||||||
}
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function redraw():Void {
|
|
||||||
drawDebugPane();
|
|
||||||
drawMask();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onResize() {
|
|
||||||
redraw();
|
|
||||||
if (autoArrangeChildren) {
|
|
||||||
arrangeChildren();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function arrangeChild(child:UIPane) {
|
|
||||||
// We do not arrange the
|
|
||||||
if (!child.autoArrange) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (endOffset == 0) {
|
|
||||||
switch (layout) {
|
|
||||||
case HORIZONTAL:
|
|
||||||
endOffset = width;
|
|
||||||
case VERTICAL:
|
|
||||||
endOffset = height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var offsetDiff:Float = endOffset - startOffset;
|
|
||||||
// Set child dimensions
|
|
||||||
switch (child.dimensions.expandBehavior) {
|
|
||||||
case STRETCH:
|
|
||||||
switch (layout) {
|
|
||||||
case HORIZONTAL:
|
|
||||||
child.width = offsetDiff;
|
|
||||||
child.height = height;
|
|
||||||
case VERTICAL:
|
|
||||||
child.width = width;
|
|
||||||
child.height = offsetDiff;
|
|
||||||
}
|
|
||||||
case FACTOR(f):
|
|
||||||
switch (layout) {
|
|
||||||
case HORIZONTAL:
|
|
||||||
child.width = width * f;
|
|
||||||
child.height = height;
|
|
||||||
case VERTICAL:
|
|
||||||
child.width = width;
|
|
||||||
child.height = height * f;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
switch (layout) {
|
|
||||||
case HORIZONTAL:
|
|
||||||
// do some shit
|
|
||||||
child.height = height;
|
|
||||||
case VERTICAL:
|
|
||||||
// do some other shit
|
|
||||||
child.width = width;
|
|
||||||
default:
|
|
||||||
child.height = child.height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Set child position
|
|
||||||
switch (child.align) {
|
|
||||||
case START:
|
|
||||||
switch (layout) {
|
|
||||||
case HORIZONTAL:
|
|
||||||
child.x = startOffset;
|
|
||||||
startOffset += child.width;
|
|
||||||
case VERTICAL:
|
|
||||||
child.y = startOffset;
|
|
||||||
startOffset += child.height;
|
|
||||||
}
|
|
||||||
case END:
|
|
||||||
switch (layout) {
|
|
||||||
case HORIZONTAL:
|
|
||||||
child.x = endOffset -= child.width;
|
|
||||||
case VERTICAL:
|
|
||||||
child.y = endOffset -= child.height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function arrangeChildren() {
|
|
||||||
// reset offsets
|
|
||||||
startOffset = 0;
|
|
||||||
endOffset = 0;
|
|
||||||
// arrance each child
|
|
||||||
for (child in children) {
|
|
||||||
arrangeChild(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
-21
@@ -1,22 +1,14 @@
|
|||||||
package game;
|
package game;
|
||||||
|
|
||||||
|
import engine.typedefs.CVar;
|
||||||
|
import game.entities.Player;
|
||||||
import openfl.display.Stage;
|
import openfl.display.Stage;
|
||||||
import openfl.display.Sprite;
|
import openfl.display.Sprite;
|
||||||
import openfl.events.Event;
|
import openfl.events.Event;
|
||||||
|
|
||||||
import engine.HProfiler;
|
|
||||||
import engine.ConVar;
|
|
||||||
import engine.ui.UIPane;
|
|
||||||
import engine.typedefs.console.CVar;
|
|
||||||
import engine.tools.ui.UITool;
|
|
||||||
|
|
||||||
import game.ui.console.ConsolePane;
|
|
||||||
import game.entities.Player;
|
|
||||||
import game.ui.console.Console;
|
|
||||||
|
|
||||||
|
|
||||||
import assets.HTex;
|
|
||||||
import assets.Scanner;
|
import assets.Scanner;
|
||||||
|
import assets.HTex;
|
||||||
|
import game.ui.ConVar;
|
||||||
|
import game.ui.console.Console;
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
@@ -25,12 +17,12 @@ class Game
|
|||||||
public var uiLayer:Sprite;
|
public var uiLayer:Sprite;
|
||||||
public function new(_stage:Stage){
|
public function new(_stage:Stage){
|
||||||
stage = _stage;
|
stage = _stage;
|
||||||
#if PRECACHE_ASSETS & sys
|
/*
|
||||||
Scanner.scanTextureDir();
|
Scanner.scanTextureDir();
|
||||||
for(tex in Scanner.textures){
|
for(tex in Scanner.textures){
|
||||||
HTex.createTextureObjectFromJSON(tex);
|
HTex.createTextureObjectFromJSON(tex);
|
||||||
}
|
}
|
||||||
#end
|
*/
|
||||||
gameLayer = new Sprite();
|
gameLayer = new Sprite();
|
||||||
uiLayer = new Sprite();
|
uiLayer = new Sprite();
|
||||||
trace("wattafak");
|
trace("wattafak");
|
||||||
@@ -40,23 +32,32 @@ class Game
|
|||||||
public function loadData():Void
|
public function loadData():Void
|
||||||
{
|
{
|
||||||
new game.ui.text.TextFormats();
|
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);
|
||||||
stage.addChild(uiLayer);
|
stage.addChild(uiLayer);
|
||||||
var console2:ConsolePane = new ConsolePane();
|
//player.graphics.lineStyle(2,0xFF0000);
|
||||||
uiLayer.addChild(console2);
|
//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);
|
||||||
HProfiler.startProfiling("frametime");
|
var cvar_cl_kankerlow:CVar = ConVar.registerCVar("cl_kankerlow", CInt, 10, FCVAR_ARCHIVE, "is de speler een kankerlow?",null,false,false,0,0,false);
|
||||||
//UITool.spawnUIEditorWindow();
|
//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
|
||||||
{
|
{
|
||||||
HProfiler.stopProfiling("frametime");
|
|
||||||
HProfiler.startProfiling("frametime");
|
|
||||||
Input.onEnterFrame();
|
Input.onEnterFrame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+29
-69
@@ -1,36 +1,25 @@
|
|||||||
package game;
|
package game;
|
||||||
|
|
||||||
import openfl.text.TextField;
|
import engine.enums.CVarFlag;
|
||||||
|
import engine.typedefs.CCmd;
|
||||||
|
import game.ui.console.Console;
|
||||||
|
import game.video.Mode;
|
||||||
import openfl.events.KeyboardEvent;
|
import openfl.events.KeyboardEvent;
|
||||||
import openfl.ui.Keyboard in Kb;
|
import openfl.ui.Keyboard in Kb;
|
||||||
import openfl.Lib;
|
import openfl.Lib;
|
||||||
|
import engine.enums.CVarType;
|
||||||
|
import engine.typedefs.CVar;
|
||||||
|
import game.ui.ConVar;
|
||||||
|
|
||||||
import engine.enums.console.CVarFlag;
|
|
||||||
import engine.enums.console.CVarType;
|
|
||||||
import engine.typedefs.console.CCmd;
|
|
||||||
import engine.typedefs.console.CVar;
|
|
||||||
import engine.ConVar;
|
|
||||||
|
|
||||||
import game.ui.console.Console;
|
|
||||||
import game.video.Mode;
|
|
||||||
|
|
||||||
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> = ["~" => "toggleconsole", "\\" => "toggleconsole", "1" => "echo kak", "2" => "+attack"];
|
public static var bindMap:Map<String, String> = [];
|
||||||
@:convar({
|
//public static var bind:CVar = Convar.registerCVar("bind",CVarType.cCmd, null, ()->{
|
||||||
name: "cl_debuginput",
|
//
|
||||||
type: CVarType.CInt,
|
//});
|
||||||
value: 0,
|
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);
|
||||||
flags: CVarFlag.None,
|
|
||||||
help: "print debug messages related to input to console",
|
|
||||||
callback: function() {
|
|
||||||
trace("Debug input changed");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
public static var cv_debugKeys:CVar;
|
|
||||||
|
|
||||||
// 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",
|
||||||
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",
|
||||||
@@ -57,16 +46,9 @@ 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)){
|
|
||||||
// Check if not null so we don't end up cooming all over unallocated memory;
|
|
||||||
if(bindMap[keyNameMap[e.keyCode]] != null)
|
|
||||||
Console.consoleInstance.parseCmd(bindMap[keyNameMap[e.keyCode]]);
|
|
||||||
}
|
|
||||||
if(!keys[e.keyCode]){
|
if(!keys[e.keyCode]){
|
||||||
if(cv_debugKeys.value == 1)
|
if(cv_debugKeys.value > 0)
|
||||||
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];
|
||||||
@@ -74,43 +56,27 @@ class Input{
|
|||||||
|
|
||||||
}
|
}
|
||||||
public static function onKeyIsUp(e:KeyboardEvent){
|
public static function onKeyIsUp(e:KeyboardEvent){
|
||||||
if(!Std.isOfType(Lib.current.stage.focus,TextField)){
|
|
||||||
// Make sure we're not checking a null value (this can cause a crash)
|
|
||||||
if(bindMap[keyNameMap[e.keyCode]] != null){
|
|
||||||
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 bindKey(input:String, action:String):Void
|
|
||||||
{
|
{
|
||||||
bindMap[input] = action;
|
return keyNameMap[key];
|
||||||
}
|
}
|
||||||
private static var bind:CCmd = ConVar.registerCCmd("bind", (cArgs:Array<String>)->{
|
// public static function bind(input:Dynamic, action:String):Void
|
||||||
cArgs[0] = cArgs[0].toUpperCase();
|
// {
|
||||||
if(cArgs.length == 2){
|
// var key:Int;
|
||||||
if(keyCodeMap[cArgs[0]]!= null) {
|
// if(Std.is(input,Int)){
|
||||||
if(cArgs[1].indexOf('"') == 0 && cArgs[1].lastIndexOf('"') == cArgs[1].length-1){
|
// key = input;
|
||||||
bindKey(cArgs[0], cArgs[1].substring(1,cArgs[1].length-1));
|
// }
|
||||||
}
|
// else if(Std.is(input, String)){
|
||||||
else{
|
// var value:String = input;
|
||||||
bindKey(cArgs[0], cArgs[1]);
|
// key = keyCodeMap[value.toUpperCase()];
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
// }
|
||||||
}
|
private static var bind:CCmd = ConVar.registerCCmd("bind", (cArgs:Array<String>)->{
|
||||||
else if(cArgs.length == 1){
|
|
||||||
Console.devMsg(bindMap[cArgs[0]]);
|
ConVar.runCmd("echo",cArgs);
|
||||||
}
|
|
||||||
else{
|
|
||||||
Console.devMsg("usage: bind <key> <command>");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
public static function onEnterFrame()
|
public static function onEnterFrame()
|
||||||
{
|
{
|
||||||
@@ -133,12 +99,6 @@ 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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package game.ui;
|
||||||
|
|
||||||
|
|
||||||
|
typedef CVar = {
|
||||||
|
var name:String;
|
||||||
|
var type:CVarType;
|
||||||
|
var value:Dynamic;
|
||||||
|
@:optional var callback:Void -> Void;
|
||||||
|
};
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package game.ui;
|
||||||
|
|
||||||
|
enum CVarType {
|
||||||
|
CInt;
|
||||||
|
CFloat;
|
||||||
|
CString;
|
||||||
|
CBool;
|
||||||
|
CCmd;
|
||||||
|
}
|
||||||
@@ -1,17 +1,14 @@
|
|||||||
package engine;
|
package game.ui;
|
||||||
|
|
||||||
import engine.typedefs.console.CVar;
|
import haxe.Constraints.Function;
|
||||||
import engine.typedefs.console.CCmd;
|
import engine.typedefs.CVar;
|
||||||
import engine.enums.console.CVarType;
|
import engine.typedefs.CCmd;
|
||||||
import engine.enums.console.CVarFlag;
|
import engine.enums.CVarType;
|
||||||
|
import engine.enums.CVarFlag;
|
||||||
import game.ui.console.Console;
|
import game.ui.console.Console;
|
||||||
|
|
||||||
import engine.ConVars_Engine;
|
|
||||||
|
|
||||||
class ConVar{
|
class ConVar{
|
||||||
// Hush the compiler about unused import
|
|
||||||
// static var ConVars_Engine:Class<ConVars_Engine> = ConVars_Engine;
|
|
||||||
|
|
||||||
static var CVarMap:Map<String, CVar> = [];
|
static var CVarMap:Map<String, CVar> = [];
|
||||||
static var CCmdMap:Map<String, CCmd> = [];
|
static var CCmdMap:Map<String, CCmd> = [];
|
||||||
/**
|
/**
|
||||||
@@ -30,7 +27,7 @@ class ConVar{
|
|||||||
*/
|
*/
|
||||||
public static inline function registerCVar(_name:String, _type:CVarType, _value:Dynamic, ?_flags:CVarFlag, ?_helpString:String = "", ?_callback:Void->Void, ?_callOnCreate:Bool=false, _bMin:Bool=false, _fMin:Float=0, _fMax:Float=0, _bMax:Bool = false):CVar
|
public static inline function registerCVar(_name:String, _type:CVarType, _value:Dynamic, ?_flags:CVarFlag, ?_helpString:String = "", ?_callback:Void->Void, ?_callOnCreate:Bool=false, _bMin:Bool=false, _fMin:Float=0, _fMax:Float=0, _bMax:Bool = false):CVar
|
||||||
{
|
{
|
||||||
if(CVarMap[_name]!=null || CCmdMap[_name]!= null){
|
if(CVarMap[_name]!=null || CCmdMap[_name]!=null){
|
||||||
Console.devMsg("Tried setting already defined convar: " + _name + ", returning null instead");
|
Console.devMsg("Tried setting already defined convar: " + _name + ", returning null instead");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -67,10 +64,6 @@ class ConVar{
|
|||||||
}
|
}
|
||||||
public static inline function setCVar(_name:String, _value:Dynamic):Void
|
public static inline function setCVar(_name:String, _value:Dynamic):Void
|
||||||
{
|
{
|
||||||
if(CVarMap == null){
|
|
||||||
Console.devMsg("CVarMap is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var cv = getCVar(_name);
|
var cv = getCVar(_name);
|
||||||
if(cv != null){
|
if(cv != null){
|
||||||
switch(cv.type){
|
switch(cv.type){
|
||||||
@@ -150,13 +143,20 @@ class ConVar{
|
|||||||
});
|
});
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
public static var cmdList:CCmd = ConVar.registerCCmd("list", (cArgs:Array<String>)->{
|
||||||
|
var keys:Array<String> = getCVarNames();
|
||||||
|
for(key in keys){
|
||||||
|
if(CVarMap[key] != null){
|
||||||
|
Console.devMsg(key+" "+CVarMap[key].value);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Console.devMsg(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
public static inline function getCVar(_name:String):CVar
|
public static inline function getCVar(_name:String):CVar
|
||||||
{
|
{
|
||||||
return CVarMap[_name];
|
return CVarMap[_name];
|
||||||
}
|
}
|
||||||
public static inline function getCVarMap():Map<String, CVar>
|
|
||||||
{
|
|
||||||
return CVarMap;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,258 @@
|
|||||||
|
package game.ui;
|
||||||
|
|
||||||
|
import openfl.display.Sprite;
|
||||||
|
import openfl.display.BitmapData;
|
||||||
|
import openfl.display.DisplayObject;
|
||||||
|
import openfl.text.TextField;
|
||||||
|
|
||||||
|
typedef P2d = {
|
||||||
|
x:Float,
|
||||||
|
y:Float
|
||||||
|
}
|
||||||
|
enum PaneLayout{
|
||||||
|
HORIZONTAL;
|
||||||
|
VERTICAL;
|
||||||
|
}
|
||||||
|
enum PaneAnchor{
|
||||||
|
LEFT;
|
||||||
|
TOPLEFT;
|
||||||
|
TOP;
|
||||||
|
TOPRIGHT;
|
||||||
|
RIGHT;
|
||||||
|
BOTTOMLEFT;
|
||||||
|
BOTTOM;
|
||||||
|
BOTTOMRIGHT;
|
||||||
|
}
|
||||||
|
enum ExpandBehavior{
|
||||||
|
FACTOR;
|
||||||
|
ABSOLUTE;
|
||||||
|
STRETCH;
|
||||||
|
FILL;
|
||||||
|
FIT;
|
||||||
|
NONE;
|
||||||
|
}
|
||||||
|
enum PaneAlign{
|
||||||
|
START;
|
||||||
|
END;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef PaneDimensions = {
|
||||||
|
var width:Float;
|
||||||
|
var height:Float;
|
||||||
|
@:optional var expandBehavior:ExpandBehavior;
|
||||||
|
@:optional var minWidth:Float;
|
||||||
|
@:optional var minHeight:Float;
|
||||||
|
@:optional var maxWidth:Float;
|
||||||
|
@:optional var maxHeight:Float;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef PaneProps = {
|
||||||
|
dimensions:PaneDimensions,
|
||||||
|
layout:PaneLayout
|
||||||
|
}
|
||||||
|
|
||||||
|
class UIPane{
|
||||||
|
public var name:String;
|
||||||
|
public var sprite:Sprite;
|
||||||
|
public var x(get, set):Float;
|
||||||
|
public var y(get, set):Float;
|
||||||
|
function get_x(){ return sprite.x; }
|
||||||
|
function set_x(x){ return sprite.x = x; }
|
||||||
|
function get_y(){ return sprite.y; }
|
||||||
|
function set_y(y){ return sprite.y = y; }
|
||||||
|
public var dimensions:PaneDimensions;
|
||||||
|
public var width(get,set):Float;
|
||||||
|
function get_width(){
|
||||||
|
return dimensions.width;
|
||||||
|
}
|
||||||
|
function set_width(width){
|
||||||
|
dimensions.width = width;
|
||||||
|
onResize();
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
public var height(get,set):Float;
|
||||||
|
function get_height(){
|
||||||
|
return dimensions.height;
|
||||||
|
}
|
||||||
|
function set_height(height){
|
||||||
|
dimensions.height = height;
|
||||||
|
onResize();
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
public var layout:PaneLayout;
|
||||||
|
public var autoArrange:Bool = true;
|
||||||
|
public var autoArrangeChildren = true;
|
||||||
|
public var expand:Bool;
|
||||||
|
public var children:Array<UIPane> = [];
|
||||||
|
public var parent:UIPane = null;
|
||||||
|
public var align:PaneAlign = START;
|
||||||
|
public var maskSprite:Sprite;
|
||||||
|
public function new(_name:String, _dimensions:PaneDimensions)
|
||||||
|
{
|
||||||
|
// Set name
|
||||||
|
name = _name;
|
||||||
|
// Set dimensions
|
||||||
|
if(_dimensions != null){
|
||||||
|
dimensions = _dimensions;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
dimensions = {
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
minWidth: 0,
|
||||||
|
minHeight: 0,
|
||||||
|
maxWidth: 0,
|
||||||
|
maxHeight: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize Sprite
|
||||||
|
initSprite();
|
||||||
|
// Draw debug pane for visualizing
|
||||||
|
//drawDebugPane();
|
||||||
|
}
|
||||||
|
public function getAnchorOffset(anchor:PaneAnchor):P2d
|
||||||
|
{
|
||||||
|
switch(anchor){
|
||||||
|
case LEFT:
|
||||||
|
return {x:0,y:(height/2)};
|
||||||
|
case TOPLEFT:
|
||||||
|
return {x:0, y:0};
|
||||||
|
case TOP:
|
||||||
|
return {x:width/2,y:0};
|
||||||
|
case TOPRIGHT:
|
||||||
|
return {x:width, y:0};
|
||||||
|
case RIGHT:
|
||||||
|
return {x:width, y:height/2}
|
||||||
|
case BOTTOMRIGHT:
|
||||||
|
return {x:width, y:height};
|
||||||
|
case BOTTOM:
|
||||||
|
return {x:width/2, y:height};
|
||||||
|
case BOTTOMLEFT:
|
||||||
|
return {x:0, y:height};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function initSprite():Void
|
||||||
|
{
|
||||||
|
|
||||||
|
// Construct Sprite object
|
||||||
|
sprite = new Sprite();
|
||||||
|
|
||||||
|
// Draw mask
|
||||||
|
//maskSprite = new Sprite();
|
||||||
|
//drawMask();
|
||||||
|
//sprite.addChild(maskSprite);
|
||||||
|
//sprite.mask = maskSprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function drawMask():Void
|
||||||
|
{
|
||||||
|
maskSprite.graphics.clear();
|
||||||
|
maskSprite.graphics.beginFill(0xffffff);
|
||||||
|
maskSprite.graphics.drawRect(0,0,width,height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function drawDebugPane()
|
||||||
|
{
|
||||||
|
// Clear graphics
|
||||||
|
sprite.graphics.clear();
|
||||||
|
// Create objects we need to draw.
|
||||||
|
var label:TextField = new TextField();
|
||||||
|
var bmp = new BitmapData(Std.int(width),Std.int(height),true,0x00000000);
|
||||||
|
// Set textfield text to the panel name
|
||||||
|
label.text = name;
|
||||||
|
// Draw textfield to bitmap
|
||||||
|
bmp.draw(label);
|
||||||
|
// Draw graphics
|
||||||
|
sprite.graphics.beginFill(Std.int(Math.random()*0xffffff),0.5);
|
||||||
|
sprite.graphics.drawRect(0,0,dimensions.width,dimensions.height);
|
||||||
|
sprite.graphics.beginBitmapFill(bmp,null);
|
||||||
|
sprite.graphics.drawRect(0,0,dimensions.width,dimensions.height);
|
||||||
|
|
||||||
|
if(true){
|
||||||
|
sprite.graphics.beginFill(Std.int(Math.random()*0xffffff),0.5);
|
||||||
|
sprite.graphics.drawCircle(getAnchorOffset(TOPLEFT).x,getAnchorOffset(TOPLEFT).y,5);
|
||||||
|
sprite.graphics.drawCircle(getAnchorOffset(TOP).x,getAnchorOffset(TOP).y,5);
|
||||||
|
sprite.graphics.drawCircle(getAnchorOffset(TOPRIGHT).x,getAnchorOffset(TOPRIGHT).y,5);
|
||||||
|
sprite.graphics.drawCircle(getAnchorOffset(RIGHT).x,getAnchorOffset(RIGHT).y,5);
|
||||||
|
sprite.graphics.drawCircle(getAnchorOffset(BOTTOMRIGHT).x,getAnchorOffset(BOTTOMRIGHT).y,5);
|
||||||
|
sprite.graphics.drawCircle(getAnchorOffset(BOTTOM).x,getAnchorOffset(BOTTOM).y,5);
|
||||||
|
sprite.graphics.drawCircle(getAnchorOffset(BOTTOMLEFT).x,getAnchorOffset(BOTTOMLEFT).y,5);
|
||||||
|
sprite.graphics.drawCircle(getAnchorOffset(LEFT).x,getAnchorOffset(LEFT).y,5);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public var endOffset:Float = 0;
|
||||||
|
public var startOffset:Float = 0;
|
||||||
|
public function addChild(child:UIPane)
|
||||||
|
{
|
||||||
|
children.push(child);
|
||||||
|
sprite.addChild(child.sprite);
|
||||||
|
child.parent = this;
|
||||||
|
if(child.autoArrange && autoArrangeChildren){
|
||||||
|
arrangeChild(child);
|
||||||
|
}
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
public function redraw():Void
|
||||||
|
{
|
||||||
|
//drawDebugPane();
|
||||||
|
//drawMask();
|
||||||
|
}
|
||||||
|
public function onResize(){
|
||||||
|
redraw();
|
||||||
|
if(autoArrangeChildren){
|
||||||
|
arrangeChildren();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private function arrangeChild(child:UIPane){
|
||||||
|
if(child.autoArrange){
|
||||||
|
switch(layout){
|
||||||
|
case HORIZONTAL:
|
||||||
|
if(endOffset == 0) endOffset = width;
|
||||||
|
switch(child.dimensions.expandBehavior){
|
||||||
|
case STRETCH:
|
||||||
|
child.width = endOffset-startOffset;
|
||||||
|
child.height = height;
|
||||||
|
default:
|
||||||
|
child.height = height;
|
||||||
|
//
|
||||||
|
}
|
||||||
|
switch(child.align){
|
||||||
|
case START:
|
||||||
|
child.x = startOffset;
|
||||||
|
startOffset += child.width;
|
||||||
|
case END:
|
||||||
|
child.x = endOffset-= child.width;
|
||||||
|
}
|
||||||
|
case VERTICAL:
|
||||||
|
if(endOffset == 0) endOffset = height;
|
||||||
|
switch(child.dimensions.expandBehavior){
|
||||||
|
case STRETCH:
|
||||||
|
child.height = endOffset-startOffset;
|
||||||
|
child.width = width;
|
||||||
|
default:
|
||||||
|
child.width = width;
|
||||||
|
//
|
||||||
|
}
|
||||||
|
switch(child.align){
|
||||||
|
case START:
|
||||||
|
child.y = startOffset;
|
||||||
|
startOffset += child.height;
|
||||||
|
case END:
|
||||||
|
child.y = endOffset-=child.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function arrangeChildren(){
|
||||||
|
startOffset = 0;
|
||||||
|
endOffset = 0;
|
||||||
|
for(child in children){
|
||||||
|
arrangeChild(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
package game.ui.console;
|
package game.ui.console;
|
||||||
|
|
||||||
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;
|
||||||
@@ -11,388 +9,373 @@ 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;
|
||||||
import engine.ConVar;
|
// Engine Imports
|
||||||
import engine.enums.console.CVarFlag;
|
import engine.enums.CVarFlag;
|
||||||
import engine.typedefs.console.CVar;
|
import engine.typedefs.CVar;
|
||||||
import engine.typedefs.console.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 engine.ui.UIPane;
|
import game.ui.UIPane;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
@:convar({
|
class Console extends Sprite{
|
||||||
name: "mat_consolebg",
|
public var textFormat:TextFormat;
|
||||||
type: "CString",
|
public var cOut:TextField;
|
||||||
value: "0x222222",
|
public var cIn:TextField;
|
||||||
help: "console background color",
|
public var cInput:ConsoleInput;
|
||||||
callback: () -> {
|
public var cAutoComp:TextField;
|
||||||
if (Console.consoleInstance != null){
|
public static var consoleInstance:Console;
|
||||||
Console.consoleInstance.cOut.backgroundColor = Std.parseInt(Console.consoleInstance.cvar_mat_consolebg.value);
|
public var cvar_mat_consolebg:CVar;
|
||||||
Console.consoleInstance.cIn.backgroundColor = Std.parseInt(Console.consoleInstance.cvar_mat_consolebg.value);
|
public function new(){
|
||||||
|
super();
|
||||||
|
|
||||||
|
consoleInstance = this;
|
||||||
|
|
||||||
|
var consolePane:UIPane = new UIPane("console pane",{width: 800, height: 600});
|
||||||
|
var topBar:UIPane = new UIPane("top bar", {width: 800, height: 32});
|
||||||
|
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);
|
||||||
|
|
||||||
|
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 = outputPane.dimensions.width;
|
||||||
|
cOut.height = outputPane.dimensions.height;
|
||||||
|
cOut.y = 0;
|
||||||
|
cOut.x = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
outputPane.sprite.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);
|
||||||
public static var scvar_mat_consolebg:CVar;
|
//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);
|
||||||
|
}
|
||||||
|
|
||||||
public var cvar_mat_consolebg:CVar;
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
public var ccmd_visible:CCmd = ConVar.registerCCmd("toggleconsole", (cArgs:Array<String>) -> {
|
}
|
||||||
toggle();
|
|
||||||
});
|
|
||||||
|
|
||||||
public function new() {
|
}
|
||||||
super();
|
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 [];
|
||||||
|
|
||||||
cvar_mat_consolebg = scvar_mat_consolebg;
|
var cVars:Array<String> = ConVar.getCVarNames();
|
||||||
consoleInstance = this;
|
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){
|
||||||
|
|
||||||
var consolePane = new UIPane("yeeto", {width: 800, height: 600, minWidth: 400, minHeight: 300, maxWidth: 1200, maxHeight: 800});
|
}
|
||||||
|
// Not currently selecting an autocomplete entry
|
||||||
|
else{
|
||||||
|
|
||||||
consolePane.layout = VERTICAL;
|
}
|
||||||
consolePane.layout = VERTICAL;
|
}
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
|
|
||||||
cOut = new TextField();
|
}
|
||||||
cAutoComp = new TextField();
|
}
|
||||||
|
public static function histNext():Void
|
||||||
drawFields(cOut, cAutoComp);
|
{
|
||||||
|
// Only complete if input field is empty or scrolling through hist
|
||||||
cOut.addEventListener(Event.CHANGE, onOutputTextChange);
|
if(consoleInstance.cIn.text == "" || histSelect != -1){
|
||||||
cIn.addEventListener(Event.CHANGE, onInputTextChange);
|
// Store current input in tmpInput
|
||||||
this.addChild(cOut);
|
if(histSelect == -1) tmpInput = consoleInstance.cIn.text;
|
||||||
this.addChild(cInput);
|
// Only go through history if history is not empty
|
||||||
this.addChild(cAutoComp);
|
if(history.length != 0){
|
||||||
ConVar.registerCCmd("echo", (args:Array<String>) -> {
|
// Check if currently selecting a history entry
|
||||||
Console.devMsg(args.join(" ").split('"').join(""));
|
if(histSelect < history.length -1){
|
||||||
});
|
histSelect++;
|
||||||
ConVar.registerCCmd("quit", (args:Array<String>) -> {
|
}
|
||||||
Lib.application.window.close();
|
// Otherwise wrap around
|
||||||
});
|
else{
|
||||||
}
|
// Put selector to no selection
|
||||||
|
histSelect = -1;
|
||||||
public function drawFields(cOut:TextField, cAutoComp:TextField) {
|
}
|
||||||
cOut.text = "hConsole Initialized\n";
|
if(histSelect != -1){
|
||||||
cOut.defaultTextFormat = TextFormats.getFormats().cOutputFmt;
|
// Put correct history entry in the input field
|
||||||
cOut.wordWrap = true;
|
consoleInstance.cIn.text = history[histSelect];
|
||||||
// cOut.autoSize = TextFieldAutoSize.LEFT;
|
}
|
||||||
cOut.multiline = true;
|
else{
|
||||||
cOut.background = true;
|
// Restore tmp input
|
||||||
trace(cvar_mat_consolebg);
|
consoleInstance.cIn.text = tmpInput;
|
||||||
cOut.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
}
|
||||||
cOut.width = 800 - 24;
|
}
|
||||||
cOut.height = 600 - cIn.height - 38;
|
// History is empty
|
||||||
cOut.y = 12;
|
else{
|
||||||
cOut.x = 12;
|
// Do nothing
|
||||||
|
return;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function parseCmd(cmd:String, bNoHist:Bool = false) {
|
|
||||||
if (!bNoHist)
|
|
||||||
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) {
|
|
||||||
// Store command name, value and args
|
|
||||||
var cName:String = command[0];
|
|
||||||
var cValue:String = command[1];
|
|
||||||
var cArgs:Array<String> = command.slice(1);
|
|
||||||
// Check if convar with that name actually exists
|
|
||||||
if (ConVar.isCVar(cName)) {
|
|
||||||
// Get reference to convar object
|
|
||||||
var cv:CVar = ConVar.getCVar(command[0]);
|
|
||||||
// Check number of params
|
|
||||||
if (command.length == 1) {
|
|
||||||
// No params after the cmd, print help string
|
|
||||||
devMsg(cv.name + " - " + cv.helpString);
|
|
||||||
devMsg(cv.name + " = " + cv.value);
|
|
||||||
} else {
|
|
||||||
// Check for convar type and set value accordingly
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// convar is actually a command, run it.
|
|
||||||
else if (ConVar.isCmd(cName)) {
|
|
||||||
ConVar.runCmd(cName, cArgs);
|
|
||||||
}
|
|
||||||
// convar doesn't exist
|
|
||||||
else {
|
|
||||||
devMsg("unkown command: " + command[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function submitInput() {
|
|
||||||
cOut.appendText(">" + cInput.getText() + "\n");
|
|
||||||
parseCmd(cInput.getText());
|
|
||||||
cInput.setText("");
|
|
||||||
cAutoComp.visible = false;
|
|
||||||
cOut.scrollV = cOut.maxScrollV;
|
|
||||||
histSelect = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onOutputTextChange(e:Event) {
|
|
||||||
cOut.scrollV = cOut.maxScrollV;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onInputTextChange(e:Event) {
|
|
||||||
if (cInput.getText() != "") {
|
|
||||||
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;
|
|
||||||
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 {
|
|
||||||
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.cInput.getText().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.cInput.getText() == "" || histSelect != -1) {
|
|
||||||
// Store current input in tmpInput
|
|
||||||
if (histSelect == -1)
|
|
||||||
tmpInput = consoleInstance.cInput.getText();
|
|
||||||
// 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.cInput.setText(history[histSelect]);
|
|
||||||
} else {
|
|
||||||
// Restore tmp input
|
|
||||||
consoleInstance.cInput.setText(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
package game.ui.console;
|
|
||||||
|
|
||||||
import engine.HProfiler;
|
|
||||||
import engine.ui.UIPane;
|
|
||||||
import engine.ui.UIElement;
|
|
||||||
import openfl.text.TextField;
|
|
||||||
import openfl.display3D.textures.Texture;
|
|
||||||
import openfl.display.Sprite;
|
|
||||||
|
|
||||||
class ConsolePane extends Sprite{
|
|
||||||
public function new(){
|
|
||||||
super();
|
|
||||||
var testPane:UIPane = new UIPane("test",{height:800,width:600});
|
|
||||||
testPane.layout = VERTICAL;
|
|
||||||
|
|
||||||
var titlebarPane:UIPane = new UIPane("titlebar", {height:32, width: 600});
|
|
||||||
titlebarPane.align = START;
|
|
||||||
titlebarPane.layout = HORIZONTAL;
|
|
||||||
|
|
||||||
var inputPane:UIPane = new UIPane("inputbar", {height:32, width: 600});
|
|
||||||
inputPane.align = END;
|
|
||||||
inputPane.layout = HORIZONTAL;
|
|
||||||
|
|
||||||
var outputPane:UIPane = new UIPane("output pane", {height: 32, width: 600});
|
|
||||||
outputPane.align = START;
|
|
||||||
outputPane.dimensions.expandBehavior = STRETCH;
|
|
||||||
HProfiler.startProfiling("ui_resize");
|
|
||||||
testPane.width = 1000;
|
|
||||||
HProfiler.stopProfiling("ui_resize");
|
|
||||||
|
|
||||||
testPane.addChild(titlebarPane);
|
|
||||||
testPane.addChild(inputPane);
|
|
||||||
testPane.addChild(outputPane);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var textField:TextField = new TextField();
|
|
||||||
textField.background = true;
|
|
||||||
textField.backgroundColor = 0x00ff00;
|
|
||||||
|
|
||||||
var testInputElement:UIElement = new UIElement("inputelem", {height: 32, width: 300},textField);
|
|
||||||
testInputElement.dimensions.expandBehavior = STRETCH;
|
|
||||||
testInputElement.padding = {x: 8, y: 8};
|
|
||||||
|
|
||||||
var inputButtonPane:UIPane = new UIPane("submit button", {height: 32, width: 32});
|
|
||||||
inputButtonPane.align = END;
|
|
||||||
|
|
||||||
var inputFieldPane:UIPane = new UIPane("input field", {height: 32, width: 3});
|
|
||||||
inputFieldPane.align = START;
|
|
||||||
inputFieldPane.dimensions.expandBehavior = STRETCH;
|
|
||||||
|
|
||||||
inputPane.addChild(inputButtonPane);
|
|
||||||
inputPane.addChild(inputFieldPane);
|
|
||||||
//inputFieldPane.addChild(testInputElement);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
addChild(testPane.sprite);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package game.video;
|
package game.video;
|
||||||
|
|
||||||
import engine.ConVar;
|
import game.ui.ConVar;
|
||||||
import engine.typedefs.console.CCmd;
|
|
||||||
import openfl.Lib;
|
import openfl.Lib;
|
||||||
import openfl.display.StageDisplayState;
|
import openfl.display.StageDisplayState;
|
||||||
|
|
||||||
@@ -11,14 +10,15 @@ class Mode
|
|||||||
{
|
{
|
||||||
return Lib.application.window;
|
return Lib.application.window;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setVideoMode(width:Int, height:Int, fs:Int = null){
|
public static function setVideoMode(width:Int, height:Int, fs:Int = null){
|
||||||
getWindow().resize(width,height);
|
getWindow().resize(width,height);
|
||||||
|
if(fs != null){
|
||||||
|
switchFsMode(fs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@:concmd("mat_setvideomode")
|
public static var cvMatSetVideoMode:engine.typedefs.CCmd = ConVar.registerCCmd("mat_setvideomode",(args:Array<String>)->{
|
||||||
public static function cCmdMatSetVideoMode(args:Array<String>){
|
setVideoMode(Std.parseInt(args[0]), Std.parseInt(args[1]), Std.parseInt(args[2]));
|
||||||
Mode.setVideoMode(Std.parseInt(args[0]), Std.parseInt(args[1]), Std.parseInt(args[2]));
|
});
|
||||||
}
|
|
||||||
public static function switchFsMode(toState:Int = 0){
|
public static function switchFsMode(toState:Int = 0){
|
||||||
if(toState == 0){
|
if(toState == 0){
|
||||||
if(Lib.current.stage.displayState != StageDisplayState.FULL_SCREEN_INTERACTIVE){
|
if(Lib.current.stage.displayState != StageDisplayState.FULL_SCREEN_INTERACTIVE){
|
||||||
|
|||||||
Reference in New Issue
Block a user