QTfrontend/hwform.cpp
author unc0rr
Sun, 13 Nov 2005 22:13:58 +0000
changeset 21 dff476dcaaa3
parent 20 ccd2c45f043d
child 25 27aa8030322b
permissions -rw-r--r--
- Many improvements to frontend - Small optimization of generating random data in uRandom.pas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
     1
/*
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
     4
 *
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
     5
 * Distributed under the terms of the BSD-modified licence:
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
     6
 *
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
     7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
     8
 * of this software and associated documentation files (the "Software"), to deal
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
     9
 * with the Software without restriction, including without limitation the
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    11
 * sell copies of the Software, and to permit persons to whom the Software is
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    12
 * furnished to do so, subject to the following conditions:
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    13
 *
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    14
 * 1. Redistributions of source code must retain the above copyright notice,
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    15
 *    this list of conditions and the following disclaimer.
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    16
 * 2. Redistributions in binary form must reproduce the above copyright notice,
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    17
 *    this list of conditions and the following disclaimer in the documentation
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    18
 *    and/or other materials provided with the distribution.
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    19
 * 3. The name of the author may not be used to endorse or promote products
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    20
 *    derived from this software without specific prior written permission.
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    21
 *
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    22
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    23
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    24
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    25
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    31
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    32
 */
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    33
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    34
#include <QtGui>
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    35
#include <QStringList>
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    36
#include <QProcess>
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    37
#include <QDir>
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    38
#include <QPixmap>
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    39
#include <QRegExp>
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    40
#include <QIcon>
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    41
#include <QFile>
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    42
#include <QTextStream>
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    43
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    44
#include "hwform.h"
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    45
#include "sdlkeys.h"
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    46
#include "hwconsts.h"
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    47
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    48
HWForm::HWForm(QWidget *parent)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    49
	: QMainWindow(parent)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    50
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    51
	ui.setupUi(this);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    52
	TeamNameEdit = new QLineEdit(ui.GBoxTeam);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    53
	TeamNameEdit->setGeometry(QRect(10, 20, 141, 20));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    54
	TeamNameEdit->setMaxLength(15);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    55
	for(int i = 0; i < 8; i++)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    56
	{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    57
		HHNameEdit[i] = new QLineEdit(ui.GBoxHedgehogs);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    58
		HHNameEdit[i]->setGeometry(QRect(10, 20 + i * 30, 141, 20));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    59
		HHNameEdit[i]->setMaxLength(15);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    60
	}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    61
	
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    62
	QStringList binds;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    63
	for(int i = 0; strlen(sdlkeys[i][1]) > 0; i++)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    64
	{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    65
		binds << sdlkeys[i][1];
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    66
	}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    67
	
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    68
	for(int i = 0; i < BINDS_NUMBER; i++)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    69
	{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    70
		LBind[i] = new QLabel(ui.GBoxBinds);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    71
		LBind[i]->setGeometry(QRect(10, 23 + i * 30, 60, 20));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    72
		LBind[i]->setText(cbinds[i].name);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    73
		LBind[i]->setAlignment(Qt::AlignRight);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    74
		CBBind[i] = new QComboBox(ui.GBoxBinds);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    75
		CBBind[i]->setGeometry(QRect(80, 20 + i * 30, 80, 20));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    76
		CBBind[i]->addItems(binds);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    77
	}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    78
	
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    79
	QDir tmpdir;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    80
	tmpdir.cd(DATA_PATH);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    81
	tmpdir.cd("Forts");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    82
	tmpdir.setFilter(QDir::Files);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    83
	
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    84
	ui.CBFort->addItems(tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L.png"), "\\1"));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    85
	
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    86
	tmpdir.cd("../Graphics/Graves");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    87
	QStringList list = tmpdir.entryList(QStringList("*.png"));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    88
	for (QStringList::Iterator it = list.begin(); it != list.end(); ++it )
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    89
	{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    90
		ui.CBGrave->addItem((*it).replace(QRegExp("^(.*).png"), "\\1"));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    91
	}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    92
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    93
	cfgdir.setPath(cfgdir.homePath());
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    94
	if (!cfgdir.exists(".hedgewars"))
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    95
	{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    96
		if (!cfgdir.mkdir(".hedgewars"))
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    97
		{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    98
			QMessageBox::critical(this, 
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    99
					tr("Error"),
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   100
					tr("Cannot create directory %s").arg("/.hedgewars"),
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   101
					tr("Quit"));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   102
		}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   103
		return ;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   104
	}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   105
	cfgdir.cd(".hedgewars");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   106
	
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   107
	list = cfgdir.entryList(QStringList("*.cfg"));
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   108
	for (QStringList::Iterator it = list.begin(); it != list.end(); ++it )
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   109
	{
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   110
		ui.CBTeamName->addItem((*it).replace(QRegExp("^(.*).cfg"), "\\1"));
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   111
	}
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   112
	
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   113
	
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   114
	QFile settings(cfgdir.absolutePath() + "/options");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   115
	if (!settings.open(QIODevice::ReadOnly))
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   116
	{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   117
		return ;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   118
	}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   119
	QTextStream stream(&settings);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   120
	stream.setCodec("UTF-8");	
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   121
	QString str;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   122
	
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   123
	while (!stream.atEnd())
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   124
	{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   125
		str = stream.readLine();
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   126
		if (str.startsWith(";")) continue;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   127
		if (str.startsWith("resolution "))
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   128
		{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   129
			str.remove(0, 11);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   130
			ui.CBResolution->setCurrentIndex(str.toLong());
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   131
		} else
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   132
		if (str.startsWith("fullscreen "))
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   133
		{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   134
			str.remove(0, 11);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   135
			ui.CBFullscreen->setChecked(str.toLong());
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   136
		}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   137
	}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   138
	settings.close();
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   139
	connect(ui.BtnSPBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   140
	connect(ui.BtnSetupBack, SIGNAL(clicked()), this, SLOT(GoToMain()));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   141
	connect(ui.BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer()));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   142
	connect(ui.BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup()));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   143
	connect(ui.BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam()));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   144
	connect(ui.BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam()));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   145
	connect(ui.BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave()));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   146
	connect(ui.BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard()));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   147
	connect(ui.BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame()));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   148
	connect(ui.BtnSaveOptions, SIGNAL(clicked()), this, SLOT(SaveOptions()));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   149
	connect(ui.CBGrave, SIGNAL(activated(const QString &)), this, SLOT(CBGrave_activated(const QString &)));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   150
	connect(ui.CBFort, SIGNAL(activated(const QString &)), this, SLOT(CBFort_activated(const QString &)));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   151
	ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   152
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   153
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   154
void HWForm::GoToMain()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   155
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   156
	ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   157
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   158
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   159
void HWForm::GoToSinglePlayer()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   160
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   161
	ui.Pages->setCurrentIndex(ID_PAGE_SINGLEPLAYER);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   162
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   163
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   164
void HWForm::GoToSetup()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   165
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   166
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   167
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   168
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   169
void HWForm::NewTeam()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   170
{
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   171
	tmpTeam = new HWTeam();
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   172
	tmpTeam->SetCfgDir(cfgdir.absolutePath());
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   173
	tmpTeam->SetToPage(this);
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   174
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   175
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   176
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   177
void HWForm::EditTeam()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   178
{
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   179
	tmpTeam = new HWTeam();
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   180
	tmpTeam->SetCfgDir(cfgdir.absolutePath());
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   181
	tmpTeam->LoadFromFile();
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   182
	tmpTeam->SetToPage(this);
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   183
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   184
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   185
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   186
void HWForm::TeamSave()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   187
{
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   188
	tmpTeam = new HWTeam();
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   189
	tmpTeam->GetFromPage(this);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   190
	tmpTeam->SaveToFile();
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   191
	delete tmpTeam;
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   192
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   193
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   194
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   195
void HWForm::TeamDiscard()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   196
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   197
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   198
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   199
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   200
void HWForm::SimpleGame()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   201
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   202
	game = new HWGame();
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   203
	game->AddTeam(cfgdir.absolutePath() + "/team.cfg");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   204
	game->AddTeam(cfgdir.absolutePath() + "/team.cfg");
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   205
	game->Start(ui.CBResolution->currentIndex(), ui.CBFullscreen->isChecked());
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   206
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   207
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   208
void HWForm::CBGrave_activated(const QString & gravename)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   209
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   210
	QPixmap pix(QString(DATA_PATH) + "/Graphics/Graves/" + gravename + ".png");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   211
	ui.GravePreview->setPixmap(pix.copy(0, 0, 32, 32));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   212
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   213
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   214
void HWForm::CBFort_activated(const QString & fortname)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   215
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   216
	QPixmap pix(QString(DATA_PATH) + "/Forts/" + fortname + "L.png");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   217
	ui.FortPreview->setPixmap(pix);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   218
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   219
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   220
void HWForm::SaveOptions()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   221
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   222
	QFile settings(cfgdir.absolutePath() + "/options");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   223
	if (!settings.open(QIODevice::WriteOnly))
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   224
	{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   225
		QMessageBox::critical(this, 
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   226
				tr("Error"),
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   227
				tr("Cannot save options to file %s").arg(settings.fileName()),
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   228
				tr("Quit"));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   229
		return ;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   230
	}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   231
	QTextStream stream(&settings);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   232
	stream.setCodec("UTF-8");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   233
	stream << "; Generated by Hedgewars, do not modify" << endl;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   234
	stream << "resolution " << ui.CBResolution->currentIndex() << endl;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   235
	stream << "fullscreen " << ui.CBFullscreen->isChecked() << endl;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   236
	settings.close();
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   237
}