forked from SwagSoftware/Kisak-Strike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPanelAnimationVar.h
161 lines (146 loc) · 5.16 KB
/
PanelAnimationVar.h
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
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#ifndef PANELANIMATIONVAR_H
#define PANELANIMATIONVAR_H
#ifdef _WIN32
#pragma once
#endif
#include "tier1/utlvector.h"
#include <vgui_controls/Panel.h>
#define DECLARE_PANELANIMATION( className ) \
static void AddToAnimationMap( char const *scriptname, char const *type, char const *var, \
char const *defaultvalue, bool array, PANELLOOKUPFUNC func ) \
{ \
PanelAnimationMap *map = FindOrAddPanelAnimationMap( GetPanelClassName() ); \
\
PanelAnimationMapEntry entry; \
entry.m_pszScriptName = scriptname; \
entry.m_pszVariable = var; \
entry.m_pszType = type; \
entry.m_pszDefaultValue = defaultvalue; \
entry.m_pfnLookup = func; \
entry.m_bArray = array; \
\
map->entries.AddToTail( entry ); \
} \
\
static void ChainToAnimationMap( void ) \
{ \
static bool chained = false; \
if ( chained ) \
return; \
chained = true; \
PanelAnimationMap *map = FindOrAddPanelAnimationMap( GetPanelClassName() ); \
map->pfnClassName = GetPanelClassName; \
if ( map && GetPanelBaseClassName() && GetPanelBaseClassName()[0] ) \
{ \
map->baseMap = FindOrAddPanelAnimationMap( GetPanelBaseClassName() ); \
} \
} \
\
class className##_Register; \
friend class className##_Register; \
class className##_Register \
{ \
public: \
className##_Register() \
{ \
className::ChainToAnimationMap(); \
} \
}; \
className##_Register m_RegisterAnimationClass; \
\
virtual PanelAnimationMap *GetAnimMap() \
{ \
return FindOrAddPanelAnimationMap( GetPanelClassName() ); \
}
typedef void *( *PANELLOOKUPFUNC )( vgui::Panel *panel );
// Use this macro to define a variable which hudanimations.txt and hudlayout.res scripts can access
#define CPanelAnimationVarAliasType( type, name, scriptname, defaultvalue, typealias ) \
class PanelAnimationVar_##name; \
friend class PanelAnimationVar_##name; \
static void *GetVar_##name( vgui::Panel *panel ) \
{ \
return &(( ThisClass *)panel)->name; \
} \
class PanelAnimationVar_##name \
{ \
public: \
static void InitVar() \
{ \
static bool bAdded = false; \
if ( !bAdded ) \
{ \
bAdded = true; \
AddToAnimationMap( scriptname, typealias, #name, defaultvalue, false, ThisClass::GetVar_##name ); \
} \
} \
PanelAnimationVar_##name() \
{ \
PanelAnimationVar_##name::InitVar(); \
} \
}; \
PanelAnimationVar_##name m_##name##_register; \
type name;
#define CPanelAnimationVar( type, name, scriptname, defaultvalue ) \
CPanelAnimationVarAliasType( type, name, scriptname, defaultvalue, #type )
// Use this macro to define a variable which hudanimations.txt and hudlayout.res scripts can access
#define CPanelAnimationStringVarAliasType( count, name, scriptname, defaultvalue, typealias ) \
class PanelAnimationVar_##name; \
friend class PanelAnimationVar_##name; \
static void *GetVar_##name( vgui::Panel *panel ) \
{ \
return &(( ThisClass *)panel)->name; \
} \
class PanelAnimationVar_##name \
{ \
public: \
static void InitVar() \
{ \
static bool bAdded = false; \
if ( !bAdded ) \
{ \
bAdded = true; \
AddToAnimationMap( scriptname, typealias, #name, defaultvalue, true, ThisClass::GetVar_##name ); \
} \
} \
PanelAnimationVar_##name() \
{ \
PanelAnimationVar_##name::InitVar(); \
} \
}; \
PanelAnimationVar_##name m_##name##_register; \
char name[ count ];
#define CPanelAnimationStringVar( count, name, scriptname, defaultvalue ) \
CPanelAnimationStringVarAliasType( count, name, scriptname, defaultvalue, "string" )
struct PanelAnimationMapEntry
{
char const *name() { return m_pszScriptName; }
char const *type() { return m_pszType; }
char const *defaultvalue() { return m_pszDefaultValue; }
bool isarray() { return m_bArray; }
char const *m_pszScriptName;
char const *m_pszVariable;
char const *m_pszType;
char const *m_pszDefaultValue;
bool m_bArray;
PANELLOOKUPFUNC m_pfnLookup;
};
struct PanelAnimationMap
{
PanelAnimationMap()
{
baseMap = NULL;
pfnClassName = NULL;
}
CUtlVector< PanelAnimationMapEntry > entries;
PanelAnimationMap *baseMap;
char const *(*pfnClassName)( void );
};
PanelAnimationMap *FindPanelAnimationMap( char const *className );
PanelAnimationMap *FindOrAddPanelAnimationMap( char const *className );
void PanelAnimationDumpVars( char const *className );
#endif // PANELANIMATIONVAR_H