184
|
1 |
/*
|
|
2 |
* Hedgewars, a worms-like game
|
|
3 |
* Copyright (c) 2006 Andrey Korotaev <unC0Rr@gmail.com>
|
|
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>
|
|
20 |
#include <QTextStream>
|
|
21 |
#include "gameuiconfig.h"
|
|
22 |
#include "hwform.h"
|
|
23 |
#include "pages.h"
|
|
24 |
#include "hwconsts.h"
|
297
|
25 |
#include "fpsedit.h"
|
184
|
26 |
|
301
|
27 |
GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName)
|
|
28 |
: QSettings(fileName, QSettings::IniFormat)
|
184
|
29 |
{
|
|
30 |
Form = FormWidgets;
|
|
31 |
|
301
|
32 |
Form->ui.pageOptions->CBResolution->setCurrentIndex(value("video/resolution").toUInt());
|
|
33 |
Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool());
|
|
34 |
|
|
35 |
Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool());
|
184
|
36 |
|
301
|
37 |
Form->ui.pageNet->editNetNick->setText(value("net/nick", QLineEdit::tr("unnamed")).toString());
|
|
38 |
Form->ui.pageNet->editIP->setText(value("net/ip", "").toString());
|
|
39 |
Form->ui.pageOptions->CBShowFPS->setChecked(value("fps/show", false).toBool());
|
|
40 |
Form->ui.pageOptions->fpsedit->setValue(value("fps/interval", 27).toUInt());
|
184
|
41 |
|
|
42 |
QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
|
|
43 |
if (themesfile.open(QIODevice::ReadOnly)) {
|
|
44 |
QTextStream stream(&themesfile);
|
|
45 |
QString str;
|
|
46 |
while (!stream.atEnd())
|
|
47 |
{
|
|
48 |
Themes << stream.readLine();
|
|
49 |
}
|
|
50 |
themesfile.close();
|
|
51 |
} else {
|
301
|
52 |
QMessageBox::critical(FormWidgets, "Error", "Cannot access themes.cfg", "OK");
|
184
|
53 |
}
|
|
54 |
}
|
|
55 |
|
|
56 |
QStringList GameUIConfig::GetTeamsList()
|
|
57 |
{
|
|
58 |
QStringList teamslist = cfgdir->entryList(QStringList("*.cfg"));
|
|
59 |
QStringList cleanedList;
|
|
60 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
|
|
61 |
QString tmpTeamStr=(*it).replace(QRegExp("^(.*).cfg$"), "\\1");
|
|
62 |
cleanedList.push_back(tmpTeamStr);
|
|
63 |
}
|
|
64 |
return cleanedList;
|
|
65 |
}
|
|
66 |
|
|
67 |
void GameUIConfig::SaveOptions()
|
|
68 |
{
|
301
|
69 |
setValue("video/resolution", vid_Resolution());
|
|
70 |
setValue("video/fullscreen", vid_Fullscreen());
|
|
71 |
|
|
72 |
setValue("audio/sound", isSoundEnabled());
|
|
73 |
|
|
74 |
setValue("net/nick", Form->ui.pageNet->editNetNick->text());
|
|
75 |
setValue("net/ip", Form->ui.pageNet->editIP->text());
|
|
76 |
|
|
77 |
setValue("fps/show", isShowFPSEnabled());
|
|
78 |
setValue("fps/interval", Form->ui.pageOptions->fpsedit->value());
|
184
|
79 |
}
|
|
80 |
|
|
81 |
int GameUIConfig::vid_Resolution()
|
|
82 |
{
|
|
83 |
return Form->ui.pageOptions->CBResolution->currentIndex();
|
|
84 |
}
|
|
85 |
|
|
86 |
bool GameUIConfig::vid_Fullscreen()
|
|
87 |
{
|
|
88 |
return Form->ui.pageOptions->CBFullscreen->isChecked();
|
|
89 |
}
|
|
90 |
|
|
91 |
bool GameUIConfig::isSoundEnabled()
|
|
92 |
{
|
|
93 |
return Form->ui.pageOptions->CBEnableSound->isChecked();
|
|
94 |
}
|
|
95 |
|
297
|
96 |
bool GameUIConfig::isShowFPSEnabled()
|
|
97 |
{
|
|
98 |
return Form->ui.pageOptions->CBShowFPS->isChecked();
|
|
99 |
}
|
|
100 |
|
|
101 |
quint8 GameUIConfig::timerInterval()
|
|
102 |
{
|
|
103 |
return 35 - Form->ui.pageOptions->fpsedit->value();
|
|
104 |
}
|
|
105 |
|
184
|
106 |
QString GameUIConfig::GetRandomTheme()
|
|
107 |
{
|
|
108 |
return (Themes.size() > 0) ? Themes[rand() % Themes.size()] : QString("steel");
|
|
109 |
}
|