# HG changeset patch # User unc0rr # Date 1133987815 0 # Node ID e32fa14529f8f5330b9b0868083f710028a287aa # Parent 27aa8030322b6421f514ac904104727268273366 Frontend lets define more binds diff -r 27aa8030322b -r e32fa14529f8 QTfrontend/binds.h --- a/QTfrontend/binds.h Tue Dec 06 19:46:40 2005 +0000 +++ b/QTfrontend/binds.h Wed Dec 07 20:36:55 2005 +0000 @@ -1,61 +1,71 @@ -/* - * Hedgewars, a worms-like game - * Copyright (c) 2005 Andrey Korotaev - * - * Distributed under the terms of the BSD-modified licence: - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * with the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef BINDS_H -#define BINDS_H - -#include - -#define BINDS_NUMBER 9 - -struct BindAction -{ - QString action; - QString strbind; - QString name; -}; - -const BindAction cbinds[BINDS_NUMBER] = -{ - {"+up", "up", QT_TR_NOOP("up")}, - {"+left", "left", QT_TR_NOOP("left")}, - {"+right", "right", QT_TR_NOOP("right")}, - {"+down", "down", QT_TR_NOOP("down")}, - {"ljump", "return", QT_TR_NOOP("jump")}, - {"hjump", "backspace", QT_TR_NOOP("jump")}, - {"+attack", "space", QT_TR_NOOP("attack")}, - {"switch", "tab", QT_TR_NOOP("switch")}, - {"quit", "F10", QT_TR_NOOP("quit")} -}; - -#endif // BINDS_H +/* + * Hedgewars, a worms-like game + * Copyright (c) 2005 Andrey Korotaev + * + * Distributed under the terms of the BSD-modified licence: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * with the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef BINDS_H +#define BINDS_H + +#include + +#define BINDS_NUMBER 18 + +struct BindAction +{ + QString action; + QString strbind; + QString name; + bool chwidget; +}; + +const BindAction cbinds[BINDS_NUMBER] = +{ + {"+up", "up", QT_TR_NOOP("up"), false}, + {"+left", "left", QT_TR_NOOP("left"), false}, + {"+right", "right", QT_TR_NOOP("right"), false}, + {"+down", "down", QT_TR_NOOP("down"), false}, + {"ljump", "return", QT_TR_NOOP("jump"), false}, + {"hjump", "backspace", QT_TR_NOOP("jump"), false}, + {"+attack", "space", QT_TR_NOOP("attack"), false}, + {"switch", "tab", QT_TR_NOOP("switch"), true}, + {"slot 1", "f1", QT_TR_NOOP("slot 1"), false}, + {"slot 2", "f2", QT_TR_NOOP("slot 2"), false}, + {"slot 3", "f3", QT_TR_NOOP("slot 3"), false}, + {"slot 4", "f4", QT_TR_NOOP("slot 4"), false}, + {"slot 5", "f5", QT_TR_NOOP("slot 5"), false}, + {"slot 6", "f6", QT_TR_NOOP("slot 6"), false}, + {"slot 7", "f7", QT_TR_NOOP("slot 7"), false}, + {"slot 8", "f8", QT_TR_NOOP("slot 8"), true}, + {"capture", "f11", QT_TR_NOOP("capture"), false}, + {"quit", "f10", QT_TR_NOOP("quit"), false} +}; + +#endif // BINDS_H diff -r 27aa8030322b -r e32fa14529f8 QTfrontend/game.cpp --- a/QTfrontend/game.cpp Tue Dec 06 19:46:40 2005 +0000 +++ b/QTfrontend/game.cpp Wed Dec 07 20:36:55 2005 +0000 @@ -41,8 +41,10 @@ #include "game.h" #include "hwconsts.h" -HWGame::HWGame() +HWGame::HWGame(int Resolution, bool Fullscreen) { + vid_Resolution = Resolution; + vid_Fullscreen = Fullscreen; IPCServer = new QTcpServer(this); IPCServer->setMaxPendingConnections(1); if (!IPCServer->listen(QHostAddress("127.0.0.1"), IPC_PORT)) @@ -54,7 +56,7 @@ connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); IPCSocket = 0; TeamCount = 0; - seed = "seed"; + seed = ""; } void HWGame::NewConnection() @@ -103,6 +105,13 @@ void HWGame::SendConfig() { + if (gameType == gtDemo) + { + SENDIPC("TD"); + SendIPCRaw(toSendBuf->constData(), toSendBuf->size()); + delete toSendBuf; + return ; + } SENDIPC("TL"); SENDIPC("e$gmflags 0"); SENDIPC("eaddteam"); @@ -168,6 +177,12 @@ demo->append(buf); } +void HWGame::SendIPCRaw(const char * msg, quint32 len) +{ + IPCSocket->write(msg, len); + demo->append(QByteArray::fromRawData(msg, len)); +} + void HWGame::ClientRead() { qint64 readbytes = 1; @@ -190,19 +205,20 @@ } } -void HWGame::Start(int Resolution, bool Fullscreen) +void HWGame::Start() { + gameType = gtLocal; if (TeamCount < 2) return; QProcess * process; QStringList arguments; seedgen.GenRNDStr(seed, 10); process = new QProcess; - arguments << resolutions[0][Resolution]; - arguments << resolutions[1][Resolution]; + arguments << resolutions[0][vid_Resolution]; + arguments << resolutions[1][vid_Resolution]; arguments << GetThemeBySeed(); arguments << "46631"; arguments << seed; - arguments << (Fullscreen ? "1" : "0"); + arguments << (vid_Fullscreen ? "1" : "0"); process->start("hw", arguments); demo = new QByteArray; demo->append(seed.toLocal8Bit()); @@ -218,7 +234,7 @@ QString HWGame::GetThemeBySeed() { - QFile themesfile("Data/Themes/themes.cfg"); + QFile themesfile(QString(DATA_PATH) + "/Themes/themes.cfg"); QStringList themes; if (themesfile.open(QIODevice::ReadOnly)) { @@ -263,4 +279,58 @@ QDataStream stream(&demofile); stream.writeRawData(demo->constData(), demo->size()); demofile.close(); + delete demo; } + +void HWGame::PlayDemo(const QString & demofilename) +{ + gameType = gtDemo; + QFile demofile(demofilename); + if (!demofile.open(QIODevice::ReadOnly)) + { + QMessageBox::critical(this, + tr("Error"), + tr("Cannot open demofile %s").arg(demofilename), + tr("Quit")); + return ; + } + + // read demo + QDataStream stream(&demofile); + toSendBuf = new QByteArray(); + char buf[512]; + quint32 readbytes; + do + { + readbytes = stream.readRawData((char *)&buf, 512); + toSendBuf -> append(QByteArray((char *)&buf, readbytes)); + + } while (readbytes > 0); + demofile.close(); + + // cut seed + quint32 index = toSendBuf->indexOf(10); + if (!index) + { + QMessageBox::critical(this, + tr("Error"), + tr("Corrupted demo file %s").arg(demofilename), + tr("Quit")); + return ; + } + seed = QString(toSendBuf->left(index++)); + toSendBuf->remove(0, index); + + // run engine + QProcess * process; + QStringList arguments; + process = new QProcess; + arguments << resolutions[0][vid_Resolution]; + arguments << resolutions[1][vid_Resolution]; + arguments << GetThemeBySeed(); + arguments << "46631"; + arguments << seed; + arguments << (vid_Fullscreen ? "1" : "0"); + process->start("hw", arguments); + demo = new QByteArray; +} diff -r 27aa8030322b -r e32fa14529f8 QTfrontend/game.h --- a/QTfrontend/game.h Tue Dec 06 19:46:40 2005 +0000 +++ b/QTfrontend/game.h Wed Dec 07 20:36:55 2005 +0000 @@ -51,12 +51,18 @@ { Q_OBJECT public: - HWGame(); - void Start(int Resolution, bool Fullscreen); + HWGame(int Resolution, bool Fullscreen); + void Start(); void AddTeam(const QString & team); + void PlayDemo(const QString & demofilename); private: - QTcpServer * IPCServer; + enum GameType { + gtLocal = 1, + gtDemo = 2, + gtNet = 3 + }; + QTcpServer * IPCServer; QTcpSocket * IPCSocket; char msgbuf[MAXMSGCHARS]; quint8 msgbufsize; @@ -66,12 +72,17 @@ int TeamCount; RNDStr seedgen; QByteArray * demo; + QByteArray * toSendBuf; + int vid_Resolution; + bool vid_Fullscreen; + GameType gameType; void SendConfig(); void SendTeamConfig(int index); void ParseMessage(); void SendIPC(const char * msg, quint8 len); void SendIPC(const QByteArray & buf); + void SendIPCRaw(const char * msg, quint32 len); void SaveDemo(const QString & filename); QString GetThemeBySeed(); diff -r 27aa8030322b -r e32fa14529f8 QTfrontend/hwform.cpp --- a/QTfrontend/hwform.cpp Tue Dec 06 19:46:40 2005 +0000 +++ b/QTfrontend/hwform.cpp Wed Dec 07 20:36:55 2005 +0000 @@ -66,15 +66,24 @@ binds << sdlkeys[i][1]; } - for(int i = 0; i < BINDS_NUMBER; i++) + quint16 widind = 0, top = 0; + for(quint8 i = 0; i < BINDS_NUMBER; i++) { - LBind[i] = new QLabel(ui.GBoxBinds); - LBind[i]->setGeometry(QRect(10, 23 + i * 30, 60, 20)); + LBind[i] = new QLabel(ui.BindsBox->widget(widind)); + LBind[i]->setGeometry(QRect(10, top + 3, 60, 20)); LBind[i]->setText(cbinds[i].name); LBind[i]->setAlignment(Qt::AlignRight); - CBBind[i] = new QComboBox(ui.GBoxBinds); - CBBind[i]->setGeometry(QRect(80, 20 + i * 30, 80, 20)); + CBBind[i] = new QComboBox(ui.BindsBox->widget(widind)); + CBBind[i]->setGeometry(QRect(80, top, 80, 20)); CBBind[i]->addItems(binds); + if (cbinds[i].chwidget) + { + top = 0; + widind++; + } else + { + top += 30; + } } QDir tmpdir; @@ -136,18 +145,22 @@ } settings.close(); } + connect(ui.BtnSPBack, SIGNAL(clicked()), this, SLOT(GoToMain())); + connect(ui.BtnDemosBack, SIGNAL(clicked()), this, SLOT(GoToMain())); connect(ui.BtnSetupBack, SIGNAL(clicked()), this, SLOT(GoToMain())); connect(ui.BtnMPBack, SIGNAL(clicked()), this, SLOT(GoToMain())); connect(ui.BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer())); connect(ui.BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup())); connect(ui.BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer())); + connect(ui.BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); connect(ui.BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); connect(ui.BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); connect(ui.BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); connect(ui.BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); connect(ui.BtnSimpleGame, SIGNAL(clicked()), this, SLOT(SimpleGame())); connect(ui.BtnSaveOptions, SIGNAL(clicked()), this, SLOT(SaveOptions())); + connect(ui.BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo())); connect(ui.CBGrave, SIGNAL(activated(const QString &)), this, SLOT(CBGrave_activated(const QString &))); connect(ui.CBFort, SIGNAL(activated(const QString &)), this, SLOT(CBFort_activated(const QString &))); ui.Pages->setCurrentIndex(ID_PAGE_MAIN); @@ -172,6 +185,17 @@ { ui.Pages->setCurrentIndex(ID_PAGE_MULTIPLAYER); } + +void HWForm::GoToDemos() +{ + QDir tmpdir; + tmpdir.cd(DATA_PATH); + tmpdir.cd("Demos"); + tmpdir.setFilter(QDir::Files); + ui.DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_1")).replaceInStrings(QRegExp("^(.*).hwd_1"), "\\1")); + ui.Pages->setCurrentIndex(ID_PAGE_DEMOS); +} + void HWForm::NewTeam() { tmpTeam = new HWTeam("unnamed"); @@ -204,10 +228,10 @@ void HWForm::SimpleGame() { - game = new HWGame(); + game = new HWGame(ui.CBResolution->currentIndex(), ui.CBFullscreen->isChecked()); game->AddTeam(cfgdir.absolutePath() + "/team.cfg"); game->AddTeam(cfgdir.absolutePath() + "/team.cfg"); - game->Start(ui.CBResolution->currentIndex(), ui.CBFullscreen->isChecked()); + game->Start(); } void HWForm::CBGrave_activated(const QString & gravename) @@ -240,3 +264,20 @@ stream << "fullscreen " << ui.CBFullscreen->isChecked() << endl; settings.close(); } + +void HWForm::PlayDemo() +{ + QListWidgetItem * curritem = ui.DemosList->currentItem(); + if (!curritem) + { + QMessageBox::critical(this, + tr("Error"), + tr("Please, select demo from the list above"), + tr("OK")); + return ; + } + game = new HWGame(ui.CBResolution->currentIndex(), ui.CBFullscreen->isChecked()); + game->PlayDemo(QString(DATA_PATH) + "/Demos/" + curritem->text() + ".hwd_1"); +} + + diff -r 27aa8030322b -r e32fa14529f8 QTfrontend/hwform.h --- a/QTfrontend/hwform.h Tue Dec 06 19:46:40 2005 +0000 +++ b/QTfrontend/hwform.h Wed Dec 07 20:36:55 2005 +0000 @@ -58,13 +58,15 @@ void GoToSinglePlayer(); void GoToSetup(); void GoToMultiplayer(); + void GoToDemos(); void NewTeam(); void EditTeam(); void TeamSave(); void TeamDiscard(); void SimpleGame(); void SaveOptions(); - + void PlayDemo(); + public slots: void CBGrave_activated(const QString & gravename); void CBFort_activated(const QString & gravename); @@ -76,10 +78,11 @@ HWTeam * tmpTeam; }; -#define ID_PAGE_MAIN 4 #define ID_PAGE_SINGLEPLAYER 0 +#define ID_PAGE_SETUP_TEAM 1 #define ID_PAGE_SETUP 2 -#define ID_PAGE_SETUP_TEAM 1 #define ID_PAGE_MULTIPLAYER 3 +#define ID_PAGE_DEMOS 4 +#define ID_PAGE_MAIN 5 #endif diff -r 27aa8030322b -r e32fa14529f8 QTfrontend/hwform.ui --- a/QTfrontend/hwform.ui Tue Dec 06 19:46:40 2005 +0000 +++ b/QTfrontend/hwform.ui Wed Dec 07 20:36:55 2005 +0000 @@ -50,39 +50,9 @@ - 4 + 1 - - - - 230 - 170 - 161 - 41 - - - - - MS Shell Dlg - 14 - 50 - false - false - false - false - - - - Back - - - false - - - false - - @@ -113,43 +83,11 @@ false - - - + - 460 - 340 - 161 - 41 - - - - - MS Shell Dlg - 14 - 50 - false - false - false - false - - - - Save - - - false - - - false - - - - - - 460 - 400 + 230 + 170 161 41 @@ -166,7 +104,7 @@ - Discard + Back false @@ -175,6 +113,8 @@ false + + @@ -188,112 +128,6 @@ Team Members - - - - 190 - 10 - 181 - 321 - - - - Key binds - - - - - - 390 - 110 - 181 - 221 - - - - Fort - - - - - 10 - 20 - 161 - 21 - - - - -1 - - - 65535 - - - - - - 10 - 50 - 161 - 161 - - - - - - - - - - true - - - - - - - 390 - 10 - 181 - 91 - - - - Grave - - - - - 10 - 20 - 161 - 21 - - - - -1 - - - 65535 - - - - - - 80 - 50 - 32 - 32 - - - - - - - true - - - @@ -360,6 +194,219 @@ + + + + 440 + 400 + 161 + 41 + + + + + MS Shell Dlg + 14 + 50 + false + false + false + false + + + + Discard + + + false + + + false + + + + + + 440 + 340 + 161 + 41 + + + + + MS Shell Dlg + 14 + 50 + false + false + false + false + + + + Save + + + false + + + false + + + + + + 420 + 110 + 181 + 221 + + + + Fort + + + + + 10 + 20 + 161 + 21 + + + + -1 + + + 65535 + + + + + + 10 + 50 + 161 + 161 + + + + + + + + + + true + + + + + + + 420 + 10 + 181 + 91 + + + + Grave + + + + + 10 + 20 + 161 + 21 + + + + -1 + + + 65535 + + + + + + 80 + 50 + 32 + 32 + + + + + + + true + + + + + + + 200 + 10 + 201 + 381 + + + + Key binds + + + + + 10 + 20 + 181 + 351 + + + + 0 + + + 1 + + + + + 0 + 0 + 181 + 297 + + + + Actions + + + + + Weapons + + + + + + 0 + 0 + 163 + 252 + + + + Other + + + + @@ -595,6 +642,78 @@ + + + + + 240 + 330 + 161 + 41 + + + + + MS Shell Dlg + 14 + 50 + false + false + false + false + + + + Play demo + + + false + + + false + + + + + + 240 + 380 + 161 + 41 + + + + + MS Shell Dlg + 14 + 50 + false + false + false + false + + + + Back + + + false + + + false + + + + + + 170 + 10 + 311 + 311 + + + + @@ -686,36 +805,6 @@ false - - - - 230 - 270 - 161 - 41 - - - - - MS Shell Dlg - 14 - 50 - false - false - false - false - - - - Demos - - - false - - - false - - @@ -776,6 +865,36 @@ false + + + + 230 + 270 + 161 + 41 + + + + + MS Shell Dlg + 14 + 50 + false + false + false + false + + + + Demos + + + false + + + false + + diff -r 27aa8030322b -r e32fa14529f8 QTfrontend/team.cpp --- a/QTfrontend/team.cpp Tue Dec 06 19:46:40 2005 +0000 +++ b/QTfrontend/team.cpp Wed Dec 07 20:36:55 2005 +0000 @@ -1,165 +1,165 @@ -/* - * Hedgewars, a worms-like game - * Copyright (c) 2005 Andrey Korotaev - * - * Distributed under the terms of the BSD-modified licence: - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * with the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include "team.h" -#include "hwform.h" - -HWTeam::HWTeam(const QString & teamname) -{ - TeamName = teamname; - for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i); - Grave = "Simple"; - Fort = "Barrelhouse"; - for(int i = 0; i < BINDS_NUMBER; i++) - { - binds[i].action = cbinds[i].action; - binds[i].strbind = cbinds[i].strbind; - } - dir = ""; -} - -bool HWTeam::LoadFromFile() -{ - QFile cfgfile(dir + "/" + TeamName + ".cfg"); - if (!cfgfile.open(QIODevice::ReadOnly)) return false; - QTextStream stream(&cfgfile); - stream.setCodec("UTF-8"); - QString str; - QString action; - - while (!stream.atEnd()) - { - str = stream.readLine(); - if (str.startsWith(";")) continue; - if (str.startsWith("name team ")) - { - str.remove(0, 10); - TeamName = str; - } else - if (str.startsWith("name hh")) - { - str.remove(0, 7); - long i = str.left(1).toLong(); - if ((i < 0) || (i > 7)) continue; - str.remove(0, 2); - HHName[i] = str; - } else - if (str.startsWith("grave ")) - { - str.remove(0, 6); - Grave = str; - } else - if (str.startsWith("fort ")) - { - str.remove(0, 5); - Fort = str; - } else - if (str.startsWith("bind ")) - { - str.remove(0, 5); - action = str.section(' ', 1); - str = str.section(' ', 0, 0); - str.truncate(15); - for (int i = 0; i < BINDS_NUMBER; i++) - if (action == binds[i].action) - { - binds[i].strbind = str; - break; - } - } - } - cfgfile.close(); - return true; -} - -bool HWTeam::SaveToFile() -{ - QFile cfgfile(dir + "/" + TeamName + ".cfg"); - if (!cfgfile.open(QIODevice::WriteOnly)) return false; - QTextStream stream(&cfgfile); - stream.setCodec("UTF-8"); - stream << "; Generated by Hedgewars, do not modify" << endl; - stream << "name team " << TeamName << endl; - for (int i = 0; i < BINDS_NUMBER; i++) - stream << "name hh" << i << " " << HHName[i] << endl; - stream << "grave " << Grave << endl; - stream << "fort " << Fort << endl; - for(int i = 0; i < BINDS_NUMBER; i++) - { - stream << "bind " << binds[i].strbind << " " << binds[i].action << endl; - } - cfgfile.close(); - return true; -} - -void HWTeam::SetToPage(HWForm * hwform) -{ - hwform->TeamNameEdit->setText(TeamName); - for(int i = 0; i < 8; i++) - { - hwform->HHNameEdit[i]->setText(HHName[i]); - } - hwform->ui.CBGrave->setCurrentIndex(hwform->ui.CBGrave->findText(Grave)); - hwform->CBGrave_activated(Grave); - - hwform->ui.CBFort->setCurrentIndex(hwform->ui.CBFort->findText(Fort)); - hwform->CBFort_activated(Fort); - - for(int i = 0; i < BINDS_NUMBER; i++) - { - hwform->CBBind[i]->setCurrentIndex(hwform->CBBind[i]->findText(binds[i].strbind)); - } -} - -void HWTeam::GetFromPage(HWForm * hwform) -{ - TeamName = hwform->TeamNameEdit->text(); - for(int i = 0; i < 8; i++) - { - HHName[i] = hwform->HHNameEdit[i]->text(); - } - - Grave = hwform->ui.CBGrave->currentText(); - Fort = hwform->ui.CBFort->currentText(); - for(int i = 0; i < 8; i++) - { - binds[i].strbind = hwform->CBBind[i]->currentText(); - } -} - -void HWTeam::SetCfgDir(const QString & dir) -{ - this->dir = dir; -} +/* + * Hedgewars, a worms-like game + * Copyright (c) 2005 Andrey Korotaev + * + * Distributed under the terms of the BSD-modified licence: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * with the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include "team.h" +#include "hwform.h" + +HWTeam::HWTeam(const QString & teamname) +{ + TeamName = teamname; + for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i); + Grave = "Simple"; + Fort = "Barrelhouse"; + for(int i = 0; i < BINDS_NUMBER; i++) + { + binds[i].action = cbinds[i].action; + binds[i].strbind = cbinds[i].strbind; + } + dir = ""; +} + +bool HWTeam::LoadFromFile() +{ + QFile cfgfile(dir + "/" + TeamName + ".cfg"); + if (!cfgfile.open(QIODevice::ReadOnly)) return false; + QTextStream stream(&cfgfile); + stream.setCodec("UTF-8"); + QString str; + QString action; + + while (!stream.atEnd()) + { + str = stream.readLine(); + if (str.startsWith(";")) continue; + if (str.startsWith("name team ")) + { + str.remove(0, 10); + TeamName = str; + } else + if (str.startsWith("name hh")) + { + str.remove(0, 7); + long i = str.left(1).toLong(); + if ((i < 0) || (i > 7)) continue; + str.remove(0, 2); + HHName[i] = str; + } else + if (str.startsWith("grave ")) + { + str.remove(0, 6); + Grave = str; + } else + if (str.startsWith("fort ")) + { + str.remove(0, 5); + Fort = str; + } else + if (str.startsWith("bind ")) + { + str.remove(0, 5); + action = str.section(' ', 1); + str = str.section(' ', 0, 0); + str.truncate(15); + for (int i = 0; i < BINDS_NUMBER; i++) + if (action == binds[i].action) + { + binds[i].strbind = str; + break; + } + } + } + cfgfile.close(); + return true; +} + +bool HWTeam::SaveToFile() +{ + QFile cfgfile(dir + "/" + TeamName + ".cfg"); + if (!cfgfile.open(QIODevice::WriteOnly)) return false; + QTextStream stream(&cfgfile); + stream.setCodec("UTF-8"); + stream << "; Generated by Hedgewars, do not modify" << endl; + stream << "name team " << TeamName << endl; + for (int i = 0; i < 8; i++) + stream << "name hh" << i << " " << HHName[i] << endl; + stream << "grave " << Grave << endl; + stream << "fort " << Fort << endl; + for(int i = 0; i < BINDS_NUMBER; i++) + { + stream << "bind " << binds[i].strbind << " " << binds[i].action << endl; + } + cfgfile.close(); + return true; +} + +void HWTeam::SetToPage(HWForm * hwform) +{ + hwform->TeamNameEdit->setText(TeamName); + for(int i = 0; i < 8; i++) + { + hwform->HHNameEdit[i]->setText(HHName[i]); + } + hwform->ui.CBGrave->setCurrentIndex(hwform->ui.CBGrave->findText(Grave)); + hwform->CBGrave_activated(Grave); + + hwform->ui.CBFort->setCurrentIndex(hwform->ui.CBFort->findText(Fort)); + hwform->CBFort_activated(Fort); + + for(int i = 0; i < BINDS_NUMBER; i++) + { + hwform->CBBind[i]->setCurrentIndex(hwform->CBBind[i]->findText(binds[i].strbind)); + } +} + +void HWTeam::GetFromPage(HWForm * hwform) +{ + TeamName = hwform->TeamNameEdit->text(); + for(int i = 0; i < 8; i++) + { + HHName[i] = hwform->HHNameEdit[i]->text(); + } + + Grave = hwform->ui.CBGrave->currentText(); + Fort = hwform->ui.CBFort->currentText(); + for(int i = 0; i < 8; i++) + { + binds[i].strbind = hwform->CBBind[i]->currentText(); + } +} + +void HWTeam::SetCfgDir(const QString & dir) +{ + this->dir = dir; +}