- Some changes to make build process clear
authorunc0rr
Mon, 20 Aug 2007 17:49:39 +0000
changeset 579 94db15de0392
parent 578 6b0af3860192
child 580 d3ebf84e9fad
- Some changes to make build process clear - There could be 1-8 hedgehogs (was 3-8) in team - Start implementing 'Load' page
QTfrontend/CMakeLists.txt
QTfrontend/hedgehogerWidget.cpp
QTfrontend/hedgewars.pro
QTfrontend/hwconsts.cpp.in
QTfrontend/hwconsts.h.in
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/main.cpp
QTfrontend/pages.cpp
QTfrontend/pages.h
QTfrontend/playrecordpage.cpp
QTfrontend/playrecordpage.h
QTfrontend/ui_hwform.cpp
--- a/QTfrontend/CMakeLists.txt	Mon Aug 20 16:05:59 2007 +0000
+++ b/QTfrontend/CMakeLists.txt	Mon Aug 20 17:49:39 2007 +0000
@@ -33,10 +33,8 @@
 	endif(DEFINED DATA_INSTALL_DIR)
 endif(WIN32 AND NOT UNIX)
 
-configure_file(${hedgewars_SOURCE_DIR}/QTfrontend/main.cpp.in 
-	${hedgewars_SOURCE_DIR}/QTfrontend/main.cpp)
-configure_file(${hedgewars_SOURCE_DIR}/QTfrontend/hwconsts.h.in 
-	${hedgewars_SOURCE_DIR}/QTfrontend/hwconsts.h)
+configure_file(${hedgewars_SOURCE_DIR}/QTfrontend/hwconsts.cpp.in 
+	${hedgewars_SOURCE_DIR}/QTfrontend/hwconsts.cpp)
 
 set(hwfr_src 
 	game.cpp
@@ -66,7 +64,9 @@
 	netudpwidget.cpp
 	chatwidget.cpp
 	binds.cpp
-	SDLs.cpp)
+	SDLs.cpp
+	playrecordpage.cpp
+	hwconsts.cpp)
 
 if (WIN32)
 	set(hwfr_src ${hwfr_src} res/hedgewars.rc)
@@ -96,13 +96,15 @@
 	netudpserver.h
 	netudpwidget.h
 	chatwidget.h
-	SDLs.h)
+	SDLs.h
+	playrecordpage.h)
 
 set(hwfr_hdrs
 	binds.h
 	ui_hwform.h
 	predefteams.h
 	KB.h
+	hwconsts.h
 )
 
 set(hwfr_rez
--- a/QTfrontend/hedgehogerWidget.cpp	Mon Aug 20 16:05:59 2007 +0000
+++ b/QTfrontend/hedgehogerWidget.cpp	Mon Aug 20 17:49:39 2007 +0000
@@ -57,7 +57,7 @@
     }
   } else if (event->button()==Qt::RightButton) {
     event->accept();
-    if(numHedgehogs > 3) {
+    if(numHedgehogs > 1) {
       numHedgehogs--;
       pOurFrameTeams->overallHedgehogs--;
       emit hedgehogsNumChanged();
--- a/QTfrontend/hedgewars.pro	Mon Aug 20 16:05:59 2007 +0000
+++ b/QTfrontend/hedgewars.pro	Mon Aug 20 17:49:39 2007 +0000
@@ -39,7 +39,9 @@
            netudpserver.h \
            netudpwidget.h \
            chatwidget.h \
-           SDLs.h
+           SDLs.h \
+           playrecordpage.h \
+           hwconsts.h
            
            
 SOURCES += binds.cpp \
@@ -69,7 +71,9 @@
            netudpserver.cpp \
            netudpwidget.cpp \
            chatwidget.cpp \
-           SDLs.cpp
+           SDLs.cpp \
+           playrecordpage.cpp \
+           hwconsts.cpp
 
 TRANSLATIONS += ../share/hedgewars/Data/Locale/hedgewars_ru.ts
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/hwconsts.cpp.in	Mon Aug 20 17:49:39 2007 +0000
@@ -0,0 +1,28 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2007 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include "hwconsts.h"
+
+QString * cProtoVer = new QString("${HEDGEWARS_PROTO_VER}");
+QString * cDataDir = new QString("${HEDGEWARS_DATADIR}");
+
+QDir * bindir = new QDir("${HEDGEWARS_BINDIR}");
+QDir * cfgdir = new QDir();
+QDir * datadir = new QDir();
+
+QStringList * Themes;
--- a/QTfrontend/hwconsts.h.in	Mon Aug 20 16:05:59 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/*
- * Hedgewars, a worms-like game
- * Copyright (c) 2005-2007 Andrey Korotaev <unC0Rr@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#include <QDir>
-#include <QString>
-
-extern QDir * cfgdir;
-extern QDir * datadir;
-extern QDir * bindir;
-extern QStringList * Themes;
-
-const QString cProtoVer("${HEDGEWARS_PROTO_VER}");
--- a/QTfrontend/hwform.cpp	Mon Aug 20 16:05:59 2007 +0000
+++ b/QTfrontend/hwform.cpp	Mon Aug 20 17:49:39 2007 +0000
@@ -43,6 +43,7 @@
 #include "netudpserver.h"
 #include "netudpwidget.h"
 #include "chatwidget.h"
+#include "playrecordpage.h"
 
 HWForm::HWForm(QWidget *parent)
   : QMainWindow(parent), pnetserver(0), pUdpServer(0), editedTeam(0)
@@ -56,6 +57,7 @@
 	connect(ui.pageMain->BtnSinglePlayer,	SIGNAL(clicked()),	this, SLOT(GoToSinglePlayer()));
 	connect(ui.pageMain->BtnSetup,	SIGNAL(clicked()),	this, SLOT(GoToSetup()));
 	connect(ui.pageMain->BtnMultiplayer,	SIGNAL(clicked()),	this, SLOT(GoToMultiplayer()));
+	connect(ui.pageMain->BtnLoad,	SIGNAL(clicked()),	this, SLOT(GoToSaves()));
 	connect(ui.pageMain->BtnDemos,	SIGNAL(clicked()),	this, SLOT(GoToDemos()));
 	connect(ui.pageMain->BtnNet,	SIGNAL(clicked()),	this, SLOT(GoToNet()));
 	connect(ui.pageMain->BtnInfo,	SIGNAL(clicked()),	this, SLOT(GoToInfo()));
@@ -149,15 +151,23 @@
 	GoToPage(ID_PAGE_MULTIPLAYER);
 }
 
+void HWForm::GoToSaves()
+{
+	QDir tmpdir;
+	tmpdir.cd(cfgdir->absolutePath());
+	tmpdir.cd("Saves");
+	ui.pagePlayDemo->FillFromDir(tmpdir);
+
+	GoToPage(ID_PAGE_DEMOS);
+}
+
 void HWForm::GoToDemos()
 {
 	QDir tmpdir;
 	tmpdir.cd(cfgdir->absolutePath());
 	tmpdir.cd("Demos");
-	tmpdir.setFilter(QDir::Files);
-	ui.pagePlayDemo->DemosList->clear();
-	ui.pagePlayDemo->DemosList->addItems(tmpdir.entryList(QStringList("*.hwd_" + cProtoVer))
-			.replaceInStrings(QRegExp("^(.*).hwd_" + cProtoVer), "\\1"));
+	ui.pagePlayDemo->FillFromDir(tmpdir);
+
 	GoToPage(ID_PAGE_DEMOS);
 }
 
@@ -298,7 +308,7 @@
 		return ;
 	}
 	CreateGame(0, 0);
-	game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + cProtoVer);
+	game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + *cProtoVer);
 }
 
 void HWForm::NetConnectServer()
@@ -500,12 +510,12 @@
 	{
 		demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD"));
 		demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD"));
-		filename = cfgdir->absolutePath() + "/Demos/LastRound.hwd_" + cProtoVer;
+		filename = cfgdir->absolutePath() + "/Demos/LastRound.hwd_" + *cProtoVer;
 	} else
 	{
 		demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS"));
 		demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS"));
-		filename = cfgdir->absolutePath() + "/Saves/LastRound.hws_" + cProtoVer;
+		filename = cfgdir->absolutePath() + "/Saves/LastRound.hws_" + *cProtoVer;
 	}
 
 
--- a/QTfrontend/hwform.h	Mon Aug 20 16:05:59 2007 +0000
+++ b/QTfrontend/hwform.h	Mon Aug 20 17:49:39 2007 +0000
@@ -46,6 +46,7 @@
 	void GoToSinglePlayer();
 	void GoToSetup();
 	void GoToMultiplayer();
+	void GoToSaves();
 	void GoToDemos();
 	void GoToNet();
 	void GoToInfo();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/main.cpp	Mon Aug 20 17:49:39 2007 +0000
@@ -0,0 +1,95 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2005-2007 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <QApplication>
+#include <QTranslator>
+#include <QLocale>
+#include <QMessageBox>
+#include <QFileInfo>
+#include <QDateTime>
+#include <QTextStream>
+#include "hwform.h"
+#include "hwconsts.h"
+
+bool checkForDir(const QString & dir)
+{
+	QDir tmpdir;
+	if (!tmpdir.exists(dir))
+		if (!tmpdir.mkdir(dir))
+		{
+			QMessageBox::critical(0,
+					QObject::tr("Error"),
+					QObject::tr("Cannot create directory %1").arg(dir),
+					QObject::tr("OK"));
+			return false;
+		}
+	return true;
+}
+
+int main(int argc, char *argv[])
+{
+	QApplication app(argc, argv);
+
+	QDateTime now = QDateTime::currentDateTime();
+	QDateTime zero;
+	srand(now.secsTo(zero));
+
+	Q_INIT_RESOURCE(hedgewars);
+
+	bindir->cd("bin"); // workaround over NSIS installer
+
+	cfgdir->setPath(cfgdir->homePath());
+	if (checkForDir(cfgdir->absolutePath() + "/.hedgewars"))
+	{
+		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Demos");
+		checkForDir(cfgdir->absolutePath() + "/.hedgewars/Saves");
+	}
+	cfgdir->cd(".hedgewars");
+
+	datadir->cd(bindir->absolutePath());
+	datadir->cd(*cDataDir);
+	if(!datadir->cd("hedgewars/Data")) {
+		QMessageBox::critical(0, QMessageBox::tr("Error"),
+			QMessageBox::tr("Failed to open data directory:\n%1\n"
+					"Please check your installation").
+					arg(datadir->absolutePath()+"/hedgewars/Data"));
+		return 1;
+	}
+
+	QTranslator Translator;
+	Translator.load(datadir->absolutePath() + "/Locale/hedgewars_" + QLocale::system().name());
+	app.installTranslator(&Translator);
+
+	Themes = new QStringList();
+	QFile themesfile(datadir->absolutePath() + "/Themes/themes.cfg");
+	if (themesfile.open(QIODevice::ReadOnly)) {
+		QTextStream stream(&themesfile);
+		QString str;
+		while (!stream.atEnd())
+		{
+			Themes->append(stream.readLine());
+		}
+		themesfile.close();
+	} else {
+		QMessageBox::critical(0, "Error", "Cannot access themes.cfg", "OK");
+	}
+
+	HWForm *Form = new HWForm();
+	Form->show();
+	return app.exec();
+}
--- a/QTfrontend/pages.cpp	Mon Aug 20 16:05:59 2007 +0000
+++ b/QTfrontend/pages.cpp	Mon Aug 20 17:49:39 2007 +0000
@@ -42,6 +42,7 @@
 #include "netudpwidget.h"
 #include "chatwidget.h"
 #include "SDLs.h"
+#include "playrecordpage.h"
 
 PageMain::PageMain(QWidget* parent) : QWidget(parent)
 {
@@ -70,23 +71,29 @@
 	BtnNet->setText(QPushButton::tr("Net game"));
 	pageLayout->addWidget(BtnNet, 3, 1);
 
+	BtnLoad = new QPushButton(this);
+	BtnLoad->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+	BtnLoad->setFont(*font14);
+	BtnLoad->setText(QPushButton::tr("Load"));
+	pageLayout->addWidget(BtnLoad, 4, 1);
+
 	BtnDemos = new QPushButton(this);
 	BtnDemos->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 	BtnDemos->setFont(*font14);
 	BtnDemos->setText(QPushButton::tr("Demos"));
-	pageLayout->addWidget(BtnDemos, 4, 1);
+	pageLayout->addWidget(BtnDemos, 5, 1);
 
 	BtnSetup = new QPushButton(this);
 	BtnSetup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 	BtnSetup->setFont(*font14);
 	BtnSetup->setText(QPushButton::tr("Setup"));
-	pageLayout->addWidget(BtnSetup, 5, 1);
+	pageLayout->addWidget(BtnSetup, 6, 1);
 
 	BtnInfo = new QPushButton(this);
 	BtnInfo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 	BtnInfo->setFont(*font14);
 	BtnInfo->setText(QPushButton::tr("About"));
-	pageLayout->addWidget(BtnInfo, 6, 1);
+	pageLayout->addWidget(BtnInfo, 7, 1);
 
 	BtnExit = new QPushButton(parent);
 	BtnExit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@@ -306,30 +313,6 @@
 	pageLayout->addWidget(BtnStartMPGame, 1, 3);
 }
 
-PagePlayDemo::PagePlayDemo(QWidget* parent) : QWidget(parent)
-{
-	QFont * font14 = new QFont("MS Shell Dlg", 14);
-	QGridLayout * pageLayout = new QGridLayout(this);
-	pageLayout->setColumnStretch(0, 1);
-	pageLayout->setColumnStretch(1, 2);
-	pageLayout->setColumnStretch(2, 1);
-
-	BtnBack = new QPushButton(this);
-	BtnBack->setFont(*font14);
-	BtnBack->setText(QPushButton::tr("Back"));
-	pageLayout->addWidget(BtnBack, 1, 0);
-
-	BtnPlayDemo	= new QPushButton(this);
-	BtnPlayDemo->setGeometry(QRect(240,	330, 161, 41));
-	BtnPlayDemo->setFont(*font14);
-	BtnPlayDemo->setText(QPushButton::tr("Play demo"));
-	pageLayout->addWidget(BtnPlayDemo, 1, 2);
-
-	DemosList =	new QListWidget(this);
-	DemosList->setGeometry(QRect(170, 10, 311, 311));
-	pageLayout->addWidget(DemosList, 0, 1);
-}
-
 PageOptions::PageOptions(QWidget* parent) : QWidget(parent)
 {
 	QFont * font14 = new QFont("MS Shell Dlg", 14);
--- a/QTfrontend/pages.h	Mon Aug 20 16:05:59 2007 +0000
+++ b/QTfrontend/pages.h	Mon Aug 20 17:49:39 2007 +0000
@@ -54,6 +54,7 @@
 	QPushButton *BtnMultiplayer;
 	QPushButton *BtnNet;
 	QPushButton *BtnSetup;
+	QPushButton *BtnLoad;
 	QPushButton *BtnDemos;
 	QPushButton *BtnInfo;
 	QPushButton *BtnExit;
@@ -122,18 +123,6 @@
 	QPushButton *BtnStartMPGame;
 };
 
-class PagePlayDemo : public QWidget
-{
-	Q_OBJECT
-
-public:
-	PagePlayDemo(QWidget* parent = 0);
-
-	QPushButton *BtnBack;
-	QPushButton *BtnPlayDemo;
-	QListWidget *DemosList;
-};
-
 class PageOptions : public QWidget
 {
 	Q_OBJECT
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/playrecordpage.cpp	Mon Aug 20 17:49:39 2007 +0000
@@ -0,0 +1,59 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2006, 2007 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <QFont>
+#include <QGridLayout>
+#include <QPushButton>
+#include <QListWidget>
+
+#include "hwconsts.h"
+#include "playrecordpage.h"
+
+PagePlayDemo::PagePlayDemo(QWidget* parent) : QWidget(parent)
+{
+	QFont * font14 = new QFont("MS Shell Dlg", 14);
+	QGridLayout * pageLayout = new QGridLayout(this);
+	pageLayout->setColumnStretch(0, 1);
+	pageLayout->setColumnStretch(1, 2);
+	pageLayout->setColumnStretch(2, 1);
+
+	BtnBack = new QPushButton(this);
+	BtnBack->setFont(*font14);
+	BtnBack->setText(QPushButton::tr("Back"));
+	pageLayout->addWidget(BtnBack, 1, 0);
+
+	BtnPlayDemo	= new QPushButton(this);
+	BtnPlayDemo->setGeometry(QRect(240,	330, 161, 41));
+	BtnPlayDemo->setFont(*font14);
+	BtnPlayDemo->setText(QPushButton::tr("Play demo"));
+	pageLayout->addWidget(BtnPlayDemo, 1, 2);
+
+	DemosList =	new QListWidget(this);
+	DemosList->setGeometry(QRect(170, 10, 311, 311));
+	pageLayout->addWidget(DemosList, 0, 1);
+}
+
+void PagePlayDemo::FillFromDir(QDir dir)
+{
+	dir.setFilter(QDir::Files);
+	DemosList->clear();
+	DemosList->addItems(dir.entryList(QStringList("*.hwd_" + *cProtoVer))
+			.replaceInStrings(QRegExp("^(.*).hwd_" + *cProtoVer + "$"), "\\1"));
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/playrecordpage.h	Mon Aug 20 17:49:39 2007 +0000
@@ -0,0 +1,43 @@
+/*
+ * Hedgewars, a worms-like game
+ * Copyright (c) 2006, 2007 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef PLAYRECORDPAGE_H
+#define PLAYRECORDPAGE_H
+
+#include <QWidget>
+#include <QDir>
+
+class QPushButton;
+class QListWidget;
+
+class PagePlayDemo : public QWidget
+{
+	Q_OBJECT
+
+public:
+	PagePlayDemo(QWidget* parent = 0);
+
+	void FillFromDir(QDir dir);
+
+	QPushButton *BtnBack;
+	QPushButton *BtnPlayDemo;
+	QListWidget *DemosList;
+};
+
+
+#endif // PLAYRECORDPAGE_H
--- a/QTfrontend/ui_hwform.cpp	Mon Aug 20 16:05:59 2007 +0000
+++ b/QTfrontend/ui_hwform.cpp	Mon Aug 20 17:49:39 2007 +0000
@@ -23,6 +23,7 @@
 
 #include "ui_hwform.h"
 #include "pages.h"
+#include "playrecordpage.h"
 
 void Ui_HWForm::setupUi(QMainWindow *HWForm)
 {