QTfrontend/pages.cpp
changeset 87 ff213e443336
child 88 6740a1c4edc9
equal deleted inserted replaced
86:664b536a1c27 87:ff213e443336
       
     1 /*
       
     2  * Hedgewars, a worms-like game
       
     3  * Copyright (c) 2006 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * Distributed under the terms of the BSD-modified licence:
       
     6  *
       
     7  * Permission is hereby granted, free of charge, to any person obtaining a copy
       
     8  * of this software and associated documentation files (the "Software"), to deal
       
     9  * with the Software without restriction, including without limitation the
       
    10  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
       
    11  * sell copies of the Software, and to permit persons to whom the Software is
       
    12  * furnished to do so, subject to the following conditions:
       
    13  *
       
    14  * 1. Redistributions of source code must retain the above copyright notice,
       
    15  *    this list of conditions and the following disclaimer.
       
    16  * 2. Redistributions in binary form must reproduce the above copyright notice,
       
    17  *    this list of conditions and the following disclaimer in the documentation
       
    18  *    and/or other materials provided with the distribution.
       
    19  * 3. The name of the author may not be used to endorse or promote products
       
    20  *    derived from this software without specific prior written permission.
       
    21  *
       
    22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
       
    23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
       
    24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
       
    25  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
       
    27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
       
    28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
       
    29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
       
    30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
       
    31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    32  */
       
    33 
       
    34 #include <QGridLayout>
       
    35 #include <QDir>
       
    36 #include <QPushButton>
       
    37 #include <QGroupBox>
       
    38 #include <QComboBox>
       
    39 #include <QLabel>
       
    40 #include <QToolBox>
       
    41 #include <QLineEdit>
       
    42 #include <QListWidget>
       
    43 
       
    44 #include "pages.h"
       
    45 #include "sdlkeys.h"
       
    46 #include "hwconsts.h"
       
    47 #include "gamecfgwidget.h"
       
    48 #include "teamselect.h"
       
    49 #include "gamecfgwidget.h"
       
    50 
       
    51 PageMain::PageMain(QWidget* parent) : QWidget(parent)
       
    52 {
       
    53 	QFont * font14 = new QFont("MS Shell Dlg", 14);
       
    54 	QGridLayout * pageLayout = new QGridLayout(this);
       
    55 	pageLayout->setMargin(25);
       
    56 	pageLayout->setColumnStretch(0, 1);
       
    57 	pageLayout->setColumnStretch(1, 2);
       
    58 	pageLayout->setColumnStretch(2, 1);
       
    59 
       
    60 	BtnSinglePlayer = new QPushButton(this);
       
    61 	BtnSinglePlayer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
    62 	BtnSinglePlayer->setFont(*font14);
       
    63 	BtnSinglePlayer->setText(QPushButton::tr("Single Player"));
       
    64 	pageLayout->addWidget(BtnSinglePlayer, 1, 1);
       
    65 
       
    66 	BtnMultiplayer = new QPushButton(this);
       
    67 	BtnMultiplayer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
    68 	BtnMultiplayer->setFont(*font14);
       
    69 	BtnMultiplayer->setText(QPushButton::tr("Multiplayer"));
       
    70 	pageLayout->addWidget(BtnMultiplayer, 2, 1);
       
    71 
       
    72 	BtnNet = new QPushButton(this);
       
    73 	BtnNet->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
    74 	BtnNet->setFont(*font14);
       
    75 	BtnNet->setText(QPushButton::tr("Net game"));
       
    76 	pageLayout->addWidget(BtnNet, 3, 1);
       
    77 
       
    78 	BtnDemos = new QPushButton(this);
       
    79 	BtnDemos->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
    80 	BtnDemos->setFont(*font14);
       
    81 	BtnDemos->setText(QPushButton::tr("Demos"));
       
    82 	pageLayout->addWidget(BtnDemos, 4, 1);
       
    83 
       
    84 	BtnSetup = new QPushButton(this);
       
    85 	BtnSetup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
    86 	BtnSetup->setFont(*font14);
       
    87 	BtnSetup->setText(QPushButton::tr("Setup"));
       
    88 	pageLayout->addWidget(BtnSetup, 5, 1);
       
    89 
       
    90 	BtnExit = new QPushButton(parent);
       
    91 	BtnExit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
    92 	BtnExit->setFont(*font14);
       
    93 	BtnExit->setText(QPushButton::tr("Exit"));
       
    94 	pageLayout->addWidget(BtnExit, 6, 1);
       
    95 }
       
    96 
       
    97 PageLocalGame::PageLocalGame(QWidget* parent) : QWidget(parent)
       
    98 {
       
    99 	QFont * font14 = new QFont("MS Shell Dlg", 14);
       
   100 	QGridLayout * pageLayout = new QGridLayout(this);
       
   101 	BtnBack =	new QPushButton(this);
       
   102 	BtnBack->setFont(*font14);
       
   103 	BtnBack->setText(QPushButton::tr("Back"));
       
   104 	pageLayout->addWidget(BtnBack, 1, 0);
       
   105 	BtnSimpleGame = new	QPushButton(this);
       
   106 	BtnSimpleGame->setFont(*font14);
       
   107 	BtnSimpleGame->setText(QPushButton::tr("Simple Game"));
       
   108 	pageLayout->addWidget(BtnSimpleGame, 1, 3);
       
   109 	gameCFG = new GameCFGWidget(this);
       
   110 	pageLayout->addWidget(gameCFG, 0, 0, 1, 2);
       
   111 }
       
   112 
       
   113 PageEditTeam::PageEditTeam(QWidget* parent) : QWidget(parent)
       
   114 {
       
   115 	QFont * font14 = new QFont("MS Shell Dlg", 14);
       
   116 	GBoxHedgehogs = new	QGroupBox(this);
       
   117 	GBoxHedgehogs->setGeometry(QRect(20, 70, 161, 261));
       
   118 	GBoxHedgehogs->setTitle(QGroupBox::tr("Team Members"));
       
   119 	GBoxTeam = new QGroupBox(this);
       
   120 	GBoxTeam->setGeometry(QRect(20, 10,	161, 51));
       
   121 	GBoxTeam->setTitle(QGroupBox::tr("Team"));
       
   122 	GBoxFort = new QGroupBox(this);
       
   123 	GBoxFort->setGeometry(QRect(420, 110, 181, 221));
       
   124 	GBoxFort->setTitle(QGroupBox::tr("Fort"));
       
   125 	CBFort = new QComboBox(GBoxFort);
       
   126 	CBFort->setGeometry(QRect(10, 20, 161, 21));
       
   127 	CBFort->setMaxCount(65535);
       
   128 	FortPreview	= new QLabel(GBoxFort);
       
   129 	FortPreview->setGeometry(QRect(10, 50, 161,	161));
       
   130 	FortPreview->setPixmap(QPixmap());
       
   131 	FortPreview->setScaledContents(true);
       
   132 	GBoxGrave =	new QGroupBox(this);
       
   133 	GBoxGrave->setGeometry(QRect(420, 10, 181, 91));
       
   134 	GBoxGrave->setTitle(QGroupBox::tr("Grave"));
       
   135 	CBGrave = new QComboBox(GBoxGrave);
       
   136 	CBGrave->setGeometry(QRect(10, 20, 161, 21));
       
   137 	CBGrave->setMaxCount(65535);
       
   138 	GravePreview = new QLabel(GBoxGrave);
       
   139 	GravePreview->setGeometry(QRect(80,	50, 32,	32));
       
   140 	GravePreview->setScaledContents(true);
       
   141 	GBoxBinds =	new QGroupBox(this);
       
   142 	GBoxBinds->setGeometry(QRect(200, 10, 201, 431));
       
   143 	GBoxBinds->setTitle(QGroupBox::tr("Key binds"));
       
   144 	BindsBox = new QToolBox(GBoxBinds);
       
   145 	BindsBox->setGeometry(QRect(10, 20,	181, 401));
       
   146 	BindsBox->setLineWidth(0);
       
   147 	page_A = new QWidget();
       
   148 	page_A->setGeometry(QRect(0, 0, 96,	26));
       
   149 	BindsBox->addItem(page_A, QToolBox::tr("Actions"));
       
   150 	page_W = new QWidget();
       
   151 	BindsBox->addItem(page_W, QToolBox::tr("Weapons"));
       
   152 	page_WP = new QWidget();
       
   153 	BindsBox->addItem(page_WP, QToolBox::tr("Weapon properties"));
       
   154 	page_O = new QWidget();
       
   155 	page_O->setGeometry(QRect(0, 0, 96,	26));
       
   156 	BindsBox->addItem(page_O, QToolBox::tr("Other"));
       
   157 	BtnTeamDiscard = new QPushButton(this);
       
   158 	BtnTeamDiscard->setGeometry(QRect(440, 380,	161, 41));
       
   159 	BtnTeamDiscard->setFont(*font14);
       
   160 	BtnTeamDiscard->setText(QPushButton::tr("Discard"));
       
   161 	BtnTeamSave	= new QPushButton(this);
       
   162 	BtnTeamSave->setGeometry(QRect(20, 380, 161, 41));
       
   163 	BtnTeamSave->setFont(*font14);
       
   164 	BtnTeamSave->setText(QPushButton::tr("Save"));
       
   165 
       
   166 	TeamNameEdit = new QLineEdit(GBoxTeam);
       
   167 	TeamNameEdit->setGeometry(QRect(10, 20, 141, 20));
       
   168 	TeamNameEdit->setMaxLength(15);
       
   169 	for(int i = 0; i < 8; i++)
       
   170 	{
       
   171 		HHNameEdit[i] = new QLineEdit(GBoxHedgehogs);
       
   172 		HHNameEdit[i]->setGeometry(QRect(10, 20 + i * 30, 141, 20));
       
   173 		HHNameEdit[i]->setMaxLength(15);
       
   174 	}
       
   175 
       
   176 	QStringList binds;
       
   177 	for(int i = 0; strlen(sdlkeys[i][1]) > 0; i++)
       
   178 	{
       
   179 		binds << sdlkeys[i][1];
       
   180 	}
       
   181 
       
   182 	quint16 widind = 0, top = 0;
       
   183 	for(quint8 i = 0; i < BINDS_NUMBER; i++)
       
   184 	{
       
   185 		LBind[i] = new QLabel(BindsBox->widget(widind));
       
   186 		LBind[i]->setGeometry(QRect(10, top + 3, 70, 20));
       
   187 		LBind[i]->setText(tr(cbinds[i].name));
       
   188 		LBind[i]->setAlignment(Qt::AlignRight);
       
   189 		CBBind[i] = new QComboBox(BindsBox->widget(widind));
       
   190 		CBBind[i]->setGeometry(QRect(90, top, 80, 20));
       
   191 		CBBind[i]->addItems(binds);
       
   192 		if (cbinds[i].chwidget)
       
   193 		{
       
   194 			top = 0;
       
   195 			widind++;
       
   196 		} else
       
   197 		{
       
   198 			top += 28;
       
   199 		}
       
   200 	}
       
   201 
       
   202 	QDir tmpdir;
       
   203 	tmpdir.cd(DATA_PATH);
       
   204 	tmpdir.cd("Forts");
       
   205 	tmpdir.setFilter(QDir::Files);
       
   206 
       
   207 	CBFort->addItems(tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L.png"), "\\1"));
       
   208 	tmpdir.cd("../Graphics/Graves");
       
   209 	QStringList list = tmpdir.entryList(QStringList("*.png"));
       
   210 	for (QStringList::Iterator it = list.begin(); it != list.end(); ++it )
       
   211 	{
       
   212 		CBGrave->addItem((*it).replace(QRegExp("^(.*).png"), "\\1"));
       
   213 	}
       
   214 
       
   215 	connect(CBGrave, SIGNAL(activated(const QString &)), this, SLOT(CBGrave_activated(const QString &)));
       
   216 	connect(CBFort, SIGNAL(activated(const QString &)), this, SLOT(CBFort_activated(const QString &)));
       
   217 }
       
   218 
       
   219 void PageEditTeam::CBGrave_activated(const QString & gravename)
       
   220 {
       
   221 	QPixmap pix(QString(DATA_PATH) + "/Graphics/Graves/" + gravename + ".png");
       
   222 	GravePreview->setPixmap(pix.copy(0, 0, 32, 32));
       
   223 }
       
   224 
       
   225 void PageEditTeam::CBFort_activated(const QString & fortname)
       
   226 {
       
   227 	QPixmap pix(QString(DATA_PATH) + "/Forts/" + fortname + "L.png");
       
   228 	FortPreview->setPixmap(pix);
       
   229 }
       
   230 
       
   231 PageMultiplayer::PageMultiplayer(QWidget* parent) : QWidget(parent)
       
   232 {
       
   233 	QFont * font14 = new QFont("MS Shell Dlg", 14);
       
   234 	QGridLayout * pageLayout = new QGridLayout(this);
       
   235 	BtnBack = new QPushButton(this);
       
   236 	BtnBack->setFont(*font14);
       
   237 	BtnBack->setText(QPushButton::tr("Back"));
       
   238 	pageLayout->addWidget(BtnBack, 1, 0);
       
   239 	gameCFG = new GameCFGWidget(this);
       
   240 	pageLayout->addWidget(gameCFG, 0, 0, 1, 2);
       
   241 	teamsSelect = new TeamSelWidget(this);
       
   242 	pageLayout->addWidget(teamsSelect, 0, 2, 1, 2);
       
   243 }
       
   244 
       
   245 PagePlayDemo::PagePlayDemo(QWidget* parent) : QWidget(parent)
       
   246 {
       
   247 	QFont * font14 = new QFont("MS Shell Dlg", 14);
       
   248 	QGridLayout * pageLayout = new QGridLayout(this);
       
   249 	pageLayout->setColumnStretch(0, 1);
       
   250 	pageLayout->setColumnStretch(1, 2);
       
   251 	pageLayout->setColumnStretch(2, 1);
       
   252 
       
   253 	BtnBack = new QPushButton(this);
       
   254 	BtnBack->setFont(*font14);
       
   255 	BtnBack->setText(QPushButton::tr("Back"));
       
   256 	pageLayout->addWidget(BtnBack, 1, 0);
       
   257 
       
   258 	BtnPlayDemo	= new QPushButton(this);
       
   259 	BtnPlayDemo->setGeometry(QRect(240,	330, 161, 41));
       
   260 	BtnPlayDemo->setFont(*font14);
       
   261 	BtnPlayDemo->setText(QPushButton::tr("Play demo"));
       
   262 	pageLayout->addWidget(BtnPlayDemo, 1, 2);
       
   263 
       
   264 	DemosList =	new QListWidget(this);
       
   265 	DemosList->setGeometry(QRect(170, 10, 311, 311));
       
   266 	pageLayout->addWidget(DemosList, 0, 1);
       
   267 }
       
   268 
       
   269 PageOptions::PageOptions(QWidget* parent) : QWidget(parent)
       
   270 {
       
   271 	QFont * font14 = new QFont("MS Shell Dlg", 14);
       
   272 	groupBox = new QGroupBox(this);
       
   273 	groupBox->setGeometry(QRect(20, 10,	591, 71));
       
   274 	groupBox->setTitle(QGroupBox::tr("Teams"));
       
   275 
       
   276 	BtnNewTeam = new QPushButton(groupBox);
       
   277 	BtnNewTeam->setGeometry(QRect(10, 20, 160, 40));
       
   278 	BtnNewTeam->setFont(*font14);
       
   279 	BtnNewTeam->setText(QPushButton::tr("New team"));
       
   280 
       
   281 	BtnEditTeam	= new QPushButton(groupBox);
       
   282 	BtnEditTeam->setGeometry(QRect(400,	20, 160, 40));
       
   283 	BtnEditTeam->setFont(*font14);
       
   284 	BtnEditTeam->setText(QPushButton::tr("Edit team"));
       
   285 
       
   286 	CBTeamName = new QComboBox(groupBox);
       
   287 	CBTeamName->setGeometry(QRect(200, 30, 171,	22));
       
   288 	CBResolution = new QComboBox(this);
       
   289 	CBResolution->addItem("640x480");
       
   290 	CBResolution->addItem("800x600");
       
   291 	CBResolution->addItem("1024x768");
       
   292 	CBResolution->addItem("1280x1024");
       
   293 	CBResolution->setGeometry(QRect(20,	120, 151, 22));
       
   294 
       
   295 	CBEnableSound = new	QCheckBox(this);
       
   296 	CBEnableSound->setGeometry(QRect(20, 180, 101, 18));
       
   297 	CBEnableSound->setText(QCheckBox::tr("Enable sound"));
       
   298 
       
   299 	CBFullscreen = new QCheckBox(this);
       
   300 	CBFullscreen->setGeometry(QRect(20,	160, 101, 18));
       
   301 	CBFullscreen->setText(QCheckBox::tr("Fullscreen"));
       
   302 
       
   303 	label = new	QLabel(this);
       
   304 	label->setGeometry(QRect(10, 233, 47, 13));
       
   305 	label->setText(QLabel::tr("Net nick"));
       
   306 
       
   307 	editNetNick	= new QLineEdit(this);
       
   308 	editNetNick->setGeometry(QRect(60, 230, 113, 20));
       
   309 	editNetNick->setMaxLength(30);
       
   310 	editNetNick->setText(QLineEdit::tr("unnamed"));
       
   311 
       
   312 	BtnSaveOptions = new QPushButton(this);
       
   313 	BtnSaveOptions->setGeometry(QRect(20, 380, 161, 41));
       
   314 	BtnSaveOptions->setFont(*font14);
       
   315 	BtnSaveOptions->setText(QPushButton::tr("Save"));
       
   316 
       
   317 	BtnBack = new QPushButton(this);
       
   318 	BtnBack->setGeometry(QRect(440, 380, 161, 41));
       
   319 	BtnBack->setFont(*font14);
       
   320 	BtnBack->setText(QPushButton::tr("Back"));
       
   321 }
       
   322 
       
   323 PageNet::PageNet(QWidget* parent) : QWidget(parent)
       
   324 {
       
   325 	QFont * font14 = new QFont("MS Shell Dlg", 14);
       
   326 	BtnNetConnect = new	QPushButton(this);
       
   327 	BtnNetConnect->setGeometry(QRect(250, 140, 161, 41));
       
   328 	BtnNetConnect->setFont(*font14);
       
   329 	BtnNetConnect->setText(QPushButton::tr("Connect"));
       
   330 	BtnBack = new QPushButton(this);
       
   331 	BtnBack->setGeometry(QRect(250, 390, 161, 41));
       
   332 	BtnBack->setFont(*font14);
       
   333 	BtnBack->setText(QPushButton::tr("Back"));
       
   334 }
       
   335 
       
   336 PageNetChat::PageNetChat(QWidget* parent) : QWidget(parent)
       
   337 {
       
   338 	QFont * font14 = new QFont("MS Shell Dlg", 14);
       
   339 	BtnDisconnect = new QPushButton(this);
       
   340 	BtnDisconnect->setGeometry(QRect(460, 390, 161, 41));
       
   341 	BtnDisconnect->setFont(*font14);
       
   342 	BtnDisconnect->setText(QPushButton::tr("Disconnect"));
       
   343 	ChannelsList = new QListWidget(this);
       
   344 	ChannelsList->setGeometry(QRect(20,	10, 201, 331));
       
   345 	BtnJoin = new QPushButton(this);
       
   346 	BtnJoin->setGeometry(QRect(460, 290,	161, 41));
       
   347 	BtnJoin->setFont(*font14);
       
   348 	BtnJoin->setText(QPushButton::tr("Join"));
       
   349 	BtnCreate = new QPushButton(this);
       
   350 	BtnCreate->setGeometry(QRect(460, 340, 161, 41));
       
   351 	BtnCreate->setFont(*font14);
       
   352 	BtnCreate->setText(QPushButton::tr("Create"));
       
   353 }
       
   354 
       
   355 
       
   356 PageNetGame::PageNetGame(QWidget* parent) : QWidget(parent)
       
   357 {
       
   358 	QFont * font14 = new QFont("MS Shell Dlg", 14);
       
   359 	BtnBack = new QPushButton(this);
       
   360 	BtnBack->setGeometry(QRect(260, 390, 161, 41));
       
   361 	BtnBack->setFont(*font14);
       
   362 	BtnBack->setText(QPushButton::tr("Back"));
       
   363 
       
   364 	BtnAddTeam = new QPushButton(this);
       
   365 	BtnAddTeam->setGeometry(QRect(260, 290, 161, 41));
       
   366 	BtnAddTeam->setFont(*font14);
       
   367 	BtnAddTeam->setText(QPushButton::tr("Add Team"));
       
   368 
       
   369 	BtnGo	= new QPushButton(this);
       
   370 	BtnGo->setGeometry(QRect(260,	340, 161, 41));
       
   371 	BtnGo->setFont(*font14);
       
   372 	BtnGo->setText(QPushButton::tr("Go!"));
       
   373 
       
   374 	listNetTeams = new QListWidget(this);
       
   375 	listNetTeams->setGeometry(QRect(270, 30, 120, 80));
       
   376 }