Crossfire Server, Trunk
RandomMaps.h
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #ifndef RANDOM_MAPS_H
14 #define RANDOM_MAPS_H
15 
16 #include "assets/AssetWrapper.h"
18 #include "RandomMap.h"
19 
20 class RandomMaps : public AssetWrapper {
21  Q_OBJECT
22 public:
24  connect(maps, SIGNAL(mapAdded(CREMapInformation *)), this, SLOT(mapAdded(CREMapInformation *)));
25  setProperty(tipProperty, tr("Display all random maps."));
26  }
27 
28  virtual QString displayName() const override { return tr("Random maps"); }
29 
30  virtual int childrenCount() const override { refresh(); return myCache.size(); }
31  virtual AssetWrapper *child(int child) override { refresh(); return myCache[child]; }
32  virtual int childIndex(AssetWrapper *child) override { refresh(); return myCache.indexOf(static_cast<RandomMap *>(child)); }
33 
34 protected slots:
36  if (!map->randomMaps().empty()) {
37  myNeedRefresh = true;
38  }
39  }
40 
41 private:
43  mutable bool myNeedRefresh;
44  mutable QList<RandomMap *> myCache;
45 
46  void refresh() const {
47  if (myNeedRefresh) {
48  myNeedRefresh = false;
50  }
51  }
52 };
53 
54 #endif /* RANDOM_MAPS_H */
RandomMap
Definition: RandomMap.h:24
CREMapInformationManager::randomMaps
QList< RandomMap * > randomMaps()
Definition: CREMapInformationManager.cpp:813
maps
static std::unordered_map< std::string, mapzone * > maps
Definition: citylife.cpp:92
AssetWrapper.h
RandomMaps::displayName
virtual QString displayName() const override
Definition: RandomMaps.h:28
RandomMap.h
RandomMaps
Definition: RandomMaps.h:20
AssetWrapper::tipProperty
static const char * tipProperty
Definition: AssetWrapper.h:34
CREMapInformation
Definition: CREMapInformation.h:27
disinfect.map
map
Definition: disinfect.py:4
AssetWrapper
Definition: AssetWrapper.h:25
RandomMaps::childIndex
virtual int childIndex(AssetWrapper *child) override
Definition: RandomMaps.h:32
RandomMaps::myCache
QList< RandomMap * > myCache
Definition: RandomMaps.h:44
RandomMaps::child
virtual AssetWrapper * child(int child) override
Definition: RandomMaps.h:31
CREMapInformationManager.h
RandomMaps::childrenCount
virtual int childrenCount() const override
Definition: RandomMaps.h:30
RandomMaps::myNeedRefresh
bool myNeedRefresh
Definition: RandomMaps.h:43
RandomMaps::refresh
void refresh() const
Definition: RandomMaps.h:46
RandomMaps::myMaps
CREMapInformationManager * myMaps
Definition: RandomMaps.h:42
RandomMaps::mapAdded
void mapAdded(CREMapInformation *map)
Definition: RandomMaps.h:35
RandomMaps::RandomMaps
RandomMaps(AssetWrapper *parent, CREMapInformationManager *maps)
Definition: RandomMaps.h:23
connect
Definition: connect.py:1
CREMapInformationManager
Definition: CREMapInformationManager.h:27