[kde-doc-english] [konquest] /: Improve "end turn" action handling.

Alexander Schuch aschuch247 at gmail.com
Sun Nov 10 01:51:15 UTC 2013


Git commit 814a1368d69f0fa2a9f3c5472ffa9ce804d78644 by Alexander Schuch.
Committed on 03/11/2013 at 16:42.
Pushed by aschuch into branch 'master'.

Improve "end turn" action handling.

The recently added KStandardGameAction::endTurn() action now has an own
default shortcut of Ctrl+E. The button is added to the toolbar by default.

Furthermore, the "end turn" button now is enabled/disabled depending on the
game state. It no longer is possible to end the turn while in the middle of
a send fleet command sequence.

Use the very same condition for enabling/disabling the custom "end turn"
button and the "end turn" action. This required some code cleanup.

The custom palette for the game board now colours disabled elements darker
so that they actually look disabled.

REVIEW: 113528
GUI:

M  +27   -42   gameview.cc
M  +3    -1    konquestui.rc
M  +13   -1    mainwin.cc
M  +3    -2    mainwin.h

http://commits.kde.org/konquest/814a1368d69f0fa2a9f3c5472ffa9ce804d78644

diff --git a/gameview.cc b/gameview.cc
index a01bfde..2505994 100644
--- a/gameview.cc
+++ b/gameview.cc
@@ -68,19 +68,19 @@ GameView::GameView( QWidget *parent, Game *game )
 
     QColor col(Qt::green);
     QPalette palette;
-    palette.setColorGroup( QPalette::Active,   Qt::white,    Qt::black, 
-                           col.light(),        col.dark(),   col,
-                           col.dark(75),       col.dark(75), col.dark(),
+    palette.setColorGroup( QPalette::Active,    Qt::white,          Qt::black,
+                           col.lighter(),       col.darker(),       col,
+                           col.lighter(125),    col.lighter(125),   col.darker(),
                            Qt::black );
-    palette.setColorGroup( QPalette::Inactive, Qt::white,    Qt::black,
-                           col.light(),        col.dark(),   col,
-                           col.dark(75),       col.dark(75), col.dark(), 
+    palette.setColorGroup( QPalette::Inactive,  Qt::white,          Qt::black,
+                           col.lighter(),       col.darker(),       col,
+                           col.lighter(125),    col.lighter(125),   col.darker(),
                            Qt::black );
-    palette.setColorGroup( QPalette::Disabled, Qt::white,    Qt::black,
-                           col.light(),        col.dark(),   col,
-                           col.dark(75),       col.dark(75), Qt::black,
+    palette.setColorGroup( QPalette::Disabled,  Qt::white,          QColor(Qt::darkGray).darker(),
+                           col.lighter(),       col.darker(),       col,
+                           col.darker(150),     col.lighter(125),   Qt::black,
                            Qt::black );
-    
+
     blackPal.setColor( QPalette::Base, Qt::black );
     blackPal.setColor( QPalette::Window, Qt::black );
     blackPal.setColor( QPalette::Button, QColor(Qt::darkGray).darker() );
@@ -144,7 +144,7 @@ GameView::GameView( QWidget *parent, Game *game )
     topLineLayout->addWidget( m_standingOrder, 1 );
     topLineLayout->addWidget( m_shipCountEdit, 1 );
     topLineLayout->addWidget( m_endTurnBtn, 1 );
-    
+
     mainLayout->addLayout( topLineLayout );
     mainLayout->addWidget( m_mapWidget );
     mainLayout->addWidget( m_msgWidget );
@@ -280,7 +280,6 @@ GameView::turn()
             m_shipCountEdit->setText( QString() );
             m_standingOrder->setEnabled(false);
             m_standingOrder->setCheckState(Qt::Unchecked);
-            m_endTurnBtn->setEnabled( true );
             m_mapScene->unselectPlanet();
             m_gameMessage->setText( i18n("<qt>%1: Select source planet...</qt>", m_game->currentPlayer()->coloredName()) );
             setFocus();
@@ -298,7 +297,6 @@ GameView::turn()
         } else {
             m_shipCountEdit->setEnabled(false);
             m_standingOrder->setEnabled(false);
-            m_endTurnBtn->setEnabled( false );
             m_mapScene->selectPlanet(sourcePlanet);
             m_gameMessage->setText( i18n("<qt>%1: Select destination planet...</qt>", m_game->currentPlayer()->coloredName()) );
             setFocus();
@@ -316,7 +314,6 @@ GameView::turn()
 
             m_shipCountEdit->setEnabled(false);
             m_standingOrder->setEnabled(false);
-            m_endTurnBtn->setEnabled( true );
 
             m_guiState = NONE;
             turn();
@@ -330,8 +327,6 @@ GameView::turn()
             m_standingOrder->setEnabled(true);
             m_shipCountEdit->setFocus();
 
-            m_endTurnBtn->setEnabled( false );
-
             m_mapScene->unselectPlanet();
         }
 
@@ -345,7 +340,6 @@ GameView::turn()
             turn();
         } else {
             m_shipCountEdit->setEnabled(false);
-            m_endTurnBtn->setEnabled( true );
             m_mapScene->unselectPlanet();
 
             m_gameMessage->setText( i18n("Ruler: Select starting planet.") );
@@ -375,7 +369,6 @@ GameView::turn()
         } else {
             m_gameMessage->setText( i18n("Ruler: Select ending planet.") );
             m_shipCountEdit->setEnabled(false);
-            m_endTurnBtn->setEnabled( false );
             m_mapScene->selectPlanet(sourcePlanet);
 
             setFocus();
@@ -386,6 +379,8 @@ GameView::turn()
         break;
     }
 
+    m_endTurnBtn->setEnabled(m_guiState == SOURCE_PLANET);
+
     emit newGUIState( m_guiState );
 }
 
@@ -492,11 +487,10 @@ GameView::startNewGame()
 
     // Set up the base GUI for a new game.
     m_msgWidget->clear();
-    m_shipCountEdit->show();
-    m_shipCountEdit->setEnabled(true);
+    m_shipCountEdit->setEnabled(false);
     m_initCompleted = true;
 
-    //call GameView::gameOver now if needed happens if the game ends immiedently after starting.
+    //call GameView::gameOver now if needed happens if the game ends immediately after starting.
     if(m_cleanupNeeded)
         gameOver();
 }
@@ -545,12 +539,8 @@ GameView::cleanupGame()
 {
     m_mapScene->clearMap();
     m_game->stop();
-    
-    m_shipCountEdit->hide();
-    m_endTurnBtn->setEnabled( false );
 
-    m_gameMessage->hide();
-    m_endTurnBtn->hide();
+    m_endTurnBtn->setEnabled( false );
 
     changeGameView();
     m_guiState = NONE;
@@ -636,22 +626,17 @@ GameView::newShipCount()
 void
 GameView::changeGameView()
 {
-    kDebug() << "Calling GameView::changeGameView" << m_game->isRunning();
-    if( m_game->isRunning()) {
-        m_msgWidget->show();
-        m_mapWidget->show();
-        m_gameMessage->show();
-        m_endTurnBtn->show();
-        m_shipCountEdit->show();
-        m_splashScreen->hide();
-    } else {
-        m_mapWidget->hide();
-        m_msgWidget->hide();
-        m_gameMessage->hide();
-        m_endTurnBtn->hide();
-        m_shipCountEdit->hide();
-        m_splashScreen->show();
-    }
+    bool isRunning = m_game->isRunning();
+
+    kDebug() << "Calling GameView::changeGameView" << isRunning;
+
+    m_msgWidget->setVisible(isRunning);
+    m_mapWidget->setVisible(isRunning);
+    m_gameMessage->setVisible(isRunning);
+    m_standingOrder->setVisible(isRunning);
+    m_shipCountEdit->setVisible(isRunning);
+    m_endTurnBtn->setVisible(isRunning);
+    m_splashScreen->setVisible(!isRunning); // negation
 }
 
 
diff --git a/konquestui.rc b/konquestui.rc
index cd43d33..a99d39d 100644
--- a/konquestui.rc
+++ b/konquestui.rc
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gui name="konquest"
-     version="1"
+     version="2"
      xmlns="http://www.kde.org/standards/kxmlgui/1.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.kde.org/standards/kxmlgui/1.0
@@ -18,6 +18,8 @@
   <Action name="game_new"/>
   <Action name="game_end"/>
   <Separator/>
+  <Action name="move_end_turn"/>
+  <Separator/>
   <Action name="game_measure"/>
   <Action name="game_scores"/>
   <Action name="game_fleets"/>
diff --git a/mainwin.cc b/mainwin.cc
index 929c61d..6f2a70d 100644
--- a/mainwin.cc
+++ b/mainwin.cc
@@ -70,6 +70,7 @@ MainWindow::setupActions()
     KStandardGameAction::quit( this, SLOT( close() ), actionCollection() );
 
     m_endTurnAction = KStandardGameAction::endTurn(this, NULL, actionCollection());
+    m_endTurnAction->setShortcut(Qt::CTRL + Qt::Key_E);
     m_endTurnAction->setEnabled(false);
 
     m_endGameAction = KStandardGameAction::end( this, NULL, actionCollection() );
@@ -145,7 +146,18 @@ MainWindow::guiStateChange( GUIState newState )
         this->setupGameView();
     }
 
-    m_endTurnAction ->setEnabled( m_game->isRunning() );
+    // An alternative to disabling the "end turn" action during "send fleet
+    // command sequence" is to simply abort this sequence if the user decides
+    // to "end turn" before completion.
+
+    /**
+     * @todo The game view handles the state of the actions, so the game view
+     * should be able to update the enabled state of the actions as well. This
+     * should be implemented via signals, instead of copying the conditions here
+     * again.
+     */
+
+    m_endTurnAction ->setEnabled( m_game->isRunning() && (newState == SOURCE_PLANET) );
     m_endGameAction ->setEnabled( m_game->isRunning() );
     m_measureAction ->setEnabled( newState == SOURCE_PLANET );
     m_standingAction->setEnabled( newState == SOURCE_PLANET );
diff --git a/mainwin.h b/mainwin.h
index d72fd46..c50ea80 100644
--- a/mainwin.h
+++ b/mainwin.h
@@ -22,7 +22,7 @@
 #ifndef KONQUEST_MAINWIN_H
 #define KONQUEST_MAINWIN_H
 
-
+#include <kaction.h>
 #include <kxmlguiwindow.h>
 
 #include "game.h"
@@ -53,7 +53,8 @@ private:
     QLabel     *m_statusBarText;
 
     // Actions
-    QAction  *m_endTurnAction;
+    KAction  *m_endTurnAction;
+
     QAction  *m_endGameAction;
     QAction  *m_measureAction;
     QAction  *m_standingAction;


More information about the kde-doc-english mailing list