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 g_basic
, g_map
, MAPDEF
, g_game
, e_graphics
,
65 g_console
, g_language
;
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 not g_Map_IsSpecialTexture(Textures
[PanelRec
.TextureNum
].TextureName
) then
202 FTextureWidth
:= Textures
[PanelRec
.TextureNum
].Width
;
203 FTextureHeight
:= Textures
[PanelRec
.TextureNum
].Height
;
204 FAlpha
:= PanelRec
.Alpha
;
205 FBlending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
209 destructor TPanel
.Destroy();
213 for i
:= 0 to High(FTextureIDs
) do
214 if FTextureIDs
[i
].Anim
then
215 FTextureIDs
[i
].AnTex
.Free();
216 SetLength(FTextureIDs
, 0);
221 procedure TPanel
.Draw();
227 if Enabled
and (FCurTexture
>= 0) and
228 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) and
229 g_Collide(X
, Y
, Width
, Height
,
230 sX
, sY
, sWidth
, sHeight
) then
232 if FTextureIDs
[FCurTexture
].Anim
then
233 begin // Àíèìèðîâàííàÿ òåêñòóðà
234 if FTextureIDs
[FCurTexture
].AnTex
= nil then
237 for xx
:= 0 to (Width
div FTextureWidth
)-1 do
238 for yy
:= 0 to (Height
div FTextureHeight
)-1 do
239 FTextureIDs
[FCurTexture
].AnTex
.Draw(
240 X
+ xx
*FTextureWidth
,
241 Y
+ yy
*FTextureHeight
, M_NONE
);
244 begin // Îáû÷íàÿ òåêñòóðà
245 case FTextureIDs
[FCurTexture
].Tex
of
246 TEXTURE_SPECIAL_WATER
:
247 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
248 0, 0, 255, 0, B_FILTER
);
249 TEXTURE_SPECIAL_ACID1
:
250 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
251 0, 128, 0, 0, B_FILTER
);
252 TEXTURE_SPECIAL_ACID2
:
253 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
254 128, 0, 0, 0, B_FILTER
);
256 if g_Texture_Get('NOTEXTURE', NoTextureID
) then
258 e_GetTextureSize(NoTextureID
, @NW
, @NH
);
259 e_DrawFill(NoTextureID
, X
, Y
, Width
div NW
, Height
div NH
,
263 xx
:= X
+ (Width
div 2);
264 yy
:= Y
+ (Height
div 2);
265 e_DrawFillQuad(X
, Y
, xx
, yy
,
267 e_DrawFillQuad(xx
, Y
, X
+Width
-1, yy
,
269 e_DrawFillQuad(X
, yy
, xx
, Y
+Height
-1,
271 e_DrawFillQuad(xx
, yy
, X
+Width
-1, Y
+Height
-1,
276 e_DrawFill(FTextureIDs
[FCurTexture
].Tex
, X
, Y
,
277 Width
div FTextureWidth
,
278 Height
div FTextureHeight
,
279 FAlpha
, True, FBlending
);
285 procedure TPanel
.Update();
287 if Enabled
and (FCurTexture
>= 0) and
288 (FTextureIDs
[FCurTexture
].Anim
) and
289 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
290 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
292 FTextureIDs
[FCurTexture
].AnTex
.Update();
293 FCurFrame
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
;
294 FCurFrameCount
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
;
298 procedure TPanel
.SetFrame(Frame
: Integer; Count
: Byte);
300 function ClampInt(X
, A
, B
: Integer): Integer;
303 if X
< A
then Result
:= A
else if X
> B
then Result
:= B
;
307 if Enabled
and (FCurTexture
>= 0) and
308 (FTextureIDs
[FCurTexture
].Anim
) and
309 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
310 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
312 FCurFrame
:= ClampInt(Frame
, 0, FTextureIDs
[FCurTexture
].AnTex
.TotalFrames
);
313 FCurFrameCount
:= Count
;
314 FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
:= FCurFrame
;
315 FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
:= FCurFrameCount
;
319 procedure TPanel
.NextTexture(AnimLoop
: Byte = 0);
321 Assert(FCurTexture
>= -1, 'FCurTexture < -1');
324 if Length(FTextureIDs
) = 0 then
327 // Òîëüêî îäíà òåêñòóðà:
328 if Length(FTextureIDs
) = 1 then
330 if FCurTexture
= 0 then
336 // Áîëüøå îäíîé òåêñòóðû:
340 // Ñëåäóþùåé íåò - âîçâðàò ê íà÷àëó:
341 if FCurTexture
>= Length(FTextureIDs
) then
345 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
346 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
348 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
350 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
355 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
358 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
360 FTextureIDs
[FCurTexture
].AnTex
.Reset();
363 LastAnimLoop
:= AnimLoop
;
366 procedure TPanel
.SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
369 if Length(FTextureIDs
) = 0 then
372 // Òîëüêî îäíà òåêñòóðà:
373 if Length(FTextureIDs
) = 1 then
375 if (ID
= 0) or (ID
= -1) then
379 // Áîëüøå îäíîé òåêñòóðû:
381 if (ID
>= -1) and (ID
<= High(FTextureIDs
)) then
385 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
386 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
388 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
390 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
395 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
398 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
400 FTextureIDs
[FCurTexture
].AnTex
.Reset();
403 LastAnimLoop
:= AnimLoop
;
406 function TPanel
.GetTextureID(): DWORD
;
408 Result
:= TEXTURE_NONE
;
410 if (FCurTexture
>= 0) then
412 if FTextureIDs
[FCurTexture
].Anim
then
413 Result
:= FTextureIDs
[FCurTexture
].AnTex
.FramesID
415 Result
:= FTextureIDs
[FCurTexture
].Tex
;
419 function TPanel
.GetTextureCount(): Integer;
421 Result
:= Length(FTextureIDs
);
422 if Enabled
and (FCurTexture
>= 0) then
423 if (FTextureIDs
[FCurTexture
].Anim
) and
424 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
425 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
426 Result
:= Result
+ 100;
429 procedure TPanel
.SaveState(Var Mem
: TBinMemoryWriter
);
434 if (not SaveIt
) or (Mem
= nil) then
438 sig
:= PANEL_SIGNATURE
; // 'PANL'
440 // Îòêðûòà/çàêðûòà, åñëè äâåðü:
441 Mem
.WriteBoolean(Enabled
);
442 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò:
443 Mem
.WriteByte(LiftType
);
444 // Íîìåð òåêóùåé òåêñòóðû:
445 Mem
.WriteInt(FCurTexture
);
446 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà:
447 if (FCurTexture
>= 0) and (FTextureIDs
[FCurTexture
].Anim
) then
449 Assert(FTextureIDs
[FCurTexture
].AnTex
<> nil,
450 'TPanel.SaveState: No animation object');
455 Mem
.WriteBoolean(anim
);
456 // Åñëè äà - ñîõðàíÿåì àíèìàöèþ:
458 FTextureIDs
[FCurTexture
].AnTex
.SaveState(Mem
);
461 procedure TPanel
.LoadState(var Mem
: TBinMemoryReader
);
466 if (not SaveIt
) or (Mem
= nil) then
471 if sig
<> PANEL_SIGNATURE
then // 'PANL'
473 raise EBinSizeError
.Create('TPanel.LoadState: Wrong Panel Signature');
475 // Îòêðûòà/çàêðûòà, åñëè äâåðü:
476 Mem
.ReadBoolean(Enabled
);
477 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò:
478 Mem
.ReadByte(LiftType
);
479 // Íîìåð òåêóùåé òåêñòóðû:
480 Mem
.ReadInt(FCurTexture
);
481 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà:
482 Mem
.ReadBoolean(anim
);
483 // Åñëè äà - çàãðóæàåì àíèìàöèþ:
486 Assert((FCurTexture
>= 0) and
487 (FTextureIDs
[FCurTexture
].Anim
) and
488 (FTextureIDs
[FCurTexture
].AnTex
<> nil),
489 'TPanel.LoadState: No animation object');
490 FTextureIDs
[FCurTexture
].AnTex
.LoadState(Mem
);