# HG changeset patch # User unc0rr # Date 1447965148 -10800 # Node ID 78d6b99ddcb0ce87118504c4aed37be249d738a7 # Parent 05cf35103206e64e60bb7dd233632ea8a22bd92f Can send chat messages now diff -r 05cf35103206 -r 78d6b99ddcb0 hedgewars/hwLibrary.pas --- 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, diff -r 05cf35103206 -r 78d6b99ddcb0 hedgewars/uFLNetProtocol.pas --- 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. diff -r 05cf35103206 -r 78d6b99ddcb0 qmlFrontend/flib.h --- 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); diff -r 05cf35103206 -r 78d6b99ddcb0 qmlFrontend/hwengine.cpp --- 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()); diff -r 05cf35103206 -r 78d6b99ddcb0 qmlFrontend/hwengine.h --- 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); diff -r 05cf35103206 -r 78d6b99ddcb0 qmlFrontend/qml/qmlFrontend/Chat.qml --- 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;