# HG changeset patch # User unc0rr # Date 1254047196 0 # Node ID e13a1117152b3c84fb99544948c8d6a23ae1d438 # Parent d01d3bf3e1de4ef772afec35e87aefc9c7b5b6c3 Colorize chat messages in frontend and engine diff -r d01d3bf3e1de -r e13a1117152b QTfrontend/chatwidget.cpp --- a/QTfrontend/chatwidget.cpp Sat Sep 26 20:54:13 2009 +0000 +++ b/QTfrontend/chatwidget.cpp Sun Sep 27 10:26:36 2009 +0000 @@ -78,9 +78,12 @@ if (chatStrings.size() > 250) chatStrings.removeFirst(); - QString formattedStr = Qt::escape(str); - if (formattedStr.startsWith("[")) + QString formattedStr = Qt::escape(str.mid(1)); + if (str.startsWith("\x03")) formattedStr = QString("%1").arg(formattedStr); + else if (str.startsWith("\x02")) + formattedStr = QString("%1").arg(formattedStr); + chatStrings.append(formattedStr); diff -r d01d3bf3e1de -r e13a1117152b QTfrontend/newnetclient.cpp --- a/QTfrontend/newnetclient.cpp Sat Sep 26 20:54:13 2009 +0000 +++ b/QTfrontend/newnetclient.cpp Sun Sep 27 10:26:36 2009 +0000 @@ -375,7 +375,7 @@ emit configAsked(); } emit nickAdded(lst[i]); - emit chatStringFromNet(QString(tr("[ %1 has joined the room ]")).arg(lst[i])); + emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i])); } return; } @@ -397,7 +397,7 @@ } emit nickAddedLobby(lst[i]); - emit chatStringLobby(QString(tr("[ %1 has joined ]")).arg(lst[i])); + emit chatStringLobby(tr("%1 *** %2 has joined").arg('\x03').arg(lst[i])); } return; } @@ -410,9 +410,9 @@ } emit nickRemoved(lst[1]); if (lst.size() < 3) - emit chatStringFromNet(QString(tr("[ %1 has left ]")).arg(lst[1])); + emit chatStringFromNet(tr("%1 *** %2 has left ]").arg('\x03').arg(lst[1])); else - emit chatStringFromNet(QString(tr("[ %1 has left (%2) ]")).arg(lst[1], lst[2])); + emit chatStringFromNet(tr("%1 *** %2 has left (%3) ]").arg('\x03').arg(lst[1], lst[2])); return; } @@ -434,9 +434,9 @@ } emit nickRemovedLobby(lst[1]); if (lst.size() < 3) - emit chatStringLobby(QString(tr("[ %1 has left ]")).arg(lst[1])); + emit chatStringLobby(tr("%1 *** %2 has left ]").arg('\x03').arg(lst[1])); else - emit chatStringLobby(QString(tr("[ %1 has left (%2) ]")).arg(lst[1], lst[2])); + emit chatStringLobby(tr("%1 *** %2 has left (%3) ]").arg('\x03').arg(lst[1], lst[2])); return; } @@ -629,9 +629,9 @@ QString HWNewNet::formatChatMsg(const QString & nick, const QString & msg) { if(msg.left(4) == "/me ") - return QString("* %1 %2").arg(nick).arg(msg.mid(4)); + return QString("\x02* %1 %2").arg(nick).arg(msg.mid(4)); else - return QString("%1: %2").arg(nick).arg(msg); + return QString("\x01%1: %2").arg(nick).arg(msg); } void HWNewNet::banPlayer(const QString & nick) diff -r d01d3bf3e1de -r e13a1117152b hedgewars/CCHandlers.inc --- a/hedgewars/CCHandlers.inc Sat Sep 26 20:54:13 2009 +0000 +++ b/hedgewars/CCHandlers.inc Sun Sep 27 10:26:36 2009 +0000 @@ -336,21 +336,20 @@ SendIPC('s' + s); if copy(s, 1, 4) = '/me ' then - s:= '* ' + UserNick + ' ' + copy(s, 5, Length(s) - 4) + s:= #2'* ' + UserNick + ' ' + copy(s, 5, Length(s) - 4) else - s:= UserNick + ': ' + s; + s:= #1 + UserNick + ': ' + s; AddChatString(s) end; procedure chTeamSay(var s: shortstring); -var text: shortstring; begin SendIPC('b' + s); -text:= copy(s, 2, Length(s)-1); +s[1]:= #4; -AddChatString(text) +AddChatString(s) end; procedure chTimer(var s: shortstring); diff -r d01d3bf3e1de -r e13a1117152b hedgewars/uChat.pas --- a/hedgewars/uChat.pas Sat Sep 26 20:54:13 2009 +0000 +++ b/hedgewars/uChat.pas Sun Sep 27 10:26:36 2009 +0000 @@ -46,16 +46,34 @@ InputStr: TChatLine; InputStrL: array[0..260] of char; // for full str + 4-byte utf-8 char +const colors: array[#1..#4] of Longword = ( + $FFFFFF, // chat message + $FF00FF, // action message + $00B000, // join/leave message + $AFFFAF // team message + ); + procedure SetLine(var cl: TChatLine; str: shortstring; isInput: boolean); var strSurface, resSurface: PSDL_Surface; w, h: LongInt; + color: Longword; begin if cl.Tex <> nil then FreeTexture(cl.Tex); + cl.s:= str; -if isInput then str:= UserNick + '> ' + str + '_'; +if isInput then + begin + color:= $00FFFF; + str:= UserNick + '> ' + str + '_' + end + else begin + color:= colors[str[1]]; + delete(str, 1, 1) + end; + TTF_SizeUTF8(Fontz[fnt16].Handle, Str2PChar(str), w, h); @@ -65,7 +83,7 @@ 32, RMask, GMask, BMask, AMask); -strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), $FFFFFF); +strSurface:= TTF_RenderUTF8_Solid(Fontz[fnt16].Handle, Str2PChar(str), color); cl.Width:= w + 4; SDL_UpperBlit(strSurface, nil, resSurface, nil); SDL_FreeSurface(strSurface); diff -r d01d3bf3e1de -r e13a1117152b hedgewars/uIO.pas --- a/hedgewars/uIO.pas Sat Sep 26 20:54:13 2009 +0000 +++ b/hedgewars/uIO.pas Sun Sep 27 10:26:36 2009 +0000 @@ -315,7 +315,7 @@ 'b': if LocalClan = byte(headcmd^.str[2]) then begin s:= copy(headcmd^.str, 3, Pred(headcmd^.len)); - AddChatString(s); + AddChatString(#4 + s); WriteLnToConsole(s) end; '1'..'5': ParseCommand('timer ' + headcmd^.cmd, true);