Crossfire Server, Branches 1.12  R18729
CREResourcesWindow.cpp
Go to the documentation of this file.
1 #include <Qt>
2 #include <QtGui>
3 
4 #include "CREResourcesWindow.h"
5 #include "CREUtils.h"
6 #include "CREPixmap.h"
7 
8 #include "CRETreeItemAnimation.h"
9 #include "CRETreeItemArchetype.h"
10 #include "CRETreeItemTreasure.h"
11 #include "CRETreeItemArtifact.h"
12 #include "CRETreeItemFormulae.h"
13 #include "CRETreeItemFace.h"
14 
15 #include "CREAnimationPanel.h"
16 #include "CREArchetypePanel.h"
17 #include "CRETreasurePanel.h"
18 #include "CREArtifactPanel.h"
19 #include "CREFormulaePanel.h"
20 #include "CREFacePanel.h"
21 
22 extern "C" {
23 #include "global.h"
24 #include "recipe.h"
25 }
26 
28 {
29  QApplication::setOverrideCursor(Qt::WaitCursor);
30 
31  setAttribute(Qt::WA_DeleteOnClose);
32 
33  QGridLayout* layout = new QGridLayout(this);
34  mySplitter = new QSplitter(this);
35  layout->addWidget(mySplitter);
36  myTree = new QTreeWidget(this);
37  mySplitter->addWidget(myTree);
38  myTree->setIconSize(QSize(32, 32));
39  myTree->setHeaderLabel(tr("All resources"));
40 
41  QString title;
42  if (mode & DisplayArchetypes)
43  {
44  title = tr("Archetypes");
46  }
47  if (mode & DisplayAnimations)
48  {
49  title = tr("Animations");
51  }
52  if (mode & DisplayTreasures)
53  {
54  title = tr("Treasures");
55  fillTreasures();
56  }
57  if (mode & DisplayFormulae)
58  {
59  title = tr("Formulae");
60  fillFormulae();
61  }
62  if (mode & DisplayArtifacts)
63  {
64  title = tr("Artifacts");
65  fillArtifacts();
66  }
67  if (mode & DisplayFaces)
68  {
69  title = tr("Faces");
70  fillFaces();
71  }
72 
73  if (mode == DisplayAll)
74  title = tr("All resources");
75 
76  myTree->setSortingEnabled(true);
77 
78  myCurrentPanel = NULL;
79 
80  connect(myTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(tree_currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
81 
82  setWindowTitle(title);
83 
84  QApplication::restoreOverrideCursor();
85 }
86 
87 void CREResourcesWindow::tree_currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem*)
88 {
89  if (!current || current->data(0, Qt::UserRole).value<void*>() == NULL)
90  return;
91  CRETreeItem* item = reinterpret_cast<CRETreeItem*>(current->data(0, Qt::UserRole).value<void*>());
92  if (!item)
93  return;
94 
95 
96  QWidget* newPanel = myPanels[item->getPanelName()];
97  if (!newPanel)
98  {
99 // printf("no panel for %s\n", qPrintable(item->getPanelName()));
100  return;
101  }
102 
103  item->fillPanel(newPanel);
104 
105  if (myCurrentPanel != newPanel)
106  {
107  if (myCurrentPanel)
108  myCurrentPanel->setVisible(false);
109  newPanel->setVisible(true);
110  myCurrentPanel = newPanel;
111  }
112 }
113 
115 {
116  QTreeWidgetItem* animationsNode = CREUtils::animationNode(NULL);
117  myTree->addTopLevelItem(animationsNode);
118 
119  QTreeWidgetItem* item;
120 
121  // There is the "bug" animation to consider
122  for (int anim = 0; anim <= num_animations; anim++)
123  {
124  item = CREUtils::animationNode(&animations[anim], animationsNode);
125  item->setData(0, Qt::UserRole, QVariant::fromValue<void*>(new CRETreeItemAnimation(&animations[anim])));
126  }
127 
128  addPanel("Animation", new CREAnimationPanel());
129 }
130 
132 {
133  QTreeWidgetItem* item, *sub;
134  const treasurelist* list;
135  const treasure* treasure;
136 
137  QTreeWidgetItem* treasures = CREUtils::treasureNode(NULL);
138  myTree->addTopLevelItem(treasures);
139 
140  for (list = first_treasurelist; list; list = list->next)
141  {
142  item = CREUtils::treasureNode(list, treasures);
143 
144  item->setData(0, Qt::UserRole, QVariant::fromValue<void*>(new CRETreeItemTreasure(list)));
145  //item->setData(0, Qt::UserRole, allTreasures[t]);
146  if (list->total_chance != 0)
147  item->setText(1, QString::number(list->total_chance));
148 
149  for (treasure = list->items; treasure; treasure = treasure->next)
150  {
151  sub = CREUtils::treasureNode(treasure, item);
152  if (treasure->chance)
153  sub->setText(1, QString::number(treasure->chance));
154  sub->setData(0, Qt::UserRole, QVariant::fromValue<void*>(new CRETreeItemTreasure(list)));
155  }
156  }
157 
158  addPanel("Treasure", new CRETreasurePanel());
159 }
160 
162 {
163  QTreeWidgetItem* item, *root, *sub;
164  archt* arch;
165 
166  root = CREUtils::archetypeNode(NULL);
167  myTree->addTopLevelItem(root);
168 
169  for (arch = first_archetype; arch; arch = arch->next)
170  {
171  item = CREUtils::archetypeNode(arch, root);
172  item->setData(0, Qt::UserRole, QVariant::fromValue<void*>(new CRETreeItemArchetype(arch)));
173 
174  for (archt* more = arch->more; more; more = more->more)
175  {
176  sub = CREUtils::archetypeNode(more, item);
177  sub->setData(0, Qt::UserRole, QVariant::fromValue<void*>(new CRETreeItemArchetype(more)));
178  }
179  }
180 
181  addPanel("Archetype", new CREArchetypePanel());
182 }
183 
185 {
186  recipelist* list;
187  recipe* recipe;
188  QTreeWidgetItem* root, *form, *sub;
189 
190  form = new QTreeWidgetItem(myTree, QStringList(tr("Formulae")));
191 // myTree->addTopLevelItem(form);
192 
193  for (int ing = 1; ; ing++)
194  {
195  list = get_formulalist(ing);
196  if (!list)
197  break;
198 
199  root = new QTreeWidgetItem(form, QStringList(tr("%1 ingredients").arg(ing)));
200 
201  for (recipe = list->items; recipe; recipe = recipe->next)
202  {
203  sub = CREUtils::formulaeNode(recipe, root);
204  sub->setData(0, Qt::UserRole, QVariant::fromValue<void*>(new CRETreeItemFormulae(recipe)));
205  }
206  }
207 
208  addPanel("Formulae", new CREFormulaePanel());
209 }
210 
212 {
213  QTreeWidgetItem* item, *root, *sub;
214  artifactlist* list;
215  const typedata* data;
216 
217  root = new QTreeWidgetItem(myTree, QStringList(tr("Artifacts")));
218 
219  for (list = first_artifactlist; list; list = list->next)
220  {
221  data = get_typedata(list->type);
222 
223  item = new QTreeWidgetItem(root, QStringList(data ? data->name : tr("type %1").arg(list->type)));
224 
225  for (artifact* art = list->items; art; art = art->next)
226  {
227  sub = CREUtils::artifactNode(art, item);
228  sub->setData(0, Qt::UserRole, QVariant::fromValue<void*>(new CRETreeItemArtifact(art)));
229  }
230  }
231 
232  addPanel("Artifact", new CREArtifactPanel());
233 }
234 
236 {
237  QTreeWidgetItem* item, *root;
238 
239  root = CREUtils::faceNode(NULL);
240  myTree->addTopLevelItem(root);
241 
242  extern int nrofpixmaps;
243 
244  for (int f = 0; f < nrofpixmaps; f++)
245  {
246  item = CREUtils::faceNode(&new_faces[f], root);
247  item->setData(0, Qt::UserRole, QVariant::fromValue<void*>(new CRETreeItemFace(&new_faces[f])));
248  }
249 
250  addPanel("Face", new CREFacePanel());
251 }
252 
253 void CREResourcesWindow::addPanel(QString name, QWidget* panel)
254 {
255  panel->setVisible(false);
256  myPanels[name] = panel;
257  mySplitter->addWidget(panel);
258 }
int nrofpixmaps
Definition: image.c:76
static QTreeWidgetItem * animationNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:142
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:11
static QTreeWidgetItem * artifactNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:25
sint16 total_chance
Definition: treasure.h:113
New_Face * new_faces
Definition: image.c:38
CREResourcesWindow(DisplayMode mode=DisplayAll)
EXTERN int num_animations
Definition: global.h:242
struct artifactstruct * items
Definition: artifact.h:52
void tree_currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)
struct treasureliststruct * next
Definition: treasure.h:118
virtual QString getPanelName() const =0
static QTreeWidgetItem * formulaeNode(const recipe *recipe, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:101
Definition: object.h:321
static QTreeWidgetItem * faceNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:129
void addPanel(QString name, QWidget *panel)
virtual void fillPanel(QWidget *panel)=0
struct titlestruct title
const typedata * get_typedata(int itemtype)
Definition: item.c:352
struct artifactliststruct * next
Definition: artifact.h:51
static char root[500]
Definition: mapper.c:361
struct recipestruct recipe
struct archt * more
Definition: object.h:325
EXTERN Animations * animations
Definition: global.h:241
EXTERN treasurelist * first_treasurelist
Definition: global.h:193
EXTERN artifactlist * first_artifactlist
Definition: global.h:194
QHash< QString, QPointer< QWidget > > myPanels
struct treasurestruct * items
Definition: treasure.h:119
const char * name
Definition: define.h:379
struct treasurestruct treasure
DisplayMode
struct archt * next
Definition: object.h:323
struct recipestruct * next
Definition: recipe.h:23
static QTreeWidgetItem * treasureNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:64
struct treasurestruct * next
Definition: treasure.h:95
EXTERN archetype * first_archetype
Definition: global.h:195
uint8 chance
Definition: treasure.h:99
struct recipestruct * items
Definition: recipe.h:33
recipelist * get_formulalist(int i)
Definition: recipe.c:112
struct artifactstruct * next
Definition: artifact.h:41