Crossfire Server, Trunk
TreasureWrapper.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 TREASURE_WRAPPER_H
14 #define TREASURE_WRAPPER_H
15 
16 #include <vector>
17 
18 #include <QObject>
19 #include <QStringList>
20 
21 #include "global.h"
22 
23 #include "CREPixmap.h"
26 
27 class ResourcesManager;
28 class TreasureYesNo;
29 
33 class TreasureWrapper : public AssetWithArtifacts<treasure> {
34  Q_OBJECT
35 
36  Q_PROPERTY(quint8 chance READ chance WRITE setChance)
37  Q_PROPERTY(quint8 magic READ magic WRITE setMagic)
38  Q_PROPERTY(quint16 nrof READ nrof WRITE setNrof)
39  Q_PROPERTY(const treasurelist *list READ list WRITE setList)
40  Q_PROPERTY(quint8 list_magic_value READ listMagicValue WRITE setListMagicValue)
42  Q_PROPERTY(const archetype *arch READ arch WRITE setArch)
43  Q_PROPERTY(QString artifact READ artifact WRITE setArtifact)
44 
45 public:
46  TreasureWrapper(AssetWrapper *parent, treasure *tr, ResourcesManager *resources);
47  virtual ~TreasureWrapper();
48 
49  virtual QString displayName() const override;
50  virtual QIcon displayIcon() const override;
51 
52  virtual int childrenCount() const override;
53  virtual AssetWrapper *child(int child) override;
54  virtual int childIndex(AssetWrapper *child) override;
55  virtual void removeChild(AssetWrapper *child) override;
56 
57  virtual PossibleUse uses(const AssetWrapper *asset, std::string &) const override;
58 
59  virtual bool canDrop(const QMimeData *data, int row) const override;
60  virtual void drop(const QMimeData *data, int row) override;
61 
62  virtual void fillMenu(QMenu *menu) override;
63 
64  uint8_t chance() const;
65  void setChance(uint8_t chance);
66  uint8_t magic() const;
67  void setMagic(uint8_t magic);
68  uint16_t nrof() const;
69  void setNrof(uint16_t nrof);
70  const treasurelist *list() const;
71  void setList(const treasurelist *list);
72  quint8 listMagicValue() const;
73  void setListMagicValue(quint8 value);
74  qint8 listMagicAdjustment() const;
75  void setListMagicAdjustment(qint8 value);
76  const archetype *arch() const;
77  void setArch(const archetype *arch);
78  const QString artifact() const;
79  void setArtifact(const QString &art);
80 
81 public slots:
82  void swapYesNo();
83 
84 protected:
87 
88  void doAddChild(TreasureYesNo **my, treasure **ti, bool isYes, int index, treasurelist *tl, archetype *arch);
89  void addChild(treasurelist *tl, archetype *arch);
90  void doRemoveChild(TreasureYesNo **tr, treasure **ti, int index);
91 };
92 
93 class TreasureYesNo : public AssetWrapper {
94  Q_OBJECT
95 public:
96  TreasureYesNo(TreasureWrapper *parent, treasure *tr, ResourcesManager *resources, bool isYes);
97 
98  virtual QString displayName() const override { return myIsYes ? "Yes" : "No"; }
99  virtual QIcon displayIcon() const override { return myIsYes ? CREPixmap::getTreasureYesIcon() : CREPixmap::getTreasureNoIcon(); }
100 
101  virtual int childrenCount() const override { return 1; }
102  virtual AssetWrapper *child(int child) override { return child == 0 ? myWrapped : nullptr; }
103  virtual int childIndex(AssetWrapper *child) override { return child == myWrapped ? 0 : -1; }
104  virtual void removeChild(AssetWrapper *) override { myParent->removeChild(this); }
105 
106  virtual void fillMenu(QMenu *menu) override;
107  void setIsYes(bool isYes) { myIsYes = isYes; }
108 
109 protected:
110  bool myIsYes;
112 };
113 
114 #endif /* TREASURE_WRAPPER_H */
global.h
TreasureYesNo::setIsYes
void setIsYes(bool isYes)
Definition: TreasureWrapper.h:107
TreasureWrapper::canDrop
virtual bool canDrop(const QMimeData *data, int row) const override
Definition: TreasureWrapper.cpp:178
TreasureWrapper::addChild
void addChild(treasurelist *tl, archetype *arch)
Definition: TreasureWrapper.cpp:168
TreasureWrapper::setList
void setList(const treasurelist *list)
Definition: TreasureWrapper.cpp:234
TreasureWrapper::list_magic_adjustment
qint8 list_magic_adjustment
Definition: TreasureWrapper.h:41
ResourcesManager
Definition: ResourcesManager.h:80
TreasureWrapper::chance
quint8 chance
Definition: TreasureWrapper.h:36
TreasureWrapper::setMagic
void setMagic(uint8_t magic)
Definition: TreasureWrapper.cpp:212
AssetWrapper::PossibleUse
PossibleUse
Definition: AssetWrapper.h:32
TreasureYesNo::removeChild
virtual void removeChild(AssetWrapper *) override
Definition: TreasureWrapper.h:104
AssetWrapper::removeChild
virtual void removeChild(AssetWrapper *)
Definition: AssetWrapper.h:71
TreasureWrapper::myNextNo
TreasureYesNo * myNextNo
Definition: TreasureWrapper.h:86
TreasureWrapper::arch
const archetype arch
Definition: TreasureWrapper.h:42
TreasureYesNo::displayIcon
virtual QIcon displayIcon() const override
Definition: TreasureWrapper.h:99
TreasureWrapper::setChance
void setChance(uint8_t chance)
Definition: TreasureWrapper.cpp:201
TreasureWrapper::removeChild
virtual void removeChild(AssetWrapper *child) override
Definition: TreasureWrapper.cpp:147
TreasureYesNo::myWrapped
AssetWrapper * myWrapped
Definition: TreasureWrapper.h:111
TreasureWrapper::displayIcon
virtual QIcon displayIcon() const override
Definition: TreasureWrapper.cpp:72
TreasureWrapper::drop
virtual void drop(const QMimeData *data, int row) override
Definition: TreasureWrapper.cpp:185
TreasureWrapper::doRemoveChild
void doRemoveChild(TreasureYesNo **tr, treasure **ti, int index)
Definition: TreasureWrapper.cpp:136
TreasureWrapper
Definition: TreasureWrapper.h:33
TreasureWrapper::childrenCount
virtual int childrenCount() const override
Definition: TreasureWrapper.cpp:87
CREPixmap::getTreasureYesIcon
static QIcon getTreasureYesIcon()
Definition: CREPixmap.cpp:114
treasurelist
Definition: treasure.h:85
AssetWrapper
Definition: AssetWrapper.h:25
AssetWrapper::myParent
AssetWrapper * myParent
Definition: AssetWrapper.h:86
navar-midane_time.data
data
Definition: navar-midane_time.py:11
archetype
Definition: object.h:483
TreasureYesNo::childIndex
virtual int childIndex(AssetWrapper *child) override
Definition: TreasureWrapper.h:103
TreasureWrapper::uses
virtual PossibleUse uses(const AssetWrapper *asset, std::string &) const override
Definition: TreasureWrapper.cpp:320
TreasureWrapper::swapYesNo
void swapYesNo()
Definition: TreasureWrapper.cpp:305
TreasureYesNo
Definition: TreasureWrapper.h:93
TreasureYesNo::displayName
virtual QString displayName() const override
Definition: TreasureWrapper.h:98
TreasureWrapper::list_magic_value
quint8 list_magic_value
Definition: TreasureWrapper.h:40
TreasureWrapper::myNextYes
TreasureYesNo * myNextYes
Definition: TreasureWrapper.h:85
TreasureWrapper::child
virtual AssetWrapper * child(int child) override
Definition: TreasureWrapper.cpp:98
TreasureWrapper::setArtifact
void setArtifact(const QString &art)
Definition: TreasureWrapper.cpp:287
AssetWithArtifacts.h
TreasureWrapper::magic
quint8 magic
Definition: TreasureWrapper.h:37
TreasureYesNo::child
virtual AssetWrapper * child(int child) override
Definition: TreasureWrapper.h:102
TreasureYesNo::childrenCount
virtual int childrenCount() const override
Definition: TreasureWrapper.h:101
autojail.value
value
Definition: autojail.py:6
TreasureWrapper::setListMagicAdjustment
void setListMagicAdjustment(qint8 value)
Definition: TreasureWrapper.cpp:260
TreasureWrapper::setListMagicValue
void setListMagicValue(quint8 value)
Definition: TreasureWrapper.cpp:250
std
Definition: json.hpp:4494
TreasureWrapper::childIndex
virtual int childIndex(AssetWrapper *child) override
Definition: TreasureWrapper.cpp:114
npc_dialog.index
int index
Definition: npc_dialog.py:102
TreasureWrapper::setArch
void setArch(const archetype *arch)
Definition: TreasureWrapper.cpp:272
TreasureWrapper::nrof
quint16 nrof
Definition: TreasureWrapper.h:38
ArtifactWrapper.h
AssetWithArtifacts
Definition: AssetWithArtifacts.h:26
TreasureWrapper::fillMenu
virtual void fillMenu(QMenu *menu) override
Definition: TreasureWrapper.cpp:298
TreasureWrapper::listMagicValue
quint8 listMagicValue() const
Definition: TreasureWrapper.cpp:246
TreasureWrapper::setNrof
void setNrof(uint16_t nrof)
Definition: TreasureWrapper.cpp:223
treasure
Definition: treasure.h:63
artifact
Definition: artifact.h:14
TreasureWrapper::listMagicAdjustment
qint8 listMagicAdjustment() const
Definition: TreasureWrapper.cpp:257
TreasureWrapper::displayName
virtual QString displayName() const override
Definition: TreasureWrapper.cpp:42
TreasureYesNo::myIsYes
bool myIsYes
Definition: TreasureWrapper.h:110
CREPixmap::getTreasureNoIcon
static QIcon getTreasureNoIcon()
Definition: CREPixmap.cpp:120
CREPixmap.h
TreasureWrapper::list
const treasurelist list
Definition: TreasureWrapper.h:39
TreasureWrapper::doAddChild
void doAddChild(TreasureYesNo **my, treasure **ti, bool isYes, int index, treasurelist *tl, archetype *arch)
Definition: TreasureWrapper.cpp:157