184
|
1 |
/*
|
|
2 |
* Hedgewars, a worms-like game
|
486
|
3 |
* Copyright (c) 2006, 2007 Andrey Korotaev <unC0Rr@gmail.com>
|
184
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; version 2 of the License
|
|
8 |
*
|
|
9 |
* This program 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
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include <QMessageBox>
|
471
|
20 |
#include <QCheckBox>
|
|
21 |
#include <QLineEdit>
|
603
|
22 |
#include <QDesktopWidget>
|
471
|
23 |
|
184
|
24 |
#include "gameuiconfig.h"
|
|
25 |
#include "hwform.h"
|
|
26 |
#include "pages.h"
|
|
27 |
#include "hwconsts.h"
|
297
|
28 |
#include "fpsedit.h"
|
184
|
29 |
|
301
|
30 |
GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName)
|
|
31 |
: QSettings(fileName, QSettings::IniFormat)
|
184
|
32 |
{
|
|
33 |
Form = FormWidgets;
|
|
34 |
|
555
|
35 |
int t = Form->ui.pageOptions->CBResolution->findText(value("video/resolution").toString());
|
|
36 |
Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 0 : t);
|
301
|
37 |
Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool());
|
|
38 |
|
|
39 |
Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool());
|
184
|
40 |
|
301
|
41 |
Form->ui.pageNet->editNetNick->setText(value("net/nick", QLineEdit::tr("unnamed")).toString());
|
|
42 |
Form->ui.pageNet->editIP->setText(value("net/ip", "").toString());
|
529
|
43 |
|
301
|
44 |
Form->ui.pageOptions->CBShowFPS->setChecked(value("fps/show", false).toBool());
|
|
45 |
Form->ui.pageOptions->fpsedit->setValue(value("fps/interval", 27).toUInt());
|
529
|
46 |
|
578
|
47 |
Form->ui.pageOptions->CBAltDamage->setChecked(value("misc/altdamage", false).toBool());
|
603
|
48 |
|
|
49 |
QDesktopWidget desktop;
|
|
50 |
depth = desktop.depth();
|
|
51 |
if (depth < 16) depth = 16;
|
|
52 |
else if (depth > 16) depth = 32;
|
184
|
53 |
}
|
|
54 |
|
|
55 |
QStringList GameUIConfig::GetTeamsList()
|
|
56 |
{
|
|
57 |
QStringList teamslist = cfgdir->entryList(QStringList("*.cfg"));
|
|
58 |
QStringList cleanedList;
|
|
59 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
|
603
|
60 |
QString tmpTeamStr=(*it).replace(QRegExp("^(.*)\\.cfg$"), "\\1");
|
184
|
61 |
cleanedList.push_back(tmpTeamStr);
|
|
62 |
}
|
|
63 |
return cleanedList;
|
|
64 |
}
|
|
65 |
|
|
66 |
void GameUIConfig::SaveOptions()
|
|
67 |
{
|
555
|
68 |
setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText());
|
301
|
69 |
setValue("video/fullscreen", vid_Fullscreen());
|
|
70 |
|
|
71 |
setValue("audio/sound", isSoundEnabled());
|
|
72 |
|
|
73 |
setValue("net/nick", Form->ui.pageNet->editNetNick->text());
|
|
74 |
setValue("net/ip", Form->ui.pageNet->editIP->text());
|
|
75 |
|
|
76 |
setValue("fps/show", isShowFPSEnabled());
|
|
77 |
setValue("fps/interval", Form->ui.pageOptions->fpsedit->value());
|
529
|
78 |
|
|
79 |
setValue("misc/altdamage", isAltDamageEnabled());
|
184
|
80 |
}
|
|
81 |
|
555
|
82 |
QRect GameUIConfig::vid_Resolution()
|
184
|
83 |
{
|
555
|
84 |
QRect result(0, 0, 640, 480);
|
|
85 |
QStringList wh = Form->ui.pageOptions->CBResolution->currentText().split('x');
|
|
86 |
if (wh.size() == 2)
|
|
87 |
{
|
|
88 |
result.setWidth(wh[0].toInt());
|
|
89 |
result.setHeight(wh[1].toInt());
|
|
90 |
}
|
|
91 |
return result;
|
184
|
92 |
}
|
|
93 |
|
|
94 |
bool GameUIConfig::vid_Fullscreen()
|
|
95 |
{
|
|
96 |
return Form->ui.pageOptions->CBFullscreen->isChecked();
|
|
97 |
}
|
|
98 |
|
|
99 |
bool GameUIConfig::isSoundEnabled()
|
|
100 |
{
|
|
101 |
return Form->ui.pageOptions->CBEnableSound->isChecked();
|
|
102 |
}
|
|
103 |
|
297
|
104 |
bool GameUIConfig::isShowFPSEnabled()
|
|
105 |
{
|
|
106 |
return Form->ui.pageOptions->CBShowFPS->isChecked();
|
|
107 |
}
|
|
108 |
|
529
|
109 |
bool GameUIConfig::isAltDamageEnabled()
|
|
110 |
{
|
|
111 |
return Form->ui.pageOptions->CBAltDamage->isChecked();;
|
|
112 |
}
|
|
113 |
|
297
|
114 |
quint8 GameUIConfig::timerInterval()
|
|
115 |
{
|
|
116 |
return 35 - Form->ui.pageOptions->fpsedit->value();
|
|
117 |
}
|
603
|
118 |
|
|
119 |
quint8 GameUIConfig::bitDepth()
|
|
120 |
{
|
|
121 |
return depth;
|
|
122 |
}
|