Commit 6e75b6b2 authored by Alexander Schuch's avatar Alexander Schuch
Browse files

Make "current standings" dialogue dockable.

The dialogue "current standings" is replaced by a dockable widget. This way
the player is able to see the standings all the time without the need to
open/close the dialogue at the beginning of each turn.

The dockable widget can also be made floating, so it can be used almost the
same as the modal dialogue before.

REVIEW: 113782
GUI:
parent 5c1f601b
......@@ -56,6 +56,8 @@ set(konquest_SRCS
players/player_gui.cpp
players/spectatorplayer.cpp
players/spectatorplayer_gui.cpp
view/standingswidget.cpp
)
kde4_add_ui_files(konquest_SRCS dialogs/newGameDialog.ui )
......
......@@ -19,6 +19,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "scoredlg.h"
#include <klocale.h>
......@@ -29,77 +30,20 @@
#include <QHeaderView>
ScoreDlg::ScoreDlg( QWidget *parent, const QString& title, QList<Player *> players )
: KDialog(parent), m_players(players)
: KDialog(parent)
{
setObjectName( QLatin1String( "ScoreDlg" ) );
setModal( true );
setCaption(title);
setButtons( KDialog::Ok );
// Create the table.
m_scoreTable = new QTableWidget( this );
m_scoreTable->setColumnCount(6);
QStringList headers;
headers << i18nc("The player name", "Player") << i18n("Ships\nBuilt")
<< i18n("Planets\nConquered") << i18n("Fleets\nLaunched")
<< i18n("Fleets\nDestroyed") << i18n("Ships\nDestroyed");
m_scoreTable->setHorizontalHeaderLabels(headers);
m_scoreTable->verticalHeader()->hide();
init();
m_scoreTable = new StandingsWidget(this, players);
m_scoreTable->setMinimumSize( m_scoreTable->sizeHint() );
m_scoreTable->setSelectionMode( QAbstractItemView::NoSelection );
m_scoreTable->setSortingEnabled(true);
setMainWidget( m_scoreTable );
connect( this, SIGNAL(okClicked()), this, SLOT(accept()) );
resize( 580, 140 );
}
ScoreDlg::~ScoreDlg()
{
}
void
ScoreDlg::init()
ScoreDlg::~ScoreDlg()
{
m_scoreTable->setRowCount(m_players.count());
int row = 0;
QTableWidgetItem *item;
foreach (Player *curPlayer, m_players) {
item = new QTableWidgetItem(curPlayer->name());
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_scoreTable->setItem(row, 0, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->shipsBuilt());
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_scoreTable->setItem(row, 1, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->planetsConquered());
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_scoreTable->setItem(row, 2, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->fleetsLaunched());
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_scoreTable->setItem(row, 3, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->enemyFleetsDestroyed());
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_scoreTable->setItem(row, 4, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->enemyShipsDestroyed());
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_scoreTable->setItem(row, 5, item);
row++;
}
}
......@@ -19,14 +19,15 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KONQUEST_SCOREDLG_H
#define KONQUEST_SCOREDLG_H
#include <QTableWidget>
#include <KDialog>
#include "../players/player.h"
#include "../view/standingswidget.h"
class ScoreDlg : public KDialog
......@@ -38,10 +39,7 @@ public:
~ScoreDlg();
private:
void init();
QList<Player *> m_players;
QTableWidget *m_scoreTable;
StandingsWidget *m_scoreTable;
};
......
......@@ -46,15 +46,18 @@
#include "dialogs/scoredlg.h"
#include "dialogs/fleetdlg.h"
#include "view/standingswidget.h"
#include <cmath>
/*********************************************************************
Game Board
*********************************************************************/
GameView::GameView(QWidget *parent, Game *game, QDockWidget *messagesDock)
GameView::GameView(QWidget *parent, Game *game, QDockWidget *messagesDock, QDockWidget *standingsDock)
: QWidget( parent ),
m_messagesDock(messagesDock),
m_standingsDock(standingsDock),
m_game( game ),
m_queueMessages(false),
m_messageQueue(),
......@@ -106,6 +109,9 @@ GameView::GameView(QWidget *parent, Game *game, QDockWidget *messagesDock)
m_messagesDock->setWidget(m_msgWidget);
m_standingsWidget = new StandingsWidget(0);
m_standingsDock->setWidget(m_standingsWidget);
m_gameMessage = new QLabel( this );
m_gameMessage->setPalette( palette );
......@@ -249,6 +255,20 @@ GameView::keyPressEvent( QKeyEvent *e )
//************************************************************************
// Game engine/state machine
//************************************************************************
/**
* Prepare the turn for a local player by updating the informational widgets.
*/
void
GameView::turnPreparation()
{
m_standingsWidget->update(m_game->players());
turn();
}
void
GameView::turn()
{
......@@ -474,7 +494,7 @@ GameView::startNewGame()
LocalPlayer *local = qobject_cast<LocalPlayer*>(player);
if (local)
connect(local, SIGNAL(canPlay()), this, SLOT(turn()));
connect(local, SIGNAL(canPlay()), this, SLOT(turnPreparation()));
}
connect(m_game, SIGNAL(finished()), this, SLOT(gameOver()));
......@@ -523,11 +543,23 @@ GameView::shutdownGame()
void
GameView::gameOver()
{
if(m_initCompleted){
if (m_initCompleted) {
kDebug() << "Game over";
ScoreDlg *scoreDlg = new ScoreDlg( this, i18n("Final Standings"),
m_game->players() );
/**
* @todo This is an attempt to remove duplicate information from screen.
* It is not a final solution, but only the best we came up with. The
* problem is that the messages cannot be seen anymore, so the player
* cannot check what happened last. Furthermore, this sudden change of
* the GUI setup can be confusing for players.
*/
m_messagesDock->hide();
m_standingsDock->hide();
ScoreDlg *scoreDlg = new ScoreDlg(this, i18n("Final Standings"), m_game->players());
scoreDlg->exec();
scoreDlg->deleteLater();
cleanupGame();
}
......@@ -535,6 +567,7 @@ GameView::gameOver()
m_cleanupNeeded = true;
}
void
GameView::cleanupGame()
{
......@@ -632,6 +665,15 @@ GameView::changeGameView()
kDebug() << "Calling GameView::changeGameView" << isRunning;
m_messagesDock->setVisible(isRunning);
if (!isRunning) {
// Only hide the standings dock if the game is not running, but do not
// automatically show it as soon as the game is running.
m_standingsDock->hide();
}
m_mapWidget->setVisible(isRunning);
m_gameMessage->setVisible(isRunning);
m_standingOrder->setVisible(isRunning);
......@@ -678,14 +720,6 @@ GameView::measureDistance()
}
}
void
GameView::showScores()
{
ScoreDlg *scoreDlg = new ScoreDlg( this, i18n("Current Standings"),
m_game->players() );
scoreDlg->exec();
scoreDlg->deleteLater();
}
void
GameView::showFleets()
......
......@@ -29,7 +29,6 @@
#include "players/player.h"
#include "game.h"
//************************************************************************
// forward declarations
//************************************************************************
......@@ -48,6 +47,7 @@ class Player;
class MapView;
class MapScene;
class GameLogic;
class StandingsWidget;
struct GameMessage {
......@@ -77,7 +77,7 @@ class GameView : public QWidget
Q_OBJECT
public:
explicit GameView(QWidget *parent, Game *game, QDockWidget *messagesDock);
explicit GameView(QWidget *parent, Game *game, QDockWidget *messagesDock, QDockWidget *standingsDock);
virtual ~GameView();
bool confirmNewGame();
......@@ -92,14 +92,13 @@ protected slots:
// Toolbar items
//***************************************************************
void measureDistance();
void showScores();
void showFleets();
public slots:
void startNewGame();
void gameMsg(const KLocalizedString &msg, Player *player = 0,
Planet *planet = 0, Player *planetPlayer = 0);
void turn();
void turnPreparation();
signals:
void newGUIState( GUIState newState );
......@@ -117,7 +116,8 @@ private slots:
private:
void changeGameView();
void cleanupGame();
void turn();
//***************************************************************
// Display Widgets
......@@ -133,7 +133,10 @@ private:
QLabel *m_splashScreen;
QTextEdit *m_msgWidget;
StandingsWidget *m_standingsWidget;
QDockWidget *m_messagesDock;
QDockWidget *m_standingsDock;
//***************************************************************
// Game objects
......
<?xml version="1.0" encoding="UTF-8"?>
<gui name="konquest"
version="3"
version="4"
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
......@@ -9,11 +9,11 @@
<MenuBar>
<Menu name="game"><text>&amp;Game</text>
<Action name="game_measure"/>
<Action name="game_scores"/>
<Action name="game_fleets"/>
</Menu>
<Menu name="view"><text>&amp;View</text>
<Action name="view_messages"/>
<Action name="view_standings"/>
</Menu>
</MenuBar>
......@@ -24,7 +24,7 @@
<Action name="move_end_turn"/>
<Separator/>
<Action name="game_measure"/>
<Action name="game_scores"/>
<Action name="view_standings"/>
<Action name="game_fleets"/>
</ToolBar>
......
......@@ -91,12 +91,6 @@ MainWindow::setupActions()
m_measureAction->setText( i18n("&Measure Distance") );
m_measureAction->setEnabled(false);
// Show standings
m_standingAction = actionCollection()->addAction( QLatin1String( "game_scores" ) );
m_standingAction->setIcon( KIcon( QLatin1String( "help-contents" )) );
m_standingAction->setText( i18n("&Show Standings") );
m_standingAction->setEnabled(false);
// Show fleet overview
m_fleetAction = actionCollection()->addAction( QLatin1String( "game_fleets" ) );
m_fleetAction->setIcon( KIcon( QLatin1String( "fork" )) );
......@@ -119,6 +113,10 @@ MainWindow::setupActions()
m_messagesAction->setCheckable(true);
m_messagesAction->setChecked(m_messagesDock->isVisible());
// The action signal "toggled" is fired even in case the state is changed
// via code using setChecked(). "triggered" however is only fired if the
// user actually triggered the change.
// The dock signal "visibilityChanged" is fired if the dock is shown or
// hidden. But this includes hidden in a tab as well. The action should not
// represent the visibility state, but if the dock is present somewhere in
......@@ -127,6 +125,22 @@ MainWindow::setupActions()
connect(m_messagesAction, SIGNAL(triggered(bool)), m_messagesDock, SLOT(setVisible(bool)));
connect(m_messagesDock, SIGNAL(visibilityChanged(bool)), this, SLOT(updateMessagesActionSlot()));
// docking area - standings
m_standingsDock = new QDockWidget(i18n("Standings"), this);
m_standingsDock->setObjectName("dock-standings");
tabifyDockWidget(m_messagesDock, m_standingsDock);
m_standingsAction = actionCollection()->addAction(QLatin1String("view_standings"));
m_standingsAction->setIcon(KIcon(QLatin1String("help-contents")));
m_standingsAction->setText(i18n("Show &Standings"));
m_standingsAction->setCheckable(true);
m_standingsAction->setChecked(m_standingsDock->isVisible());
connect(m_standingsAction, SIGNAL(triggered(bool)), m_standingsDock, SLOT(setVisible(bool)));
connect(m_standingsDock, SIGNAL(visibilityChanged(bool)), this, SLOT(updateStandingsActionSlot()));
}
......@@ -134,7 +148,7 @@ void
MainWindow::setupGameView()
{
m_game = new LocalGame( this );
m_gameView = new GameView(this, m_game, m_messagesDock);
m_gameView = new GameView(this, m_game, m_messagesDock, m_standingsDock);
setCentralWidget( m_gameView );
connect ( m_game, SIGNAL( gameMsg(const KLocalizedString &,
......@@ -147,7 +161,6 @@ MainWindow::setupGameView()
this, SLOT( guiStateChange( GUIState ) ) );
connect(m_measureAction, SIGNAL(triggered(bool)), m_gameView, SLOT( measureDistance() ));
connect(m_standingAction, SIGNAL(triggered(bool)), m_gameView, SLOT( showScores() ));
connect(m_fleetAction, SIGNAL(triggered(bool)), m_gameView, SLOT( showFleets() ));
connect(m_endTurnAction, SIGNAL(triggered()), m_gameView, SLOT(nextPlayer()));
connect(m_endGameAction, SIGNAL(triggered()), m_gameView, SLOT(shutdownGame()));
......@@ -169,10 +182,13 @@ MainWindow::setupGUI()
*/
m_messagesAction->setEnabled(false);
m_standingsAction->setEnabled(false);
m_messagesDock->toggleViewAction()->setEnabled(false);
m_standingsDock->toggleViewAction()->setEnabled(false);
m_messagesDock->hide();
m_standingsDock->hide();
}
......@@ -211,12 +227,13 @@ MainWindow::guiStateChange( GUIState newState )
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 );
m_fleetAction ->setEnabled( newState == SOURCE_PLANET );
m_messagesAction->setEnabled(m_game->isRunning());
m_standingsAction->setEnabled(m_game->isRunning());
m_messagesDock->toggleViewAction()->setEnabled(m_game->isRunning());
m_standingsDock->toggleViewAction()->setEnabled(m_game->isRunning());
m_statusBarText->setText(i18n("Turn # %1", m_game->turnCounter()));
}
......@@ -227,3 +244,10 @@ MainWindow::updateMessagesActionSlot()
{
m_messagesAction->setChecked(m_messagesDock->toggleViewAction()->isChecked());
}
void
MainWindow::updateStandingsActionSlot()
{
m_standingsAction->setChecked(m_standingsDock->toggleViewAction()->isChecked());
}
......@@ -52,6 +52,7 @@ private slots:
void guiStateChange( GUIState );
void startNewGame();
void updateMessagesActionSlot();
void updateStandingsActionSlot();
private:
// Widgets
......@@ -62,13 +63,14 @@ private:
// Actions
KAction *m_endTurnAction;
KAction *m_messagesAction;
KAction *m_standingsAction;
QAction *m_endGameAction;
QAction *m_measureAction;
QAction *m_standingAction;
QAction *m_fleetAction;
QDockWidget *m_messagesDock;
QDockWidget *m_standingsDock;
};
#endif // KONQUEST_MAINWIN_H
/*
Copyright 2003 Russell Steffen <rsteffen@bayarea.net>
Copyright 2003 Stephan Zehetner <s.zehetner@nevox.org>
Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>
Copyright 2006 Inge Wallin <inge@lysator.liu.se>
Copyright 2006 Pierre Ducroquet <pinaraf@gmail.com>
Copyright 2013 Alexander Schuch <aschuch247@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "standingswidget.h"
#include <QHeaderView>
#include <QTableWidget>
#include <QVBoxLayout>
#include <klocale.h>
#include <kcomponentdata.h>
#include <KStandardGuiItem>
#include <kguiitem.h>
StandingsWidget::StandingsWidget(QWidget *parent) :
QWidget(parent)
{
setupTable();
}
/**
* @note Use "delegating constructor" once C++11 is required by KDE.
*/
StandingsWidget::StandingsWidget(QWidget *parent, const QList<Player *> players) :
// StandingsWidget(parent)
QWidget(parent)
{
setupTable();
update(players);
}
StandingsWidget::~StandingsWidget()
{
}
QSize
StandingsWidget::sizeHint() const
{
int w = m_scoreTable->verticalHeader()->width();
int h = m_scoreTable->horizontalHeader()->height();
for (int col = 0; col < m_scoreTable->columnCount(); ++col) {
w += m_scoreTable->columnWidth(col);
}
for (int row = 0; row < m_scoreTable->rowCount(); ++row ) {
h += m_scoreTable->rowHeight(row);
}
/**
* @todo The size calculated here does not yet prevent scrollbars to be
* shown for the table. Figure out the offsets needed to be added and remove
* the hard-coded numbers below!
*/
return QSize(w, h) + QSize(20, 40);
}
void
StandingsWidget::update(const QList<Player *> players )
{
m_scoreTable->setRowCount(players.count());
m_scoreTable->clearContents();
m_scoreTable->setSortingEnabled(false);
int row = 0;
QTableWidgetItem *item;
foreach (Player *curPlayer, players) {
item = new QTableWidgetItem(curPlayer->name());
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_scoreTable->setItem(row, 0, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->shipsBuilt());
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_scoreTable->setItem(row, 1, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->planetsConquered());
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_scoreTable->setItem(row, 2, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->fleetsLaunched());
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_scoreTable->setItem(row, 3, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->enemyFleetsDestroyed());
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_scoreTable->setItem(row, 4, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->enemyShipsDestroyed());
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
m_scoreTable->setItem(row, 5, item);
++row;
}
m_scoreTable->setSortingEnabled(true);
m_scoreTable->resizeColumnsToContents();
}
void
StandingsWidget::setupTable()
{
setObjectName(QLatin1String("widget-standings"));
QVBoxLayout *main = new QVBoxLayout(this);
m_scoreTable = new QTableWidget();
m_scoreTable->setColumnCount(6);
m_scoreTable->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
m_scoreTable->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
m_scoreTable->setSelectionMode(QAbstractItemView::NoSelection);
QStringList headers;
headers
<< i18nc("The player name", "Player")
<< i18n("Ships\nBuilt")
<< i18n("Planets\nConquered")
<< i18n("Fleets\nLaunched")
<< i18n("Fleets\nDestroyed")
<< i18n("Ships\nDestroyed");
m_scoreTable->setHorizontalHeaderLabels(headers);
m_scoreTable->verticalHeader()->hide();
main->addWidget(m_scoreTable);
}
/*
Copyright 2003 Russell Steffen <rsteffen@bayarea.net>
Copyright 2003 Stephan Zehetner <s.zehetner@nevox.org>
Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com>
Copyright 2006 Inge Wallin <inge@lysator.liu.se>
Copyright 2006 Pierre Ducroquet <pinaraf@gmail.com>
Copyright 2013 Alexander Schuch <aschuch247@gmail.com>
This program is free software; you can redistribute it and/or modify