author | unc0rr |
Sun, 27 Jul 2008 23:01:41 +0000 | |
changeset 1132 | b4c0698fbb6b |
parent 1129 | b74ffca22762 |
child 1162 | 91bf5e3e558d |
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 |
||
674 | 36 |
Form->resize(value("window/width", 640).toUInt(), value("window/height", 450).toUInt()); |
37 |
||
555 | 38 |
int t = Form->ui.pageOptions->CBResolution->findText(value("video/resolution").toString()); |
39 |
Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 0 : t); |
|
301 | 40 |
Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool()); |
41 |
||
42 |
Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool()); |
|
1129 | 43 |
Form->ui.pageOptions->CBEnableMusic->setChecked(value("audio/music", true).toBool()); |
184 | 44 |
|
647 | 45 |
Form->ui.pageOptions->editNetNick->setText(value("net/nick", QLineEdit::tr("unnamed")).toString()); |
654 | 46 |
|
47 |
delete netHost; |
|
48 |
netHost = new QString(value("net/ip", "").toString()); |
|
49 |
netPort = value("net/port", 46631).toUInt(); |
|
529 | 50 |
|
657
b34fc518a48a
Basic concept for net server options page (subject to change)
unc0rr
parents:
654
diff
changeset
|
51 |
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
|
52 |
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
|
53 |
|
301 | 54 |
Form->ui.pageOptions->CBShowFPS->setChecked(value("fps/show", false).toBool()); |
55 |
Form->ui.pageOptions->fpsedit->setValue(value("fps/interval", 27).toUInt()); |
|
529 | 56 |
|
578 | 57 |
Form->ui.pageOptions->CBAltDamage->setChecked(value("misc/altdamage", false).toBool()); |
603 | 58 |
|
674 | 59 |
depth = QApplication::desktop()->depth(); |
603 | 60 |
if (depth < 16) depth = 16; |
61 |
else if (depth > 16) depth = 32; |
|
184 | 62 |
} |
63 |
||
64 |
QStringList GameUIConfig::GetTeamsList() |
|
65 |
{ |
|
66 |
QStringList teamslist = cfgdir->entryList(QStringList("*.cfg")); |
|
67 |
QStringList cleanedList; |
|
68 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
|
603 | 69 |
QString tmpTeamStr=(*it).replace(QRegExp("^(.*)\\.cfg$"), "\\1"); |
184 | 70 |
cleanedList.push_back(tmpTeamStr); |
71 |
} |
|
72 |
return cleanedList; |
|
73 |
} |
|
74 |
||
75 |
void GameUIConfig::SaveOptions() |
|
76 |
{ |
|
555 | 77 |
setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText()); |
301 | 78 |
setValue("video/fullscreen", vid_Fullscreen()); |
79 |
||
80 |
setValue("audio/sound", isSoundEnabled()); |
|
1129 | 81 |
setValue("audio/music", isMusicEnabled()); |
301 | 82 |
|
949 | 83 |
setValue("net/nick", netNick()); |
654 | 84 |
setValue("net/ip", *netHost); |
85 |
setValue("net/port", netPort); |
|
657
b34fc518a48a
Basic concept for net server options page (subject to change)
unc0rr
parents:
654
diff
changeset
|
86 |
setValue("net/servername", Form->ui.pageNetServer->leServerDescr->text()); |
b34fc518a48a
Basic concept for net server options page (subject to change)
unc0rr
parents:
654
diff
changeset
|
87 |
setValue("net/serverport", Form->ui.pageNetServer->sbPort->value()); |
301 | 88 |
|
89 |
setValue("fps/show", isShowFPSEnabled()); |
|
90 |
setValue("fps/interval", Form->ui.pageOptions->fpsedit->value()); |
|
529 | 91 |
|
92 |
setValue("misc/altdamage", isAltDamageEnabled()); |
|
674 | 93 |
|
94 |
setValue("window/width", Form->width()); |
|
95 |
setValue("window/height", Form->height()); |
|
184 | 96 |
} |
97 |
||
555 | 98 |
QRect GameUIConfig::vid_Resolution() |
184 | 99 |
{ |
555 | 100 |
QRect result(0, 0, 640, 480); |
101 |
QStringList wh = Form->ui.pageOptions->CBResolution->currentText().split('x'); |
|
102 |
if (wh.size() == 2) |
|
103 |
{ |
|
104 |
result.setWidth(wh[0].toInt()); |
|
105 |
result.setHeight(wh[1].toInt()); |
|
106 |
} |
|
107 |
return result; |
|
184 | 108 |
} |
109 |
||
110 |
bool GameUIConfig::vid_Fullscreen() |
|
111 |
{ |
|
112 |
return Form->ui.pageOptions->CBFullscreen->isChecked(); |
|
113 |
} |
|
114 |
||
115 |
bool GameUIConfig::isSoundEnabled() |
|
116 |
{ |
|
117 |
return Form->ui.pageOptions->CBEnableSound->isChecked(); |
|
118 |
} |
|
119 |
||
1129 | 120 |
bool GameUIConfig::isMusicEnabled() |
121 |
{ |
|
122 |
return Form->ui.pageOptions->CBEnableMusic->isChecked(); |
|
123 |
} |
|
124 |
||
297 | 125 |
bool GameUIConfig::isShowFPSEnabled() |
126 |
{ |
|
127 |
return Form->ui.pageOptions->CBShowFPS->isChecked(); |
|
128 |
} |
|
129 |
||
529 | 130 |
bool GameUIConfig::isAltDamageEnabled() |
131 |
{ |
|
132 |
return Form->ui.pageOptions->CBAltDamage->isChecked();; |
|
133 |
} |
|
134 |
||
297 | 135 |
quint8 GameUIConfig::timerInterval() |
136 |
{ |
|
137 |
return 35 - Form->ui.pageOptions->fpsedit->value(); |
|
138 |
} |
|
603 | 139 |
|
140 |
quint8 GameUIConfig::bitDepth() |
|
141 |
{ |
|
142 |
return depth; |
|
143 |
} |
|
949 | 144 |
|
145 |
QString GameUIConfig::netNick() |
|
146 |
{ |
|
147 |
return Form->ui.pageOptions->editNetNick->text(); |
|
148 |
} |