-
Notifications
You must be signed in to change notification settings - Fork 1
/
gameprofile.h
168 lines (124 loc) · 4.4 KB
/
gameprofile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#ifndef GAMEPROFILE_H
#define GAMEPROFILE_H
#include <QStringList>
#include <QObject>
#include <QXmlStreamReader>
#define DIFF_LOW 1
#define DIFF_NORMAL 2
#define DIFF_HARD 3
#define LANG_DEFAULT "English"
struct ItemInfo
{
ItemInfo() :
totalCount(0), localCount(0)
{
}
int totalCount, localCount;
};
struct LevelPackInfo
{
LevelPackInfo(const QString &s) :
levelpack(s),
diff(DIFF_NORMAL), mode(0),
score(0), localScore(0), level(1),
time_bonus(0), speed_bonus(0), score_bonus(0), speed_mag_bonus(2),
next_tool(2) { }
void init();
bool isPuzzle() { return mode == 1; }
QString levelpack;
int diff, mode;
// game progress
int score, localScore, level;
int time_bonus, speed_bonus, score_bonus, speed_mag_bonus;
int next_tool;
QList<ItemInfo> items;
};
struct PlayerInfo
{
PlayerInfo(const QString &s) :
name(s), theme("default"),
currentlevelpack("default"),
m_fullscreen(false),
m_width(0), m_height(0),
musicEnabled(false), soundVolume(64), musicVolume(64),
x(0), y(0), screen(0)
{ addLevelPack("default"); }
LevelPackInfo* currentLevelPackInfo();
void addLevelPack(const QString &levelpack);
void addLevelPack(LevelPackInfo* lpi);
void setCurrentLevelPack(const QString &levelpack)
{ addLevelPack(levelpack); currentlevelpack = levelpack; }
QString name, theme;
QString currentlevelpack; // levelpack
// settings
bool m_fullscreen;
int m_width, m_height;
bool musicEnabled;
int soundVolume, musicVolume;
int x, y, screen;
QList<LevelPackInfo*> levelpacks;
};
struct PlayerScore
{
PlayerScore(const QString &s, int _score) :
name(s), score(_score) { }
QString name;
int score;
};
class GameProfile : public QObject
{
Q_OBJECT
public:
GameProfile(QObject *parent);
PlayerInfo *currentPlayer();
void setCurrentPlayer(const QString &name);
void removePlayer(const QString &name);
void renamePlayer(const QString &before, const QString &after);
void saveProfile();
void loadProfile();
void loadOldProfile(); // for backward compability
void saveXml();
void loadXml();
void readXmlUnknownElement(QXmlStreamReader &xsr);
void readXmlPlayer(QXmlStreamReader &xsr);
void readXmlLevelPack(QXmlStreamReader &xsr, PlayerInfo *pl);
void readXmlLevelItem(QXmlStreamReader &xsr, LevelPackInfo *lpi);
void setPlayerNames(const QStringList &sl);
QStringList playerNames();
void setGameStarted(bool yes = true) { m_started = yes; }
bool isGameStarted() { return m_started; }
void setGamePaused(bool yes = true) { m_paused = yes; }
bool isGamePaused() { return m_paused; }
void scanThemes();
QStringList themesList() { return m_themes; }
void setCurrentTheme(const QString &_theme) { currentPlayer()->theme = _theme; }
QString currentTheme() { return currentPlayer()->theme; }
void setCurrentLevelPack(const QString &_lp) { currentPlayer()->setCurrentLevelPack(_lp); }
QString currentLevelPack() { return currentPlayer()->currentlevelpack; }
int levelPackCount(const QString &lp);
QString levelPackName(const QString &lp);
void setFullscreen(bool yes = true) { currentPlayer()->m_fullscreen = yes; }
bool isFullscreen() { return currentPlayer()->m_fullscreen; }
void setAccelerated(bool yes = true) { m_accel = yes; }
bool isAccelerated() { return m_accel; }
inline int screenWidth() { return currentPlayer()->m_width; }
inline int screenHeight() { return currentPlayer()->m_height; }
inline void setVideoMode(int w, int h) { currentPlayer()->m_width = w; currentPlayer()->m_height = h; }
inline void setWindowPos(int xx, int yy) { currentPlayer()->x = xx; currentPlayer()->y = yy; }
inline void setScreen(int screen) { currentPlayer()->screen = screen; }
// void addTopTenPlayer(PlayerScore ps);
// QList<PlayerScore> topTenList() { return m_topten; }
signals:
void profileChanged();
private:
void saveTopTen();
void loadTopTen();
int m_current;
QList<PlayerInfo*> m_players;
// QList<PlayerScore> m_topten;
QStringList m_themes;
QString userPath;
bool m_started, m_paused, m_accel;
};
extern GameProfile* gameProfile;
#endif // GAMEPROFILE_H