UI knowns local player nickname qmlfrontend
authorunc0rr
Wed, 25 Nov 2015 21:31:30 +0300
branchqmlfrontend
changeset 11435 f88b3948adf3
parent 11434 d96a37de1076
child 11436 80a9b14bb8d3
UI knowns local player nickname
hedgewars/uFLNetProtocol.pas
hedgewars/uFLTypes.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/Chat.qml
--- a/hedgewars/uFLNetProtocol.pas	Tue Nov 24 20:19:00 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas	Wed Nov 25 21:31:30 2015 +0300
@@ -16,8 +16,9 @@
     PHandler = procedure (var t: TCmdData);
 
 var isInRoom: boolean;
+    myNickname: shortstring;
 
-    procedure handler_ADD_TEAM(var p: TCmdParam);
+procedure handler_ADD_TEAM(var p: TCmdParam);
 begin
 end;
 
@@ -158,7 +159,7 @@
 
 procedure handler_JOINED_s(var s: TCmdParamS);
 begin
-    if s.str1 = 'qmlfrontend' then // we joined a room
+    if s.str1 = myNickname then // we joined a room
     begin
         isInRoom:= true;
         sendUI(mtMoveToRoom, nil, 0);
@@ -192,7 +193,7 @@
 
 procedure handler_LOBBY_JOINED_s(var s: TCmdParamS);
 begin
-    if s.str1 = 'qmlfrontend' then
+    if s.str1 = myNickname then
     begin
         sendUI(mtMoveToLobby, nil, 0);
         sendNet('LIST');
@@ -209,6 +210,8 @@
 
 procedure handler_NICK(var p: TCmdParamS);
 begin
+    myNickname:= p.str1;
+    sendUI(mtNickname, @p.str1[1], length(p.str1));
 end;
 
 procedure handler_NOTICE(var p: TCmdParamL);
--- a/hedgewars/uFLTypes.pas	Tue Nov 24 20:19:00 2015 +0300
+++ b/hedgewars/uFLTypes.pas	Wed Nov 25 21:31:30 2015 +0300
@@ -6,7 +6,8 @@
                     , mtTeamColor, mtNetData, mtConnected, mtDisconnected, mtAddLobbyClient
                     , mtRemoveLobbyClient, mtLobbyChatLine, mtAddRoomClient
                     , mtRemoveRoomClient, mtRoomChatLine, mtAddRoom, mtUpdateRoom
-                    , mtRemoveRoom, mtError, mtWarning, mtMoveToLobby, mtMoveToRoom);
+                    , mtRemoveRoom, mtError, mtWarning, mtMoveToLobby, mtMoveToRoom
+                    , mtNickname);
 
     TIPCMessage = record
                    str: shortstring;
--- a/qmlFrontend/flib.h	Tue Nov 24 20:19:00 2015 +0300
+++ b/qmlFrontend/flib.h	Wed Nov 25 21:31:30 2015 +0300
@@ -30,6 +30,7 @@
     , MSG_WARNING
     , MSG_MOVETOLOBBY
     , MSG_MOVETOROOM
+    , MSG_NICKNAME
 };
 
 typedef union string255_
--- a/qmlFrontend/hwengine.cpp	Tue Nov 24 20:19:00 2015 +0300
+++ b/qmlFrontend/hwengine.cpp	Wed Nov 25 21:31:30 2015 +0300
@@ -248,6 +248,10 @@
         emit movedToRoom();
         break;
     }
+    case MSG_NICKNAME: {
+        m_myNickname = QString::fromUtf8(msg);
+        break;
+    }
     }
 }
 
@@ -339,6 +343,11 @@
     flibPartRoom(message.toUtf8().constData());
 }
 
+QString HWEngine::myNickname()
+{
+    return m_myNickname;
+}
+
 void HWEngine::setTheme(const QString &theme)
 {
     flibSetTheme(theme.toUtf8().constData());
--- a/qmlFrontend/hwengine.h	Tue Nov 24 20:19:00 2015 +0300
+++ b/qmlFrontend/hwengine.h	Wed Nov 25 21:31:30 2015 +0300
@@ -41,6 +41,8 @@
     Q_INVOKABLE void joinRoom(const QString & roomName);
     Q_INVOKABLE void partRoom(const QString & message);
 
+    Q_INVOKABLE QString myNickname();
+
 signals:
     void errorMessage(const QString & message);
     void warningMessage(const QString & message);
@@ -93,6 +95,7 @@
 
 private:
     QQmlEngine * m_engine;
+    QString m_myNickname;
 
     static void guiMessagesCallback(void * context, MessageType mt, const char * msg, uint32_t len);
     void fillModels();
--- a/qmlFrontend/qml/qmlFrontend/Chat.qml	Tue Nov 24 20:19:00 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/Chat.qml	Wed Nov 25 21:31:30 2015 +0300
@@ -71,7 +71,7 @@
 
         onAccepted: {
             HWEngine.sendChatMessage(text)
-            chatLines.addLine("me", text)
+            chatLines.addLine(HWEngine.myNickname(), text)
             text = ""
         }
     }