author | unc0rr |
Thu, 05 Oct 2006 20:13:51 +0000 | |
changeset 190 | 206aabea2229 |
parent 189 | 33d147c69a83 |
child 191 | a03c2d037e24 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
47 | 3 |
* Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
19 |
unit uStore; |
|
20 |
interface |
|
21 |
uses uConsts, uTeams, SDLh; |
|
22 |
{$INCLUDE options.inc} |
|
23 |
||
24 |
procedure StoreInit; |
|
25 |
procedure StoreLoad; |
|
26 |
procedure StoreRelease; |
|
27 |
procedure DrawGear(Stuff : TStuff; X, Y: integer; Surface: PSDL_Surface); |
|
28 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface); |
|
161 | 29 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: integer; Surface: PSDL_Surface); |
43 | 30 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface); |
4 | 31 |
procedure DrawLand (X, Y: integer; Surface: PSDL_Surface); |
32 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); |
|
95 | 33 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface); |
34 |
procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface); |
|
47 | 35 |
procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface); |
4 | 36 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface); |
108 | 37 |
function RenderString(s: string; Color: integer; font: THWFont): PSDL_Surface; |
4 | 38 |
procedure RenderHealth(var Hedgehog: THedgehog); |
39 |
procedure AddProgress; |
|
80 | 40 |
function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true): PSDL_Surface; |
4 | 41 |
|
42 |
var PixelFormat: PSDL_PixelFormat; |
|
43 |
SDLPrimSurface: PSDL_Surface; |
|
44 |
||
45 |
implementation |
|
53 | 46 |
uses uMisc, uIO, uConsole, uLand, uCollisions; |
4 | 47 |
|
48 |
var StoreSurface, |
|
49 |
HHSurface: PSDL_Surface; |
|
50 |
||
51 |
procedure StoreInit; |
|
52 |
begin |
|
74 | 53 |
StoreSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 576, 1024, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0); |
4 | 54 |
TryDo( StoreSurface <> nil, errmsgCreateSurface + ': store' , true); |
37 | 55 |
SDL_FillRect(StoreSurface, nil, 0); |
4 | 56 |
|
57 |
TryDo(SDL_SetColorKey( StoreSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
|
58 |
end; |
|
59 |
||
60 |
procedure LoadToSurface(Filename: String; Surface: PSDL_Surface; X, Y: integer); |
|
61 |
var tmpsurf: PSDL_Surface; |
|
62 |
rr: TSDL_Rect; |
|
63 |
begin |
|
35 | 64 |
tmpsurf:= LoadImage(Filename, false); |
4 | 65 |
rr.x:= X; |
66 |
rr.y:= Y; |
|
67 |
SDL_UpperBlit(tmpsurf, nil, Surface, @rr); |
|
68 |
SDL_FreeSurface(tmpsurf); |
|
69 |
end; |
|
70 |
||
83 | 71 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; const Clear: boolean = true); |
47 | 72 |
var r: TSDL_Rect; |
73 |
begin |
|
74 |
r:= rect^; |
|
83 | 75 |
if Clear then SDL_FillRect(Surface, @r, 0); |
47 | 76 |
r.y:= rect.y + 1; |
77 |
r.h:= rect.h - 2; |
|
78 |
SDL_FillRect(Surface, @r, BorderColor); |
|
79 |
r.x:= rect.x + 1; |
|
80 |
r.w:= rect.w - 2; |
|
81 |
r.y:= rect.y; |
|
82 |
r.h:= rect.h; |
|
83 |
SDL_FillRect(Surface, @r, BorderColor); |
|
84 |
r.x:= rect.x + 2; |
|
85 |
r.y:= rect.y + 1; |
|
86 |
r.w:= rect.w - 4; |
|
87 |
r.h:= rect.h - 2; |
|
88 |
SDL_FillRect(Surface, @r, FillColor); |
|
89 |
r.x:= rect.x + 1; |
|
90 |
r.y:= rect.y + 2; |
|
91 |
r.w:= rect.w - 2; |
|
92 |
r.h:= rect.h - 4; |
|
93 |
SDL_FillRect(Surface, @r, FillColor) |
|
94 |
end; |
|
95 |
||
4 | 96 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: integer; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
97 |
var w, h: integer; |
|
98 |
tmpsurf: PSDL_Surface; |
|
99 |
clr: TSDL_Color; |
|
100 |
begin |
|
74 | 101 |
TTF_SizeUTF8(Fontz[Font].Handle, PChar(s), w, h); |
4 | 102 |
Result.x:= X; |
103 |
Result.y:= Y; |
|
104 |
Result.w:= w + 6; |
|
74 | 105 |
Result.h:= h + 2; |
47 | 106 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface); |
189 | 107 |
clr.r:= Color shr 16; |
108 |
clr.g:= (Color shr 8) and $FF; |
|
109 |
clr.b:= Color and $FF; |
|
190 | 110 |
clr.a:= $FF; |
74 | 111 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, PChar(s), clr); |
4 | 112 |
Result.x:= X + 3; |
74 | 113 |
Result.y:= Y + 1; |
4 | 114 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
115 |
SDL_FreeSurface(tmpsurf); |
|
116 |
Result.x:= X; |
|
117 |
Result.y:= Y; |
|
118 |
Result.w:= w + 6; |
|
74 | 119 |
Result.h:= h + 2 |
4 | 120 |
end; |
121 |
||
122 |
procedure StoreLoad; |
|
123 |
var i: TStuff; |
|
124 |
ii: TSprite; |
|
125 |
fi: THWFont; |
|
126 |
s: string; |
|
127 |
tmpsurf: PSDL_Surface; |
|
128 |
||
129 |
procedure WriteNames(Font: THWFont); |
|
130 |
var Team: PTeam; |
|
131 |
i: integer; |
|
47 | 132 |
r, rr: TSDL_Rect; |
49 | 133 |
drY: integer; |
4 | 134 |
begin |
135 |
r.x:= 0; |
|
136 |
r.y:= 272; |
|
70 | 137 |
drY:= cScreenHeight - 4; |
4 | 138 |
Team:= TeamsList; |
139 |
while Team<>nil do |
|
140 |
begin |
|
47 | 141 |
r.w:= 104; |
95 | 142 |
Team.NameTag:= RenderString(Team.TeamName, Team.Color, Font); |
47 | 143 |
r.w:= cTeamHealthWidth + 5; |
95 | 144 |
r.h:= Team.NameTag.h; |
47 | 145 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, StoreSurface); |
146 |
Team.HealthRect:= r; |
|
147 |
rr:= r; |
|
148 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
189 | 149 |
DrawRoundRect(@rr, Team.AdjColor, Team.AdjColor, StoreSurface, false); |
47 | 150 |
inc(r.y, r.h); |
49 | 151 |
dec(drY, r.h + 2); |
152 |
Team.DrawHealthY:= drY; |
|
4 | 153 |
for i:= 0 to 7 do |
95 | 154 |
with Team.Hedgehogs[i] do |
155 |
if Gear <> nil then |
|
156 |
NameTag:= RenderString(Name, Team.Color, fnt16); |
|
4 | 157 |
Team:= Team.Next |
158 |
end; |
|
159 |
end; |
|
160 |
||
161 |
procedure MakeCrossHairs; |
|
162 |
var Team: PTeam; |
|
163 |
r: TSDL_Rect; |
|
164 |
tmpsurf: PSDL_Surface; |
|
165 |
s: string; |
|
166 |
TransColor: Longword; |
|
167 |
begin |
|
168 |
r.x:= 0; |
|
169 |
r.y:= 256; |
|
170 |
r.w:= 16; |
|
171 |
r.h:= 16; |
|
53 | 172 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
74 | 173 |
tmpsurf:= LoadImage(PChar(s), false); |
4 | 174 |
TransColor:= SDL_MapRGB(tmpsurf.format, $FF, $FF, $FF); |
175 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, TransColor) = 0, errmsgTransparentSet, true); |
|
176 |
||
177 |
Team:= TeamsList; |
|
178 |
while Team<>nil do |
|
179 |
begin |
|
189 | 180 |
SDL_FillRect(StoreSurface, @r, Team.AdjColor); |
4 | 181 |
SDL_UpperBlit(tmpsurf, nil, StoreSurface, @r); |
182 |
Team.CrossHairRect:= r; |
|
183 |
inc(r.x, 16); |
|
184 |
Team:= Team.Next |
|
185 |
end; |
|
186 |
||
187 |
SDL_FreeSurface(tmpsurf) |
|
188 |
end; |
|
189 |
||
190 |
procedure InitHealth; |
|
191 |
var p: PTeam; |
|
95 | 192 |
i: integer; |
4 | 193 |
begin |
194 |
p:= TeamsList; |
|
195 |
while p <> nil do |
|
196 |
begin |
|
197 |
for i:= 0 to cMaxHHIndex do |
|
198 |
if p.Hedgehogs[i].Gear <> nil then |
|
199 |
RenderHealth(p.Hedgehogs[i]); |
|
200 |
p:= p.Next |
|
201 |
end |
|
202 |
end; |
|
203 |
||
204 |
procedure LoadGraves; |
|
205 |
var p: PTeam; |
|
206 |
l: integer; |
|
207 |
begin |
|
208 |
p:= TeamsList; |
|
209 |
l:= 512; |
|
210 |
while p <> nil do |
|
211 |
begin |
|
212 |
dec(l, 32); |
|
213 |
if p.GraveName = '' then p.GraveName:= 'Simple'; |
|
74 | 214 |
LoadToSurface(Pathz[ptGraves] + '/' + p.GraveName, StoreSurface, l, 512); |
4 | 215 |
p.GraveRect.x:= l; |
216 |
p.GraveRect.y:= 512; |
|
217 |
p.GraveRect.w:= 32; |
|
218 |
p.GraveRect.h:= 256; |
|
219 |
p:= p.Next |
|
220 |
end |
|
221 |
end; |
|
222 |
||
223 |
procedure GetSkyColor; |
|
107 | 224 |
var p: PByteArray; |
4 | 225 |
begin |
80 | 226 |
if SDL_MustLock(SpritesData[sprSky].Surface) then |
227 |
SDLTry(SDL_LockSurface(SpritesData[sprSky].Surface) >= 0, true); |
|
107 | 228 |
p:= SpritesData[sprSky].Surface.pixels; |
80 | 229 |
case SpritesData[sprSky].Surface.format.BytesPerPixel of |
4 | 230 |
1: cSkyColor:= PByte(p)^; |
231 |
2: cSkyColor:= PWord(p)^; |
|
107 | 232 |
3: cSkyColor:= (p^[0]) or (p^[1] shl 8) or (p^[2] shl 16); |
4 | 233 |
4: cSkyColor:= PLongword(p)^; |
234 |
end; |
|
80 | 235 |
if SDL_MustLock(SpritesData[sprSky].Surface) then |
236 |
SDL_UnlockSurface(SpritesData[sprSky].Surface) |
|
4 | 237 |
end; |
238 |
||
239 |
procedure GetExplosionBorderColor; |
|
240 |
var f: textfile; |
|
241 |
c: integer; |
|
242 |
begin |
|
80 | 243 |
s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename; |
4 | 244 |
WriteToConsole(msgLoading + s + ' '); |
245 |
AssignFile(f, s); |
|
246 |
{$I-} |
|
247 |
Reset(f); |
|
248 |
Readln(f, s); |
|
249 |
Closefile(f); |
|
250 |
{$I+} |
|
251 |
TryDo(IOResult = 0, msgFailed, true); |
|
252 |
WriteLnToConsole(msgOK); |
|
253 |
val(s, cExplosionBorderColor, c); |
|
254 |
if cFullScreen then |
|
255 |
cExplosionBorderColor:= SDL_MapRGB(PixelFormat, (cExplosionBorderColor shr 16) and $FF, |
|
256 |
(cExplosionBorderColor shr 8) and $FF, |
|
257 |
cExplosionBorderColor and $FF) |
|
258 |
else |
|
259 |
cExplosionBorderColor:= SDL_MapRGB(LandSurface.format, (cExplosionBorderColor shr 16) and $FF, |
|
260 |
(cExplosionBorderColor shr 8) and $FF, |
|
261 |
cExplosionBorderColor and $FF) |
|
262 |
end; |
|
263 |
||
264 |
begin |
|
265 |
for fi:= Low(THWFont) to High(THWFont) do |
|
266 |
with Fontz[fi] do |
|
267 |
begin |
|
53 | 268 |
s:= Pathz[ptFonts] + '/' + Name; |
4 | 269 |
WriteToConsole(msgLoading + s + ' '); |
270 |
Handle:= TTF_OpenFont(PChar(s), Height); |
|
271 |
TryDo(Handle <> nil, msgFailed, true); |
|
272 |
WriteLnToConsole(msgOK) |
|
273 |
end; |
|
274 |
AddProgress; |
|
53 | 275 |
|
105 | 276 |
WriteToConsole('LandSurface tuning... '); |
4 | 277 |
tmpsurf:= LandSurface; |
278 |
TryDo(tmpsurf <> nil, msgFailed, true); |
|
279 |
if cFullScreen then |
|
280 |
begin |
|
281 |
LandSurface:= SDL_DisplayFormat(tmpsurf); |
|
282 |
SDL_FreeSurface(tmpsurf); |
|
283 |
end else LandSurface:= tmpsurf; |
|
35 | 284 |
TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
4 | 285 |
WriteLnToConsole(msgOK); |
286 |
||
287 |
GetExplosionBorderColor; |
|
288 |
||
289 |
AddProgress; |
|
290 |
for i:= Low(TStuff) to High(TStuff) do |
|
53 | 291 |
LoadToSurface(Pathz[StuffLoadData[i].Path] + '/' + StuffLoadData[i].FileName, StoreSurface, StuffPoz[i].x, StuffPoz[i].y); |
4 | 292 |
|
293 |
AddProgress; |
|
294 |
WriteNames(fnt16); |
|
70 | 295 |
MakeCrossHairs; |
4 | 296 |
LoadGraves; |
297 |
||
298 |
AddProgress; |
|
299 |
for ii:= Low(TSprite) to High(TSprite) do |
|
300 |
with SpritesData[ii] do |
|
80 | 301 |
begin |
302 |
if AltPath = ptNone then |
|
303 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha) |
|
304 |
else begin |
|
305 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, false); |
|
306 |
if Surface = nil then |
|
307 |
Surface:= LoadImage(Pathz[AltPath] + '/' + FileName, hasAlpha) |
|
308 |
end; |
|
309 |
if Width = 0 then Width:= Surface.w; |
|
310 |
if Height = 0 then Height:= Surface.h |
|
311 |
end; |
|
312 |
||
313 |
GetSkyColor; |
|
4 | 314 |
|
315 |
AddProgress; |
|
53 | 316 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, false); |
35 | 317 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
4 | 318 |
HHSurface:= SDL_DisplayFormat(tmpsurf); |
319 |
SDL_FreeSurface(tmpsurf); |
|
320 |
||
321 |
InitHealth; |
|
322 |
||
323 |
{$IFDEF DUMP} |
|
324 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
325 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
326 |
{$ENDIF} |
|
327 |
end; |
|
328 |
||
329 |
procedure DrawFromRect(X, Y: integer; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface); |
|
330 |
var rr: TSDL_Rect; |
|
331 |
begin |
|
332 |
rr.x:= X; |
|
333 |
rr.y:= Y; |
|
334 |
rr.w:= r.w; |
|
335 |
rr.h:= r.h; |
|
336 |
if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then |
|
337 |
begin |
|
43 | 338 |
OutError('Blit: ' + SDL_GetError, true); |
4 | 339 |
exit |
340 |
end; |
|
341 |
end; |
|
342 |
||
343 |
procedure DrawGear(Stuff: TStuff; X, Y: integer; Surface: PSDL_Surface); |
|
344 |
begin |
|
345 |
DrawFromRect(X, Y, @StuffPoz[Stuff], StoreSurface, Surface) |
|
346 |
end; |
|
347 |
||
348 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface); |
|
349 |
begin |
|
350 |
r.y:= r.y + Height * Position; |
|
351 |
r.h:= Height; |
|
352 |
DrawFromRect(X, Y, @r, StoreSurface, Surface) |
|
353 |
end; |
|
354 |
||
161 | 355 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: integer; Surface: PSDL_Surface); |
4 | 356 |
var r: TSDL_Rect; |
357 |
begin |
|
358 |
r.x:= 0; |
|
359 |
r.w:= SpritesData[Sprite].Width; |
|
161 | 360 |
r.y:= Frame * SpritesData[Sprite].Height; |
4 | 361 |
r.h:= SpritesData[Sprite].Height; |
362 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) |
|
363 |
end; |
|
364 |
||
43 | 365 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface); |
366 |
var r: TSDL_Rect; |
|
367 |
begin |
|
368 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
369 |
r.w:= SpritesData[Sprite].Width; |
|
370 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
371 |
r.h:= SpritesData[Sprite].Height; |
|
372 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) |
|
373 |
end; |
|
374 |
||
4 | 375 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); |
376 |
var clr: TSDL_Color; |
|
377 |
tmpsurf: PSDL_Surface; |
|
378 |
r: TSDL_Rect; |
|
379 |
begin |
|
380 |
r.x:= X; |
|
381 |
r.y:= Y; |
|
189 | 382 |
clr.r:= $FF; |
383 |
clr.g:= $FF; |
|
384 |
clr.b:= $FF; |
|
190 | 385 |
clr.a:= $FF; |
74 | 386 |
tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, PChar(s), clr); |
4 | 387 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
388 |
SDL_FreeSurface(tmpsurf) |
|
389 |
end; |
|
390 |
||
391 |
procedure DrawLand(X, Y: integer; Surface: PSDL_Surface); |
|
392 |
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024); |
|
393 |
begin |
|
394 |
DrawFromRect(X, Y, @r, LandSurface, Surface) |
|
395 |
end; |
|
396 |
||
47 | 397 |
procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface); |
398 |
begin |
|
399 |
DrawFromRect(X, Y, Rect, StoreSurface, Surface) |
|
400 |
end; |
|
401 |
||
95 | 402 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface); |
4 | 403 |
begin |
95 | 404 |
DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface) |
405 |
end; |
|
406 |
||
407 |
procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface); |
|
408 |
var r: TSDL_Rect; |
|
409 |
begin |
|
410 |
r.x:= X - Source.w div 2; |
|
411 |
r.y:= Top; |
|
412 |
r.w:= Source.w; |
|
413 |
r.h:= Source.h; |
|
414 |
SDL_UpperBlit(Source, nil, Surface, @r) |
|
4 | 415 |
end; |
416 |
||
417 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface); |
|
418 |
var r: TSDL_Rect; |
|
419 |
begin |
|
420 |
r.x:= Step * 32; |
|
421 |
r.y:= Pos * 32; |
|
422 |
if Dir = -1 then r.x:= cHHSurfaceWidth - 32 - r.x; |
|
423 |
r.w:= 32; |
|
424 |
r.h:= 32; |
|
425 |
DrawFromRect(X, Y, @r, HHSurface, Surface) |
|
426 |
end; |
|
427 |
||
428 |
procedure StoreRelease; |
|
429 |
var ii: TSprite; |
|
430 |
begin |
|
431 |
for ii:= Low(TSprite) to High(TSprite) do |
|
432 |
SDL_FreeSurface(SpritesData[ii].Surface); |
|
433 |
SDL_FreeSurface( HHSurface ); |
|
434 |
SDL_FreeSurface(LandSurface ); |
|
435 |
SDL_FreeSurface(StoreSurface ) |
|
436 |
end; |
|
437 |
||
108 | 438 |
function RenderString(s: string; Color: integer; font: THWFont): PSDL_Surface; |
95 | 439 |
var w, h: integer; |
440 |
begin |
|
108 | 441 |
TTF_SizeUTF8(Fontz[font].Handle, PChar(s), w, h); |
95 | 442 |
Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + 6, h + 2, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0); |
107 | 443 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
95 | 444 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
445 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true) |
|
446 |
end; |
|
447 |
||
4 | 448 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 449 |
var s: shortstring; |
4 | 450 |
begin |
451 |
str(Hedgehog.Gear.Health, s); |
|
95 | 452 |
if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
453 |
Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Color, fnt16) |
|
4 | 454 |
end; |
455 |
||
456 |
procedure AddProgress; |
|
457 |
const Step: Longword = 0; |
|
458 |
ProgrSurf: PSDL_Surface = nil; |
|
71 | 459 |
MaxCalls = 11; // MaxCalls should be the count of calls to AddProgress to prevent memory leakage |
4 | 460 |
var r: TSDL_Rect; |
461 |
begin |
|
462 |
if Step = 0 then |
|
463 |
begin |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
95
diff
changeset
|
464 |
WriteToConsole(msgLoading + 'progress sprite: '); |
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
95
diff
changeset
|
465 |
ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/BigDigits', false); |
4 | 466 |
end; |
467 |
SDL_FillRect(SDLPrimSurface, nil, 0); |
|
468 |
r.x:= 0; |
|
469 |
r.w:= 32; |
|
470 |
r.h:= 32; |
|
71 | 471 |
r.y:= (Step mod 10) * 32; |
4 | 472 |
DrawFromRect(cScreenWidth div 2 - 16, cScreenHeight div 2 - 16, @r, ProgrSurf, SDLPrimSurface); |
473 |
SDL_Flip(SDLPrimSurface); |
|
474 |
inc(Step); |
|
475 |
if Step = MaxCalls then |
|
476 |
begin |
|
477 |
WriteLnToConsole('Freeing progress surface... '); |
|
478 |
SDL_FreeSurface(ProgrSurf) |
|
479 |
end; |
|
480 |
end; |
|
481 |
||
80 | 482 |
function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true): PSDL_Surface; |
30 | 483 |
var tmpsurf: PSDL_Surface; |
4 | 484 |
begin |
485 |
WriteToConsole(msgLoading + filename + '... '); |
|
74 | 486 |
tmpsurf:= IMG_Load(PChar(filename + '.' + cBitsStr + '.png')); |
487 |
if tmpsurf = nil then |
|
488 |
tmpsurf:= IMG_Load(PChar(filename + '.png')); |
|
80 | 489 |
|
490 |
if tmpsurf = nil then |
|
491 |
if critical then OutError(msgFailed, true) |
|
492 |
else begin |
|
493 |
WriteLnToConsole(msgFailed); |
|
494 |
Result:= nil; |
|
495 |
exit |
|
496 |
end; |
|
497 |
||
35 | 498 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
80 | 499 |
if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
500 |
else Result:= SDL_DisplayFormat(tmpsurf); |
|
4 | 501 |
WriteLnToConsole(msgOK) |
502 |
end; |
|
503 |
||
504 |
end. |