1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 MAPSTRUCT
, BinEditor
, g_textures
;
25 TAddTextureArray
= Array of
31 TPanel
= Class (TObject
)
40 False: (Tex
: Cardinal);
41 True: (AnTex
: TAnimation
);
45 FCurTexture
: Integer; // Íîìåð òåêóùåé òåêñòóðû
51 SaveIt
: Boolean; // Ñîõðàíÿòü ïðè SaveState?
58 constructor Create(PanelRec
: TPanelRec_1
;
59 AddTextures
: TAddTextureArray
;
61 var Textures
: TLevelTextureArray
);
62 destructor Destroy(); override;
66 procedure SetFrame(Frame
: Integer; Count
: Byte);
67 procedure NextTexture(AnimLoop
: Byte = 0);
68 procedure SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
69 function GetTextureID(): Cardinal;
70 function GetTextureCount(): Integer;
72 procedure SaveState(var Mem
: TBinMemoryWriter
);
73 procedure LoadState(var Mem
: TBinMemoryReader
);
77 TPanelArray
= Array of TPanel
;
82 SysUtils
, g_basic
, g_map
, MAPDEF
, g_game
, e_graphics
,
83 g_console
, g_language
, e_log
;
86 PANEL_SIGNATURE
= $4C4E4150; // 'PANL'
90 constructor TPanel
.Create(PanelRec
: TPanelRec_1
;
91 AddTextures
: TAddTextureArray
;
93 var Textures
: TLevelTextureArray
);
99 Width
:= PanelRec
.Width
;
100 Height
:= PanelRec
.Height
;
109 PanelType
:= PanelRec
.PanelType
;
147 if ByteBool(PanelRec
.Flags
and PANEL_FLAG_HIDE
) then
149 SetLength(FTextureIDs
, 0);
153 // Ïàíåëè, íå èñïîëüçóþùèå òåêñòóðû:
154 if ByteBool(PanelType
and
159 PANEL_BLOCKMON
)) then
161 SetLength(FTextureIDs
, 0);
166 // Åñëè ýòî æèäêîñòü áåç òåêñòóðû - ñïåöòåêñòóðó:
167 if WordBool(PanelType
and (PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
)) and
168 (not ByteBool(PanelRec
.Flags
and PANEL_FLAG_WATERTEXTURES
)) then
170 SetLength(FTextureIDs
, 1);
171 FTextureIDs
[0].Anim
:= False;
173 case PanelRec
.PanelType
of
175 FTextureIDs
[0].Tex
:= TEXTURE_SPECIAL_WATER
;
177 FTextureIDs
[0].Tex
:= TEXTURE_SPECIAL_ACID1
;
179 FTextureIDs
[0].Tex
:= TEXTURE_SPECIAL_ACID2
;
186 SetLength(FTextureIDs
, Length(AddTextures
));
191 if CurTex
>= Length(FTextureIDs
) then
192 FCurTexture
:= Length(FTextureIDs
) - 1
194 FCurTexture
:= CurTex
;
196 for i
:= 0 to Length(FTextureIDs
)-1 do
198 FTextureIDs
[i
].Anim
:= AddTextures
[i
].Anim
;
199 if FTextureIDs
[i
].Anim
then
200 begin // Àíèìèðîâàííàÿ òåêñòóðà
201 FTextureIDs
[i
].AnTex
:=
202 TAnimation
.Create(Textures
[AddTextures
[i
].Texture
].FramesID
,
203 True, Textures
[AddTextures
[i
].Texture
].Speed
);
204 FTextureIDs
[i
].AnTex
.Blending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
205 FTextureIDs
[i
].AnTex
.Alpha
:= PanelRec
.Alpha
;
209 begin // Îáû÷íàÿ òåêñòóðà
210 FTextureIDs
[i
].Tex
:= Textures
[AddTextures
[i
].Texture
].TextureID
;
214 // Òåêñòóð íåñêîëüêî - íóæíî ñîõðàíÿòü òåêóùóþ:
215 if Length(FTextureIDs
) > 1 then
218 // Åñëè íå ñïåöòåêñòóðà, òî çàäàåì ðàçìåðû:
219 if PanelRec
.TextureNum
> High(Textures
) then
221 e_WriteLog(Format('WTF?! PanelRec.TextureNum is out of limits! (%d : %d)', [PanelRec
.TextureNum
, High(Textures
)]), MSG_FATALERROR
);
225 FBlending
:= ByteBool(0);
227 else if not g_Map_IsSpecialTexture(Textures
[PanelRec
.TextureNum
].TextureName
) then
229 FTextureWidth
:= Textures
[PanelRec
.TextureNum
].Width
;
230 FTextureHeight
:= Textures
[PanelRec
.TextureNum
].Height
;
231 FAlpha
:= PanelRec
.Alpha
;
232 FBlending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
236 destructor TPanel
.Destroy();
240 for i
:= 0 to High(FTextureIDs
) do
241 if FTextureIDs
[i
].Anim
then
242 FTextureIDs
[i
].AnTex
.Free();
243 SetLength(FTextureIDs
, 0);
248 procedure TPanel
.Draw();
254 if Enabled
and (FCurTexture
>= 0) and
255 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) and
256 g_Collide(X
, Y
, Width
, Height
,
257 sX
, sY
, sWidth
, sHeight
) then
259 if FTextureIDs
[FCurTexture
].Anim
then
260 begin // Àíèìèðîâàííàÿ òåêñòóðà
261 if FTextureIDs
[FCurTexture
].AnTex
= nil then
264 for xx
:= 0 to (Width
div FTextureWidth
)-1 do
265 for yy
:= 0 to (Height
div FTextureHeight
)-1 do
266 FTextureIDs
[FCurTexture
].AnTex
.Draw(
267 X
+ xx
*FTextureWidth
,
268 Y
+ yy
*FTextureHeight
, M_NONE
);
271 begin // Îáû÷íàÿ òåêñòóðà
272 case FTextureIDs
[FCurTexture
].Tex
of
273 TEXTURE_SPECIAL_WATER
:
274 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
275 0, 0, 255, 0, B_FILTER
);
276 TEXTURE_SPECIAL_ACID1
:
277 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
278 0, 128, 0, 0, B_FILTER
);
279 TEXTURE_SPECIAL_ACID2
:
280 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
281 128, 0, 0, 0, B_FILTER
);
283 if g_Texture_Get('NOTEXTURE', NoTextureID
) then
285 e_GetTextureSize(NoTextureID
, @NW
, @NH
);
286 e_DrawFill(NoTextureID
, X
, Y
, Width
div NW
, Height
div NH
,
290 xx
:= X
+ (Width
div 2);
291 yy
:= Y
+ (Height
div 2);
292 e_DrawFillQuad(X
, Y
, xx
, yy
,
294 e_DrawFillQuad(xx
, Y
, X
+Width
-1, yy
,
296 e_DrawFillQuad(X
, yy
, xx
, Y
+Height
-1,
298 e_DrawFillQuad(xx
, yy
, X
+Width
-1, Y
+Height
-1,
303 e_DrawFill(FTextureIDs
[FCurTexture
].Tex
, X
, Y
,
304 Width
div FTextureWidth
,
305 Height
div FTextureHeight
,
306 FAlpha
, True, FBlending
);
312 procedure TPanel
.Update();
314 if Enabled
and (FCurTexture
>= 0) and
315 (FTextureIDs
[FCurTexture
].Anim
) and
316 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
317 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
319 FTextureIDs
[FCurTexture
].AnTex
.Update();
320 FCurFrame
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
;
321 FCurFrameCount
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
;
325 procedure TPanel
.SetFrame(Frame
: Integer; Count
: Byte);
327 function ClampInt(X
, A
, B
: Integer): Integer;
330 if X
< A
then Result
:= A
else if X
> B
then Result
:= B
;
334 if Enabled
and (FCurTexture
>= 0) and
335 (FTextureIDs
[FCurTexture
].Anim
) and
336 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
337 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
339 FCurFrame
:= ClampInt(Frame
, 0, FTextureIDs
[FCurTexture
].AnTex
.TotalFrames
);
340 FCurFrameCount
:= Count
;
341 FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
:= FCurFrame
;
342 FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
:= FCurFrameCount
;
346 procedure TPanel
.NextTexture(AnimLoop
: Byte = 0);
348 Assert(FCurTexture
>= -1, 'FCurTexture < -1');
351 if Length(FTextureIDs
) = 0 then
354 // Òîëüêî îäíà òåêñòóðà:
355 if Length(FTextureIDs
) = 1 then
357 if FCurTexture
= 0 then
363 // Áîëüøå îäíîé òåêñòóðû:
367 // Ñëåäóþùåé íåò - âîçâðàò ê íà÷àëó:
368 if FCurTexture
>= Length(FTextureIDs
) then
372 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
373 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
375 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
377 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
382 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
385 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
387 FTextureIDs
[FCurTexture
].AnTex
.Reset();
390 LastAnimLoop
:= AnimLoop
;
393 procedure TPanel
.SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
396 if Length(FTextureIDs
) = 0 then
399 // Òîëüêî îäíà òåêñòóðà:
400 if Length(FTextureIDs
) = 1 then
402 if (ID
= 0) or (ID
= -1) then
406 // Áîëüøå îäíîé òåêñòóðû:
408 if (ID
>= -1) and (ID
<= High(FTextureIDs
)) then
412 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
413 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
415 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
417 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
422 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
425 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
427 FTextureIDs
[FCurTexture
].AnTex
.Reset();
430 LastAnimLoop
:= AnimLoop
;
433 function TPanel
.GetTextureID(): DWORD
;
435 Result
:= TEXTURE_NONE
;
437 if (FCurTexture
>= 0) then
439 if FTextureIDs
[FCurTexture
].Anim
then
440 Result
:= FTextureIDs
[FCurTexture
].AnTex
.FramesID
442 Result
:= FTextureIDs
[FCurTexture
].Tex
;
446 function TPanel
.GetTextureCount(): Integer;
448 Result
:= Length(FTextureIDs
);
449 if Enabled
and (FCurTexture
>= 0) then
450 if (FTextureIDs
[FCurTexture
].Anim
) and
451 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
452 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
453 Result
:= Result
+ 100;
456 procedure TPanel
.SaveState(Var Mem
: TBinMemoryWriter
);
461 if (not SaveIt
) or (Mem
= nil) then
465 sig
:= PANEL_SIGNATURE
; // 'PANL'
467 // Îòêðûòà/çàêðûòà, åñëè äâåðü:
468 Mem
.WriteBoolean(Enabled
);
469 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò:
470 Mem
.WriteByte(LiftType
);
471 // Íîìåð òåêóùåé òåêñòóðû:
472 Mem
.WriteInt(FCurTexture
);
476 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà:
477 if (FCurTexture
>= 0) and (FTextureIDs
[FCurTexture
].Anim
) then
479 Assert(FTextureIDs
[FCurTexture
].AnTex
<> nil,
480 'TPanel.SaveState: No animation object');
485 Mem
.WriteBoolean(anim
);
486 // Åñëè äà - ñîõðàíÿåì àíèìàöèþ:
488 FTextureIDs
[FCurTexture
].AnTex
.SaveState(Mem
);
491 procedure TPanel
.LoadState(var Mem
: TBinMemoryReader
);
496 if (not SaveIt
) or (Mem
= nil) then
501 if sig
<> PANEL_SIGNATURE
then // 'PANL'
503 raise EBinSizeError
.Create('TPanel.LoadState: Wrong Panel Signature');
505 // Îòêðûòà/çàêðûòà, åñëè äâåðü:
506 Mem
.ReadBoolean(Enabled
);
507 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò:
508 Mem
.ReadByte(LiftType
);
509 // Íîìåð òåêóùåé òåêñòóðû:
510 Mem
.ReadInt(FCurTexture
);
514 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà:
515 Mem
.ReadBoolean(anim
);
516 // Åñëè äà - çàãðóæàåì àíèìàöèþ:
519 Assert((FCurTexture
>= 0) and
520 (FTextureIDs
[FCurTexture
].Anim
) and
521 (FTextureIDs
[FCurTexture
].AnTex
<> nil),
522 'TPanel.LoadState: No animation object');
523 FTextureIDs
[FCurTexture
].AnTex
.LoadState(Mem
);