Compare commits
11 Commits
changes_la
...
d7bd0d02ee
| Author | SHA1 | Date | |
|---|---|---|---|
| d7bd0d02ee | |||
| 720b4d45f2 | |||
| 8951795e9b | |||
| 4208265d21 | |||
| 5422b854e0 | |||
| 4f9469ead5 | |||
| a07bdb6b99 | |||
| 24432f1b91 | |||
| 07fa2e7868 | |||
| 4fe14e341c | |||
| c3ac30208b |
@@ -27,7 +27,6 @@ class Main extends Sprite {
|
|||||||
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 {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package game.ui;
|
package engine;
|
||||||
|
|
||||||
|
|
||||||
typedef CVar = {
|
typedef CVar = {
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package game.ui;
|
package engine;
|
||||||
|
|
||||||
import haxe.Constraints.Function;
|
import haxe.Constraints.Function;
|
||||||
import engine.typedefs.CVar;
|
import engine.typedefs.console.CVar;
|
||||||
import engine.typedefs.CCmd;
|
import engine.typedefs.console.CCmd;
|
||||||
import engine.enums.CVarType;
|
import engine.enums.console.CVarType;
|
||||||
import engine.enums.CVarFlag;
|
import engine.enums.console.CVarFlag;
|
||||||
import game.ui.console.Console;
|
import game.ui.console.Console;
|
||||||
|
|
||||||
|
|
||||||
48
hGameTest/src/engine/HProfiler.hx
Normal file
48
hGameTest/src/engine/HProfiler.hx
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
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,4 +1,4 @@
|
|||||||
package engine.enums;
|
package engine.enums.console;
|
||||||
|
|
||||||
enum CVarFlag{
|
enum CVarFlag{
|
||||||
FCVAR_ARCHIVE;
|
FCVAR_ARCHIVE;
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package engine.enums;
|
package engine.enums.console;
|
||||||
|
|
||||||
enum CVarType {
|
enum CVarType {
|
||||||
CInt;
|
CInt;
|
||||||
CFloat;
|
CFloat;
|
||||||
CString;
|
CString;
|
||||||
CBool;
|
CBool;
|
||||||
|
//CCmd;
|
||||||
}
|
}
|
||||||
7
hGameTest/src/engine/geom/Geom.hx
Normal file
7
hGameTest/src/engine/geom/Geom.hx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package engine.geom;
|
||||||
|
|
||||||
|
|
||||||
|
typedef P2d = {
|
||||||
|
x:Float,
|
||||||
|
y:Float
|
||||||
|
}
|
||||||
34
hGameTest/src/engine/tools/HWindow.hx
Normal file
34
hGameTest/src/engine/tools/HWindow.hx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
68
hGameTest/src/engine/tools/ui/UITool.hx
Normal file
68
hGameTest/src/engine/tools/ui/UITool.hx
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
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.
|
||||||
|
|
||||||
|
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 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(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package engine.typedefs;
|
package engine.typedefs.console;
|
||||||
|
|
||||||
import engine.typedefs.CVar;
|
import engine.typedefs.console.CVar;
|
||||||
|
|
||||||
|
|
||||||
typedef CCmd = {
|
typedef CCmd = {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package engine.typedefs;
|
package engine.typedefs.console;
|
||||||
|
|
||||||
import engine.enums.CVarType;
|
import engine.enums.console.CVarType;
|
||||||
import engine.enums.CVarFlag;
|
import engine.enums.console.CVarFlag;
|
||||||
|
|
||||||
typedef CVar = {
|
typedef CVar = {
|
||||||
var name:String;
|
var name:String;
|
||||||
30
hGameTest/src/engine/ui/UIElement.hx
Normal file
30
hGameTest/src/engine/ui/UIElement.hx
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
333
hGameTest/src/engine/ui/UIPane.hx
Normal file
333
hGameTest/src/engine/ui/UIPane.hx
Normal file
@@ -0,0 +1,333 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,23 @@
|
|||||||
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 assets.Scanner;
|
|
||||||
import assets.HTex;
|
import engine.HProfiler;
|
||||||
import game.ui.ConVar;
|
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 game.ui.console.Console;
|
||||||
|
|
||||||
|
|
||||||
|
import assets.HTex;
|
||||||
|
import assets.Scanner;
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
public var stage:Stage;
|
public var stage:Stage;
|
||||||
@@ -17,12 +25,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");
|
||||||
@@ -32,32 +40,23 @@ 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);
|
||||||
//player.graphics.lineStyle(2,0xFF0000);
|
var console2:ConsolePane = new ConsolePane();
|
||||||
//player.graphics.drawRect(0,0,16,16);
|
uiLayer.addChild(console2);
|
||||||
// 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);
|
HProfiler.startProfiling("frametime");
|
||||||
//var sheet:SpriteSheet = new SpriteSheet(sheetData);
|
//UITool.spawnUIEditorWindow();
|
||||||
//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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,24 +1,23 @@
|
|||||||
package game;
|
package game;
|
||||||
|
|
||||||
import engine.enums.CVarFlag;
|
import openfl.text.TextField;
|
||||||
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> = [];
|
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 +45,16 @@ 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 > 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 +62,43 @@ 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 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 +121,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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package game.ui;
|
|
||||||
|
|
||||||
enum CVarType {
|
|
||||||
CInt;
|
|
||||||
CFloat;
|
|
||||||
CString;
|
|
||||||
CBool;
|
|
||||||
CCmd;
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package game.ui;
|
|
||||||
|
|
||||||
import openfl.geom.Point;
|
|
||||||
import openfl.display.Sprite;
|
|
||||||
|
|
||||||
class UIElement extends Sprite
|
|
||||||
{
|
|
||||||
public function new(){
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package game.ui;
|
|
||||||
|
|
||||||
class UIPane{
|
|
||||||
public static var paneList:Array<UIPane>=[];
|
|
||||||
public var x:Int;
|
|
||||||
public var y:Int;
|
|
||||||
public var width:Int;
|
|
||||||
public var height:Int;
|
|
||||||
public var parent:UIPane;
|
|
||||||
|
|
||||||
public function new(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package game.ui.console;
|
package game.ui.console;
|
||||||
|
|
||||||
import engine.enums.CVarFlag;
|
|
||||||
import game.ui.text.TextFormats;
|
import game.ui.text.TextFormats;
|
||||||
import assets.Fonts;
|
import assets.Fonts;
|
||||||
import openfl.Lib;
|
import openfl.Lib;
|
||||||
@@ -11,11 +10,12 @@ 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.typedefs.CVar;
|
import engine.ConVar;
|
||||||
import game.ui.ConVar;
|
import engine.enums.console.CVarFlag;
|
||||||
import engine.typedefs.CCmd;
|
import engine.typedefs.console.CVar;
|
||||||
|
import engine.typedefs.console.CCmd;
|
||||||
import game.ui.console.elements.ConsoleInput;
|
import game.ui.console.elements.ConsoleInput;
|
||||||
|
import engine.ui.UIPane;
|
||||||
|
|
||||||
|
|
||||||
class Console extends Sprite{
|
class Console extends Sprite{
|
||||||
@@ -26,14 +26,22 @@ 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;
|
||||||
|
|
||||||
|
|
||||||
graphics.beginFill(0x555555);
|
var consolePane:UIPane = new UIPane("yeeto",{width:800, height:600});
|
||||||
graphics.drawRect(0,0,800,600);
|
|
||||||
|
this.addChild(consolePane.sprite);
|
||||||
|
consolePane.layout = VERTICAL;
|
||||||
|
|
||||||
|
//graphics.beginFill(0x555555);
|
||||||
|
//graphics.drawRect(0,0,800,600);
|
||||||
|
|
||||||
cInput = new ConsoleInput();
|
cInput = new ConsoleInput();
|
||||||
cIn = cInput.tf;
|
cIn = cInput.tf;
|
||||||
@@ -48,6 +56,21 @@ class Console extends Sprite{
|
|||||||
},false,false,0,0,false);
|
},false,false,0,0,false);
|
||||||
|
|
||||||
cOut = new TextField();
|
cOut = new TextField();
|
||||||
|
cAutoComp = new TextField();
|
||||||
|
|
||||||
|
drawFields(cOut, cAutoComp);
|
||||||
|
|
||||||
|
|
||||||
|
cOut.addEventListener(Event.CHANGE, onOutputTextChange);
|
||||||
|
cIn.addEventListener(Event.CHANGE, onInputTextChange);
|
||||||
|
this.addChild(cOut);
|
||||||
|
this.addChild(cInput);
|
||||||
|
this.addChild(cAutoComp);
|
||||||
|
ConVar.registerCCmd("echo", (args:Array<String>) -> { Console.devMsg(args.join(" ").split('"').join(""));});
|
||||||
|
ConVar.registerCCmd("quit", (args:Array<String>) -> { Lib.application.window.close();});
|
||||||
|
}
|
||||||
|
public function drawFields(cOut:TextField, cAutoComp:TextField){
|
||||||
|
|
||||||
cOut.text = "hConsole Initialized\n";
|
cOut.text = "hConsole Initialized\n";
|
||||||
cOut.defaultTextFormat = TextFormats.getFormats().cOutputFmt;
|
cOut.defaultTextFormat = TextFormats.getFormats().cOutputFmt;
|
||||||
cOut.wordWrap = true;
|
cOut.wordWrap = true;
|
||||||
@@ -60,7 +83,6 @@ class Console extends Sprite{
|
|||||||
cOut.y = 12;
|
cOut.y = 12;
|
||||||
cOut.x = 12;
|
cOut.x = 12;
|
||||||
|
|
||||||
cAutoComp = new TextField();
|
|
||||||
cAutoComp.text = "";
|
cAutoComp.text = "";
|
||||||
cAutoComp.defaultTextFormat = TextFormats.getFormats().cInputFmt;
|
cAutoComp.defaultTextFormat = TextFormats.getFormats().cInputFmt;
|
||||||
cAutoComp.wordWrap = false;
|
cAutoComp.wordWrap = false;
|
||||||
@@ -75,21 +97,13 @@ class Console extends Sprite{
|
|||||||
cAutoComp.visible = false;
|
cAutoComp.visible = false;
|
||||||
cAutoComp.x = 0;
|
cAutoComp.x = 0;
|
||||||
cAutoComp.y = 600;
|
cAutoComp.y = 600;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cOut.addEventListener(Event.CHANGE, onOutputTextChange);
|
|
||||||
cIn.addEventListener(Event.CHANGE, onInputTextChange);
|
|
||||||
//cOut.addEventListener()
|
|
||||||
this.addChild(cOut);
|
|
||||||
this.addChild(cInput);
|
|
||||||
this.addChild(cAutoComp);
|
|
||||||
//ConVar.registerCVar("echo", CVarType.CCmd, null, devMsg())
|
|
||||||
ConVar.registerCCmd("echo", (args:Array<String>) -> { Console.devMsg(args.join(" ").split('"').join(""));});
|
|
||||||
ConVar.registerCCmd("quit", (args:Array<String>) -> { Lib.application.window.close();});
|
|
||||||
}
|
}
|
||||||
public function parseCmd(cmd:String){
|
|
||||||
history.push(cmd);
|
|
||||||
|
public function parseCmd(cmd:String, bNoHist:Bool = false){
|
||||||
|
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('"');
|
||||||
@@ -147,16 +161,22 @@ class Console extends Sprite{
|
|||||||
}
|
}
|
||||||
public function execCommands(commands:Array<Array<String>>){
|
public function execCommands(commands:Array<Array<String>>){
|
||||||
for(command in commands){
|
for(command in commands){
|
||||||
|
// Store command name, value and args
|
||||||
var cName:String = command[0];
|
var cName:String = command[0];
|
||||||
var cValue:String = command[1];
|
var cValue:String = command[1];
|
||||||
var cArgs:Array<String> = command.slice(1);
|
var cArgs:Array<String> = command.slice(1);
|
||||||
|
//Check if convar with that name actually exists
|
||||||
if(ConVar.isCVar(cName)){
|
if(ConVar.isCVar(cName)){
|
||||||
|
//Get reference to convar object
|
||||||
var cv:CVar = ConVar.getCVar(command[0]);
|
var cv:CVar = ConVar.getCVar(command[0]);
|
||||||
|
//Check number of params
|
||||||
if(command.length == 1){
|
if(command.length == 1){
|
||||||
|
//No params after the cmd, print help string
|
||||||
devMsg(cv.name+" - "+cv.helpString);
|
devMsg(cv.name+" - "+cv.helpString);
|
||||||
devMsg(cv.name+" = "+cv.value);
|
devMsg(cv.name+" = "+cv.value);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
//Check for convar type and set value accordingly
|
||||||
switch(cv.type){
|
switch(cv.type){
|
||||||
case CInt:
|
case CInt:
|
||||||
ConVar.setCVar(cName,Std.parseInt(cValue));
|
ConVar.setCVar(cName,Std.parseInt(cValue));
|
||||||
@@ -182,18 +202,20 @@ class Console extends Sprite{
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//convar is actually a command, run it.
|
||||||
else if(ConVar.isCmd(cName)){
|
else if(ConVar.isCmd(cName)){
|
||||||
ConVar.runCmd(cName,cArgs);
|
ConVar.runCmd(cName,cArgs);
|
||||||
}
|
}
|
||||||
|
//convar doesn't exist
|
||||||
else{
|
else{
|
||||||
devMsg("unkown command: "+command[0]);
|
devMsg("unkown command: "+command[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public function submitInput(){
|
public function submitInput(){
|
||||||
cOut.appendText(">"+cIn.text+"\n");
|
cOut.appendText(">"+cInput.getText()+"\n");
|
||||||
parseCmd(cIn.text);
|
parseCmd(cInput.getText());
|
||||||
cIn.text = "";
|
cInput.setText("");
|
||||||
cAutoComp.visible = false;
|
cAutoComp.visible = false;
|
||||||
cOut.scrollV = cOut.maxScrollV;
|
cOut.scrollV = cOut.maxScrollV;
|
||||||
histSelect = -1;
|
histSelect = -1;
|
||||||
@@ -202,7 +224,7 @@ class Console extends Sprite{
|
|||||||
cOut.scrollV = cOut.maxScrollV;
|
cOut.scrollV = cOut.maxScrollV;
|
||||||
}
|
}
|
||||||
public function onInputTextChange(e:Event){
|
public function onInputTextChange(e:Event){
|
||||||
if(cIn.text != ""){
|
if(cInput.getText() != ""){
|
||||||
cAutoComp.text = "";
|
cAutoComp.text = "";
|
||||||
for(string in (autocompleteList = getCompList())){
|
for(string in (autocompleteList = getCompList())){
|
||||||
cAutoComp.text += string+"\n";
|
cAutoComp.text += string+"\n";
|
||||||
@@ -218,6 +240,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
|
||||||
{
|
{
|
||||||
@@ -232,7 +262,7 @@ class Console extends Sprite{
|
|||||||
public static function getCompList():Array<String>
|
public static function getCompList():Array<String>
|
||||||
{
|
{
|
||||||
// Split words
|
// Split words
|
||||||
var inp:Array<String> = consoleInstance.cIn.text.split(" ");
|
var inp:Array<String> = consoleInstance.cInput.getText().split(" ");
|
||||||
var inpStripped:Array<String> = [
|
var inpStripped:Array<String> = [
|
||||||
for(word in inp){
|
for(word in inp){
|
||||||
if(word != "" && word != " "){
|
if(word != "" && word != " "){
|
||||||
@@ -279,9 +309,9 @@ class Console extends Sprite{
|
|||||||
public static function histPrev():Void
|
public static function histPrev():Void
|
||||||
{
|
{
|
||||||
// Only complete if input field is empty or scrolling through hist
|
// Only complete if input field is empty or scrolling through hist
|
||||||
if(consoleInstance.cIn.text == "" || histSelect != -1){
|
if(consoleInstance.cInput.getText() == "" || histSelect != -1){
|
||||||
// Store current input in tmpInput
|
// Store current input in tmpInput
|
||||||
if(histSelect == -1) tmpInput = consoleInstance.cIn.text;
|
if(histSelect == -1) tmpInput = consoleInstance.cInput.getText();
|
||||||
// Only go through history if history is not empty
|
// Only go through history if history is not empty
|
||||||
if(history.length != 0){
|
if(history.length != 0){
|
||||||
// Check if currently selecting a history entry
|
// Check if currently selecting a history entry
|
||||||
@@ -295,11 +325,11 @@ class Console extends Sprite{
|
|||||||
}
|
}
|
||||||
if(histSelect != -1){
|
if(histSelect != -1){
|
||||||
// Put correct history entry in the input field
|
// Put correct history entry in the input field
|
||||||
consoleInstance.cIn.text = history[histSelect];
|
consoleInstance.cInput.setText(history[histSelect]);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Restore tmp input
|
// Restore tmp input
|
||||||
consoleInstance.cIn.text = tmpInput;
|
consoleInstance.cInput.setText(tmpInput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// History is empty
|
// History is empty
|
||||||
|
|||||||
65
hGameTest/src/game/ui/console/ConsolePane.hx
Normal file
65
hGameTest/src/game/ui/console/ConsolePane.hx
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
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,6 +1,7 @@
|
|||||||
package game.video;
|
package game.video;
|
||||||
|
|
||||||
import game.ui.ConVar;
|
import engine.ConVar;
|
||||||
|
import engine.typedefs.console.CCmd;
|
||||||
import openfl.Lib;
|
import openfl.Lib;
|
||||||
import openfl.display.StageDisplayState;
|
import openfl.display.StageDisplayState;
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ class Mode
|
|||||||
switchFsMode(fs);
|
switchFsMode(fs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static var cvMatSetVideoMode:engine.typedefs.CCmd = ConVar.registerCCmd("mat_setvideomode",(args:Array<String>)->{
|
public static var cvMatSetVideoMode:CCmd = ConVar.registerCCmd("mat_setvideomode",(args:Array<String>)->{
|
||||||
setVideoMode(Std.parseInt(args[0]), Std.parseInt(args[1]), Std.parseInt(args[2]));
|
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){
|
||||||
|
|||||||
Reference in New Issue
Block a user