• 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 
30 namespace KExtHighscore
31 {
32 
33 //-----------------------------------------------------------------------------
34 ManagerPrivate *internal = 0;
35 
36 uint gameType()
37 {
38  internal->checkFirst();
39  return internal->gameType();
40 }
41 
42 void setGameType(uint type)
43 {
44  internal->setGameType(type);
45 }
46 
47 bool 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 
57 void show(TQWidget *parent, int rank)
58 {
59  HighscoresDialog *hd = new HighscoresDialog(rank, parent);
60  hd->exec();
61  delete hd;
62 }
63 
64 void 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 
84 void show(TQWidget *widget)
85 {
86  internal->checkFirst();
87  show(widget, -1);
88 }
89 
90 Score lastScore()
91 {
92  internal->checkFirst();
93  internal->hsConfig().readCurrentConfig();
94  uint nb = internal->scoreInfos().maxNbEntries();
95  return internal->readScore(nb-1);
96 }
97 
98 Score firstScore()
99 {
100  internal->checkFirst();
101  internal->hsConfig().readCurrentConfig();
102  return internal->readScore(0);
103 }
104 
105 
106 //-----------------------------------------------------------------------------
107 Manager::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 
117 Manager::~Manager()
118 {
119  delete internal;
120  internal = 0;
121 }
122 
123 void Manager::setTrackLostGames(bool track)
124 {
125  internal->trackLostGames = track;
126 }
127 
128 void Manager::setTrackDrawGames(bool track)
129 {
130  internal->trackDrawGames = track;
131 }
132 
133 void Manager::setShowStatistics(bool show)
134 {
135  internal->showStatistics = show;
136 }
137 
138 void Manager::showStatistics(bool show)
139 {
140  internal->showStatistics = show;
141 }
142 
143 void Manager::setShowDrawGamesStatistic(bool show)
144 {
145  internal->showDrawGames = show;
146 }
147 
148 void Manager::setScoreHistogram(const TQMemArray<uint> &scores,
149  ScoreTypeBound type)
150 {
151  Q_ASSERT( scores.size()>=2 );
152  for (uint i=0; i<scores.size()-1; i++)
153  Q_ASSERT( scores[i]<scores[i+1] );
154  internal->playerInfos().createHistoItems(scores, type==ScoreBound);
155 }
156 
157 void Manager::setShowMode(ShowMode mode)
158 {
159  internal->showMode = mode;
160 }
161 
162 void Manager::setScoreType(ScoreType type)
163 {
164  switch (type) {
165  case Normal:
166  return;
167  case MinuteTime: {
168  Item *item = createItem(ScoreDefault);
169  item->setPrettyFormat(Item::MinuteTime);
170  setScoreItem(0, item);
171 
172  item = createItem(MeanScoreDefault);
173  item->setPrettyFormat(Item::MinuteTime);
174  setPlayerItem(MeanScore, item);
175 
176  item = createItem(BestScoreDefault);
177  item->setPrettyFormat(Item::MinuteTime);
178  setPlayerItem(BestScore, item);
179  return;
180  }
181  }
182 }
183 
184 void Manager::submitLegacyScore(const Score &score) const
185 {
186  internal->submitLocal(score);
187 }
188 
189 bool Manager::isStrictlyLess(const Score &s1, const Score &s2) const
190 {
191  return s1.score()<s2.score();
192 }
193 
194 Item *Manager::createItem(ItemType type)
195 {
196  Item *item = 0;
197  switch (type) {
198  case ScoreDefault:
199  item = new Item((uint)0, i18n("Score"), TQt::AlignRight);
200  break;
201  case MeanScoreDefault:
202  item = new Item((double)0, i18n("Mean Score"), TQt::AlignRight);
203  item->setPrettyFormat(Item::OneDecimal);
204  item->setPrettySpecial(Item::DefaultNotDefined);
205  break;
206  case BestScoreDefault:
207  item = new Item((uint)0, i18n("Best Score"), TQt::AlignRight);
208  item->setPrettySpecial(Item::DefaultNotDefined);
209  break;
210  case ElapsedTime:
211  item = new Item((uint)0, i18n("Elapsed Time"), TQt::AlignRight);
212  item->setPrettyFormat(Item::MinuteTime);
213  item->setPrettySpecial(Item::ZeroNotDefined);
214  break;
215  }
216  return item;
217 }
218 
219 void Manager::setScoreItem(uint worstScore, Item *item)
220 {
221  item->setDefaultValue(worstScore);
222  internal->scoreInfos().setItem("score", item);
223  internal->playerInfos().item("mean score")
224  ->item()->setDefaultValue(double(worstScore));
225  internal->playerInfos().item("best score")
226  ->item()->setDefaultValue(worstScore);
227 }
228 
229 void Manager::addScoreItem(const TQString &name, Item *item)
230 {
231  internal->scoreInfos().addItem(name, item, true);
232 }
233 
234 void Manager::setPlayerItem(PlayerItemType type, Item *item)
235 {
236  const Item *scoreItem = internal->scoreInfos().item("score")->item();
237  uint def = scoreItem->defaultValue().toUInt();
238  TQString name;
239  switch (type) {
240  case MeanScore:
241  name = "mean score";
242  item->setDefaultValue(double(def));
243  break;
244  case BestScore:
245  name = "best score";
246  item->setDefaultValue(def);
247  break;
248  }
249  internal->playerInfos().setItem(name, item);
250 }
251 
252 TQString Manager::gameTypeLabel(uint gameType, LabelType type) const
253 {
254  if ( gameType!=0 )
255  kdFatal(11002) << "You need to reimplement KExtHighscore::Manager for "
256  << "multiple game types" << endl;
257  switch (type) {
258  case Icon:
259  case Standard:
260  case I18N: break;
261  case WW: return "normal";
262  }
263  return TQString();
264 }
265 
266 } // 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::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:234
KExtHighscore::Manager::setShowMode
void setShowMode(ShowMode mode)
Set how the highscores dialog is shown at game end.
Definition: kexthighscore.cpp:157
KExtHighscore::Manager::ShowMode
ShowMode
Enumerate different conditions under which to show the high score dialog.
Definition: kexthighscore.h:208
KExtHighscore::Manager::AlwaysShow
@ AlwaysShow
Always show the dialog.
Definition: kexthighscore.h:208
KExtHighscore::Manager::NeverShow
@ NeverShow
Never show the dialog.
Definition: kexthighscore.h:209
KExtHighscore::Manager::ShowForHighestScore
@ ShowForHighestScore
Only for the top spot.
Definition: kexthighscore.h:211
KExtHighscore::Manager::ShowForHigherScore
@ ShowForHigherScore
Show if score has improved.
Definition: kexthighscore.h:210
KExtHighscore::Manager::ItemType
ItemType
Some predefined item types.
Definition: kexthighscore.h:243
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:291
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:219
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:194
KExtHighscore::Manager::isStrictlyLess
virtual bool isStrictlyLess(const Score &s1, const Score &s2) const
Definition: kexthighscore.cpp:189
KExtHighscore::Manager::ScoreType
ScoreType
Score type (.
Definition: kexthighscore.h:226
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:252
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:229
KExtHighscore::Manager::setScoreHistogram
void setScoreHistogram(const TQMemArray< uint > &scores, ScoreTypeBound type)
Set the ranges for the score histogram.
Definition: kexthighscore.cpp:148
KExtHighscore::Manager::setScoreType
void setScoreType(ScoreType type)
Set score type.
Definition: kexthighscore.cpp:162
KExtHighscore::Manager::submitLegacyScore
void submitLegacyScore(const Score &score) const
This method should be called from convertLegacy.
Definition: kexthighscore.cpp:184
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.1
This website is maintained by Timothy Pearson.