@@ -71,17 +71,17 @@ private void Start()
7171 private const float FADE_TIME = 2f ;
7272
7373 private bool _writingMessage ;
74- private readonly string [ ] _lines = new string [ LINE_COUNT ] ;
74+ private readonly ( string msg , Color color ) [ ] _lines = new ( string msg , Color color ) [ LINE_COUNT ] ;
7575 // this should really be a deque, but eh
76- private readonly ListStack < string > _messages = new ( false ) ;
76+ private readonly ListStack < ( string msg , Color color ) > _messages = new ( false ) ;
7777 private float _lastMessageTime ;
7878
79- public void WriteMessage ( string message )
79+ public void WriteMessage ( string message , Color color )
8080 {
8181 /* Tricky problem to solve.
8282 * - 11 available lines for text to fit onto
8383 * - Each line can be max 41 characters
84- * - Newest messages apepear at the bottom, and get pushed up by newer messages.
84+ * - Newest messages appear at the bottom, and get pushed up by newer messages.
8585 * - Messages can use several lines.
8686 *
8787 * From newest to oldest message, work out how many lines it needs
@@ -90,7 +90,7 @@ public void WriteMessage(string message)
9090
9191 _lastMessageTime = Time . time ;
9292
93- _messages . Push ( message ) ;
93+ _messages . Push ( ( message , color ) ) ;
9494
9595 if ( _messages . Count > LINE_COUNT )
9696 {
@@ -101,7 +101,7 @@ public void WriteMessage(string message)
101101
102102 foreach ( var msg in _messages . Reverse ( ) )
103103 {
104- var characterCount = msg . Length ;
104+ var characterCount = msg . msg . Length ;
105105 var linesNeeded = Mathf . CeilToInt ( ( float ) characterCount / CHAR_COUNT ) ;
106106 var chunk = 0 ;
107107 for ( var i = linesNeeded - 1 ; i >= 0 ; i -- )
@@ -112,8 +112,8 @@ public void WriteMessage(string message)
112112 continue ;
113113 }
114114
115- var chunkString = string . Concat ( msg . Skip ( CHAR_COUNT * chunk ) . Take ( CHAR_COUNT ) ) ;
116- _lines [ currentLineIndex - i ] = chunkString ;
115+ var chunkString = string . Concat ( msg . msg . Skip ( CHAR_COUNT * chunk ) . Take ( CHAR_COUNT ) ) ;
116+ _lines [ currentLineIndex - i ] = ( chunkString , msg . color ) ;
117117 chunk ++ ;
118118 }
119119
@@ -128,17 +128,20 @@ public void WriteMessage(string message)
128128 var finalText = "" ;
129129 foreach ( var line in _lines )
130130 {
131+ var msgColor = ColorUtility . ToHtmlStringRGBA ( line . color ) ;
132+ var msg = $ "<color=#{ msgColor } >{ line . msg } </color>";
133+
131134 if ( line == default )
132135 {
133136 finalText += Environment . NewLine ;
134137 }
135- else if ( line . Length == 42 )
138+ else if ( line . msg . Length == CHAR_COUNT + 1 )
136139 {
137- finalText += line ;
140+ finalText += msg ;
138141 }
139142 else
140143 {
141- finalText += $ "{ line } { Environment . NewLine } ";
144+ finalText += $ "{ msg } { Environment . NewLine } ";
142145 }
143146 }
144147
@@ -183,7 +186,7 @@ private void Update()
183186 _inputField . text = "" ;
184187 message = message . Replace ( "\n " , "" ) . Replace ( "\r " , "" ) ;
185188 message = $ "{ QSBPlayerManager . LocalPlayer . Name } : { message } ";
186- new ChatMessage ( message ) . Send ( ) ;
189+ new ChatMessage ( message , Color . white ) . Send ( ) ;
187190 }
188191
189192 if ( OWInput . IsNewlyPressed ( InputLibrary . escape , InputMode . KeyboardInput ) && _writingMessage )
@@ -398,7 +401,7 @@ private void OnRemovePlayer(PlayerInfo player)
398401 Destroy ( player . HUDBox ? . gameObject ) ;
399402 Destroy ( player . MinimapPlayerMarker ) ;
400403
401- WriteMessage ( $ "<color=yellow> { string . Format ( QSBLocalization . Current . PlayerLeftTheGame , player . Name ) } </color>" ) ;
404+ WriteMessage ( string . Format ( QSBLocalization . Current . PlayerLeftTheGame , player . Name ) , Color . yellow ) ;
402405 }
403406
404407 private PlanetTrigger CreateTrigger ( string parentPath , HUDIcon icon )
0 commit comments