Crossfire Server, Branches 1.12  R18729
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 QLineEdit(this);
20  layout->addWidget(myTitle, 1, 2);
21 
22  layout->addWidget(new QLabel(tr("Skill:"), this), 2, 1);
23  mySkill = new QComboBox(this);
24  layout->addWidget(mySkill, 2, 2);
25 
26  layout->addWidget(new QLabel(tr("Cauldron:"), this), 3, 1);
27  myCauldron = new QComboBox(this);
28  layout->addWidget(myCauldron, 3, 2);
29 
30  layout->addWidget(new QLabel(tr("Yield:"), this), 4, 1);
31  myYield = new QLineEdit(this);
32  layout->addWidget(myYield, 4, 2);
33 
34  layout->addWidget(new QLabel(tr("Chance:"), this), 5, 1);
35  myChance = new QLineEdit(this);
36  layout->addWidget(myChance, 5, 2);
37 
38  layout->addWidget(new QLabel(tr("Experience:"), this), 6, 1);
39  myExperience = new QLineEdit(this);
40  layout->addWidget(myExperience, 6, 2);
41 
42  layout->addWidget(new QLabel(tr("Difficulty:"), this), 7, 1);
43  myDifficulty = new QLineEdit(this);
44  layout->addWidget(myDifficulty, 7, 2);
45 
46  mySkill->addItem(tr("(none)"), 0);
47  myCauldron->addItem(tr("(none)"), 0);
48  const archt* arch = first_archetype;
49  for (; arch; arch = arch->next)
50  {
51  if (arch->clone.type == SKILL)
52  mySkill->addItem(arch->clone.name);
53  if (QUERY_FLAG(&arch->clone, FLAG_IS_CAULDRON))
54  myCauldron->addItem(arch->name);
55  }
56 
57  myArchetypes = new QTreeWidget(this);
58  myArchetypes->setHeaderLabel(tr("Archetypes:"));
59  myArchetypes->setRootIsDecorated(false);
60  myArchetypes->setIconSize(QSize(32, 32));
61  layout->addWidget(myArchetypes, 8, 1, 1, 2);
62 
63  layout->addWidget(new QLabel(tr("Ingredients:"), this), 9, 1, 1, 2);
64  myIngredients = new QTextEdit(this);
65  layout->addWidget(myIngredients, 10, 1, 1, 2);
66 
67  QHBoxLayout* buttons = new QHBoxLayout;
68  myValidate = new QPushButton(tr("&Validate"));
69  buttons->addWidget(myValidate);
70  myReset = new QPushButton(tr("&Reset"));
71  buttons->addWidget(myReset);
72  layout->addLayout(buttons, 11, 1, 1, 2);
73 
74  connect(myReset, SIGNAL(clicked(bool)), this, SLOT(resetClicked(bool)));
75  connect(myValidate, SIGNAL(clicked(bool)), this, SLOT(validateClicked(bool)));
76 }
77 
79 {
80  Q_ASSERT(recipe);
81  myRecipe = recipe;
82 
83  myTitle->setText(recipe->title);
84  myYield->setText(QString::number(recipe->yield));
85  myChance->setText(QString::number(recipe->chance));
86  myExperience->setText(QString::number(recipe->exp));
87  myDifficulty->setText(QString::number(recipe->diff));
88 
89  int index = mySkill->findText(recipe->skill);
90  if (index == -1)
91  index = 0;
92  mySkill->setCurrentIndex(index);
93 
94  index = myCauldron->findText(recipe->cauldron);
95  if (index == -1)
96  index = 0;
97  myCauldron->setCurrentIndex(index);
98 
99  myArchetypes->clear();
100 
101  const archt* arch;
102  for (size_t a = 0; a < recipe->arch_names; a++)
103  {
104  arch = find_archetype(recipe->arch_name[a]);
105  myArchetypes->addTopLevelItem(CREUtils::archetypeNode(arch, NULL));
106  }
107 
108  QStringList list;
109  for (const linked_char* ing = myRecipe->ingred; ing; ing = ing->next)
110  {
111  list.append(ing->name);
112  }
113  myIngredients->setPlainText(list.join("\n"));
114 }
115 
117 {
119 }
120 
122 {
123 #if 0
124  Q_ASSERT(myRecipe);
125 
126  myRecipe->setTitle(myTitle->text());
127  myRecipe->setYield(myYield->text().toInt());
128  myRecipe->setChance(myChance->text().toInt());
129  myRecipe->setExperience(myExperience->text().toInt());
130  myRecipe->setDifficulty(myDifficulty->text().toInt());
131  if (mySkill->currentIndex() != 0)
132  myRecipe->setSkill(mySkill->currentText());
133  else
134  myRecipe->setSkill("");
135  if (myCauldron->currentIndex() != 0)
136  myRecipe->setCauldron(myCauldron->currentText());
137  else
138  myRecipe->setCauldron("");
139 
140  QStringList arches;
141  const Archetype* arch;
142  ManagedReference ref;
143  for (int a = 0; a < myArchetypes->topLevelItemCount(); a++)
144  {
145  ref = myArchetypes->topLevelItem(a)->data(0, Qt::UserRole).toInt();
146  arch = DM_ARCHS->get(ref);
147  arches.append(arch->name);
148  DM_ARCHS->release(ref);
149  }
150  myRecipe->setArches(arches);
151 
152  myRecipe->setIngredients(myIngredients->toPlainText().split('\n'));
153 #endif
154 }
const char * title
Definition: recipe.h:11
archetype * find_archetype(const char *name)
Definition: arch.c:700
int diff
Definition: recipe.h:16
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:11
int yield
Definition: recipe.h:21
QTreeWidget * myArchetypes
void validateClicked(bool)
object clone
Definition: object.h:326
linked_char * ingred
Definition: recipe.h:22
Definition: object.h:321
int chance
Definition: recipe.h:14
QLineEdit * myDifficulty
char ** arch_name
Definition: recipe.h:13
QLineEdit * myYield
void setRecipe(const recipe *recipe)
struct linked_char * next
Definition: global.h:161
struct recipestruct recipe
const char * name
Definition: object.h:167
QLineEdit * myChance
QPushButton * myReset
QLineEdit * myExperience
#define FLAG_IS_CAULDRON
Definition: define.h:635
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
QComboBox * mySkill
int exp
Definition: recipe.h:17
const char * cauldron
Definition: recipe.h:26
const recipe * myRecipe
const char * skill
Definition: recipe.h:25
size_t arch_names
Definition: recipe.h:12
QTextEdit * myIngredients
#define SKILL
Definition: define.h:157
QPushButton * myValidate
struct archt * next
Definition: object.h:323
QLineEdit * myTitle
QComboBox * myCauldron
EXTERN archetype * first_archetype
Definition: global.h:195
const char * name
Definition: object.h:322
uint8 type
Definition: object.h:189