Crossfire Server, Trunk
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 #include "assets.h"
9 #include "AssetsManager.h"
10 
11 #include "CREFormulaePanel.h"
12 #include "CREUtils.h"
13 
15 {
16  myRecipe = NULL;
17 
18  QGridLayout* layout = new QGridLayout(this);
19 
20  layout->addWidget(new QLabel(tr("Title:"), this), 1, 1);
21  myTitle = new QComboBox(this);
22 
23  layout->addWidget(myTitle, 1, 2);
24 
25  layout->addWidget(new QLabel(tr("Skill:"), this), 2, 1);
26  mySkill = new QComboBox(this);
27  layout->addWidget(mySkill, 2, 2);
28 
29  layout->addWidget(new QLabel(tr("Cauldron:"), this), 3, 1);
30  myCauldron = new QComboBox(this);
31  layout->addWidget(myCauldron, 3, 2);
32 
33  layout->addWidget(new QLabel(tr("Yield:"), this), 4, 1);
34  myYield = new QLineEdit(this);
35  layout->addWidget(myYield, 4, 2);
36 
37  layout->addWidget(new QLabel(tr("Chance:"), this), 5, 1);
38  myChance = new QLineEdit(this);
39  layout->addWidget(myChance, 5, 2);
40 
41  layout->addWidget(new QLabel(tr("Experience:"), this), 6, 1);
42  myExperience = new QLineEdit(this);
43  layout->addWidget(myExperience, 6, 2);
44 
45  layout->addWidget(new QLabel(tr("Difficulty:"), this), 7, 1);
46  myDifficulty = new QLineEdit(this);
47  layout->addWidget(myDifficulty, 7, 2);
48 
49  myIsTransmute = new QCheckBox(tr("Transmutation"), this);
50  myIsTransmute->setEnabled(false);
51  layout->addWidget(myIsTransmute, 8, 1, 1, 2);
52 
53  mySkill->addItem(tr("(none)"), 0);
54  myCauldron->addItem(tr("(none)"), 0);
55  getManager()->archetypes()->each([this] (archetype *arch)
56  {
57  if (arch->head)
58  return;
59  if (arch->clone.type == SKILL)
60  mySkill->addItem(arch->clone.name);
62  myCauldron->addItem(arch->name);
63  });
64 
65  layout->addWidget(new QLabel(tr("Index:"), this), 9, 1);
66  myIndex = new QLineEdit(this);
67  myIndex->setReadOnly(true);
68  layout->addWidget(myIndex, 9, 2);
69 
70  myArchetypes = new QTreeWidget(this);
71  myArchetypes->setHeaderLabel(tr("Archetypes:"));
72  myArchetypes->setRootIsDecorated(false);
73  myArchetypes->setIconSize(QSize(32, 32));
74  layout->addWidget(myArchetypes, 10, 1, 1, 2);
75 
76  layout->addWidget(new QLabel(tr("Ingredients:"), this), 11, 1, 1, 2);
77  myIngredients = new QTextEdit(this);
78  layout->addWidget(myIngredients, 12, 1, 1, 2);
79 
80  QHBoxLayout* buttons = new QHBoxLayout;
81  myValidate = new QPushButton(tr("&Validate"));
82  buttons->addWidget(myValidate);
83  myReset = new QPushButton(tr("&Reset"));
84  buttons->addWidget(myReset);
85  layout->addLayout(buttons, 13, 1, 1, 2);
86 
87  connect(myReset, SIGNAL(clicked(bool)), this, SLOT(resetClicked(bool)));
88  connect(myValidate, SIGNAL(clicked(bool)), this, SLOT(validateClicked(bool)));
89 }
90 
92 {
93  Q_ASSERT(recipe);
94  myRecipe = recipe;
95 
96  myTitle->clear();
97  myTitle->addItem("NONE");
98  if (recipe->arch_names > 0)
99  {
101  if (arch)
102  {
103  const artifactlist* at = find_artifactlist(arch->clone.type);
104  if (at != NULL)
105  {
106  artifact* art = at->items;
107  while (art)
108  {
109  if (art->item != NULL && art->item->name != NULL)
110  myTitle->addItem(art->item->name);
111  art = art->next;
112  }
113  }
114  }
115  }
116 
117  int index = myTitle->findText(recipe->title);
118  if (index == -1)
119  index = 0;
120  myTitle->setCurrentIndex(index);
121  myYield->setText(QString::number(recipe->yield));
122  myChance->setText(QString::number(recipe->chance));
123  myExperience->setText(QString::number(recipe->exp));
124  myDifficulty->setText(QString::number(recipe->diff));
125  myIsTransmute->setChecked(recipe->transmute);
126  myIndex->setText(QString::number(recipe->index));
127 
128  index = mySkill->findText(recipe->skill);
129  if (index == -1)
130  index = 0;
131  mySkill->setCurrentIndex(index);
132 
133  index = myCauldron->findText(recipe->cauldron);
134  if (index == -1)
135  index = 0;
136  myCauldron->setCurrentIndex(index);
137 
138  myArchetypes->clear();
139 
140  const archt* arch;
141  for (size_t a = 0; a < recipe->arch_names; a++)
142  {
144  if (arch)
145  {
146  myArchetypes->addTopLevelItem(CREUtils::archetypeNode(arch, NULL));
147  }
148  }
149 
150  QStringList list;
151  for (const linked_char* ing = myRecipe->ingred; ing; ing = ing->next)
152  {
153  list.append(ing->name);
154  }
155  myIngredients->setPlainText(list.join("\n"));
156 }
157 
159 {
160  setItem(myRecipe);
161 }
162 
164 {
165 #if 0
166  Q_ASSERT(myRecipe);
167 
168  myRecipe->setTitle(myTitle->text());
169  myRecipe->setYield(myYield->text().toInt());
170  myRecipe->setChance(myChance->text().toInt());
171  myRecipe->setExperience(myExperience->text().toInt());
172  myRecipe->setDifficulty(myDifficulty->text().toInt());
173  if (mySkill->currentIndex() != 0)
174  myRecipe->setSkill(mySkill->currentText());
175  else
176  myRecipe->setSkill("");
177  if (myCauldron->currentIndex() != 0)
178  myRecipe->setCauldron(myCauldron->currentText());
179  else
180  myRecipe->setCauldron("");
181 
182  QStringList arches;
183  const Archetype* arch;
184  ManagedReference ref;
185  for (int a = 0; a < myArchetypes->topLevelItemCount(); a++)
186  {
187  ref = myArchetypes->topLevelItem(a)->data(0, Qt::UserRole).toInt();
188  arch = DM_ARCHS->get(ref);
189  arches.append(arch->name);
190  DM_ARCHS->release(ref);
191  }
192  myRecipe->setArches(arches);
193 
194  myRecipe->setIngredients(myIngredients->toPlainText().split('\n'));
195 #endif
196 }
recipestruct::arch_names
size_t arch_names
Definition: recipe.h:12
CREFormulaePanel::validateClicked
void validateClicked(bool)
Definition: CREFormulaePanel.cpp:163
CREFormulaePanel.h
CRETPanel
Definition: CREPanel.h:20
global.h
CREFormulaePanel::resetClicked
void resetClicked(bool)
Definition: CREFormulaePanel.cpp:158
layout
Definition: main.c:85
CREFormulaePanel::CREFormulaePanel
CREFormulaePanel(QWidget *parent)
Definition: CREFormulaePanel.cpp:14
recipestruct::yield
int yield
Definition: recipe.h:21
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
AssetsManager.h
disinfect.a
a
Definition: disinfect.py:13
CREUtils::archetypeNode
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:14
CREUtils.h
CREFormulaePanel::myArchetypes
QTreeWidget * myArchetypes
Definition: CREFormulaePanel.h:33
guildoracle.list
list
Definition: guildoracle.py:87
recipe.h
CREFormulaePanel::myReset
QPushButton * myReset
Definition: CREFormulaePanel.h:36
recipestruct::title
sstring title
Definition: recipe.h:11
SKILL
@ SKILL
Definition: object.h:143
CREFormulaePanel::myChance
QLineEdit * myChance
Definition: CREFormulaePanel.h:26
artifactliststruct::items
struct artifactstruct * items
Definition: artifact.h:30
CREFormulaePanel::myIngredients
QTextEdit * myIngredients
Definition: CREFormulaePanel.h:34
getManager
AssetsManager * getManager()
Definition: assets.cpp:329
recipestruct::chance
int chance
Definition: recipe.h:14
find_artifactlist
const artifactlist * find_artifactlist(int type)
Definition: artifact.c:647
linked_char
Definition: global.h:86
CREFormulaePanel::myCauldron
QComboBox * myCauldron
Definition: CREFormulaePanel.h:30
archt
Definition: object.h:468
recipestruct
Definition: recipe.h:10
obj::name
sstring name
Definition: object.h:312
artifactstruct::next
struct artifactstruct * next
Definition: artifact.h:18
recipestruct::cauldron
sstring cauldron
Definition: recipe.h:27
recipestruct::arch_name
char ** arch_name
Definition: recipe.h:13
CREFormulaePanel::myExperience
QLineEdit * myExperience
Definition: CREFormulaePanel.h:27
CREFormulaePanel::setItem
void setItem(const recipe *recipe) override
Definition: CREFormulaePanel.cpp:91
recipestruct::exp
int exp
Definition: recipe.h:17
linked_char::next
struct linked_char * next
Definition: global.h:88
artifactliststruct
Definition: artifact.h:26
CREFormulaePanel::myIsTransmute
QCheckBox * myIsTransmute
Definition: CREFormulaePanel.h:31
CREFormulaePanel::myDifficulty
QLineEdit * myDifficulty
Definition: CREFormulaePanel.h:28
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:135
recipestruct::ingred
linked_char * ingred
Definition: recipe.h:22
CREFormulaePanel::myYield
QLineEdit * myYield
Definition: CREFormulaePanel.h:25
AssetsManager::archetypes
Archetypes * archetypes()
Definition: AssetsManager.h:44
artifactstruct
Definition: artifact.h:14
CREFormulaePanel::myValidate
QPushButton * myValidate
Definition: CREFormulaePanel.h:35
CREFormulaePanel::mySkill
QComboBox * mySkill
Definition: CREFormulaePanel.h:29
recipestruct::skill
sstring skill
Definition: recipe.h:26
find_archetype
archetype * find_archetype(const char *name)
Definition: assets.cpp:278
CREFormulaePanel::myRecipe
const recipe * myRecipe
Definition: CREFormulaePanel.h:23
assets.h
npc_dialog.index
int index
Definition: npc_dialog.py:102
CREFormulaePanel::myTitle
QComboBox * myTitle
Definition: CREFormulaePanel.h:24
recipestruct::diff
int diff
Definition: recipe.h:16
recipestruct::transmute
int transmute
Definition: recipe.h:19
artifactstruct::item
object * item
Definition: artifact.h:15
recipestruct::index
int index
Definition: recipe.h:18
CREFormulaePanel::myIndex
QLineEdit * myIndex
Definition: CREFormulaePanel.h:32
connect
Definition: connect.py:1
FLAG_IS_CAULDRON
#define FLAG_IS_CAULDRON
Definition: define.h:338
if
if(!(yy_init))
Definition: loader.c:2589
recipe
struct recipestruct recipe