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 |
|
|
27 |
GameUIConfig::GameUIConfig(HWForm * FormWidgets)
|
|
28 |
: QObject()
|
|
29 |
{
|
|
30 |
Form = FormWidgets;
|
|
31 |
|
|
32 |
QFile settings(cfgdir->absolutePath() + "/options");
|
|
33 |
if (settings.open(QIODevice::ReadOnly))
|
|
34 |
{
|
|
35 |
QTextStream stream(&settings);
|
|
36 |
stream.setCodec("UTF-8");
|
|
37 |
QString str;
|
|
38 |
|
|
39 |
while (!stream.atEnd())
|
|
40 |
{
|
|
41 |
str = stream.readLine();
|
|
42 |
if (str.startsWith(";")) continue;
|
|
43 |
if (str.startsWith("resolution "))
|
|
44 |
{
|
|
45 |
Form->ui.pageOptions->CBResolution->setCurrentIndex(str.mid(11).toLong());
|
|
46 |
} else
|
|
47 |
if (str.startsWith("fullscreen "))
|
|
48 |
{
|
|
49 |
Form->ui.pageOptions->CBFullscreen->setChecked(str.mid(11).toLong());
|
|
50 |
} else
|
|
51 |
if (str.startsWith("sound "))
|
|
52 |
{
|
|
53 |
Form->ui.pageOptions->CBEnableSound->setChecked(str.mid(6).toLong());
|
|
54 |
} else
|
|
55 |
if (str.startsWith("nick "))
|
|
56 |
{
|
|
57 |
Form->ui.pageNet->editNetNick->setText(str.mid(5));
|
|
58 |
} else
|
|
59 |
if (str.startsWith("ip "))
|
|
60 |
{
|
|
61 |
Form->ui.pageNet->editIP->setText(str.mid(3));
|
297
|
62 |
} else
|
|
63 |
if (str.startsWith("showfps "))
|
|
64 |
{
|
|
65 |
Form->ui.pageOptions->CBShowFPS->setChecked(str.mid(8).toLong());
|
|
66 |
} else
|
|
67 |
if (str.startsWith("interval "))
|
|
68 |
{
|
|
69 |
Form->ui.pageOptions->fpsedit->setValue(str.mid(9).toUInt());
|
184
|
70 |
}
|
|
71 |
}
|
|
72 |
settings.close();
|
|
73 |
}
|
|
74 |
|
|
75 |
QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
|
|
76 |
if (themesfile.open(QIODevice::ReadOnly)) {
|
|
77 |
QTextStream stream(&themesfile);
|
|
78 |
QString str;
|
|
79 |
while (!stream.atEnd())
|
|
80 |
{
|
|
81 |
Themes << stream.readLine();
|
|
82 |
}
|
|
83 |
themesfile.close();
|
|
84 |
} else {
|
|
85 |
QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
|
|
86 |
}
|
|
87 |
}
|
|
88 |
|
|
89 |
QStringList GameUIConfig::GetTeamsList()
|
|
90 |
{
|
|
91 |
QStringList teamslist = cfgdir->entryList(QStringList("*.cfg"));
|
|
92 |
QStringList cleanedList;
|
|
93 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
|
|
94 |
QString tmpTeamStr=(*it).replace(QRegExp("^(.*).cfg$"), "\\1");
|
|
95 |
cleanedList.push_back(tmpTeamStr);
|
|
96 |
}
|
|
97 |
return cleanedList;
|
|
98 |
}
|
|
99 |
|
|
100 |
void GameUIConfig::SaveOptions()
|
|
101 |
{
|
|
102 |
QFile settings(cfgdir->absolutePath() + "/options");
|
|
103 |
if (!settings.open(QIODevice::WriteOnly))
|
|
104 |
{
|
|
105 |
QMessageBox::critical(0,
|
|
106 |
tr("Error"),
|
|
107 |
tr("Cannot save options to file %1").arg(settings.fileName()),
|
|
108 |
tr("Quit"));
|
|
109 |
return ;
|
|
110 |
}
|
|
111 |
QTextStream stream(&settings);
|
|
112 |
stream.setCodec("UTF-8");
|
|
113 |
stream << "; Generated by Hedgewars, do not modify" << endl;
|
297
|
114 |
stream << "resolution " << vid_Resolution() << endl;
|
|
115 |
stream << "fullscreen " << vid_Fullscreen() << endl;
|
|
116 |
stream << "sound " << isSoundEnabled() << endl;
|
184
|
117 |
stream << "nick " << Form->ui.pageNet->editNetNick->text() << endl;
|
|
118 |
stream << "ip " << Form->ui.pageNet->editIP->text() << endl;
|
297
|
119 |
stream << "showfps " << isShowFPSEnabled() << endl;
|
|
120 |
stream << "interval " << Form->ui.pageOptions->fpsedit->value() << endl;
|
184
|
121 |
settings.close();
|
|
122 |
}
|
|
123 |
|
|
124 |
int GameUIConfig::vid_Resolution()
|
|
125 |
{
|
|
126 |
return Form->ui.pageOptions->CBResolution->currentIndex();
|
|
127 |
}
|
|
128 |
|
|
129 |
bool GameUIConfig::vid_Fullscreen()
|
|
130 |
{
|
|
131 |
return Form->ui.pageOptions->CBFullscreen->isChecked();
|
|
132 |
}
|
|
133 |
|
|
134 |
bool GameUIConfig::isSoundEnabled()
|
|
135 |
{
|
|
136 |
return Form->ui.pageOptions->CBEnableSound->isChecked();
|
|
137 |
}
|
|
138 |
|
297
|
139 |
bool GameUIConfig::isShowFPSEnabled()
|
|
140 |
{
|
|
141 |
return Form->ui.pageOptions->CBShowFPS->isChecked();
|
|
142 |
}
|
|
143 |
|
|
144 |
quint8 GameUIConfig::timerInterval()
|
|
145 |
{
|
|
146 |
return 35 - Form->ui.pageOptions->fpsedit->value();
|
|
147 |
}
|
|
148 |
|
184
|
149 |
QString GameUIConfig::GetRandomTheme()
|
|
150 |
{
|
|
151 |
return (Themes.size() > 0) ? Themes[rand() % Themes.size()] : QString("steel");
|
|
152 |
}
|