PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
authorsheepluva
Tue, 27 Sep 2011 04:31:08 +0200
changeset 6048 ae213ef7030a
parent 6046 d681b8127523
child 6050 07561ade87ca
PIMP'ed up training screen. special thanks to mikade for supplying the pics <3 not quite finished (as you'll notice) - but this sheep is heading for sleep.
QTfrontend/AbstractPage.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/pagetraining.cpp
QTfrontend/pagetraining.h
share/hedgewars/Data/Graphics/CMakeLists.txt
share/hedgewars/Data/Graphics/Missions/CMakeLists.txt
share/hedgewars/Data/Graphics/Missions/Training/Basic_Training_-_Bazooka.png
share/hedgewars/Data/Graphics/Missions/Training/Basic_Training_-_Shotgun.png
share/hedgewars/Data/Graphics/Missions/Training/Basic_Training_-_Sniper_Rifle.png
share/hedgewars/Data/Graphics/Missions/Training/CMakeLists.txt
share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_Bamboo_Thicket.png
share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_Dangerous_Ducklings.png
share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_Diver.png
share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_Newton_and_the_Hammock.png
share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_Spooky_Tree.png
share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_Teamwork.png
share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_That_Sinking_Feeling.png
--- a/QTfrontend/AbstractPage.h	Mon Sep 26 21:29:40 2011 -0400
+++ b/QTfrontend/AbstractPage.h	Tue Sep 27 04:31:08 2011 +0200
@@ -78,6 +78,7 @@
 
         virtual ~AbstractPage() {};
 
+        QPushButton * formattedButton(const QString & btname, bool hasIcon);
         QPushButton * addButton(const QString & btname, QGridLayout * grid, int wy, int wx, bool hasIcon = false);
         QPushButton * addButton(const QString & btname, QGridLayout * grid, int wy, int wx, int rowSpan, int columnSpan, bool hasIcon = false);
         QPushButton * addButton(const QString & btname, QBoxLayout * box, int where, bool hasIcon = false);
@@ -87,7 +88,6 @@
         QFont * font14;
 
     private:
-        QPushButton * formattedButton(const QString & btname, bool hasIcon);
 
         QPushButton * btnBack;
 };
--- a/QTfrontend/hwform.cpp	Mon Sep 26 21:29:40 2011 -0400
+++ b/QTfrontend/hwform.cpp	Tue Sep 27 04:31:08 2011 +0200
@@ -234,7 +234,7 @@
     connect(ui.pageSinglePlayer->BtnLoad, SIGNAL(clicked()), this, SLOT(GoToSaves()));
     connect(ui.pageSinglePlayer->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos()));
 
-    connect(ui.pageTraining->BtnStartTrain, SIGNAL(clicked()), this, SLOT(StartTraining()));
+    connect(ui.pageTraining, SIGNAL(startMission(const QString&)), this, SLOT(startTraining(const QString&)));
 
     connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign()));
     connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
@@ -1126,11 +1126,11 @@
     demofile.close();
 }
 
-void HWForm::StartTraining()
+void HWForm::startTraining(const QString & scriptName)
 {
     CreateGame(0, 0, 0);
 
-    game->StartTraining(ui.pageTraining->CBSelect->itemData(ui.pageTraining->CBSelect->currentIndex()).toString());
+    game->StartTraining(scriptName);
 }
 
 void HWForm::StartCampaign()
--- a/QTfrontend/hwform.h	Mon Sep 26 21:29:40 2011 -0400
+++ b/QTfrontend/hwform.h	Tue Sep 27 04:31:08 2011 +0200
@@ -86,7 +86,7 @@
     void DeleteWeaponSet();
     void SimpleGame();
     void PlayDemo();
-    void StartTraining();
+    void startTraining(const QString&);
     void StartCampaign();
     void NetConnect();
     void NetConnectServer(const QString & host, quint16 port);
--- a/QTfrontend/pagetraining.cpp	Mon Sep 26 21:29:40 2011 -0400
+++ b/QTfrontend/pagetraining.cpp	Tue Sep 27 04:31:08 2011 +0200
@@ -17,8 +17,10 @@
  */
 
 #include <QGridLayout>
+#include <QLabel>
+#include <QListWidget>
+#include <QListWidgetItem>
 #include <QPushButton>
-#include <QComboBox>
 
 #include "pagetraining.h"
 #include "hwconsts.h"
@@ -27,29 +29,51 @@
 {
     QGridLayout * pageLayout = new QGridLayout();
 
-    pageLayout->setColumnStretch(0, 1);
-    pageLayout->setColumnStretch(1, 2);
-    pageLayout->setColumnStretch(2, 1);
+// left column
+
+    // declare start button, caption and description
+    btnStart = formattedButton(":/res/Trainings.png", true);
+    btnStart->setToolTip(QPushButton::tr("Go!"));
+    lblCaption = new QLabel(this);
+    lblDescription = new QLabel(this);
+    lblDescription->setWordWrap(true);
+
+    // add start button, caption and description to 3 different rows
+    pageLayout->addWidget(btnStart, 0, 0);
+    pageLayout->addWidget(lblCaption, 1, 0);
+    pageLayout->addWidget(lblDescription, 2, 0);
+
+    // make first and last row stretch vertically
     pageLayout->setRowStretch(0, 1);
+    pageLayout->setRowStretch(1, 0);
     pageLayout->setRowStretch(2, 1);
 
-    CBSelect = new QComboBox(this);
+    // make both columns equal width
+    pageLayout->setColumnStretch(0, 1);
+    pageLayout->setColumnStretch(1, 1);
 
-    pageLayout->addWidget(CBSelect, 1, 1);
-    
-    BtnStartTrain = new QPushButton(this);
-    BtnStartTrain->setFont(*font14);
-    BtnStartTrain->setText(QPushButton::tr("Go!"));
-    pageLayout->addWidget(BtnStartTrain, 1, 2);
+    // center widgets within their grid cells
+    pageLayout->setAlignment(btnStart, Qt::AlignHCenter | Qt::AlignVCenter);
+    pageLayout->setAlignment(lblCaption, Qt::AlignHCenter | Qt::AlignVCenter);
+    pageLayout->setAlignment(lblDescription, Qt::AlignHCenter | Qt::AlignVCenter);
+
+// right column
+
+    lstMissions = new QListWidget(this);
+    pageLayout->addWidget(lstMissions, 0, 1, 3, 1); // spans over 3 rows
 
     return pageLayout;
 }
 
+
 void PageTraining::connectSignals()
 {
-    //TODO
+    connect(lstMissions, SIGNAL(itemSelectionChanged()), this, SLOT(updateInfo()));
+    connect(lstMissions, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(startSelected()));
+    connect(btnStart, SIGNAL(clicked()), this, SLOT(startSelected()));
 }
 
+
 PageTraining::PageTraining(QWidget* parent) : AbstractPage(parent)
 {
     initPage();
@@ -57,29 +81,32 @@
     QDir tmpdir;
     tmpdir.cd(cfgdir->absolutePath());
     tmpdir.cd("Data/Missions/Training");
-    QStringList userlist = scriptList(tmpdir);
+    QStringList missionList = scriptList(tmpdir);
+    missionList.sort();
+    missionList.replaceInStrings(QRegExp("$")," *");
 
     tmpdir.cd(datadir->absolutePath());
     tmpdir.cd("Missions/Training");
-    QStringList defaultlist = scriptList(tmpdir);
+    QStringList defaultList = scriptList(tmpdir);
+    defaultList.sort();
 
-    CBSelect->addItems(userlist);
+    missionList << defaultList;
 
     // add only default scripts that have names different from detected user scripts
-    foreach (const QString & line, defaultlist)
+    foreach (const QString & mission, missionList)
     {
-        if (!userlist.contains(line,Qt::CaseInsensitive)) CBSelect->addItem(line);
+        QListWidgetItem * item = new QListWidgetItem(mission);
+
+        // replace underscores in mission name with spaces
+        item->setText(item->text().replace("_", " "));
+
+        // store original name in data
+        item->setData(Qt::UserRole, mission);
+
+        lstMissions->addItem(item);
     }
 
-    // replace underscores with spaces in the displayed that
-    for(int i = 0; i < CBSelect->count(); i++)
-    {
-        QString text = CBSelect->itemText(i);
-        CBSelect->setItemData(i, text);
-        CBSelect->setItemText(i, text.replace("_", " "));
-//        if (userlist.contains(text))
-//            CBSelect->setItemText(i, text + " (" + AbstractPage::tr("custom") + ")");
-    }
+    updateInfo();
 }
 
 QStringList PageTraining::scriptList(const QDir & scriptDir) const
@@ -88,3 +115,33 @@
     dir.setFilter(QDir::Files);
     return dir.entryList(QStringList("*.lua")).replaceInStrings(QRegExp("^(.*)\\.lua"), "\\1");
 }
+
+
+void PageTraining::startSelected()
+{
+    emit startMission(lstMissions->currentItem()->data(Qt::UserRole).toString());
+}
+
+
+void PageTraining::updateInfo()
+{
+    if (lstMissions->currentItem())
+    {
+        QString thumbFile = datadir->absolutePath() + "/Graphics/Missions/Training/" + lstMissions->currentItem()->data(Qt::UserRole).toString() + ".png";
+        if (QFile::exists(thumbFile))
+            btnStart->setIcon(QIcon(thumbFile));
+        else
+            btnStart->setIcon(QIcon(":/res/Trainings.png"));
+
+        lblCaption->setText(lstMissions->currentItem()->text());
+        // TODO load mission description from file
+        lblDescription->setText("< Imagine\nMission\nDescription\nhere >\n\nThank you.");
+    }
+    else
+    {
+        btnStart->setIcon(QIcon(":/res/Trainings.png"));
+        lblCaption->setText(tr("Select a mission on the right -->"));
+        // TODO better text and tr()
+        lblDescription->setText("Welcome to the Training screen.\n\n\n...\nWHAT?\nIt's not finished yet...");
+    }
+}
--- a/QTfrontend/pagetraining.h	Mon Sep 26 21:29:40 2011 -0400
+++ b/QTfrontend/pagetraining.h	Tue Sep 27 04:31:08 2011 +0200
@@ -30,15 +30,31 @@
 public:
     PageTraining(QWidget* parent = 0);
 
-    QPushButton *BtnStartTrain;
-    QComboBox   *CBSelect;
+
+signals:
+    void startMission(const QString & scriptName);
+
 
 protected:
     QLayout * bodyLayoutDefinition();
+    // TODO: footer that says "* downloaded/custom content"
     void connectSignals();
 
+
 private:
+    QPushButton * btnStart; // is also preview
+    QLabel * lblCaption;
+    QLabel * lblDescription;
+    QListWidget * lstMissions;
+    // TODO reload/refresh button
+
     QStringList scriptList(const QDir & scriptDir) const;
+
+
+private slots:
+    void startSelected();
+    void updateInfo();
+
 };
 
 #endif
--- a/share/hedgewars/Data/Graphics/CMakeLists.txt	Mon Sep 26 21:29:40 2011 -0400
+++ b/share/hedgewars/Data/Graphics/CMakeLists.txt	Tue Sep 27 04:31:08 2011 +0200
@@ -4,6 +4,7 @@
 add_subdirectory(Hats)
 add_subdirectory(Hedgehog)
 add_subdirectory(SuddenDeath)
+add_subdirectory(Missions)
 
 file(GLOB BaseSprites *.png) 
 list(REMOVE_ITEM BaseSprites *@2x.png)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Graphics/Missions/CMakeLists.txt	Tue Sep 27 04:31:08 2011 +0200
@@ -0,0 +1,1 @@
+add_subdirectory(Training)
Binary file share/hedgewars/Data/Graphics/Missions/Training/Basic_Training_-_Bazooka.png has changed
Binary file share/hedgewars/Data/Graphics/Missions/Training/Basic_Training_-_Shotgun.png has changed
Binary file share/hedgewars/Data/Graphics/Missions/Training/Basic_Training_-_Sniper_Rifle.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Graphics/Missions/Training/CMakeLists.txt	Tue Sep 27 04:31:08 2011 +0200
@@ -0,0 +1,5 @@
+file(GLOB MissionPics *.png)
+
+install(FILES
+	${MissionPics}
+	DESTINATION ${SHAREPATH}Data/Graphics/Missions/Training)
Binary file share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_Bamboo_Thicket.png has changed
Binary file share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_Dangerous_Ducklings.png has changed
Binary file share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_Diver.png has changed
Binary file share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_Newton_and_the_Hammock.png has changed
Binary file share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_Spooky_Tree.png has changed
Binary file share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_Teamwork.png has changed
Binary file share/hedgewars/Data/Graphics/Missions/Training/User_Mission_-_That_Sinking_Feeling.png has changed