You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
278 lines
8.2 KiB
278 lines
8.2 KiB
15 years ago
|
/*
|
||
|
This file is part of the KDE games library
|
||
|
Copyright (C) 2001-2004 Nicolas Hadacek (hadacek@kde.org)
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#ifndef KEXTHIGHSCORE_INTERNAL_H
|
||
|
#define KEXTHIGHSCORE_INTERNAL_H
|
||
|
|
||
|
#include <kapplication.h>
|
||
|
#include <kconfig.h>
|
||
|
#include <klocale.h>
|
||
|
#include <kurl.h>
|
||
|
|
||
|
#include "khighscore.h"
|
||
|
#include "kexthighscore.h"
|
||
|
|
||
14 years ago
|
class TQTextStream;
|
||
|
class TQTabWidget;
|
||
|
class TQDomNamedNodeMap;
|
||
15 years ago
|
|
||
|
|
||
|
namespace KExtHighscore
|
||
|
{
|
||
|
|
||
|
class PlayerInfos;
|
||
|
class Score;
|
||
|
class Manager;
|
||
|
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
class RankItem : public Item
|
||
|
{
|
||
|
public:
|
||
|
RankItem()
|
||
14 years ago
|
: Item((uint)0, i18n("Rank"), TQt::AlignRight) {}
|
||
15 years ago
|
|
||
15 years ago
|
TQVariant read(uint rank, const TQVariant &) const { return rank; }
|
||
|
TQString pretty(uint rank, const TQVariant &) const
|
||
|
{ return TQString::number(rank+1); }
|
||
15 years ago
|
};
|
||
|
|
||
|
class NameItem : public Item
|
||
|
{
|
||
|
public:
|
||
|
NameItem()
|
||
14 years ago
|
: Item(TQString(), i18n("Name"), TQt::AlignLeft) {
|
||
15 years ago
|
setPrettySpecial(Anonymous);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
class DateItem : public Item
|
||
|
{
|
||
|
public:
|
||
|
DateItem()
|
||
14 years ago
|
: Item(TQDateTime(), i18n("Date"), TQt::AlignRight) {
|
||
15 years ago
|
setPrettyFormat(DateTime);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
class SuccessPercentageItem : public Item
|
||
|
{
|
||
|
public:
|
||
|
SuccessPercentageItem()
|
||
14 years ago
|
: Item((double)-1, i18n("Success"), TQt::AlignRight) {
|
||
15 years ago
|
setPrettyFormat(Percentage);
|
||
|
setPrettySpecial(NegativeNotDefined);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
class ItemContainer
|
||
|
{
|
||
|
public:
|
||
|
ItemContainer();
|
||
|
~ItemContainer();
|
||
|
|
||
|
void setItem(Item *item);
|
||
|
const Item *item() const { return _item; }
|
||
|
Item *item() { return _item; }
|
||
|
|
||
15 years ago
|
void setName(const TQString &name) { _name = name; }
|
||
|
TQString name() const { return _name; }
|
||
15 years ago
|
|
||
15 years ago
|
void setGroup(const TQString &group) { _group = group; }
|
||
15 years ago
|
bool isStored() const { return !_group.isNull(); }
|
||
|
|
||
15 years ago
|
void setSubGroup(const TQString &subGroup) { _subGroup = subGroup; }
|
||
15 years ago
|
bool canHaveSubGroup() const { return !_subGroup.isNull(); }
|
||
|
|
||
|
static const char ANONYMOUS[]; // name assigned to anonymous players
|
||
|
static const char ANONYMOUS_LABEL[];
|
||
|
|
||
15 years ago
|
TQVariant read(uint i) const;
|
||
|
TQString pretty(uint i) const;
|
||
|
void write(uint i, const TQVariant &value) const;
|
||
|
// for UInt TQVariant (return new value)
|
||
15 years ago
|
uint increment(uint i) const;
|
||
|
|
||
|
private:
|
||
|
Item *_item;
|
||
15 years ago
|
TQString _name, _group, _subGroup;
|
||
15 years ago
|
|
||
15 years ago
|
TQString entryName() const;
|
||
15 years ago
|
|
||
|
ItemContainer(const ItemContainer &);
|
||
|
ItemContainer &operator =(const ItemContainer &);
|
||
|
};
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
/**
|
||
|
* Manage a bunch of @ref Item which are saved under the same group
|
||
|
* in KHighscores config file.
|
||
|
*/
|
||
15 years ago
|
class ItemArray : public TQMemArray<ItemContainer *>
|
||
15 years ago
|
{
|
||
|
public:
|
||
|
ItemArray();
|
||
|
virtual ~ItemArray();
|
||
|
|
||
|
virtual uint nbEntries() const = 0;
|
||
|
|
||
15 years ago
|
const ItemContainer *item(const TQString &name) const;
|
||
|
ItemContainer *item(const TQString &name);
|
||
15 years ago
|
|
||
15 years ago
|
void addItem(const TQString &name, Item *, bool stored = true,
|
||
15 years ago
|
bool canHaveSubGroup = false);
|
||
15 years ago
|
void setItem(const TQString &name, Item *);
|
||
|
int findIndex(const TQString &name) const;
|
||
15 years ago
|
|
||
15 years ago
|
void setGroup(const TQString &group);
|
||
|
void setSubGroup(const TQString &subGroup);
|
||
15 years ago
|
|
||
|
void read(uint k, Score &data) const;
|
||
|
void write(uint k, const Score &data, uint maxNbLines) const;
|
||
|
|
||
15 years ago
|
void exportToText(TQTextStream &) const;
|
||
15 years ago
|
|
||
|
private:
|
||
15 years ago
|
TQString _group, _subGroup;
|
||
15 years ago
|
|
||
15 years ago
|
void _setItem(uint i, const TQString &name, Item *, bool stored,
|
||
15 years ago
|
bool canHaveSubGroup);
|
||
|
|
||
|
ItemArray(const ItemArray &);
|
||
|
ItemArray &operator =(const ItemArray &);
|
||
|
};
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
class ScoreInfos : public ItemArray
|
||
|
{
|
||
|
public:
|
||
|
ScoreInfos(uint maxNbEntries, const PlayerInfos &infos);
|
||
|
|
||
|
uint nbEntries() const;
|
||
|
uint maxNbEntries() const { return _maxNbEntries; }
|
||
|
|
||
|
private:
|
||
|
uint _maxNbEntries;
|
||
|
};
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
class ConfigGroup : public KConfigGroupSaver
|
||
|
{
|
||
|
public:
|
||
14 years ago
|
ConfigGroup(const TQString &group = TQString())
|
||
15 years ago
|
: KConfigGroupSaver(kapp->config(), group) {}
|
||
|
};
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
class PlayerInfos : public ItemArray
|
||
|
{
|
||
|
public:
|
||
|
PlayerInfos();
|
||
|
|
||
|
bool isNewPlayer() const { return _newPlayer; }
|
||
|
bool isOldLocalPlayer() const { return _oldLocalPlayer; }
|
||
|
uint nbEntries() const;
|
||
15 years ago
|
TQString name() const { return item("name")->read(_id).toString(); }
|
||
15 years ago
|
bool isAnonymous() const;
|
||
15 years ago
|
TQString prettyName() const { return prettyName(_id); }
|
||
|
TQString prettyName(uint id) const { return item("name")->pretty(id); }
|
||
|
TQString registeredName() const;
|
||
|
TQString comment() const { return item("comment")->pretty(_id); }
|
||
15 years ago
|
bool isWWEnabled() const;
|
||
15 years ago
|
TQString key() const;
|
||
15 years ago
|
uint id() const { return _id; }
|
||
|
uint oldLocalId() const { return _oldLocalId; }
|
||
|
|
||
15 years ago
|
void createHistoItems(const TQMemArray<uint> &scores, bool bound);
|
||
|
TQString histoName(uint i) const;
|
||
15 years ago
|
uint histoSize() const;
|
||
15 years ago
|
const TQMemArray<uint> &histogram() const { return _histogram; }
|
||
15 years ago
|
|
||
|
void submitScore(const Score &) const;
|
||
|
// return true if the nickname is already used locally
|
||
15 years ago
|
bool isNameUsed(const TQString &name) const;
|
||
|
void modifyName(const TQString &newName) const;
|
||
|
void modifySettings(const TQString &newName, const TQString &comment,
|
||
|
bool WWEnabled, const TQString &newKey) const;
|
||
15 years ago
|
void removeKey();
|
||
|
|
||
|
private:
|
||
|
bool _newPlayer, _bound, _oldLocalPlayer;
|
||
|
uint _id, _oldLocalId;
|
||
15 years ago
|
TQMemArray<uint> _histogram;
|
||
15 years ago
|
};
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
class ManagerPrivate
|
||
|
{
|
||
|
public:
|
||
|
ManagerPrivate(uint nbGameTypes, Manager &manager);
|
||
|
void init(uint maxNbentries);
|
||
|
~ManagerPrivate();
|
||
|
|
||
15 years ago
|
bool modifySettings(const TQString &newName, const TQString &comment,
|
||
|
bool WWEnabled, TQWidget *widget);
|
||
15 years ago
|
|
||
|
void setGameType(uint type);
|
||
|
void checkFirst();
|
||
|
int submitLocal(const Score &score);
|
||
15 years ago
|
int submitScore(const Score &score, TQWidget *widget, bool askIfAnonymous);
|
||
15 years ago
|
Score readScore(uint i) const;
|
||
|
|
||
|
uint gameType() const { return _gameType; }
|
||
|
uint nbGameTypes() const { return _nbGameTypes; }
|
||
|
bool isWWHSAvailable() const { return !serverURL.isEmpty(); }
|
||
|
ScoreInfos &scoreInfos() { return *_scoreInfos; }
|
||
|
PlayerInfos &playerInfos() { return *_playerInfos; }
|
||
|
KHighscore &hsConfig() { return *_hsConfig; }
|
||
|
enum QueryType { Submit, Register, Change, Players, Scores };
|
||
14 years ago
|
KURL queryURL(QueryType type, const TQString &newName=TQString()) const;
|
||
15 years ago
|
|
||
15 years ago
|
void exportHighscores(TQTextStream &);
|
||
15 years ago
|
|
||
|
Manager &manager;
|
||
|
KURL serverURL;
|
||
15 years ago
|
TQString version;
|
||
15 years ago
|
bool showStatistics, showDrawGames, trackLostGames, trackDrawGames;
|
||
|
Manager::ShowMode showMode;
|
||
|
|
||
|
private:
|
||
|
KHighscore *_hsConfig;
|
||
|
PlayerInfos *_playerInfos;
|
||
|
ScoreInfos *_scoreInfos;
|
||
|
bool _first;
|
||
|
const uint _nbGameTypes;
|
||
|
uint _gameType;
|
||
|
|
||
|
// return -1 if not a local best score
|
||
|
int rank(const Score &score) const;
|
||
|
|
||
13 years ago
|
bool submitWorldWide(const Score &score, TQWidget *parent) const;
|
||
|
static bool doQuery(const KURL &url, TQWidget *parent,
|
||
15 years ago
|
TQDomNamedNodeMap *map = 0);
|
||
|
static bool getFromQuery(const TQDomNamedNodeMap &map, const TQString &name,
|
||
13 years ago
|
TQString &value, TQWidget *parent);
|
||
15 years ago
|
void convertToGlobal();
|
||
|
};
|
||
|
|
||
|
} // namespace
|
||
|
|
||
|
#endif
|