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