1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#ifndef ANIMATIONCONTROLLER_H
#define ANIMATIONCONTROLLER_H
#ifdef _WIN32
#pragma once
#endif
#include <vgui_controls/Panel.h>
#include <vgui_controls/PHandle.h>
#include "tier1/utlsymbol.h"
#include "tier1/utlvector.h"
namespace vgui
{
//-----------------------------------------------------------------------------
// Purpose: Handles controlling panel animation
// It is never visible, but needs to be a panel so that can receive messages
//-----------------------------------------------------------------------------
class AnimationController : public Panel
{
DECLARE_CLASS_SIMPLE( AnimationController, Panel );
public:
AnimationController(Panel *parent);
~AnimationController();
// sets which script file to use
bool SetScriptFile( VPANEL sizingPanel, const char *fileName, bool wipeAll = false );
// reloads the currently set script file
void ReloadScriptFile();
// runs a frame of animation (time is passed in so slow motion, etc. works)
void UpdateAnimations( float curtime );
int GetNumActiveAnimations( void ) { return m_ActiveAnimations.Count(); }
// plays all animations to completion instantly
void RunAllAnimationsToCompletion();
// stops all animations
void CancelAllAnimations();
// starts an animation sequence script
bool StartAnimationSequence(const char *sequenceName);
bool StartAnimationSequence(Panel *pWithinParent, const char *sequenceName);
bool StopAnimationSequence( Panel *pWithinParent, const char *sequenceName );
void CancelAnimationsForPanel( Panel *pWithinParent );
// gets the length of an animation sequence, in seconds
float GetAnimationSequenceLength(const char *sequenceName);
// sets that the script file should be reloaded each time a script is ran
// used for development
void SetAutoReloadScript(bool state);
enum Interpolators_e
{
INTERPOLATOR_LINEAR,
INTERPOLATOR_ACCEL,
INTERPOLATOR_DEACCEL,
INTERPOLATOR_PULSE,
INTERPOLATOR_FLICKER,
INTERPOLATOR_SIMPLESPLINE, // ease in / out
INTERPOLATOR_BOUNCE, // gravitational bounce
};
// runs the specific animation command (doesn't use script file at all)
void RunAnimationCommand(vgui::Panel *panel, const char *variable, float targetValue, float startDelaySeconds, float durationSeconds, Interpolators_e interpolator, float animParameter = 0 );
void RunAnimationCommand(vgui::Panel *panel, const char *variable, Color targetValue, float startDelaySeconds, float durationSeconds, Interpolators_e interpolator, float animParameter = 0 );
private:
bool UpdateScreenSize();
bool LoadScriptFile(const char *fileName);
bool ParseScriptFile(char *pMem, int length);
void UpdatePostedMessages(bool bRunToCompletion);
void UpdateActiveAnimations(bool bRunToCompletion);
bool m_bAutoReloadScript;
float m_flCurrentTime;
enum AnimCommandType_e
{
CMD_ANIMATE,
CMD_RUNEVENT,
CMD_STOPEVENT,
CMD_STOPANIMATION,
CMD_STOPPANELANIMATIONS,
CMD_SETFONT,
CMD_SETTEXTURE,
CMD_SETSTRING,
CMD_RUNEVENTCHILD,
CMD_FIRECOMMAND,
CMD_SETVISIBLE,
};
enum RelativeAlignment
{
a_northwest = 0,
a_north,
a_northeast,
a_west,
a_center,
a_east,
a_southwest,
a_south,
a_southeast,
};
struct RelativeAlignmentLookup
{
RelativeAlignment align;
char const *name;
};
// a single animatable value
// some var types use 1, 2, 3 or all 4 of the values
struct Value_t
{
float a, b, c, d;
};
struct AnimAlign_t
{
// For Position, Xpos, YPos
bool relativePosition;
UtlSymId_t alignPanel;
RelativeAlignment alignment;
};
// info for the animate command
struct AnimCmdAnimate_t
{
UtlSymId_t panel;
UtlSymId_t variable;
Value_t target;
int interpolationFunction;
float interpolationParameter;
float startTime;
float duration;
AnimAlign_t align;
};
// info for the run event command
struct AnimCmdEvent_t
{
UtlSymId_t event;
UtlSymId_t variable;
UtlSymId_t variable2;
float timeDelay;
};
// holds a single command from an animation sequence
struct AnimCommand_t
{
AnimCommandType_e commandType;
union
{
AnimCmdAnimate_t animate;
AnimCmdEvent_t runEvent;
} cmdData;
};
// holds a full sequence
struct AnimSequence_t
{
UtlSymId_t name;
float duration;
CUtlVector<AnimCommand_t> cmdList;
};
// holds the list of sequences
CUtlVector<AnimSequence_t> m_Sequences;
// list of active animations
struct ActiveAnimation_t
{
PHandle panel;
UtlSymId_t seqName; // the sequence this belongs to
UtlSymId_t variable;
bool started;
Value_t startValue;
Value_t endValue;
int interpolator;
float interpolatorParam;
float startTime;
float endTime;
AnimAlign_t align;
};
CUtlVector<ActiveAnimation_t> m_ActiveAnimations;
// posted messages
struct PostedMessage_t
{
AnimCommandType_e commandType;
UtlSymId_t seqName;
UtlSymId_t event;
UtlSymId_t variable;
UtlSymId_t variable2;
float startTime;
PHandle parent;
};
CUtlVector<PostedMessage_t> m_PostedMessages;
struct RanEvent_t
{
UtlSymId_t event;
Panel *pParent;
bool operator==( const RanEvent_t &other ) const
{
return ( event == other.event && pParent == other.pParent );
}
};
// variable names
UtlSymId_t m_sPosition, m_sSize, m_sFgColor, m_sBgColor;
UtlSymId_t m_sXPos, m_sYPos, m_sWide, m_sTall;
UtlSymId_t m_sModelPos;
// file name
CUtlVector<UtlSymId_t> m_ScriptFileNames;
// runs a single line of the script
void ExecAnimationCommand(UtlSymId_t seqName, AnimCommand_t &animCommand, Panel *pWithinParent);
// removes all commands belonging to a script
void RemoveQueuedAnimationCommands(UtlSymId_t seqName, vgui::Panel *panel = NULL);
// removes an existing instance of a command
void RemoveQueuedAnimationByType(vgui::Panel *panel, UtlSymId_t variable, UtlSymId_t sequenceToIgnore);
// handlers
void StartCmd_Animate(UtlSymId_t seqName, AnimCmdAnimate_t &cmd, Panel *pWithinParent);
void StartCmd_Animate(Panel *panel, UtlSymId_t seqName, AnimCmdAnimate_t &cmd);
void RunCmd_RunEvent(PostedMessage_t &msg);
void RunCmd_StopEvent(PostedMessage_t &msg);
void RunCmd_StopPanelAnimations(PostedMessage_t &msg);
void RunCmd_StopAnimation(PostedMessage_t &msg);
void RunCmd_SetFont(PostedMessage_t &msg);
void RunCmd_SetTexture(PostedMessage_t &msg);
void RunCmd_SetString(PostedMessage_t &msg);
// value access
Value_t GetValue(ActiveAnimation_t& anim, Panel *panel, UtlSymId_t var);
void SetValue(ActiveAnimation_t& anim, Panel *panel, UtlSymId_t var, Value_t &value);
// interpolation
Value_t GetInterpolatedValue(int interpolator, float interpolatorParam, float currentTime, float startTime, float endTime, Value_t &startValue, Value_t &endValue);
void SetupPosition( AnimCmdAnimate_t& cmd, float *output, char const *psz, int screendimension );
static RelativeAlignment LookupAlignment( char const *token );
static RelativeAlignmentLookup g_AlignmentLookup[];
int GetRelativeOffset( AnimAlign_t& cmd, bool xcoord );
VPANEL m_hSizePanel;
int m_nScreenBounds[ 4 ];
};
// singleton accessor for use only by other vgui_controls
extern AnimationController *GetAnimationController();
} // namespace vgui
#endif // ANIMATIONCONTROLLER_H
|