author | unc0rr |
Thu, 13 Dec 2007 23:07:16 +0000 | |
changeset 657 | b34fc518a48a |
parent 654 | 1019b8fa8638 |
child 674 | a15c8e3c69b3 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
486 | 3 |
* Copyright (c) 2006, 2007 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> |
471 | 23 |
|
184 | 24 |
#include "gameuiconfig.h" |
25 |
#include "hwform.h" |
|
26 |
#include "pages.h" |
|
27 |
#include "hwconsts.h" |
|
297 | 28 |
#include "fpsedit.h" |
184 | 29 |
|
301 | 30 |
GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName) |
31 |
: QSettings(fileName, QSettings::IniFormat) |
|
184 | 32 |
{ |
33 |
Form = FormWidgets; |
|
34 |
||
555 | 35 |
int t = Form->ui.pageOptions->CBResolution->findText(value("video/resolution").toString()); |
36 |
Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 0 : t); |
|
301 | 37 |
Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool()); |
38 |
||
39 |
Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool()); |
|
184 | 40 |
|
647 | 41 |
Form->ui.pageOptions->editNetNick->setText(value("net/nick", QLineEdit::tr("unnamed")).toString()); |
654 | 42 |
|
43 |
delete netHost; |
|
44 |
netHost = new QString(value("net/ip", "").toString()); |
|
45 |
netPort = value("net/port", 46631).toUInt(); |
|
529 | 46 |
|
657
b34fc518a48a
Basic concept for net server options page (subject to change)
unc0rr
parents:
654
diff
changeset
|
47 |
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
|
48 |
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
|
49 |
|
301 | 50 |
Form->ui.pageOptions->CBShowFPS->setChecked(value("fps/show", false).toBool()); |
51 |
Form->ui.pageOptions->fpsedit->setValue(value("fps/interval", 27).toUInt()); |
|
529 | 52 |
|
578 | 53 |
Form->ui.pageOptions->CBAltDamage->setChecked(value("misc/altdamage", false).toBool()); |
603 | 54 |
|
55 |
QDesktopWidget desktop; |
|
56 |
depth = desktop.depth(); |
|
57 |
if (depth < 16) depth = 16; |
|
58 |
else if (depth > 16) depth = 32; |
|
184 | 59 |
} |
60 |
||
61 |
QStringList GameUIConfig::GetTeamsList() |
|
62 |
{ |
|
63 |
QStringList teamslist = cfgdir->entryList(QStringList("*.cfg")); |
|
64 |
QStringList cleanedList; |
|
65 |
for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
|
603 | 66 |
QString tmpTeamStr=(*it).replace(QRegExp("^(.*)\\.cfg$"), "\\1"); |
184 | 67 |
cleanedList.push_back(tmpTeamStr); |
68 |
} |
|
69 |
return cleanedList; |
|
70 |
} |
|
71 |
||
72 |
void GameUIConfig::SaveOptions() |
|
73 |
{ |
|
555 | 74 |
setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText()); |
301 | 75 |
setValue("video/fullscreen", vid_Fullscreen()); |
76 |
||
77 |
setValue("audio/sound", isSoundEnabled()); |
|
78 |
||
647 | 79 |
setValue("net/nick", Form->ui.pageOptions->editNetNick->text()); |
654 | 80 |
setValue("net/ip", *netHost); |
81 |
setValue("net/port", netPort); |
|
657
b34fc518a48a
Basic concept for net server options page (subject to change)
unc0rr
parents:
654
diff
changeset
|
82 |
setValue("net/servername", Form->ui.pageNetServer->leServerDescr->text()); |
b34fc518a48a
Basic concept for net server options page (subject to change)
unc0rr
parents:
654
diff
changeset
|
83 |
setValue("net/serverport", Form->ui.pageNetServer->sbPort->value()); |
301 | 84 |
|
85 |
setValue("fps/show", isShowFPSEnabled()); |
|
86 |
setValue("fps/interval", Form->ui.pageOptions->fpsedit->value()); |
|
529 | 87 |
|
88 |
setValue("misc/altdamage", isAltDamageEnabled()); |
|
184 | 89 |
} |
90 |
||
555 | 91 |
QRect GameUIConfig::vid_Resolution() |
184 | 92 |
{ |
555 | 93 |
QRect result(0, 0, 640, 480); |
94 |
QStringList wh = Form->ui.pageOptions->CBResolution->currentText().split('x'); |
|
95 |
if (wh.size() == 2) |
|
96 |
{ |
|
97 |
result.setWidth(wh[0].toInt()); |
|
98 |
result.setHeight(wh[1].toInt()); |
|
99 |
} |
|
100 |
return result; |
|
184 | 101 |
} |
102 |
||
103 |
bool GameUIConfig::vid_Fullscreen() |
|
104 |
{ |
|
105 |
return Form->ui.pageOptions->CBFullscreen->isChecked(); |
|
106 |
} |
|
107 |
||
108 |
bool GameUIConfig::isSoundEnabled() |
|
109 |
{ |
|
110 |
return Form->ui.pageOptions->CBEnableSound->isChecked(); |
|
111 |
} |
|
112 |
||
297 | 113 |
bool GameUIConfig::isShowFPSEnabled() |
114 |
{ |
|
115 |
return Form->ui.pageOptions->CBShowFPS->isChecked(); |
|
116 |
} |
|
117 |
||
529 | 118 |
bool GameUIConfig::isAltDamageEnabled() |
119 |
{ |
|
120 |
return Form->ui.pageOptions->CBAltDamage->isChecked();; |
|
121 |
} |
|
122 |
||
297 | 123 |
quint8 GameUIConfig::timerInterval() |
124 |
{ |
|
125 |
return 35 - Form->ui.pageOptions->fpsedit->value(); |
|
126 |
} |
|
603 | 127 |
|
128 |
quint8 GameUIConfig::bitDepth() |
|
129 |
{ |
|
130 |
return depth; |
|
131 |
} |