Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Saving a last configuration

  • Loading branch information...
commit f3c9a0dbd5d43862e8a55203acede1e9aec92efb 1 parent 2e55e79
Minh Ngo authored
4 dottable.cpp
View
@@ -26,7 +26,7 @@
#include "dottable.hpp"
#include <KMessageBox>
#include <KLocalizedString>
-#include <KDebug>
+#include "graph.hpp"
#include "polygonfinder.hpp"
#include "stepqueue.hpp"
@@ -116,7 +116,7 @@ namespace KDots
if (currentPoint.owner () != NONE || currentPoint.isCaptured ())
return;
-
+
const Owner current = m_steps->getCurrentOwner ();
currentPoint.setOwner (current);
4 include/dottable.hpp
View
@@ -27,12 +27,12 @@
#define KDOTS_DOTTABLE_HPP
#include <memory>
#include <QObject>
-#include "graph.hpp"
#include "gameconfig.hpp"
#include "polygon.hpp"
namespace KDots
{
+ class Graph;
class StepQueue;
class KDOTS_EXPORT DotTable : public QObject
{
@@ -44,7 +44,7 @@ namespace KDots
std::vector<Polygon_ptr> m_polygons;
public:
DotTable (const GameConfig& config, QObject *parent = 0);
-
+ virtual ~DotTable () {}
GameConfig gameConfig () const;
void pushPoint (const Point& point);
7 interface/iplugin.hpp
View
@@ -28,17 +28,10 @@
#include <QString>
#include <QIcon>
#include <QtPlugin>
-#include <kexportplugin.h>
-#include <kpluginfactory.h>
-#include <point.hpp>
-
-class QDialog;
namespace KDots
{
- class DotTable;
class IRival;
-
class IPlugin : public QObject
{
public:
1  interface/irival.hpp
View
@@ -28,7 +28,6 @@
#include <QObject>
#include <include/newgamewidget.hpp>
-class QWidget;
class QStatusBar;
namespace KDots
17 kdots.kcfg
View
@@ -24,5 +24,22 @@
<default>0</default>
</entry>
</group>
+<group name="Game">
+ <entry name="lastPlugin" type="Int">
+ <default>0</default>
+ </entry>
+ <entry name="lastHeight" type="Int">
+ <default>10</default>
+ </entry>
+ <entry name="lastWidth" type="Int">
+ <default>10</default>
+ </entry>
+ <entry name="lastGameMode" type="Int">
+ <default>0</default>
+ </entry>
+ <entry name="lastFirstMoving" type="Int">
+ <default>0</default>
+ </entry>
+</group>
</kcfg>
7 newgamedialog.cpp
View
@@ -25,13 +25,14 @@
*/
#include "newgamedialog.hpp"
#include <KDebug>
+#include <interface/irival.hpp>
+#include <interface/iplugin.hpp>
+#include <interface/iconfigurationwidget.hpp>
#include "ui_newgamedialog.h"
#include "pluginmanagerwidget.hpp"
#include "newgamewidget.hpp"
#include "plugincontainer.hpp"
-#include <interface/irival.hpp>
-#include <interface/iplugin.hpp>
-#include <interface/iconfigurationwidget.hpp>
+
namespace KDots
{
19 newgamewidget.cpp
View
@@ -26,6 +26,7 @@
#include "newgamewidget.hpp"
#include "ui_newgamewidget.h"
#include <QMetaType>
+#include "kdots.h"
#include "constants.hpp"
#include "plugincontainer.hpp"
@@ -37,26 +38,34 @@ namespace KDots
{
m_ui->setupUi (this);
+ m_ui->HeightSpinBox->setValue (Settings::lastHeight ());
+ m_ui->WidthSpinBox->setValue (Settings::lastWidth ());
+ m_ui->GameMode->setCurrentIndex (Settings::lastGameMode ());
+ m_ui->FirstMoving->setCurrentIndex (Settings::lastFirstMoving ());
}
int NewGameWidget::getHeight () const
{
- return m_ui->HeightSpinBox->value ();
+ Settings::setLastHeight (m_ui->HeightSpinBox->value ());
+ return Settings::lastHeight ();
}
int NewGameWidget::getWidth () const
{
- return m_ui->WidthSpinBox->value ();
+ Settings::setLastWidth (m_ui->WidthSpinBox->value ());
+ return Settings::lastWidth ();
}
GameMode NewGameWidget::getGameMode () const
{
- return m_ui->GameMode->currentIndex () ? GameMode::EXTRA_TURN_MODE : GameMode::DEFAULT_MODE;
+ Settings::setLastGameMode (m_ui->GameMode->currentIndex ());
+ return Settings::lastGameMode () ? GameMode::EXTRA_TURN_MODE : GameMode::DEFAULT_MODE;
}
Owner NewGameWidget::getFirstMoving () const
{
- return m_ui->FirstMoving->currentIndex () ? Owner::SECOND : Owner::FIRST;
+ Settings::setLastFirstMoving (m_ui->FirstMoving->currentIndex ());
+ return Settings::lastFirstMoving () ? Owner::SECOND : Owner::FIRST;
}
GameConfig NewGameWidget::getGameConfig () const
@@ -66,7 +75,7 @@ namespace KDots
config.m_height = getHeight ();
config.m_width = getWidth ();
config.m_mode = getGameMode ();
-
+
return config;
}
6 pluginmanagerwidget.cpp
View
@@ -25,6 +25,7 @@
*/
#include "pluginmanagerwidget.hpp"
#include <interface/iplugin.hpp>
+#include "kdots.h"
#include "plugincontainer.hpp"
#include "ui_pluginmanagerwidget.h"
@@ -39,7 +40,8 @@ namespace KDots
for (IPlugin *plugin : PluginContainer::instance ().plugins ().values ())
m_ui->PluginComboBox->addItem (plugin->icon (), plugin->name ());
- onIndexChanged (0);
+ m_ui->PluginComboBox->setCurrentIndex (Settings::lastPlugin ());
+ onIndexChanged (Settings::lastPlugin ());
connect (m_ui->PluginComboBox,
SIGNAL (currentIndexChanged (int)),
@@ -51,6 +53,8 @@ namespace KDots
{
IPlugin *first = PluginContainer::instance ().plugin (m_ui->PluginComboBox->itemText (current));
m_ui->Description->setText (first->description ());
+
+ Settings::setLastPlugin (current);
}
QString PluginManagerWidget::pluginName () const
1  plugins/ipconnect/configurationwidget.cpp
View
@@ -25,7 +25,6 @@
*/
#include "configurationwidget.hpp"
#include "ui_configurationwidget.h"
-#include <QDebug>
namespace KDots
{
6 plugins/ipconnect/connectdialog.cpp
View
@@ -25,7 +25,7 @@
*/
#include "connectdialog.hpp"
#include <QTcpServer>
-#include <QDebug>
+#include <KDebug>
#include "ui_connectdialog.h"
namespace KDots
@@ -45,9 +45,9 @@ namespace KDots
SLOT (accept ()));
if (m_server->listen (QHostAddress::Any, port))
- qDebug () << Q_FUNC_INFO << "Listening the port" << port;
+ kDebug () << Q_FUNC_INFO << "Listening the port" << port;
else
- qWarning () << Q_FUNC_INFO << "Couldn't listen the port " << port;
+ kWarning () << Q_FUNC_INFO << "Couldn't listen the port " << port;
}
}
29 plugins/ipconnect/rival.cpp
View
@@ -24,15 +24,19 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "rival.hpp"
-#include <QMessageBox>
+#include <KMessageBox>
+#include <KDebug>
#include <KLocalizedString>
#ifdef NEW_LIBKDEGAMES
# include <KgDifficulty>
#else
# include <KGameDifficulty>
#endif
+#include <include/dottable.hpp>
#include <include/stepqueue.hpp>
+#include <include/graph.hpp>
#include "connectdialog.hpp"
+#include "configurationwidget.hpp"
namespace KDots
{
@@ -81,7 +85,6 @@ namespace KDots
if (!m_configWidget->clientConfig (config))
{
- qWarning () << Q_FUNC_INFO;
return GameConfig ();
}
@@ -94,16 +97,16 @@ namespace KDots
m_socket->connectToHost (config.m_host, config.m_port);
- qDebug () << Q_FUNC_INFO << "Connecting to the server...";
+ kDebug () << "Connecting to the server...";
if (m_socket->waitForConnected (5000))
{
- qDebug () << Q_FUNC_INFO << "Connected";
+ kDebug () << "Connected";
if (m_socket->waitForReadyRead ())
{
- qDebug () << Q_FUNC_INFO << "Reading Table config";
+ kDebug () << "Reading Table config";
const QByteArray& data = m_socket->readAll();
- qDebug () << Q_FUNC_INFO << "Data size" << data.size ();
+ kDebug () << "Data size" << data.size ();
QDataStream in (&const_cast<QByteArray&> (data), QIODevice::ReadOnly);
QVariant variantData;
@@ -113,14 +116,14 @@ namespace KDots
if (!variantData.canConvert<GameConfig> ())
{
- qWarning () << Q_FUNC_INFO << "Cannot convert to GameConfig: "
+ kWarning () << "Cannot convert to GameConfig: "
<< variantData.typeName ();
}
const GameConfig& config = variantData.value<GameConfig> ();
if (!config.isInititialized ())
{
- qWarning () << Q_FUNC_INFO << "Table config is invalid";
+ kWarning () << "Table config is invalid";
return GameConfig ();
}
else
@@ -130,7 +133,7 @@ namespace KDots
this,
SLOT (onReadyRead ()));
- QMessageBox::information (0,
+ KMessageBox::information (0,
i18n ("Connected"),
i18n ("Good luck have fun"));
return config;
@@ -164,7 +167,6 @@ namespace KDots
//Create server
- qDebug () << Q_FUNC_INFO;
m_server = new QTcpServer (this);
connect (m_server,
@@ -198,17 +200,16 @@ namespace KDots
if (!m_socket)
return;
- qDebug () << Q_FUNC_INFO << "Sending point";
+ kDebug () << "Sending point";
QByteArray array;
QDataStream out (&array, QIODevice::WriteOnly);
out << QVariant::fromValue<Point> (point);
- qDebug () << Q_FUNC_INFO << m_socket->write (array);
+ kDebug () << m_socket->write (array);
}
void Rival::onNewConnectionHandle ()
{
- qDebug () << Q_FUNC_INFO;
m_socket = m_server->nextPendingConnection ();
if (!m_socket)
return;
@@ -218,7 +219,7 @@ namespace KDots
out << QVariant::fromValue<GameConfig> (m_table->gameConfig ())
<< static_cast<quint32> (StepQueue::other (m_me));
m_socket->write (gameData);
- qDebug () << Q_FUNC_INFO << "Game config sent";
+ kDebug () << "Game config sent";
connect (m_socket,
SIGNAL (readyRead ()),
this,
5 plugins/ipconnect/rival.hpp
View
@@ -25,17 +25,18 @@
*/
#ifndef KDOTS_PLUGINS_IPCONNECT_RIVAL_HPP
#define KDOTS_PLUGINS_IPCONNECT_RIVAL_HPP
+#include <memory>
#include <QObject>
#include <QTcpSocket>
#include <QTcpServer>
#include <interface/irival.hpp>
-#include <include/dottable.hpp>
-#include "configurationwidget.hpp"
namespace KDots
{
+ class DotTable;
namespace ipconnect
{
+ class ConfigurationWidget;
class Rival : public KDots::IRival
{
Q_OBJECT
1  plugins/simpleai/prioritymap.cpp
View
@@ -24,7 +24,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "prioritymap.hpp"
-#include <QDebug>
namespace KDots
{
8 plugins/simpleai/rival.cpp
View
@@ -37,6 +37,7 @@
#include <include/dottable.hpp>
#include <include/stepqueue.hpp>
#include <include/constants.hpp>
+#include <include/graph.hpp>
#include "prioritymap.hpp"
namespace KDots
@@ -49,7 +50,6 @@ namespace KDots
, m_current (FIRST)
, m_other (SECOND)
, m_iterations (3)
- , m_statusBar (NULL)
{
PriorityMap::instance ();
#ifdef NEW_LIBKDEGAMES
@@ -274,11 +274,5 @@ namespace KDots
m_current = m_table->stepQueue ()->getCurrentOwner ();
m_other = StepQueue::other (m_current);
}
-
- void Rival::setStatusBar (QStatusBar* bar)
- {
- Q_UNUSED (bar);
- }
-
}
}
2  plugins/simpleai/rival.hpp
View
@@ -42,13 +42,11 @@ namespace KDots
std::vector<Point> m_pointStack;
Owner m_current, m_other;
int m_iterations;
- QStatusBar *m_statusBar;
public:
Rival (QObject *parent = 0);
~Rival ();
bool isAllow () const;
- void setStatusBar (QStatusBar *bar);
void setDifficulty (int diff);
public slots:
void nextStep (const Point& point);
2  polygonfinder.cpp
View
@@ -25,8 +25,6 @@
*/
#include "polygonfinder.hpp"
#include <algorithm>
-#include <iostream>
-#include <KDebug>
#include "point.hpp"
#include "constants.hpp"
#include "graph.hpp"
1  tablewidget.cpp
View
@@ -36,6 +36,7 @@
#include "stepqueue.hpp"
#include "brushcombodelegate.hpp"
#include "kdots.h"
+#include "graph.hpp"
namespace KDots
{
Please sign in to comment.
Something went wrong with that request. Please try again.