20 #include "kexthighscore.h"
26 #include "kexthighscore_internal.h"
27 #include "kexthighscore_gui.h"
30 namespace KExtHighscore
34 ManagerPrivate *
internal = 0;
38 internal->checkFirst();
39 return internal->gameType();
42 void setGameType(uint type)
44 internal->setGameType(type);
47 bool configure(TQWidget *parent)
49 internal->checkFirst();
50 ConfigDialog *cd =
new ConfigDialog(parent);
52 bool saved = cd->hasBeenSaved();
57 void show(TQWidget *parent,
int rank)
59 HighscoresDialog *hd =
new HighscoresDialog(rank, parent);
64 void submitScore(
const Score &score, TQWidget *widget)
66 int rank =
internal->submitScore(score, widget,
69 switch (internal->showMode) {
74 if ( rank!=-1) show(widget, rank);
77 if ( rank==0 ) show(widget, rank);
84 void show(TQWidget *widget)
86 internal->checkFirst();
92 internal->checkFirst();
93 internal->hsConfig().readCurrentConfig();
94 uint nb =
internal->scoreInfos().maxNbEntries();
95 return internal->readScore(nb-1);
100 internal->checkFirst();
101 internal->hsConfig().readCurrentConfig();
102 return internal->readScore(0);
109 Q_ASSERT(nbGameTypes);
110 Q_ASSERT(maxNbEntries);
112 kdFatal(11002) <<
"A highscore object already exists" << endl;
113 internal =
new ManagerPrivate(nbGameTypes, *
this);
114 internal->init(maxNbEntries);
125 internal->trackLostGames = track;
130 internal->trackDrawGames = track;
135 internal->showStatistics = show;
140 internal->showStatistics = show;
145 internal->showDrawGames = show;
150 Q_ASSERT( url.isValid() );
151 internal->serverURL = url;
152 const char *HS_WW_URL =
"ww hs url";
154 if ( cg.config()->hasKey(HS_WW_URL) )
155 internal->serverURL = cg.config()->readEntry(HS_WW_URL);
156 else cg.config()->writeEntry(HS_WW_URL, url.url());
157 internal->version = version;
163 Q_ASSERT( scores.size()>=2 );
164 for (uint i=0; i<scores.size()-1; i++)
165 Q_ASSERT( scores[i]<scores[i+1] );
166 internal->playerInfos().createHistoItems(scores, type==ScoreBound);
171 internal->showMode = mode;
198 internal->submitLocal(score);
211 item =
new Item((uint)0, i18n(
"Score"), TQt::AlignRight);
213 case MeanScoreDefault:
214 item =
new Item((
double)0, i18n(
"Mean Score"), TQt::AlignRight);
218 case BestScoreDefault:
219 item =
new Item((uint)0, i18n(
"Best Score"), TQt::AlignRight);
223 item =
new Item((uint)0, i18n(
"Elapsed Time"), TQt::AlignRight);
234 internal->scoreInfos().setItem(
"score", item);
235 internal->playerInfos().item(
"mean score")
236 ->item()->setDefaultValue(
double(worstScore));
237 internal->playerInfos().item(
"best score")
238 ->item()->setDefaultValue(worstScore);
243 internal->scoreInfos().addItem(name, item,
true);
248 const Item *scoreItem =
internal->scoreInfos().item(
"score")->item();
261 internal->playerInfos().setItem(name, item);
267 kdFatal(11002) <<
"You need to reimplement KExtHighscore::Manager for "
268 <<
"multiple game types" << endl;
273 case WW:
return "normal";
279 const TQString &content)
281 Q_ASSERT( !item.isEmpty() && url.queryItem(item).isNull() );
283 TQString query = url.query();
284 if ( !query.isEmpty() ) query +=
'&';
285 query += item +
'=' + KURL::encode_string(content);
This class defines how to convert and how to display a highscore element (such as the score,...
void setDefaultValue(const TQVariant &value)
Set default value.
const TQVariant & defaultValue() const
void setPrettyFormat(Format format)
Set the display format.
void setPrettySpecial(Special special)
Set the special value for display.
static void addToQueryURL(KURL &url, const TQString &item, const TQString &content)
Add an entry to the url to be submitted (.
void setTrackDrawGames(bool track)
void setPlayerItem(PlayerItemType type, Item *item)
Replace an item in the players list.
void setWWHighscores(const KURL &url, const TQString &version)
Set the world-wide highscores.
void setShowMode(ShowMode mode)
Set how the highscores dialog is shown at game end.
ShowMode
Enumerate different conditions under which to show the high score dialog.
@ AlwaysShow
Always show the dialog.
@ NeverShow
Never show the dialog.
@ ShowForHighestScore
Only for the top spot.
@ ShowForHigherScore
Show if score has improved.
ItemType
Some predefined item types.
void setTrackLostGames(bool track)
Set if the number of lost games should be track for the world-wide highscores statistics.
LabelType
Possible type of label (.
void setScoreItem(uint worstScore, Item *item)
Replace the default score item in the highscores list by the given one.
void setShowStatistics(bool show)
static Item * createItem(ItemType type)
Create a predefined item.
virtual bool isStrictlyLess(const Score &s1, const Score &s2) const
Manager(uint nbGameTypes=1, uint maxNbEntries=10)
Constructor.
virtual TQString gameTypeLabel(uint gameType, LabelType type) const
void showStatistics(bool show) TDE_DEPRECATED
void addScoreItem(const TQString &name, Item *item)
Add an item in the highscores list (it will add a column to this list).
void setScoreHistogram(const TQMemArray< uint > &scores, ScoreTypeBound type)
Set the ranges for the score histogram.
void setScoreType(ScoreType type)
Set score type.
void submitLegacyScore(const Score &score) const
This method should be called from convertLegacy.
void setShowDrawGamesStatistic(bool show)
This class contains data for a score.