Prevent saving of demo after /lua command was used
authorWuzzy <Wuzzy2@mail.ru>
Sat, 27 Jul 2019 03:42:17 +0200
changeset 15278 16f389fcd462
parent 15277 7b05af5912cb
child 15279 7ab5cf405686
Prevent saving of demo after /lua command was used Done because demos are unable to record any manual Lua command atm.
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/ui/page/pagegamestats.cpp
QTfrontend/ui/page/pagegamestats.h
hedgewars/uCommandHandlers.pas
hedgewars/uGearsHandlersMess.pas
--- a/QTfrontend/game.cpp	Fri Jul 26 01:13:48 2019 +0200
+++ b/QTfrontend/game.cpp	Sat Jul 27 03:42:17 2019 +0200
@@ -76,22 +76,29 @@
 
 void HWGame::onClientDisconnect()
 {
-    switch (gameType)
+    if (demoIsPresent)
     {
-        case gtDemo:
-            // for video recording we need demo anyway
-            emit HaveRecord(rtNeither, demo);
-            break;
-        case gtNet:
-            emit HaveRecord(rtDemo, demo);
-            break;
-        default:
-            if (gameState == gsInterrupted || gameState == gsHalted)
-                emit HaveRecord(rtSave, demo);
-            else if (gameState == gsFinished)
+        switch (gameType)
+        {
+            case gtDemo:
+                // for video recording we need demo anyway
+                emit HaveRecord(rtNeither, demo);
+                break;
+            case gtNet:
                 emit HaveRecord(rtDemo, demo);
-            else
-                emit HaveRecord(rtNeither, demo);
+                break;
+            default:
+                if (gameState == gsInterrupted || gameState == gsHalted)
+                    emit HaveRecord(rtSave, demo);
+                else if (gameState == gsFinished)
+                    emit HaveRecord(rtDemo, demo);
+                else
+                    emit HaveRecord(rtNeither, demo);
+        }
+    }
+    else
+    {
+        emit HaveRecord(rtNeither, demo);
     }
     SetGameState(gsStopped);
 }
@@ -452,6 +459,11 @@
             SetGameState(gsFinished);
             break;
         }
+        case 'm':
+        {
+            SetDemoPresence(false);
+            break;
+        }
         case 'H':
         {
             SetGameState(gsHalted);
@@ -751,6 +763,11 @@
     }
 }
 
+void HWGame::SetDemoPresence(bool hasDemo)
+{
+    emit DemoPresenceChanged(hasDemo);
+}
+
 void HWGame::abort()
 {
     QByteArray buf;
--- a/QTfrontend/game.h	Fri Jul 26 01:13:48 2019 +0200
+++ b/QTfrontend/game.h	Sat Jul 27 03:42:17 2019 +0200
@@ -96,6 +96,7 @@
         void SendChat(const QString & msg);
         void SendTeamMessage(const QString & msg);
         void GameStateChanged(GameState gameState);
+        void DemoPresenceChanged(bool hasDemo);
         void GameStats(char type, const QString & info);
         void HaveRecord(RecordType type, const QByteArray & record);
         void ErrorMessage(const QString &);
@@ -126,6 +127,7 @@
         void SendCampaignConfig();
         void ParseMessage(const QByteArray & msg);
         void SetGameState(GameState state);
+        void SetDemoPresence(bool hasDemo);
         void sendCampaignVar(const QByteArray & varToSend);
         void writeCampaignVar(const QByteArray &varVal);
         void sendMissionVar(const QByteArray & varToSend);
--- a/QTfrontend/hwform.cpp	Fri Jul 26 01:13:48 2019 +0200
+++ b/QTfrontend/hwform.cpp	Sat Jul 27 03:42:17 2019 +0200
@@ -129,6 +129,7 @@
 // I started handing this down to each place it touches, but it was getting ridiculous
 // and this one flag does not warrant a static class
 bool frontendEffects = true;
+bool demoIsPresent = true;
 QString playerHash;
 
 QIcon finishedIcon;
@@ -823,6 +824,7 @@
             ui.pageGameStats->restartBtnVisible(false);
             break;
         }
+        ui.pageGameStats->saveDemoBtnEnabled(demoIsPresent);
     }
 
     if (id == ID_PAGE_MAIN)
@@ -1793,6 +1795,7 @@
     {
         case gsStarted:
         {
+            demoIsPresent = true;
             Music(false);
             if (wBackground) wBackground->stopAnimation();
             if (!hwnet || (!hwnet->isRoomChief() || !hwnet->isInRoom())) GoToPage(ID_PAGE_INGAME);
@@ -1846,12 +1849,18 @@
     }
 }
 
+void HWForm::DemoPresenceChanged(bool hasDemo)
+{
+    demoIsPresent = hasDemo;
+}
+
 void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo)
 {
     game = new HWGame(config, gamecfg, ammo, pTeamSelWidget);
     connect(game, SIGNAL(CampStateChanged(int)), this, SLOT(UpdateCampaignPageProgress(int)));
     connect(game, SIGNAL(TrainingStateChanged(int)), this, SLOT(UpdateTrainingPageTeam(int)));
     connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
+    connect(game, SIGNAL(DemoPresenceChanged(bool)), this, SLOT(DemoPresenceChanged(bool)));
     connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &)));
     connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowFatalErrorMessage(const QString &)), Qt::QueuedConnection);
     connect(game, SIGNAL(HaveRecord(RecordType, const QByteArray &)), this, SLOT(GetRecord(RecordType, const QByteArray &)));
--- a/QTfrontend/hwform.h	Fri Jul 26 01:13:48 2019 +0200
+++ b/QTfrontend/hwform.h	Sat Jul 27 03:42:17 2019 +0200
@@ -52,6 +52,7 @@
 class QSignalMapper;
 
 extern bool frontendEffects;
+extern bool demoIsPresent;
 extern QString playerHash;
 
 class HWForm : public QMainWindow
@@ -121,6 +122,7 @@
         void RemoveNetTeam(const HWTeam& team);
         void StartMPGame();
         void GameStateChanged(GameState gameState);
+        void DemoPresenceChanged(bool hasDemo);
         void ForcedDisconnect(const QString & reason);
         void ShowFatalErrorMessage(const QString &);
         void GetRecord(RecordType type, const QByteArray & record);
--- a/QTfrontend/ui/page/pagegamestats.cpp	Fri Jul 26 01:13:48 2019 +0200
+++ b/QTfrontend/ui/page/pagegamestats.cpp	Sat Jul 27 03:42:17 2019 +0200
@@ -171,6 +171,11 @@
     btnRestart->setVisible(visible);
 }
 
+void PageGameStats::saveDemoBtnEnabled(bool enabled)
+{
+    btnSave->setEnabled(enabled);
+}
+
 void PageGameStats::renderStats()
 {
     if(defaultGraphTitle) {
--- a/QTfrontend/ui/page/pagegamestats.h	Fri Jul 26 01:13:48 2019 +0200
+++ b/QTfrontend/ui/page/pagegamestats.h	Sat Jul 27 03:42:17 2019 +0200
@@ -58,6 +58,7 @@
         void clear();
         void renderStats();
         void restartBtnVisible(bool visible);
+        void saveDemoBtnEnabled(bool enabled);
 
     signals:
         void saveDemoRequested();
--- a/hedgewars/uCommandHandlers.pas	Fri Jul 26 01:13:48 2019 +0200
+++ b/hedgewars/uCommandHandlers.pas	Sat Jul 27 03:42:17 2019 +0200
@@ -73,6 +73,8 @@
     s:= s; // avoid compiler hint
     if GameState = gsConfirm then
         begin
+        if (luaCmdUsed) then
+            SendIPC(_S'm');
         SendIPC(_S'Q');
         GameState:= gsExit
         end
@@ -81,6 +83,8 @@
 procedure chHalt (var s: shortstring);
 begin
     s:= s; // avoid compiler hint
+    if (luaCmdUsed) then
+        SendIPC(_S'm');
     SendIPC(_S'H');
     GameState:= gsExit
 end;
--- a/hedgewars/uGearsHandlersMess.pas	Fri Jul 26 01:13:48 2019 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Sat Jul 27 03:42:17 2019 +0200
@@ -1701,6 +1701,8 @@
         if Gear^.Timer = 0 then
             begin
             SendIPC(_S'N');
+            if (luaCmdUsed) then
+                SendIPC(_S'm');
             SendIPC(_S'q');
             GameState := gsExit
             end