-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplayersettings.cpp
262 lines (210 loc) · 6.88 KB
/
playersettings.cpp
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2015 Simon Stuerz <[email protected]> *
* *
* This file is part of Monster Wars. *
* *
* Monster Wars is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* Monster Wars 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with Monster Wars. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "playersettings.h"
#include <QDebug>
PlayerSettings::PlayerSettings(QObject *parent) :
QObject(parent)
{
QSettings settings;
settings.beginGroup("game");
m_muted = settings.value("muted", false).toBool();
emit mutedChanged();
settings.endGroup();
settings.beginGroup("player");
m_tunePoints = settings.value("tunePoints", 0).toInt();
m_tunePointsStored = m_tunePoints;
emit tunePointsChanged();
m_strengthPoints = settings.value("strength", 0).toInt();
m_strengthPointsStored = m_strengthPoints;
emit strengthPointsChanged();
m_defensePoints = settings.value("defense", 0).toInt();
m_defensePointsStored = m_defensePoints;
emit defensePointsChanged();
m_reproductionPoints = settings.value("reproduction", 0).toInt();
m_reproductionPointsStored = m_reproductionPoints;
emit reproductionPointsChanged();
m_speedPoints = settings.value("speed", 0).toInt();
m_speedPointsStored = m_speedPoints;
emit speedPointsChanged();
settings.endGroup();
m_changed = false;
emit settingsChanged();
}
bool PlayerSettings::muted() const
{
return m_muted;
}
void PlayerSettings::setMuted(const bool &muted)
{
m_muted = muted;
emit mutedChanged();
QSettings settings;
settings.beginGroup("game");
settings.setValue("muted", muted);
settings.endGroup();
}
bool PlayerSettings::changed() const
{
return m_changed;
}
int PlayerSettings::tunePoints() const
{
return m_tunePoints;
}
void PlayerSettings::setTunePoints(const int &tunePoints)
{
m_tunePoints = tunePoints;
emit tunePointsChanged();
qDebug() << "Player 1 -> tune points" << m_tunePoints;
QSettings settings;
settings.beginGroup("player");
settings.setValue("tunePoints", m_tunePoints);
settings.endGroup();
}
void PlayerSettings::increaseTunePoints()
{
setTunePoints(m_tunePoints + 1);
store();
}
int PlayerSettings::strengthPoints() const
{
return m_strengthPoints;
}
void PlayerSettings::setStrengthPoints(const int &strengthPoints)
{
m_strengthPoints = strengthPoints;
emit strengthPointsChanged();
qDebug() << "Player 1 -> strength" << m_strengthPoints;
QSettings settings;
settings.beginGroup("player");
settings.setValue("strength", m_strengthPoints);
settings.endGroup();
m_changed = true;
emit settingsChanged();
}
void PlayerSettings::increaseStrengthPoints()
{
if (m_tunePoints > 0 && m_strengthPoints < 8) {
setTunePoints(m_tunePoints - 1);
setStrengthPoints(m_strengthPoints + 1);
}
}
int PlayerSettings::defensePoints() const
{
return m_defensePoints;
}
void PlayerSettings::setDefensePoints(const int &defensePoints)
{
m_defensePoints = defensePoints;
emit defensePointsChanged();
qDebug() << "Player 1 -> defense" << m_defensePoints;
QSettings settings;
settings.beginGroup("player");
settings.setValue("defense", m_defensePoints);
settings.endGroup();
m_changed = true;
emit settingsChanged();
}
void PlayerSettings::increaseDefensePoints()
{
if (m_tunePoints > 0 && m_defensePoints < 8) {
setTunePoints(m_tunePoints - 1);
setDefensePoints(m_defensePoints + 1);
}
}
int PlayerSettings::reproductionPoints() const
{
return m_reproductionPoints;
}
void PlayerSettings::setReproductionPoints(const int &reproductionPoints)
{
m_reproductionPoints = reproductionPoints;
emit reproductionPointsChanged();
qDebug() << "Player 1 -> reproduction" << m_reproductionPoints;
QSettings settings;
settings.beginGroup("player");
settings.setValue("reproduction", m_reproductionPoints);
settings.endGroup();
m_changed = true;
emit settingsChanged();
}
void PlayerSettings::increaseReproductionPoints()
{
if (m_tunePoints > 0 && m_reproductionPoints < 8) {
setTunePoints(m_tunePoints - 1);
setReproductionPoints(m_reproductionPoints + 1);
}
}
int PlayerSettings::speedPoints() const
{
return m_speedPoints;
}
void PlayerSettings::setSpeedPoints(const int &speedPoints)
{
m_speedPoints = speedPoints;
emit speedPointsChanged();
qDebug() << "Player 1 -> speed" << m_speedPoints;
QSettings settings;
settings.beginGroup("player");
settings.setValue("speed", m_speedPoints);
settings.endGroup();
m_changed = true;
emit settingsChanged();
}
void PlayerSettings::increaseSpeedPoints()
{
if (m_tunePoints > 0 && m_speedPoints < 8) {
setTunePoints(m_tunePoints - 1);
setSpeedPoints(m_speedPoints + 1);
}
}
void PlayerSettings::resetSettings()
{
qDebug() << "Reset player settings...";
setTunePoints(0);
setSpeedPoints(0);
setStrengthPoints(0);
setDefensePoints(0);
setReproductionPoints(0);
store();
}
void PlayerSettings::store()
{
qDebug() << "Store settings...";
m_tunePointsStored = m_tunePoints;
m_strengthPointsStored = m_strengthPoints;
m_defensePointsStored = m_defensePoints;
m_reproductionPointsStored = m_reproductionPoints;
m_speedPointsStored = m_speedPoints;
emit settingsStored();
m_changed = false;
emit settingsChanged();
}
void PlayerSettings::restore()
{
qDebug() << "Restore settings...";
setTunePoints(m_tunePointsStored);
setStrengthPoints(m_strengthPointsStored);
setDefensePoints(m_defensePointsStored);
setReproductionPoints(m_reproductionPointsStored);
setSpeedPoints(m_speedPointsStored);
m_changed = false;
emit settingsChanged();
}