# HG changeset patch # User sheepluva # Date 1461861170 -7200 # Node ID 6874644a2d00bbb00ff3d15dc1e63b36ad7bccb4 # Parent df92c83375e2a3845206a2f2bcd737674be66d55 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 diff -r df92c83375e2 -r 6874644a2d00 QTfrontend/model/MapModel.cpp --- 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() diff -r df92c83375e2 -r 6874644a2d00 QTfrontend/model/MapModel.h --- 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 +#include #include #include #include @@ -105,6 +106,8 @@ /// Loads the maps bool loadMaps(); + /// returns this model but excluding DLC themes + QSortFilterProxyModel * withoutDLC(); private: /// map index lookup table. QPair contains: @@ -112,6 +115,7 @@ QHash m_mapIndexes; MapType m_maptype; bool m_loaded; + QSortFilterProxyModel * m_filteredNoDLC; /** * @brief Creates a QStandardItem, that holds the map info and item appearance. diff -r df92c83375e2 -r 6874644a2d00 QTfrontend/model/ThemeModel.cpp --- 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 >(); 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 diff -r df92c83375e2 -r 6874644a2d00 QTfrontend/model/ThemeModel.h --- 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 +#include #include #include #include @@ -44,10 +45,12 @@ int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role) const; + QSortFilterProxyModel * withoutDLC(); private: mutable QList > m_data; mutable bool m_themesLoaded; + mutable QSortFilterProxyModel * m_filteredNoDLC; void loadThemes() const; }; diff -r df92c83375e2 -r 6874644a2d00 QTfrontend/ui/page/pagenetgame.cpp --- 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 diff -r df92c83375e2 -r 6874644a2d00 QTfrontend/ui/widget/gamecfgwidget.cpp --- 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); diff -r df92c83375e2 -r 6874644a2d00 QTfrontend/ui/widget/gamecfgwidget.h --- 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; diff -r df92c83375e2 -r 6874644a2d00 QTfrontend/ui/widget/mapContainer.cpp --- 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); } diff -r df92c83375e2 -r 6874644a2d00 QTfrontend/ui/widget/mapContainer.h --- 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);