• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libtdegames
 

libtdegames

  • libtdegames
  • highscore
kexthighscore.cpp
1/*
2 This file is part of the TDE games library
3 Copyright (C) 2001-2004 Nicolas Hadacek (hadacek@kde.org)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "kexthighscore.h"
21
22#include <tqlayout.h>
23
24#include <kdebug.h>
25
26#include "kexthighscore_internal.h"
27#include "kexthighscore_gui.h"
28
29
30namespace KExtHighscore
31{
32
33//-----------------------------------------------------------------------------
34ManagerPrivate *internal = 0;
35
36uint gameType()
37{
38 internal->checkFirst();
39 return internal->gameType();
40}
41
42void setGameType(uint type)
43{
44 internal->setGameType(type);
45}
46
47bool configure(TQWidget *parent)
48{
49 internal->checkFirst();
50 ConfigDialog *cd = new ConfigDialog(parent);
51 cd->exec();
52 bool saved = cd->hasBeenSaved();
53 delete cd;
54 return saved;
55}
56
57void show(TQWidget *parent, int rank)
58{
59 HighscoresDialog *hd = new HighscoresDialog(rank, parent);
60 hd->exec();
61 delete hd;
62}
63
64void submitScore(const Score &score, TQWidget *widget)
65{
66 int rank = internal->submitScore(score, widget,
67 internal->showMode!=Manager::NeverShow);
68
69 switch (internal->showMode) {
70 case Manager::AlwaysShow:
71 show(widget, -1);
72 break;
73 case Manager::ShowForHigherScore:
74 if ( rank!=-1) show(widget, rank);
75 break;
76 case Manager::ShowForHighestScore:
77 if ( rank==0 ) show(widget, rank);
78 break;
79 case Manager::NeverShow:
80 break;
81 }
82}
83
84void show(TQWidget *widget)
85{
86 internal->checkFirst();
87 show(widget, -1);
88}
89
90Score lastScore()
91{
92 internal->checkFirst();
93 internal->hsConfig().readCurrentConfig();
94 uint nb = internal->scoreInfos().maxNbEntries();
95 return internal->readScore(nb-1);
96}
97
98Score firstScore()
99{
100 internal->checkFirst();
101 internal->hsConfig().readCurrentConfig();
102 return internal->readScore(0);
103}
104
105
106//-----------------------------------------------------------------------------
107Manager::Manager(uint nbGameTypes, uint maxNbEntries)
108{
109 Q_ASSERT(nbGameTypes);
110 Q_ASSERT(maxNbEntries);
111 if (internal)
112 kdFatal(11002) << "A highscore object already exists" << endl;
113 internal = new ManagerPrivate(nbGameTypes, *this);
114 internal->init(maxNbEntries);
115}
116
117Manager::~Manager()
118{
119 delete internal;
120 internal = 0;
121}
122
123void Manager::setTrackLostGames(bool track)
124{
125 internal->trackLostGames = track;
126}
127
128void Manager::setTrackDrawGames(bool track)
129{
130 internal->trackDrawGames = track;
131}
132
133void Manager::setShowStatistics(bool show)
134{
135 internal->showStatistics = show;
136}
137
138void Manager::showStatistics(bool show)
139{
140 internal->showStatistics = show;
141}
142
143void Manager::setShowDrawGamesStatistic(bool show)
144{
145 internal->showDrawGames = show;
146}
147
148void Manager::setWWHighscores(const KURL &url, const TQString &version)
149{
150 Q_ASSERT( url.isValid() );
151 internal->serverURL = url;
152 const char *HS_WW_URL = "ww hs url";
153 ConfigGroup cg;
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;
158}
159
160void Manager::setScoreHistogram(const TQMemArray<uint> &scores,
161 ScoreTypeBound type)
162{
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);
167}
168
169void Manager::setShowMode(ShowMode mode)
170{
171 internal->showMode = mode;
172}
173
174void Manager::setScoreType(ScoreType type)
175{
176 switch (type) {
177 case Normal:
178 return;
179 case MinuteTime: {
180 Item *item = createItem(ScoreDefault);
181 item->setPrettyFormat(Item::MinuteTime);
182 setScoreItem(0, item);
183
184 item = createItem(MeanScoreDefault);
185 item->setPrettyFormat(Item::MinuteTime);
186 setPlayerItem(MeanScore, item);
187
188 item = createItem(BestScoreDefault);
189 item->setPrettyFormat(Item::MinuteTime);
190 setPlayerItem(BestScore, item);
191 return;
192 }
193 }
194}
195
196void Manager::submitLegacyScore(const Score &score) const
197{
198 internal->submitLocal(score);
199}
200
201bool Manager::isStrictlyLess(const Score &s1, const Score &s2) const
202{
203 return s1.score()<s2.score();
204}
205
206Item *Manager::createItem(ItemType type)
207{
208 Item *item = 0;
209 switch (type) {
210 case ScoreDefault:
211 item = new Item((uint)0, i18n("Score"), TQt::AlignRight);
212 break;
213 case MeanScoreDefault:
214 item = new Item((double)0, i18n("Mean Score"), TQt::AlignRight);
215 item->setPrettyFormat(Item::OneDecimal);
216 item->setPrettySpecial(Item::DefaultNotDefined);
217 break;
218 case BestScoreDefault:
219 item = new Item((uint)0, i18n("Best Score"), TQt::AlignRight);
220 item->setPrettySpecial(Item::DefaultNotDefined);
221 break;
222 case ElapsedTime:
223 item = new Item((uint)0, i18n("Elapsed Time"), TQt::AlignRight);
224 item->setPrettyFormat(Item::MinuteTime);
225 item->setPrettySpecial(Item::ZeroNotDefined);
226 break;
227 }
228 return item;
229}
230
231void Manager::setScoreItem(uint worstScore, Item *item)
232{
233 item->setDefaultValue(worstScore);
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);
239}
240
241void Manager::addScoreItem(const TQString &name, Item *item)
242{
243 internal->scoreInfos().addItem(name, item, true);
244}
245
246void Manager::setPlayerItem(PlayerItemType type, Item *item)
247{
248 const Item *scoreItem = internal->scoreInfos().item("score")->item();
249 uint def = scoreItem->defaultValue().toUInt();
250 TQString name;
251 switch (type) {
252 case MeanScore:
253 name = "mean score";
254 item->setDefaultValue(double(def));
255 break;
256 case BestScore:
257 name = "best score";
258 item->setDefaultValue(def);
259 break;
260 }
261 internal->playerInfos().setItem(name, item);
262}
263
264TQString Manager::gameTypeLabel(uint gameType, LabelType type) const
265{
266 if ( gameType!=0 )
267 kdFatal(11002) << "You need to reimplement KExtHighscore::Manager for "
268 << "multiple game types" << endl;
269 switch (type) {
270 case Icon:
271 case Standard:
272 case I18N: break;
273 case WW: return "normal";
274 }
275 return TQString();
276}
277
278void Manager::addToQueryURL(KURL &url, const TQString &item,
279 const TQString &content)
280{
281 Q_ASSERT( !item.isEmpty() && url.queryItem(item).isNull() );
282
283 TQString query = url.query();
284 if ( !query.isEmpty() ) query += '&';
285 query += item + '=' + KURL::encode_string(content);
286 url.setQuery(query);
287}
288
289} // namescape
KExtHighscore::Item
This class defines how to convert and how to display a highscore element (such as the score,...
Definition: kexthighscore_item.h:41
KExtHighscore::Item::setDefaultValue
void setDefaultValue(const TQVariant &value)
Set default value.
Definition: kexthighscore_item.h:124
KExtHighscore::Item::defaultValue
const TQVariant & defaultValue() const
Definition: kexthighscore_item.h:129
KExtHighscore::Item::setPrettyFormat
void setPrettyFormat(Format format)
Set the display format.
Definition: kexthighscore_item.cpp:49
KExtHighscore::Item::setPrettySpecial
void setPrettySpecial(Special special)
Set the special value for display.
Definition: kexthighscore_item.cpp:73
KExtHighscore::Manager::addToQueryURL
static void addToQueryURL(KURL &url, const TQString &item, const TQString &content)
Add an entry to the url to be submitted (.
Definition: kexthighscore.cpp:278
KExtHighscore::Manager::setTrackDrawGames
void setTrackDrawGames(bool track)
Definition: kexthighscore.cpp:128
KExtHighscore::Manager::setPlayerItem
void setPlayerItem(PlayerItemType type, Item *item)
Replace an item in the players list.
Definition: kexthighscore.cpp:246
KExtHighscore::Manager::setWWHighscores
void setWWHighscores(const KURL &url, const TQString &version)
Set the world-wide highscores.
Definition: kexthighscore.cpp:148
KExtHighscore::Manager::setShowMode
void setShowMode(ShowMode mode)
Set how the highscores dialog is shown at game end.
Definition: kexthighscore.cpp:169
KExtHighscore::Manager::ShowMode
ShowMode
Enumerate different conditions under which to show the high score dialog.
Definition: kexthighscore.h:220
KExtHighscore::Manager::AlwaysShow
@ AlwaysShow
Always show the dialog.
Definition: kexthighscore.h:220
KExtHighscore::Manager::NeverShow
@ NeverShow
Never show the dialog.
Definition: kexthighscore.h:221
KExtHighscore::Manager::ShowForHighestScore
@ ShowForHighestScore
Only for the top spot.
Definition: kexthighscore.h:223
KExtHighscore::Manager::ShowForHigherScore
@ ShowForHigherScore
Show if score has improved.
Definition: kexthighscore.h:222
KExtHighscore::Manager::ItemType
ItemType
Some predefined item types.
Definition: kexthighscore.h:255
KExtHighscore::Manager::setTrackLostGames
void setTrackLostGames(bool track)
Set if the number of lost games should be track for the world-wide highscores statistics.
Definition: kexthighscore.cpp:123
KExtHighscore::Manager::LabelType
LabelType
Possible type of label (.
Definition: kexthighscore.h:303
KExtHighscore::Manager::setScoreItem
void setScoreItem(uint worstScore, Item *item)
Replace the default score item in the highscores list by the given one.
Definition: kexthighscore.cpp:231
KExtHighscore::Manager::setShowStatistics
void setShowStatistics(bool show)
Definition: kexthighscore.cpp:133
KExtHighscore::Manager::createItem
static Item * createItem(ItemType type)
Create a predefined item.
Definition: kexthighscore.cpp:206
KExtHighscore::Manager::isStrictlyLess
virtual bool isStrictlyLess(const Score &s1, const Score &s2) const
Definition: kexthighscore.cpp:201
KExtHighscore::Manager::ScoreType
ScoreType
Score type (.
Definition: kexthighscore.h:238
KExtHighscore::Manager::Manager
Manager(uint nbGameTypes=1, uint maxNbEntries=10)
Constructor.
Definition: kexthighscore.cpp:107
KExtHighscore::Manager::gameTypeLabel
virtual TQString gameTypeLabel(uint gameType, LabelType type) const
Definition: kexthighscore.cpp:264
KExtHighscore::Manager::showStatistics
void showStatistics(bool show) TDE_DEPRECATED
Definition: kexthighscore.cpp:138
KExtHighscore::Manager::addScoreItem
void addScoreItem(const TQString &name, Item *item)
Add an item in the highscores list (it will add a column to this list).
Definition: kexthighscore.cpp:241
KExtHighscore::Manager::setScoreHistogram
void setScoreHistogram(const TQMemArray< uint > &scores, ScoreTypeBound type)
Set the ranges for the score histogram.
Definition: kexthighscore.cpp:160
KExtHighscore::Manager::setScoreType
void setScoreType(ScoreType type)
Set score type.
Definition: kexthighscore.cpp:174
KExtHighscore::Manager::submitLegacyScore
void submitLegacyScore(const Score &score) const
This method should be called from convertLegacy.
Definition: kexthighscore.cpp:196
KExtHighscore::Manager::setShowDrawGamesStatistic
void setShowDrawGamesStatistic(bool show)
Definition: kexthighscore.cpp:143
KExtHighscore::Score
This class contains data for a score.
Definition: kexthighscore_item.h:176
KExtHighscore::Score::score
uint score() const
Definition: kexthighscore_item.h:209

libtdegames

Skip menu "libtdegames"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libtdegames

Skip menu "libtdegames"
  • libtdegames
Generated for libtdegames by doxygen 1.9.4
This website is maintained by Timothy Pearson.