author | unc0rr |
Fri, 15 Aug 2008 07:54:13 +0000 | |
changeset 1218 | ada50f82ea53 |
parent 1165 | 40eeae82e70b |
child 1223 | 41d7283934c1 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2006-2008 Andrey Korotaev <unC0Rr@gmail.com> |
184 | 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> |
|
471 | 20 |
#include <QCheckBox> |
21 |
#include <QLineEdit> |
|
603 | 22 |
#include <QDesktopWidget> |
674 | 23 |
#include <QApplication> |
471 | 24 |
|
184 | 25 |
#include "gameuiconfig.h" |
26 |
#include "hwform.h" |
|
27 |
#include "pages.h" |
|
28 |
#include "hwconsts.h" |
|
297 | 29 |
#include "fpsedit.h" |
184 | 30 |
|
301 | 31 |
GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName) |
32 |
: QSettings(fileName, QSettings::IniFormat) |
|
184 | 33 |
{ |
34 |
Form = FormWidgets; |
|
35 |
||
1165
40eeae82e70b
correct restoring window size after fullscreen mode
displacer
parents:
1162
diff
changeset
|
36 |
//Form->resize(value("window/width", 640).toUInt(), value("window/height", 450).toUInt()); |
40eeae82e70b
correct restoring window size after fullscreen mode
displacer
parents:
1162
diff
changeset
|
37 |
resizeToConfigValues(); |
674 | 38 |
|
555 | 39 |
int t = Form->ui.pageOptions->CBResolution->findText(value("video/resolution").toString()); |
40 |
Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 0 : t); |
|
301 | 41 |
Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool()); |
1162 | 42 |
bool ffscr=value("video/frontendfullscreen", false).toBool(); |
43 |
Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr); |
|
301 | 44 |
|
45 |
Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool()); |
|
1129 | 46 |
Form->ui.pageOptions->CBEnableMusic->setChecked(value("audio/music", true).toBool()); |
184 | 47 |
|
647 | 48 |
Form->ui.pageOptions->editNetNick->setText(value("net/nick", QLineEdit::tr("unnamed")).toString()); |
654 | 49 |
|
50 |
delete netHost; |
|
51 |
netHost = new QString(value("net/ip", "").toString()); |
|
52 |
netPort = value("net/port", 46631).toUInt(); |
|
529 | 53 |
|
657
b34fc518a48a
Basic concept for net server options page (subject to change)
unc0rr
parents:
654
diff
changeset
|
54 |
Form->ui.pageNetServer->leServerDescr->setText(value("net/servername", "hedgewars server").toString()); |
b34fc518a48a
Basic concept for net server options page (subject to change)
unc0rr
parents:
654
diff
changeset
|
55 |
Form->ui.pageNetServer->sbPort->setValue(value("net/serverport", 46631).toUInt()); |
b34fc518a48a
Basic concept for net server options page (subject to change)
unc0rr
parents:
654
diff
changeset
|
56 |
|
301 | 57 |
Form->ui.pageOptions->CBShowFPS->setChecked(value("fps/show", false).toBool()); |
58 |
Form->ui.pageOptions->fpsedit->setValue(value("fps/interval", 27).toUInt()); |
|
529 | 59 |
|
578 | 60 |
Form->ui.pageOptions->CBAltDamage->setChecked(value("misc/altdamage", false).toBool()); |
603 | 61 |
|
674 | 62 |
depth = QApplication::desktop()->depth(); |
603 | 63 |
if (depth < 16) depth = 16; |
64 |
else if (depth > 16) depth = 32; |
|
184 | 65 |
} |
66 |
||
67 |
QStringList GameUIConfig::GetTeamsList() |
|
68 |
{ |
|
69 |
QStringList teamslist = cfgdir->entryList(QStringList("*.cfg")); |
|
70 |
QStringList cleanedList; |
|
71 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
|
603 | 72 |
QString tmpTeamStr=(*it).replace(QRegExp("^(.*)\\.cfg$"), "\\1"); |
184 | 73 |
cleanedList.push_back(tmpTeamStr); |
74 |
} |
|
75 |
return cleanedList; |
|
76 |
} |
|
77 |
||
1165
40eeae82e70b
correct restoring window size after fullscreen mode
displacer
parents:
1162
diff
changeset
|
78 |
void GameUIConfig::resizeToConfigValues() |
40eeae82e70b
correct restoring window size after fullscreen mode
displacer
parents:
1162
diff
changeset
|
79 |
{ |
40eeae82e70b
correct restoring window size after fullscreen mode
displacer
parents:
1162
diff
changeset
|
80 |
Form->resize(value("window/width", 640).toUInt(), value("window/height", 450).toUInt()); |
40eeae82e70b
correct restoring window size after fullscreen mode
displacer
parents:
1162
diff
changeset
|
81 |
} |
40eeae82e70b
correct restoring window size after fullscreen mode
displacer
parents:
1162
diff
changeset
|
82 |
|
184 | 83 |
void GameUIConfig::SaveOptions() |
84 |
{ |
|
555 | 85 |
setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText()); |
301 | 86 |
setValue("video/fullscreen", vid_Fullscreen()); |
1162 | 87 |
bool ffscr=isFrontendFullscreen(); |
88 |
setValue("video/frontendfullscreen", ffscr); |
|
89 |
emit frontendFullscreen(ffscr); |
|
1165
40eeae82e70b
correct restoring window size after fullscreen mode
displacer
parents:
1162
diff
changeset
|
90 |
if (!ffscr) { |
40eeae82e70b
correct restoring window size after fullscreen mode
displacer
parents:
1162
diff
changeset
|
91 |
setValue("window/width", Form->width()); |
40eeae82e70b
correct restoring window size after fullscreen mode
displacer
parents:
1162
diff
changeset
|
92 |
setValue("window/height", Form->height()); |
40eeae82e70b
correct restoring window size after fullscreen mode
displacer
parents:
1162
diff
changeset
|
93 |
} else { |
40eeae82e70b
correct restoring window size after fullscreen mode
displacer
parents:
1162
diff
changeset
|
94 |
resizeToConfigValues(); |
40eeae82e70b
correct restoring window size after fullscreen mode
displacer
parents:
1162
diff
changeset
|
95 |
} |
301 | 96 |
|
97 |
setValue("audio/sound", isSoundEnabled()); |
|
1129 | 98 |
setValue("audio/music", isMusicEnabled()); |
301 | 99 |
|
949 | 100 |
setValue("net/nick", netNick()); |
654 | 101 |
setValue("net/ip", *netHost); |
102 |
setValue("net/port", netPort); |
|
657
b34fc518a48a
Basic concept for net server options page (subject to change)
unc0rr
parents:
654
diff
changeset
|
103 |
setValue("net/servername", Form->ui.pageNetServer->leServerDescr->text()); |
b34fc518a48a
Basic concept for net server options page (subject to change)
unc0rr
parents:
654
diff
changeset
|
104 |
setValue("net/serverport", Form->ui.pageNetServer->sbPort->value()); |
301 | 105 |
|
106 |
setValue("fps/show", isShowFPSEnabled()); |
|
107 |
setValue("fps/interval", Form->ui.pageOptions->fpsedit->value()); |
|
529 | 108 |
|
109 |
setValue("misc/altdamage", isAltDamageEnabled()); |
|
184 | 110 |
} |
111 |
||
555 | 112 |
QRect GameUIConfig::vid_Resolution() |
184 | 113 |
{ |
555 | 114 |
QRect result(0, 0, 640, 480); |
115 |
QStringList wh = Form->ui.pageOptions->CBResolution->currentText().split('x'); |
|
116 |
if (wh.size() == 2) |
|
117 |
{ |
|
118 |
result.setWidth(wh[0].toInt()); |
|
119 |
result.setHeight(wh[1].toInt()); |
|
120 |
} |
|
121 |
return result; |
|
184 | 122 |
} |
123 |
||
124 |
bool GameUIConfig::vid_Fullscreen() |
|
125 |
{ |
|
126 |
return Form->ui.pageOptions->CBFullscreen->isChecked(); |
|
127 |
} |
|
128 |
||
1162 | 129 |
bool GameUIConfig::isFrontendFullscreen() const |
130 |
{ |
|
131 |
return Form->ui.pageOptions->CBFrontendFullscreen->isChecked(); |
|
132 |
} |
|
133 |
||
184 | 134 |
bool GameUIConfig::isSoundEnabled() |
135 |
{ |
|
136 |
return Form->ui.pageOptions->CBEnableSound->isChecked(); |
|
137 |
} |
|
138 |
||
1129 | 139 |
bool GameUIConfig::isMusicEnabled() |
140 |
{ |
|
141 |
return Form->ui.pageOptions->CBEnableMusic->isChecked(); |
|
142 |
} |
|
143 |
||
297 | 144 |
bool GameUIConfig::isShowFPSEnabled() |
145 |
{ |
|
146 |
return Form->ui.pageOptions->CBShowFPS->isChecked(); |
|
147 |
} |
|
148 |
||
529 | 149 |
bool GameUIConfig::isAltDamageEnabled() |
150 |
{ |
|
151 |
return Form->ui.pageOptions->CBAltDamage->isChecked();; |
|
152 |
} |
|
153 |
||
297 | 154 |
quint8 GameUIConfig::timerInterval() |
155 |
{ |
|
156 |
return 35 - Form->ui.pageOptions->fpsedit->value(); |
|
157 |
} |
|
603 | 158 |
|
159 |
quint8 GameUIConfig::bitDepth() |
|
160 |
{ |
|
161 |
return depth; |
|
162 |
} |
|
949 | 163 |
|
164 |
QString GameUIConfig::netNick() |
|
165 |
{ |
|
166 |
return Form->ui.pageOptions->editNetNick->text(); |
|
167 |
} |