6 MAPSTRUCT
, BinEditor
, g_textures
;
9 TAddTextureArray
= Array of
15 TPanel
= Class (TObject
)
24 False: (Tex
: Cardinal);
25 True: (AnTex
: TAnimation
);
29 FCurTexture
: Integer; // Íîìåð òåêóùåé òåêñòóðû
35 SaveIt
: Boolean; // Ñîõðàíÿòü ïðè SaveState?
41 constructor Create(PanelRec
: TPanelRec_1
;
42 AddTextures
: TAddTextureArray
;
44 var Textures
: TLevelTextureArray
);
45 destructor Destroy(); override;
49 procedure SetFrame(Frame
: Integer; Count
: Byte);
50 procedure NextTexture(AnimLoop
: Byte = 0);
51 procedure SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
52 function GetTextureID(): Cardinal;
53 function GetTextureCount(): Integer;
55 procedure SaveState(var Mem
: TBinMemoryWriter
);
56 procedure LoadState(var Mem
: TBinMemoryReader
);
59 TPanelArray
= Array of TPanel
;
64 SysUtils
, g_basic
, g_map
, MAPDEF
, g_game
, e_graphics
,
65 g_console
, g_language
, e_log
;
68 PANEL_SIGNATURE
= $4C4E4150; // 'PANL'
72 constructor TPanel
.Create(PanelRec
: TPanelRec_1
;
73 AddTextures
: TAddTextureArray
;
75 var Textures
: TLevelTextureArray
);
81 Width
:= PanelRec
.Width
;
82 Height
:= PanelRec
.Height
;
90 PanelType
:= PanelRec
.PanelType
;
128 if ByteBool(PanelRec
.Flags
and PANEL_FLAG_HIDE
) then
130 SetLength(FTextureIDs
, 0);
134 // Ïàíåëè, íå èñïîëüçóþùèå òåêñòóðû:
135 if ByteBool(PanelType
and
140 PANEL_BLOCKMON
)) then
142 SetLength(FTextureIDs
, 0);
147 // Åñëè ýòî æèäêîñòü áåç òåêñòóðû - ñïåöòåêñòóðó:
148 if WordBool(PanelType
and (PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
)) and
149 (not ByteBool(PanelRec
.Flags
and PANEL_FLAG_WATERTEXTURES
)) then
151 SetLength(FTextureIDs
, 1);
152 FTextureIDs
[0].Anim
:= False;
154 case PanelRec
.PanelType
of
156 FTextureIDs
[0].Tex
:= TEXTURE_SPECIAL_WATER
;
158 FTextureIDs
[0].Tex
:= TEXTURE_SPECIAL_ACID1
;
160 FTextureIDs
[0].Tex
:= TEXTURE_SPECIAL_ACID2
;
167 SetLength(FTextureIDs
, Length(AddTextures
));
172 if CurTex
>= Length(FTextureIDs
) then
173 FCurTexture
:= Length(FTextureIDs
) - 1
175 FCurTexture
:= CurTex
;
177 for i
:= 0 to Length(FTextureIDs
)-1 do
179 FTextureIDs
[i
].Anim
:= AddTextures
[i
].Anim
;
180 if FTextureIDs
[i
].Anim
then
181 begin // Àíèìèðîâàííàÿ òåêñòóðà
182 FTextureIDs
[i
].AnTex
:=
183 TAnimation
.Create(Textures
[AddTextures
[i
].Texture
].FramesID
,
184 True, Textures
[AddTextures
[i
].Texture
].Speed
);
185 FTextureIDs
[i
].AnTex
.Blending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
186 FTextureIDs
[i
].AnTex
.Alpha
:= PanelRec
.Alpha
;
190 begin // Îáû÷íàÿ òåêñòóðà
191 FTextureIDs
[i
].Tex
:= Textures
[AddTextures
[i
].Texture
].TextureID
;
195 // Òåêñòóð íåñêîëüêî - íóæíî ñîõðàíÿòü òåêóùóþ:
196 if Length(FTextureIDs
) > 1 then
199 // Åñëè íå ñïåöòåêñòóðà, òî çàäàåì ðàçìåðû:
200 if PanelRec
.TextureNum
> High(Textures
) then
202 e_WriteLog(Format('WTF?! PanelRec.TextureNum is out of limits! (%d : %d)', [PanelRec
.TextureNum
, High(Textures
)]), MSG_FATALERROR
);
204 else if not g_Map_IsSpecialTexture(Textures
[PanelRec
.TextureNum
].TextureName
) then
206 FTextureWidth
:= Textures
[PanelRec
.TextureNum
].Width
;
207 FTextureHeight
:= Textures
[PanelRec
.TextureNum
].Height
;
208 FAlpha
:= PanelRec
.Alpha
;
209 FBlending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
213 destructor TPanel
.Destroy();
217 for i
:= 0 to High(FTextureIDs
) do
218 if FTextureIDs
[i
].Anim
then
219 FTextureIDs
[i
].AnTex
.Free();
220 SetLength(FTextureIDs
, 0);
225 procedure TPanel
.Draw();
231 if Enabled
and (FCurTexture
>= 0) and
232 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) and
233 g_Collide(X
, Y
, Width
, Height
,
234 sX
, sY
, sWidth
, sHeight
) then
236 if FTextureIDs
[FCurTexture
].Anim
then
237 begin // Àíèìèðîâàííàÿ òåêñòóðà
238 if FTextureIDs
[FCurTexture
].AnTex
= nil then
241 for xx
:= 0 to (Width
div FTextureWidth
)-1 do
242 for yy
:= 0 to (Height
div FTextureHeight
)-1 do
243 FTextureIDs
[FCurTexture
].AnTex
.Draw(
244 X
+ xx
*FTextureWidth
,
245 Y
+ yy
*FTextureHeight
, M_NONE
);
248 begin // Îáû÷íàÿ òåêñòóðà
249 case FTextureIDs
[FCurTexture
].Tex
of
250 TEXTURE_SPECIAL_WATER
:
251 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
252 0, 0, 255, 0, B_FILTER
);
253 TEXTURE_SPECIAL_ACID1
:
254 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
255 0, 128, 0, 0, B_FILTER
);
256 TEXTURE_SPECIAL_ACID2
:
257 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
258 128, 0, 0, 0, B_FILTER
);
260 if g_Texture_Get('NOTEXTURE', NoTextureID
) then
262 e_GetTextureSize(NoTextureID
, @NW
, @NH
);
263 e_DrawFill(NoTextureID
, X
, Y
, Width
div NW
, Height
div NH
,
267 xx
:= X
+ (Width
div 2);
268 yy
:= Y
+ (Height
div 2);
269 e_DrawFillQuad(X
, Y
, xx
, yy
,
271 e_DrawFillQuad(xx
, Y
, X
+Width
-1, yy
,
273 e_DrawFillQuad(X
, yy
, xx
, Y
+Height
-1,
275 e_DrawFillQuad(xx
, yy
, X
+Width
-1, Y
+Height
-1,
280 e_DrawFill(FTextureIDs
[FCurTexture
].Tex
, X
, Y
,
281 Width
div FTextureWidth
,
282 Height
div FTextureHeight
,
283 FAlpha
, True, FBlending
);
289 procedure TPanel
.Update();
291 if Enabled
and (FCurTexture
>= 0) and
292 (FTextureIDs
[FCurTexture
].Anim
) and
293 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
294 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
296 FTextureIDs
[FCurTexture
].AnTex
.Update();
297 FCurFrame
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
;
298 FCurFrameCount
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
;
302 procedure TPanel
.SetFrame(Frame
: Integer; Count
: Byte);
304 function ClampInt(X
, A
, B
: Integer): Integer;
307 if X
< A
then Result
:= A
else if X
> B
then Result
:= B
;
311 if Enabled
and (FCurTexture
>= 0) and
312 (FTextureIDs
[FCurTexture
].Anim
) and
313 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
314 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
316 FCurFrame
:= ClampInt(Frame
, 0, FTextureIDs
[FCurTexture
].AnTex
.TotalFrames
);
317 FCurFrameCount
:= Count
;
318 FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
:= FCurFrame
;
319 FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
:= FCurFrameCount
;
323 procedure TPanel
.NextTexture(AnimLoop
: Byte = 0);
325 Assert(FCurTexture
>= -1, 'FCurTexture < -1');
328 if Length(FTextureIDs
) = 0 then
331 // Òîëüêî îäíà òåêñòóðà:
332 if Length(FTextureIDs
) = 1 then
334 if FCurTexture
= 0 then
340 // Áîëüøå îäíîé òåêñòóðû:
344 // Ñëåäóþùåé íåò - âîçâðàò ê íà÷àëó:
345 if FCurTexture
>= Length(FTextureIDs
) then
349 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
350 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
352 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
354 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
359 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
362 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
364 FTextureIDs
[FCurTexture
].AnTex
.Reset();
367 LastAnimLoop
:= AnimLoop
;
370 procedure TPanel
.SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
373 if Length(FTextureIDs
) = 0 then
376 // Òîëüêî îäíà òåêñòóðà:
377 if Length(FTextureIDs
) = 1 then
379 if (ID
= 0) or (ID
= -1) then
383 // Áîëüøå îäíîé òåêñòóðû:
385 if (ID
>= -1) and (ID
<= High(FTextureIDs
)) then
389 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
390 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
392 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
394 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
399 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
402 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
404 FTextureIDs
[FCurTexture
].AnTex
.Reset();
407 LastAnimLoop
:= AnimLoop
;
410 function TPanel
.GetTextureID(): DWORD
;
412 Result
:= TEXTURE_NONE
;
414 if (FCurTexture
>= 0) then
416 if FTextureIDs
[FCurTexture
].Anim
then
417 Result
:= FTextureIDs
[FCurTexture
].AnTex
.FramesID
419 Result
:= FTextureIDs
[FCurTexture
].Tex
;
423 function TPanel
.GetTextureCount(): Integer;
425 Result
:= Length(FTextureIDs
);
426 if Enabled
and (FCurTexture
>= 0) then
427 if (FTextureIDs
[FCurTexture
].Anim
) and
428 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
429 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
430 Result
:= Result
+ 100;
433 procedure TPanel
.SaveState(Var Mem
: TBinMemoryWriter
);
438 if (not SaveIt
) or (Mem
= nil) then
442 sig
:= PANEL_SIGNATURE
; // 'PANL'
444 // Îòêðûòà/çàêðûòà, åñëè äâåðü:
445 Mem
.WriteBoolean(Enabled
);
446 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò:
447 Mem
.WriteByte(LiftType
);
448 // Íîìåð òåêóùåé òåêñòóðû:
449 Mem
.WriteInt(FCurTexture
);
450 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà:
451 if (FCurTexture
>= 0) and (FTextureIDs
[FCurTexture
].Anim
) then
453 Assert(FTextureIDs
[FCurTexture
].AnTex
<> nil,
454 'TPanel.SaveState: No animation object');
459 Mem
.WriteBoolean(anim
);
460 // Åñëè äà - ñîõðàíÿåì àíèìàöèþ:
462 FTextureIDs
[FCurTexture
].AnTex
.SaveState(Mem
);
465 procedure TPanel
.LoadState(var Mem
: TBinMemoryReader
);
470 if (not SaveIt
) or (Mem
= nil) then
475 if sig
<> PANEL_SIGNATURE
then // 'PANL'
477 raise EBinSizeError
.Create('TPanel.LoadState: Wrong Panel Signature');
479 // Îòêðûòà/çàêðûòà, åñëè äâåðü:
480 Mem
.ReadBoolean(Enabled
);
481 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò:
482 Mem
.ReadByte(LiftType
);
483 // Íîìåð òåêóùåé òåêñòóðû:
484 Mem
.ReadInt(FCurTexture
);
485 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà:
486 Mem
.ReadBoolean(anim
);
487 // Åñëè äà - çàãðóæàåì àíèìàöèþ:
490 Assert((FCurTexture
>= 0) and
491 (FTextureIDs
[FCurTexture
].Anim
) and
492 (FTextureIDs
[FCurTexture
].AnTex
<> nil),
493 'TPanel.LoadState: No animation object');
494 FTextureIDs
[FCurTexture
].AnTex
.LoadState(Mem
);