Crossfire Server, Trunk
TreasureListWrapper.cpp
Go to the documentation of this file.
1 #include "TreasureListWrapper.h"
2 #include "../ResourcesManager.h"
3 #include "../CREPixmap.h"
4 #include "MimeUtils.h"
5 #include "TreasureLoader.h"
6 #include "assets.h"
7 #include "AssetsManager.h"
8 
10  : AssetTWrapper(parent, "TreasureList", list), myResources(resources)
11 {
12 }
13 
15  int count = 0;
16  auto item = myWrappedItem->items;
17  while (item) {
18  count++;
19  item = item->next;
20  }
21  return count;
22 }
23 
25  return itemCount();
26 }
27 
29  auto item = myWrappedItem->items;
30  while (item && child > 0) {
31  item = item->next;
32  child--;
33  }
34  return myResources->wrap(item, this);
35 }
36 
38  auto item = myWrappedItem->items;
39  int index = 0;
40  while (item) {
41  if (myResources->wrap(item, this) == child) {
42  return index;
43  }
44  item = item->next;
45  index++;
46  }
47  return -1;
48 }
49 
51  AssetWrapperPanel *p = static_cast<AssetWrapperPanel *>(panel);
52  p->setItem(this);
53 }
54 
56  if (isSingle == isSingleItem()) {
57  return;
58  }
59  if (isSingle) {
61  } else {
63  }
65 }
66 
69  auto item = myWrappedItem->items;
70  while (item) {
71  myWrappedItem->total_chance += item->chance;
72  item = item->next;
73  }
74 }
75 
78  if (childIndex(asset) != -1 && type == AssetUpdated) {
82  return;
83  }
84  }
85  AssetWrapper::wasModified(asset, type, extra);
86 }
87 
88 void TreasureListWrapper::drag(QMimeData *data) const {
89  QByteArray ba(data->data(MimeUtils::TreasureList));
90  QDataStream df(&ba, QIODevice::WriteOnly);
91  df << QString(myWrappedItem->name);
92  data->setData(MimeUtils::TreasureList, ba);
93 }
94 
95 bool TreasureListWrapper::canDrop(const QMimeData *data, int) const {
96  return
97  data->hasFormat(MimeUtils::Archetype)
98  || data->hasFormat(MimeUtils::TreasureList)
99  ;
100 }
101 
102 void TreasureListWrapper::drop(const QMimeData *data, int row) {
103  bool modified = false;
104  if (row == -1) {
105  row = childrenCount();
106  }
107 
108  auto archs = MimeUtils::extract(data, MimeUtils::Archetype, getManager()->archetypes());
109  modified |= !archs.empty();
110  for (auto arch : archs) {
112  auto item = treasure_insert(myWrappedItem, row);
113  item->item = arch;
115  row++;
116  }
117 
119  modified |= !lists.empty();
120  for (auto list : lists) {
122  auto item = treasure_insert(myWrappedItem, row);
123  item->name = add_string(list->name);
125  row++;
126  }
128  fixTotalChance();
130  }
131 }
132 
134  int index = childIndex(child);
135  if (index != -1) {
136  auto t = dynamic_cast<TreasureWrapper *>(child);
138  myResources->remove(t->wrappedItem());
142  fixTotalChance();
144  return;
145  }
146  }
147 }
ResourcesManager::treasureModified
void treasureModified(treasurelist *treasure)
Definition: ResourcesManager.cpp:197
AssetWrapperPanel
Definition: AssetWrapperPanel.h:16
MimeUtils::Archetype
static const char * Archetype
Definition: MimeUtils.h:12
AssetTWrapper< treasurelist >::myWrappedItem
treasurelist * myWrappedItem
Definition: AssetWrapper.h:87
TreasureListWrapper::myResources
ResourcesManager * myResources
Definition: TreasureListWrapper.h:49
add_string
sstring add_string(const char *str)
Definition: shstr.c:124
TreasureListWrapper::TreasureListWrapper
TreasureListWrapper(AssetWrapper *parent, treasurelist *list, ResourcesManager *resources)
Definition: TreasureListWrapper.cpp:9
AssetWrapper::AssetUpdated
@ AssetUpdated
Definition: AssetWrapper.h:15
ResourcesManager
Definition: ResourcesManager.h:67
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
AssetWrapper::AfterChildAdd
@ AfterChildAdd
Definition: AssetWrapper.h:15
AssetsManager.h
TreasureListWrapper::fixTotalChance
void fixTotalChance()
Definition: TreasureListWrapper.cpp:67
lists
ignore_list ** lists
Definition: gridarta-types-convert.c:73
TreasureListWrapper::wasModified
virtual void wasModified(AssetWrapper *asset, ChangeType type, int extra) override
Definition: TreasureListWrapper.cpp:76
guildoracle.list
list
Definition: guildoracle.py:87
TreasureListWrapper::setSingleItem
void setSingleItem(bool isSingle)
Definition: TreasureListWrapper.cpp:55
ResourcesManager::wrap
ArchetypeWrapper * wrap(archt *arch, AssetWrapper *parent)
Definition: ResourcesManager.h:112
AssetWrapper::AfterChildRemove
@ AfterChildRemove
Definition: AssetWrapper.h:15
TreasureListWrapper::drag
virtual void drag(QMimeData *data) const override
Definition: TreasureListWrapper.cpp:88
AssetWrapperPanel::setItem
virtual void setItem(AssetWrapper *item) override
Definition: AssetWrapperPanel.cpp:13
TreasureLoader.h
treasureliststruct::name
sstring name
Definition: treasure.h:83
TreasureListWrapper::child
virtual AssetWrapper * child(int child) override
Definition: TreasureListWrapper.cpp:28
getManager
AssetsManager * getManager()
Definition: assets.cpp:333
treasure_remove_item
void treasure_remove_item(treasurelist *list, int position)
Definition: treasure.c:1414
MimeUtils::TreasureList
static const char * TreasureList
Definition: MimeUtils.h:13
AssetWrapper::BeforeChildAdd
@ BeforeChildAdd
Definition: AssetWrapper.h:15
TreasureWrapper
Definition: TreasureWrapper.h:20
AssetWrapper
Definition: AssetWrapper.h:11
AssetWrapper::ChangeType
ChangeType
Definition: AssetWrapper.h:15
TreasureListWrapper::removeChild
virtual void removeChild(AssetWrapper *child) override
Definition: TreasureListWrapper.cpp:133
navar-midane_time.data
data
Definition: navar-midane_time.py:11
disinfect.count
int count
Definition: disinfect.py:7
TreasureListWrapper::childrenCount
virtual int childrenCount() const override
Definition: TreasureListWrapper.cpp:24
AssetWrapper::modified
void modified()
TreasureListWrapper::isSingleItem
bool isSingleItem
Definition: TreasureListWrapper.h:23
MimeUtils::extract
static QList< T * > extract(const QMimeData *data, const QString &mime, AssetsCollection< T > *assets)
Definition: MimeUtils.h:18
treasureliststruct::total_chance
int16_t total_chance
Definition: treasure.h:84
TreasureListWrapper::displayFillPanel
virtual void displayFillPanel(QWidget *panel) override
Definition: TreasureListWrapper.cpp:50
treasureliststruct::items
struct treasurestruct * items
Definition: treasure.h:89
treasure_insert
treasure * treasure_insert(treasurelist *list, int position)
Definition: treasure.c:1391
Floor.t
t
Definition: Floor.py:62
TreasureListWrapper::canDrop
virtual bool canDrop(const QMimeData *data, int row) const override
Definition: TreasureListWrapper.cpp:95
item
Definition: item.py:1
ResourcesManager::remove
void remove(treasure *tr)
Definition: ResourcesManager.h:130
AssetWrapper::wasModified
virtual void wasModified(AssetWrapper *asset, ChangeType type, int extra)
Definition: AssetWrapper.h:59
TreasureListWrapper::itemCount
int itemCount
Definition: TreasureListWrapper.h:22
TreasureListWrapper.h
assets.h
npc_dialog.index
int index
Definition: npc_dialog.py:102
AssetWrapper::BeforeChildRemove
@ BeforeChildRemove
Definition: AssetWrapper.h:15
MimeUtils.h
AssetWrapper::markModified
void markModified(ChangeType change, int extra=0)
Definition: AssetWrapper.h:36
TreasureListWrapper::drop
virtual void drop(const QMimeData *data, int row) override
Definition: TreasureListWrapper.cpp:102
TreasureListWrapper::childIndex
virtual int childIndex(AssetWrapper *child) override
Definition: TreasureListWrapper.cpp:37
treasureliststruct
Definition: treasure.h:82
is_valid_types_gen.type
list type
Definition: is_valid_types_gen.py:25
AssetTWrapper
Definition: AssetWrapper.h:72