• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

libkdegames/highscore

  • sources
  • kde-4.14
  • kdegames
  • libkdegames
  • highscore
kexthighscore.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE 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 <QLayout>
23 //Added by qt3to4:
24 #include <QVector>
25 
26 #include <kdebug.h>
27 
28 #include "kexthighscore_internal.h"
29 #include "kexthighscore_gui.h"
30 
31 
32 namespace KExtHighscore
33 {
34 
35 //-----------------------------------------------------------------------------
36 ManagerPrivate *internal = 0;
37 
38 uint gameType()
39 {
40  internal->checkFirst();
41  return internal->gameType();
42 }
43 
44 void setGameType(uint type)
45 {
46  internal->setGameType(type);
47 }
48 
49 bool configure(QWidget *parent)
50 {
51  internal->checkFirst();
52  ConfigDialog *cd = new ConfigDialog(parent);
53  cd->exec();
54  bool saved = cd->hasBeenSaved();
55  delete cd;
56  return saved;
57 }
58 
59 void show(QWidget *parent, int rank)
60 {
61  HighscoresDialog *hd = new HighscoresDialog(rank, parent);
62  hd->exec();
63  delete hd;
64 }
65 
66 void submitScore(const Score &score, QWidget *widget)
67 {
68  int rank = internal->submitScore(score, widget,
69  internal->showMode!=Manager::NeverShow);
70 
71  switch (internal->showMode) {
72  case Manager::AlwaysShow:
73  show(widget, -1);
74  break;
75  case Manager::ShowForHigherScore:
76  if ( rank!=-1) show(widget, rank);
77  break;
78  case Manager::ShowForHighestScore:
79  if ( rank==0 ) show(widget, rank);
80  break;
81  case Manager::NeverShow:
82  break;
83  }
84 }
85 
86 void show(QWidget *widget)
87 {
88  internal->checkFirst();
89  show(widget, -1);
90 }
91 
92 Score lastScore()
93 {
94  internal->checkFirst();
95  internal->hsConfig().readCurrentConfig();
96  uint nb = internal->scoreInfos().maxNbEntries();
97  return internal->readScore(nb-1);
98 }
99 
100 Score firstScore()
101 {
102  internal->checkFirst();
103  internal->hsConfig().readCurrentConfig();
104  return internal->readScore(0);
105 }
106 
107 
108 //-----------------------------------------------------------------------------
109 Manager::Manager(uint nbGameTypes, uint maxNbEntries)
110 {
111  Q_ASSERT(nbGameTypes);
112  Q_ASSERT(maxNbEntries);
113  if (internal)
114  kFatal(11002) << "A highscore object already exists";
115  internal = new ManagerPrivate(nbGameTypes, *this);
116  internal->init(maxNbEntries);
117 }
118 
119 Manager::~Manager()
120 {
121  delete internal;
122  internal = 0;
123 }
124 
125 void Manager::setTrackLostGames(bool track)
126 {
127  internal->trackLostGames = track;
128 }
129 
130 void Manager::setTrackDrawGames(bool track)
131 {
132  internal->trackDrawGames = track;
133 }
134 
135 void Manager::setShowStatistics(bool show)
136 {
137  internal->showStatistics = show;
138 }
139 
140 void Manager::setShowDrawGamesStatistic(bool show)
141 {
142  internal->showDrawGames = show;
143 }
144 
145 void Manager::setWWHighscores(const KUrl &url, const QString &version)
146 {
147  Q_ASSERT( url.isValid() );
148  internal->serverURL = url;
149  const char *HS_WW_URL = "ww hs url";
150  ConfigGroup cg;
151  if ( cg.hasKey(HS_WW_URL) )
152  internal->serverURL = cg.readEntry(HS_WW_URL);
153  else cg.writeEntry(HS_WW_URL, url.url());
154  internal->version = version;
155 }
156 
157 void Manager::setScoreHistogram(const QVector<uint> &scores,
158  ScoreTypeBound type)
159 {
160  Q_ASSERT( scores.size()>=2 );
161  for (int i=0; i<scores.size()-1; i++)
162  Q_ASSERT( scores[i]<scores[i+1] );
163  internal->playerInfos().createHistoItems(scores, type==ScoreBound);
164 }
165 
166 void Manager::setShowMode(ShowMode mode)
167 {
168  internal->showMode = mode;
169 }
170 
171 void Manager::setScoreType(ScoreType type)
172 {
173  switch (type) {
174  case Normal:
175  return;
176  case MinuteTime: {
177  Item *item = createItem(ScoreDefault);
178  item->setPrettyFormat(Item::MinuteTime);
179  setScoreItem(0, item);
180 
181  item = createItem(MeanScoreDefault);
182  item->setPrettyFormat(Item::MinuteTime);
183  setPlayerItem(MeanScore, item);
184 
185  item = createItem(BestScoreDefault);
186  item->setPrettyFormat(Item::MinuteTime);
187  setPlayerItem(BestScore, item);
188  return;
189  }
190  }
191 }
192 
193 void Manager::submitLegacyScore(const Score &score) const
194 {
195  internal->submitLocal(score);
196 }
197 
198 bool Manager::isStrictlyLess(const Score &s1, const Score &s2) const
199 {
200  return s1.score()<s2.score();
201 }
202 
203 Item *Manager::createItem(ItemType type)
204 {
205  Item *item = 0;
206  switch (type) {
207  case ScoreDefault:
208  item = new Item((uint)0, i18n("Score"), Qt::AlignRight);
209  break;
210  case MeanScoreDefault:
211  item = new Item((double)0, i18n("Mean Score"), Qt::AlignRight);
212  item->setPrettyFormat(Item::OneDecimal);
213  item->setPrettySpecial(Item::DefaultNotDefined);
214  break;
215  case BestScoreDefault:
216  item = new Item((uint)0, i18n("Best Score"), Qt::AlignRight);
217  item->setPrettySpecial(Item::DefaultNotDefined);
218  break;
219  case ElapsedTime:
220  item = new Item((uint)0, i18n("Elapsed Time"), Qt::AlignRight);
221  item->setPrettyFormat(Item::MinuteTime);
222  item->setPrettySpecial(Item::ZeroNotDefined);
223  break;
224  }
225  return item;
226 }
227 
228 void Manager::setScoreItem(uint worstScore, Item *item)
229 {
230  item->setDefaultValue(worstScore);
231  internal->scoreInfos().setItem(QLatin1String( "score" ), item);
232  internal->playerInfos().item(QLatin1String( "mean score" ))
233  ->item()->setDefaultValue(double(worstScore));
234  internal->playerInfos().item(QLatin1String( "best score" ))
235  ->item()->setDefaultValue(worstScore);
236 }
237 
238 void Manager::addScoreItem(const QString &name, Item *item)
239 {
240  internal->scoreInfos().addItem(name, item, true);
241 }
242 
243 void Manager::setPlayerItem(PlayerItemType type, Item *item)
244 {
245  const Item *scoreItem = internal->scoreInfos().item(QLatin1String( "score" ))->item();
246  uint def = scoreItem->defaultValue().toUInt();
247  QString name;
248  switch (type) {
249  case MeanScore:
250  name = QLatin1String( "mean score" );
251  item->setDefaultValue(double(def));
252  break;
253  case BestScore:
254  name = QLatin1String( "best score" );
255  item->setDefaultValue(def);
256  break;
257  }
258  internal->playerInfos().setItem(name, item);
259 }
260 
261 QString Manager::gameTypeLabel(uint gameType, LabelType type) const
262 {
263  if ( gameType!=0 )
264  kFatal(11002) << "You need to reimplement KExtHighscore::Manager for "
265  << "multiple game types";
266  switch (type) {
267  case Icon:
268  case Standard:
269  case I18N: break;
270  case WW: return QLatin1String( "normal" );
271  }
272  return QString();
273 }
274 
275 void Manager::addToQueryURL(KUrl &url, const QString &item,
276  const QString &content)
277 {
278  Q_ASSERT( !item.isEmpty() && url.queryItem(item).isNull() );
279 
280  QString query = url.query();
281  if ( !query.isEmpty() ) query += QLatin1Char( '&' );
282  query += item + QLatin1Char( '=' ) + QLatin1String( QUrl::toPercentEncoding( content ) );
283  url.setQuery(query);
284 }
285 
286 } // namescape
QWidget
KExtHighscore::Manager::~Manager
virtual ~Manager()
Definition: kexthighscore.cpp:119
KExtHighscore::Manager::ScoreType
ScoreType
Score type (.
Definition: kexthighscore.h:233
KExtHighscore::Score::score
uint score() const
Definition: kexthighscore_item.h:212
KExtHighscore::Manager::setScoreType
void setScoreType(ScoreType type)
Set score type.
Definition: kexthighscore.cpp:171
KExtHighscore::Manager::ScoreBound
Definition: kexthighscore.h:203
KExtHighscore::submitScore
void submitScore(const Score &score, QWidget *widget)
Submit a score.
Definition: kexthighscore.cpp:66
KExtHighscore::show
void show(QWidget *parent, int rank)
Definition: kexthighscore.cpp:59
KExtHighscore::Manager::PlayerItemType
PlayerItemType
Definition: kexthighscore.h:272
KExtHighscore::ManagerPrivate::serverURL
KUrl serverURL
Definition: kexthighscore_internal.h:255
KExtHighscore::Manager::BestScore
Definition: kexthighscore.h:272
KExtHighscore::HighscoresDialog
Definition: kexthighscore_gui.h:109
KExtHighscore::Manager::setTrackDrawGames
void setTrackDrawGames(bool track)
Set if the number of "draw" games should be track for the world-wide highscores statistics.
Definition: kexthighscore.cpp:130
KExtHighscore::ConfigDialog
Definition: kexthighscore_gui.h:157
KExtHighscore::Item::setDefaultValue
void setDefaultValue(const QVariant &value)
Set default value.
Definition: kexthighscore_item.h:123
KExtHighscore::Item::DefaultNotDefined
Definition: kexthighscore_item.h:72
KExtHighscore::Item::defaultValue
QVariant defaultValue() const
Definition: kexthighscore_item.h:128
KExtHighscore::Manager::AlwaysShow
Always show the dialog.
Definition: kexthighscore.h:215
KExtHighscore::Manager::setShowMode
void setShowMode(ShowMode mode)
Set how the highscores dialog is shown at game end.
Definition: kexthighscore.cpp:166
KExtHighscore::lastScore
Score lastScore()
Definition: kexthighscore.cpp:92
KExtHighscore::ManagerPrivate
Definition: kexthighscore_internal.h:227
kexthighscore_gui.h
KExtHighscore::Manager::MinuteTime
Definition: kexthighscore.h:233
KExtHighscore::internal
ManagerPrivate * internal
Definition: kexthighscore.cpp:36
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:125
QVariant::toUInt
uint toUInt(bool *ok) const
KExtHighscore::Item
This class defines how to convert and how to display a highscore element (such as the score...
Definition: kexthighscore_item.h:39
KExtHighscore::Manager::submitLegacyScore
void submitLegacyScore(const Score &score) const
This method should be called from convertLegacy.
Definition: kexthighscore.cpp:193
KExtHighscore::Manager::ShowMode
ShowMode
Enumerate different conditions under which to show the high score dialog.
Definition: kexthighscore.h:215
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:228
KExtHighscore::Item::MinuteTime
Definition: kexthighscore_item.h:54
KExtHighscore::Manager::ItemType
ItemType
Some predefined item types.
Definition: kexthighscore.h:250
QString::isEmpty
bool isEmpty() const
kexthighscore_internal.h
KExtHighscore::Manager::createItem
static Item * createItem(ItemType type)
Create a predefined item.
Definition: kexthighscore.cpp:203
KExtHighscore::Manager::setShowDrawGamesStatistic
void setShowDrawGamesStatistic(bool show)
Set if draw games statistics should be shown (enable this if draws are possible in your game)...
Definition: kexthighscore.cpp:140
KExtHighscore::Manager::LabelType
LabelType
Possible type of label (.
Definition: kexthighscore.h:298
KExtHighscore::Manager::addScoreItem
void addScoreItem(const QString &name, Item *item)
Add an item in the highscores list (it will add a column to this list).
Definition: kexthighscore.cpp:238
KExtHighscore::Manager::gameTypeLabel
virtual QString gameTypeLabel(uint gameType, LabelType type) const
Definition: kexthighscore.cpp:261
KExtHighscore::Manager::WW
Definition: kexthighscore.h:298
QString
KExtHighscore::firstScore
Score firstScore()
Definition: kexthighscore.cpp:100
KExtHighscore::Manager::ScoreTypeBound
ScoreTypeBound
Definition: kexthighscore.h:203
KExtHighscore::Item::ZeroNotDefined
Definition: kexthighscore_item.h:71
KExtHighscore::Manager::ShowForHighestScore
Only for the top spot.
Definition: kexthighscore.h:218
KExtHighscore::Manager::addToQueryURL
static void addToQueryURL(KUrl &url, const QString &item, const QString &content)
Add an entry to the url to be submitted (.
Definition: kexthighscore.cpp:275
KExtHighscore::Manager::ManagerPrivate
friend class ManagerPrivate
Definition: kexthighscore.h:353
KExtHighscore::setGameType
void setGameType(uint type)
Set the current game type.
Definition: kexthighscore.cpp:44
KExtHighscore::Manager::MeanScore
Definition: kexthighscore.h:272
KExtHighscore::Item::setPrettyFormat
void setPrettyFormat(Format format)
Set the display format.
Definition: kexthighscore_item.cpp:53
KExtHighscore::Manager::setShowStatistics
void setShowStatistics(bool show)
Set if the statistics tab should be shown in the highscores dialog.
Definition: kexthighscore.cpp:135
KExtHighscore::Manager::setScoreHistogram
void setScoreHistogram(const QVector< uint > &scores, ScoreTypeBound type)
Set the ranges for the score histogram.
Definition: kexthighscore.cpp:157
KExtHighscore::configure
bool configure(QWidget *parent)
Configure the highscores.
Definition: kexthighscore.cpp:49
QLatin1Char
KExtHighscore::Manager::MeanScoreDefault
Definition: kexthighscore.h:250
KExtHighscore::gameType
uint gameType()
Get the current game type.
Definition: kexthighscore.cpp:38
KExtHighscore::Manager::ShowForHigherScore
Show if score has improved.
Definition: kexthighscore.h:217
QVector< uint >
KExtHighscore::Manager::Normal
Definition: kexthighscore.h:233
QLatin1String
KExtHighscore::Manager::Manager
Manager(uint nbGameTypes=1, uint maxNbEntries=10)
Constructor.
Definition: kexthighscore.cpp:109
KExtHighscore::Manager::ScoreDefault
Definition: kexthighscore.h:250
KExtHighscore::Manager::BestScoreDefault
Definition: kexthighscore.h:250
KExtHighscore::Manager::setPlayerItem
void setPlayerItem(PlayerItemType type, Item *item)
Replace an item in the players list.
Definition: kexthighscore.cpp:243
KExtHighscore::Manager::I18N
Definition: kexthighscore.h:298
KExtHighscore::Manager::Icon
Definition: kexthighscore.h:298
KExtHighscore::Score
This class contains data for a score.
Definition: kexthighscore_item.h:178
KExtHighscore::Manager::Standard
Definition: kexthighscore.h:298
KExtHighscore::Manager::ElapsedTime
Definition: kexthighscore.h:251
QUrl::toPercentEncoding
QByteArray toPercentEncoding(const QString &input, const QByteArray &exclude, const QByteArray &include)
KExtHighscore::Manager::isStrictlyLess
virtual bool isStrictlyLess(const Score &s1, const Score &s2) const
Definition: kexthighscore.cpp:198
KExtHighscore::ManagerPrivate::showMode
Manager::ShowMode showMode
Definition: kexthighscore_internal.h:258
KExtHighscore::Manager::NeverShow
Never show the dialog.
Definition: kexthighscore.h:216
KExtHighscore::ConfigGroup
Definition: kexthighscore_internal.h:180
kexthighscore.h
KExtHighscore::Item::OneDecimal
Definition: kexthighscore_item.h:54
KExtHighscore::Item::setPrettySpecial
void setPrettySpecial(Special special)
Set the special value for display.
Definition: kexthighscore_item.cpp:77
QVector::size
int size() const
KExtHighscore::Manager::setWWHighscores
void setWWHighscores(const KUrl &url, const QString &version)
Set the world-wide highscores.
Definition: kexthighscore.cpp:145
KExtHighscore::ConfigDialog::hasBeenSaved
bool hasBeenSaved() const
Definition: kexthighscore_gui.h:163
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:46 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdegames/highscore

Skip menu "libkdegames/highscore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal