Can send chat messages now qmlfrontend
authorunc0rr
Thu, 19 Nov 2015 23:32:28 +0300
branchqmlfrontend
changeset 11421 78d6b99ddcb0
parent 11420 05cf35103206
child 11422 4815e406a760
Can send chat messages now
hedgewars/hwLibrary.pas
hedgewars/uFLNetProtocol.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/Chat.qml
--- a/hedgewars/hwLibrary.pas	Thu Nov 19 23:04:53 2015 +0300
+++ b/hedgewars/hwLibrary.pas	Thu Nov 19 23:32:28 2015 +0300
@@ -180,6 +180,7 @@
     // network
     connectOfficialServer,
     passNetData,
+    sendChatLine,
 
     // dunno what these are
     RunEngine,
--- a/hedgewars/uFLNetProtocol.pas	Thu Nov 19 23:04:53 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas	Thu Nov 19 23:32:28 2015 +0300
@@ -3,6 +3,8 @@
 
 procedure passNetData(p: pointer); cdecl;
 
+procedure sendChatLine(msg: PChar); cdecl;
+
 implementation
 uses uFLNetTypes, uFLTypes, uFLUICallback, uFLNet;
 
@@ -202,5 +204,11 @@
     handlers[TCmdData(p^).cmd.cmd](TCmdData(p^))
 end;
 
+procedure sendChatLine(msg: PChar); cdecl;
+begin
+    sendNetLn('CHAT');
+    sendNet(msg);
+end;
+
 end.
 
--- a/qmlFrontend/flib.h	Thu Nov 19 23:04:53 2015 +0300
+++ b/qmlFrontend/flib.h	Thu Nov 19 23:32:28 2015 +0300
@@ -48,6 +48,7 @@
 typedef void flibInit_t(const char * localPrefix, const char * userPrefix);
 typedef void flibFree_t();
 typedef void passNetData_t(const char * data);
+typedef void sendChatLine_t(const char * msg);
 
 typedef char **getThemesList_t();
 typedef void freeThemesList_t(char **list);
--- a/qmlFrontend/hwengine.cpp	Thu Nov 19 23:04:53 2015 +0300
+++ b/qmlFrontend/hwengine.cpp	Thu Nov 19 23:32:28 2015 +0300
@@ -36,6 +36,7 @@
 
     connectOfficialServer_t * flibConnectOfficialServer;
     passNetData_t * flibPassNetData;
+    sendChatLine_t * flibSendChatLine;
 }
 
 Q_DECLARE_METATYPE(MessageType);
@@ -82,6 +83,7 @@
 
     flibConnectOfficialServer = (connectOfficialServer_t*) hwlib.resolve("connectOfficialServer");
     flibPassNetData = (passNetData_t*) hwlib.resolve("passNetData");
+    flibSendChatLine = (sendChatLine_t*) hwlib.resolve("sendChatLine");
 
     flibInit("/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GC/share/hedgewars/Data", "/usr/home/unC0Rr/.hedgewars");
     flibRegisterUIMessagesCallback(this, &guiMessagesCallback);
@@ -273,6 +275,11 @@
     flibConnectOfficialServer();
 }
 
+void HWEngine::sendChatMessage(const QString &msg)
+{
+    flibSendChatLine(msg.toUtf8().constData());
+}
+
 void HWEngine::setTheme(const QString &theme)
 {
     flibSetTheme(theme.toUtf8().constData());
--- a/qmlFrontend/hwengine.h	Thu Nov 19 23:04:53 2015 +0300
+++ b/qmlFrontend/hwengine.h	Thu Nov 19 23:32:28 2015 +0300
@@ -36,6 +36,8 @@
 
     Q_INVOKABLE void connect(const QString & host, quint16 port);
 
+    Q_INVOKABLE void sendChatMessage(const QString & msg);
+
 signals:
     void previewImageChanged();
     void localTeamAdded(const QString & teamName, int aiLevel);
--- a/qmlFrontend/qml/qmlFrontend/Chat.qml	Thu Nov 19 23:04:53 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/Chat.qml	Thu Nov 19 23:32:28 2015 +0300
@@ -14,7 +14,7 @@
         x: 0
         y: 0
         width: parent.width - clientsList.width
-        height: parent.height
+        height: parent.height - input.height
         focus: true
         clip: true
         highlightFollowsCurrentItem: true
@@ -55,14 +55,31 @@
 
         }
 
+        function addLine(nickname, line) {
+            chatLinesModel.append({"nick" : nickname, "name": line})
+            if(chatLinesModel.count > 200)
+                chatLinesModel.remove(0)
+            chatLines.currentIndex = chatLinesModel.count - 1
+        }
+
         Connections {
             target: HWEngine
-            onLobbyChatLine: {
-                chatLinesModel.append({"nick" : nickname, "name": line})
-                if(chatLinesModel.count > 200)
-                    chatLinesModel.remove(0)
-                chatLines.currentIndex = chatLinesModel.count - 1
-            }
+            onLobbyChatLine: chatLines.addLine(nickname, line)
+        }
+    }
+
+    TextInput {
+        id: input
+        x: 0
+        y: chatLines.height
+        width: chatLines.width
+        height: 24
+        color: "#eccd2f"
+
+        onAccepted: {
+            HWEngine.sendChatMessage(text)
+            chatLines.addLine("me", text)
+            text = ""
         }
     }
 
@@ -101,9 +118,7 @@
 
         Connections {
             target: HWEngine
-            onLobbyClientAdded: {
-                chatClientsModel.append({"isAdmin": false, "name": clientName})
-            }
+            onLobbyClientAdded: chatClientsModel.append({"isAdmin": false, "name": clientName})
             onLobbyClientRemoved: {
                 var i = chatClientsModel.count - 1;
                 while ((i >= 0) && (chatClientsModel.get(i).name !== clientName)) --i;