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
);
206 FBlending
:= ByteBool(0);
208 else if not g_Map_IsSpecialTexture(Textures
[PanelRec
.TextureNum
].TextureName
) then
210 FTextureWidth
:= Textures
[PanelRec
.TextureNum
].Width
;
211 FTextureHeight
:= Textures
[PanelRec
.TextureNum
].Height
;
212 FAlpha
:= PanelRec
.Alpha
;
213 FBlending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
217 destructor TPanel
.Destroy();
221 for i
:= 0 to High(FTextureIDs
) do
222 if FTextureIDs
[i
].Anim
then
223 FTextureIDs
[i
].AnTex
.Free();
224 SetLength(FTextureIDs
, 0);
229 procedure TPanel
.Draw();
235 if Enabled
and (FCurTexture
>= 0) and
236 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) and
237 g_Collide(X
, Y
, Width
, Height
,
238 sX
, sY
, sWidth
, sHeight
) then
240 if FTextureIDs
[FCurTexture
].Anim
then
241 begin // Àíèìèðîâàííàÿ òåêñòóðà
242 if FTextureIDs
[FCurTexture
].AnTex
= nil then
245 for xx
:= 0 to (Width
div FTextureWidth
)-1 do
246 for yy
:= 0 to (Height
div FTextureHeight
)-1 do
247 FTextureIDs
[FCurTexture
].AnTex
.Draw(
248 X
+ xx
*FTextureWidth
,
249 Y
+ yy
*FTextureHeight
, M_NONE
);
252 begin // Îáû÷íàÿ òåêñòóðà
253 case FTextureIDs
[FCurTexture
].Tex
of
254 TEXTURE_SPECIAL_WATER
:
255 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
256 0, 0, 255, 0, B_FILTER
);
257 TEXTURE_SPECIAL_ACID1
:
258 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
259 0, 128, 0, 0, B_FILTER
);
260 TEXTURE_SPECIAL_ACID2
:
261 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
262 128, 0, 0, 0, B_FILTER
);
264 if g_Texture_Get('NOTEXTURE', NoTextureID
) then
266 e_GetTextureSize(NoTextureID
, @NW
, @NH
);
267 e_DrawFill(NoTextureID
, X
, Y
, Width
div NW
, Height
div NH
,
271 xx
:= X
+ (Width
div 2);
272 yy
:= Y
+ (Height
div 2);
273 e_DrawFillQuad(X
, Y
, xx
, yy
,
275 e_DrawFillQuad(xx
, Y
, X
+Width
-1, yy
,
277 e_DrawFillQuad(X
, yy
, xx
, Y
+Height
-1,
279 e_DrawFillQuad(xx
, yy
, X
+Width
-1, Y
+Height
-1,
284 e_DrawFill(FTextureIDs
[FCurTexture
].Tex
, X
, Y
,
285 Width
div FTextureWidth
,
286 Height
div FTextureHeight
,
287 FAlpha
, True, FBlending
);
293 procedure TPanel
.Update();
295 if Enabled
and (FCurTexture
>= 0) and
296 (FTextureIDs
[FCurTexture
].Anim
) and
297 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
298 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
300 FTextureIDs
[FCurTexture
].AnTex
.Update();
301 FCurFrame
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
;
302 FCurFrameCount
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
;
306 procedure TPanel
.SetFrame(Frame
: Integer; Count
: Byte);
308 function ClampInt(X
, A
, B
: Integer): Integer;
311 if X
< A
then Result
:= A
else if X
> B
then Result
:= B
;
315 if Enabled
and (FCurTexture
>= 0) and
316 (FTextureIDs
[FCurTexture
].Anim
) and
317 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
318 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
320 FCurFrame
:= ClampInt(Frame
, 0, FTextureIDs
[FCurTexture
].AnTex
.TotalFrames
);
321 FCurFrameCount
:= Count
;
322 FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
:= FCurFrame
;
323 FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
:= FCurFrameCount
;
327 procedure TPanel
.NextTexture(AnimLoop
: Byte = 0);
329 Assert(FCurTexture
>= -1, 'FCurTexture < -1');
332 if Length(FTextureIDs
) = 0 then
335 // Òîëüêî îäíà òåêñòóðà:
336 if Length(FTextureIDs
) = 1 then
338 if FCurTexture
= 0 then
344 // Áîëüøå îäíîé òåêñòóðû:
348 // Ñëåäóþùåé íåò - âîçâðàò ê íà÷àëó:
349 if FCurTexture
>= Length(FTextureIDs
) then
353 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
354 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
356 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
358 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
363 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
366 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
368 FTextureIDs
[FCurTexture
].AnTex
.Reset();
371 LastAnimLoop
:= AnimLoop
;
374 procedure TPanel
.SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
377 if Length(FTextureIDs
) = 0 then
380 // Òîëüêî îäíà òåêñòóðà:
381 if Length(FTextureIDs
) = 1 then
383 if (ID
= 0) or (ID
= -1) then
387 // Áîëüøå îäíîé òåêñòóðû:
389 if (ID
>= -1) and (ID
<= High(FTextureIDs
)) then
393 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
394 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
396 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
398 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
403 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
406 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
408 FTextureIDs
[FCurTexture
].AnTex
.Reset();
411 LastAnimLoop
:= AnimLoop
;
414 function TPanel
.GetTextureID(): DWORD
;
416 Result
:= TEXTURE_NONE
;
418 if (FCurTexture
>= 0) then
420 if FTextureIDs
[FCurTexture
].Anim
then
421 Result
:= FTextureIDs
[FCurTexture
].AnTex
.FramesID
423 Result
:= FTextureIDs
[FCurTexture
].Tex
;
427 function TPanel
.GetTextureCount(): Integer;
429 Result
:= Length(FTextureIDs
);
430 if Enabled
and (FCurTexture
>= 0) then
431 if (FTextureIDs
[FCurTexture
].Anim
) and
432 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
433 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
434 Result
:= Result
+ 100;
437 procedure TPanel
.SaveState(Var Mem
: TBinMemoryWriter
);
442 if (not SaveIt
) or (Mem
= nil) then
446 sig
:= PANEL_SIGNATURE
; // 'PANL'
448 // Îòêðûòà/çàêðûòà, åñëè äâåðü:
449 Mem
.WriteBoolean(Enabled
);
450 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò:
451 Mem
.WriteByte(LiftType
);
452 // Íîìåð òåêóùåé òåêñòóðû:
453 Mem
.WriteInt(FCurTexture
);
454 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà:
455 if (FCurTexture
>= 0) and (FTextureIDs
[FCurTexture
].Anim
) then
457 Assert(FTextureIDs
[FCurTexture
].AnTex
<> nil,
458 'TPanel.SaveState: No animation object');
463 Mem
.WriteBoolean(anim
);
464 // Åñëè äà - ñîõðàíÿåì àíèìàöèþ:
466 FTextureIDs
[FCurTexture
].AnTex
.SaveState(Mem
);
469 procedure TPanel
.LoadState(var Mem
: TBinMemoryReader
);
474 if (not SaveIt
) or (Mem
= nil) then
479 if sig
<> PANEL_SIGNATURE
then // 'PANL'
481 raise EBinSizeError
.Create('TPanel.LoadState: Wrong Panel Signature');
483 // Îòêðûòà/çàêðûòà, åñëè äâåðü:
484 Mem
.ReadBoolean(Enabled
);
485 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò:
486 Mem
.ReadByte(LiftType
);
487 // Íîìåð òåêóùåé òåêñòóðû:
488 Mem
.ReadInt(FCurTexture
);
489 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà:
490 Mem
.ReadBoolean(anim
);
491 // Åñëè äà - çàãðóæàåì àíèìàöèþ:
494 Assert((FCurTexture
>= 0) and
495 (FTextureIDs
[FCurTexture
].Anim
) and
496 (FTextureIDs
[FCurTexture
].AnTex
<> nil),
497 'TPanel.LoadState: No animation object');
498 FTextureIDs
[FCurTexture
].AnTex
.LoadState(Mem
);