author | Wuzzy <Wuzzy2@mail.ru> |
Mon, 01 Jul 2019 22:35:19 +0200 | |
changeset 15209 | fe79f62ef158 |
parent 13274 | e381f5260b45 |
permissions | -rw-r--r-- |
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
1 |
/* |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
4 |
* |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
8 |
* |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
12 |
* GNU General Public License for more details. |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
13 |
* |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
17 |
*/ |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
18 |
|
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
19 |
/** |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
20 |
* @file |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
21 |
* @brief MapModel class implementation |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
22 |
*/ |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
23 |
|
8385
9e8924ff9813
Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents:
8377
diff
changeset
|
24 |
#include <QSettings> |
9e8924ff9813
Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents:
8377
diff
changeset
|
25 |
|
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8393
diff
changeset
|
26 |
#include "physfs.h" |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
27 |
#include "MapModel.h" |
8385
9e8924ff9813
Convert feedback page to dialog (+some fixes from unC0Rr)
dag10
parents:
8377
diff
changeset
|
28 |
#include "HWApplication.h" |
8464 | 29 |
#include "hwconsts.h" |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
30 |
|
9736
d2b01d350035
add missing initializers for 'dlc' variables for the 3 default generated map types (fixes 3 clang warnings)
sheepluva
parents:
9080
diff
changeset
|
31 |
MapModel::MapInfo MapModel::MapInfoRandom = {MapModel::GeneratedMap, "+rnd+", "", 0, "", "", "", false}; |
d2b01d350035
add missing initializers for 'dlc' variables for the 3 default generated map types (fixes 3 clang warnings)
sheepluva
parents:
9080
diff
changeset
|
32 |
MapModel::MapInfo MapModel::MapInfoMaze = {MapModel::GeneratedMaze, "+maze+", "", 0, "", "", "", false}; |
10391 | 33 |
MapModel::MapInfo MapModel::MapInfoPerlin = {MapModel::GeneratedMaze, "+perlin+", "", 0, "", "", "", false}; |
9736
d2b01d350035
add missing initializers for 'dlc' variables for the 3 default generated map types (fixes 3 clang warnings)
sheepluva
parents:
9080
diff
changeset
|
34 |
MapModel::MapInfo MapModel::MapInfoDrawn = {MapModel::HandDrawnMap, "+drawn+", "", 0, "", "", "", false}; |
11744
ac58a063d26a
Added "Forts" to map type selection. This makes the mode easier selectable/discoverable. Also the slider can be used to adjust the distance between forts.
sheepluva
parents:
11046
diff
changeset
|
35 |
MapModel::MapInfo MapModel::MapInfoForts = {MapModel::FortsMap, "+forts+", "", 0, "", "", "", false}; |
9744 | 36 |
|
37 |
MapModel::MapModel(MapType maptype, QObject *parent) : QStandardItemModel(parent) |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
38 |
{ |
9744 | 39 |
m_maptype = maptype; |
40 |
m_loaded = false; |
|
11757
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
41 |
m_filteredNoDLC = NULL; |
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
42 |
} |
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
43 |
|
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
44 |
QSortFilterProxyModel * MapModel::withoutDLC() |
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
45 |
{ |
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
46 |
if (m_filteredNoDLC == NULL) |
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
47 |
{ |
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
48 |
m_filteredNoDLC = new QSortFilterProxyModel(this); |
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
49 |
m_filteredNoDLC->setSourceModel(this); |
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
50 |
// filtering based on IsDlcRole would be nicer |
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
51 |
// but seems this model can only do string-based filtering :| |
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
52 |
m_filteredNoDLC->setFilterRegExp(QRegExp("^[^*]")); |
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
53 |
} |
6874644a2d00
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
sheepluva
parents:
11744
diff
changeset
|
54 |
return m_filteredNoDLC; |
9744 | 55 |
} |
56 |
||
57 |
bool MapModel::loadMaps() |
|
58 |
{ |
|
59 |
if(m_loaded) |
|
60 |
return false; |
|
61 |
||
62 |
m_loaded = true; |
|
63 |
||
64 |
qDebug("[LAZINESS] MapModel::loadMaps()"); |
|
65 |
||
6943 | 66 |
// this method resets the contents of this model (important to know for views). |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
67 |
beginResetModel(); |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
68 |
|
6943 | 69 |
// we'll need the DataManager a few times, so let's get a reference to it |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
70 |
DataManager & datamgr = DataManager::instance(); |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
71 |
|
6943 | 72 |
// fetch list of available maps |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
73 |
QStringList maps = |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
74 |
datamgr.entryList("Maps", QDir::AllDirs | QDir::NoDotAndDotDot); |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
75 |
|
6943 | 76 |
// empty list, so that we can (re)fill it |
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
77 |
QStandardItemModel::clear(); |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
78 |
|
8377 | 79 |
//QList<QStandardItem *> staticMaps; |
80 |
//QList<QStandardItem *> missionMaps; |
|
81 |
QList<QStandardItem *> mapList; |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
82 |
|
12685
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
83 |
|
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
84 |
QIcon dlcIcon; |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
85 |
dlcIcon.addFile(":/res/dlcMarker.png", QSize(), QIcon::Normal, QIcon::On); |
12686 | 86 |
dlcIcon.addFile(":/res/dlcMarkerSelected.png", QSize(), QIcon::Selected, QIcon::On); |
12685
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
87 |
QPixmap emptySpace = QPixmap(7, 15); |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
88 |
emptySpace.fill(QColor(0, 0, 0, 0)); |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
89 |
QIcon notDlcIcon = QIcon(emptySpace); |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
90 |
|
6943 | 91 |
// add mission/static maps to lists |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
92 |
foreach (QString map, maps) |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
93 |
{ |
8386 | 94 |
// only 2 map relate files are relevant: |
95 |
// - the cfg file that contains the settings/info of the map |
|
96 |
// - the lua file - if it exists it's a mission, otherwise it isn't |
|
97 |
QFile mapLuaFile(QString("physfs://Maps/%1/map.lua").arg(map)); |
|
98 |
QFile mapCfgFile(QString("physfs://Maps/%1/map.cfg").arg(map)); |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
99 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
100 |
if (mapCfgFile.open(QFile::ReadOnly)) |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
101 |
{ |
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
102 |
QString caption; |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
103 |
QString theme; |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
104 |
quint32 limit = 0; |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
105 |
QString scheme; |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
106 |
QString weapons; |
8377 | 107 |
QString desc; |
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8393
diff
changeset
|
108 |
bool dlc; |
8377 | 109 |
|
6943 | 110 |
// if there is a lua file for this map, then it's a mission |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
111 |
bool isMission = mapLuaFile.exists(); |
8377 | 112 |
MapType type = isMission ? MissionMap : StaticMap; |
113 |
||
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8393
diff
changeset
|
114 |
// if we're supposed to ignore this type, continue |
9744 | 115 |
if (type != m_maptype) continue; |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
116 |
|
6943 | 117 |
// load map info from file |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
118 |
QTextStream input(&mapCfgFile); |
8377 | 119 |
theme = input.readLine(); |
120 |
limit = input.readLine().toInt(); |
|
6943 | 121 |
if (isMission) { // scheme and weapons are only relevant for missions |
8377 | 122 |
scheme = input.readLine(); |
123 |
weapons = input.readLine(); |
|
6943 | 124 |
} |
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
125 |
mapCfgFile.close(); |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
126 |
|
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8393
diff
changeset
|
127 |
// load description (if applicable) |
8377 | 128 |
if (isMission) |
129 |
{ |
|
11899
0b6baf802b3d
Fix improper locale detection for mission map descriptions
Wuzzy <almikes@aol.com>
parents:
11757
diff
changeset
|
130 |
// get locale |
11900
d71448338ac2
UTF-8 support for mission map descriptions
Wuzzy <almikes@aol.com>
parents:
11899
diff
changeset
|
131 |
QSettings settings(datamgr.settingsFileName(), QSettings::IniFormat); |
13274
e381f5260b45
Change how locale is loaded in frontend, and fix some bugs
Wuzzy <Wuzzy2@mail.ru>
parents:
12686
diff
changeset
|
132 |
QString locale = QLocale().name(); |
8386 | 133 |
|
134 |
QSettings descSettings(QString("physfs://Maps/%1/desc.txt").arg(map), QSettings::IniFormat); |
|
11900
d71448338ac2
UTF-8 support for mission map descriptions
Wuzzy <almikes@aol.com>
parents:
11899
diff
changeset
|
135 |
descSettings.setIniCodec("UTF-8"); |
11902
38d27c1645eb
Fix and change escaping for mission map descriptions
Wuzzy <almikes@aol.com>
parents:
11901
diff
changeset
|
136 |
desc = descSettings.value(locale, QString()).toString(); |
13274
e381f5260b45
Change how locale is loaded in frontend, and fix some bugs
Wuzzy <Wuzzy2@mail.ru>
parents:
12686
diff
changeset
|
137 |
// If not found, try with language-only code |
11901
291d53985dcd
Show mission map descriptions for default language as well
Wuzzy <almikes@aol.com>
parents:
11900
diff
changeset
|
138 |
if (desc.isEmpty()) |
291d53985dcd
Show mission map descriptions for default language as well
Wuzzy <almikes@aol.com>
parents:
11900
diff
changeset
|
139 |
{ |
291d53985dcd
Show mission map descriptions for default language as well
Wuzzy <almikes@aol.com>
parents:
11900
diff
changeset
|
140 |
QString localeSimple = locale.remove(QRegExp("_.*$")); |
11902
38d27c1645eb
Fix and change escaping for mission map descriptions
Wuzzy <almikes@aol.com>
parents:
11901
diff
changeset
|
141 |
desc = descSettings.value(localeSimple, QString()).toString(); |
13274
e381f5260b45
Change how locale is loaded in frontend, and fix some bugs
Wuzzy <Wuzzy2@mail.ru>
parents:
12686
diff
changeset
|
142 |
// If still not found, use English |
e381f5260b45
Change how locale is loaded in frontend, and fix some bugs
Wuzzy <Wuzzy2@mail.ru>
parents:
12686
diff
changeset
|
143 |
if (desc.isEmpty()) |
e381f5260b45
Change how locale is loaded in frontend, and fix some bugs
Wuzzy <Wuzzy2@mail.ru>
parents:
12686
diff
changeset
|
144 |
desc = descSettings.value("en", QString()).toString(); |
11901
291d53985dcd
Show mission map descriptions for default language as well
Wuzzy <almikes@aol.com>
parents:
11900
diff
changeset
|
145 |
} |
11902
38d27c1645eb
Fix and change escaping for mission map descriptions
Wuzzy <almikes@aol.com>
parents:
11901
diff
changeset
|
146 |
desc = desc.replace("_n", "\n").replace("_c", ",").replace("__", "_"); |
8377 | 147 |
} |
148 |
||
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8393
diff
changeset
|
149 |
// detect if map is dlc |
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8393
diff
changeset
|
150 |
QString mapDir = PHYSFS_getRealDir(QString("Maps/%1/map.cfg").arg(map).toLocal8Bit().data()); |
8464 | 151 |
dlc = !mapDir.startsWith(datadir->absolutePath()); |
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8393
diff
changeset
|
152 |
|
6943 | 153 |
// let's use some semi-sane hedgehog limit, rather than none |
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
154 |
if (limit == 0) |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
155 |
limit = 18; |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
156 |
|
6943 | 157 |
// the default scheme/weaponset for missions. |
158 |
// if empty we assume the map sets these internally -> locked |
|
159 |
if (isMission) |
|
160 |
{ |
|
161 |
if (scheme.isEmpty()) |
|
162 |
scheme = "locked"; |
|
163 |
else |
|
164 |
scheme.replace("_", " "); |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
165 |
|
6943 | 166 |
if (weapons.isEmpty()) |
167 |
weapons = "locked"; |
|
168 |
else |
|
169 |
weapons.replace("_", " "); |
|
170 |
} |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
171 |
|
8377 | 172 |
// caption |
173 |
caption = map; |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
174 |
|
12685
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
175 |
QIcon icon; |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
176 |
if (dlc) |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
177 |
icon = dlcIcon; |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
178 |
else |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
179 |
icon = notDlcIcon; |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
180 |
|
6943 | 181 |
// we know everything there is about the map, let's get am item for it |
8377 | 182 |
QStandardItem * item = MapModel::infoToItem( |
12685
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
183 |
icon, caption, type, map, theme, limit, scheme, weapons, desc, dlc); |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
184 |
|
6943 | 185 |
// append item to the list |
8377 | 186 |
mapList.append(item); |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
187 |
} |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
188 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
189 |
} |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
190 |
|
8377 | 191 |
// Create column-index lookup table |
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
192 |
|
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
193 |
m_mapIndexes.clear(); |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
194 |
|
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
195 |
|
8377 | 196 |
int count = mapList.size(); |
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
197 |
for (int i = 0; i < count; i++) |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
198 |
{ |
8377 | 199 |
QStandardItem * si = mapList.at(i); |
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
200 |
QVariant v = si->data(Qt::UserRole + 1); |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
201 |
if (v.canConvert<MapInfo>()) |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
202 |
m_mapIndexes.insert(v.value<MapInfo>().name, i); |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
203 |
} |
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
204 |
|
8377 | 205 |
QStandardItemModel::appendColumn(mapList); |
6943 | 206 |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
207 |
endResetModel(); |
9744 | 208 |
|
209 |
return true; |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
210 |
} |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
211 |
|
9744 | 212 |
bool MapModel::mapExists(const QString & map) |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
213 |
{ |
8377 | 214 |
return findMap(map) >= 0; |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
215 |
} |
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
216 |
|
9744 | 217 |
int MapModel::findMap(const QString & map) |
8377 | 218 |
{ |
9744 | 219 |
loadMaps(); |
220 |
||
8377 | 221 |
return m_mapIndexes.value(map, -1); |
222 |
} |
|
223 |
||
224 |
QStandardItem * MapModel::getMap(const QString & map) |
|
225 |
{ |
|
226 |
int loc = findMap(map); |
|
227 |
if (loc < 0) return NULL; |
|
228 |
return item(loc); |
|
229 |
} |
|
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
230 |
|
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
231 |
QStandardItem * MapModel::infoToItem( |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
232 |
const QIcon & icon, |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
233 |
const QString caption, |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
234 |
MapType type, |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
235 |
QString name, |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
236 |
QString theme, |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
237 |
quint32 limit, |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
238 |
QString scheme, |
8377 | 239 |
QString weapons, |
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8393
diff
changeset
|
240 |
QString desc, |
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8393
diff
changeset
|
241 |
bool dlc) |
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
242 |
{ |
12685
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11902
diff
changeset
|
243 |
QStandardItem * item = new QStandardItem(icon, caption); |
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
244 |
MapInfo mapInfo; |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
245 |
QVariant qvar(QVariant::UserType); |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
246 |
|
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
247 |
mapInfo.type = type; |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
248 |
mapInfo.name = name; |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
249 |
mapInfo.theme = theme; |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
250 |
mapInfo.limit = limit; |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
251 |
mapInfo.scheme = scheme; |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
252 |
mapInfo.weapons = weapons; |
8377 | 253 |
mapInfo.desc = desc.isEmpty() ? tr("No description available.") : desc; |
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8393
diff
changeset
|
254 |
mapInfo.dlc = dlc; |
6939
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
255 |
|
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
256 |
qvar.setValue(mapInfo); |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
257 |
item->setData(qvar, Qt::UserRole + 1); |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
258 |
|
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
259 |
return item; |
970389573788
MapModel converted to QStandardItemList; separators fixed; changed used data format (human-readable struct instead of magic list) for map info in HwMapContainer (+ various small cleanups in that class)
sheepluva
parents:
6938
diff
changeset
|
260 |
} |