QTfrontend/gameuiconfig.cpp
author unc0rr
Sun, 07 Jan 2007 22:54:08 +0000
changeset 310 b95fd124cb09
parent 301 29bf9c1a3ad3
child 320 1ee7f087195a
permissions -rw-r--r--
Fix for middle column not being growing in width
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     1
/*
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     2
 * Hedgewars, a worms-like game
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     3
 * Copyright (c) 2006 Andrey Korotaev <unC0Rr@gmail.com>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     4
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     8
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    12
 * GNU General Public License for more details.
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    13
 *
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    15
 * along with this program; if not, write to the Free Software
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    17
 */
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    18
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    19
#include <QMessageBox>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    20
#include <QTextStream>
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    21
#include "gameuiconfig.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    22
#include "hwform.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    23
#include "pages.h"
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    24
#include "hwconsts.h"
297
279e10ec31b4 'Show FPS' and 'FPS limit' options
unc0rr
parents: 184
diff changeset
    25
#include "fpsedit.h"
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    26
301
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    27
GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName)
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    28
	: QSettings(fileName, QSettings::IniFormat)
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    29
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    30
	Form = FormWidgets;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    31
301
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    32
	Form->ui.pageOptions->CBResolution->setCurrentIndex(value("video/resolution").toUInt());
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    33
	Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool());
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    34
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    35
	Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool());
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    36
301
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    37
	Form->ui.pageNet->editNetNick->setText(value("net/nick", QLineEdit::tr("unnamed")).toString());
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    38
	Form->ui.pageNet->editIP->setText(value("net/ip", "").toString());
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    39
	Form->ui.pageOptions->CBShowFPS->setChecked(value("fps/show", false).toBool());
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    40
	Form->ui.pageOptions->fpsedit->setValue(value("fps/interval", 27).toUInt());
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    41
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    42
	QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    43
	if (themesfile.open(QIODevice::ReadOnly)) {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    44
		QTextStream stream(&themesfile);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    45
		QString str;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    46
		while (!stream.atEnd())
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    47
		{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    48
			Themes << stream.readLine();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    49
		}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    50
		themesfile.close();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    51
	} else {
301
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    52
		QMessageBox::critical(FormWidgets, "Error", "Cannot access themes.cfg", "OK");
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    53
	}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    54
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    55
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    56
QStringList GameUIConfig::GetTeamsList()
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    57
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    58
	QStringList teamslist = cfgdir->entryList(QStringList("*.cfg"));
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    59
	QStringList cleanedList;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    60
	for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    61
	  QString tmpTeamStr=(*it).replace(QRegExp("^(.*).cfg$"), "\\1");
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    62
	  cleanedList.push_back(tmpTeamStr);
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    63
	}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    64
	return cleanedList;
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    65
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    66
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    67
void GameUIConfig::SaveOptions()
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    68
{
301
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    69
	setValue("video/resolution", vid_Resolution());
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    70
	setValue("video/fullscreen", vid_Fullscreen());
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    71
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    72
	setValue("audio/sound", isSoundEnabled());
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    73
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    74
	setValue("net/nick", Form->ui.pageNet->editNetNick->text());
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    75
	setValue("net/ip", Form->ui.pageNet->editIP->text());
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    76
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    77
	setValue("fps/show", isShowFPSEnabled());
29bf9c1a3ad3 Use QSettings to storing config
unc0rr
parents: 297
diff changeset
    78
	setValue("fps/interval", Form->ui.pageOptions->fpsedit->value());
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    79
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    80
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    81
int GameUIConfig::vid_Resolution()
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    82
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    83
	return Form->ui.pageOptions->CBResolution->currentIndex();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    84
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    85
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    86
bool GameUIConfig::vid_Fullscreen()
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    87
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    88
	return Form->ui.pageOptions->CBFullscreen->isChecked();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    89
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    90
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    91
bool GameUIConfig::isSoundEnabled()
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    92
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    93
	return Form->ui.pageOptions->CBEnableSound->isChecked();
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    94
}
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
    95
297
279e10ec31b4 'Show FPS' and 'FPS limit' options
unc0rr
parents: 184
diff changeset
    96
bool GameUIConfig::isShowFPSEnabled()
279e10ec31b4 'Show FPS' and 'FPS limit' options
unc0rr
parents: 184
diff changeset
    97
{
279e10ec31b4 'Show FPS' and 'FPS limit' options
unc0rr
parents: 184
diff changeset
    98
	return Form->ui.pageOptions->CBShowFPS->isChecked();
279e10ec31b4 'Show FPS' and 'FPS limit' options
unc0rr
parents: 184
diff changeset
    99
}
279e10ec31b4 'Show FPS' and 'FPS limit' options
unc0rr
parents: 184
diff changeset
   100
279e10ec31b4 'Show FPS' and 'FPS limit' options
unc0rr
parents: 184
diff changeset
   101
quint8 GameUIConfig::timerInterval()
279e10ec31b4 'Show FPS' and 'FPS limit' options
unc0rr
parents: 184
diff changeset
   102
{
279e10ec31b4 'Show FPS' and 'FPS limit' options
unc0rr
parents: 184
diff changeset
   103
	return 35 - Form->ui.pageOptions->fpsedit->value();
279e10ec31b4 'Show FPS' and 'FPS limit' options
unc0rr
parents: 184
diff changeset
   104
}
279e10ec31b4 'Show FPS' and 'FPS limit' options
unc0rr
parents: 184
diff changeset
   105
184
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   106
QString GameUIConfig::GetRandomTheme()
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   107
{
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   108
	return (Themes.size() > 0) ? Themes[rand() % Themes.size()] : QString("steel");
f97a7a3dc8f6 - Update more headers
unc0rr
parents: 183
diff changeset
   109
}