Commit 368e343e authored by Denis Kuplyakov's avatar Denis Kuplyakov

Difficulty selector works on StartGameDialog now.

You can select computer skill on StartGameDialog. Also KgThemeProvider
is now stored in KReversiMainWindow to allow StartGameDialog use it.
parent 6b44917b
......@@ -19,17 +19,15 @@
#include "kreversiview.h"
KReversiView::KReversiView(KReversiGame* game, QWidget *parent) :
KReversiView::KReversiView(KReversiGame* game, QWidget *parent, KgThemeProvider *provider) :
KgDeclarativeView(parent), m_delay(ANIMATION_SPEED_NORMAL), m_game(0),
m_showLastMove(false), m_showLegalMoves(false),
m_showLabels(false)
m_showLabels(false), m_provider(provider)
{
qmlRegisterType<ColorScheme>("ColorScheme", 1, 0, "ColorScheme");
m_provider = new KgThemeProvider();
m_provider->discoverThemes("appdata", QLatin1String("pics"));
m_provider->setDeclarativeEngine("themeProvider", engine());
qmlRegisterType<ColorScheme>("ColorScheme", 1, 0, "ColorScheme");
QString path =
KStandardDirs::locate("appdata", QLatin1String("qml/Table.qml"));
setSource(QUrl::fromLocalFile(path));
......
......@@ -44,7 +44,7 @@ class KReversiView : public KgDeclarativeView
Q_OBJECT
public:
enum ChipsPrefix { Colored, BlackWhite };
explicit KReversiView(KReversiGame* game, QWidget *parent = 0);
explicit KReversiView(KReversiGame* game, QWidget *parent, KgThemeProvider *provider);
/**
* Sets the game object which this view will visualize/use
......
......@@ -78,10 +78,13 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo)
: KXmlGuiWindow(parent), m_view(0), m_game(0),
m_historyDock(0), m_historyView(0),
m_firstShow(true), m_startInDemoMode(startDemo), /*m_lowestSkill(6),*/
m_undoAct(0), m_hintAct(0), m_demoAct(0)
m_undoAct(0), m_hintAct(0), /*m_demoAct(0),*/ m_startDialog(0)
{
memset(m_player, 0, sizeof(m_player));
m_provider = new KgThemeProvider();
m_provider->discoverThemes("appdata", QLatin1String("pics"));
statusBar()->insertItem(i18n("Press start game!"), COMMON_STATUSBAR_ID);
statusBar()->insertItem("", BLACK_STATUSBAR_ID);
statusBar()->insertItem("", WHITE_STATUSBAR_ID);
......@@ -105,7 +108,7 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo)
addDockWidget(Qt::RightDockWidgetArea, m_historyDock);
// create main game view
m_view = new KReversiView(m_game, this);
m_view = new KReversiView(m_game, this, m_provider);
setCentralWidget(m_view);
// initialise actions
......@@ -118,8 +121,14 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo)
m_historyDock->hide();
// initialise dialog handlers
connect(&m_startDialog, SIGNAL(startGame()), this, SLOT(slotDialogReady()));
// initialise dialog handler
m_startDialog = new StartGameDialog(this, m_provider);
connect(m_startDialog, SIGNAL(startGame()), this, SLOT(slotDialogReady()));
}
KReversiMainWindow::~KReversiMainWindow()
{
delete m_provider;
}
void KReversiMainWindow::setupActionsInit()
......@@ -222,7 +231,8 @@ void KReversiMainWindow::slotShowMovesHistory(bool toggled)
// if (m_game && m_game->isGameOver())
// slotNewGame();
// toggled = true;
// toggled = true
// m_undoAct->setEnabled(m_game->canUndo());;
// m_demoAct->setIcon(KIcon(QLatin1String("media-playback-pause")));
// m_demoAct->setChecked(true);
// }
......@@ -243,7 +253,7 @@ void KReversiMainWindow::slotNewGame()
// if (m_undoAct)
// m_undoAct->setEnabled(false);
m_startDialog.exec();
m_startDialog->exec();
}
void KReversiMainWindow::slotGameOver()
......@@ -251,9 +261,6 @@ void KReversiMainWindow::slotGameOver()
m_hintAct->setEnabled(false);
m_undoAct->setEnabled(m_game->canUndo());
// //TODO: only if it is not computer-computer match
// m_undoAct->setEnabled(m_game->canUndo());
int blackScore = m_game->playerScore(Black);
int whiteScore = m_game->playerScore(White);
......@@ -330,8 +337,6 @@ void KReversiMainWindow::slotGameOver()
void KReversiMainWindow::slotMoveFinished()
{
// m_undoAct->setEnabled(m_game->canUndo());
updateHistory();
updateStatusBar();
......@@ -372,7 +377,7 @@ void KReversiMainWindow::slotHighscores()
void KReversiMainWindow::slotDialogReady()
{
GameStartInformation info = m_startDialog.createGameStartInformation();
GameStartInformation info = m_startDialog->createGameStartInformation();
receivedGameStartInformation(info);
}
......
......@@ -70,6 +70,7 @@ class KReversiMainWindow : public KXmlGuiWindow
Q_OBJECT
public:
explicit KReversiMainWindow(QWidget* parent = 0, bool startDemo = false);
~KReversiMainWindow();
public slots:
void slotNewGame();
void levelChanged();
......@@ -94,7 +95,7 @@ private:
void receivedGameStartInformation(GameStartInformation info);
KReversiPlayer *m_player[2];
StartGameDialog m_startDialog;
StartGameDialog *m_startDialog;
GameStartInformation m_nowPlayingInfo;
......@@ -106,9 +107,11 @@ private:
bool m_firstShow;
bool m_startInDemoMode;
KgThemeProvider *m_provider;
QAction *m_undoAct;
QAction *m_hintAct;
QAction *m_demoAct;
// QAction *m_demoAct;
KToggleAction *m_showLast;
KToggleAction *m_showLegal;
KToggleAction *m_showMovesAct;
......
......@@ -3,10 +3,12 @@
#include <QMessageBox>
#include <QCloseEvent>
#include <KgDifficulty>
#include <kdebug.h>
StartGameDialog::StartGameDialog(QWidget *parent) :
StartGameDialog::StartGameDialog(QWidget *parent, KgThemeProvider *provider) :
KDialog(parent),
ui(new Ui::StartGameDialog)
ui(new Ui::StartGameDialog), m_provider(provider)
{
setModal(true);
......@@ -28,6 +30,19 @@ StartGameDialog::StartGameDialog(QWidget *parent) :
ui->blackTypeGroup->setId(ui->blackHuman, GameStartInformation::Human);
ui->blackTypeGroup->setId(ui->blackAI, GameStartInformation::AI);
QList< const KgDifficultyLevel * > diffList = Kg::difficulty()->levels();
const KIcon icon("games-difficult");
for (int i = 0; i < diffList.size(); i++) {
ui->blackSkill->addItem(icon, diffList.at(i)->title());
ui->whiteSkill->addItem(icon, diffList.at(i)->title());
if (diffList.at(i)->isDefault())
{
ui->whiteSkill->setCurrentIndex(i);
ui->blackSkill->setCurrentIndex(i);
}
}
connect(ui->blackTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotUpdateBlack(int)));
connect(ui->whiteTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotUpdateWhite(int)));
......
......@@ -5,6 +5,7 @@
#include "gamestartinformation.h"
#include "commondefs.h"
#include <KUser>
#include <KgThemeProvider>
namespace Ui {
class StartGameDialog;
......@@ -15,7 +16,7 @@ class StartGameDialog : public KDialog
Q_OBJECT
public:
explicit StartGameDialog(QWidget *parent = 0);
explicit StartGameDialog(QWidget *parent, KgThemeProvider *provider);
~StartGameDialog();
GameStartInformation createGameStartInformation() const;
......@@ -32,6 +33,7 @@ private:
Ui::StartGameDialog *ui;
QWidget *m_contents;
KUser m_user;
KgThemeProvider *m_provider;
};
#endif // STARTGAMEDIALOG_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment