Crossfire Server, Trunk
TreasureListPanel.cpp
Go to the documentation of this file.
1 #include <Qt>
2 
3 extern "C" {
4 #include "global.h"
5 #include "treasure.h"
6 }
7 
8 #include "TreasureListPanel.h"
9 #include "CREUtils.h"
10 
11 #include "assets.h"
12 #include "AssetsManager.h"
13 #include "TreasureListWrapper.h"
14 #include "TreasureWrapper.h"
15 
17 
18  addCheckBox(tr("Single item"), "isSingleItem", false);
19 
20  myLayout->addWidget(new QLabel("Difficulty:"), 2, 0);
21  myLayout->addWidget(myDifficulty = new QSpinBox(this), 2, 1);
22  myDifficulty->setRange(0, 150);
23  myDifficulty->setValue(150);
24  QPushButton* generate = new QPushButton("generate", this);
25  connect(generate, SIGNAL(clicked(bool)), this, SLOT(onGenerate(bool)));
26  myLayout->addWidget(generate, 2, 2);
27  myLayout->addWidget(myGenerated = new QTreeWidget(this), 3, 0, 1, 3);
28  myGenerated->setHeaderLabel(tr("Generation result"));
29  myGenerated->setIconSize(QSize(32, 32));
30 
31  myUsing = new QTreeWidget(this);
32  myUsing->setColumnCount(1);
33  myUsing->setHeaderLabel(tr("Used by"));
34  myUsing->setIconSize(QSize(32, 32));
35  myLayout->addWidget(myUsing, 1, 4, 3, 1);
36 }
37 
40  myTreasure = dynamic_cast<TreasureListWrapper *>(asset);
41  Q_ASSERT(myTreasure);
42 
43  myUsing->clear();
44 
45  QTreeWidgetItem* root = NULL;
46 
47  QString name = myTreasure->displayName();
48 
49  getManager()->archetypes()->each([this, &root, &name] (const archetype * arch) {
50  if (arch->clone.randomitems && name == arch->clone.randomitems->name) {
51  if (root == NULL) {
52  root = CREUtils::archetypeNode(NULL);
53  myUsing->addTopLevelItem(root);
54  root->setExpanded(true);
55  }
57  }
58  });
59 
60  root = NULL;
61 
62  getManager()->treasures()->each([this, &root, &name] (treasurelist * list) {
63  for (const treasure *t = list->items; t; t = t->next) {
64  if (t->name == name) {
65  if (root == NULL) {
66  root = CREUtils::treasureNode(NULL);
67  myUsing->addTopLevelItem(root);
68  root->setExpanded(true);
69  }
70  CREUtils::treasureNode(list, root);
71  }
72  }
73  });
74 
75  myGenerated->clear();
76 }
77 
79  const int difficulty = myDifficulty->value();
80  myGenerated->clear();
81  object* result = object_new(), *item;
82  create_treasure(const_cast<treasurelist *>(myTreasure->wrappedItem()), result, 0, difficulty, 0);
83  while ((item = result->inv)) {
84  identify(result->inv);
85  myGenerated->addTopLevelItem(CREUtils::objectNode(item, NULL));
86 
88  object_free(item, 0);
89  }
90 
91  object_free(result, 0);
92 }
AssetWrapperPanel
Definition: AssetWrapperPanel.h:16
global.h
object_free
void object_free(object *ob, int flags)
Definition: object.c:1578
object_remove
void object_remove(object *op)
Definition: object.c:1819
TreasureListPanel.h
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
AssetsManager.h
CRETreasurePanel::myDifficulty
QSpinBox * myDifficulty
Definition: TreasureListPanel.h:25
object_new
object * object_new(void)
Definition: object.c:1255
CRETreasurePanel::myUsing
QTreeWidget * myUsing
Definition: TreasureListPanel.h:23
CREUtils::archetypeNode
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:14
CREUtils.h
guildoracle.list
list
Definition: guildoracle.py:87
root
static char root[500]
Definition: mapper.cpp:305
AssetWrapperPanel::setItem
virtual void setItem(AssetWrapper *item) override
Definition: AssetWrapperPanel.cpp:13
CRETreasurePanel::myTreasure
TreasureListWrapper * myTreasure
Definition: TreasureListPanel.h:22
CRETreasurePanel::CRETreasurePanel
CRETreasurePanel(QWidget *parent)
Definition: TreasureListPanel.cpp:16
TreasureListWrapper
Definition: TreasureListWrapper.h:17
create_treasure
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:241
getManager
AssetsManager * getManager()
Definition: assets.cpp:333
treasurestruct
Definition: treasure.h:63
archt
Definition: object.h:470
identify
object * identify(object *op)
Definition: item.c:1409
AssetWrapperPanel::myLayout
QGridLayout * myLayout
Definition: AssetWrapperPanel.h:37
AssetsManager::treasures
Treasures * treasures()
Definition: AssetsManager.h:54
CRETreasurePanel::onGenerate
void onGenerate(bool pressed)
Definition: TreasureListPanel.cpp:78
AssetWrapper
Definition: AssetWrapper.h:11
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:135
AssetTWrapper::wrappedItem
T * wrappedItem() const
Definition: AssetWrapper.h:79
AssetsManager::archetypes
Archetypes * archetypes()
Definition: AssetsManager.h:44
treasure.h
Floor.t
t
Definition: Floor.py:62
item
Definition: item.py:1
CREUtils::objectNode
static QTreeWidgetItem * objectNode(const object *op, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:27
TreasureListWrapper.h
assets.h
TreasureListWrapper::displayName
virtual QString displayName() const override
Definition: TreasureListWrapper.h:28
CRETreasurePanel::myGenerated
QTreeWidget * myGenerated
Definition: TreasureListPanel.h:24
say.item
dictionary item
Definition: say.py:149
connect
Definition: connect.py:1
AssetWrapperPanel::addCheckBox
QCheckBox * addCheckBox(const QString &label, const char *property, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:59
TreasureWrapper.h
CRETreasurePanel::setItem
virtual void setItem(AssetWrapper *asset) override
Definition: TreasureListPanel.cpp:38
treasureliststruct
Definition: treasure.h:82
obj::inv
struct obj * inv
Definition: object.h:293
give.name
name
Definition: give.py:27