Crossfire Server, Trunk
QuestWrapper.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 QUEST_WRAPPER_H
14 #define QUEST_WRAPPER_H
15 
16 #include <QObject>
17 
18 #include "global.h"
19 #include "quest.h"
20 #include "assets/AssetWrapper.h"
21 #include "CREPixmap.h"
22 
23 class ResourcesManager;
24 
25 class QuestStepWrapper : public AssetTWrapper<quest_step_definition> {
26  Q_OBJECT
27 
28  Q_PROPERTY(int step READ step WRITE setStep)
29  Q_PROPERTY(QString description READ description WRITE setDescription)
30  Q_PROPERTY(bool isEnd READ isEnd WRITE setEnd)
31  Q_PROPERTY(QList<QStringList> conditions READ conditions WRITE setConditions)
32 
33 public:
35  : AssetTWrapper(parent, "QuestStep", step) {
36  }
37 
38  virtual QString displayName() const override { return tr("%1 (%2)%3")
40 
41  virtual void fillMenu(QMenu *menu) override;
42  virtual bool canDrag() const override { return true; }
43  virtual void drag(QMimeData *) const override;
44  virtual bool canDrop(const QMimeData *, int) const override;
45  virtual void drop(const QMimeData *, int) override;
46 
47  int step() const { return myWrappedItem->step; }
48  QString description() const { return myWrappedItem->step_description; }
49  bool isEnd() const { return myWrappedItem->is_completion_step; }
50 
52  void setDescription(QString description) {
54  myWrappedItem->step_description = add_string(description.toLocal8Bit().data());
56  }
57  void setEnd(bool end) {
58  myWrappedItem->is_completion_step = end ? 1 : 0;
60  }
61 
62  QList<QStringList> conditions() const;
63  void setConditions(const QList<QStringList> &conditions);
64 };
65 
66 class QuestWrapper : public AssetTWrapper<quest_definition> {
67  Q_OBJECT
68 
69  Q_PROPERTY(QString code READ code)
70  Q_PROPERTY(QString title READ title WRITE setTitle)
71  Q_PROPERTY(const Face *face READ face WRITE setFace)
72  Q_PROPERTY(const quest_definition *questParent READ questParent WRITE setQuestParent);
73  Q_PROPERTY(bool canRestart READ canRestart WRITE setRestart)
74  Q_PROPERTY(bool isSystem READ isSystem WRITE setSystem)
75  Q_PROPERTY(QString description READ description WRITE setDescription)
76  Q_PROPERTY(QString comment READ comment WRITE setComment)
77 
78 public:
80  : AssetTWrapper(parent, "Quest", quest), myResources(resources) { }
81 
82  virtual QString displayName() const override { return myWrappedItem->quest_title; }
83  virtual QIcon displayIcon() const override { return CREPixmap::getIcon(myWrappedItem->face); }
84 
85  virtual int childrenCount() const override;
86  virtual AssetWrapper *child(int) override;
87  virtual int childIndex(AssetWrapper *) override;
88 
89  virtual bool canDrop(const QMimeData *, int) const override;
90  virtual void drop(const QMimeData *, int) override;
91  virtual void fillMenu(QMenu *menu) override;
92 
93  virtual PossibleUse uses(const AssetWrapper *asset, std::string &) const override;
94 
95  QString code() const { return myWrappedItem->quest_code; }
96  QString title() const { return myWrappedItem->quest_title; }
97  const Face *face() const { return myWrappedItem->face; }
98  const quest_definition *questParent() const { return myWrappedItem->parent; }
99  QString description() const { return myWrappedItem->quest_description; }
100  QString comment() const { return myWrappedItem->quest_comment; }
101  bool canRestart() const { return myWrappedItem->quest_restart; }
102  bool isSystem() const { return myWrappedItem->quest_is_system; }
103 
104  void setTitle(const QString &title) {
105  if (title != myWrappedItem->quest_title) {
107  myWrappedItem->quest_title = add_string(title.toLocal8Bit().data());
109  }
110  }
111  void setFace(const Face *face) {
112  if (face != myWrappedItem->face) {
115  }
116  }
117  void setQuestParent(const quest_definition *parent) {
118  if (parent != myWrappedItem->parent) {
119  myWrappedItem->parent = const_cast<quest_definition *>(parent);
121  }
122  }
123  void setRestart(bool restart) {
124  if (restart != myWrappedItem->quest_restart) {
125  myWrappedItem->quest_restart = restart ? 1 : 0;
127  }
128  }
129  void setSystem(bool system) {
130  if (system != myWrappedItem->quest_is_system) {
131  myWrappedItem->quest_is_system = system;
133  }
134  }
135  void setDescription(const QString &description) {
138  myWrappedItem->quest_description = add_string(description.toLocal8Bit().data());
140  }
141  }
142  void setComment(const QString &comment) {
145  myWrappedItem->quest_comment = add_string(comment.toLocal8Bit().data());
147  }
148  }
149 
150 protected:
152 
153  virtual void wasModified(AssetWrapper *asset, ChangeType type, int extra) override;
154  void addStep();
155  virtual void removeChild(AssetWrapper *child) override;
156 };
157 
158 #endif // QUEST_WRAPPER_H
AssetTWrapper< quest_step_definition >::myWrappedItem
quest_step_definition * myWrappedItem
Definition: AssetWrapper.h:104
Face
Definition: face.h:14
QuestStepWrapper::step
int step() const
Definition: QuestWrapper.h:47
FREE_AND_CLEAR_STR_IF
#define FREE_AND_CLEAR_STR_IF(xyz)
Definition: global.h:200
global.h
AssetWrapper.h
QuestWrapper::childrenCount
virtual int childrenCount() const override
Definition: QuestWrapper.cpp:74
QuestWrapper::title
QString title() const
Definition: QuestWrapper.h:96
AssetWrapper::AssetUpdated
@ AssetUpdated
Definition: AssetWrapper.h:33
QuestStepWrapper::displayName
virtual QString displayName() const override
Definition: QuestWrapper.h:38
QuestWrapper::setTitle
void setTitle(const QString &title)
Definition: QuestWrapper.h:104
ResourcesManager
Definition: ResourcesManager.h:80
QuestWrapper::isSystem
bool isSystem
Definition: QuestWrapper.h:74
QuestWrapper
Definition: QuestWrapper.h:66
AssetWrapper::PossibleUse
PossibleUse
Definition: AssetWrapper.h:32
MimeUtils::QuestStep
static const char * QuestStep
Definition: MimeUtils.h:26
quest_definition::quest_description
sstring quest_description
Definition: quest.h:40
CREPixmap::getIcon
static QIcon getIcon(uint16_t faceNumber)
Definition: CREPixmap.cpp:65
QuestWrapper::code
QString code
Definition: QuestWrapper.h:69
QuestWrapper::comment
QString comment
Definition: QuestWrapper.h:76
QuestStepWrapper::isEnd
bool isEnd() const
Definition: QuestWrapper.h:49
quest_step_definition::step
int step
Definition: quest.h:30
QuestWrapper::setComment
void setComment(const QString &comment)
Definition: QuestWrapper.h:142
QuestWrapper::face
const Face face
Definition: QuestWrapper.h:71
quest_definition::quest_is_system
bool quest_is_system
Definition: quest.h:45
quest_step_definition
Definition: quest.h:29
QuestWrapper::setFace
void setFace(const Face *face)
Definition: QuestWrapper.h:111
QuestWrapper::canRestart
bool canRestart() const
Definition: QuestWrapper.h:101
quest_definition::quest_title
sstring quest_title
Definition: quest.h:39
quest_definition::quest_comment
sstring quest_comment
Definition: quest.h:41
quest
Definition: quest.py:1
QuestWrapper::code
QString code() const
Definition: QuestWrapper.h:95
QuestStepWrapper::isEnd
bool isEnd
Definition: QuestWrapper.h:30
QuestWrapper::drop
virtual void drop(const QMimeData *, int) override
Definition: QuestWrapper.cpp:103
QuestWrapper::displayIcon
virtual QIcon displayIcon() const override
Definition: QuestWrapper.h:83
quest_step_definition::is_completion_step
int is_completion_step
Definition: quest.h:32
QuestWrapper::comment
QString comment() const
Definition: QuestWrapper.h:100
QuestWrapper::canDrop
virtual bool canDrop(const QMimeData *, int) const override
Definition: QuestWrapper.cpp:99
QuestWrapper::description
QString description() const
Definition: QuestWrapper.h:99
QuestStepWrapper::description
QString description() const
Definition: QuestWrapper.h:48
QuestWrapper::removeChild
virtual void removeChild(AssetWrapper *child) override
Definition: QuestWrapper.cpp:154
QuestStepWrapper
Definition: QuestWrapper.h:25
quest_definition::face
const Face * face
Definition: quest.h:43
AssetWrapper
Definition: AssetWrapper.h:25
add_string
sstring add_string(const char *str)
Definition: shstr.cpp:124
QuestWrapper::setSystem
void setSystem(bool system)
Definition: QuestWrapper.h:129
QuestWrapper::face
const Face * face() const
Definition: QuestWrapper.h:97
quest_definition::quest_code
sstring quest_code
Definition: quest.h:38
QuestWrapper::child
virtual AssetWrapper * child(int) override
Definition: QuestWrapper.cpp:78
QuestStepWrapper::step
int step
Definition: QuestWrapper.h:28
QuestWrapper::wasModified
virtual void wasModified(AssetWrapper *asset, ChangeType type, int extra) override
Definition: QuestWrapper.cpp:94
quest_definition::parent
struct quest_definition * parent
Definition: quest.h:47
QuestStepWrapper::setStep
void setStep(int step)
Definition: QuestWrapper.h:51
AssetWrapper::ChangeType
ChangeType
Definition: AssetWrapper.h:33
QuestWrapper::setDescription
void setDescription(const QString &description)
Definition: QuestWrapper.h:135
title
Definition: readable.cpp:108
QuestStepWrapper::canDrag
virtual bool canDrag() const override
Definition: QuestWrapper.h:42
QuestWrapper::myResources
ResourcesManager * myResources
Definition: QuestWrapper.h:151
QuestWrapper::isSystem
bool isSystem() const
Definition: QuestWrapper.h:102
QuestStepWrapper::canDrop
virtual bool canDrop(const QMimeData *, int) const override
Definition: QuestWrapper.cpp:30
QuestStepWrapper::setEnd
void setEnd(bool end)
Definition: QuestWrapper.h:57
QuestWrapper::canRestart
bool canRestart
Definition: QuestWrapper.h:72
QuestStepWrapper::fillMenu
virtual void fillMenu(QMenu *menu) override
Definition: QuestWrapper.cpp:19
QuestWrapper::setQuestParent
void setQuestParent(const quest_definition *parent)
Definition: QuestWrapper.h:117
quest.h
QuestWrapper::fillMenu
virtual void fillMenu(QMenu *menu) override
Definition: QuestWrapper.cpp:137
QuestWrapper::questParent
const quest_definition questParent
Definition: QuestWrapper.h:72
QuestStepWrapper::conditions
QList< QStringList > conditions
Definition: QuestWrapper.h:31
quest_definition
Definition: quest.h:37
QuestStepWrapper::setConditions
void setConditions(const QList< QStringList > &conditions)
Definition: QuestWrapper.cpp:49
QuestWrapper::uses
virtual PossibleUse uses(const AssetWrapper *asset, std::string &) const override
Definition: QuestWrapper.cpp:66
QuestWrapper::displayName
virtual QString displayName() const override
Definition: QuestWrapper.h:82
QuestStepWrapper::drop
virtual void drop(const QMimeData *, int) override
Definition: QuestWrapper.cpp:34
QuestWrapper::description
QString description
Definition: QuestWrapper.h:75
AssetWrapper::markModified
void markModified(ChangeType change, int extra=0)
Definition: AssetWrapper.h:55
QuestStepWrapper::description
QString description
Definition: QuestWrapper.h:29
QuestWrapper::questParent
const quest_definition * questParent() const
Definition: QuestWrapper.h:98
quest_step_definition::step_description
sstring step_description
Definition: quest.h:31
QuestWrapper::addStep
void addStep()
Definition: QuestWrapper.cpp:144
QuestWrapper::setRestart
void setRestart(bool restart)
Definition: QuestWrapper.h:123
QuestWrapper::childIndex
virtual int childIndex(AssetWrapper *) override
Definition: QuestWrapper.cpp:85
quest_definition::quest_restart
int quest_restart
Definition: quest.h:42
CREPixmap.h
QuestStepWrapper::setDescription
void setDescription(QString description)
Definition: QuestWrapper.h:52
is_valid_types_gen.type
list type
Definition: is_valid_types_gen.py:25
QuestStepWrapper::drag
virtual void drag(QMimeData *) const override
Definition: QuestWrapper.cpp:23
AssetTWrapper
Definition: AssetWrapper.h:94