Crossfire Server, Trunk  R22047
CREFormulaePanel.cpp
Go to the documentation of this file.
1 #include <Qt>
2 #include <QtWidgets>
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  myIsTransmute = new QCheckBox(tr("Transmutation"), this);
48  myIsTransmute->setEnabled(false);
49  layout->addWidget(myIsTransmute, 8, 1, 1, 2);
50 
51  mySkill->addItem(tr("(none)"), 0);
52  myCauldron->addItem(tr("(none)"), 0);
53  archt* arch = get_next_archetype(NULL);
54  for (; arch; arch = get_next_archetype(arch))
55  {
56  if (arch->head)
57  continue;
58  if (arch->clone.type == SKILL)
59  mySkill->addItem(arch->clone.name);
60  if (QUERY_FLAG(&arch->clone, FLAG_IS_CAULDRON))
61  myCauldron->addItem(arch->name);
62  }
63 
64  layout->addWidget(new QLabel(tr("Index:"), this), 9, 1);
65  myIndex = new QLineEdit(this);
66  myIndex->setReadOnly(true);
67  layout->addWidget(myIndex, 9, 2);
68 
69  myArchetypes = new QTreeWidget(this);
70  myArchetypes->setHeaderLabel(tr("Archetypes:"));
71  myArchetypes->setRootIsDecorated(false);
72  myArchetypes->setIconSize(QSize(32, 32));
73  layout->addWidget(myArchetypes, 10, 1, 1, 2);
74 
75  layout->addWidget(new QLabel(tr("Ingredients:"), this), 11, 1, 1, 2);
76  myIngredients = new QTextEdit(this);
77  layout->addWidget(myIngredients, 12, 1, 1, 2);
78 
79  QHBoxLayout* buttons = new QHBoxLayout;
80  myValidate = new QPushButton(tr("&Validate"));
81  buttons->addWidget(myValidate);
82  myReset = new QPushButton(tr("&Reset"));
83  buttons->addWidget(myReset);
84  layout->addLayout(buttons, 13, 1, 1, 2);
85 
86  connect(myReset, SIGNAL(clicked(bool)), this, SLOT(resetClicked(bool)));
87  connect(myValidate, SIGNAL(clicked(bool)), this, SLOT(validateClicked(bool)));
88 }
89 
91 {
92  Q_ASSERT(recipe);
93  myRecipe = recipe;
94 
95  myTitle->clear();
96  myTitle->addItem("NONE");
97  if (recipe->arch_names > 0)
98  {
99  archetype* arch = find_archetype(recipe->arch_name[0]);
100  if (arch)
101  {
102  const artifactlist* at = find_artifactlist(arch->clone.type);
103  if (at != NULL)
104  {
105  artifact* art = at->items;
106  while (art)
107  {
108  if (art->item != NULL && art->item->name != NULL)
109  myTitle->addItem(art->item->name);
110  art = art->next;
111  }
112  }
113  }
114  }
115 
116  int index = myTitle->findText(recipe->title);
117  if (index == -1)
118  index = 0;
119  myTitle->setCurrentIndex(index);
120  myYield->setText(QString::number(recipe->yield));
121  myChance->setText(QString::number(recipe->chance));
122  myExperience->setText(QString::number(recipe->exp));
123  myDifficulty->setText(QString::number(recipe->diff));
124  myIsTransmute->setChecked(recipe->transmute);
125  myIndex->setText(QString::number(recipe->index));
126 
127  index = mySkill->findText(recipe->skill);
128  if (index == -1)
129  index = 0;
130  mySkill->setCurrentIndex(index);
131 
132  index = myCauldron->findText(recipe->cauldron);
133  if (index == -1)
134  index = 0;
135  myCauldron->setCurrentIndex(index);
136 
137  myArchetypes->clear();
138 
139  const archt* arch;
140  for (size_t a = 0; a < recipe->arch_names; a++)
141  {
142  arch = find_archetype(recipe->arch_name[a]);
143  if (arch)
144  {
145  myArchetypes->addTopLevelItem(CREUtils::archetypeNode(arch, NULL));
146  }
147  }
148 
149  QStringList list;
150  for (const linked_char* ing = myRecipe->ingred; ing; ing = ing->next)
151  {
152  list.append(ing->name);
153  }
154  myIngredients->setPlainText(list.join("\n"));
155 }
156 
158 {
159  setItem(myRecipe);
160 }
161 
163 {
164 #if 0
165  Q_ASSERT(myRecipe);
166 
167  myRecipe->setTitle(myTitle->text());
168  myRecipe->setYield(myYield->text().toInt());
169  myRecipe->setChance(myChance->text().toInt());
170  myRecipe->setExperience(myExperience->text().toInt());
171  myRecipe->setDifficulty(myDifficulty->text().toInt());
172  if (mySkill->currentIndex() != 0)
173  myRecipe->setSkill(mySkill->currentText());
174  else
175  myRecipe->setSkill("");
176  if (myCauldron->currentIndex() != 0)
177  myRecipe->setCauldron(myCauldron->currentText());
178  else
179  myRecipe->setCauldron("");
180 
181  QStringList arches;
182  const Archetype* arch;
183  ManagedReference ref;
184  for (int a = 0; a < myArchetypes->topLevelItemCount(); a++)
185  {
186  ref = myArchetypes->topLevelItem(a)->data(0, Qt::UserRole).toInt();
187  arch = DM_ARCHS->get(ref);
188  arches.append(arch->name);
189  DM_ARCHS->release(ref);
190  }
191  myRecipe->setArches(arches);
192 
193  myRecipe->setIngredients(myIngredients->toPlainText().split('\n'));
194 #endif
195 }
int diff
Definition: recipe.h:16
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:15
const artifactlist * find_artifactlist(int type)
Definition: artifact.c:642
archetype * find_archetype(const char *name)
Definition: assets.cpp:253
int yield
Definition: recipe.h:21
struct artifactstruct * items
Definition: artifact.h:30
QTreeWidget * myArchetypes
void validateClicked(bool)
linked_char * ingred
Definition: recipe.h:22
void setItem(const recipe *recipe)
int transmute
Definition: recipe.h:19
int chance
Definition: recipe.h:14
QLineEdit * myDifficulty
QCheckBox * myIsTransmute
sstring title
Definition: recipe.h:11
char ** arch_name
Definition: recipe.h:13
QLineEdit * myYield
struct linked_char * next
Definition: global.h:88
struct recipestruct recipe
QLineEdit * myChance
QPushButton * myReset
QLineEdit * myExperience
#define FLAG_IS_CAULDRON
Definition: define.h:339
archetype * get_next_archetype(archetype *current)
Definition: assets.cpp:249
sstring skill
Definition: recipe.h:26
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
CREFormulaePanel(QWidget *parent)
int index
Definition: recipe.h:18
QComboBox * mySkill
int exp
Definition: recipe.h:17
const recipe * myRecipe
size_t arch_names
Definition: recipe.h:12
QTextEdit * myIngredients
QPushButton * myValidate
QComboBox * myTitle
object * item
Definition: artifact.h:15
QComboBox * myCauldron
QLineEdit * myIndex
sstring cauldron
Definition: recipe.h:27
struct artifactstruct * next
Definition: artifact.h:18
Definition: main.c:85