2
2
* Hedgewars, a free turn based strategy game
3
* Copyright (c) 2006-2010 Andrey Korotaev <unC0Rr@gmail.com>
3
* Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@gmail.com>
5
5
* This program is free software; you can redistribute it and/or modify
6
6
* it under the terms of the GNU General Public License as published by
20
20
#include <QCheckBox>
21
21
#include <QLineEdit>
22
22
#include <QDesktopWidget>
23
#include <QApplication>
24
23
#include <QInputDialog>
24
#include <QCryptographicHash>
26
26
#include "gameuiconfig.h"
27
27
#include "hwform.h"
28
#include "pageoptions.h"
29
#include "pagenetserver.h"
29
30
#include "hwconsts.h"
30
31
#include "fpsedit.h"
32
#include "HWApplication.h"
32
34
GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName)
33
35
: QSettings(fileName, QSettings::IniFormat)
42
44
Form->ui.pageOptions->WeaponTooltip->setChecked(value("misc/weaponTooltips", true).toBool());
44
46
int t = Form->ui.pageOptions->CBResolution->findText(value("video/resolution").toString());
45
Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 0 : t);
48
if (Form->ui.pageOptions->CBResolution->count() > 1)
49
Form->ui.pageOptions->CBResolution->setCurrentIndex(1);
51
Form->ui.pageOptions->CBResolution->setCurrentIndex(0);
53
else Form->ui.pageOptions->CBResolution->setCurrentIndex(t);
54
Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 1 : t);
46
55
Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool());
47
56
bool ffscr=value("frontend/fullscreen", false).toBool();
48
57
Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr);
50
59
Form->ui.pageOptions->SLQuality->setValue(value("video/quality", 5).toUInt());
60
Form->ui.pageOptions->CBStereoMode->setCurrentIndex(value("video/stereo", 0).toUInt());
51
61
Form->ui.pageOptions->CBFrontendEffects->setChecked(frontendEffects);
52
62
Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool());
53
63
Form->ui.pageOptions->CBEnableFrontendSound->setChecked(value("frontend/sound", true).toBool());
56
66
Form->ui.pageOptions->volumeBox->setValue(value("audio/volume", 100).toUInt());
58
68
QString netNick = value("net/nick", "").toString();
59
if (netNick.isEmpty())
60
netNick = QInputDialog::getText(Form,
61
QObject::tr("Nickname"),
62
QObject::tr("Please enter your nickname"),
64
QDir::home().dirName());
66
69
Form->ui.pageOptions->editNetNick->setText(netNick);
71
Form->ui.pageOptions->editNetPassword->installEventFilter(this);
73
int passLength = value("net/passwordlength", 0).toInt();
74
setNetPasswordLength(passLength);
69
77
netHost = new QString(value("net/ip", "").toString());
85
93
Form->ui.pageOptions->CBLanguage->setCurrentIndex(Form->ui.pageOptions->CBLanguage->findData(value("misc/locale", "").toString()));
87
depth = QApplication::desktop()->depth();
95
depth = HWApplication::desktop()->depth();
88
96
if (depth < 16) depth = 16;
89
97
else if (depth > 16) depth = 32;
95
103
teamdir.cd(cfgdir->absolutePath() + "/Teams");
96
QStringList teamslist = teamdir.entryList(QStringList("*.hwt"));
104
QStringList teamslist = teamdir.entryList(QStringList("*.hwt"),QDir::Files|QDir::Hidden);
97
105
QStringList cleanedList;
98
106
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
99
107
QString tmpTeamStr=(*it).replace(QRegExp("^(.*)\\.hwt$"), "\\1");
113
121
setValue("video/fullscreen", vid_Fullscreen());
115
123
setValue("video/quality", Form->ui.pageOptions->SLQuality->value());
124
setValue("video/stereo", stereoMode());
117
126
setValue("frontend/effects", isFrontendEffects());
135
144
setValue("audio/volume", Form->ui.pageOptions->volumeBox->value());
137
146
setValue("net/nick", netNick());
147
if (netPasswordIsValid())
149
setValue("net/passwordhash", netPasswordHash());
150
setValue("net/passwordlength", netPasswordLength());
138
152
setValue("net/ip", *netHost);
139
153
setValue("net/port", netPort);
140
154
setValue("net/servername", Form->ui.pageNetServer->leServerDescr->text());
143
157
setValue("fps/show", isShowFPSEnabled());
144
158
setValue("fps/limit", Form->ui.pageOptions->fpsedit->value());
146
160
setValue("misc/altdamage", isAltDamageEnabled());
147
161
setValue("misc/appendTimeToRecords", appendDateTimeToRecordName());
148
162
setValue("misc/locale", language());
183
197
quint32 rqNoBackground = 0x00000004; // don't draw background
184
198
quint32 rqSimpleRope = 0x00000008; // avoid drawing rope
185
199
quint32 rq2DWater = 0x00000010; // disabe 3D water effect
186
quint32 rqFancyBoom = 0x00000020; // no fancy explosion effects
200
quint32 rqAntiBoom = 0x00000020; // no fancy explosion effects
187
201
quint32 rqKillFlakes = 0x00000040; // no flakes
188
202
quint32 rqSlowMenu = 0x00000080; // ammomenu appears with no animation
189
203
quint32 rqPlainSplash = 0x00000100; // no droplets
206
220
result |= rqBlurryLand | rqKillFlakes | rqPlainSplash | rq2DWater |
207
rqFancyBoom | rqSlowMenu;
221
rqAntiBoom | rqSlowMenu;
210
224
result |= rqBlurryLand | rqKillFlakes | rqPlainSplash | rq2DWater |
211
rqFancyBoom | rqSlowMenu | rqSimpleRope | rqDesyncVBlank;
225
rqAntiBoom | rqSlowMenu | rqSimpleRope | rqDesyncVBlank;
214
228
result |= rqBlurryLand | rqKillFlakes | rqPlainSplash | rq2DWater |
215
rqFancyBoom | rqSlowMenu | rqSimpleRope | rqDesyncVBlank |
229
rqAntiBoom | rqSlowMenu | rqSimpleRope | rqDesyncVBlank |
216
230
rqNoBackground | rqClampLess;
261
275
return Form->ui.pageOptions->CBAltDamage->isChecked();
278
quint32 GameUIConfig::stereoMode() const
280
return Form->ui.pageOptions->CBStereoMode->currentIndex();
264
283
bool GameUIConfig::appendDateTimeToRecordName()
266
285
return Form->ui.pageOptions->CBNameWithDate->isChecked();
288
307
return Form->ui.pageOptions->editNetNick->text();
310
void GameUIConfig::updNetNick()
312
Form->ui.pageOptions->editNetNick->setText(value("net/nick", "").toString());
315
QByteArray GameUIConfig::netPasswordHash()
317
return QCryptographicHash::hash(Form->ui.pageOptions->editNetPassword->text().toLatin1(), QCryptographicHash::Md5).toHex();
320
int GameUIConfig::netPasswordLength()
322
return Form->ui.pageOptions->editNetPassword->text().size();
325
bool GameUIConfig::netPasswordIsValid()
327
return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '\0'));
330
// When hedgewars launches, the password field is set with null characters. If the user tries to edit the field and there are such characters, then clear the field
331
bool GameUIConfig::eventFilter(QObject *object, QEvent *event)
333
if (event->type() == QEvent::FocusIn)
335
if ((QLineEdit *)object == Form->ui.pageOptions->editNetPassword)
337
if (!netPasswordIsValid())
339
Form->ui.pageOptions->editNetPassword->clear();
344
// Don't filter anything
348
void GameUIConfig::setNetPasswordLength(int passwordLength)
350
if (passwordLength > 0)
352
Form->ui.pageOptions->editNetPassword->setText(QString(passwordLength, '\0'));
356
Form->ui.pageOptions->editNetPassword->setText("");
291
360
quint8 GameUIConfig::volume()
293
362
return Form->ui.pageOptions->volumeBox->value() * 128 / 100;