Crossfire Server, Trunk
AssetWithArtifacts.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 ASSET_WITH_ARTIFACTS_H
14 #define ASSET_WITH_ARTIFACTS_H
15 
16 #include "assets/AssetWrapper.h"
18 #include "global.h"
19 
20 class ResourcesManager;
21 
25 template<class T>
26 class AssetWithArtifacts : public AssetTWrapper<T> {
27 public:
28  AssetWithArtifacts(AssetWrapper *parent, const QString &panelName, T* item, ResourcesManager *resources)
29  : AssetTWrapper<T>(parent, panelName, item), mySpecificItem(nullptr), myResources(resources) {
30  }
31 
32  virtual ~AssetWithArtifacts() {
33  for (auto art : myArtifacts) {
34  delete art;
35  }
36  }
37 
38  virtual int childrenCount() const override {
39  return myArtifacts.size();
40  }
41 
42  virtual AssetWrapper *child(int child) override {
43  if (child >= 0 && child < static_cast<int>(myArtifacts.size())) {
44  return myArtifacts[child];
45  }
46  return nullptr;
47  }
48  virtual int childIndex(AssetWrapper *child) override {
49  auto pos = std::find(myArtifacts.begin(), myArtifacts.end(), child);
50  if (pos != myArtifacts.end()) {
51  return (pos - myArtifacts.begin());
52  }
53  return -1;
54  }
55 
56 protected:
57  const object *mySpecificItem;
59  std::vector<ArtifactWrapper *> myArtifacts;
60 
61  void setSpecificItem(const object *item, bool notify) {
63  updateArtifacts(notify);
64  }
65 
66  void updateArtifacts(bool notify) {
67  std::vector<ArtifactWrapper *> artifacts;
68  if (mySpecificItem) {
70  if (list) {
71  for (auto art : list->items) {
73  auto wrap = new ArtifactWrapper(this, art, myResources);
74  wrap->setSpecificItem(mySpecificItem);
75  artifacts.push_back(wrap);
76  }
77  }
78  }
79  }
80 
81  if (notify)
83  std::swap(myArtifacts, artifacts);
84  if (notify)
86 
87  for (auto art : artifacts) {
88  delete art;
89  }
90  }
91 };
92 
93 #endif /* ASSET_WITH_ARTIFACTS_H */
AssetWrapper::AfterLayoutChange
@ AfterLayoutChange
Definition: AssetWrapper.h:33
global.h
ArtifactWrapper
Definition: ArtifactWrapper.h:24
AssetWrapper.h
AssetWithArtifacts::childrenCount
virtual int childrenCount() const override
Definition: AssetWithArtifacts.h:38
ResourcesManager
Definition: ResourcesManager.h:80
AssetWithArtifacts::AssetWithArtifacts
AssetWithArtifacts(AssetWrapper *parent, const QString &panelName, T *item, ResourcesManager *resources)
Definition: AssetWithArtifacts.h:28
AssetWithArtifacts::setSpecificItem
void setSpecificItem(const object *item, bool notify)
Definition: AssetWithArtifacts.h:61
guildoracle.list
list
Definition: guildoracle.py:87
AssetWithArtifacts::child
virtual AssetWrapper * child(int child) override
Definition: AssetWithArtifacts.h:42
AssetWithArtifacts::mySpecificItem
const object * mySpecificItem
Definition: AssetWithArtifacts.h:57
AssetWrapper
Definition: AssetWrapper.h:25
AssetWithArtifacts::myArtifacts
std::vector< ArtifactWrapper * > myArtifacts
Definition: AssetWithArtifacts.h:59
object::type
uint8_t type
Definition: object.h:348
AssetWithArtifacts::myResources
ResourcesManager * myResources
Definition: AssetWithArtifacts.h:58
AssetWithArtifacts::updateArtifacts
void updateArtifacts(bool notify)
Definition: AssetWithArtifacts.h:66
AssetWithArtifacts::childIndex
virtual int childIndex(AssetWrapper *child) override
Definition: AssetWithArtifacts.h:48
item
Definition: item.py:1
AssetWrapper::BeforeLayoutChange
@ BeforeLayoutChange
Definition: AssetWrapper.h:33
ArtifactWrapper.h
AssetWrapper::markModified
void markModified(ChangeType change, int extra=0)
Definition: AssetWrapper.h:55
AssetWithArtifacts
Definition: AssetWithArtifacts.h:26
AssetWithArtifacts::~AssetWithArtifacts
virtual ~AssetWithArtifacts()
Definition: AssetWithArtifacts.h:32
say.item
dictionary item
Definition: say.py:149
find_artifactlist
artifactlist * find_artifactlist(int type)
Definition: artifact.cpp:574
legal_artifact_combination
int legal_artifact_combination(const object *op, const artifact *art)
Definition: artifact.cpp:252
AssetTWrapper
Definition: AssetWrapper.h:94