Crossfire Server, Trunk  R20513
CREAnimationPanel.cpp
Go to the documentation of this file.
1 #include <Qt>
2 
3 extern "C" {
4 #include "global.h"
5 #include "artifact.h"
6 #include "object.h"
7 #include "face.h"
8 }
9 
10 #include "CREAnimationPanel.h"
11 #include "CREAnimationControl.h"
12 #include "CREUtils.h"
13 
15 {
16  myAnimation = 0;
17 
18  QGridLayout* layout = new QGridLayout(this);
19 
20  myUsing = new QTreeWidget(this);
21  myUsing->setColumnCount(1);
22  myUsing->setHeaderLabel(tr("Used by"));
23  myUsing->setIconSize(QSize(32, 32));
24  myUsing->sortByColumn(0, Qt::AscendingOrder);
25  layout->addWidget(myUsing, 1, 1);
26 
27  myFaces = new QTreeWidget(this);
28  myFaces->setColumnCount(1);
29  myFaces->setHeaderLabel(tr("Faces"));
30  myFaces->setIconSize(QSize(32, 32));
31  layout->addWidget(myFaces, 2, 1);
32 
33  myDisplay = new CREAnimationControl(this);
34  layout->addWidget(myDisplay, 3, 1);
35 }
36 
37 void CREAnimationPanel::setItem(const Animations* animation)
38 {
39  Q_ASSERT(animation);
40  myAnimation = animation;
41 
42  myUsing->clear();
43 
45 
46  QTreeWidgetItem* root = NULL;
47 
48  const archt* arch;
49  sstring key;
50 
51  for (arch = first_archetype; arch; arch = (arch->more ? arch->more : arch->next))
52  {
53  key = object_get_value(&arch->clone, "identified_animation");
54  if (arch->clone.animation_id == myAnimation->num || (key && strcmp(animation->name, key) == 0))
55  {
56  if (root == NULL)
57  {
58  root = CREUtils::archetypeNode(NULL);
59  myUsing->addTopLevelItem(root);
60  root->setExpanded(true);
61  }
62  CREUtils::archetypeNode(arch, root);
63  }
64  }
65 
66  root = NULL;
67 
68  artifactlist* list;
69  artifact* art;
70 
71  for (list = first_artifactlist; list; list = list->next)
72  {
73  for (art = list->items; art; art = art->next)
74  {
75  if (art->item->animation_id == myAnimation->num)
76  {
77  if (root == NULL)
78  {
79  root = CREUtils::artifactNode(NULL);
80  myUsing->addTopLevelItem(root);
81  root->setExpanded(true);
82  }
83  CREUtils::artifactNode(art, root);
84  }
85  }
86  }
87 
88  myFaces->clear();
89  root = CREUtils::faceNode(NULL);
90  myFaces->addTopLevelItem(root);
91  root->setExpanded(true);
92 
93  for (int face = 0; face < animation->num_animations; face++)
94  {
95  CREUtils::faceNode(animation->faces[face], root);
96  }
97 }
QTreeWidget * myFaces
virtual void setItem(const Animations *animation)
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:15
static QTreeWidgetItem * artifactNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:42
uint16_t animation_id
An index into the animation array.
Definition: object.h:416
const char * name
Name of the animation sequence.
Definition: face.h:27
const Animations * myAnimation
struct artifactstruct * items
Artifacts for this type.
Definition: artifact.h:30
const char * object_get_value(const object *op, const char *const key)
Get an extra value by key.
Definition: object.c:4246
object clone
An object from which to do object_copy()
Definition: object.h:470
CREAnimationControl * myDisplay
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
static QTreeWidgetItem * faceNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:169
struct artifactliststruct * next
Next list of artifacts.
Definition: artifact.h:29
static char root[500]
Path to store generated files.
Definition: mapper.c:365
uint16_t num
Where we are in the array.
Definition: face.h:30
QTreeWidget * myUsing
struct archt * more
Next part of a linked object.
Definition: object.h:469
This represents one animation.
Definition: face.h:26
uint8_t num_animations
How many different faces to animate, size of the faces array.
Definition: face.h:28
Face-related structures.
void setAnimation(const Animations *animation, int facings=-1)
Define the animation to display.
This represents all archetypes for one particular object type.
Definition: artifact.h:26
EXTERN artifactlist * first_artifactlist
First artifact.
Definition: global.h:121
This is one artifact, ie one special item.
Definition: artifact.h:14
const char * sstring
Strings that should be manipulated through add_string() and free_string().
Definition: global.h:40
const New_Face ** faces
The actual faces for the animation.
Definition: face.h:31
Object structure, the core of Crossfire.
struct archt * next
Next archetype in a linked list.
Definition: object.h:467
object * item
Special values of the artifact.
Definition: artifact.h:15
EXTERN archetype * first_archetype
First archetype.
Definition: global.h:122
Artifact-related structures.
struct artifactstruct * next
Next artifact in the list.
Definition: artifact.h:18
Definition: main.c:88