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 
7 extern "C" {
8 #include "global.h"
9 #include "recipe.h"
10 #include "libproto.h"
11 #include "ScriptFile.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::artifactNode(QTreeWidgetItem* parent)
41 {
42  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Artifacts")));
43  return item;
44 }
45 
46 QTreeWidgetItem* CREUtils::artifactNode(const artifact* arti, QTreeWidgetItem* parent)
47 {
48  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(arti->item->name));
49  if (arti->item->face != NULL && arti->item->face != blank_face)
50  item->setIcon(0, CREPixmap::getIcon(arti->item->face->number));
51  else
52  {
53  int face = 0;
54  for (linked_char* allowed = arti->allowed; allowed; allowed = allowed->next)
55  {
56  if (allowed->name[0] == '!')
57  continue;
58  const archt* specific = try_find_archetype(allowed->name);
59  if (!specific)
60  specific = find_archetype_by_object_name(allowed->name);
61  if (specific && specific->clone.face != NULL)
62  {
63  face = specific->clone.face->number;
64  break;
65  }
66  }
67 
68  if (face == 0)
69  {
70  const archt* generic = get_archetype_by_type_subtype(arti->item->type, -1);
71  if (generic != NULL && generic->clone.face != NULL)
72  face = generic->clone.face->number;
73  }
74 
75  if (face)
76  item->setIcon(0, CREPixmap::getIcon(face));
77  }
78  return item;
79 }
80 
81 QTreeWidgetItem* CREUtils::treasureNode(QTreeWidgetItem* parent)
82 {
83  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Treasures")));
84  return item;
85 }
86 
87 QTreeWidgetItem* CREUtils::treasureNode(const treasurelist* list, QTreeWidgetItem* parent)
88 {
89  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(list->name));
90  if (list->total_chance == 0)
91  item->setIcon(0, CREPixmap::getTreasureIcon());
92  else
93  item->setIcon(0, CREPixmap::getTreasureOneIcon());
94  return item;
95 }
96 
97 QTreeWidgetItem* CREUtils::treasureNode(const treasure* treasure, const treasurelist* list, QTreeWidgetItem* parent)
98 {
99  QTreeWidgetItem* item;
100  if (treasure->item)
101  {
103  if (treasure->next_yes)
104  {
105  QTreeWidgetItem* node = new QTreeWidgetItem(item, QStringList(QTreeWidget::tr("Yes")));
106  node->setIcon(0, CREPixmap::getTreasureYesIcon());
108  }
109  if (treasure->next_no)
110  {
111  QTreeWidgetItem* node = new QTreeWidgetItem(item, QStringList(QTreeWidget::tr("No")));
112  node->setIcon(0, CREPixmap::getTreasureNoIcon());
114  }
115  }
116  else
117  {
118  if (treasure->name && strcmp(treasure->name, "NONE") == 0)
119  item = new QTreeWidgetItem(parent, QStringList(QString(QTreeWidget::tr("Nothing"))));
120  else
121  {
123  item = CREUtils::treasureNode(other, parent);
124  }
125  }
126 
127  if (list->total_chance != 0)
128  {
129  item->setText(0, QTreeWidget::tr("%1 (%2%3%, %4 chances on %5)")
130  .arg(item->text(0))
131  .arg(treasure->nrof > 0 ? QTreeWidget::tr("1 to %2, ").arg(treasure->nrof) : "")
132  .arg(qRound((float)100 * treasure->chance / list->total_chance))
133  .arg(treasure->chance)
134  .arg(list->total_chance));
135  }
136  else
137  {
138  item->setText(0, QTreeWidget::tr("%1 (%2%3%)")
139  .arg(item->text(0))
140  .arg(treasure->nrof > 0 ? QTreeWidget::tr("1 to %2, ").arg(treasure->nrof) : "")
141  .arg(treasure->chance));
142  }
143 
144  return item;
145 }
146 
147 QTreeWidgetItem* CREUtils::formulaeNode(const recipe* recipe, QTreeWidgetItem* parent)
148 {
149  QString title;
150  const archt* base = NULL;
151 
152  if (recipe->arch_names == 0)
153  {
154  title = QString("%1 (no archetype?)").arg(recipe->title);
155  }
156  else
157  {
158  base = find_archetype(recipe->arch_name[0]);
159  if (!base)
160  {
161  title = QString("%1 (no archetype?)").arg(recipe->title);
162  }
163  else if (strcmp(recipe->title, "NONE") == 0)
164  {
165  if (base->clone.title)
166  title = QString("%1 %2").arg(base->clone.name, base->clone.title);
167  else
168  title = base->clone.name;
169  }
170  else
171  {
172  title = QString("%1 of %2").arg(base->clone.name, recipe->title);
173  }
174  }
175  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(title));
176  const Face *face = recipe_get_face(recipe);
177  if (!face && base != NULL)
178  {
179  face = base->clone.face;
180  }
181  if (face)
182  item->setIcon(0, CREPixmap::getIcon(face->number));
183 
184  return item;
185 }
186 
187 QTreeWidgetItem* CREUtils::faceNode(QTreeWidgetItem* parent)
188 {
189  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Faces")));
190  return item;
191 }
192 
193 QTreeWidgetItem* CREUtils::faceNode(const Face* face, QTreeWidgetItem* parent)
194 {
195  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(face->name));
196  item->setIcon(0, CREPixmap::getIcon(face->number));
197  return item;
198 }
199 
200 QTreeWidgetItem* CREUtils::animationNode(QTreeWidgetItem* parent)
201 {
202  return new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Animations")));
203 }
204 
205 QTreeWidgetItem* CREUtils::animationNode(const Animations* anim, QTreeWidgetItem* parent)
206 {
207  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(anim->name));
208  if (anim->num_animations > 0)
209  item->setIcon(0, CREPixmap::getIcon((anim->faces[0] != NULL) ? anim->faces[0]->number : 0));
210  else
211  LOG(llevDebug, "empty animation: %s\n", anim->name);
212  return item;
213 }
214 
215 QTreeWidgetItem* CREUtils::regionNode(const QString& name, int count, QTreeWidgetItem *parent)
216 {
217  return new QTreeWidgetItem(parent, QStringList(QObject::tr("%1 - %2 maps").arg(name).arg(count)));
218 }
219 
220 QTreeWidgetItem* CREUtils::mapNode(QTreeWidgetItem *parent)
221 {
222  return new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Maps")));
223 }
224 
225 QTreeWidgetItem* CREUtils::mapNode(const CREMapInformation* map, QTreeWidgetItem *parent)
226 {
227  return new QTreeWidgetItem(parent, QStringList(QObject::tr("%1 [%2]").arg(map->name(), map->path())));
228 }
229 
230 QTreeWidgetItem* CREUtils::questsNode()
231 {
232  return new QTreeWidgetItem(QStringList(QTreeWidget::tr("Quests")));
233 }
234 
235 QTreeWidgetItem* CREUtils::questNode(const quest_definition* quest, QTreeWidgetItem* parent)
236 {
237  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(quest->quest_code));
238  if (quest->face != nullptr)
239  item->setIcon(0, CREPixmap::getIcon(quest->face->number));
240  return item;
241 }
242 
243 QTreeWidgetItem* CREUtils::messagesNode()
244 {
245  return new QTreeWidgetItem(QStringList(QTreeWidget::tr("NPC dialogs")));
246 }
247 
248 QTreeWidgetItem* CREUtils::messageNode(const MessageFile* message, QTreeWidgetItem* parent)
249 {
250  return new QTreeWidgetItem(parent, QStringList(message->path()));
251 }
252 
253 QTreeWidgetItem* CREUtils::scriptsNode()
254 {
255  return new QTreeWidgetItem(QStringList(QTreeWidget::tr("Scripts")));
256 }
257 QTreeWidgetItem* CREUtils::scriptNode(const ScriptFile* script, QTreeWidgetItem* parent)
258 {
259  return new QTreeWidgetItem(parent, QStringList(script->path()));
260 }
261 
263 {
264  return new QTreeWidgetItem(QStringList(QTreeWidget::tr("Messages")));
265 }
266 QTreeWidgetItem* CREUtils::generalMessageNode(const GeneralMessage* message, QTreeWidgetItem* parent)
267 {
268  QString title;
269  if (message->identifier && message->identifier[0] == '\n')
270  title = "General message";
271  else
272  title = message->title;
273 
274  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(title));
275  if (message->face != nullptr)
276  item->setIcon(0, CREPixmap::getIcon(message->face->number));
277  return item;
278 }
279 
280 QTreeWidgetItem* CREUtils::facesetsNode()
281 {
282  return new QTreeWidgetItem(QStringList(QTreeWidget::tr("Facesets")));
283 }
284 QTreeWidgetItem* CREUtils::facesetsNode(const face_sets* faceset, QTreeWidgetItem* parent)
285 {
286  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(faceset->fullname));
287  return item;
288 }
289 
290 void CREUtils::addCountSuffix(QTreeWidgetItem *item, int column)
291 {
292  item->setText(column, QTreeWidget::tr("%1 (%2)").arg(item->text(column)).arg(item->childCount()));
293 }
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
GeneralMessage
Definition: book.h:44
obj::face
const Face * face
Definition: object.h:334
CREUtils::addCountSuffix
static void addCountSuffix(QTreeWidgetItem *item, int column=0)
Definition: CREUtils.cpp:290
CREUtils::generalMessageNode
static QTreeWidgetItem * generalMessageNode()
Definition: CREUtils.cpp:262
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
CREMapInformation.h
CREUtils::facesetsNode
static QTreeWidgetItem * facesetsNode()
Definition: CREUtils.cpp:280
CREUtils::faceNode
static QTreeWidgetItem * faceNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:187
CREUtils::archetypeNode
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:14
CREUtils.h
CREPixmap::getTreasureIcon
static QIcon getTreasureIcon()
Definition: CREPixmap.cpp:82
guildoracle.list
list
Definition: guildoracle.py:87
recipe.h
CREUtils::scriptsNode
static QTreeWidgetItem * scriptsNode()
Definition: CREUtils.cpp:253
CREUtils::artifactNode
static QTreeWidgetItem * artifactNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:40
CREPixmap::getIcon
static QIcon getIcon(uint16_t faceNumber)
Definition: CREPixmap.cpp:55
blank_face
const Face * blank_face
Definition: image.c:35
recipestruct::title
sstring title
Definition: recipe.h:11
find_treasurelist
treasurelist * find_treasurelist(const char *name)
Definition: assets.cpp:257
CREUtils::mapNode
static QTreeWidgetItem * mapNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:220
CREUtils::questsNode
static QTreeWidgetItem * questsNode()
Definition: CREUtils.cpp:230
MessageFile
Definition: MessageFile.h:55
treasurestruct::next_no
struct treasurestruct * next_no
Definition: treasure.h:68
treasurestruct
Definition: treasure.h:63
linked_char
Definition: global.h:86
archt
Definition: object.h:468
CREUtils::scriptNode
static QTreeWidgetItem * scriptNode(const ScriptFile *script, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:257
quest
Definition: quest.py:1
CREMapInformation
Definition: CREMapInformation.h:13
recipestruct
Definition: recipe.h:10
disinfect.map
map
Definition: disinfect.py:4
titlestruct
Definition: readable.c:107
CREUtils::questNode
static QTreeWidgetItem * questNode(const quest_definition *quest, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:235
obj::name
sstring name
Definition: object.h:312
ScriptFile::path
const QString & path() const
Definition: ScriptFile.cpp:36
ScriptFile.h
CREPixmap::getTreasureYesIcon
static QIcon getTreasureYesIcon()
Definition: CREPixmap.cpp:94
query_name
void query_name(const object *op, char *buf, size_t size)
Definition: item.c:584
Face::number
uint16_t number
Definition: face.h:15
recipestruct::arch_name
char ** arch_name
Definition: recipe.h:13
linked_char::next
struct linked_char * next
Definition: global.h:88
disinfect.count
int count
Definition: disinfect.py:7
animate.anim
string anim
Definition: animate.py:20
recipe_get_face
const Face * recipe_get_face(const recipe *rp)
Definition: recipe.c:788
CREUtils::messageNode
static QTreeWidgetItem * messageNode(const MessageFile *message, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:248
artifactstruct
Definition: artifact.h:14
title
struct titlestruct title
ScriptFile
Definition: ScriptFile.h:31
CREUtils::formulaeNode
static QTreeWidgetItem * formulaeNode(const recipe *recipe, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:147
obj::title
sstring title
Definition: object.h:318
diamondslots.message
string message
Definition: diamondslots.py:57
animations_struct
Definition: face.h:25
MessageFile.h
obj::type
uint8_t type
Definition: object.h:341
find_archetype_by_object_name
archetype * find_archetype_by_object_name(const char *name)
Definition: arch.cpp:55
archt::clone
object clone
Definition: object.h:472
item
Definition: item.py:1
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
CREUtils::objectNode
static QTreeWidgetItem * objectNode(const object *op, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:27
give.op
op
Definition: give.py:33
quest_definition
Definition: quest.h:42
find_archetype
archetype * find_archetype(const char *name)
Definition: assets.cpp:278
CREPixmap::getTreasureOneIcon
static QIcon getTreasureOneIcon()
Definition: CREPixmap.cpp:88
treasurestruct::nrof
uint16_t nrof
Definition: treasure.h:76
artifactstruct::item
object * item
Definition: artifact.h:15
CREUtils::treasureNode
static QTreeWidgetItem * treasureNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:81
treasurestruct::name
const char * name
Definition: treasure.h:65
get_archetype_by_type_subtype
archetype * get_archetype_by_type_subtype(int type, int subtype)
Definition: arch.cpp:101
CREUtils::animationNode
static QTreeWidgetItem * animationNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:200
try_find_archetype
archetype * try_find_archetype(const char *name)
Definition: assets.cpp:282
face_sets::fullname
char * fullname
Definition: image.h:20
say.item
dictionary item
Definition: say.py:149
face_sets
Definition: image.h:17
CREPixmap::getTreasureNoIcon
static QIcon getTreasureNoIcon()
Definition: CREPixmap.cpp:100
CREUtils::regionNode
static QTreeWidgetItem * regionNode(const QString &name, int count, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:215
CREPixmap.h
CREUtils::messagesNode
static QTreeWidgetItem * messagesNode()
Definition: CREUtils.cpp:243
libproto.h
llevDebug
@ llevDebug
Definition: logger.h:13
artifactstruct::allowed
linked_char * allowed
Definition: artifact.h:19
treasureliststruct
Definition: treasure.h:82
give.name
name
Definition: give.py:27