@@ -14,13 +14,7 @@ public class Console : IGameSystem
1414 float m_ConsoleFoldout ;
1515 float m_ConsoleFoldoutDest ;
1616
17- enum ConsoleState
18- {
19- Closed ,
20- SneakPeek ,
21- Open
22- }
23- ConsoleState m_ConsoleState ;
17+ bool m_ConsoleOpen ;
2418
2519 char [ ] m_InputFieldBuffer ;
2620 int m_CursorPos = 0 ;
@@ -110,25 +104,12 @@ public void TickUpdate()
110104 {
111105 if ( Input . GetKeyDown ( KeyCode . F12 ) )
112106 {
113- switch ( m_ConsoleState )
114- {
115- case ConsoleState . Closed :
116- m_ConsoleState = ConsoleState . Open ;
117- m_ConsoleFoldoutDest = 1.0f ;
118- break ;
119- case ConsoleState . Open :
120- m_ConsoleState = ConsoleState . SneakPeek ;
121- m_ConsoleFoldoutDest = 0.1f ;
122- break ;
123- case ConsoleState . SneakPeek :
124- m_ConsoleState = ConsoleState . Closed ;
125- m_ConsoleFoldoutDest = 0.0f ;
126- break ;
127- }
107+ m_ConsoleOpen = ! m_ConsoleOpen ;
108+ m_ConsoleFoldoutDest = m_ConsoleOpen ? 1.0f : 0.0f ;
128109 Show ( m_ConsoleFoldoutDest ) ;
129110 }
130111
131- if ( m_ConsoleState != ConsoleState . Open )
112+ if ( ! m_ConsoleOpen )
132113 return ;
133114
134115 Scroll ( ( int ) Input . mouseScrollDelta . y ) ;
@@ -208,14 +189,24 @@ public void TickLateUpdate()
208189 line -= 1 ;
209190 }
210191
192+ Vector4 col = m_TextColor ;
193+ UInt32 icol = 0 ;
211194 for ( var i = 0 ; i < m_Height - 1 ; i ++ , line -- )
212195 {
213196 var idx = ( line % m_NumLines ) * m_Width ;
214197 for ( var j = 0 ; j < m_Width ; j ++ )
215198 {
216- char c = ( char ) ( m_ConsoleBuffer [ idx + j ] & 0xff ) ;
199+ UInt32 c = m_ConsoleBuffer [ idx + j ] ;
200+ char ch = ( char ) ( c & 0xff ) ;
201+ if ( icol != ( c & 0xffffff00 ) )
202+ {
203+ icol = c & 0xffffff00 ;
204+ col . x = ( float ) ( ( icol >> 24 ) & 0xff ) / 255.0f ;
205+ col . y = ( float ) ( ( icol >> 16 ) & 0xff ) / 255.0f ;
206+ col . z = ( float ) ( ( icol >> 8 ) & 0xff ) / 255.0f ;
207+ }
217208 if ( c != '\0 ' )
218- DebugOverlay . instance . AddQuad ( j , m_Height - 2 - i + yoffset , 1 , 1 , c , m_TextColor ) ;
209+ DebugOverlay . instance . AddQuad ( j , m_Height - 2 - i + yoffset , 1 , 1 , ch , col ) ;
219210 }
220211 }
221212
@@ -228,8 +219,7 @@ public void TickLateUpdate()
228219 if ( c != '\0 ' )
229220 DebugOverlay . instance . AddQuad ( i - horizontalScroll , m_Height - 1 + yoffset , 1 , 1 , c , m_TextColor ) ;
230221 }
231- if ( m_ConsoleState == ConsoleState . Open )
232- DebugOverlay . instance . AddQuad ( m_CursorPos - horizontalScroll , m_Height - 1 + yoffset , 1 , 1 , '\0 ' , m_CursorCol ) ;
222+ DebugOverlay . instance . AddQuad ( m_CursorPos - horizontalScroll , m_Height - 1 + yoffset , 1 , 1 , '\0 ' , m_CursorCol ) ;
233223 }
234224
235225 void NewLine ( )
@@ -260,15 +250,30 @@ void Scroll(int amount)
260250
261251 public void _Write ( char [ ] buf , int length )
262252 {
253+ const string hexes = "0123456789ABCDEF" ;
254+ UInt32 col = 0xBBBBBB00 ;
263255 for ( int i = 0 ; i < length ; i ++ )
264256 {
265257 if ( buf [ i ] == '\n ' )
266258 {
267259 NewLine ( ) ;
268260 continue ;
269261 }
262+ // Parse color markup of the form �AF7 -> color(0xAA, 0xFF, 0x77)
263+ if ( buf [ i ] == '�' && i < length - 3 )
264+ {
265+ UInt32 res = 0 ;
266+ for ( var j = i + 1 ; j < i + 4 ; j ++ )
267+ {
268+ var v = ( uint ) hexes . IndexOf ( buf [ j ] ) ;
269+ res = res * 256 + v * 16 + v ;
270+ }
271+ col = res << 8 ;
272+ i += 3 ;
273+ continue ;
274+ }
270275 var idx = ( m_LastLine % m_NumLines ) * m_Width + m_LastColumn ;
271- m_ConsoleBuffer [ idx ] = ( byte ) buf [ i ] ;
276+ m_ConsoleBuffer [ idx ] = col | ( byte ) buf [ i ] ;
272277 m_LastColumn ++ ;
273278 if ( m_LastColumn >= m_Width )
274279 {
@@ -352,10 +357,10 @@ void TabComplete()
352357 {
353358 // write list of possible completions
354359 for ( var i = 0 ; i < matches . Count ; i ++ )
355- Write ( " {0}\n " , matches [ i ] ) ;
360+ Write ( " {0}\n " , matches [ i ] ) ;
356361 }
357362
358- if ( matches . Count == 1 )
363+ if ( matches . Count == 1 )
359364 Type ( ' ' ) ;
360365 }
361366
0 commit comments