Selaa lähdekoodia

Console hide, show and fix log

Christian Afonso Ferreira 9 vuotta sitten
vanhempi
commit
3cd1f73fee
1 muutettua tiedostoa jossa 13 lisäystä ja 9 poistoa
  1. 13 9
      h2d/Console.hx

+ 13 - 9
h2d/Console.hx

@@ -136,6 +136,17 @@ class Console extends h2d.Sprite {
 	public function isActive() {
 		return bg.visible;
 	}
+	
+	public function hide() {
+		bg.visible = false;
+		tf.text = "";
+		cursorPos = 0;
+	}
+	
+	public function show() {
+		bg.visible = true;
+		logIndex = -1;
+	}
 
 	function set_cursorPos(v:Int) {
 		if( v > tf.text.length ) v = tf.text.length;
@@ -145,8 +156,7 @@ class Console extends h2d.Sprite {
 
 	function handleKey( e : hxd.Event ) {
 		if( e.charCode == shortKeyChar && !bg.visible ) {
-			bg.visible = true;
-			logIndex = -1;
+			show();
 		}
 		if( !bg.visible )
 			return;
@@ -207,12 +217,6 @@ class Console extends h2d.Sprite {
 		}
 	}
 
-	function hide() {
-		bg.visible = false;
-		tf.text = "";
-		cursorPos = 0;
-	}
-
 	function handleCommand( command : String ) {
 		command = StringTools.trim(command);
 		if( command.charCodeAt(0) == "/".code ) command = command.substr(1);
@@ -293,7 +297,7 @@ class Console extends h2d.Sprite {
 	public function log( text : String, ?color ) {
 		if( color == null ) color = tf.textColor;
 		var oldH = logTxt.textHeight;
-		logTxt.text += '<font color="#${StringTools.hex(color&0xFFFFFF,6)}">${StringTools.htmlEscape(text)}</font><br/>';
+		logTxt.text = logTxt.text + '<font color="#${StringTools.hex(color&0xFFFFFF,6)}">${StringTools.htmlEscape(text)}</font><br/>';
 		if( logDY != 0 ) logDY += logTxt.textHeight - oldH;
 		logTxt.alpha = 1;
 		logTxt.visible = true;