Crossfire Server, Trunk
CREArtifactPanel.cpp
Go to the documentation of this file.
1 #include <QtWidgets>
2 
3 extern "C" {
4 #include "global.h"
5 #include "artifact.h"
6 }
7 
8 #include "CREArtifactPanel.h"
9 #include "CREUtils.h"
10 #include "CREAnimationWidget.h"
11 
12 #include "assets.h"
13 #include "AssetsManager.h"
14 #include "Archetypes.h"
15 
17 {
18  myArtifact = NULL;
19 
20  QGridLayout* layout = new QGridLayout(this);
21 
22  QLabel* label = new QLabel(this);
23  label->setText("Name:");
24  layout->addWidget(label, 1, 1);
25  myName = new QLineEdit(this);
26  layout->addWidget(myName, 1, 2);
27  myName->setReadOnly(true);
28 
29  label = new QLabel(this);
30  label->setText("Chance:");
31  layout->addWidget(label, 2, 1);
32  myChance = new QLineEdit(this);
33  layout->addWidget(myChance, 2, 2);
34  myChance->setReadOnly(true);
35 
36  label = new QLabel(this);
37  label->setText("Type:");
38  layout->addWidget(label, 3, 1);
39  myType = new QLineEdit(this);
40  layout->addWidget(myType, 3, 2);
41  myType->setReadOnly(true);
42 
43  myViaAlchemy = new QLabel(this);
44  myViaAlchemy->setWordWrap(true);
45  layout->addWidget(myViaAlchemy, 4, 1, 1, 2);
46 
47  layout->addWidget(new QLabel(tr("Values:"), this), 5, 1, 1, 2);
48  myValues = new QTextEdit(this);
49  layout->addWidget(myValues, 6, 1, 1, 2);
50  myValues->setReadOnly(true);
51 
52  myArchetypes = new QTreeWidget(this);
53  layout->addWidget(myArchetypes, 7, 1, 3, 1);
54  myArchetypes->setHeaderLabel("Allowed/forbidden archetypes");
55  myArchetypes->setIconSize(QSize(32, 32));
56  myArchetypes->setRootIsDecorated(false);
57  connect(myArchetypes, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(artifactChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
58 
59  layout->addWidget(new QLabel(tr("Result:"), this), 7, 2);
60  myInstance = new QTextEdit(this);
61  layout->addWidget(myInstance, 8, 2);
62  myInstance->setReadOnly(true);
63 
64  layout->addWidget(myAnimation = new CREAnimationControl(this), 9, 2);
65  layout->addWidget(myFace = new CREAnimationWidget(this), 9, 2);
66 }
67 
69 {
70  Q_ASSERT(artifact != NULL);
71 
72  const recipelist* list;
73  const recipe* recipe;
74  const archetype* arch;
75  QStringList possible;
76 
77  for (int ing = 1; ; ing++)
78  {
79  list = get_formulalist(ing);
80  if (!list)
81  break;
82  for (recipe = list->items; recipe; recipe = recipe->next)
83  {
84  if (recipe->title == NULL)
85  continue;
86 
87  if (strcmp(recipe->title, artifact->item->name) != 0)
88  continue;
89 
90  for (size_t a = 0; a < recipe->arch_names; a++)
91  {
93  if (!arch)
94  continue;
95  if ((arch->clone.type == artifact->item->type) && legal_artifact_combination(&arch->clone, artifact))
96  {
97  if (!possible.contains(arch->name))
98  possible.append(arch->name);
99  }
100  }
101  }
102  }
103 
104  if (possible.isEmpty())
105  myViaAlchemy->setText(tr("Can't be made via alchemy."));
106  else
107  {
108  if (possible.size() == artifact->allowed_size)
109  myViaAlchemy->setText(tr("Can be made via alchemy."));
110  else
111  {
112  possible.sort();
113  myViaAlchemy->setText(tr("The following archetypes can be used via alchemy: %1").arg(possible.join(tr(", "))));
114  }
115  }
116 }
117 
125 static void addArchetypes(const artifact* artifact, const char* name, bool check, QTreeWidget* root)
126 {
127  QTreeWidgetItem* item = NULL;
128  item = NULL;
129 
131  {
132  if (arch->head || arch->clone.type != artifact->item->type)
133  {
134  return;
135  }
136 
137  if (name == NULL || (check && arch->clone.name && (!strcmp(name, arch->clone.name) || (!strcmp(name, arch->name)))) || (!check && (arch->clone.name && strcmp(name, arch->clone.name)) && strcmp(name, arch->name)))
138  {
139  if (item == NULL)
140  {
141  item = new QTreeWidgetItem(root, QStringList(name == NULL ? "(all)" : name));
142  item->setCheckState(0, check ? Qt::Checked : Qt::Unchecked);
143  root->addTopLevelItem(item);
144  item->setExpanded(true);
145  }
146  CREUtils::archetypeNode(arch, item)->setData(0, Qt::UserRole, arch->name);
147  }
148  });
149 }
150 
152 {
153  Q_ASSERT(artifact);
155 
156  myName->setText(artifact->item->name);
157  myChance->setText(QString::number(artifact->chance));
158  myType->setText(QString::number(artifact->item->type));
159 
161 
162  const char* name;
163  bool check;
164 
165  myArchetypes->clear();
166  myInstance->clear();
167 
168  /* 'allowed' is either the archetype name or the item's name, so check all archetypes for each word */
169  for (const linked_char* allowed = artifact->allowed; allowed; allowed = allowed->next)
170  {
171  name = allowed->name;
172  if (name[0] == '!')
173  {
174  name = name + 1;
175  check = false;
176  }
177  else
178  check = true;
179 
181  }
182 
183  /* all items are allowed, so add them */
184  if (artifact->allowed == NULL)
185  {
186  addArchetypes(myArtifact, NULL, true, myArchetypes);
187  }
188 
191  char* final = stringbuffer_finish(dump);
192  myValues->setText(final);
193  free(final);
194 }
195 
196 void CREArtifactPanel::artifactChanged(QTreeWidgetItem* current, QTreeWidgetItem*)
197 {
198  myAnimation->setVisible(false);
199  myFace->setVisible(false);
200  myInstance->clear();
201  if (!current || current->data(0, Qt::UserRole).toString().isEmpty())
202  {
203  return;
204  }
205  archt* arch = try_find_archetype(current->data(0, Qt::UserRole).toString().toUtf8().constData());
206  if (!arch)
207  {
208  return;
209  }
210 
211  char* desc;
212  object* obj = arch_to_object(arch);
216  desc = stringbuffer_finish(describe_item(obj, NULL, 0, NULL));
217  myInstance->setText(desc);
218  free(desc);
219 
220  if (obj->animation != nullptr)
221  {
222  myAnimation->setVisible(true);
224  }
225  else
226  {
227  myFace->setVisible(true);
228  QList<int> faces;
229  faces.append(obj->face->number);
231  myFace->step();
232  }
233 
235 }
recipestruct::arch_names
size_t arch_names
Definition: recipe.h:12
empty_archetype
EXTERN archetype * empty_archetype
Definition: global.h:142
artifact
struct artifactstruct artifact
CRETPanel
Definition: CREPanel.h:20
global.h
FREE_OBJ_NO_DESTROY_CALLBACK
#define FREE_OBJ_NO_DESTROY_CALLBACK
Definition: object.h:532
get_formulalist
recipelist * get_formulalist(int i)
Definition: recipe.c:96
object_free
void object_free(object *ob, int flags)
Definition: object.c:1565
stringbuffer_new
StringBuffer * stringbuffer_new(void)
Definition: stringbuffer.c:57
obj::face
const Face * face
Definition: object.h:334
layout
Definition: main.c:85
CREArtifactPanel::myChance
QLineEdit * myChance
Definition: CREArtifactPanel.h:25
give_artifact_abilities
void give_artifact_abilities(object *op, const object *artifact)
Definition: artifact.c:194
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
CREArtifactPanel::myValues
QTextEdit * myValues
Definition: CREArtifactPanel.h:29
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
AssetsManager.h
CREArtifactPanel::myInstance
QTextEdit * myInstance
Definition: CREArtifactPanel.h:30
FLAG_IS_TURNABLE
#define FLAG_IS_TURNABLE
Definition: define.h:256
disinfect.a
a
Definition: disinfect.py:13
CREAnimationControl::setAnimation
void setAnimation(const Animations *animation, int facings=-1)
Definition: CREAnimationControl.cpp:29
CREArtifactPanel.h
CREUtils::archetypeNode
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:14
CREArtifactPanel::myName
QLineEdit * myName
Definition: CREArtifactPanel.h:24
CREUtils.h
get_ob_diff
void get_ob_diff(StringBuffer *sb, const object *op, const object *op2)
Definition: object.c:4952
guildoracle.list
list
Definition: guildoracle.py:87
root
static char root[500]
Definition: mapper.cpp:305
recipestruct::title
sstring title
Definition: recipe.h:11
CREArtifactPanel::artifactChanged
void artifactChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
Definition: CREArtifactPanel.cpp:196
CREAnimationWidget::step
void step()
Definition: CREAnimationWidget.cpp:19
artifact.h
CREArtifactPanel::myArtifact
const artifact * myArtifact
Definition: CREArtifactPanel.h:23
CREAnimationWidget::setAnimation
void setAnimation(QList< int > faces)
Definition: CREAnimationWidget.cpp:13
describe_item
StringBuffer * describe_item(const object *op, const object *owner, int use_media_tags, StringBuffer *buf)
Definition: item.c:940
getManager
AssetsManager * getManager()
Definition: assets.cpp:329
linked_char
Definition: global.h:86
reputation_trigger_connect.check
def check()
Definition: reputation_trigger_connect.py:18
archt
Definition: object.h:468
obj
Definition: object.h:275
CREArtifactPanel::myAnimation
CREAnimationControl * myAnimation
Definition: CREArtifactPanel.h:31
recipestruct
Definition: recipe.h:10
artifactstruct::chance
uint16_t chance
Definition: artifact.h:16
obj::name
sstring name
Definition: object.h:312
CREArtifactPanel::myType
QLineEdit * myType
Definition: CREArtifactPanel.h:26
CREArtifactPanel::myViaAlchemy
QLabel * myViaAlchemy
Definition: CREArtifactPanel.h:27
Face::number
uint16_t number
Definition: face.h:15
CREAnimationControl
Definition: CREAnimationControl.h:14
recipestruct::arch_name
char ** arch_name
Definition: recipe.h:13
addArchetypes
static void addArchetypes(const artifact *artifact, const char *name, bool check, QTreeWidget *root)
Definition: CREArtifactPanel.cpp:125
dump
Definition: quest.c:859
CREArtifactPanel::computeMadeViaAlchemy
void computeMadeViaAlchemy(const artifact *artifact) const
Definition: CREArtifactPanel.cpp:68
artifactstruct::allowed_size
int allowed_size
Definition: artifact.h:20
stringbuffer_finish
char * stringbuffer_finish(StringBuffer *sb)
Definition: stringbuffer.c:76
linked_char::next
struct linked_char * next
Definition: global.h:88
CREArtifactPanel::myFace
CREAnimationWidget * myFace
Definition: CREArtifactPanel.h:32
object_give_identified_properties
void object_give_identified_properties(object *op)
Definition: item.c:1343
CREArtifactPanel::myArchetypes
QTreeWidget * myArchetypes
Definition: CREArtifactPanel.h:28
recipeliststruct
Definition: recipe.h:37
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:135
obj::animation
const Animations * animation
Definition: object.h:420
AssetsManager::archetypes
Archetypes * archetypes()
Definition: AssetsManager.h:44
artifactstruct
Definition: artifact.h:14
StringBuffer
Definition: stringbuffer.c:25
obj::type
uint8_t type
Definition: object.h:341
CREArtifactPanel::setItem
virtual void setItem(const artifact *artifact) override
Definition: CREArtifactPanel.cpp:151
archt::clone
object clone
Definition: object.h:472
item
Definition: item.py:1
find_archetype
archetype * find_archetype(const char *name)
Definition: assets.cpp:278
assets.h
Archetypes.h
CREAnimationWidget
Definition: CREAnimationWidget.h:7
recipestruct::next
struct recipestruct * next
Definition: recipe.h:24
dragon_attune.faces
dictionary faces
Definition: dragon_attune.py:31
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:232
CREArtifactPanel::CREArtifactPanel
CREArtifactPanel(QWidget *parent)
Definition: CREArtifactPanel.cpp:16
artifactstruct::item
object * item
Definition: artifact.h:15
try_find_archetype
archetype * try_find_archetype(const char *name)
Definition: assets.cpp:282
FREE_OBJ_FREE_INVENTORY
#define FREE_OBJ_FREE_INVENTORY
Definition: object.h:531
CREAnimationWidget.h
connect
Definition: connect.py:1
replace.current
current
Definition: replace.py:64
legal_artifact_combination
int legal_artifact_combination(const object *op, const artifact *art)
Definition: artifact.c:216
if
if(!(yy_init))
Definition: loader.c:2589
artifactstruct::allowed
linked_char * allowed
Definition: artifact.h:19
FLAG_IDENTIFIED
#define FLAG_IDENTIFIED
Definition: define.h:261
give.name
name
Definition: give.py:27
recipe
struct recipestruct recipe