Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
authordag10
Mon, 21 Jan 2013 14:07:39 -0500
changeset 8419 d99f46b676b5
parent 8418 4543cc2049af
child 8420 98e3cc0418f9
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue #515)
QTfrontend/model/GameStyleModel.cpp
QTfrontend/model/GameStyleModel.h
QTfrontend/model/MapModel.cpp
QTfrontend/model/MapModel.h
QTfrontend/model/ThemeModel.cpp
QTfrontend/ui/widget/themeprompt.cpp
--- a/QTfrontend/model/GameStyleModel.cpp	Mon Jan 21 13:04:57 2013 -0500
+++ b/QTfrontend/model/GameStyleModel.cpp	Mon Jan 21 14:07:39 2013 -0500
@@ -23,14 +23,16 @@
 
 #include <QTextStream>
 
+#include "physfs.h"
 #include "GameStyleModel.h"
 
 
 void GameStyleModel::loadGameStyles()
 {
+    const QString appDir = QString(PHYSFS_getBaseDir());
+
     beginResetModel();
 
-
     // empty list, so that we can (re)fill it
     QStandardItemModel::clear();
 
@@ -77,11 +79,16 @@
                 weapons.replace("_", " ");
         }
 
-        QStandardItem * item = new QStandardItem(name);
+        // detect if script is dlc
+        QString scriptPath = PHYSFS_getRealDir(QString("Scripts/Multiplayer/%1.lua").arg(script).toLocal8Bit().data());
+        bool isDLC = !scriptPath.startsWith(appDir);
+
+        QStandardItem * item = new QStandardItem((isDLC ? "*" : "") + name);
 
         item->setData(script, ScriptRole);
         item->setData(scheme, SchemeRole);
         item->setData(weapons, WeaponsRole);
+        item->setData(isDLC, IsDlcRole);
 
         items.append(item);
     }
--- a/QTfrontend/model/GameStyleModel.h	Mon Jan 21 13:04:57 2013 -0500
+++ b/QTfrontend/model/GameStyleModel.h	Mon Jan 21 14:07:39 2013 -0500
@@ -38,7 +38,7 @@
         Q_OBJECT
 
     public:
-        enum DataRoles { ScriptRole = Qt::UserRole+1, SchemeRole, WeaponsRole };
+        enum DataRoles { ScriptRole = Qt::UserRole+1, SchemeRole, WeaponsRole, IsDlcRole };
 
     public slots:
         /// reloads the themes from the DataManager
--- a/QTfrontend/model/MapModel.cpp	Mon Jan 21 13:04:57 2013 -0500
+++ b/QTfrontend/model/MapModel.cpp	Mon Jan 21 14:07:39 2013 -0500
@@ -23,6 +23,7 @@
 
 #include <QSettings>
 
+#include "physfs.h"
 #include "MapModel.h"
 #include "HWApplication.h"
 
@@ -32,6 +33,8 @@
 
 void MapModel::loadMaps(MapType maptype)
 {
+    const QString appDir = QString(PHYSFS_getBaseDir());
+
     // this method resets the contents of this model (important to know for views).
     beginResetModel();
 
@@ -66,12 +69,13 @@
             QString scheme;
             QString weapons;
             QString desc;
+            bool dlc;
 
             // if there is a lua file for this map, then it's a mission
             bool isMission = mapLuaFile.exists();
             MapType type = isMission ? MissionMap : StaticMap;
 
-            // If we're supposed to ignore this type, continue
+            // if we're supposed to ignore this type, continue
             if (type != maptype) continue;
 
             // load map info from file
@@ -84,7 +88,7 @@
             }
             mapCfgFile.close();
 
-            // Load description (if applicable)
+            // load description (if applicable)
             if (isMission)
             {
                 QString locale = HWApplication::keyboardInputLocale().name();
@@ -93,6 +97,10 @@
                 desc = descSettings.value(locale, QString()).toString().replace("|", "\n").replace("\\,", ",");
             }
 
+            // detect if map is dlc
+            QString mapDir = PHYSFS_getRealDir(QString("Maps/%1/map.cfg").arg(map).toLocal8Bit().data());
+            dlc = !mapDir.startsWith(appDir);
+
             // let's use some semi-sane hedgehog limit, rather than none
             if (limit == 0)
                 limit = 18;
@@ -117,7 +125,7 @@
 
             // we know everything there is about the map, let's get am item for it
             QStandardItem * item = MapModel::infoToItem(
-                QIcon(), caption, type, map, theme, limit, scheme, weapons, desc);
+                QIcon(), caption, type, map, theme, limit, scheme, weapons, desc, dlc);
 
             // append item to the list
             mapList.append(item);
@@ -170,9 +178,10 @@
     quint32 limit,
     QString scheme,
     QString weapons,
-    QString desc)
+    QString desc,
+    bool dlc)
 {
-    QStandardItem * item = new QStandardItem(icon, caption);
+    QStandardItem * item = new QStandardItem(icon, (dlc ? "*" : "") + caption);
     MapInfo mapInfo;
     QVariant qvar(QVariant::UserType);
 
@@ -183,6 +192,7 @@
     mapInfo.scheme = scheme;
     mapInfo.weapons = weapons;
     mapInfo.desc = desc.isEmpty() ? tr("No description available.") : desc;
+    mapInfo.dlc = dlc;
 
     qvar.setValue(mapInfo);
     item->setData(qvar, Qt::UserRole + 1);
--- a/QTfrontend/model/MapModel.h	Mon Jan 21 13:04:57 2013 -0500
+++ b/QTfrontend/model/MapModel.h	Mon Jan 21 14:07:39 2013 -0500
@@ -64,6 +64,7 @@
             QString scheme; ///< Default scheme name or "locked", for mission-maps.
             QString weapons; ///< Default weaponset name or "locked", for missions-maps.
             QString desc; ///< The brief 1-2 sentence description of the mission, for mission-maps.
+            bool dlc; ///< True if this map was not packaged with the game
         };
 
         /**
@@ -131,7 +132,8 @@
             quint32 limit = 0,
             QString scheme = "",
             QString weapons = "",
-            QString desc = "");
+            QString desc = "",
+            bool dlc = false);
 };
 
 Q_DECLARE_METATYPE(MapModel::MapInfo)
--- a/QTfrontend/model/ThemeModel.cpp	Mon Jan 21 13:04:57 2013 -0500
+++ b/QTfrontend/model/ThemeModel.cpp	Mon Jan 21 14:07:39 2013 -0500
@@ -21,6 +21,7 @@
  * @brief ThemeModel class implementation
  */
 
+#include "physfs.h"
 #include "ThemeModel.h"
 
 ThemeModel::ThemeModel(QObject *parent) :
@@ -49,9 +50,10 @@
 
 void ThemeModel::loadThemes()
 {
+    const QString appDir = QString(PHYSFS_getBaseDir());
+
     beginResetModel();
 
-
     DataManager & datamgr = DataManager::instance();
 
     QStringList themes =
@@ -73,6 +75,10 @@
 
         QMap<int, QVariant> dataset;
 
+        // detect if theme is dlc
+        QString themeDir = PHYSFS_getRealDir(QString("Themes/%1/icon.png").arg(theme).toLocal8Bit().data());
+        dataset.insert(Qt::UserRole + 2, !themeDir.startsWith(appDir));
+
         // set icon path
         dataset.insert(Qt::UserRole + 1, iconpath);
 
@@ -95,8 +101,4 @@
 
 
     endResetModel();
-}
-
-
-
-
+}
\ No newline at end of file
--- a/QTfrontend/ui/widget/themeprompt.cpp	Mon Jan 21 13:04:57 2013 -0500
+++ b/QTfrontend/ui/widget/themeprompt.cpp	Mon Jan 21 14:07:39 2013 -0500
@@ -81,9 +81,10 @@
 	{
 		QModelIndex index = themes->index(i, 0);
 		QToolButton * btn = new QToolButton();
+		bool dlc = themes->data(index, Qt::UserRole + 2).toBool();
 		btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
 		btn->setIcon(qVariantValue<QIcon>(themes->data(index, Qt::UserRole)));
-		btn->setText(themes->data(index, Qt::DisplayRole).toString());
+		btn->setText((dlc ? "*" : "") + themes->data(index, Qt::DisplayRole).toString());
 		btn->setIconSize(QSize(60, 60));
 		btn->setProperty("themeID", QVariant(i));
 		btn->setStyleSheet("padding: 2px;");