[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegames/kmines
From:       Stefan Majewsky <majewsky () gmx ! net>
Date:       2012-03-07 22:12:33
Message-ID: 20120307221233.2455CAC897 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1284143 by majewsky:

Port KMines from KGameDifficulty to KgDifficulty (singleton).

CCMAIL: piacentini@kde.org

 M  +0 -5      kmines.kcfg  
 M  +19 -40    mainwindow.cpp  
 M  +0 -3      mainwindow.h  


--- trunk/KDE/kdegames/kmines/kmines.kcfg #1284142:1284143
@@ -4,7 +4,6 @@
       xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
       http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
   <kcfgfile name="kminesrc"/>
-  <include>KGameDifficulty</include>
   <group name="General">
     <entry name="UseQuestionMarks" type="Bool" key="question mark">
       <label>Whether the "unsure" marker may be used.</label>
@@ -33,9 +32,5 @@
       <min>1</min>
       <default>20</default>
     </entry>
-    <entry name="level" type="Int">
-      <label>The difficulty level.</label>
-      <default code="true">KGameDifficulty::Easy</default>
-    </entry>
   </group>
 </kcfg>
--- trunk/KDE/kdegames/kmines/mainwindow.cpp #1284142:1284143
@@ -22,6 +22,7 @@
 #include "settings.h"
 
 #include <KGameClock>
+#include <KgDifficulty>
 #include <KStandardGameAction>
 #include <KActionCollection>
 #include <KToggleAction>
@@ -108,8 +109,6 @@
     setCentralWidget(m_view);
     setupActions();
 
-    KGameDifficulty::setLevel( KGameDifficulty::standardLevel(Settings::level()) );
-
     newGame();
 }
 
@@ -122,13 +121,14 @@
     KStandardAction::preferences( this, SLOT(configureSettings()), \
                actionCollection() );
     m_actionPause = KStandardGameAction::pause( this, SLOT(pauseGame(bool)), \
actionCollection() );  
-    KGameDifficulty::init(this, this, \
                SLOT(levelChanged(KGameDifficulty::standardLevel)),
-                         SLOT(customLevelChanged(int)));
-    KGameDifficulty::setRestartOnChange(KGameDifficulty::RestartOnChange);
-    KGameDifficulty::addStandardLevel(KGameDifficulty::Easy);
-    KGameDifficulty::addStandardLevel(KGameDifficulty::Medium);
-    KGameDifficulty::addStandardLevel(KGameDifficulty::Hard);
-    KGameDifficulty::addStandardLevel(KGameDifficulty::Configurable);
+    Kg::difficulty()->addStandardLevelRange(
+        KgDifficultyLevel::Easy, KgDifficultyLevel::Hard
+    );
+    Kg::difficulty()->addLevel(new KgDifficultyLevel(1000,
+        QByteArray( "Custom" ), i18n( "Custom" )
+    ));
+    KgDifficultyGUI::init(this);
+    connect(Kg::difficulty(), SIGNAL(currentLevelChanged(const KgDifficultyLevel*)), \
SLOT(newGame()));  
     setupGUI(qApp->desktop()->availableGeometry().size()*0.4);
 }
@@ -138,19 +138,6 @@
     statusBar()->changeItem( i18n("Mines: %1/%2", count, m_scene->totalMines()), 0 \
);  }
 
-void KMinesMainWindow::levelChanged(KGameDifficulty::standardLevel)
-{
-    Settings::setLevel(KGameDifficulty::level());
-    Settings::self()->writeConfig();
-
-    newGame();
-}
-
-void KMinesMainWindow::customLevelChanged(int)
-{
-    newGame();
-}
-
 void KMinesMainWindow::newGame()
 {
     m_gameClock->restart();
@@ -164,19 +151,19 @@
     }
     m_actionPause->setEnabled(false);
 
-    KGameDifficulty::setRunning(false);
-    switch(KGameDifficulty::level())
+    Kg::difficulty()->setGameRunning(false);
+    switch(Kg::difficultyLevel())
     {
-        case KGameDifficulty::Easy:
+        case KgDifficultyLevel::Easy:
             m_scene->startNewGame(9, 9, 10);
             break;
-        case KGameDifficulty::Medium:
+        case KgDifficultyLevel::Medium:
             m_scene->startNewGame(16,16,40);
             break;
-        case KGameDifficulty::Hard:
+        case KgDifficultyLevel::Hard:
             m_scene->startNewGame(16,30,99);
             break;
-        case KGameDifficulty::Configurable:
+        case KgDifficultyLevel::Custom:
             m_scene->startNewGame(Settings::customHeight(),
                                   Settings::customWidth(),
                                   Settings::customMines());
@@ -191,19 +178,13 @@
 {
     m_gameClock->pause();
     m_actionPause->setEnabled(false);
-    KGameDifficulty::setRunning(false);
+    Kg::difficulty()->setGameRunning(false);
     if(won)
     {
         KScoreDialog scoreDialog(KScoreDialog::Name | KScoreDialog::Time, this);
-        scoreDialog.addLocalizedConfigGroupNames(KGameDifficulty::localizedLevelStrings()); \
                //Add all the translations of the group names
-        scoreDialog.setConfigGroupWeights(KGameDifficulty::levelWeights());
+        scoreDialog.initFromDifficulty(Kg::difficulty());
         scoreDialog.hideField(KScoreDialog::Score);
 
-        QPair<QByteArray, QString> group = KGameDifficulty::localizedLevelString();
-        if(group.first.isEmpty())
-            group = qMakePair(QByteArray("Custom"), i18n("Custom"));
-        scoreDialog.setConfigGroup( group );
-
         KScoreDialog::FieldInfo scoreInfo;
         // score-in-seconds will be hidden
         scoreInfo[KScoreDialog::Score].setNum(m_gameClock->seconds());
@@ -227,16 +208,14 @@
     m_actionPause->setEnabled(true);
     // start clock
     m_gameClock->resume();
-    KGameDifficulty::setRunning(true);
+    Kg::difficulty()->setGameRunning(true);
 }
 
 void KMinesMainWindow::showHighscores()
 {
     KScoreDialog scoreDialog(KScoreDialog::Name | KScoreDialog::Time, this);
-    scoreDialog.addLocalizedConfigGroupNames(KGameDifficulty::localizedLevelStrings()); \
                //Add all the translations of the group names
-    scoreDialog.setConfigGroupWeights(KGameDifficulty::levelWeights());
+    scoreDialog.initFromDifficulty(Kg::difficulty());
     scoreDialog.hideField(KScoreDialog::Score);
-    scoreDialog.setConfigGroup( KGameDifficulty::localizedLevelString() );
     scoreDialog.exec();
 }
 
--- trunk/KDE/kdegames/kmines/mainwindow.h #1284142:1284143
@@ -19,7 +19,6 @@
 #define MAINWINDOW_H
 
 #include <KXmlGuiWindow>
-#include <KGameDifficulty>
 
 class KMinesScene;
 class KMinesView;
@@ -33,8 +32,6 @@
     KMinesMainWindow();
 private slots:
     void onMinesCountChanged(int count);
-    void levelChanged(KGameDifficulty::standardLevel);
-    void customLevelChanged(int);
     void newGame();
     void onGameOver(bool);
     void advanceTime(const QString&);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic