in non-local games, don't include DLC-themes/maps/missions during random selection. thanks to unC0Rr for helping me realize that I was stupid in a different way than I thought :P
authorsheepluva
Thu, 28 Apr 2016 18:32:50 +0200
changeset 11757 6874644a2d00
parent 11756 df92c83375e2
child 11762 660599c04bd8
in non-local games, don't include DLC-themes/maps/missions during random selection. thanks to unC0Rr for helping me realize that I was stupid in a different way than I thought :P
QTfrontend/model/MapModel.cpp
QTfrontend/model/MapModel.h
QTfrontend/model/ThemeModel.cpp
QTfrontend/model/ThemeModel.h
QTfrontend/ui/page/pagenetgame.cpp
QTfrontend/ui/widget/gamecfgwidget.cpp
QTfrontend/ui/widget/gamecfgwidget.h
QTfrontend/ui/widget/mapContainer.cpp
QTfrontend/ui/widget/mapContainer.h
--- a/QTfrontend/model/MapModel.cpp	Thu Apr 28 17:42:43 2016 +0200
+++ b/QTfrontend/model/MapModel.cpp	Thu Apr 28 18:32:50 2016 +0200
@@ -38,6 +38,20 @@
 {
     m_maptype = maptype;
     m_loaded = false;
+    m_filteredNoDLC = NULL;
+}
+
+QSortFilterProxyModel * MapModel::withoutDLC()
+{
+    if (m_filteredNoDLC == NULL)
+    {
+        m_filteredNoDLC = new QSortFilterProxyModel(this);
+        m_filteredNoDLC->setSourceModel(this);
+        // filtering based on IsDlcRole would be nicer
+        // but seems this model can only do string-based filtering :|
+        m_filteredNoDLC->setFilterRegExp(QRegExp("^[^*]"));
+    }
+    return m_filteredNoDLC;
 }
 
 bool MapModel::loadMaps()
--- a/QTfrontend/model/MapModel.h	Thu Apr 28 17:42:43 2016 +0200
+++ b/QTfrontend/model/MapModel.h	Thu Apr 28 18:32:50 2016 +0200
@@ -25,6 +25,7 @@
 #define HEDGEWARS_MAPMODEL_H
 
 #include <QStandardItemModel>
+#include <QSortFilterProxyModel>
 #include <QStringList>
 #include <QTextStream>
 #include <QHash>
@@ -105,6 +106,8 @@
         /// Loads the maps
         bool loadMaps();
 
+        /// returns this model but excluding DLC themes
+        QSortFilterProxyModel * withoutDLC();
 
     private:
         /// map index lookup table. QPair<int, int> contains: <column, index>
@@ -112,6 +115,7 @@
         QHash<QString, int> m_mapIndexes;
         MapType m_maptype;
         bool m_loaded;
+        QSortFilterProxyModel * m_filteredNoDLC;
 
         /**
          * @brief Creates a QStandardItem, that holds the map info and item appearance.
--- a/QTfrontend/model/ThemeModel.cpp	Thu Apr 28 17:42:43 2016 +0200
+++ b/QTfrontend/model/ThemeModel.cpp	Thu Apr 28 18:32:50 2016 +0200
@@ -31,6 +31,21 @@
     m_data = QList<QMap<int, QVariant> >();
 
     m_themesLoaded = false;
+
+    m_filteredNoDLC = NULL;
+}
+
+QSortFilterProxyModel * ThemeModel::withoutDLC()
+{
+    if (m_filteredNoDLC == NULL)
+    {
+        m_filteredNoDLC = new QSortFilterProxyModel(this);
+        m_filteredNoDLC->setSourceModel(this);
+        // filtering based on IsDlcRole would be nicer
+        // but seems this model can only do string-based filtering :|
+        m_filteredNoDLC->setFilterRegExp(QRegExp("^[^*]"));
+    }
+    return m_filteredNoDLC;
 }
 
 int ThemeModel::rowCount(const QModelIndex &parent) const
--- a/QTfrontend/model/ThemeModel.h	Thu Apr 28 17:42:43 2016 +0200
+++ b/QTfrontend/model/ThemeModel.h	Thu Apr 28 18:32:50 2016 +0200
@@ -25,6 +25,7 @@
 #define HEDGEWARS_THEMEMODEL_H
 
 #include <QAbstractListModel>
+#include <QSortFilterProxyModel>
 #include <QStringList>
 #include <QMap>
 #include <QIcon>
@@ -44,10 +45,12 @@
 
         int rowCount(const QModelIndex &parent = QModelIndex()) const;
         QVariant data(const QModelIndex &index, int role) const;
+        QSortFilterProxyModel * withoutDLC();
 
     private:
         mutable QList<QMap<int, QVariant> > m_data;
         mutable bool m_themesLoaded;
+        mutable QSortFilterProxyModel * m_filteredNoDLC;
 
         void loadThemes() const;
 };
--- a/QTfrontend/ui/page/pagenetgame.cpp	Thu Apr 28 17:42:43 2016 +0200
+++ b/QTfrontend/ui/page/pagenetgame.cpp	Thu Apr 28 18:32:50 2016 +0200
@@ -86,7 +86,7 @@
 
     // Game config
 
-    pGameCFG = new GameCFGWidget(this);
+    pGameCFG = new GameCFGWidget(this, true);
     pageLayout->addWidget(pGameCFG, 1, 0);
 
     // Teams
--- a/QTfrontend/ui/widget/gamecfgwidget.cpp	Thu Apr 28 17:42:43 2016 +0200
+++ b/QTfrontend/ui/widget/gamecfgwidget.cpp	Thu Apr 28 18:32:50 2016 +0200
@@ -39,7 +39,7 @@
 #include "GameStyleModel.h"
 #include "themeprompt.h"
 
-GameCFGWidget::GameCFGWidget(QWidget* parent) :
+GameCFGWidget::GameCFGWidget(QWidget* parent, bool randomWithoutDLC) :
     QGroupBox(parent)
     , mainLayout(this)
     , seedRegexp("\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}")
@@ -80,6 +80,7 @@
     // Map options
 
     pMapContainer = new HWMapContainer(mapContainerFree);
+    pMapContainer->setRandomWithoutDLC(randomWithoutDLC);
     stackLayout->addWidget(mapContainerFree, 0, Qt::AlignHCenter);
     pMapContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
     pMapContainer->setFixedSize(width() - 14, 278);
--- a/QTfrontend/ui/widget/gamecfgwidget.h	Thu Apr 28 17:42:43 2016 +0200
+++ b/QTfrontend/ui/widget/gamecfgwidget.h	Thu Apr 28 18:32:50 2016 +0200
@@ -40,7 +40,7 @@
         Q_PROPERTY(bool master READ isMaster WRITE setMaster)
 
     public:
-        GameCFGWidget(QWidget* parent);
+        GameCFGWidget(QWidget* parent, bool randomWithoutDLC = false);
         quint32 getGameFlags() const;
         quint32 getInitHealth() const;
         QByteArray getFullConfig() const;
--- a/QTfrontend/ui/widget/mapContainer.cpp	Thu Apr 28 17:42:43 2016 +0200
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Thu Apr 28 18:32:50 2016 +0200
@@ -63,6 +63,7 @@
     m_script = QString();
     m_prevMapFeatureSize = 12;
     m_mapFeatureSize = 12;
+    m_withoutDLC = false;
 
     hhSmall.load(":/res/hh_small.png");
     hhLimit = 18;
@@ -500,6 +501,9 @@
     if (!m_master) return;
 
     setRandomSeed();
+
+    QSortFilterProxyModel * mmodel = NULL;
+
     switch(m_mapInfo.type)
     {
         case MapModel::GeneratedMap:
@@ -509,10 +513,22 @@
             setRandomTheme();
             break;
         case MapModel::MissionMap:
-            missionMapChanged(m_missionMapModel->index(rand() % m_missionMapModel->rowCount(), 0));
+            if (m_withoutDLC)
+            {
+                mmodel = m_missionMapModel->withoutDLC();
+                missionMapChanged(mmodel->mapToSource(mmodel->index(rand() % mmodel->rowCount(),0)));
+            }
+            else
+                missionMapChanged(m_missionMapModel->index(rand() % m_missionMapModel->rowCount(),0));
             break;
         case MapModel::StaticMap:
-            staticMapChanged(m_staticMapModel->index(rand() % m_staticMapModel->rowCount(), 0));
+            if (m_withoutDLC)
+            {
+                mmodel = m_staticMapModel->withoutDLC();
+                staticMapChanged(mmodel->mapToSource(mmodel->index(rand() % mmodel->rowCount(),0)));
+            }
+            else
+                staticMapChanged(m_staticMapModel->index(rand() % m_staticMapModel->rowCount(),0));
             break;
         default:
             break;
@@ -525,11 +541,23 @@
     emit seedChanged(m_seed);
 }
 
+void HWMapContainer::setRandomWithoutDLC(bool withoutDLC)
+{
+    m_withoutDLC = withoutDLC;
+}
+
 void HWMapContainer::setRandomTheme()
 {
-    if(!m_themeModel->rowCount()) return;
-    quint32 themeNum = rand() % m_themeModel->rowCount();
-    updateTheme(m_themeModel->index(themeNum));
+    QAbstractItemModel * tmodel;
+
+    if (m_withoutDLC)
+        tmodel = m_themeModel->withoutDLC();
+    else
+        tmodel = m_themeModel;
+
+    if(!tmodel->rowCount()) return;
+    quint32 themeNum = rand() % tmodel->rowCount();
+    updateTheme(tmodel->index(themeNum,0));
     emit themeChanged(m_theme);
 }
 
--- a/QTfrontend/ui/widget/mapContainer.h	Thu Apr 28 17:42:43 2016 +0200
+++ b/QTfrontend/ui/widget/mapContainer.h	Thu Apr 28 18:32:50 2016 +0200
@@ -85,6 +85,7 @@
         void updateModelViews();
         void onPreviewMapDestroyed(QObject * map);
         void setMaster(bool master);
+        void setRandomWithoutDLC(bool withoutDLC);
 
     signals:
         void seedChanged(const QString & seed);
@@ -161,6 +162,7 @@
         bool m_previewEnabled;
         bool m_missionsViewSetup;
         bool m_staticViewSetup;
+        bool m_withoutDLC;
 
         void intSetSeed(const QString & seed);
         void intSetMap(const QString & map);