Crossfire Server, Trunk
AnimationControl.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include <Qt>
14 
15 #include "AnimationControl.h"
16 #include "AnimationWidget.h"
17 #include "face.h"
18 
19 AnimationControl::AnimationControl(QWidget* parent) : QWidget(parent)
20 {
21  myAnimation = NULL;
22  myStep = 0;
23  myLastStep = 0;
24 
25  AnimationWidget* widget;
26  QGridLayout* layout = new QGridLayout(this);
27 
28  for (int dir = 1; dir <= 8; dir++)
29  {
30  widget = new AnimationWidget(this);
31  widget->setVisible(false);
32 
33  layout->addWidget(widget, 2 + freearr_y[dir], 2 + freearr_x[dir]);
34  myWidgets.append(widget);
35  }
36 
37  myTimer = new QTimer(this);
38  connect(myTimer, SIGNAL(timeout()), this, SLOT(step()));
39 }
40 
42 {
43  myTimer->stop();
44  myAnimation = animation;
45  display(animation, facings);
46  myTimer->start(250);
47 }
48 
49 void AnimationControl::display(const Animations* animation, int facings)
50 {
51  myFacings = facings == -1 ? animation->facings : facings;
52 
53  int widget, widgetStep, faceCount, face, faceCurrent;
54 
55  for (widget = 0; widget < 8; widget++)
56  myWidgets[widget]->setVisible(false);
57 
58  widget = 0;
59 
60  if (myFacings == 1)
61  {
62  widgetStep = 8;
63  faceCount = animation->num_animations;
64  }
65  else if (myFacings == 2)
66  {
67  widgetStep = 4;
68  faceCount = animation->num_animations / 2;
69  }
70  else if (myFacings == 4)
71  {
72  widgetStep = 2;
73  faceCount = animation->num_animations / 4;
74  }
75  else
76  {
77  widgetStep = 1;
78  faceCount = animation->num_animations / 8;
79  }
80 
81  face = facings == -1 ? 0 : 1;
82  while (widget < 8)
83  {
84  myWidgets[widget]->setVisible(true);
85  QList<int> faces;
86  for (faceCurrent = 0; faceCurrent < faceCount; faceCurrent++)
87  faces.append(animation->faces[face++]->number);
88  myWidgets[widget]->setAnimation(faces);
89 
90  widget += widgetStep;
91  }
92 }
93 
95 {
96  if (myAnimation == NULL)
97  return;
98 
99  for (int w = 0; w < myWidgets.size(); w++)
100  myWidgets[w]->step();
101 }
layout
Definition: main.cpp:84
face.h
AnimationControl.h
AnimationControl::myLastStep
int myLastStep
Definition: AnimationControl.h:43
AnimationWidget.h
make_face_from_files.facings
list facings
Definition: make_face_from_files.py:39
freearr_y
short freearr_y[SIZEOFFREE]
Definition: object.cpp:305
Face::number
uint16_t number
Definition: face.h:15
AnimationControl::myFacings
int myFacings
Definition: AnimationControl.h:44
Animations::facings
uint8_t facings
Definition: face.h:28
Animations::num_animations
uint8_t num_animations
Definition: face.h:27
Animations::faces
const Face ** faces
Definition: face.h:30
AnimationControl::step
void step()
Definition: AnimationControl.cpp:94
AnimationWidget
Definition: AnimationWidget.h:22
AnimationControl::display
void display(const Animations *animation, int facings=-1)
Definition: AnimationControl.cpp:49
AnimationControl::myWidgets
QList< AnimationWidget * > myWidgets
Definition: AnimationControl.h:47
Animations
Definition: face.h:25
dragon_attune.faces
dictionary faces
Definition: dragon_attune.py:31
AnimationControl::setAnimation
void setAnimation(const Animations *animation, int facings=-1)
Definition: AnimationControl.cpp:41
AnimationControl::myAnimation
const Animations * myAnimation
Definition: AnimationControl.h:41
AnimationControl::myTimer
QTimer * myTimer
Definition: AnimationControl.h:48
connect
Definition: connect.py:1
freearr_x
short freearr_x[SIZEOFFREE]
Definition: object.cpp:299
AnimationControl::myStep
int myStep
Definition: AnimationControl.h:42
AnimationControl::AnimationControl
AnimationControl(QWidget *parent)
Definition: AnimationControl.cpp:19