Crossfire Server, Branches 1.12  R18729
CREUtils.cpp
Go to the documentation of this file.
1 #include <QtGui>
2 #include "CREUtils.h"
3 #include "CREPixmap.h"
4 
5 extern "C" {
6 #include "global.h"
7 #include "recipe.h"
8 #include "libproto.h"
9 }
10 
11 QTreeWidgetItem* CREUtils::archetypeNode(QTreeWidgetItem* parent)
12 {
13  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Archetypes")));
14  return item;
15 }
16 
17 QTreeWidgetItem* CREUtils::archetypeNode(const archt* arch, QTreeWidgetItem* parent)
18 {
19  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(arch->name));
20  //item->setData(0, Qt::UserRole, arch->getId());
21  item->setIcon(0, CREPixmap::getIcon(arch->clone.face->number));
22  return item;
23 }
24 
25 QTreeWidgetItem* CREUtils::artifactNode(QTreeWidgetItem* parent)
26 {
27  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Artifacts")));
28  return item;
29 }
30 
31 QTreeWidgetItem* CREUtils::artifactNode(const artifact* arti, QTreeWidgetItem* parent)
32 {
33  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(arti->item->name));
34  if (arti->item->face != NULL && arti->item->face != blank_face)
35  item->setIcon(0, CREPixmap::getIcon(arti->item->face->number));
36  else
37  {
38  int face = 0;
39  for (linked_char* allowed = arti->allowed; allowed; allowed = allowed->next)
40  {
41  if (allowed->name[0] == '!')
42  continue;
43  const archt* specific = find_archetype(allowed->name);
44  if (specific && specific->clone.face != NULL)
45  {
46  face = specific->clone.face->number;
47  break;
48  }
49  }
50 
51  if (face == 0)
52  {
53  const archt* generic = get_archetype_by_type_subtype(arti->item->type, -1);
54  if (generic != NULL && generic->clone.face != NULL)
55  face = generic->clone.face->number;
56  }
57 
58  if (face)
59  item->setIcon(0, CREPixmap::getIcon(face));
60  }
61  return item;
62 }
63 
64 QTreeWidgetItem* CREUtils::treasureNode(QTreeWidgetItem* parent)
65 {
66  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Treasures")));
67  return item;
68 }
69 
70 QTreeWidgetItem* CREUtils::treasureNode(const treasurelist* list, QTreeWidgetItem* parent)
71 {
72  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(list->name));
73  if (list->total_chance == 0)
74  item->setIcon(0, CREPixmap::getTreasureIcon());
75  else
76  item->setIcon(0, CREPixmap::getTreasureOneIcon());
77  return item;
78 }
79 
80 QTreeWidgetItem* CREUtils::treasureNode(const treasure* treasure, QTreeWidgetItem* parent)
81 {
82  QTreeWidgetItem* item;
83  if (treasure->item)
84  {
85  item = CREUtils::archetypeNode(treasure->item, parent);
86  }
87  else
88  {
89  treasurelist* other = find_treasurelist(treasure->name);
90  if (other == NULL)
91  item = new QTreeWidgetItem(parent, QStringList(QString(QTreeWidget::tr("Invalid list: %1")).arg(treasure->name)));
92  else
93  {
94  item = CREUtils::treasureNode(other, parent);
95  }
96  }
97 
98  return item;
99 }
100 
101 QTreeWidgetItem* CREUtils::formulaeNode(const recipe* recipe, QTreeWidgetItem* parent)
102 {
103  QString title;
104  const archt* base = NULL;
105 
106  if (recipe->arch_names == 0)
107  {
108  title = QString("%1 (no archetype?)").arg(recipe->title);
109  }
110  else
111  {
112  base = find_archetype(recipe->arch_name[0]);
113  if (strcmp(recipe->title, "NONE") == 0)
114  {
115  title = base->clone.name;
116  }
117  else
118  {
119  title = QString("%1 of %2").arg(base->clone.name, recipe->title);
120  }
121  }
122  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(title));
123  if (base != NULL && base->clone.face != 0)
124  item->setIcon(0, CREPixmap::getIcon(base->clone.face->number));
125 
126  return item;
127 }
128 
129 QTreeWidgetItem* CREUtils::faceNode(QTreeWidgetItem* parent)
130 {
131  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Faces")));
132  return item;
133 }
134 
135 QTreeWidgetItem* CREUtils::faceNode(const New_Face* face, QTreeWidgetItem* parent)
136 {
137  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(face->name));
138  item->setIcon(0, CREPixmap::getIcon(face->number));
139  return item;
140 }
141 
142 QTreeWidgetItem* CREUtils::animationNode(QTreeWidgetItem* parent)
143 {
144  return new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Animations")));
145 }
146 
147 QTreeWidgetItem* CREUtils::animationNode(const Animations* anim, QTreeWidgetItem* parent)
148 {
149  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(anim->name));
150  if (anim->num_animations > 0)
151  item->setIcon(0, CREPixmap::getIcon(anim->faces[0]));
152  else
153  LOG(llevDebug, "empty animation: %s\n", anim->name);
154  return item;
155 }
const char * title
Definition: recipe.h:11
archetype * find_archetype(const char *name)
Definition: arch.c:700
static QTreeWidgetItem * animationNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:142
static QIcon getTreasureIcon()
Definition: CREPixmap.cpp:45
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:11
static QTreeWidgetItem * artifactNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:25
sint16 total_chance
Definition: treasure.h:113
const char * name
Definition: face.h:55
treasurelist * find_treasurelist(const char *name)
Definition: treasure.c:295
object clone
Definition: object.h:326
Fontindex * faces
Definition: face.h:59
static QTreeWidgetItem * formulaeNode(const recipe *recipe, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:101
Definition: object.h:321
static QTreeWidgetItem * faceNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:129
struct archt * item
Definition: treasure.h:93
struct titlestruct title
uint16 number
Definition: face.h:43
const char * name
Definition: face.h:48
char ** arch_name
Definition: recipe.h:13
struct linked_char * next
Definition: global.h:161
const char * name
Definition: object.h:167
linked_char * allowed
Definition: artifact.h:42
uint8 num_animations
Definition: face.h:56
const char * name
Definition: treasure.h:112
static QIcon getIcon(int faceNumber)
Definition: CREPixmap.cpp:27
New_Face * blank_face
Definition: image.c:66
archetype * get_archetype_by_type_subtype(int type, int subtype)
Definition: arch.c:149
size_t arch_names
Definition: recipe.h:12
static QTreeWidgetItem * treasureNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:64
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:63
object * item
Definition: artifact.h:38
New_Face * face
Definition: object.h:183
const char * name
Definition: treasure.h:94
const char * name
Definition: object.h:322
uint8 type
Definition: object.h:189
static QIcon getTreasureOneIcon()
Definition: CREPixmap.cpp:51