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