commiting changes to separate branch for later use
This commit is contained in:
parent
7fa7ece574
commit
e0e4109bde
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -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 +1,258 @@
|
|||||||
package game.ui;
|
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{
|
class UIPane{
|
||||||
public static var paneList:Array<UIPane>=[];
|
public var name:String;
|
||||||
public var x:Int;
|
public var sprite:Sprite;
|
||||||
public var y:Int;
|
public var x(get, set):Float;
|
||||||
public var width:Int;
|
public var y(get, set):Float;
|
||||||
public var height:Int;
|
function get_x(){ return sprite.x; }
|
||||||
public var parent:UIPane;
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public function new(){
|
// 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,7 +1,5 @@
|
|||||||
package game.ui.console;
|
package game.ui.console;
|
||||||
|
|
||||||
import engine.enums.CVarFlag;
|
|
||||||
import game.ui.text.TextFormats;
|
|
||||||
import assets.Fonts;
|
import assets.Fonts;
|
||||||
import openfl.Lib;
|
import openfl.Lib;
|
||||||
import openfl.events.Event;
|
import openfl.events.Event;
|
||||||
@ -11,10 +9,15 @@ import openfl.display.Sprite;
|
|||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import openfl.text.TextFormat;
|
import openfl.text.TextFormat;
|
||||||
import openfl.text.TextFieldType;
|
import openfl.text.TextFieldType;
|
||||||
|
// Engine Imports
|
||||||
|
import engine.enums.CVarFlag;
|
||||||
import engine.typedefs.CVar;
|
import engine.typedefs.CVar;
|
||||||
import game.ui.ConVar;
|
|
||||||
import engine.typedefs.CCmd;
|
import engine.typedefs.CCmd;
|
||||||
|
// Game imports
|
||||||
|
import game.ui.ConVar;
|
||||||
|
import game.ui.text.TextFormats;
|
||||||
import game.ui.console.elements.ConsoleInput;
|
import game.ui.console.elements.ConsoleInput;
|
||||||
|
import game.ui.UIPane;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -31,8 +34,20 @@ class Console extends Sprite{
|
|||||||
|
|
||||||
consoleInstance = this;
|
consoleInstance = this;
|
||||||
|
|
||||||
|
var consolePane:UIPane = new UIPane("console pane",{width: 800, height: 600});
|
||||||
graphics.beginFill(0x555555);
|
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);
|
graphics.drawRect(0,0,800,600);
|
||||||
|
|
||||||
cInput = new ConsoleInput();
|
cInput = new ConsoleInput();
|
||||||
@ -55,10 +70,13 @@ class Console extends Sprite{
|
|||||||
cOut.multiline = true;
|
cOut.multiline = true;
|
||||||
cOut.background = true;
|
cOut.background = true;
|
||||||
cOut.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
cOut.backgroundColor = Std.parseInt(cvar_mat_consolebg.value);
|
||||||
cOut.width = 800 - 24;
|
cOut.width = outputPane.dimensions.width;
|
||||||
cOut.height = 600 - cIn.height - 38;
|
cOut.height = outputPane.dimensions.height;
|
||||||
cOut.y = 12;
|
cOut.y = 0;
|
||||||
cOut.x = 12;
|
cOut.x = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cAutoComp = new TextField();
|
cAutoComp = new TextField();
|
||||||
cAutoComp.text = "";
|
cAutoComp.text = "";
|
||||||
@ -81,7 +99,7 @@ class Console extends Sprite{
|
|||||||
cOut.addEventListener(Event.CHANGE, onOutputTextChange);
|
cOut.addEventListener(Event.CHANGE, onOutputTextChange);
|
||||||
cIn.addEventListener(Event.CHANGE, onInputTextChange);
|
cIn.addEventListener(Event.CHANGE, onInputTextChange);
|
||||||
//cOut.addEventListener()
|
//cOut.addEventListener()
|
||||||
this.addChild(cOut);
|
outputPane.sprite.addChild(cOut);
|
||||||
this.addChild(cInput);
|
this.addChild(cInput);
|
||||||
this.addChild(cAutoComp);
|
this.addChild(cAutoComp);
|
||||||
//ConVar.registerCVar("echo", CVarType.CCmd, null, devMsg())
|
//ConVar.registerCVar("echo", CVarType.CCmd, null, devMsg())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user