Crossfire Server, Trunk
CREUtils.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include <QtWidgets>
14 #include "CREUtils.h"
15 #include "CREPixmap.h"
16 #include "CREMapInformation.h"
17 #include "MessageFile.h"
18 #include "scripts/ScriptFile.h"
19 
20 #include "global.h"
21 #include "recipe.h"
22 #include "libproto.h"
23 
24 static QMutex g_crossfireLock;
25 
26 QTreeWidgetItem* CREUtils::archetypeNode(const archetype* arch, QTreeWidgetItem* parent)
27 {
28  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(arch->name));
29  item->setIcon(0, CREPixmap::getIcon(arch->clone.face ? arch->clone.face->number : 0));
30  return item;
31 }
32 
33 QTreeWidgetItem* CREUtils::objectNode(const object* op, QTreeWidgetItem* parent)
34 {
35  char name[500];
36  query_name(op, name, sizeof(name));
37  QString n;
38  if (op->nrof > 1)
39  n.append(QString::number(op->nrof)).append(" ");
40  n.append(name);
41  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(n));
42  item->setIcon(0, CREPixmap::getIcon(op->face->number));
43  return item;
44 }
45 
46 QTreeWidgetItem* CREUtils::faceNode(QTreeWidgetItem* parent)
47 {
48  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(QTreeWidget::tr("Faces")));
49  return item;
50 }
51 
52 QTreeWidgetItem* CREUtils::faceNode(const Face* face, QTreeWidgetItem* parent)
53 {
54  QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(face->name));
55  item->setIcon(0, CREPixmap::getIcon(face->number));
56  return item;
57 }
58 
59 std::unique_ptr<QMutexLocker> CREUtils::lockCrossfireData()
60 {
61  return std::make_unique<QMutexLocker>(&g_crossfireLock);
62 }
Face::name
sstring name
Definition: face.h:19
Face
Definition: face.h:14
global.h
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
CREMapInformation.h
CREUtils::faceNode
static QTreeWidgetItem * faceNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:46
CREUtils.h
recipe.h
CREPixmap::getIcon
static QIcon getIcon(uint16_t faceNumber)
Definition: CREPixmap.cpp:65
CREUtils::archetypeNode
static QTreeWidgetItem * archetypeNode(const archetype *arch, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:26
ScriptFile.h
query_name
void query_name(const object *op, char *buf, size_t size)
Definition: item.cpp:588
Face::number
uint16_t number
Definition: face.h:15
CREUtils::lockCrossfireData
static std::unique_ptr< QMutexLocker > lockCrossfireData()
Definition: CREUtils.cpp:59
archetype
Definition: object.h:483
MessageFile.h
item
Definition: item.py:1
CREUtils::objectNode
static QTreeWidgetItem * objectNode(const object *op, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:33
give.op
op
Definition: give.py:33
say.item
dictionary item
Definition: say.py:149
CREPixmap.h
g_crossfireLock
static QMutex g_crossfireLock
Definition: CREUtils.cpp:24
libproto.h
give.name
name
Definition: give.py:27