-
Notifications
You must be signed in to change notification settings - Fork 0
/
HudPicHolder.es
239 lines (204 loc) · 5.63 KB
/
HudPicHolder.es
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
/* Copyright (c) 2002-2012 Croteam Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as published by
the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
241
%{
#include "StdH.h"
#include "Entities/WorldSettingsController.h"
#include "Entities/BackgroundViewer.h"
%}
%{
BOOL _bDataLoaded = FALSE;
BOOL _bDataError = FALSE;
CTextureObject _toTexture;
%}
class CHudPicHolder: CRationalEntity {
name "HudPicHolder";
thumbnail "Thumbnails\\HudPicHolder.tbn";
features "IsTargetable", "HasName", "IsImportant";
properties:
1 CTString m_strName "Name" 'N' = "Hud pic holder",
2 CTString m_strDescription = "",
3 CTFileName m_fnmPicture "Picture file" 'P' = CTString(""),
4 FLOAT m_tmFadeInStart = 1e6,
5 FLOAT m_tmFadeOutStart = 1e6,
6 FLOAT m_tmFadeInLen "Fade in time" 'I' = 0.5f,
7 FLOAT m_tmFadeOutLen "Fade out time" 'O' = 0.5f,
8 FLOAT m_tmAutoFadeOut "Auto fade out time" 'A' = -1.0f,
9 FLOAT m_fYRatio "Vertical position ratio" 'Y' = 0.5f,
10 FLOAT m_fXRatio "Horizontal position ratio" 'X' = 0.5f,
11 FLOAT m_fPictureStretch "Picture stretch" 'S' = 1.0f,
components:
1 model MODEL_MARKER "Models\\Editor\\MessageHolder.mdl",
2 texture TEXTURE_MARKER "Models\\Editor\\MessageHolder.tex"
functions:
const CTString &GetDescription(void) const {
((CTString&)m_strDescription).PrintF("%s", m_fnmPicture.FileName());
return m_strDescription;
}
BOOL ReloadData(void)
{
_bDataError = FALSE;
if (!Picture_On(m_fnmPicture))
{
Picture_Off();
return FALSE;
}
return TRUE;
}
BOOL LoadOneFile(const CTFileName &fnm)
{
if(fnm=="") { return FALSE; }
try
{
_toTexture.SetData_t(fnm);
return TRUE;
}
catch (char *strError)
{
CPrintF("%s\n", strError);
return FALSE;
}
}
// turn text on
BOOL Picture_On(CTFileName fnPic)
{
return LoadOneFile(fnPic);
}
// turn text off
void Picture_Off(void)
{
_toTexture.SetData(NULL);
}
// render credits to given drawport
FLOAT HudPic_Render(CHudPicHolder *penThis, CDrawPort *pdp)
{
if (_bDataError) { return 0; }
if (!_bDataLoaded) {
if (!ReloadData()) {
_bDataError = TRUE;
return 0;
}
_bDataLoaded = TRUE;
return 1;
}
FLOAT fNow=_pTimer->CurrentTick();
if( fNow<m_tmFadeInStart) { return 0; }
if( fNow>m_tmFadeOutStart+m_tmFadeOutLen) { return 0;}
CDrawPort *pdpCurr=pdp;
pdp->Unlock();
pdpCurr->Lock();
FLOAT fRatio=1.0f;
if( fNow>m_tmFadeOutStart)
{
fRatio=CalculateRatio(fNow, m_tmFadeOutStart, m_tmFadeOutStart+m_tmFadeOutLen, 0, 1);
}
if( fNow<m_tmFadeInStart+m_tmFadeInLen)
{
fRatio=CalculateRatio(fNow, m_tmFadeInStart, m_tmFadeInStart+m_tmFadeInLen, 1, 0);
}
UBYTE ubA=ClampUp(UBYTE(fRatio*255.0f), UBYTE(255));
CTextureData *ptd=(CTextureData *)_toTexture.GetData();
FLOAT fResScale = (FLOAT)pdpCurr->GetHeight() / 480.0f;
const MEX mexTexW = ptd->GetWidth();
const MEX mexTexH = ptd->GetHeight();
FLOAT fPicRatioW, fPicRatioH;
if( mexTexW > mexTexH) {
fPicRatioW = mexTexW/mexTexH;
fPicRatioH = 1.0f;
} else {
fPicRatioW = 1.0f;
fPicRatioH = mexTexH/mexTexW;
}
PIX picW = 128*m_fPictureStretch*fResScale*fPicRatioW;
PIX picH = 128*m_fPictureStretch*fResScale*fPicRatioH;
FLOAT fXCenter = m_fXRatio * pdpCurr->GetWidth();
FLOAT fYCenter = m_fYRatio * pdpCurr->GetHeight();
PIXaabbox2D boxScr=PIXaabbox2D(
PIX2D(fXCenter-picW/2, fYCenter-picH/2),
PIX2D(fXCenter+picW/2, fYCenter+picH/2) );
pdpCurr->PutTexture(&_toTexture, boxScr, C_WHITE|ubA);
pdpCurr->Unlock();
pdp->Lock();
return 1;
}
procedures:
WaitAndFadeOut(EVoid)
{
autowait( m_tmAutoFadeOut);
jump ApplyFadeOut();
}
ApplyFadeOut(EVoid)
{
m_tmFadeOutStart = _pTimer->CurrentTick();
CWorldSettingsController *pwsc = GetWSC(this);
if( pwsc!=NULL)
{
autowait(m_tmFadeOutLen);
CWorldSettingsController *pwsc = GetWSC(this);
ETextFX etfx;
etfx.bStart=FALSE;
etfx.penSender=this;
pwsc->SendEvent(etfx);
}
return EReturn();
}
Main()
{
InitAsEditorModel();
SetPhysicsFlags(EPF_MODEL_IMMATERIAL);
SetCollisionFlags(ECF_IMMATERIAL);
// set appearance
SetModel(MODEL_MARKER);
SetModelMainTexture(TEXTURE_MARKER);
autowait(0.05f);
if( !Picture_On(m_fnmPicture))
{
Picture_Off();
return;
}
_bDataError = FALSE;
wait() {
on (EBegin):
{
resume;
}
on (EStart eStart):
{
CWorldSettingsController *pwsc = GetWSC(this);
if( pwsc!=NULL)
{
m_tmFadeInStart = _pTimer->CurrentTick();
EHudPicFX etfx;
etfx.bStart=TRUE;
etfx.penSender=this;
pwsc->SendEvent(etfx);
if( m_tmAutoFadeOut!=-1)
{
call WaitAndFadeOut();
}
}
resume;
}
on (EStop eStop):
{
call ApplyFadeOut();
resume;
}
on (EReturn):
{
resume;
}
}
Picture_Off();
return;
}
};