QTfrontend/hwform.cpp
author unc0rr
Tue, 27 Dec 2005 10:19:21 +0000
changeset 30 794e98e11b66
parent 28 59f7db859b8a
child 31 99888245a4e8
permissions -rw-r--r--
- Fixed slow sprite blt - More and better land templates
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"
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
    47
//#include "gamecmds.h"
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    48
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    49
HWForm::HWForm(QWidget *parent)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    50
	: QMainWindow(parent)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    51
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    52
	ui.setupUi(this);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    53
	TeamNameEdit = new QLineEdit(ui.GBoxTeam);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    54
	TeamNameEdit->setGeometry(QRect(10, 20, 141, 20));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    55
	TeamNameEdit->setMaxLength(15);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    56
	for(int i = 0; i < 8; i++)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    57
	{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    58
		HHNameEdit[i] = new QLineEdit(ui.GBoxHedgehogs);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    59
		HHNameEdit[i]->setGeometry(QRect(10, 20 + i * 30, 141, 20));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    60
		HHNameEdit[i]->setMaxLength(15);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    61
	}
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
    62
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    63
	QStringList binds;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    64
	for(int i = 0; strlen(sdlkeys[i][1]) > 0; i++)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    65
	{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    66
		binds << sdlkeys[i][1];
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    67
	}
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
    68
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    69
	quint16 widind = 0, top = 0;
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    70
	for(quint8 i = 0; i < BINDS_NUMBER; i++)
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    71
	{
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    72
		LBind[i] = new QLabel(ui.BindsBox->widget(widind));
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    73
		LBind[i]->setGeometry(QRect(10, top + 3, 60, 20));
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    74
		LBind[i]->setText(cbinds[i].name);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    75
		LBind[i]->setAlignment(Qt::AlignRight);
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    76
		CBBind[i] = new QComboBox(ui.BindsBox->widget(widind));
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    77
		CBBind[i]->setGeometry(QRect(80, top, 80, 20));
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    78
		CBBind[i]->addItems(binds);
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    79
		if (cbinds[i].chwidget)
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    80
		{
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    81
			top = 0;
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    82
			widind++;
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    83
		} else
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    84
		{
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    85
			top += 30;
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
    86
		}
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    87
	}
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
    88
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    89
	QDir tmpdir;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    90
	tmpdir.cd(DATA_PATH);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    91
	tmpdir.cd("Forts");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    92
	tmpdir.setFilter(QDir::Files);
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
    93
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    94
	ui.CBFort->addItems(tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L.png"), "\\1"));
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
    95
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    96
	tmpdir.cd("../Graphics/Graves");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    97
	QStringList list = tmpdir.entryList(QStringList("*.png"));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    98
	for (QStringList::Iterator it = list.begin(); it != list.end(); ++it )
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    99
	{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   100
		ui.CBGrave->addItem((*it).replace(QRegExp("^(.*).png"), "\\1"));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   101
	}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   102
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   103
	cfgdir.setPath(cfgdir.homePath());
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   104
	if (!cfgdir.exists(".hedgewars"))
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   105
	{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   106
		if (!cfgdir.mkdir(".hedgewars"))
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   107
		{
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   108
			QMessageBox::critical(this,
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   109
					tr("Error"),
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   110
					tr("Cannot create directory %s").arg("/.hedgewars"),
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   111
					tr("Quit"));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   112
		}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   113
		return ;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   114
	}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   115
	cfgdir.cd(".hedgewars");
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   116
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   117
	list = cfgdir.entryList(QStringList("*.cfg"));
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   118
	for (QStringList::Iterator it = list.begin(); it != list.end(); ++it )
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   119
	{
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   120
		ui.CBTeamName->addItem((*it).replace(QRegExp("^(.*).cfg"), "\\1"));
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   121
	}
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   122
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   123
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   124
	QFile settings(cfgdir.absolutePath() + "/options");
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   125
	if (settings.open(QIODevice::ReadOnly))
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   126
	{
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   127
		QTextStream stream(&settings);
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   128
		stream.setCodec("UTF-8");
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   129
		QString str;
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   130
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   131
		while (!stream.atEnd())
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   132
		{
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   133
			str = stream.readLine();
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   134
			if (str.startsWith(";")) continue;
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   135
			if (str.startsWith("resolution "))
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   136
			{
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   137
				str.remove(0, 11);
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   138
				ui.CBResolution->setCurrentIndex(str.toLong());
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   139
			} else
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   140
			if (str.startsWith("fullscreen "))
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   141
			{
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   142
				str.remove(0, 11);
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   143
				ui.CBFullscreen->setChecked(str.toLong());
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   144
			}
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   145
		}
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   146
		settings.close();
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   147
	}
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   148
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   149
	connect(ui.BtnSPBack,	SIGNAL(clicked()),	this, SLOT(GoToMain()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   150
	connect(ui.BtnDemosBack,	SIGNAL(clicked()),	this, SLOT(GoToMain()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   151
	connect(ui.BtnSetupBack,	SIGNAL(clicked()),	this, SLOT(GoToMain()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   152
	connect(ui.BtnMPBack,	SIGNAL(clicked()),	this, SLOT(GoToMain()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   153
	connect(ui.BtnNetBack,	SIGNAL(clicked()),	this, SLOT(GoToMain()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   154
	connect(ui.BtnSinglePlayer,	SIGNAL(clicked()),	this, SLOT(GoToSinglePlayer()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   155
	connect(ui.BtnSetup,	SIGNAL(clicked()),	this, SLOT(GoToSetup()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   156
	connect(ui.BtnMultiplayer,	SIGNAL(clicked()),	this, SLOT(GoToMultiplayer()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   157
	connect(ui.BtnDemos,	SIGNAL(clicked()),	this, SLOT(GoToDemos()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   158
	connect(ui.BtnNet,	SIGNAL(clicked()),	this, SLOT(GoToNet()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   159
	connect(ui.BtnNewTeam,	SIGNAL(clicked()),	this, SLOT(NewTeam()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   160
	connect(ui.BtnEditTeam,	SIGNAL(clicked()),	this, SLOT(EditTeam()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   161
	connect(ui.BtnTeamSave,	SIGNAL(clicked()),	this, SLOT(TeamSave()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   162
	connect(ui.BtnTeamDiscard,	SIGNAL(clicked()),	this, SLOT(TeamDiscard()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   163
	connect(ui.BtnSimpleGame,	SIGNAL(clicked()),	this, SLOT(SimpleGame()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   164
	connect(ui.BtnSaveOptions,	SIGNAL(clicked()),	this, SLOT(SaveOptions()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   165
	connect(ui.BtnPlayDemo,	SIGNAL(clicked()),	this, SLOT(PlayDemo()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   166
	connect(ui.BtnNetConnect,	SIGNAL(clicked()),	this, SLOT(NetConnect()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   167
	connect(ui.BtnNetChatDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   168
	connect(ui.CBGrave,	SIGNAL(activated(const QString &)),	this, SLOT(CBGrave_activated(const QString &)));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   169
	connect(ui.CBFort,	SIGNAL(activated(const QString &)),	this, SLOT(CBFort_activated(const QString &)));
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   170
	ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   171
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   172
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   173
void HWForm::GoToMain()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   174
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   175
	ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   176
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   177
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   178
void HWForm::GoToSinglePlayer()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   179
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   180
	ui.Pages->setCurrentIndex(ID_PAGE_SINGLEPLAYER);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   181
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   182
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   183
void HWForm::GoToSetup()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   184
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   185
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   186
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   187
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   188
void HWForm::GoToMultiplayer()
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   189
{
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   190
	ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER);
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   191
}
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   192
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   193
void HWForm::GoToDemos()
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   194
{
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   195
	QDir tmpdir;
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   196
	tmpdir.cd(DATA_PATH);
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   197
	tmpdir.cd("Demos");
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   198
	tmpdir.setFilter(QDir::Files);
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   199
	ui.DemosList->clear();
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   200
	ui.DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1"));
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   201
	ui.Pages->setCurrentIndex(ID_PAGE_DEMOS);
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   202
}
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   203
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   204
void HWForm::GoToNet()
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   205
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   206
	ui.Pages->setCurrentIndex(ID_PAGE_NET);
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   207
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   208
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   209
void HWForm::GoToNetChat()
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   210
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   211
	ui.Pages->setCurrentIndex(ID_PAGE_NETCHAT);
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   212
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   213
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   214
void HWForm::NewTeam()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   215
{
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   216
	tmpTeam = new HWTeam("unnamed");
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   217
	tmpTeam->SetCfgDir(cfgdir.absolutePath());
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   218
	tmpTeam->SetToPage(this);
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   219
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   220
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   221
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   222
void HWForm::EditTeam()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   223
{
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   224
	tmpTeam = new HWTeam(ui.CBTeamName->currentText());
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   225
	tmpTeam->SetCfgDir(cfgdir.absolutePath());
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   226
	tmpTeam->LoadFromFile();
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   227
	tmpTeam->SetToPage(this);
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   228
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   229
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   230
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   231
void HWForm::TeamSave()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   232
{
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   233
	tmpTeam->GetFromPage(this);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   234
	tmpTeam->SaveToFile();
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   235
	delete tmpTeam;
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   236
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   237
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   238
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   239
void HWForm::TeamDiscard()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   240
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   241
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   242
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   243
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   244
void HWForm::SimpleGame()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   245
{
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   246
	game = new HWGame(ui.CBResolution->currentIndex(), ui.CBFullscreen->isChecked());
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   247
	game->AddTeam(cfgdir.absolutePath() + "/team.cfg");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   248
	game->AddTeam(cfgdir.absolutePath() + "/team.cfg");
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   249
	game->Start();
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   250
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   251
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   252
void HWForm::CBGrave_activated(const QString & gravename)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   253
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   254
	QPixmap pix(QString(DATA_PATH) + "/Graphics/Graves/" + gravename + ".png");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   255
	ui.GravePreview->setPixmap(pix.copy(0, 0, 32, 32));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   256
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   257
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   258
void HWForm::CBFort_activated(const QString & fortname)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   259
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   260
	QPixmap pix(QString(DATA_PATH) + "/Forts/" + fortname + "L.png");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   261
	ui.FortPreview->setPixmap(pix);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   262
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   263
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   264
void HWForm::SaveOptions()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   265
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   266
	QFile settings(cfgdir.absolutePath() + "/options");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   267
	if (!settings.open(QIODevice::WriteOnly))
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   268
	{
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   269
		QMessageBox::critical(this,
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   270
				tr("Error"),
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   271
				tr("Cannot save options to file %s").arg(settings.fileName()),
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   272
				tr("Quit"));
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   273
		return ;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   274
	}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   275
	QTextStream stream(&settings);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   276
	stream.setCodec("UTF-8");
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   277
	stream << "; Generated by Hedgewars, do not modify" << endl;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   278
	stream << "resolution " << ui.CBResolution->currentIndex() << endl;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   279
	stream << "fullscreen " << ui.CBFullscreen->isChecked() << endl;
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   280
	settings.close();
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   281
}
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   282
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   283
void HWForm::PlayDemo()
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   284
{
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   285
	QListWidgetItem * curritem = ui.DemosList->currentItem();
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   286
	if (!curritem)
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   287
	{
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   288
		QMessageBox::critical(this,
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   289
				tr("Error"),
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   290
				tr("Please, select demo from the list above"),
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   291
				tr("OK"));
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   292
		return ;
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   293
	}
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   294
	game = new HWGame(ui.CBResolution->currentIndex(), ui.CBFullscreen->isChecked());
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   295
	game->PlayDemo(QString(DATA_PATH) + "/Demos/" + curritem->text() + ".hwd_1");
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   296
}
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   297
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   298
void HWForm::NetConnect()
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   299
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   300
	hwnet = new HWNet();
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   301
	hwnet->Connect("localhost", 6667);
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   302
	connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   303
	connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &)));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   304
}
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   305
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   306
void HWForm::NetDisconnect()
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   307
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   308
	hwnet->Disconnect();
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   309
	GoToNet();
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   310
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   311
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   312
void HWForm::AddGame(const QString & chan)
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   313
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   314
	ui.ChannelsList->addItem(chan);
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   315
}