-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlifebar.cpp
More file actions
134 lines (115 loc) · 3.89 KB
/
lifebar.cpp
File metadata and controls
134 lines (115 loc) · 3.89 KB
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
#include "prism/lifebar.h"
#include "prism/mugenanimationhandler.h"
namespace prism {
class LifeBar
{
public:
MugenAnimationHandlerElement* mFGElement;
MugenAnimationHandlerElement* mBGElement;
int mCurrentValue;
int mMaxValue;
int mFullSize;
LifeBarType mType;
LifeBar(const Vector3D& tPosition, MugenSpriteFile& mSprites, MugenAnimations& mAnimations, int tFGAnimNo, int tBGAnimNo, LifeBarType tType, int tStartValue, int tMaxValue, int tFullSize, const Vector3D& tFGOffset)
{
mFGElement = addMugenAnimation(getMugenAnimation(&mAnimations, tFGAnimNo), &mSprites, tPosition + tFGOffset);
mBGElement = addMugenAnimation(getMugenAnimation(&mAnimations, tBGAnimNo), &mSprites, tPosition);
mCurrentValue = tStartValue;
mMaxValue = tMaxValue;
mFullSize = tFullSize;
mType = tType;
updateInternal();
}
LifeBar() {}
void unload()
{
removeMugenAnimation(mFGElement);
removeMugenAnimation(mBGElement);
}
void updateInternal()
{
double percentage = ((double)mCurrentValue) / mMaxValue;
if (mType == LifeBarType::STRETCH)
{
setMugenAnimationDrawScale(mFGElement, Vector2D(percentage * mFullSize, 1));
}
else if (mType == LifeBarType::WIDTH)
{
setMugenAnimationRectangleWidth(mFGElement, int(percentage * mFullSize));
}
}
void updateByPercentage(double tPercentage)
{
mCurrentValue = (int)(tPercentage * mMaxValue);
updateInternal();
}
void updateByValue(int tValue)
{
mCurrentValue = tValue;
updateInternal();
}
void setVisibility(int tIsVisible)
{
setMugenAnimationVisibility(mFGElement, tIsVisible);
setMugenAnimationVisibility(mBGElement, tIsVisible);
}
};
static struct
{
std::map<int, LifeBar> mLifeBars;
} gLifeBarHandlerData;
class LifeBarHandler {
public:
LifeBarHandler()
{
gLifeBarHandlerData.mLifeBars.clear();
}
~LifeBarHandler()
{
gLifeBarHandlerData.mLifeBars.clear();
}
void update()
{
}
};
EXPORT_ACTOR_CLASS(LifeBarHandler);
int addLifeBar(const Vector3D& tPosition, MugenSpriteFile& mSprites, MugenAnimations& mAnimations, int tFGAnimNo, int tBGAnimNo, LifeBarType tType, int tStartValue, int tMaxValue, int tFullSize, const Vector3D& tFGOffset)
{
int id = stl_int_map_get_id();
gLifeBarHandlerData.mLifeBars[id] = LifeBar(tPosition, mSprites, mAnimations, tFGAnimNo, tBGAnimNo, tType, tStartValue, tMaxValue, tFullSize, tFGOffset);
return id;
}
void removeLifeBar(int tID)
{
gLifeBarHandlerData.mLifeBars[tID].unload();
gLifeBarHandlerData.mLifeBars.erase(tID);
}
int getLifeBarPercentage(int tID)
{
return gLifeBarHandlerData.mLifeBars[tID].mCurrentValue / gLifeBarHandlerData.mLifeBars[tID].mMaxValue;
}
void setLifeBarPercentage(int tID, double tPercentage)
{
gLifeBarHandlerData.mLifeBars[tID].updateByPercentage(tPercentage);
}
int getLifeBarValue(int tID)
{
return gLifeBarHandlerData.mLifeBars[tID].mCurrentValue;
}
void setLifeBarValue(int tID, int tValue)
{
gLifeBarHandlerData.mLifeBars[tID].updateByValue(tValue);
}
void setLifeBarVisibility(int tID, int tIsVisible)
{
gLifeBarHandlerData.mLifeBars[tID].setVisibility(tIsVisible);
}
void removeAllLifebars()
{
for (auto& lifeBar : gLifeBarHandlerData.mLifeBars)
{
lifeBar.second.unload();
}
gLifeBarHandlerData.mLifeBars.clear();
}
}