Git commit 14ac667518330e47f1ca0d04628b9fc282ef020c by Ashwin Rajeev. Committed on 04/04/2013 at 23:33. Pushed by rajeev into branch 'master'.
Add custom game level Custom game level where user can select size ( 3 - 11 ) and whether wrapping is needed. FEATURE: 221727 FIXED-IN: 4.10.3 REVIEW: 109827 GUI: New settings dialog page to configure custom level M +3 -2 doc/index.docbook M +2 -0 src/CMakeLists.txt A +71 -0 src/customgame.ui M +12 -0 src/knetwalk.kcfg M +1 -1 src/main.cpp M +32 -3 src/mainwindow.cpp M +1 -0 src/mainwindow.h http://commits.kde.org/knetwalk/14ac667518330e47f1ca0d04628b9fc282ef020c diff --git a/doc/index.docbook b/doc/index.docbook index b264e43..b68af1b 100644 --- a/doc/index.docbook +++ b/doc/index.docbook @@ -32,7 +32,7 @@ <legalnotice>&FDLNotice;</legalnotice> <date>2007-11-13</date> -<releaseinfo>3.0.1</releaseinfo> +<releaseinfo>3.1.0</releaseinfo> <abstract> <para> @@ -206,12 +206,13 @@ Toggles on and off the display of the statusbar. </menuchoice></term> <listitem> <para>Lets you set the difficulty level from a sub-menu.</para> -<para>There are four levels of difficulty: +<para>There are five levels of difficulty: <itemizedlist> <listitem><para><guimenuitem>Easy</guimenuitem>: 5 rows, 5 columns, without wrapping.</para></listitem> <listitem><para><guimenuitem>Medium</guimenuitem>: 7 rows, 7 columns, without wrapping.</para></listitem> <listitem><para><guimenuitem>Hard</guimenuitem>: 9 rows, 9 columns, without wrapping.</para></listitem> <listitem><para><guimenuitem>Very hard</guimenuitem>: 9 rows, 9 columns, with wrapping.</para></listitem> +<listitem><para><guimenuitem>Custom</guimenuitem>: The settings you have configured in the Configure KNetWalk dialog will be used.</para></listitem> </itemizedlist> </para></listitem> </varlistentry> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fbee0f6..d017d1a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,6 +14,8 @@ set(knetwalk_SRCS mainwindow.cpp abstractgrid.cpp) +kde4_add_ui_files( knetwalk_SRCS customgame.ui ) + kde4_add_kcfg_files(knetwalk_SRCS settings.kcfgc ) kde4_add_app_icon(knetwalk_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/pics/hi*-app-knetwalk.png") diff --git a/src/customgame.ui b/src/customgame.ui new file mode 100644 index 0000000..a83af50 --- /dev/null +++ b/src/customgame.ui @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>CustomGameConfig</class> + <widget class="QWidget" name="CustomGameConfig"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>316</width> + <height>241</height> + </rect> + </property> + <layout class="QGridLayout"> + <item row="0" column="2"> + <spacer> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="2" column="1"> + <spacer> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item row="0" column="1"> + <widget class="KIntSpinBox" name="kcfg_Size"/> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Size:</string> + </property> + </widget> + </item> + <item row="1" column="0" colspan="2"> + <widget class="QCheckBox" name="kcfg_Wrapping"> + <property name="toolTip"> + <string>Wrap from left to right and from top to bottom</string> + </property> + <property name="text"> + <string>Wrapping</string> + </property> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>KIntSpinBox</class> + <extends>QSpinBox</extends> + <header>knuminput.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> diff --git a/src/knetwalk.kcfg b/src/knetwalk.kcfg index 19e6f97..906367e 100644 --- a/src/knetwalk.kcfg +++ b/src/knetwalk.kcfg @@ -15,4 +15,16 @@ <default>false</default> </entry> </group> + <group name="Custom"> + <entry name="Size" type="Int" key="Size"> + <label>The size of the board.</label> + <min>3</min> + <max>11</max> + <default>6</default> + </entry> + <entry name="Wrapping" type="Bool" key="Wrapping"> + <label>Whether wrap from left to right and from top to bottom is enabled.</label> + <default>false</default> + </entry> + </group> </kcfg> diff --git a/src/main.cpp b/src/main.cpp index 0113bcf..ce3d7a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,7 +28,7 @@ static const char description[] = I18N_NOOP("KNetWalk, a game for system administrators."); -static const char version[] = "3.0.1"; +static const char version[] = "3.1.0"; int main(int argc, char ** argv) { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7c1e47f..d7d6fbd 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -40,6 +40,8 @@ #include <ctime> #include <cmath> +#include "ui_customgame.h" + #include "globals.h" #include "settings.h" #include "cell.h" @@ -48,6 +50,18 @@ #include "view.h" #include "fielditem.h" +class CustomGameConfig : public QWidget +{ +public: + CustomGameConfig(QWidget *parent) + : QWidget(parent) + { + ui.setupUi(this); + } +private: + Ui::CustomGameConfig ui; +}; + MainWindow::MainWindow(QWidget *parent) : KXmlGuiWindow(parent), m_clickCount(0) { @@ -72,6 +86,9 @@ MainWindow::MainWindow(QWidget *parent) Kg::difficulty()->addStandardLevelRange( KgDifficultyLevel::Easy, KgDifficultyLevel::VeryHard ); + Kg::difficulty()->addLevel( + new KgDifficultyLevel(100, QByteArray("Custom"), i18n("Custom")) + ); KgDifficultyGUI::init(this); connect(Kg::difficulty(), SIGNAL(currentLevelChanged(const KgDifficultyLevel*)), SLOT(startNewGame())); @@ -111,8 +128,7 @@ void MainWindow::setupActions() KStandardGameAction::quit(this, SLOT(close()), actionCollection()); // Settings - KStandardAction::preferences(m_selector, SLOT(showAsDialog()), - actionCollection()); + KStandardAction::preferences(this, SLOT(configureSettings()), actionCollection()); m_soundAction = new KToggleAction(i18n("&Play Sounds"), this); connect(m_soundAction, SIGNAL(triggered(bool)), this, SLOT(setSounds(bool))); @@ -161,6 +177,16 @@ void MainWindow::loadSettings() m_scene->resizeScene(m_scene->sceneRect().size()); } +void MainWindow::configureSettings() +{ + if (KConfigDialog::showDialog(QLatin1String("settings"))) + return; + KConfigDialog *dialog = new KConfigDialog(this, QLatin1String("settings"), Settings::self()); + dialog->addPage(m_selector, i18n("Theme"), QLatin1String("games-config-theme")); + dialog->addPage(new CustomGameConfig(dialog), i18n("Custom Game"), QLatin1String("games-config-custom")); + dialog->show(); +} + void MainWindow::showHighscores() { KScoreDialog scoreDialog(KScoreDialog::Name | KScoreDialog::Time, this); @@ -182,7 +208,9 @@ void MainWindow::startNewGame() const KgDifficultyLevel::StandardLevel l = Kg::difficultyLevel(); - const bool isWrapped = (l == KgDifficultyLevel::VeryHard); + bool isWrapped = (l == KgDifficultyLevel::VeryHard); + if (Kg::difficultyLevel() == KgDifficultyLevel::Custom) + isWrapped = Settings::wrapping(); const int size = boardSize(); m_scene->startNewGame(size, size, (Wrapping)isWrapped); m_clickCount = -m_scene->fieldItem()->minimumMoves(); @@ -267,6 +295,7 @@ int MainWindow::boardSize() case KgDifficultyLevel::Easy: return NoviceBoardSize; case KgDifficultyLevel::Medium: return NormalBoardSize; case KgDifficultyLevel::Hard: return ExpertBoardSize; + case KgDifficultyLevel::Custom: return Settings::size(); default: return MasterBoardSize; } } diff --git a/src/mainwindow.h b/src/mainwindow.h index f5609e4..2c047b6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -63,6 +63,7 @@ private slots: void showHighscores(); void loadSettings(); + void configureSettings(); void setSounds(bool val); private: void setupActions();
