- Hedgehogs number display qmlfrontend
authorunc0rr
Sat, 05 Dec 2015 16:14:59 +0300
branchqmlfrontend
changeset 11443 5182d44fb733
parent 11442 6b04a266feee
child 11444 91f8c6ff5bab
- Hedgehogs number display - Accept team removal message from net - Reset teams list leaving a room
hedgewars/uFLGameConfig.pas
hedgewars/uFLNetProtocol.pas
hedgewars/uFLTypes.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/GameConfig.qml
--- a/hedgewars/uFLGameConfig.pas	Thu Dec 03 23:59:06 2015 +0300
+++ b/hedgewars/uFLGameConfig.pas	Sat Dec 05 16:14:59 2015 +0300
@@ -30,6 +30,9 @@
 procedure netSetScheme(scheme: TScheme);
 procedure netAddTeam(team: TTeam);
 procedure netSetTeamColor(team: shortstring; color: Longword);
+procedure netSetHedgehogsNumber(team: shortstring; hogsNumber: Longword);
+procedure netRemoveTeam(teamName: shortstring);
+procedure netResetTeams();
 procedure updatePreviewIfNeeded;
 
 procedure sendConfig(config: PGameConfig);
@@ -222,6 +225,9 @@
         msg:= teamName + #10 + colorsSet[teams[i].color];
         sendUI(mtTeamColor, @msg[1], length(msg));
 
+        msg:= teamName + #10 + IntToStr(hn);
+        sendUI(mtHedgehogsNumber, @msg[1], length(msg));
+
         msg:= teamName;
         sendUI(mtRemoveTeam, @msg[1], length(msg))
     end
@@ -229,7 +235,7 @@
 
 
 procedure tryRemoveTeam(teamName: PChar); cdecl;
-var msg: ansistring;
+var msg: shortstring;
     i: Longword;
     tn: shortstring;
 begin
@@ -262,7 +268,7 @@
 procedure changeTeamColor(teamName: PChar; dir: LongInt); cdecl;
 var i, dc: Longword;
     tn: shortstring;
-    msg:  ansistring;
+    msg: ansistring;
 begin
     with currentConfig do
     begin
@@ -456,9 +462,43 @@
     end
 end;
 
+procedure netRemoveTeam(teamName: shortstring);
+var msg: shortstring;
+    i: Longword;
+    tn: shortstring;
+    isLocal: boolean;
+begin
+    with currentConfig do
+    begin
+        i:= 0;
+        tn:= teamName;
+        while (i < 8) and (teams[i].teamName <> tn) do
+            inc(i);
+
+        // team not found???
+        if (i > 7) then exit;
+
+        isLocal:= not teams[i].extDriven;
+
+        while (i < 7) and (teams[i + 1].hogsNumber > 0) do
+        begin
+            teams[i]:= teams[i + 1];
+            inc(i)
+        end;
+
+        teams[i].hogsNumber:= 0
+    end;
+
+    msg:= teamName;
+
+    sendUI(mtRemovePlayingTeam, @msg[1], length(msg));
+    if isLocal then
+        sendUI(mtAddTeam, @msg[1], length(msg))
+end;
+
 procedure netSetTeamColor(team: shortstring; color: Longword);
 var i: Longword;
-    msg:  ansistring;
+    msg: ansistring;
 begin
     with currentConfig do
     begin
@@ -476,4 +516,49 @@
     end
 end;
 
+procedure netSetHedgehogsNumber(team: shortstring; hogsNumber: Longword);
+var i: Longword;
+    msg: ansistring;
+begin
+    if hogsNumber > 8 then exit;
+
+    with currentConfig do
+    begin
+        i:= 0;
+
+        while (i < 8) and (teams[i].teamName <> team) do
+            inc(i);
+        // team not found???
+        if (i > 7) then exit;
+
+        teams[i].hogsNumber:= hogsNumber;
+
+        msg:= team + #10 + IntToStr(hogsNumber);
+        sendUI(mtHedgehogsNumber, @msg[1], length(msg))
+    end
+end;
+
+procedure netResetTeams();
+var msg: shortstring;
+    i: Longword;
+begin
+    with currentConfig do
+    begin
+        i:= 0;
+
+        while (i < 8) and (teams[i].hogsNumber > 0) do
+        begin
+            msg:= teams[i].teamName;
+
+            sendUI(mtRemovePlayingTeam, @msg[1], length(msg));
+            if not teams[i].extDriven then 
+                sendUI(mtAddTeam, @msg[1], length(msg));
+
+            teams[i].hogsNumber:= 0;
+            inc(i)
+        end;
+
+    end;
+end;
+
 end.
--- a/hedgewars/uFLNetProtocol.pas	Thu Dec 03 23:59:06 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas	Sat Dec 05 16:14:59 2015 +0300
@@ -18,6 +18,13 @@
 var isInRoom: boolean;
     myNickname: shortstring;
 
+procedure onRoomLeaving();
+begin
+    isInRoom:= false;
+    sendUI(mtMoveToLobby, nil, 0);
+    netResetTeams
+end;
+
 var teamIndex: LongInt;
     tmpTeam: TTeam;
 
@@ -293,6 +300,7 @@
 
 procedure handler_HH_NUM(var p: TCmdParamSS);
 begin
+    netSetHedgehogsNumber(p.str1, StrToInt(p.str2))
 end;
 
 procedure handler_INFO(var p: TCmdParam);
@@ -324,8 +332,7 @@
 
 procedure handler_KICKED(var p: TCmdParam);
 begin
-    isInRoom:= false;
-    sendUI(mtMoveToLobby, nil, 0);
+    onRoomLeaving()
 end;
 
 procedure handler_LEFT(var p: TCmdParamSL);
@@ -381,6 +388,7 @@
 
 procedure handler_REMOVE_TEAM(var p: TCmdParamS);
 begin
+    netRemoveTeam(p.str1)
 end;
 
 var roomInfo: string;
@@ -529,12 +537,12 @@
 begin
     if isInRoom then
     begin
-        isInRoom:= false;
         s:= 'PART';
         if length(msg) > 0 then
             s:= s + #10 + msg;
         sendNet(s);
-        sendUI(mtMoveToLobby, nil, 0);
+
+        onRoomLeaving()
     end
 end;
 
--- a/hedgewars/uFLTypes.pas	Thu Dec 03 23:59:06 2015 +0300
+++ b/hedgewars/uFLTypes.pas	Sat Dec 05 16:14:59 2015 +0300
@@ -5,8 +5,9 @@
     MAXARGS = 32;
 
 type
-    TMessageType = (mtRenderingPreview, mtPreview, mtAddPlayingTeam, mtRemovePlayingTeam, mtAddTeam, mtRemoveTeam
-                    , mtTeamColor, mtNetData, mtFlibEvent, mtConnected, mtDisconnected, mtAddLobbyClient
+    TMessageType = (mtRenderingPreview, mtPreview, mtAddPlayingTeam, mtRemovePlayingTeam
+                    , mtAddTeam, mtRemoveTeam, mtTeamColor, mtHedgehogsNumber, mtNetData
+                    , mtFlibEvent, mtConnected, mtDisconnected, mtAddLobbyClient
                     , mtRemoveLobbyClient, mtLobbyChatLine, mtAddRoomClient
                     , mtRemoveRoomClient, mtRoomChatLine, mtAddRoom, mtUpdateRoom
                     , mtRemoveRoom, mtError, mtWarning, mtMoveToLobby, mtMoveToRoom
--- a/qmlFrontend/flib.h	Thu Dec 03 23:59:06 2015 +0300
+++ b/qmlFrontend/flib.h	Sat Dec 05 16:14:59 2015 +0300
@@ -15,6 +15,7 @@
     , MSG_ADDTEAM
     , MSG_REMOVETEAM
     , MSG_TEAMCOLOR
+    , MSG_HEDGEHOGSNUMBER
     , MSG_NETDATA
     , MSG_FLIBEVENT
     , MSG_CONNECTED
--- a/qmlFrontend/hwengine.cpp	Thu Dec 03 23:59:06 2015 +0300
+++ b/qmlFrontend/hwengine.cpp	Sat Dec 05 16:14:59 2015 +0300
@@ -188,6 +188,11 @@
         emit teamColorChanged(l[0], QColor::fromRgba(l[1].toInt()).name());
         break;
     }
+    case MSG_HEDGEHOGSNUMBER: {
+        QStringList l = QString::fromUtf8(msg).split('\n');
+        emit hedgehogsNumberChanged(l[0], l[1].toInt());
+        break;
+    }
     case MSG_NETDATA: {
         flibPassNetData(msg.constData());
         break;
--- a/qmlFrontend/hwengine.h	Thu Dec 03 23:59:06 2015 +0300
+++ b/qmlFrontend/hwengine.h	Sat Dec 05 16:14:59 2015 +0300
@@ -56,6 +56,7 @@
     void playingTeamRemoved(const QString & teamName);
 
     void teamColorChanged(const QString & teamName, const QString & colorValue);
+    void hedgehogsNumberChanged(const QString & teamName, int hedgehogsNumber);
 
     void netConnected();
     void netDisconnected(const QString & message);
--- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Thu Dec 03 23:59:06 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Sat Dec 05 16:14:59 2015 +0300
@@ -213,13 +213,18 @@
                    }
                 }
 
-                Text { text: name
+                Text {
+                    text: name
                     MouseArea {
                         z: 1
                         anchors.fill: parent
                         onClicked: HWEngine.tryRemoveTeam(name)
                    }
                 }
+
+                Text {
+                    text: hedgehogsNumber
+                }
             }
 
 
@@ -231,6 +236,7 @@
                                                              "aiLevel": aiLevel
                                                              , "name": teamName
                                                              , "local": isLocal
+                                                             , "hedgehogsNumber" : 4
                                                              , "teamColor": "#000000"
                                                          })
             onPlayingTeamRemoved: {
@@ -245,6 +251,12 @@
 
                 if(i >= 0) playingTeamsModel.setProperty(i, "teamColor", colorValue)
             }
+            onHedgehogsNumberChanged: {
+                var i = playingTeamsModel.count - 1;
+                while ((i >= 0) && (playingTeamsModel.get(i).name !== teamName)) --i
+
+                if(i >= 0) playingTeamsModel.setProperty(i, "hedgehogsNumber", hedgehogsNumber)
+            }
         }
     }