Crossfire Server, Trunk  R20513
CREFormulaePanel.cpp
Go to the documentation of this file.
1 #include <Qt>
2 #include <QtGui>
3 
4 extern "C" {
5 #include "global.h"
6 #include "recipe.h"
7 }
8 
9 #include "CREFormulaePanel.h"
10 #include "CREUtils.h"
11 
13 {
14  myRecipe = NULL;
15 
16  QGridLayout* layout = new QGridLayout(this);
17 
18  layout->addWidget(new QLabel(tr("Title:"), this), 1, 1);
19  myTitle = new QComboBox(this);
20 
21  layout->addWidget(myTitle, 1, 2);
22 
23  layout->addWidget(new QLabel(tr("Skill:"), this), 2, 1);
24  mySkill = new QComboBox(this);
25  layout->addWidget(mySkill, 2, 2);
26 
27  layout->addWidget(new QLabel(tr("Cauldron:"), this), 3, 1);
28  myCauldron = new QComboBox(this);
29  layout->addWidget(myCauldron, 3, 2);
30 
31  layout->addWidget(new QLabel(tr("Yield:"), this), 4, 1);
32  myYield = new QLineEdit(this);
33  layout->addWidget(myYield, 4, 2);
34 
35  layout->addWidget(new QLabel(tr("Chance:"), this), 5, 1);
36  myChance = new QLineEdit(this);
37  layout->addWidget(myChance, 5, 2);
38 
39  layout->addWidget(new QLabel(tr("Experience:"), this), 6, 1);
40  myExperience = new QLineEdit(this);
41  layout->addWidget(myExperience, 6, 2);
42 
43  layout->addWidget(new QLabel(tr("Difficulty:"), this), 7, 1);
44  myDifficulty = new QLineEdit(this);
45  layout->addWidget(myDifficulty, 7, 2);
46 
47  mySkill->addItem(tr("(none)"), 0);
48  myCauldron->addItem(tr("(none)"), 0);
49  const archt* arch = first_archetype;
50  for (; arch; arch = arch->next)
51  {
52  if (arch->clone.type == SKILL)
53  mySkill->addItem(arch->clone.name);
54  if (QUERY_FLAG(&arch->clone, FLAG_IS_CAULDRON))
55  myCauldron->addItem(arch->name);
56  }
57 
58  layout->addWidget(new QLabel(tr("Index:"), this), 8, 1);
59  myIndex = new QLabel(this);
60  layout->addWidget(myIndex, 8, 2);
61 
62  myArchetypes = new QTreeWidget(this);
63  myArchetypes->setHeaderLabel(tr("Archetypes:"));
64  myArchetypes->setRootIsDecorated(false);
65  myArchetypes->setIconSize(QSize(32, 32));
66  layout->addWidget(myArchetypes, 9, 1, 1, 2);
67 
68  layout->addWidget(new QLabel(tr("Ingredients:"), this), 10, 1, 1, 2);
69  myIngredients = new QTextEdit(this);
70  layout->addWidget(myIngredients, 11, 1, 1, 2);
71 
72  QHBoxLayout* buttons = new QHBoxLayout;
73  myValidate = new QPushButton(tr("&Validate"));
74  buttons->addWidget(myValidate);
75  myReset = new QPushButton(tr("&Reset"));
76  buttons->addWidget(myReset);
77  layout->addLayout(buttons, 12, 1, 1, 2);
78 
79  connect(myReset, SIGNAL(clicked(bool)), this, SLOT(resetClicked(bool)));
80  connect(myValidate, SIGNAL(clicked(bool)), this, SLOT(validateClicked(bool)));
81 }
82 
84 {
85  Q_ASSERT(recipe);
86  myRecipe = recipe;
87 
88  myTitle->clear();
89  myTitle->addItem("NONE");
90  if (recipe->arch_names > 0)
91  {
92  archetype* arch = find_archetype(recipe->arch_name[0]);
93  const artifactlist* at = find_artifactlist(arch->clone.type);
94  if (at != NULL)
95  {
96  artifact* art = at->items;
97  while (art)
98  {
99  if (art->item != NULL && art->item->name != NULL)
100  myTitle->addItem(art->item->name);
101  art = art->next;
102  }
103  }
104  }
105 
106  int index = myTitle->findText(recipe->title);
107  if (index == -1)
108  index = 0;
109  myTitle->setCurrentIndex(index);
110  myYield->setText(QString::number(recipe->yield));
111  myChance->setText(QString::number(recipe->chance));
112  myExperience->setText(QString::number(recipe->exp));
113  myDifficulty->setText(QString::number(recipe->diff));
114  myIndex->setText(QString::number(recipe->index));
115 
116  index = mySkill->findText(recipe->skill);
117  if (index == -1)
118  index = 0;
119  mySkill->setCurrentIndex(index);
120 
121  index = myCauldron->findText(recipe->cauldron);
122  if (index == -1)
123  index = 0;
124  myCauldron->setCurrentIndex(index);
125 
126  myArchetypes->clear();
127 
128  const archt* arch;
129  for (size_t a = 0; a < recipe->arch_names; a++)
130  {
131  arch = find_archetype(recipe->arch_name[a]);
132  myArchetypes->addTopLevelItem(CREUtils::archetypeNode(arch, NULL));
133  }
134 
135  QStringList list;
136  for (const linked_char* ing = myRecipe->ingred; ing; ing = ing->next)
137  {
138  list.append(ing->name);
139  }
140  myIngredients->setPlainText(list.join("\n"));
141 }
142 
144 {
145  setItem(myRecipe);
146 }
147 
149 {
150 #if 0
151  Q_ASSERT(myRecipe);
152 
153  myRecipe->setTitle(myTitle->text());
154  myRecipe->setYield(myYield->text().toInt());
155  myRecipe->setChance(myChance->text().toInt());
156  myRecipe->setExperience(myExperience->text().toInt());
157  myRecipe->setDifficulty(myDifficulty->text().toInt());
158  if (mySkill->currentIndex() != 0)
159  myRecipe->setSkill(mySkill->currentText());
160  else
161  myRecipe->setSkill("");
162  if (myCauldron->currentIndex() != 0)
163  myRecipe->setCauldron(myCauldron->currentText());
164  else
165  myRecipe->setCauldron("");
166 
167  QStringList arches;
168  const Archetype* arch;
169  ManagedReference ref;
170  for (int a = 0; a < myArchetypes->topLevelItemCount(); a++)
171  {
172  ref = myArchetypes->topLevelItem(a)->data(0, Qt::UserRole).toInt();
173  arch = DM_ARCHS->get(ref);
174  arches.append(arch->name);
175  DM_ARCHS->release(ref);
176  }
177  myRecipe->setArches(arches);
178 
179  myRecipe->setIngredients(myIngredients->toPlainText().split('\n'));
180 #endif
181 }
archetype * find_archetype(const char *name)
Finds, using the hashtable, which archetype matches the given name.
Definition: arch.c:695
int diff
Alchemical dfficulty level.
Definition: recipe.h:16
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:15
const artifactlist * find_artifactlist(int type)
Searches the artifact lists and returns one that has the same type of objects on it.
Definition: artifact.c:630
int yield
Maximum number of items produced by the recipe.
Definition: recipe.h:21
struct artifactstruct * items
Artifacts for this type.
Definition: artifact.h:30
QTreeWidget * myArchetypes
void validateClicked(bool)
object clone
An object from which to do object_copy()
Definition: object.h:470
linked_char * ingred
List of ingredients.
Definition: recipe.h:22
void setItem(const recipe *recipe)
Global type definitions and header inclusions.
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:465
int chance
Chance that recipe for this item will appear in an alchemical grimore.
Definition: recipe.h:14
QLineEdit * myDifficulty
sstring title
Distinguishing name of product.
Definition: recipe.h:11
char ** arch_name
Possible archetypes of the final product made.
Definition: recipe.h:13
QLineEdit * myYield
struct linked_char * next
Definition: global.h:88
struct recipestruct recipe
One alchemy recipe.
const char * name
The name of the object, obviously...
Definition: object.h:311
QLineEdit * myChance
QPushButton * myReset
QLineEdit * myExperience
#define FLAG_IS_CAULDRON
container can make alchemical stuff
Definition: define.h:339
This represents all archetypes for one particular object type.
Definition: artifact.h:26
Alchemy recipe structures.
sstring skill
Skill name used to make this recipe.
Definition: recipe.h:26
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
int index
Index value derived from formula ingredients.
Definition: recipe.h:18
This is one artifact, ie one special item.
Definition: artifact.h:14
QComboBox * mySkill
int exp
How much exp to give for this formulae.
Definition: recipe.h:17
Also see SKILL_TOOL (74) below.
Definition: object.h:143
const recipe * myRecipe
size_t arch_names
Size of the arch_name[] array.
Definition: recipe.h:12
QTextEdit * myIngredients
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
QPushButton * myValidate
struct archt * next
Next archetype in a linked list.
Definition: object.h:467
QComboBox * myTitle
object * item
Special values of the artifact.
Definition: artifact.h:15
QComboBox * myCauldron
EXTERN archetype * first_archetype
First archetype.
Definition: global.h:122
sstring cauldron
Arch of the cauldron/workbench used to house the formulae.
Definition: recipe.h:27
const char * name
More definite name, like "generate_kobold".
Definition: object.h:466
struct artifactstruct * next
Next artifact in the list.
Definition: artifact.h:18
One alchemy recipe.
Definition: recipe.h:10
Definition: main.c:88