Some game config methods and signals qmlfrontend
authorunc0rr
Wed, 25 Nov 2015 22:10:01 +0300
branchqmlfrontend
changeset 11431 80a9b14bb8d3
parent 11430 f88b3948adf3
child 11432 97e3e62ea5f9
Some game config methods and signals
hedgewars/uFLGameConfig.pas
hedgewars/uFLNetProtocol.pas
hedgewars/uFLTypes.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
--- a/hedgewars/uFLGameConfig.pas	Wed Nov 25 21:31:30 2015 +0300
+++ b/hedgewars/uFLGameConfig.pas	Wed Nov 25 22:10:01 2015 +0300
@@ -18,6 +18,10 @@
 procedure tryRemoveTeam(teamName: PChar); cdecl;
 procedure changeTeamColor(teamName: PChar; dir: LongInt); cdecl;
 
+procedure netSetSeed(seed: shortstring);
+procedure netSetTheme(themeName: shortstring);
+procedure netSetScript(scriptName: shortstring);
+
 implementation
 uses uFLIPC, hwengine, uFLUtils, uFLTeams, uFLData, uFLSChemes, uFLAmmo, uFLUICallback;
 
@@ -44,6 +48,10 @@
 var
     currentConfig: TGameConfig;
 
+function getScriptPath(scriptName: shortstring): shortstring;
+begin
+    getScriptPath:= '/Scripts/Multiplayer/' + scriptName + '.lua'
+end;
 
 procedure sendConfig(config: PGameConfig);
 var i: Longword;
@@ -52,14 +60,14 @@
 begin
     case gameType of
     gtPreview: begin
-            if script <> '' then
-                ipcToEngine('escript ' + script);
+            if script <> 'Normal' then
+                ipcToEngine('escript ' + getScriptPath(script));
             ipcToEngine('eseed ' + seed);
             ipcToEngine('e$mapgen ' + intToStr(mapgen));
         end;
     gtLocal: begin
-            if script <> '' then
-                ipcToEngine('escript ' + script);
+            if script <> 'Normal' then
+                ipcToEngine('escript ' + getScriptPath(script));
             ipcToEngine('eseed ' + seed);
             ipcToEngine('e$mapgen ' + intToStr(mapgen));
             ipcToEngine('e$theme ' + theme);
@@ -108,6 +116,8 @@
 begin
     with currentConfig do
     begin
+        script:= 'Normal';
+
         for i:= 0 to 7 do
             teams[i].hogsNumber:= 0
     end
@@ -115,10 +125,10 @@
 
 procedure setSeed(seed: PChar); cdecl;
 begin
+    sendUI(mtSeed, @seed[1], length(seed));
     currentConfig.seed:= seed
 end;
 
-
 function getSeed: PChar; cdecl;
 begin
     getSeed:= str2PChar(currentConfig.seed)
@@ -300,10 +310,7 @@
 
 procedure setScript(scriptName: PChar); cdecl;
 begin
-    if scriptName <> 'Normal' then
-        currentConfig.script:= '/Scripts/Multiplayer/' + scriptName + '.lua'
-    else
-        currentConfig.script:= ''
+    currentConfig.script:= scriptName
 end;
 
 procedure setScheme(schemeName: PChar); cdecl;
@@ -324,4 +331,31 @@
         currentConfig.ammo:= ammo^
 end;
 
+procedure netSetSeed(seed: shortstring);
+begin
+    if seed <> currentConfig.seed then
+    begin
+        currentConfig.seed:= seed;
+        sendUI(mtSeed, @seed[1], length(seed))
+    end
+end;
+
+procedure netSetTheme(themeName: shortstring);
+begin
+    if themeName <> currentConfig.theme then
+    begin
+        currentConfig.theme:= themeName;
+        sendUI(mtTheme, @themeName[1], length(themeName))
+    end
+end;
+
+procedure netSetScript(scriptName: shortstring);
+begin
+    if scriptName <> currentConfig.script then
+    begin
+        currentConfig.script:= scriptName;
+        sendUI(mtScript, @scriptName[1], length(scriptName))
+    end
+end;
+
 end.
--- a/hedgewars/uFLNetProtocol.pas	Wed Nov 25 21:31:30 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas	Wed Nov 25 22:10:01 2015 +0300
@@ -10,7 +10,7 @@
 procedure ResetNetState;
 
 implementation
-uses uFLNetTypes, uFLTypes, uFLUICallback, uFLNet;
+uses uFLNetTypes, uFLTypes, uFLUICallback, uFLNet, uFLGameConfig;
 
 type
     PHandler = procedure (var t: TCmdData);
@@ -85,10 +85,14 @@
 
 procedure handler_CFG_SCRIPT(var p: TCmdParamS);
 begin
+    if isInRoom then
+        netSetScript(p.str1)
 end;
 
 procedure handler_CFG_SEED(var p: TCmdParamS);
 begin
+    if isInRoom then
+        netSetSeed(p.str1)
 end;
 
 procedure handler_CFG_TEMPLATE(var p: TCmdParami);
@@ -97,6 +101,8 @@
 
 procedure handler_CFG_THEME(var p: TCmdParamS);
 begin
+    if isInRoom then
+        netSetTheme(p.str1)
 end;
 
 procedure handler_CHAT(var p: TCmdParamSL);
@@ -394,7 +400,6 @@
     end
 end;
 
-
 procedure ResetNetState;
 begin
     isInRoom:= false;
--- a/hedgewars/uFLTypes.pas	Wed Nov 25 21:31:30 2015 +0300
+++ b/hedgewars/uFLTypes.pas	Wed Nov 25 22:10:01 2015 +0300
@@ -7,7 +7,7 @@
                     , mtRemoveLobbyClient, mtLobbyChatLine, mtAddRoomClient
                     , mtRemoveRoomClient, mtRoomChatLine, mtAddRoom, mtUpdateRoom
                     , mtRemoveRoom, mtError, mtWarning, mtMoveToLobby, mtMoveToRoom
-                    , mtNickname);
+                    , mtNickname, mtSeed, mtTheme, mtScript);
 
     TIPCMessage = record
                    str: shortstring;
--- a/qmlFrontend/flib.h	Wed Nov 25 21:31:30 2015 +0300
+++ b/qmlFrontend/flib.h	Wed Nov 25 22:10:01 2015 +0300
@@ -31,6 +31,9 @@
     , MSG_MOVETOLOBBY
     , MSG_MOVETOROOM
     , MSG_NICKNAME
+    , MSG_SEED
+    , MSG_THEME
+    , MSG_SCRIPT
 };
 
 typedef union string255_
--- a/qmlFrontend/hwengine.cpp	Wed Nov 25 21:31:30 2015 +0300
+++ b/qmlFrontend/hwengine.cpp	Wed Nov 25 22:10:01 2015 +0300
@@ -252,6 +252,18 @@
         m_myNickname = QString::fromUtf8(msg);
         break;
     }
+    case MSG_SEED: {
+        emit seedChanged(QString::fromUtf8(msg));
+        break;
+    }
+    case MSG_THEME: {
+        emit themeChanged(QString::fromUtf8(msg));
+        break;
+    }
+    case MSG_SCRIPT: {
+        emit scriptChanged(QString::fromUtf8(msg));
+        break;
+    }
     }
 }
 
--- a/qmlFrontend/hwengine.h	Wed Nov 25 21:31:30 2015 +0300
+++ b/qmlFrontend/hwengine.h	Wed Nov 25 22:10:01 2015 +0300
@@ -70,6 +70,10 @@
     void movedToLobby();
     void movedToRoom();
 
+    void seedChanged(const QString & seed);
+    void themeChanged(const QString & theme);
+    void scriptChanged(const QString & script);
+
     void roomAdded(quint32 flags
                    , const QString & name
                    , int players