author | unc0rr |
Thu, 05 Oct 2006 16:33:18 +0000 | |
changeset 183 | 57c2ef19f719 |
parent 140 | 50ccde437ea1 |
child 184 | f97a7a3dc8f6 |
permissions | -rw-r--r-- |
84 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2006 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
183 | 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 |
|
84 | 8 |
* |
183 | 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. |
|
84 | 13 |
* |
183 | 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 |
|
84 | 17 |
*/ |
18 |
||
19 |
#include <QMessageBox> |
|
20 |
#include <QTextStream> |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
21 |
#include "gameuiconfig.h" |
87 | 22 |
#include "hwform.h" |
23 |
#include "pages.h" |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
87
diff
changeset
|
24 |
#include "hwconsts.h" |
84 | 25 |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
26 |
GameUIConfig::GameUIConfig(HWForm * FormWidgets) |
84 | 27 |
: QObject() |
28 |
{ |
|
29 |
Form = FormWidgets; |
|
30 |
||
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
87
diff
changeset
|
31 |
QFile settings(cfgdir->absolutePath() + "/options"); |
84 | 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 |
{ |
|
87 | 44 |
Form->ui.pageOptions->CBResolution->setCurrentIndex(str.mid(11).toLong()); |
84 | 45 |
} else |
46 |
if (str.startsWith("fullscreen ")) |
|
47 |
{ |
|
87 | 48 |
Form->ui.pageOptions->CBFullscreen->setChecked(str.mid(11).toLong()); |
84 | 49 |
} else |
50 |
if (str.startsWith("sound ")) |
|
51 |
{ |
|
87 | 52 |
Form->ui.pageOptions->CBEnableSound->setChecked(str.mid(6).toLong()); |
84 | 53 |
} else |
54 |
if (str.startsWith("nick ")) |
|
55 |
{ |
|
111
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
56 |
Form->ui.pageNet->editNetNick->setText(str.mid(5)); |
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
57 |
} else |
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
58 |
if (str.startsWith("ip ")) |
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
59 |
{ |
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
60 |
Form->ui.pageNet->editIP->setText(str.mid(3)); |
84 | 61 |
} |
62 |
} |
|
63 |
settings.close(); |
|
64 |
} |
|
127 | 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 |
} |
|
84 | 78 |
} |
79 |
||
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
80 |
QStringList GameUIConfig::GetTeamsList() |
84 | 81 |
{ |
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
82 |
QStringList teamslist = cfgdir->entryList(QStringList("*.cfg")); |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
83 |
QStringList cleanedList; |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
84 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
85 |
QString tmpTeamStr=(*it).replace(QRegExp("^(.*).cfg$"), "\\1"); |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
86 |
cleanedList.push_back(tmpTeamStr); |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
87 |
} |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
88 |
return cleanedList; |
84 | 89 |
} |
90 |
||
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
91 |
void GameUIConfig::SaveOptions() |
84 | 92 |
{ |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
87
diff
changeset
|
93 |
QFile settings(cfgdir->absolutePath() + "/options"); |
84 | 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; |
|
87 | 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; |
|
111
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
108 |
stream << "nick " << Form->ui.pageNet->editNetNick->text() << endl; |
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
109 |
stream << "ip " << Form->ui.pageNet->editIP->text() << endl; |
84 | 110 |
settings.close(); |
111 |
} |
|
112 |
||
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
113 |
int GameUIConfig::vid_Resolution() |
84 | 114 |
{ |
87 | 115 |
return Form->ui.pageOptions->CBResolution->currentIndex(); |
84 | 116 |
} |
117 |
||
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
118 |
bool GameUIConfig::vid_Fullscreen() |
84 | 119 |
{ |
87 | 120 |
return Form->ui.pageOptions->CBFullscreen->isChecked(); |
84 | 121 |
} |
122 |
||
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
123 |
bool GameUIConfig::isSoundEnabled() |
84 | 124 |
{ |
87 | 125 |
return Form->ui.pageOptions->CBEnableSound->isChecked(); |
84 | 126 |
} |
127 | 127 |
|
128 |
QString GameUIConfig::GetRandomTheme() |
|
129 |
{ |
|
130 |
return (Themes.size() > 0) ? Themes[rand() % Themes.size()] : QString("steel"); |
|
131 |
} |