KGameHighScoreDialog
#include <KGameHighScoreDialog>
Public Types | |
enum | AddScoreFlag { AskName = 0x1 , LessIsMore = 0x2 } |
typedef QFlags< AddScoreFlag > | AddScoreFlags |
typedef QMap< int, QString > | FieldInfo |
enum | Fields { Name = 1 << 0 , Level = 1 << 1 , Date = 1 << 2 , Time = 1 << 3 , Score = 1 << 4 , Custom1 = 1 << 10 , Custom2 = 1 << 11 , Custom3 = 1 << 12 , Custom4 = 1 << 13 , Custom5 = 1 << 14 , Max = 1 << 30 } |
Public Types inherited from QDialog | |
enum | DialogCode |
Public Types inherited from QWidget | |
enum | RenderFlag |
Public Types inherited from QPaintDevice | |
enum | PaintDeviceMetric |
Detailed Description
A simple high score implementation.
This class can be used both for displaying the current high scores and also for adding new highscores. It is the recommended way of implementing a simple highscore table.
To display the current highscores it is simply a case of creating a KGameHighScoreDialog object and calling exec(). This example code will display the Name and Score (the score is always added automatically unless hidden hideField since it is used for sorting) of the top 10 players:
To add a new highscore, e.g. at the end of a game you simply create an object with the Fields you want to write (i.e. KGameHighScoreDialog::Name | KGameHighScoreDialog::Score), call addScore and then (optionally) display the dialog. This code will allow you to add a highscore with a Name and Score field. If it's the first time a player has a score on the table, they will be prompted for their name but subsequent times they will have their name filled in automatically.
Or if you want to fill the name in from the code you can pass a default name by doing
If you want to add an extra field (e.g. the number of moves taken) then do
You can define up to 5 Custom fields.
Definition at line 79 of file kgamehighscoredialog.h.
Member Typedef Documentation
◆ AddScoreFlags
Stores a combination of AddScoreFlag values.
Definition at line 109 of file kgamehighscoredialog.h.
◆ FieldInfo
typedef QMap<int, QString> KGameHighScoreDialog::FieldInfo |
Definition at line 111 of file kgamehighscoredialog.h.
Member Enumeration Documentation
◆ AddScoreFlag
Flags for setting preferences for adding scores.
Enumerator | |
---|---|
AskName | Promt the player for their name. |
LessIsMore | A lower numerical score means higher placing on the table. |
Definition at line 102 of file kgamehighscoredialog.h.
◆ Fields
Highscore fields.
Enumerator | |
---|---|
Custom1 | Field for custom information. |
Max | Only for setting a maximum. |
Definition at line 85 of file kgamehighscoredialog.h.
Constructor & Destructor Documentation
◆ KGameHighScoreDialog()
|
explicit |
- Parameters
-
fields Bitwise OR of the Fields that should be listed (Score is always present) parent passed to parent QWidget constructor.
Definition at line 94 of file kgamehighscoredialog.cpp.
◆ ~KGameHighScoreDialog()
|
override |
Definition at line 142 of file kgamehighscoredialog.cpp.
Member Function Documentation
◆ addField()
Define an extra FieldInfo entry.
- Parameters
-
field id of this field Fields e.g. KGameHighScoreDialog::Custom1 header text shown in the header in the dialog for this field. e.g. "Number of Moves" key unique key used to store this field. e.g. "moves"
Definition at line 223 of file kgamehighscoredialog.cpp.
◆ addLocalizedConfigGroupName()
void KGameHighScoreDialog::addLocalizedConfigGroupName | ( | const QPair< QByteArray, QString > & | group | ) |
You must add the translations of all group names to the dialog.
This is best done by passing the name through i18n(). The group set through setConfigGroup(const QPair<QByteArray, QString>& group) will be added automatically
- Parameters
-
group the translated group name
Definition at line 158 of file kgamehighscoredialog.cpp.
◆ addLocalizedConfigGroupNames()
void KGameHighScoreDialog::addLocalizedConfigGroupNames | ( | const QMap< QByteArray, QString > & | groups | ) |
You must add the translations of all group names to the dialog.
This is best done by passing the name through i18n(). The group set through setConfigGroup(const QPair<QByteArray, QString>& group) will be added automatically.
This function can be used directly with KGameDifficulty::localizedLevelStrings().
- Parameters
-
groups the list of translated group names
Definition at line 168 of file kgamehighscoredialog.cpp.
◆ addScore() [1/2]
int KGameHighScoreDialog::addScore | ( | const FieldInfo & | newInfo = FieldInfo(), |
AddScoreFlags | flags = {} ) |
Adds a new score to the list.
- Parameters
-
newInfo info about the score. flags set whether the user should be prompted for their name and how the scores should be sorted
- Returns
- The highscore position if the score was good enough to make it into the list (1 being topscore) or 0 otherwise.
Definition at line 494 of file kgamehighscoredialog.cpp.
◆ addScore() [2/2]
int KGameHighScoreDialog::addScore | ( | int | newScore, |
AddScoreFlags | flags = {} ) |
Convenience function for ease of use.
- Parameters
-
newScore the score of the player. flags set whether the user should be prompted for their name and how the scores should be sorted
- Returns
- The highscore position if the score was good enough to make it into the list (1 being topscore) or 0 otherwise.
Definition at line 569 of file kgamehighscoredialog.cpp.
◆ exec()
|
overridevirtual |
Display the dialog as modal.
Reimplemented from QDialog.
Definition at line 584 of file kgamehighscoredialog.cpp.
◆ hideField()
void KGameHighScoreDialog::hideField | ( | int | field | ) |
Hide a field so that it is not shown on the table (but is still stored in the configuration file).
- Parameters
-
field id of this field Fields e.g. KGameHighScoreDialog::Score
Definition at line 232 of file kgamehighscoredialog.cpp.
◆ highScore()
int KGameHighScoreDialog::highScore | ( | ) |
- Returns
- the current best score in the group
Definition at line 651 of file kgamehighscoredialog.cpp.
◆ initFromDifficulty()
void KGameHighScoreDialog::initFromDifficulty | ( | const KGameDifficulty * | difficulty, |
bool | setConfigGroup = true ) |
Assume that config groups (incl.
current selection) are equal to difficulty levels, and initialize them. This is usually equal to the following code using KGameDifficulty:
Definition at line 178 of file kgamehighscoredialog.cpp.
◆ setComment()
- Parameters
-
comment to add when showing high-scores. The comment is only used once.
Definition at line 216 of file kgamehighscoredialog.cpp.
◆ setConfigGroup()
void KGameHighScoreDialog::setConfigGroup | ( | const QPair< QByteArray, QString > & | group | ) |
The group name must be passed though i18n() in order for the group name to be translated.
i.e.
If you set a group, it will be prefixed in the config file by 'KHighscore_' otherwise the group will simply be 'KHighscore'.
- Parameters
-
group to use for reading/writing highscores from/to.
Definition at line 149 of file kgamehighscoredialog.cpp.
◆ setConfigGroupWeights()
void KGameHighScoreDialog::setConfigGroupWeights | ( | const QMap< int, QByteArray > & | weights | ) |
It is a good idea giving config group weights, otherwise tabs get ordered by their tab name that is not probably what you want.
This function can be used directly with KGameDifficulty::levelWeights().
- Parameters
-
weights the list of untranslated group weights
- Since
- KDE 4.2
Definition at line 202 of file kgamehighscoredialog.cpp.
◆ setHiddenConfigGroups()
void KGameHighScoreDialog::setHiddenConfigGroups | ( | const QList< QByteArray > & | hiddenGroups | ) |
Hide some config groups so that they are not shown on the dialog (but are still stored in the configuration file).
- Parameters
-
hiddenGroups the list of group names you want to hide
- Since
- KDE 4.6
Definition at line 195 of file kgamehighscoredialog.cpp.
◆ show()
|
virtual |
Display the dialog as non-modal.
Definition at line 576 of file kgamehighscoredialog.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 3 2024 11:47:37 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.