Handle some CFG parameters qmlfrontend
authorunc0rr
Sat, 28 Nov 2015 00:18:04 +0300
branchqmlfrontend
changeset 11438 bca9afcc3a72
parent 11437 97e3e62ea5f9
child 11439 23912c93935a
Handle some CFG parameters
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 Nov 26 20:11:54 2015 +0300
+++ b/hedgewars/uFLGameConfig.pas	Sat Nov 28 00:18:04 2015 +0300
@@ -21,6 +21,12 @@
 procedure netSetSeed(seed: shortstring);
 procedure netSetTheme(themeName: shortstring);
 procedure netSetScript(scriptName: shortstring);
+procedure netSetFeatureSize(fsize: LongInt);
+procedure netSetMapGen(mapgen: LongInt);
+procedure netSetMap(map: shortstring);
+procedure netSetMazeSize(mazesize: LongInt);
+procedure netSetTemplate(template: LongInt);
+procedure updatePreviewIfNeeded;
 
 implementation
 uses uFLIPC, hwengine, uFLUtils, uFLTeams, uFLData, uFLSChemes, uFLAmmo, uFLUICallback;
@@ -34,9 +40,13 @@
             seed: shortstring;
             theme: shortstring;
             script: shortstring;
+            map: shortstring;
             scheme: TScheme;
             ammo: TAmmo;
-            mapgen: Longint;
+            mapgen: LongInt;
+            featureSize: LongInt;
+            mazesize: LongInt;
+            template: LongInt;
             gameType: TGameType;
             teams: array[0..7] of TTeam;
             arguments: array[0..Pred(MAXARGS)] of shortstring;
@@ -47,6 +57,7 @@
 
 var
     currentConfig: TGameConfig;
+    previewNeedsUpdate: boolean;
 
 function getScriptPath(scriptName: shortstring): shortstring;
 begin
@@ -179,6 +190,8 @@
 
 procedure getPreview; cdecl;
 begin
+    previewNeedsUpdate:= false;
+
     with currentConfig do
     begin
         gameType:= gtPreview;
@@ -355,9 +368,69 @@
 begin
     if scriptName <> currentConfig.script then
     begin
+        previewNeedsUpdate:= true;
         currentConfig.script:= scriptName;
         sendUI(mtScript, @scriptName[1], length(scriptName))
     end
 end;
 
+procedure netSetFeatureSize(fsize: LongInt);
+var s: shortstring;
+begin
+    if fsize <> currentConfig.featureSize then
+    begin
+        previewNeedsUpdate:= true;
+        currentConfig.featureSize:= fsize;
+        s:= IntToStr(fsize);
+        sendUI(mtFeatureSize, @s[1], length(s))
+    end
+end;
+
+procedure netSetMapGen(mapgen: LongInt);
+var s: shortstring;
+begin
+    if mapgen <> currentConfig.mapgen then
+    begin
+        previewNeedsUpdate:= true;
+        currentConfig.mapgen:= mapgen;
+        s:= IntToStr(mapgen);
+        sendUI(mtMapGen, @s[1], length(s))
+    end
+end;
+
+procedure netSetMap(map: shortstring);
+begin
+    sendUI(mtMap, @map[1], length(map))
+end;
+
+procedure netSetMazeSize(mazesize: LongInt);
+var s: shortstring;
+begin
+    if mazesize <> currentConfig.mazesize then
+    begin
+        previewNeedsUpdate:= true;
+        currentConfig.mazesize:= mazesize;
+        s:= IntToStr(mazesize);
+        sendUI(mtMazeSize, @s[1], length(s))
+    end
+end;
+
+procedure netSetTemplate(template: LongInt);
+var s: shortstring;
+begin
+    if template <> currentConfig.template then
+    begin
+        previewNeedsUpdate:= true;
+        currentConfig.template:= template;
+        s:= IntToStr(template);
+        sendUI(mtTemplate, @s[1], length(s))
+    end
+end;
+
+procedure updatePreviewIfNeeded;
+begin
+    if previewNeedsUpdate then
+        getPreview
+end;
+
 end.
--- a/hedgewars/uFLNetProtocol.pas	Thu Nov 26 20:11:54 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas	Sat Nov 28 00:18:04 2015 +0300
@@ -10,7 +10,7 @@
 procedure ResetNetState;
 
 implementation
-uses uFLNetTypes, uFLTypes, uFLUICallback, uFLNet, uFLGameConfig;
+uses uFLNetTypes, uFLTypes, uFLUICallback, uFLNet, uFLGameConfig, uFLUtils;
 
 type
     PHandler = procedure (var t: TCmdData);
@@ -53,26 +53,60 @@
 
 procedure handler_CFG_FEATURE_SIZE(var p: TCmdParami);
 begin
+    if isInRoom then
+    begin
+        netSetFeatureSize(p.param1);
+        updatePreviewIfNeeded
+    end;
 end;
 
+var fmcfgIndex: integer;
+
 procedure handler_CFG_FULLMAPCONFIG(var p: TCmdParam);
 begin
+    fmcfgIndex:= 0;
 end;
 
 procedure handler_CFG_FULLMAPCONFIG_s(var s: TCmdParamS);
 begin
+    if not isInRoom then exit;
+
+    inc(fmcfgIndex);
+    case fmcfgIndex of
+        1: if s.str1[0] <> '+' then netSetMap(s.str1);
+        2: netSetMapGen(strToInt(s.str1));
+        3: netSetMazeSize(strToInt(s.str1));
+        4: netSetTheme(s.str1);
+        5: netSetTemplate(strToInt(s.str1));
+        6: begin
+                netSetFeatureSize(strToInt(s.str1));
+                updatePreviewIfNeeded;
+           end;
+    end;
 end;
 
 procedure handler_CFG_MAP(var p: TCmdParamS);
 begin
+    if isInRoom then
+        netSetMap(p.str1);
 end;
 
 procedure handler_CFG_MAPGEN(var p: TCmdParami);
 begin
+    if isInRoom then
+    begin
+        netSetMapGen(p.param1);
+        updatePreviewIfNeeded
+    end
 end;
 
 procedure handler_CFG_MAZE_SIZE(var p: TCmdParami);
 begin
+    if isInRoom then
+    begin
+        netSetMazeSize(p.param1);
+        updatePreviewIfNeeded
+    end
 end;
 
 procedure handler_CFG_SCHEME(var p: TCmdParam);
@@ -97,6 +131,11 @@
 
 procedure handler_CFG_TEMPLATE(var p: TCmdParami);
 begin
+    if isInRoom then
+    begin
+        netSetTemplate(p.param1);
+        updatePreviewIfNeeded
+    end
 end;
 
 procedure handler_CFG_THEME(var p: TCmdParamS);
--- a/hedgewars/uFLTypes.pas	Thu Nov 26 20:11:54 2015 +0300
+++ b/hedgewars/uFLTypes.pas	Sat Nov 28 00:18:04 2015 +0300
@@ -7,7 +7,8 @@
                     , mtRemoveLobbyClient, mtLobbyChatLine, mtAddRoomClient
                     , mtRemoveRoomClient, mtRoomChatLine, mtAddRoom, mtUpdateRoom
                     , mtRemoveRoom, mtError, mtWarning, mtMoveToLobby, mtMoveToRoom
-                    , mtNickname, mtSeed, mtTheme, mtScript);
+                    , mtNickname, mtSeed, mtTheme, mtScript, mtFeatureSize, mtMapGen
+                    , mtMap, mtMazeSize, mtTemplate);
 
     TIPCMessage = record
                    str: shortstring;
--- a/qmlFrontend/flib.h	Thu Nov 26 20:11:54 2015 +0300
+++ b/qmlFrontend/flib.h	Sat Nov 28 00:18:04 2015 +0300
@@ -34,6 +34,11 @@
     , MSG_SEED
     , MSG_THEME
     , MSG_SCRIPT
+    , MSG_FEATURESIZE
+    , MSG_MAPGEN
+    , MSG_MAP
+    , MSG_MAZESIZE
+    , MSG_TEMPLATE
 };
 
 typedef union string255_
--- a/qmlFrontend/hwengine.cpp	Thu Nov 26 20:11:54 2015 +0300
+++ b/qmlFrontend/hwengine.cpp	Sat Nov 28 00:18:04 2015 +0300
@@ -264,6 +264,26 @@
         emit scriptChanged(QString::fromUtf8(msg));
         break;
     }
+    case MSG_FEATURESIZE: {
+        emit featureSizeChanged(msg.toInt());
+        break;
+    }
+    case MSG_MAPGEN: {
+        emit mapGenChanged(msg.toInt());
+        break;
+    }
+    case MSG_MAP: {
+        emit mapChanged(QString::fromUtf8(msg));
+        break;
+    }
+    case MSG_MAZESIZE: {
+        emit mazeSizeChanged(msg.toInt());
+        break;
+    }
+    case MSG_TEMPLATE: {
+        emit templateChanged(msg.toInt());
+        break;
+    }
     }
 }
 
--- a/qmlFrontend/hwengine.h	Thu Nov 26 20:11:54 2015 +0300
+++ b/qmlFrontend/hwengine.h	Sat Nov 28 00:18:04 2015 +0300
@@ -73,6 +73,11 @@
     void seedChanged(const QString & seed);
     void themeChanged(const QString & theme);
     void scriptChanged(const QString & script);
+    void featureSizeChanged(int featureSize);
+    void mapGenChanged(int mapgen);
+    void mapChanged(const QString & map);
+    void mazeSizeChanged(int mazeSize);
+    void templateChanged(int templ);
 
     void roomAdded(quint32 flags
                    , const QString & name
--- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Thu Nov 26 20:11:54 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Sat Nov 28 00:18:04 2015 +0300
@@ -92,7 +92,7 @@
             }
             Connections {
                 target: HWEngine
-                onScriptChanged: scriptsModel.showItem({"iconSource" : "", "text" : script});
+                onScriptChanged: cbScript.showItem({"iconSource" : "", "text" : script});
             }
         }
     }