- Warnings/errors message box qmlfrontend
authorunc0rr
Sat, 21 Nov 2015 17:07:06 +0300
branchqmlfrontend
changeset 11428 e045dc60c37e
parent 11427 c6c6a4b32cea
child 11429 86c13e5662f1
- Warnings/errors message box - Send JOIN_ROOM on double click on rooms list - Some small iprovements more
hedgewars/hwLibrary.pas
hedgewars/uFLNet.pas
hedgewars/uFLNetProtocol.pas
hedgewars/uFLTypes.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/Chat.qml
qmlFrontend/qml/qmlFrontend/LobbyPage.qml
qmlFrontend/qml/qmlFrontend/main.qml
--- a/hedgewars/hwLibrary.pas	Sat Nov 21 12:40:33 2015 +0300
+++ b/hedgewars/hwLibrary.pas	Sat Nov 21 17:07:06 2015 +0300
@@ -181,6 +181,7 @@
     connectOfficialServer,
     passNetData,
     sendChatLine,
+    joinRoom,
 
     // dunno what these are
     RunEngine,
--- a/hedgewars/uFLNet.pas	Sat Nov 21 12:40:33 2015 +0300
+++ b/hedgewars/uFLNet.pas	Sat Nov 21 17:07:06 2015 +0300
@@ -61,20 +61,33 @@
 procedure handler_;
 begin
     sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
-    writeln('handler_');
     handleTail()
 end;
 
 procedure handler_L;
+var cmd: TCmdParamL;
 begin
-    writeln('handler_L');
+    cmd.cmd:= state.cmd;
+    cmd.str1:= getShortString; // FIXME long line
+    if cmd.str1[0] = #0 then exit;
+    sendUI(mtNetData, @cmd, sizeof(cmd));
     handleTail()
 end;
 
 procedure handler_ML;
+var cmd: TCmdParamL;
+    f: boolean;
 begin
     writeln('handler_ML');
-    handleTail()
+    sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
+    cmd.cmd:= Succ(state.cmd);
+
+    repeat
+        cmd.str1:= getShortString; // FIXME long line
+        f:= cmd.str1[0] <> #0;
+        if f then
+            sendUI(mtNetData, @cmd, sizeof(cmd));
+    until not f
 end;
 
 procedure handler_MS;
@@ -93,8 +106,12 @@
 end;
 
 procedure handler_S;
+var cmd: TCmdParamS;
 begin
-    writeln('handler_S');
+    cmd.cmd:= state.cmd;
+    cmd.str1:= getShortString;
+    if cmd.str1[0] = #0 then exit;
+    sendUI(mtNetData, @cmd, sizeof(cmd));
     handleTail()
 end;
 
--- a/hedgewars/uFLNetProtocol.pas	Sat Nov 21 12:40:33 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas	Sat Nov 21 17:07:06 2015 +0300
@@ -4,6 +4,7 @@
 procedure passNetData(p: pointer); cdecl;
 
 procedure sendChatLine(msg: PChar); cdecl;
+procedure joinRoom(roomName: PChar); cdecl;
 
 implementation
 uses uFLNetTypes, uFLTypes, uFLUICallback, uFLNet;
@@ -60,6 +61,7 @@
 
 procedure handler_ERROR(var p: TCmdParamL);
 begin
+    sendUI(mtError, @p.str1[1], length(p.str1));
 end;
 
 procedure handler_HH_NUM(var p: TCmdParam);
@@ -84,6 +86,8 @@
 
 procedure handler_JOINED_s(var s: TCmdParamS);
 begin
+    if s.str1 = 'qmlfrontend' then // we joined a room
+        sendNet('LIST');
 end;
 
 procedure handler_JOINING(var p: TCmdParamS);
@@ -115,6 +119,8 @@
 
 procedure handler_LOBBY_LEFT(var p: TCmdParamSL);
 begin
+    p.str2:= p.str1 + #10 + p.str2;
+    sendUI(mtRemoveLobbyClient, @p.str2[1], length(p.str2));
 end;
 
 procedure handler_NICK(var p: TCmdParamS);
@@ -230,6 +236,7 @@
 
 procedure handler_WARNING(var p: TCmdParamL);
 begin
+    sendUI(mtWarning, @p.str1[1], length(p.str1));
 end;
 
 const handlers: array[TCmdType] of PHandler = (PHandler(@handler_ASKPASSWORD),
@@ -263,5 +270,11 @@
     sendNet(msg);
 end;
 
+procedure joinRoom(roomName: PChar); cdecl;
+begin
+    sendNetLn('JOIN_ROOM');
+    sendNet(roomName);
+end;
+
 end.
 
--- a/hedgewars/uFLTypes.pas	Sat Nov 21 12:40:33 2015 +0300
+++ b/hedgewars/uFLTypes.pas	Sat Nov 21 17:07:06 2015 +0300
@@ -5,7 +5,7 @@
     TMessageType = (mtPreview, mtAddPlayingTeam, mtRemovePlayingTeam, mtAddTeam, mtRemoveTeam
                     , mtTeamColor, mtNetData, mtConnected, mtDisconnected, mtAddLobbyClient
                     , mtRemoveLobbyClient, mtLobbyChatLine, mtAddRoom, mtUpdateRoom
-                    , mtRemoveRoom);
+                    , mtRemoveRoom, mtError, mtWarning);
 
     TIPCMessage = record
                    str: shortstring;
--- a/qmlFrontend/flib.h	Sat Nov 21 12:40:33 2015 +0300
+++ b/qmlFrontend/flib.h	Sat Nov 21 17:07:06 2015 +0300
@@ -23,6 +23,8 @@
     , MSG_ADDROOM
     , MSG_UPDATEROOM
     , MSG_REMOVEROOM
+    , MSG_ERROR
+    , MSG_WARNING
 };
 
 typedef union string255_
@@ -52,6 +54,7 @@
 typedef void flibFree_t();
 typedef void passNetData_t(const char * data);
 typedef void sendChatLine_t(const char * msg);
+typedef void joinRoom_t(const char * roomName);
 
 typedef char **getThemesList_t();
 typedef void freeThemesList_t(char **list);
--- a/qmlFrontend/hwengine.cpp	Sat Nov 21 12:40:33 2015 +0300
+++ b/qmlFrontend/hwengine.cpp	Sat Nov 21 17:07:06 2015 +0300
@@ -37,6 +37,7 @@
     connectOfficialServer_t * flibConnectOfficialServer;
     passNetData_t * flibPassNetData;
     sendChatLine_t * flibSendChatLine;
+    joinRoom_t * flibJoinRoom;
 }
 
 Q_DECLARE_METATYPE(MessageType);
@@ -84,6 +85,7 @@
     flibConnectOfficialServer = (connectOfficialServer_t*) hwlib.resolve("connectOfficialServer");
     flibPassNetData = (passNetData_t*) hwlib.resolve("passNetData");
     flibSendChatLine = (sendChatLine_t*) hwlib.resolve("sendChatLine");
+    flibJoinRoom = (joinRoom_t*) hwlib.resolve("joinRoom");
 
     flibInit("/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GC/share/hedgewars/Data", "/usr/home/unC0Rr/.hedgewars");
     flibRegisterUIMessagesCallback(this, &guiMessagesCallback);
@@ -191,7 +193,8 @@
         break;
     }
     case MSG_REMOVELOBBYCLIENT: {
-        emit lobbyClientRemoved(QString::fromUtf8(msg));
+        QStringList l = QString::fromUtf8(msg).split('\n');
+        emit lobbyClientRemoved(l[0], l[1]);
         break;
     }
     case MSG_LOBBYCHATLINE: {
@@ -213,6 +216,14 @@
         emit roomRemoved(QString::fromUtf8(msg));
         break;
     }
+    case MSG_ERROR: {
+        emit errorMessage(QString::fromUtf8(msg));
+        break;
+    }
+    case MSG_WARNING: {
+        emit warningMessage(QString::fromUtf8(msg));
+        break;
+    }
     }
 }
 
@@ -294,6 +305,11 @@
     flibSendChatLine(msg.toUtf8().constData());
 }
 
+void HWEngine::joinRoom(const QString &roomName)
+{
+    flibJoinRoom(roomName.toUtf8().constData());
+}
+
 void HWEngine::setTheme(const QString &theme)
 {
     flibSetTheme(theme.toUtf8().constData());
--- a/qmlFrontend/hwengine.h	Sat Nov 21 12:40:33 2015 +0300
+++ b/qmlFrontend/hwengine.h	Sat Nov 21 17:07:06 2015 +0300
@@ -38,7 +38,12 @@
 
     Q_INVOKABLE void sendChatMessage(const QString & msg);
 
+    Q_INVOKABLE void joinRoom(const QString & roomName);
+
 signals:
+    void errorMessage(const QString & message);
+    void warningMessage(const QString & message);
+
     void previewImageChanged();
     void localTeamAdded(const QString & teamName, int aiLevel);
     void localTeamRemoved(const QString & teamName);
@@ -52,7 +57,7 @@
     void netDisconnected(const QString & message);
 
     void lobbyClientAdded(const QString & clientName);
-    void lobbyClientRemoved(const QString & clientName);
+    void lobbyClientRemoved(const QString & clientName, const QString & reason);
     void lobbyChatLine(const QString & nickname, const QString & line);
 
     void roomAdded(quint32 flags
--- a/qmlFrontend/qml/qmlFrontend/Chat.qml	Sat Nov 21 12:40:33 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/Chat.qml	Sat Nov 21 17:07:06 2015 +0300
@@ -43,7 +43,7 @@
                 }
                 Text {
                     color: "#ffffff"
-                    text: name
+                    text: line
 
                     MouseArea {
                          z: 1
@@ -56,7 +56,7 @@
         }
 
         function addLine(nickname, line) {
-            chatLinesModel.append({"nick" : nickname, "name": line})
+            chatLinesModel.append({"nick" : nickname, "line": line})
             if(chatLinesModel.count > 200)
                 chatLinesModel.remove(0)
             chatLines.currentIndex = chatLinesModel.count - 1
@@ -118,12 +118,18 @@
 
         Connections {
             target: HWEngine
-            onLobbyClientAdded: chatClientsModel.append({"isAdmin": false, "name": clientName})
+            onLobbyClientAdded: {
+                chatClientsModel.append({"isAdmin": false, "name": clientName})
+                chatLines.addLine("***", qsTr("%1 joined").arg(clientName))
+            }
             onLobbyClientRemoved: {
                 var i = chatClientsModel.count - 1;
                 while ((i >= 0) && (chatClientsModel.get(i).name !== clientName)) --i;
 
-                if(i >= 0) chatClientsModel.remove(i, 1);
+                if(i >= 0) {
+                    chatClientsModel.remove(i, 1);
+                    chatLines.addLine("***", qsTr("%1 quit (%2)").arg(clientName).arg(reason))
+                }
             }
         }
     }
--- a/qmlFrontend/qml/qmlFrontend/LobbyPage.qml	Sat Nov 21 12:40:33 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/LobbyPage.qml	Sat Nov 21 17:07:06 2015 +0300
@@ -49,7 +49,7 @@
             MouseArea {
                  z: 1
                  anchors.fill: parent
-                 onClicked: ;
+                 onDoubleClicked: HWEngine.joinRoom(name);
             }
         }
 
--- a/qmlFrontend/qml/qmlFrontend/main.qml	Sat Nov 21 12:40:33 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/main.qml	Sat Nov 21 17:07:06 2015 +0300
@@ -36,9 +36,45 @@
         }
     }
 
+    Rectangle {
+        id: warningsBox
+        y: parent.height - height
+        width: parent.width - 120
+        height: 80
+        anchors.horizontalCenter: parent.horizontalCenter
+        color: "#7e3232"
+        border.color: "#d3ec2d"
+        visible: false
+        z: 2
+
+        function showMessage(message) {
+            msgBox.text = message
+            visible = true
+        }
+
+        Text {
+            id: msgBox
+            x: 0
+            y: 0
+            height: parent.height
+            font.pixelSize: 12
+            wrapMode: Text.Wrap
+        }
+        HWButton {
+            id: closeButton
+            x: parent.width - width
+            y: 0
+            width: 40
+            height: 40
+            onClicked: warningsBox.visible = false
+        }
+    }
+
     Connections {
         target: HWEngine
         onNetConnected: currentPage = "LobbyPage";
         onNetDisconnected: currentPage = "First";
+        onWarningMessage: warningsBox.showMessage(message);
+        onErrorMessage: warningsBox.showMessage(message);
     }
 }