Crossfire Server, Trunk
CREUtils.cpp
Go to the documentation of this file.
1 #include <QtWidgets>
2 #include "CREUtils.h"
3 #include "CREPixmap.h"
4 #include "CREMapInformation.h"
5 #include "MessageFile.h"
6 #include "scripts/ScriptFile.h"
7 
8 extern "C" {
9 #include "global.h"
10 #include "recipe.h"
11 #include "libproto.h"
12 }
13 
14 QTreeWidgetItem* CREUtils::archetypeNode(QTreeWidgetItem* parent)
15 {
16  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Archetypes")));
17  return item;
18 }
19 
20 QTreeWidgetItem* CREUtils::archetypeNode(const archt* arch, QTreeWidgetItem* parent)
21 {
22  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(arch->name));
23  item->setIcon(0, CREPixmap::getIcon(arch->clone.face ? arch->clone.face->number : 0));
24  return item;
25 }
26 
27 QTreeWidgetItem* CREUtils::objectNode(const object* op, QTreeWidgetItem* parent)
28 {
29  char name[500];
30  query_name(op, name, sizeof(name));
31  QString n;
32  if (op->nrof > 1)
33  n.append(QString::number(op->nrof)).append(" ");
34  n.append(name);
35  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(n));
36  item->setIcon(0, CREPixmap::getIcon(op->face->number));
37  return item;
38 }
39 
40 QTreeWidgetItem* CREUtils::treasureNode(QTreeWidgetItem* parent)
41 {
42  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Treasures")));
43  return item;
44 }
45 
46 QTreeWidgetItem* CREUtils::treasureNode(const treasurelist* list, QTreeWidgetItem* parent)
47 {
48  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(list->name));
49  if (list->total_chance == 0)
50  item->setIcon(0, CREPixmap::getTreasureIcon());
51  else
52  item->setIcon(0, CREPixmap::getTreasureOneIcon());
53  return item;
54 }
55 
56 QTreeWidgetItem* CREUtils::treasureNode(const treasure* treasure, const treasurelist* list, QTreeWidgetItem* parent)
57 {
58  QTreeWidgetItem* item;
59  if (treasure->item)
60  {
62  if (treasure->next_yes)
63  {
64  QTreeWidgetItem* node = new QTreeWidgetItem(item, QStringList(QTreeWidget::tr("Yes")));
65  node->setIcon(0, CREPixmap::getTreasureYesIcon());
67  }
68  if (treasure->next_no)
69  {
70  QTreeWidgetItem* node = new QTreeWidgetItem(item, QStringList(QTreeWidget::tr("No")));
71  node->setIcon(0, CREPixmap::getTreasureNoIcon());
73  }
74  }
75  else
76  {
77  if (treasure->name && strcmp(treasure->name, "NONE") == 0)
78  item = new QTreeWidgetItem(parent, QStringList(QString(QTreeWidget::tr("Nothing"))));
79  else
80  {
82  item = CREUtils::treasureNode(other, parent);
83  }
84  }
85 
86  if (list->total_chance != 0)
87  {
88  item->setText(0, QTreeWidget::tr("%1 (%2%3%, %4 chances on %5)")
89  .arg(item->text(0))
90  .arg(treasure->nrof > 0 ? QTreeWidget::tr("1 to %2, ").arg(treasure->nrof) : "")
91  .arg(qRound((float)100 * treasure->chance / list->total_chance))
92  .arg(treasure->chance)
93  .arg(list->total_chance));
94  }
95  else
96  {
97  item->setText(0, QTreeWidget::tr("%1 (%2%3%)")
98  .arg(item->text(0))
99  .arg(treasure->nrof > 0 ? QTreeWidget::tr("1 to %2, ").arg(treasure->nrof) : "")
100  .arg(treasure->chance));
101  }
102 
103  return item;
104 }
105 
106 QTreeWidgetItem* CREUtils::formulaeNode(const recipe* recipe, QTreeWidgetItem* parent)
107 {
108  QString title;
109  const archt* base = NULL;
110 
111  if (recipe->arch_names == 0)
112  {
113  title = QString("%1 (no archetype?)").arg(recipe->title);
114  }
115  else
116  {
117  base = find_archetype(recipe->arch_name[0]);
118  if (!base)
119  {
120  title = QString("%1 (no archetype?)").arg(recipe->title);
121  }
122  else if (strcmp(recipe->title, "NONE") == 0)
123  {
124  if (base->clone.title)
125  title = QString("%1 %2").arg(base->clone.name, base->clone.title);
126  else
127  title = base->clone.name;
128  }
129  else
130  {
131  title = QString("%1 of %2").arg(base->clone.name, recipe->title);
132  }
133  }
134  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(title));
135  const Face *face = recipe_get_face(recipe);
136  if (!face && base != NULL)
137  {
138  face = base->clone.face;
139  }
140  if (face)
141  item->setIcon(0, CREPixmap::getIcon(face->number));
142 
143  return item;
144 }
145 
146 QTreeWidgetItem* CREUtils::faceNode(QTreeWidgetItem* parent)
147 {
148  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Faces")));
149  return item;
150 }
151 
152 QTreeWidgetItem* CREUtils::faceNode(const Face* face, QTreeWidgetItem* parent)
153 {
154  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(face->name));
155  item->setIcon(0, CREPixmap::getIcon(face->number));
156  return item;
157 }
158 
159 QTreeWidgetItem* CREUtils::mapNode(QTreeWidgetItem *parent)
160 {
161  return new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Maps")));
162 }
163 
164 QTreeWidgetItem* CREUtils::mapNode(const CREMapInformation* map, QTreeWidgetItem *parent)
165 {
166  return new QTreeWidgetItem(parent, QStringList(QObject::tr("%1 [%2]").arg(map->name(), map->path())));
167 }
168 
169 void CREUtils::addCountSuffix(QTreeWidgetItem *item, int column)
170 {
171  item->setText(column, QTreeWidget::tr("%1 (%2)").arg(item->text(column)).arg(item->childCount()));
172 }
recipestruct::arch_names
size_t arch_names
Definition: recipe.h:12
Face::name
sstring name
Definition: face.h:19
treasurestruct::item
struct archt * item
Definition: treasure.h:64
Face
Definition: face.h:14
treasurestruct::chance
uint8_t chance
Definition: treasure.h:70
global.h
treasurestruct::next_yes
struct treasurestruct * next_yes
Definition: treasure.h:67
obj::face
const Face * face
Definition: object.h:336
CREUtils::addCountSuffix
static void addCountSuffix(QTreeWidgetItem *item, int column=0)
Definition: CREUtils.cpp:169
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
CREMapInformation.h
CREUtils::faceNode
static QTreeWidgetItem * faceNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:146
CREUtils::archetypeNode
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:14
CREUtils.h
CREPixmap::getTreasureIcon
static QIcon getTreasureIcon()
Definition: CREPixmap.cpp:92
guildoracle.list
list
Definition: guildoracle.py:87
recipe.h
CREPixmap::getIcon
static QIcon getIcon(uint16_t faceNumber)
Definition: CREPixmap.cpp:55
recipestruct::title
sstring title
Definition: recipe.h:11
find_treasurelist
treasurelist * find_treasurelist(const char *name)
Definition: assets.cpp:261
CREUtils::mapNode
static QTreeWidgetItem * mapNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:159
treasurestruct::next_no
struct treasurestruct * next_no
Definition: treasure.h:68
treasurestruct
Definition: treasure.h:63
archt
Definition: object.h:470
CREMapInformation
Definition: CREMapInformation.h:16
recipestruct
Definition: recipe.h:10
disinfect.map
map
Definition: disinfect.py:4
titlestruct
Definition: readable.c:107
obj::name
sstring name
Definition: object.h:314
ScriptFile.h
CREPixmap::getTreasureYesIcon
static QIcon getTreasureYesIcon()
Definition: CREPixmap.cpp:104
query_name
void query_name(const object *op, char *buf, size_t size)
Definition: item.c:585
Face::number
uint16_t number
Definition: face.h:15
recipestruct::arch_name
char ** arch_name
Definition: recipe.h:13
recipe_get_face
const Face * recipe_get_face(const recipe *rp)
Definition: recipe.c:797
title
struct titlestruct title
CREUtils::formulaeNode
static QTreeWidgetItem * formulaeNode(const recipe *recipe, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:106
obj::title
sstring title
Definition: object.h:320
MessageFile.h
archt::clone
object clone
Definition: object.h:474
item
Definition: item.py:1
CREUtils::objectNode
static QTreeWidgetItem * objectNode(const object *op, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:27
give.op
op
Definition: give.py:33
find_archetype
archetype * find_archetype(const char *name)
Definition: assets.cpp:282
CREPixmap::getTreasureOneIcon
static QIcon getTreasureOneIcon()
Definition: CREPixmap.cpp:98
treasurestruct::nrof
uint16_t nrof
Definition: treasure.h:76
CREUtils::treasureNode
static QTreeWidgetItem * treasureNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:40
say.item
dictionary item
Definition: say.py:149
CREPixmap::getTreasureNoIcon
static QIcon getTreasureNoIcon()
Definition: CREPixmap.cpp:110
CREPixmap.h
treasurestruct::name
sstring name
Definition: treasure.h:65
libproto.h
treasureliststruct
Definition: treasure.h:82
give.name
name
Definition: give.py:27