# HG changeset patch # User displacer # Date 1159127476 0 # Node ID 92cff18a3ab6758ef54ad1e4bd1f25132a1c6f03 # Parent f864a68e512c4f268cca1b2f0478a1af98e6cbd4 first map preview added (still experimental) diff -r f864a68e512c -r 92cff18a3ab6 QTfrontend/CMakeLists.txt --- a/QTfrontend/CMakeLists.txt Sun Sep 24 18:55:06 2006 +0000 +++ b/QTfrontend/CMakeLists.txt Sun Sep 24 19:51:16 2006 +0000 @@ -26,7 +26,9 @@ gamecfgwidget.cpp pages.cpp SquareLabel.cpp - hedgehogerWidget.cpp) + hedgehogerWidget.cpp + hwmap.cpp + mapContainer.cpp) if (WIN32) set(hwfr_src ${hwfr_src} res/hedgewars.rc) @@ -46,7 +48,9 @@ predefteams.h pages.h SquareLabel.h - hedgehogerWidget.h) + hedgehogerWidget.h + hwmap.h + mapContainer.h) set(hwfr_rez diff -r f864a68e512c -r 92cff18a3ab6 QTfrontend/gamecfgwidget.cpp --- a/QTfrontend/gamecfgwidget.cpp Sun Sep 24 18:55:06 2006 +0000 +++ b/QTfrontend/gamecfgwidget.cpp Sun Sep 24 19:51:16 2006 +0000 @@ -34,10 +34,14 @@ #include #include "gamecfgwidget.h" -GameCFGWidget::GameCFGWidget(QWidget* parent) : QWidget(parent) +GameCFGWidget::GameCFGWidget(QWidget* parent) : + QWidget(parent), mainLayout(this) { CB_mode_Forts = new QCheckBox(this); CB_mode_Forts->setText(QCheckBox::tr("Forts mode")); + mainLayout.addWidget(CB_mode_Forts); + pMapContainer=new HWMapContainer(this); + mainLayout.addWidget(pMapContainer, 80); } quint32 GameCFGWidget::getGameFlags() @@ -47,3 +51,8 @@ result |= 1; return result; } + +QString GameCFGWidget::getCurrentSeed() const +{ + return pMapContainer->getCurrentSeed(); +} diff -r f864a68e512c -r 92cff18a3ab6 QTfrontend/gamecfgwidget.h --- a/QTfrontend/gamecfgwidget.h Sun Sep 24 18:55:06 2006 +0000 +++ b/QTfrontend/gamecfgwidget.h Sun Sep 24 19:51:16 2006 +0000 @@ -36,7 +36,9 @@ #include #include +#include +#include "mapContainer.h" class GameCFGWidget : public QWidget { @@ -45,11 +47,14 @@ public: GameCFGWidget(QWidget* parent=0); quint32 getGameFlags(); + QString getCurrentSeed() const; private slots: private: QCheckBox * CB_mode_Forts; + QVBoxLayout mainLayout; + HWMapContainer* pMapContainer; }; #endif // GAMECONFIGWIDGET_H diff -r f864a68e512c -r 92cff18a3ab6 QTfrontend/hedgewars.pro --- a/QTfrontend/hedgewars.pro Sun Sep 24 18:55:06 2006 +0000 +++ b/QTfrontend/hedgewars.pro Sun Sep 24 19:51:16 2006 +0000 @@ -26,7 +26,9 @@ predefteams.h \ pages.h \ SquareLabel.h \ - hedgehogerWidget.h + hedgehogerWidget.h \ + hwmap.h \ + mapContainer.h SOURCES += game.cpp \ main.cpp \ @@ -42,7 +44,9 @@ gamecfgwidget.cpp \ pages.cpp \ SquareLabel.cpp \ - hedgehogerWidget.cpp + hedgehogerWidget.cpp \ + hwmap.cpp \ + mapContainer.cpp TRANSLATIONS += translations/hedgewars_ru.ts diff -r f864a68e512c -r 92cff18a3ab6 QTfrontend/hwmap.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/hwmap.cpp Sun Sep 24 19:51:16 2006 +0000 @@ -0,0 +1,88 @@ +#include "hwmap.h" + +#include "hwconsts.h" + +#include + +HWMap::HWMap() : + m_isStarted(false) +{ +} + +void HWMap::getImage(std::string seed) +{ + m_seed=seed; + Start(); +} + +void HWMap::ClientDisconnect() +{ + QImage im((uchar*)(const char*)readbuffer, 256, 128, QImage::Format_Mono); + im.setNumColors(2); + + IPCSocket->close(); + IPCSocket->deleteLater(); + IPCSocket = 0; + IPCServer->close(); + deleteLater(); + + emit ImageReceived(im); +} + +void HWMap::ClientRead() +{ + readbuffer.append(IPCSocket->readAll()); +} + +void HWMap::SendToClientFirst() +{ + std::string toSend=std::string("eseed ")+m_seed; + char ln=(char)toSend.length(); + IPCSocket->write(&ln, 1); + IPCSocket->write(toSend.c_str(), ln); + + IPCSocket->write("\x01!", 2); +} + +void HWMap::NewConnection() +{ + QTcpSocket * client = IPCServer->nextPendingConnection(); + if(!IPCSocket) { + IPCServer->close(); + IPCSocket = client; + connect(client, SIGNAL(disconnected()), this, SLOT(ClientDisconnect())); + connect(client, SIGNAL(readyRead()), this, SLOT(ClientRead())); + SendToClientFirst(); + } else { + qWarning("2nd IPC client?!"); + client->disconnectFromHost(); + } +} + +void HWMap::StartProcessError(QProcess::ProcessError error) +{ + QMessageBox::critical(0, tr("Error"), + tr("Unable to run engine: %1 (") + .arg(error) + bindir->absolutePath() + "/hwengine)"); +} + +void HWMap::Start() +{ + IPCServer = new QTcpServer(this); + connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); + IPCServer->setMaxPendingConnections(1); + IPCSocket = 0; + if (!IPCServer->listen(QHostAddress::LocalHost, IPC_PORT)) { + QMessageBox::critical(0, tr("Error"), + tr("Unable to start the server: %1.") + .arg(IPCServer->errorString())); + } + + QProcess * process; + QStringList arguments; + process = new QProcess; + connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError))); + arguments << "46631"; + arguments << "landpreview"; + process->start(bindir->absolutePath() + "/hwengine", arguments); +} diff -r f864a68e512c -r 92cff18a3ab6 QTfrontend/hwmap.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/hwmap.h Sun Sep 24 19:51:16 2006 +0000 @@ -0,0 +1,80 @@ +/* + * Hedgewars, a worms-like game + * Copyright (c) 2006 Igor Ulyanov + * + * 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 _HWMAP_INCLUDED +#define _HWMAP_INCLUDED + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "game.h" + +#include + +class HWMap : public QObject +{ + Q_OBJECT + + public: + HWMap(); + void getImage(std::string seed); + + signals: + void ImageReceived(const QImage newImage); + + private: + bool m_isStarted; + std::string m_seed; + QTcpServer * IPCServer; + QTcpSocket * IPCSocket; + + QByteArray readbuffer; + + void Start(); + + void SendToClientFirst(); + + private slots: + void NewConnection(); + void ClientDisconnect(); + void ClientRead(); + void StartProcessError(QProcess::ProcessError error); +}; + +#endif // _HWMAP_INCLUDED diff -r f864a68e512c -r 92cff18a3ab6 QTfrontend/mapContainer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/mapContainer.cpp Sun Sep 24 19:51:16 2006 +0000 @@ -0,0 +1,81 @@ +/* + * Hedgewars, a worms-like game + * Copyright (c) 2006 Igor Ulyanov + * + * 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 "mapContainer.h" + +#include +#include +#include + +HWMapContainer::HWMapContainer(QWidget * parent) : + QWidget(parent), mainLayout(this) +{ + imageButt=new QPushButton(this); + imageButt->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + mainLayout.addWidget(imageButt); + connect(imageButt, SIGNAL(clicked()), this, SLOT(changeImage())); + changeImage(); +} + +void HWMapContainer::setImage(const QImage newImage) +{ + // unfortunately QPixmap::fromImage doesn't work + // with this image in current (4.1.4) version of QT + QByteArray ba; + QBuffer buffer(&ba); + buffer.open(QIODevice::ReadWrite); + newImage.save(&buffer, "XBM"); + QPixmap px; + px.loadFromData(buffer.data(), "XBM"); + + imageButt->setIcon(px); + imageButt->setIconSize(QSize(128, 256)); +} + +void HWMapContainer::changeImage() +{ + m_seed = QUuid::createUuid().toString(); + pMap=new HWMap(); + connect(pMap, SIGNAL(ImageReceived(const QImage)), this, SLOT(setImage(const QImage))); + pMap->getImage(m_seed.toStdString()); +} + +QString HWMapContainer::getCurrentSeed() const +{ + return m_seed; +} + +void HWMapContainer::resizeEvent ( QResizeEvent * event ) +{ + //imageButt->setIconSize(imageButt->size()); +} diff -r f864a68e512c -r 92cff18a3ab6 QTfrontend/mapContainer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/mapContainer.h Sun Sep 24 19:51:16 2006 +0000 @@ -0,0 +1,68 @@ +/* + * Hedgewars, a worms-like game + * Copyright (c) 2006 Igor Ulyanov + * + * 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 _HWMAP_CONTAINER_INCLUDED +#define _HWMAP_CONTAINER_INCLUDED + +#include "hwmap.h" + +#include +#include + +class QPushButton; + +class HWMapContainer : public QWidget +{ + Q_OBJECT + + public: + HWMapContainer(QWidget * parent=0); + QString getCurrentSeed() const; + + public slots: + void changeImage(); + + private slots: + void setImage(const QImage newImage); + + protected: + virtual void resizeEvent ( QResizeEvent * event ); + + private: + QVBoxLayout mainLayout; + QPushButton* imageButt; + HWMap* pMap; + QString m_seed; +}; + +#endif // _HWMAP_CONTAINER_INCLUDED diff -r f864a68e512c -r 92cff18a3ab6 QTfrontend/pages.cpp --- a/QTfrontend/pages.cpp Sun Sep 24 18:55:06 2006 +0000 +++ b/QTfrontend/pages.cpp Sun Sep 24 19:51:16 2006 +0000 @@ -49,6 +49,7 @@ #include "teamselect.h" #include "gamecfgwidget.h" #include "SquareLabel.h" +#include "mapContainer.h" PageMain::PageMain(QWidget* parent) : QWidget(parent) { @@ -258,6 +259,9 @@ BtnBack->setFont(*font14); BtnBack->setText(QPushButton::tr("Back")); pageLayout->addWidget(BtnBack, 1, 0); + + //HWMapContainer* pMapContainer=new HWMapContainer(this); + //pageLayout->addWidget(pMapContainer, 1, 1); gameCFG = new GameCFGWidget(this); pageLayout->addWidget(gameCFG, 0, 0, 1, 2);