Crossfire Server, Trunk
TreasureListWrapper.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_LIST_WRAPPER_H
14 #define TREASURE_LIST_WRAPPER_H
15 
16 #include <QObject>
17 #include <QStringList>
18 
19 #include "global.h"
20 
21 #include "assets/AssetWrapper.h"
22 #include "CREPixmap.h"
23 
24 class ResourcesManager;
25 class TreasureWrapper;
26 
27 class TreasureListWrapper : public AssetTWrapper<treasurelist> {
28  Q_OBJECT
29 
30  Q_PROPERTY(QString name READ displayName)
31  Q_PROPERTY(int totalChance READ totalChance)
32  Q_PROPERTY(int itemCount READ itemCount)
33  Q_PROPERTY(bool isSingleItem READ isSingleItem WRITE setSingleItem)
34 
35 public:
37 
38  virtual QString displayName() const override { return myWrappedItem->name; }
39  virtual QIcon displayIcon() const override { return myWrappedItem->total_chance == 0 ? CREPixmap::getTreasureIcon() : CREPixmap::getTreasureOneIcon(); }
40 
41  virtual int childrenCount() const override;
42  virtual AssetWrapper *child(int child) override;
43  virtual int childIndex(AssetWrapper *child) override;
44  virtual void removeChild(AssetWrapper *child) override;
45 
46  virtual bool canDrag() const override { return true; }
47  virtual void drag(QMimeData *data) const override;
48  virtual bool canDrop(const QMimeData *data, int row) const override;
49  virtual void drop(const QMimeData *data, int row) override;
50 
51  int totalChance() const { return myWrappedItem->total_chance; }
52  void fixTotalChance();
53  bool isSingleItem() const { return myWrappedItem->total_chance != 0; }
54  void setSingleItem(bool isSingle);
55  int itemCount() const;
56 
57  virtual PossibleUse uses(const AssetWrapper *, std::string &) const override;
58 
59 protected:
61 
62  virtual void wasModified(AssetWrapper *asset, ChangeType type, int extra) override;
63 };
64 
65 #endif /* TREASURE_LIST_WRAPPER_H */
AssetTWrapper< treasurelist >::myWrappedItem
treasurelist * myWrappedItem
Definition: AssetWrapper.h:104
global.h
TreasureListWrapper::myResources
ResourcesManager * myResources
Definition: TreasureListWrapper.h:60
AssetWrapper.h
ResourcesManager
Definition: ResourcesManager.h:80
TreasureListWrapper::fixTotalChance
void fixTotalChance()
Definition: TreasureListWrapper.cpp:75
TreasureListWrapper::wasModified
virtual void wasModified(AssetWrapper *asset, ChangeType type, int extra) override
Definition: TreasureListWrapper.cpp:84
treasurelist::total_chance
int16_t total_chance
Definition: treasure.h:87
CREPixmap::getTreasureIcon
static QIcon getTreasureIcon()
Definition: CREPixmap.cpp:102
AssetWrapper::PossibleUse
PossibleUse
Definition: AssetWrapper.h:32
guildoracle.list
list
Definition: guildoracle.py:87
TreasureListWrapper::setSingleItem
void setSingleItem(bool isSingle)
Definition: TreasureListWrapper.cpp:63
TreasureListWrapper::drag
virtual void drag(QMimeData *data) const override
Definition: TreasureListWrapper.cpp:96
TreasureListWrapper
Definition: TreasureListWrapper.h:27
TreasureListWrapper::child
virtual AssetWrapper * child(int child) override
Definition: TreasureListWrapper.cpp:41
TreasureListWrapper::uses
virtual PossibleUse uses(const AssetWrapper *, std::string &) const override
Definition: TreasureListWrapper.cpp:157
TreasureListWrapper::totalChance
int totalChance() const
Definition: TreasureListWrapper.h:51
TreasureListWrapper::displayIcon
virtual QIcon displayIcon() const override
Definition: TreasureListWrapper.h:39
TreasureWrapper
Definition: TreasureWrapper.h:33
treasurelist
Definition: treasure.h:85
AssetWrapper
Definition: AssetWrapper.h:25
treasurelist::name
sstring name
Definition: treasure.h:86
AssetWrapper::ChangeType
ChangeType
Definition: AssetWrapper.h:33
TreasureListWrapper::removeChild
virtual void removeChild(AssetWrapper *child) override
Definition: TreasureListWrapper.cpp:141
navar-midane_time.data
data
Definition: navar-midane_time.py:11
TreasureListWrapper::childrenCount
virtual int childrenCount() const override
Definition: TreasureListWrapper.cpp:37
TreasureListWrapper::isSingleItem
bool isSingleItem
Definition: TreasureListWrapper.h:33
TreasureListWrapper::totalChance
int totalChance
Definition: TreasureListWrapper.h:31
TreasureListWrapper::isSingleItem
bool isSingleItem() const
Definition: TreasureListWrapper.h:53
TreasureListWrapper::canDrop
virtual bool canDrop(const QMimeData *data, int row) const override
Definition: TreasureListWrapper.cpp:103
TreasureListWrapper::itemCount
int itemCount
Definition: TreasureListWrapper.h:32
CREPixmap::getTreasureOneIcon
static QIcon getTreasureOneIcon()
Definition: CREPixmap.cpp:108
TreasureListWrapper::displayName
virtual QString displayName() const override
Definition: TreasureListWrapper.h:38
TreasureListWrapper::drop
virtual void drop(const QMimeData *data, int row) override
Definition: TreasureListWrapper.cpp:110
TreasureListWrapper::childIndex
virtual int childIndex(AssetWrapper *child) override
Definition: TreasureListWrapper.cpp:50
TreasureListWrapper::canDrag
virtual bool canDrag() const override
Definition: TreasureListWrapper.h:46
CREPixmap.h
is_valid_types_gen.type
list type
Definition: is_valid_types_gen.py:25
TreasureListWrapper::name
QString name
Definition: TreasureListWrapper.h:30
AssetTWrapper
Definition: AssetWrapper.h:94