implemented actions for closing/enging program (needs testing over the net) 0.9.15
authorkoda
Sat, 15 Jan 2011 16:44:32 +0100
branch0.9.15
changeset 4746 3ae448aebe7e
parent 4744 ecc2c757d0df
child 4749 62471157bd62
implemented actions for closing/enging program (needs testing over the net)
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/hwform.cpp
hedgewars/uCommandHandlers.pas
hedgewars/uKeys.pas
--- a/QTfrontend/game.cpp	Fri Jan 14 00:31:21 2011 +0100
+++ b/QTfrontend/game.cpp	Sat Jan 15 16:44:32 2011 +0100
@@ -56,7 +56,7 @@
             emit HaveRecord(true, demo);
             break;
         default:
-            if (gameState == gsInterrupted) emit HaveRecord(false, demo);
+            if (gameState == gsInterrupted || gameState == gsHalted) emit HaveRecord(false, demo);
             else if (gameState == gsFinished) emit HaveRecord(true, demo);
     }
     SetGameState(gsStopped);
@@ -229,6 +229,10 @@
             SetGameState(gsFinished);
             break;
         }
+        case 'H': {
+            SetGameState(gsHalted);
+            break;
+        }
         case 's': {
             int size = msg.size();
             QString msgbody = QString::fromUtf8(msg.mid(2).left(size - 4));
@@ -250,8 +254,8 @@
             {
                 emit SendNet(msg);
             }
-        if (msg.at(1) != 's')
-            demo.append(msg);
+            if (msg.at(1) != 's')
+                demo.append(msg);
         }
     }
 }
--- a/QTfrontend/game.h	Fri Jan 14 00:31:21 2011 +0100
+++ b/QTfrontend/game.h	Sat Jan 15 16:44:32 2011 +0100
@@ -35,7 +35,8 @@
     gsInterrupted = 2,
     gsFinished = 3,
     gsStopped = 4,
-    gsDestroyed = 5
+    gsDestroyed = 5,
+    gsHalted = 6
 };
 
 bool checkForDir(const QString & dir);
--- a/QTfrontend/hwform.cpp	Fri Jan 14 00:31:21 2011 +0100
+++ b/QTfrontend/hwform.cpp	Sat Jan 15 16:44:32 2011 +0100
@@ -974,12 +974,13 @@
             if (id == ID_PAGE_INGAME ||
 // was room chief and the game was aborted
                 (hwnet && hwnet->isRoomChief() && hwnet->isInRoom() && 
-                    (gameState == gsInterrupted || gameState == gsStopped || gameState == gsDestroyed))) {
+                    (gameState == gsInterrupted || gameState == gsStopped || gameState == gsDestroyed || gameState == gsHalted))) {
                 if (id == ID_PAGE_INGAME) GoBack();
                 Music(ui.pageOptions->CBEnableFrontendMusic->isChecked());
                 if (wBackground) wBackground->startAnimation();
                 if (hwnet) hwnet->gameFinished();
             }
+            if (gameState == gsHalted) close();
         };
     }
 }
--- a/hedgewars/uCommandHandlers.pas	Fri Jan 14 00:31:21 2011 +0100
+++ b/hedgewars/uCommandHandlers.pas	Sat Jan 15 16:44:32 2011 +0100
@@ -51,6 +51,13 @@
     ParseCommand('chat team', true);
 end;
 
+procedure chShutdown (var s: shortstring);
+begin
+    s:= s; // avoid compiler hint
+    SendIPC('H');
+    GameState:= gsExit
+end;
+
 procedure chCheckProto(var s: shortstring);
 var i, c: LongInt;
 begin
@@ -591,6 +598,7 @@
     RegisterVariable('quit'    , vtCommand, @chQuit         , true );
     RegisterVariable('forcequit', vtCommand, @chForceQuit   , true );
     RegisterVariable('confirm' , vtCommand, @chConfirm      , true );
+    RegisterVariable('shutdown', vtCommand, @chShutdown     , true );
     RegisterVariable('+speedup', vtCommand, @chSpeedup_p    , true );
     RegisterVariable('-speedup', vtCommand, @chSpeedup_m    , true );
     RegisterVariable('zoomin'  , vtCommand, @chZoomIn       , true );
--- a/hedgewars/uKeys.pas	Fri Jan 14 00:31:21 2011 +0100
+++ b/hedgewars/uKeys.pas	Sat Jan 15 16:44:32 2011 +0100
@@ -136,8 +136,8 @@
     if ((tkbdn[KeyNameToCode('left_ctrl')] = 1) or (tkbdn[KeyNameToCode('right_ctrl')] = 1)) then
 {$ENDIF}
     begin
-        if tkbdn[KeyNameToCode('q')] = 1 then writelntoconsole ('cmd+q pressed')
-        else if tkbdn[KeyNameToCode('w')] = 1 then writelntoconsole ('cmd+w pressed')
+        if tkbdn[KeyNameToCode('q')] = 1 then ParseCommand ('shutdown', true)
+        else if tkbdn[KeyNameToCode('w')] = 1 then ParseCommand ('forcequit', true);
     end;
 
 // now process strokes