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 |
|
647
|
41 |
Form->ui.pageOptions->editNetNick->setText(value("net/nick", QLineEdit::tr("unnamed")).toString());
|
654
|
42 |
|
|
43 |
delete netHost;
|
|
44 |
netHost = new QString(value("net/ip", "").toString());
|
|
45 |
netPort = value("net/port", 46631).toUInt();
|
529
|
46 |
|
301
|
47 |
Form->ui.pageOptions->CBShowFPS->setChecked(value("fps/show", false).toBool());
|
|
48 |
Form->ui.pageOptions->fpsedit->setValue(value("fps/interval", 27).toUInt());
|
529
|
49 |
|
578
|
50 |
Form->ui.pageOptions->CBAltDamage->setChecked(value("misc/altdamage", false).toBool());
|
603
|
51 |
|
|
52 |
QDesktopWidget desktop;
|
|
53 |
depth = desktop.depth();
|
|
54 |
if (depth < 16) depth = 16;
|
|
55 |
else if (depth > 16) depth = 32;
|
184
|
56 |
}
|
|
57 |
|
|
58 |
QStringList GameUIConfig::GetTeamsList()
|
|
59 |
{
|
|
60 |
QStringList teamslist = cfgdir->entryList(QStringList("*.cfg"));
|
|
61 |
QStringList cleanedList;
|
|
62 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
|
603
|
63 |
QString tmpTeamStr=(*it).replace(QRegExp("^(.*)\\.cfg$"), "\\1");
|
184
|
64 |
cleanedList.push_back(tmpTeamStr);
|
|
65 |
}
|
|
66 |
return cleanedList;
|
|
67 |
}
|
|
68 |
|
|
69 |
void GameUIConfig::SaveOptions()
|
|
70 |
{
|
555
|
71 |
setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText());
|
301
|
72 |
setValue("video/fullscreen", vid_Fullscreen());
|
|
73 |
|
|
74 |
setValue("audio/sound", isSoundEnabled());
|
|
75 |
|
647
|
76 |
setValue("net/nick", Form->ui.pageOptions->editNetNick->text());
|
654
|
77 |
setValue("net/ip", *netHost);
|
|
78 |
setValue("net/port", netPort);
|
301
|
79 |
|
|
80 |
setValue("fps/show", isShowFPSEnabled());
|
|
81 |
setValue("fps/interval", Form->ui.pageOptions->fpsedit->value());
|
529
|
82 |
|
|
83 |
setValue("misc/altdamage", isAltDamageEnabled());
|
184
|
84 |
}
|
|
85 |
|
555
|
86 |
QRect GameUIConfig::vid_Resolution()
|
184
|
87 |
{
|
555
|
88 |
QRect result(0, 0, 640, 480);
|
|
89 |
QStringList wh = Form->ui.pageOptions->CBResolution->currentText().split('x');
|
|
90 |
if (wh.size() == 2)
|
|
91 |
{
|
|
92 |
result.setWidth(wh[0].toInt());
|
|
93 |
result.setHeight(wh[1].toInt());
|
|
94 |
}
|
|
95 |
return result;
|
184
|
96 |
}
|
|
97 |
|
|
98 |
bool GameUIConfig::vid_Fullscreen()
|
|
99 |
{
|
|
100 |
return Form->ui.pageOptions->CBFullscreen->isChecked();
|
|
101 |
}
|
|
102 |
|
|
103 |
bool GameUIConfig::isSoundEnabled()
|
|
104 |
{
|
|
105 |
return Form->ui.pageOptions->CBEnableSound->isChecked();
|
|
106 |
}
|
|
107 |
|
297
|
108 |
bool GameUIConfig::isShowFPSEnabled()
|
|
109 |
{
|
|
110 |
return Form->ui.pageOptions->CBShowFPS->isChecked();
|
|
111 |
}
|
|
112 |
|
529
|
113 |
bool GameUIConfig::isAltDamageEnabled()
|
|
114 |
{
|
|
115 |
return Form->ui.pageOptions->CBAltDamage->isChecked();;
|
|
116 |
}
|
|
117 |
|
297
|
118 |
quint8 GameUIConfig::timerInterval()
|
|
119 |
{
|
|
120 |
return 35 - Form->ui.pageOptions->fpsedit->value();
|
|
121 |
}
|
603
|
122 |
|
|
123 |
quint8 GameUIConfig::bitDepth()
|
|
124 |
{
|
|
125 |
return depth;
|
|
126 |
}
|