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