author | unC0Rr |
Wed, 04 Sep 2024 14:54:34 +0200 | |
branch | transitional_engine |
changeset 16031 | 1b1d5729ff3e |
parent 16026 | ce4b50823a95 |
permissions | -rw-r--r-- |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
1 |
/* |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
4 |
* |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
8 |
* |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
13 |
* |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
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 |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
17 |
*/ |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
18 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
19 |
/** |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
20 |
* @file |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
21 |
* @brief MapModel class definition |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
22 |
*/ |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
23 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
24 |
#ifndef HEDGEWARS_MAPMODEL_H |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
25 |
#define HEDGEWARS_MAPMODEL_H |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
26 |
|
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
|
27 |
#include <QStandardItemModel> |
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
|
28 |
#include <QSortFilterProxyModel> |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
29 |
#include <QStringList> |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
30 |
#include <QTextStream> |
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
31 |
#include <QHash> |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
32 |
#include <QMap> |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
33 |
#include <QIcon> |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
34 |
#include <QComboBox> |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
35 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
36 |
#include "DataManager.h" |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
37 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
38 |
/** |
6947
1be3e48e1d53
MapModel: add getters for random maps based on type, so that the mapContainer does not have to magically know how maps and separators are ordered within the model
sheepluva
parents:
6943
diff
changeset
|
39 |
* @brief A model that vertically lists available maps |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
40 |
* |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
41 |
* @author sheepluva |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
42 |
* @since 0.9.18 |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
43 |
*/ |
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
|
44 |
class MapModel : public QStandardItemModel |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
45 |
{ |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
46 |
Q_OBJECT |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
47 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
48 |
public: |
16026
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
49 |
enum MapType { |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
50 |
Invalid, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
51 |
GeneratedMap, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
52 |
GeneratedMaze, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
53 |
GeneratedPerlin, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
54 |
HandDrawnMap, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
55 |
MissionMap, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
56 |
StaticMap, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
57 |
FortsMap, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
58 |
WfcMap |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
59 |
}; |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
60 |
|
16026
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
61 |
/// a struct for holding the attributes of a map. |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
62 |
struct MapInfo { |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
63 |
MapType type; ///< The map-type |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
64 |
QString name; ///< The internal name. |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
65 |
QString theme; ///< The theme to be used. (can be empty) |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
66 |
quint32 limit; ///< The maximum allowed number of hedgehogs. |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
67 |
QString scheme; ///< Default scheme name or "locked", for mission-maps. |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
68 |
QString |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
69 |
weapons; ///< Default weaponset name or "locked", for missions-maps. |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
70 |
QString desc; ///< The brief 1-2 sentence description of the mission, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
71 |
///< for mission-maps. |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
11757
diff
changeset
|
72 |
bool dlc; ///< True if this map was not packaged with the game |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
73 |
}; |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
74 |
|
9744 | 75 |
MapModel(MapType maptype, QObject *parent = 0); |
76 |
||
6943 | 77 |
/** |
8377 | 78 |
* @brief Searches maps in model to find out if one exists |
79 |
* @param map map of which to check existence |
|
80 |
* @return true if it exists |
|
6943 | 81 |
*/ |
9744 | 82 |
bool mapExists(const QString & map); |
8377 | 83 |
|
84 |
/** |
|
85 |
* @brief Finds a map index (column, row) for a map name |
|
86 |
* @param map map of which to find index+column |
|
87 |
* @return QPair<int, int> with column, index, or (-1, -1) if map not found |
|
88 |
*/ |
|
89 |
//QPair<int, int> findMap(const QString & map) const; |
|
6947
1be3e48e1d53
MapModel: add getters for random maps based on type, so that the mapContainer does not have to magically know how maps and separators are ordered within the model
sheepluva
parents:
6943
diff
changeset
|
90 |
|
1be3e48e1d53
MapModel: add getters for random maps based on type, so that the mapContainer does not have to magically know how maps and separators are ordered within the model
sheepluva
parents:
6943
diff
changeset
|
91 |
/** |
8377 | 92 |
* @brief Finds a map index for a map name |
93 |
* @param map map of which to find index |
|
94 |
* @return int of index, or -1 if map not found |
|
6947
1be3e48e1d53
MapModel: add getters for random maps based on type, so that the mapContainer does not have to magically know how maps and separators are ordered within the model
sheepluva
parents:
6943
diff
changeset
|
95 |
*/ |
9744 | 96 |
int findMap(const QString & map); |
8377 | 97 |
|
98 |
/** |
|
99 |
* @brief Finds and returns a map item for a map name |
|
100 |
* @param map map |
|
101 |
* @return QStandardItem of map, or NULL if map not found |
|
102 |
*/ |
|
103 |
QStandardItem * getMap(const QString & map); |
|
104 |
||
105 |
// Static MapInfos for drawn and generated maps |
|
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
|
106 |
static MapInfo MapInfoRandom, MapInfoMaze, MapInfoPerlin, MapInfoDrawn, MapInfoForts; |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
107 |
|
9744 | 108 |
/// Loads the maps |
109 |
bool loadMaps(); |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
110 |
|
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
|
111 |
/// returns this model but excluding DLC themes |
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
|
112 |
QSortFilterProxyModel * withoutDLC(); |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
113 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
114 |
private: |
8377 | 115 |
/// map index lookup table. QPair<int, int> contains: <column, index> |
116 |
//QHash<QString, QPair<int, int> > m_mapIndexes; |
|
6983
ede55af89e78
roomslistmodel: prettier names for map +rnd+ etc.; point out unavailable maps
sheepluva
parents:
6952
diff
changeset
|
117 |
QHash<QString, int> m_mapIndexes; |
9744 | 118 |
MapType m_maptype; |
119 |
bool m_loaded; |
|
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
|
120 |
QSortFilterProxyModel * m_filteredNoDLC; |
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
|
121 |
|
6943 | 122 |
/** |
123 |
* @brief Creates a QStandardItem, that holds the map info and item appearance. |
|
124 |
* The used role for the data is Qt::UserRole + 1. |
|
125 |
* @param icon the icon to be displayed (can be an empty QIcon()). |
|
126 |
* @param caption the text to be displayed. |
|
127 |
* @param type the type of the map. |
|
128 |
* @param name the internal name of the map. |
|
129 |
* @param theme the theme of the map (or empty if none). |
|
130 |
* @param limit the hedgehog limit of the map. |
|
131 |
* @param scheme mission map: default scheme name or "locked". |
|
132 |
* @param weapons mission map: default weaponset name or "locked". |
|
8377 | 133 |
* @param desc mission map: description of mission. |
6943 | 134 |
* @return pointer to item representing the map info: at Qt::UserRole + 1. |
135 |
*/ |
|
8377 | 136 |
static QStandardItem * infoToItem( |
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
|
137 |
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
|
138 |
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
|
139 |
MapType type = Invalid, |
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
|
140 |
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
|
141 |
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
|
142 |
quint32 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
|
143 |
QString scheme = "", |
8377 | 144 |
QString weapons = "", |
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8377
diff
changeset
|
145 |
QString desc = "", |
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8377
diff
changeset
|
146 |
bool dlc = false); |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
147 |
}; |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
148 |
|
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
|
149 |
Q_DECLARE_METATYPE(MapModel::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
|
150 |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
diff
changeset
|
151 |
#endif // HEDGEWARS_MAPMODEL_H |