Crossfire Server, Trunk
AnimationControl.cpp
Go to the documentation of this file.
1 #include <Qt>
2 
3 #include "AnimationControl.h"
4 #include "AnimationWidget.h"
5 #include "face.h"
6 
7 AnimationControl::AnimationControl(QWidget* parent) : QWidget(parent)
8 {
9  myAnimation = NULL;
10  myStep = 0;
11  myLastStep = 0;
12 
13  AnimationWidget* widget;
14  QGridLayout* layout = new QGridLayout(this);
15 
16  for (int dir = 1; dir <= 8; dir++)
17  {
18  widget = new AnimationWidget(this);
19  widget->setVisible(false);
20 
21  layout->addWidget(widget, 2 + freearr_y[dir], 2 + freearr_x[dir]);
22  myWidgets.append(widget);
23  }
24 
25  myTimer = new QTimer(this);
26  connect(myTimer, SIGNAL(timeout()), this, SLOT(step()));
27 }
28 
30 {
31  myTimer->stop();
32  myAnimation = animation;
33  display(animation, facings);
34  myTimer->start(250);
35 }
36 
37 void AnimationControl::display(const Animations* animation, int facings)
38 {
39  myFacings = facings == -1 ? animation->facings : facings;
40 
41  int widget, widgetStep, faceCount, face, faceCurrent;
42 
43  for (widget = 0; widget < 8; widget++)
44  myWidgets[widget]->setVisible(false);
45 
46  widget = 0;
47 
48  if (myFacings == 1)
49  {
50  widgetStep = 8;
51  faceCount = animation->num_animations;
52  }
53  else if (myFacings == 2)
54  {
55  widgetStep = 4;
56  faceCount = animation->num_animations / 2;
57  }
58  else if (myFacings == 4)
59  {
60  widgetStep = 2;
61  faceCount = animation->num_animations / 4;
62  }
63  else
64  {
65  widgetStep = 1;
66  faceCount = animation->num_animations / 8;
67  }
68 
69  face = facings == -1 ? 0 : 1;
70  while (widget < 8)
71  {
72  myWidgets[widget]->setVisible(true);
73  QList<int> faces;
74  for (faceCurrent = 0; faceCurrent < faceCount; faceCurrent++)
75  faces.append(animation->faces[face++]->number);
76  myWidgets[widget]->setAnimation(faces);
77 
78  widget += widgetStep;
79  }
80 }
81 
83 {
84  if (myAnimation == NULL)
85  return;
86 
87  for (int w = 0; w < myWidgets.size(); w++)
88  myWidgets[w]->step();
89 }
layout
Definition: main.c:85
face.h
AnimationControl.h
AnimationControl::myLastStep
int myLastStep
Definition: AnimationControl.h:30
AnimationWidget.h
make_face_from_files.facings
list facings
Definition: make_face_from_files.py:39
freearr_x
short freearr_x[SIZEOFFREE]
Definition: object.c:299
freearr_y
short freearr_y[SIZEOFFREE]
Definition: object.c:305
Face::number
uint16_t number
Definition: face.h:15
animations_struct::num_animations
uint8_t num_animations
Definition: face.h:27
AnimationControl::myFacings
int myFacings
Definition: AnimationControl.h:31
animations_struct
Definition: face.h:25
animations_struct::facings
uint8_t facings
Definition: face.h:28
AnimationControl::step
void step()
Definition: AnimationControl.cpp:82
AnimationWidget
Definition: AnimationWidget.h:7
AnimationControl::display
void display(const Animations *animation, int facings=-1)
Definition: AnimationControl.cpp:37
AnimationControl::myWidgets
QList< AnimationWidget * > myWidgets
Definition: AnimationControl.h:34
animations_struct::faces
const Face ** faces
Definition: face.h:30
dragon_attune.faces
dictionary faces
Definition: dragon_attune.py:31
AnimationControl::setAnimation
void setAnimation(const Animations *animation, int facings=-1)
Definition: AnimationControl.cpp:29
AnimationControl::myAnimation
const Animations * myAnimation
Definition: AnimationControl.h:28
AnimationControl::myTimer
QTimer * myTimer
Definition: AnimationControl.h:35
connect
Definition: connect.py:1
AnimationControl::myStep
int myStep
Definition: AnimationControl.h:29
AnimationControl::AnimationControl
AnimationControl(QWidget *parent)
Definition: AnimationControl.cpp:7