QTfrontend/hwform.cpp
author displacer
Mon, 18 Sep 2006 17:37:22 +0000
changeset 151 9eb5a4cee35e
parent 144 e6084b0c9316
child 152 c558957ef644
permissions -rw-r--r--
reset playing teams
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
85
44d9045b26ff New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents: 84
diff changeset
     3
 * Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
20
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"
87
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    45
#include "game.h"
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    46
#include "team.h"
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    47
#include "netclient.h"
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    48
#include "teamselect.h"
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    49
#include "gameuiconfig.h"
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    50
#include "pages.h"
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    51
#include "hwconsts.h"
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    52
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    53
HWForm::HWForm(QWidget *parent)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    54
	: QMainWindow(parent)
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    55
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    56
	ui.setupUi(this);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
    57
85
44d9045b26ff New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents: 84
diff changeset
    58
	config = new GameUIConfig(this);
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 60
diff changeset
    59
0f6669da2fcb Start rewrite ui
unc0rr
parents: 60
diff changeset
    60
	QStringList teamslist = config->GetTeamsList();
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
    61
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 60
diff changeset
    62
	if(teamslist.empty()) {
116
00d3d6d2e699 GameUIConfig* member removed
displacer
parents: 111
diff changeset
    63
		HWTeam defaultTeam("DefaultTeam");
86
664b536a1c27 Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents: 85
diff changeset
    64
		defaultTeam.SaveToFile();
664b536a1c27 Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents: 85
diff changeset
    65
		teamslist.push_back("DefaultTeam");
44
1ef9546971ff added default team on loading
displacer
parents: 43
diff changeset
    66
	}
1ef9546971ff added default team on loading
displacer
parents: 43
diff changeset
    67
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 60
diff changeset
    68
	for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it )
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
    69
	{
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 137
diff changeset
    70
	  ui.pageMultiplayer->teamsSelect->addTeam(*it);
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 137
diff changeset
    71
	  ui.pageOptions->CBTeamName->addItem(*it);
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
    72
	}
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
    73
87
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    74
	connect(ui.pageMain->BtnSinglePlayer,	SIGNAL(clicked()),	this, SLOT(GoToSinglePlayer()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    75
	connect(ui.pageMain->BtnSetup,	SIGNAL(clicked()),	this, SLOT(GoToSetup()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    76
	connect(ui.pageMain->BtnMultiplayer,	SIGNAL(clicked()),	this, SLOT(GoToMultiplayer()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    77
	connect(ui.pageMain->BtnDemos,	SIGNAL(clicked()),	this, SLOT(GoToDemos()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    78
	connect(ui.pageMain->BtnNet,	SIGNAL(clicked()),	this, SLOT(GoToNet()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    79
	connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(close()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    80
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    81
	connect(ui.pageLocalGame->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoToMain()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    82
	connect(ui.pageLocalGame->BtnSimpleGame,	SIGNAL(clicked()),	this, SLOT(SimpleGame()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    83
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    84
	connect(ui.pageEditTeam->BtnTeamSave,	SIGNAL(clicked()),	this, SLOT(TeamSave()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    85
	connect(ui.pageEditTeam->BtnTeamDiscard,	SIGNAL(clicked()),	this, SLOT(TeamDiscard()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    86
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    87
	connect(ui.pageMultiplayer->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoToMain()));
133
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 116
diff changeset
    88
	connect(ui.pageMultiplayer->BtnStartMPGame,	SIGNAL(clicked()),	this, SLOT(StartMPGame()));
87
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    89
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    90
	connect(ui.pagePlayDemo->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoToMain()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    91
	connect(ui.pagePlayDemo->BtnPlayDemo,	SIGNAL(clicked()),	this, SLOT(PlayDemo()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    92
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    93
	connect(ui.pageOptions->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoToMain()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    94
	connect(ui.pageOptions->BtnNewTeam,	SIGNAL(clicked()),	this, SLOT(NewTeam()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    95
	connect(ui.pageOptions->BtnEditTeam,	SIGNAL(clicked()),	this, SLOT(EditTeam()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    96
	connect(ui.pageOptions->BtnSaveOptions,	SIGNAL(clicked()),	config, SLOT(SaveOptions()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    97
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    98
	connect(ui.pageNet->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoToMain()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
    99
	connect(ui.pageNet->BtnNetConnect,	SIGNAL(clicked()),	this, SLOT(NetConnect()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   100
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   101
	connect(ui.pageNetGame->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoToNetChat()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   102
	connect(ui.pageNetGame->BtnAddTeam,	SIGNAL(clicked()),	this, SLOT(NetAddTeam()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   103
	connect(ui.pageNetGame->BtnGo,	SIGNAL(clicked()),	this, SLOT(NetStartGame()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   104
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   105
	connect(ui.pageNetChat->BtnDisconnect, SIGNAL(clicked()), this, SLOT(NetDisconnect()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   106
	connect(ui.pageNetChat->BtnJoin,	SIGNAL(clicked()),	this, SLOT(NetJoin()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   107
	connect(ui.pageNetChat->BtnCreate,	SIGNAL(clicked()),	this, SLOT(NetCreate()));
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   108
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   109
	ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   110
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   111
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   112
void HWForm::GoToMain()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   113
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   114
	ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   115
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   116
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   117
void HWForm::GoToSinglePlayer()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   118
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   119
	ui.Pages->setCurrentIndex(ID_PAGE_SINGLEPLAYER);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   120
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   121
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   122
void HWForm::GoToSetup()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   123
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   124
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   125
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   126
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   127
void HWForm::GoToMultiplayer()
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   128
{
151
9eb5a4cee35e reset playing teams
displacer
parents: 144
diff changeset
   129
	ui.pageMultiplayer->teamsSelect->resetPlayingTeams(config->GetTeamsList());
25
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   130
	ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER);
27aa8030322b - Get rid of old frontend
unc0rr
parents: 21
diff changeset
   131
}
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   132
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   133
void HWForm::GoToDemos()
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   134
{
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   135
	QDir tmpdir;
97
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 87
diff changeset
   136
	tmpdir.cd(datadir->absolutePath());
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   137
	tmpdir.cd("Demos");
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   138
	tmpdir.setFilter(QDir::Files);
87
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   139
	ui.pagePlayDemo->DemosList->clear();
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   140
	ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1"));
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   141
	ui.Pages->setCurrentIndex(ID_PAGE_DEMOS);
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   142
}
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   143
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   144
void HWForm::GoToNet()
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   145
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   146
	ui.Pages->setCurrentIndex(ID_PAGE_NET);
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   147
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   148
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   149
void HWForm::GoToNetChat()
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   150
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   151
	ui.Pages->setCurrentIndex(ID_PAGE_NETCHAT);
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   152
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   153
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   154
void HWForm::NewTeam()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   155
{
116
00d3d6d2e699 GameUIConfig* member removed
displacer
parents: 111
diff changeset
   156
	tmpTeam = new HWTeam("unnamed");
144
e6084b0c9316 - Fix 'new team' regression
unc0rr
parents: 140
diff changeset
   157
	tmpTeam->SetToPage(this);
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   158
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   159
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   160
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   161
void HWForm::EditTeam()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   162
{
116
00d3d6d2e699 GameUIConfig* member removed
displacer
parents: 111
diff changeset
   163
	tmpTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   164
	tmpTeam->LoadFromFile();
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   165
	tmpTeam->SetToPage(this);
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   166
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
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::TeamSave()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   170
{
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   171
	tmpTeam->GetFromPage(this);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   172
	tmpTeam->SaveToFile();
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents: 20
diff changeset
   173
	delete tmpTeam;
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   174
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
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::TeamDiscard()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   178
{
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   179
	ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   180
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   181
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   182
void HWForm::SimpleGame()
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   183
{
87
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   184
	game = new HWGame(config, ui.pageLocalGame->gameCFG);
86
664b536a1c27 Predefined teams, 'simple game' doesn't need to create team
unc0rr
parents: 85
diff changeset
   185
	game->StartQuick();
20
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   186
}
ccd2c45f043d frontend rewrite for QT4
unc0rr
parents:
diff changeset
   187
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   188
void HWForm::PlayDemo()
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   189
{
87
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   190
	QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem();
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   191
	if (!curritem)
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   192
	{
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   193
		QMessageBox::critical(this,
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   194
				tr("Error"),
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   195
				tr("Please, select demo from the list above"),
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   196
				tr("OK"));
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   197
		return ;
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   198
	}
85
44d9045b26ff New GameCFGWidget. Now it's possible to set forts mode from ui
unc0rr
parents: 84
diff changeset
   199
	game = new HWGame(config, 0);
97
e7c1df9cce2c - make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents: 87
diff changeset
   200
	game->PlayDemo(datadir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_1");
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   201
}
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   202
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   203
void HWForm::NetConnect()
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   204
{
84
0f6669da2fcb Start rewrite ui
unc0rr
parents: 60
diff changeset
   205
	hwnet = new HWNet(config);
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   206
	connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   207
	connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &)));
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   208
	connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
32
78bff13b11c0 With this patch the game doesn't crash when gaming by net
unc0rr
parents: 31
diff changeset
   209
	connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &)));
111
30ca06092a64 - 'net nickname' and 'server address' options are on PageNet
unc0rr
parents: 97
diff changeset
   210
	hwnet->Connect(ui.pageNet->editIP->text(), 6667, ui.pageNet->editNetNick->text());
30ca06092a64 - 'net nickname' and 'server address' options are on PageNet
unc0rr
parents: 97
diff changeset
   211
	config->SaveOptions();
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   212
}
26
e32fa14529f8 Frontend lets define more binds
unc0rr
parents: 25
diff changeset
   213
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   214
void HWForm::NetDisconnect()
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   215
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   216
	hwnet->Disconnect();
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   217
	GoToNet();
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   218
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   219
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   220
void HWForm::AddGame(const QString & chan)
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   221
{
87
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   222
	ui.pageNetChat->ChannelsList->addItem(chan);
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents: 26
diff changeset
   223
}
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   224
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   225
void HWForm::NetGameEnter()
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   226
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   227
	ui.Pages->setCurrentIndex(ID_PAGE_NETCFG);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   228
}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   229
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   230
void HWForm::NetJoin()
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   231
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   232
	hwnet->JoinGame("#hw");
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   233
}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   234
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   235
void HWForm::NetCreate()
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   236
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   237
	hwnet->JoinGame("#hw");
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   238
}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   239
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   240
void HWForm::NetAddTeam()
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   241
{
116
00d3d6d2e699 GameUIConfig* member removed
displacer
parents: 111
diff changeset
   242
	HWTeam team("DefaultTeam");
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   243
	team.LoadFromFile();
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   244
	hwnet->AddTeam(team);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   245
}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   246
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   247
void HWForm::NetStartGame()
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   248
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   249
	hwnet->StartGame();
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 28
diff changeset
   250
}
32
78bff13b11c0 With this patch the game doesn't crash when gaming by net
unc0rr
parents: 31
diff changeset
   251
78bff13b11c0 With this patch the game doesn't crash when gaming by net
unc0rr
parents: 31
diff changeset
   252
void HWForm::ChangeInNetTeams(const QStringList & teams)
78bff13b11c0 With this patch the game doesn't crash when gaming by net
unc0rr
parents: 31
diff changeset
   253
{
87
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   254
	ui.pageNetGame->listNetTeams->clear();
ff213e443336 Convert all pages to classes
unc0rr
parents: 86
diff changeset
   255
	ui.pageNetGame->listNetTeams->addItems(teams);
32
78bff13b11c0 With this patch the game doesn't crash when gaming by net
unc0rr
parents: 31
diff changeset
   256
}
78bff13b11c0 With this patch the game doesn't crash when gaming by net
unc0rr
parents: 31
diff changeset
   257
133
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 116
diff changeset
   258
void HWForm::StartMPGame()
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 116
diff changeset
   259
{
137
bcab861a3262 Get game modes from right GameCFGWidget
unc0rr
parents: 133
diff changeset
   260
	game = new HWGame(config, ui.pageMultiplayer->gameCFG);
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 137
diff changeset
   261
	QStringList teamslist = config->GetTeamsList();
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 137
diff changeset
   262
	for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 137
diff changeset
   263
	  if(ui.pageMultiplayer->teamsSelect->isPlaying(*it)) {
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 137
diff changeset
   264
	    game->AddTeam(*it, ui.pageMultiplayer->teamsSelect->numHedgedogs(*it));
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 137
diff changeset
   265
	  }
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 137
diff changeset
   266
	}
133
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 116
diff changeset
   267
	game->StartLocal();
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 116
diff changeset
   268
}