author | displacer |
Tue, 26 Sep 2006 19:45:47 +0000 | |
changeset 169 | a78d4a552500 |
parent 140 | 50ccde437ea1 |
child 183 | 57c2ef19f719 |
permissions | -rw-r--r-- |
84 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2006 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*/ |
|
33 |
||
34 |
#include <QMessageBox> |
|
35 |
#include <QTextStream> |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
36 |
#include "gameuiconfig.h" |
87 | 37 |
#include "hwform.h" |
38 |
#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
|
39 |
#include "hwconsts.h" |
84 | 40 |
|
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
41 |
GameUIConfig::GameUIConfig(HWForm * FormWidgets) |
84 | 42 |
: QObject() |
43 |
{ |
|
44 |
Form = FormWidgets; |
|
45 |
||
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
87
diff
changeset
|
46 |
QFile settings(cfgdir->absolutePath() + "/options"); |
84 | 47 |
if (settings.open(QIODevice::ReadOnly)) |
48 |
{ |
|
49 |
QTextStream stream(&settings); |
|
50 |
stream.setCodec("UTF-8"); |
|
51 |
QString str; |
|
52 |
||
53 |
while (!stream.atEnd()) |
|
54 |
{ |
|
55 |
str = stream.readLine(); |
|
56 |
if (str.startsWith(";")) continue; |
|
57 |
if (str.startsWith("resolution ")) |
|
58 |
{ |
|
87 | 59 |
Form->ui.pageOptions->CBResolution->setCurrentIndex(str.mid(11).toLong()); |
84 | 60 |
} else |
61 |
if (str.startsWith("fullscreen ")) |
|
62 |
{ |
|
87 | 63 |
Form->ui.pageOptions->CBFullscreen->setChecked(str.mid(11).toLong()); |
84 | 64 |
} else |
65 |
if (str.startsWith("sound ")) |
|
66 |
{ |
|
87 | 67 |
Form->ui.pageOptions->CBEnableSound->setChecked(str.mid(6).toLong()); |
84 | 68 |
} else |
69 |
if (str.startsWith("nick ")) |
|
70 |
{ |
|
111
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
71 |
Form->ui.pageNet->editNetNick->setText(str.mid(5)); |
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
72 |
} else |
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
73 |
if (str.startsWith("ip ")) |
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
74 |
{ |
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
75 |
Form->ui.pageNet->editIP->setText(str.mid(3)); |
84 | 76 |
} |
77 |
} |
|
78 |
settings.close(); |
|
79 |
} |
|
127 | 80 |
|
81 |
QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg"); |
|
82 |
if (themesfile.open(QIODevice::ReadOnly)) { |
|
83 |
QTextStream stream(&themesfile); |
|
84 |
QString str; |
|
85 |
while (!stream.atEnd()) |
|
86 |
{ |
|
87 |
Themes << stream.readLine(); |
|
88 |
} |
|
89 |
themesfile.close(); |
|
90 |
} else { |
|
91 |
QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK"); |
|
92 |
} |
|
84 | 93 |
} |
94 |
||
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
95 |
QStringList GameUIConfig::GetTeamsList() |
84 | 96 |
{ |
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
97 |
QStringList teamslist = cfgdir->entryList(QStringList("*.cfg")); |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
98 |
QStringList cleanedList; |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
99 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
100 |
QString tmpTeamStr=(*it).replace(QRegExp("^(.*).cfg$"), "\\1"); |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
101 |
cleanedList.push_back(tmpTeamStr); |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
102 |
} |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
127
diff
changeset
|
103 |
return cleanedList; |
84 | 104 |
} |
105 |
||
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
106 |
void GameUIConfig::SaveOptions() |
84 | 107 |
{ |
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
87
diff
changeset
|
108 |
QFile settings(cfgdir->absolutePath() + "/options"); |
84 | 109 |
if (!settings.open(QIODevice::WriteOnly)) |
110 |
{ |
|
111 |
QMessageBox::critical(0, |
|
112 |
tr("Error"), |
|
113 |
tr("Cannot save options to file %1").arg(settings.fileName()), |
|
114 |
tr("Quit")); |
|
115 |
return ; |
|
116 |
} |
|
117 |
QTextStream stream(&settings); |
|
118 |
stream.setCodec("UTF-8"); |
|
119 |
stream << "; Generated by Hedgewars, do not modify" << endl; |
|
87 | 120 |
stream << "resolution " << Form->ui.pageOptions->CBResolution->currentIndex() << endl; |
121 |
stream << "fullscreen " << Form->ui.pageOptions->CBFullscreen->isChecked() << endl; |
|
122 |
stream << "sound " << Form->ui.pageOptions->CBEnableSound->isChecked() << endl; |
|
111
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
123 |
stream << "nick " << Form->ui.pageNet->editNetNick->text() << endl; |
30ca06092a64
- 'net nickname' and 'server address' options are on PageNet
unc0rr
parents:
97
diff
changeset
|
124 |
stream << "ip " << Form->ui.pageNet->editIP->text() << endl; |
84 | 125 |
settings.close(); |
126 |
} |
|
127 |
||
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
128 |
int GameUIConfig::vid_Resolution() |
84 | 129 |
{ |
87 | 130 |
return Form->ui.pageOptions->CBResolution->currentIndex(); |
84 | 131 |
} |
132 |
||
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
133 |
bool GameUIConfig::vid_Fullscreen() |
84 | 134 |
{ |
87 | 135 |
return Form->ui.pageOptions->CBFullscreen->isChecked(); |
84 | 136 |
} |
137 |
||
85
44d9045b26ff
New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents:
84
diff
changeset
|
138 |
bool GameUIConfig::isSoundEnabled() |
84 | 139 |
{ |
87 | 140 |
return Form->ui.pageOptions->CBEnableSound->isChecked(); |
84 | 141 |
} |
127 | 142 |
|
143 |
QString GameUIConfig::GetRandomTheme() |
|
144 |
{ |
|
145 |
return (Themes.size() > 0) ? Themes[rand() % Themes.size()] : QString("steel"); |
|
146 |
} |