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