[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdegames/libkdegames
From: Stefan Majewsky <majewsky () gmx ! net>
Date: 2012-02-21 21:20:40
Message-ID: 20120221212040.848BEAC895 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1281542 by majewsky:
add KgDifficultyLevel::isDefault property
Bovo needs a way to mark the default level (Medium there). Until now,
the easiest level was chosen, but "Ridiculously easy" is a bad default.
M +35 -14 kgdifficulty.cpp
M +10 -3 kgdifficulty.h
--- trunk/KDE/kdegames/libkdegames/kgdifficulty.cpp #1281541:1281542
@@ -37,34 +37,36 @@
struct KgDifficultyLevel::Private
{
+ bool m_isDefault;
int m_hardness;
StandardLevel m_level;
QByteArray m_key;
QString m_title;
- Private(int hardness, const QByteArray& key, const QString& title, StandardLevel \
level);
- static Private* fromStandardLevel(StandardLevel level);
+ Private(int hardness, const QByteArray& key, const QString& title, StandardLevel \
level, bool isDefault); + static Private* fromStandardLevel(StandardLevel level, bool \
isDefault); };
-KgDifficultyLevel::KgDifficultyLevel(int hardness, const QByteArray& key, const \
QString& title)
- : d(new Private(hardness, key, title, Custom))
+KgDifficultyLevel::KgDifficultyLevel(int hardness, const QByteArray& key, const \
QString& title, bool isDefault) + : d(new Private(hardness, key, title, Custom, \
isDefault)) {
}
-KgDifficultyLevel::Private::Private(int hardness, const QByteArray& key, const \
QString& title, StandardLevel level)
- : m_hardness(hardness)
+KgDifficultyLevel::Private::Private(int hardness, const QByteArray& key, const \
QString& title, StandardLevel level, bool isDefault) + : m_isDefault(isDefault)
+ , m_hardness(hardness)
, m_level(level)
, m_key(key)
, m_title(title)
{
}
-KgDifficultyLevel::KgDifficultyLevel(StandardLevel level)
- : d(Private::fromStandardLevel(level))
+KgDifficultyLevel::KgDifficultyLevel(StandardLevel level, bool isDefault)
+ : d(Private::fromStandardLevel(level, isDefault))
{
}
-KgDifficultyLevel::Private* \
KgDifficultyLevel::Private::fromStandardLevel(KgDifficultyLevel::StandardLevel level) \
+KgDifficultyLevel::Private* \
KgDifficultyLevel::Private::fromStandardLevel(KgDifficultyLevel::StandardLevel level, \
bool isDefault) {
Q_ASSERT_X(level != Custom,
"KgDifficultyLevel(StandardLevel) constructor",
@@ -101,7 +103,7 @@
case Custom:
return 0;
}
- return new KgDifficultyLevel::Private(level, data.first, data.second, level);
+ return new KgDifficultyLevel::Private(level, data.first, data.second, level, \
isDefault); }
KgDifficultyLevel::~KgDifficultyLevel()
@@ -109,6 +111,11 @@
delete d;
}
+bool KgDifficultyLevel::isDefault() const
+{
+ return d->m_isDefault;
+}
+
int KgDifficultyLevel::hardness() const
{
return d->m_hardness;
@@ -184,13 +191,19 @@
typedef KgDifficultyLevel::StandardLevel DS;
-void KgDifficulty::addStandardLevel(DS level)
+void KgDifficulty::addStandardLevel(DS level, bool isDefault)
{
- addLevel(new KgDifficultyLevel(level));
+ addLevel(new KgDifficultyLevel(level, isDefault));
}
void KgDifficulty::addStandardLevelRange(DS from, DS to)
{
+ //every level in range != Custom, therefore no level is default
+ addStandardLevelRange(from, to, KgDifficultyLevel::Custom);
+}
+
+void KgDifficulty::addStandardLevelRange(DS from, DS to, DS defaultLevel)
+{
const QVector<DS> levels = QVector<DS>()
<< KgDifficultyLevel::RidiculouslyEasy
<< KgDifficultyLevel::VeryEasy
@@ -209,7 +222,7 @@
);
for (int i = fromIndex; i <= toIndex; ++i)
{
- addLevel(new KgDifficultyLevel(levels[i]));
+ addLevel(new KgDifficultyLevel(levels[i], levels[i] == defaultLevel));
}
}
@@ -235,7 +248,15 @@
return d->m_currentLevel = level;
}
}
- //no level predefined - easiest level is probably a sane default
+ //no level predefined - look for a default level
+ foreach (const KgDifficultyLevel* level, d->m_levels)
+ {
+ if (level->isDefault())
+ {
+ return d->m_currentLevel = level;
+ }
+ }
+ //no default level predefined - easiest level is probably a sane default
return d->m_currentLevel = d->m_levels[0];
}
--- trunk/KDE/kdegames/libkdegames/kgdifficulty.h #1281541:1281542
@@ -34,6 +34,7 @@
{
Q_OBJECT
Q_DISABLE_COPY(KgDifficultyLevel)
+ Q_PROPERTY(bool default READ isDefault)
Q_PROPERTY(int hardness READ hardness)
Q_PROPERTY(QByteArray key READ key)
Q_PROPERTY(QString title READ title)
@@ -54,10 +55,13 @@
};
///Refer to the getters' documentation for details on the params.
- KgDifficultyLevel(int hardness, const QByteArray& key, const QString& title);
- explicit KgDifficultyLevel(StandardLevel level);
+ KgDifficultyLevel(int hardness, const QByteArray& key, const QString& title, bool \
isDefault = false); + explicit KgDifficultyLevel(StandardLevel level, bool isDefault \
= false); virtual ~KgDifficultyLevel();
+ ///@return whether this level is the default level when no selection has
+ /// been stored (e.g. on first startup)
+ bool isDefault() const;
///@return a numeric key which is used to sort the levels by difficulty
/// (smaller values mean easier levels)
///@note For standard levels, this equals the numeric value of the level
@@ -107,7 +111,7 @@
///currentLevel() if there is one.
void addLevel(KgDifficultyLevel* level);
///A shortcut for addLevel(new KgDifficultyLevel(@a level)).
- void addStandardLevel(KgDifficultyLevel::StandardLevel level);
+ void addStandardLevel(KgDifficultyLevel::StandardLevel level, bool isDefault = \
false); ///This convenience method adds a range of standard levels to this
///instance (including the boundaries). For example:
///@code
@@ -118,6 +122,9 @@
///@endcode
///This adds the levels "Easy", "Medium", "Hard" and "Very hard".
void addStandardLevelRange(KgDifficultyLevel::StandardLevel from, \
KgDifficultyLevel::StandardLevel to); + ///@overload
+ ///This overload allows to specify a @a defaultLevel.
+ void addStandardLevelRange(KgDifficultyLevel::StandardLevel from, \
KgDifficultyLevel::StandardLevel to, KgDifficultyLevel::StandardLevel defaultLevel); \
///@return a list of all difficulty levels, sorted by hardness
QList<const KgDifficultyLevel*> levels() const;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic