various changes
This commit is contained in:
		
							parent
							
								
									96e0695497
								
							
						
					
					
						commit
						caa062a5aa
					
				
							
								
								
									
										41
									
								
								hGameTest/src/engine/HProfiler.hx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								hGameTest/src/engine/HProfiler.hx
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,41 @@ | |||||||
|  | package engine; | ||||||
|  | 
 | ||||||
|  | import game.ui.console.Console; | ||||||
|  | import 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"); | ||||||
|  |         } | ||||||
|  |     }); | ||||||
|  | } | ||||||
| @ -1,5 +1,8 @@ | |||||||
| package game; | package game; | ||||||
| 
 | 
 | ||||||
|  | import engine.HProfiler; | ||||||
|  | import game.ui.console.ConsolePane; | ||||||
|  | import game.ui.UIPane; | ||||||
| import engine.typedefs.CVar; | import engine.typedefs.CVar; | ||||||
| import game.entities.Player; | import game.entities.Player; | ||||||
| import openfl.display.Stage; | import openfl.display.Stage; | ||||||
| @ -32,21 +35,22 @@ 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(); | ||||||
|  |         uiLayer.addChild(console2); | ||||||
|         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"); | ||||||
|          |  | ||||||
| 	} | 	} | ||||||
| 	public function onEnterFrame(e:Event):Void | 	public function onEnterFrame(e:Event):Void | ||||||
| 	{ | 	{ | ||||||
|  |         HProfiler.stopProfiling("frametime"); | ||||||
|  |         HProfiler.startProfiling("frametime"); | ||||||
|         Input.onEnterFrame(); |         Input.onEnterFrame(); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @ -1,12 +1,30 @@ | |||||||
| package game.ui; | package game.ui; | ||||||
| 
 | 
 | ||||||
| import openfl.geom.Point; | import game.ui.UIPane.P2d; | ||||||
| import openfl.display.Sprite; | import openfl.display.DisplayObject; | ||||||
|  | import game.ui.UIPane.PaneDimensions; | ||||||
| 
 | 
 | ||||||
| class UIElement extends Sprite | class UIElement extends UIPane | ||||||
| { | { | ||||||
|     public function new(){ |     public var dispObj:DisplayObject; | ||||||
|         super(); |     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,17 +1,28 @@ | |||||||
| package game.ui; | package game.ui; | ||||||
| 
 | 
 | ||||||
|  | //  __      __     _____    ______ | ||||||
|  | // |  |    |  |  /  ___ \  |  ____| | ||||||
|  | // |  |____|  | |  /  _\_| | |____ | ||||||
|  | // |   ____   | |  | |_ \  |  ____| | ||||||
|  | // |  |    |  | |  \__/  | | |____ | ||||||
|  | // |__|    |__|  \______/  |______| | ||||||
|  | // file: UIPane.hx | ||||||
|  | // author: and.schaafsma@gmail.com | ||||||
|  | // purpose: Class for resizable and scalable UI Panels | ||||||
|  | 
 | ||||||
| import openfl.display.Sprite; | import openfl.display.Sprite; | ||||||
| import openfl.display.BitmapData; | import openfl.display.BitmapData; | ||||||
| import openfl.display.DisplayObject; | import openfl.display.DisplayObject; | ||||||
| import openfl.text.TextField; | import openfl.text.TextField; | ||||||
|  | import engine.ConVar; | ||||||
| 
 | 
 | ||||||
| typedef P2d = { | typedef P2d = { | ||||||
|     x:Float, |     x:Float, | ||||||
|     y:Float |     y:Float | ||||||
| } | } | ||||||
| enum PaneLayout{ | @:enum abstract PaneLayout(Int){ | ||||||
| 	HORIZONTAL; | 	var HORIZONTAL = 0; | ||||||
| 	VERTICAL; | 	var VERTICAL = 1; | ||||||
| } | } | ||||||
| enum PaneAnchor{ | enum PaneAnchor{ | ||||||
|     LEFT; |     LEFT; | ||||||
| @ -24,8 +35,9 @@ enum PaneAnchor{ | |||||||
| 	BOTTOMRIGHT; | 	BOTTOMRIGHT; | ||||||
| } | } | ||||||
| enum ExpandBehavior{ | enum ExpandBehavior{ | ||||||
|     FACTOR; |  | ||||||
|     ABSOLUTE; |     ABSOLUTE; | ||||||
|  |     FACTOR(f:Float); | ||||||
|  |     CONTENT; | ||||||
|     STRETCH; |     STRETCH; | ||||||
|     FILL; |     FILL; | ||||||
|     FIT; |     FIT; | ||||||
| @ -87,6 +99,8 @@ class UIPane{ | |||||||
|     public var parent:UIPane = null; |     public var parent:UIPane = null; | ||||||
|     public var align:PaneAlign = START; |     public var align:PaneAlign = START; | ||||||
|     public var maskSprite:Sprite; |     public var maskSprite:Sprite; | ||||||
|  |      | ||||||
|  |     public static var panelist:Array<UIPane> = []; | ||||||
|     public function new(_name:String, _dimensions:PaneDimensions) |     public function new(_name:String, _dimensions:PaneDimensions) | ||||||
| 	{ | 	{ | ||||||
|         // Set name |         // Set name | ||||||
| @ -109,8 +123,18 @@ class UIPane{ | |||||||
|         // Initialize Sprite |         // Initialize Sprite | ||||||
|         initSprite(); |         initSprite(); | ||||||
|         // Draw debug pane for visualizing |         // Draw debug pane for visualizing | ||||||
| 		//drawDebugPane(); | 		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 |     public function getAnchorOffset(anchor:PaneAnchor):P2d | ||||||
|     { |     { | ||||||
|         switch(anchor){ |         switch(anchor){ | ||||||
| @ -139,10 +163,10 @@ class UIPane{ | |||||||
|         sprite = new Sprite(); |         sprite = new Sprite(); | ||||||
| 
 | 
 | ||||||
| 		// Draw mask | 		// Draw mask | ||||||
| 		//maskSprite = new Sprite(); | 		maskSprite = new Sprite(); | ||||||
| 		//drawMask(); | 		drawMask(); | ||||||
| 		//sprite.addChild(maskSprite); | 		sprite.addChild(maskSprite); | ||||||
| 		//sprite.mask = maskSprite; | 		sprite.mask = maskSprite; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function drawMask():Void |     public function drawMask():Void | ||||||
| @ -169,24 +193,25 @@ class UIPane{ | |||||||
| 		sprite.graphics.drawRect(0,0,dimensions.width,dimensions.height); | 		sprite.graphics.drawRect(0,0,dimensions.width,dimensions.height); | ||||||
| 		sprite.graphics.beginBitmapFill(bmp,null); | 		sprite.graphics.beginBitmapFill(bmp,null); | ||||||
| 		sprite.graphics.drawRect(0,0,dimensions.width,dimensions.height); | 		sprite.graphics.drawRect(0,0,dimensions.width,dimensions.height); | ||||||
|          |         //Visualize Anchor Points | ||||||
|         if(true){ |         if(false){ | ||||||
|             sprite.graphics.beginFill(Std.int(Math.random()*0xffffff),0.5); |             sprite.graphics.beginFill(Std.int(Math.random()*0xffffff),0.5); | ||||||
|             sprite.graphics.drawCircle(getAnchorOffset(TOPLEFT).x,getAnchorOffset(TOPLEFT).y,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(TOP).x,          getAnchorOffset(TOP).y,         5); | ||||||
|             sprite.graphics.drawCircle(getAnchorOffset(TOPRIGHT).x,getAnchorOffset(TOPRIGHT).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(RIGHT).x,        getAnchorOffset(RIGHT).y,       5); | ||||||
|             sprite.graphics.drawCircle(getAnchorOffset(BOTTOMRIGHT).x,getAnchorOffset(BOTTOMRIGHT).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(BOTTOM).x,       getAnchorOffset(BOTTOM).y,      5); | ||||||
|             sprite.graphics.drawCircle(getAnchorOffset(BOTTOMLEFT).x,getAnchorOffset(BOTTOMLEFT).y,5); |             sprite.graphics.drawCircle(getAnchorOffset(BOTTOMLEFT).x,   getAnchorOffset(BOTTOMLEFT).y,  5); | ||||||
|             sprite.graphics.drawCircle(getAnchorOffset(LEFT).x,getAnchorOffset(LEFT).y,5);     |             sprite.graphics.drawCircle(getAnchorOffset(LEFT).x,         getAnchorOffset(LEFT).y,        5);     | ||||||
|         }    |         }    | ||||||
|          |  | ||||||
| 	} | 	} | ||||||
|     public var endOffset:Float = 0; |     public var endOffset:Float = 0; | ||||||
|     public var startOffset:Float = 0; |     public var startOffset:Float = 0; | ||||||
| 	public function addChild(child:UIPane) | 	public function addChild(child:UIPane) | ||||||
| 	{ | 	{ | ||||||
|  |         if(child.parent != null) | ||||||
|  |             throw "Attempting to attach child UIPane that already has a parent"; | ||||||
|         children.push(child); |         children.push(child); | ||||||
|         sprite.addChild(child.sprite); |         sprite.addChild(child.sprite); | ||||||
|         child.parent = this; |         child.parent = this; | ||||||
| @ -197,8 +222,8 @@ class UIPane{ | |||||||
| 	} | 	} | ||||||
|     public function redraw():Void |     public function redraw():Void | ||||||
|     { |     { | ||||||
|         //drawDebugPane(); |         drawDebugPane(); | ||||||
|         //drawMask(); |         drawMask(); | ||||||
|     } |     } | ||||||
| 	public function onResize(){ | 	public function onResize(){ | ||||||
|         redraw(); |         redraw(); | ||||||
| @ -207,49 +232,70 @@ class UIPane{ | |||||||
|         } |         } | ||||||
| 	} | 	} | ||||||
|     private function arrangeChild(child:UIPane){ |     private function arrangeChild(child:UIPane){ | ||||||
|         if(child.autoArrange){ |         // We do not arrange the | ||||||
|  |         if(!child.autoArrange){ | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         if(endOffset == 0){ | ||||||
|             switch(layout){ |             switch(layout){ | ||||||
|                 case HORIZONTAL: |                 case HORIZONTAL: | ||||||
|                     if(endOffset == 0) endOffset = width; |                     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: |                 case VERTICAL: | ||||||
|                     if(endOffset == 0) endOffset = height; |                     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; |  | ||||||
|                     } |  | ||||||
|             } |             } | ||||||
|              |         } | ||||||
|  |         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){ | ||||||
|  |                     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(){ | 	public function arrangeChildren(){ | ||||||
|  |         // reset offsets | ||||||
| 		startOffset = 0; | 		startOffset = 0; | ||||||
|         endOffset = 0; |         endOffset = 0; | ||||||
|  |         // arrance each child | ||||||
|         for(child in children){ |         for(child in children){ | ||||||
|             arrangeChild(child); |             arrangeChild(child); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -35,8 +35,13 @@ class Console extends Sprite{ | |||||||
|         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; | ||||||
| @ -51,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; | ||||||
| @ -63,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; | ||||||
| @ -78,19 +97,9 @@ 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, bNoHist:Bool = false){ |     public function parseCmd(cmd:String, bNoHist:Bool = false){ | ||||||
|         if(!bNoHist) |         if(!bNoHist) | ||||||
|             history.push(cmd); |             history.push(cmd); | ||||||
| @ -196,9 +205,9 @@ class Console extends Sprite{ | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     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; | ||||||
| @ -207,7 +216,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"; | ||||||
| @ -245,7 +254,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 != " "){ | ||||||
| @ -292,9 +301,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 | ||||||
| @ -308,11 +317,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 | ||||||
|  | |||||||
							
								
								
									
										53
									
								
								hGameTest/src/game/ui/console/ConsolePane.hx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								hGameTest/src/game/ui/console/ConsolePane.hx
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,53 @@ | |||||||
|  | package game.ui.console; | ||||||
|  | 
 | ||||||
|  | import engine.HProfiler; | ||||||
|  | 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 inputFieldPane:UIPane = new UIPane("input field", {height: 32, width: 3}); | ||||||
|  |         var inputButtonPane:UIPane = new UIPane("submit button", {height: 32, width: 32}); | ||||||
|  | 
 | ||||||
|  |         inputPane.addChild(testInputElement); | ||||||
|  |          | ||||||
|  |          | ||||||
|  |          | ||||||
|  |         addChild(testPane.sprite); | ||||||
|  |     }     | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user