30 procedure StoreRelease(reload: boolean); |
30 procedure StoreRelease(reload: boolean); |
31 procedure RenderHealth(var Hedgehog: THedgehog); |
31 procedure RenderHealth(var Hedgehog: THedgehog); |
32 procedure AddProgress; |
32 procedure AddProgress; |
33 procedure FinishProgress; |
33 procedure FinishProgress; |
34 function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
34 function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
|
35 |
|
36 // loads an image from the game's data files |
|
37 function LoadDataImage(const path: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
|
38 // like LoadDataImage but uses altPath as fallback-path if file not found/loadable in path |
|
39 function LoadDataImageAltPath(const path, altPath: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
|
40 // like LoadDataImage but uses altFile as fallback-filename if file cannot be loaded |
|
41 function LoadDataImageAltFile(const path: TPathType; const filename, altFile: shortstring; imageFlags: LongInt): PSDL_Surface; |
|
42 |
35 procedure LoadHedgehogHat(HHGear: PGear; newHat: shortstring); |
43 procedure LoadHedgehogHat(HHGear: PGear; newHat: shortstring); |
36 procedure SetupOpenGL; |
44 procedure SetupOpenGL; |
37 procedure SetScale(f: GLfloat); |
45 procedure SetScale(f: GLfloat); |
38 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture; |
46 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture; |
39 procedure RenderWeaponTooltip(atype: TAmmoType); |
47 procedure RenderWeaponTooltip(atype: TAmmoType); |
93 var t: LongInt; |
101 var t: LongInt; |
94 tmpsurf, texsurf: PSDL_Surface; |
102 tmpsurf, texsurf: PSDL_Surface; |
95 Color, i: Longword; |
103 Color, i: Longword; |
96 s: shortstring; |
104 s: shortstring; |
97 begin |
105 begin |
98 s:= UserPathz[ptGraphics] + '/' + cCHFileName; |
106 tmpsurf:= LoadDataImage(ptGraphics, cCHFileName, ifAlpha or ifCritical); |
99 if not FileExists(s+'.png') then s:= Pathz[ptGraphics] + '/' + cCHFileName; |
|
100 tmpsurf:= LoadImage(s, ifAlpha or ifCritical); |
|
101 |
107 |
102 for t:= 0 to Pred(TeamsCount) do |
108 for t:= 0 to Pred(TeamsCount) do |
103 with TeamsArray[t]^ do |
109 with TeamsArray[t]^ do |
104 begin |
110 begin |
105 texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask); |
111 texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask); |
198 Flag:= 'cpu' |
204 Flag:= 'cpu' |
199 end |
205 end |
200 else if (Flag = 'cpu') or (Flag = 'cpu_plain') then |
206 else if (Flag = 'cpu') or (Flag = 'cpu_plain') then |
201 Flag:= 'hedgewars'; |
207 Flag:= 'hedgewars'; |
202 |
208 |
203 flagsurf:= LoadImage(UserPathz[ptFlags] + '/' + Flag, ifNone); |
209 flagsurf:= LoadDataImageAltFile(ptFlags, Flag, 'hedgewars', ifNone); |
204 if flagsurf = nil then |
|
205 flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone); |
|
206 if flagsurf = nil then |
|
207 flagsurf:= LoadImage(UserPathz[ptFlags] + '/hedgewars', ifNone); |
|
208 if flagsurf = nil then |
|
209 flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone); |
|
210 TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true); |
210 TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true); |
211 |
211 |
212 case maxLevel of |
212 case maxLevel of |
213 1: copyToXY(SpritesData[sprBotlevels].Surface, flagsurf, 0, 0); |
213 1: copyToXY(SpritesData[sprBotlevels].Surface, flagsurf, 0, 0); |
214 2: copyToXYFromRect(SpritesData[sprBotlevels].Surface, flagsurf, 5, 2, 17, 13, 5, 2); |
214 2: copyToXYFromRect(SpritesData[sprBotlevels].Surface, flagsurf, 5, 2, 17, 13, 5, 2); |
249 else |
249 else |
250 LoadHedgehogHat(Gear, Hat); |
250 LoadHedgehogHat(Gear, Hat); |
251 end |
251 end |
252 end; |
252 end; |
253 end; |
253 end; |
254 MissionIcons:= LoadImage(UserPathz[ptGraphics] + '/missions', ifNone); |
254 MissionIcons:= LoadDataImage(ptGraphics, 'missions', ifCritical); |
255 if MissionIcons = nil then |
|
256 MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical); |
|
257 iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask); |
255 iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask); |
258 if iconsurf <> nil then |
256 if iconsurf <> nil then |
259 begin |
257 begin |
260 r.x:= 0; |
258 r.x:= 0; |
261 r.y:= 0; |
259 r.y:= 0; |
289 if TeamsArray[t] <> nil then |
287 if TeamsArray[t] <> nil then |
290 with TeamsArray[t]^ do |
288 with TeamsArray[t]^ do |
291 begin |
289 begin |
292 if GraveName = '' then |
290 if GraveName = '' then |
293 GraveName:= 'Statue'; |
291 GraveName:= 'Statue'; |
294 texsurf:= LoadImage(UserPathz[ptGraves] + '/' + GraveName, ifTransparent); |
292 texsurf:= LoadDataImageAltFile(ptGraves, GraveName, 'Statue', ifCritical or ifTransparent); |
295 if texsurf = nil then |
|
296 texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent); |
|
297 if texsurf = nil then |
|
298 texsurf:= LoadImage(UserPathz[ptGraves] + '/Statue', ifTransparent); |
|
299 if texsurf = nil then |
|
300 texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent); |
|
301 GraveTex:= Surface2Tex(texsurf, false); |
293 GraveTex:= Surface2Tex(texsurf, false); |
302 SDL_FreeSurface(texsurf) |
294 SDL_FreeSurface(texsurf) |
303 end |
295 end |
304 end; |
296 end; |
305 |
297 |
340 (((cReducedQuality and rqPlainSplash) = 0) or ((not (ii in [sprSplash, sprDroplet, sprSDSplash, sprSDDroplet])))) and |
332 (((cReducedQuality and rqPlainSplash) = 0) or ((not (ii in [sprSplash, sprDroplet, sprSDSplash, sprSDDroplet])))) and |
341 (((cReducedQuality and rqKillFlakes) = 0) or (Theme = 'Snow') or (Theme = 'Christmas') or ((not (ii in [sprFlake, sprSDFlake])))) and |
333 (((cReducedQuality and rqKillFlakes) = 0) or (Theme = 'Snow') or (Theme = 'Christmas') or ((not (ii in [sprFlake, sprSDFlake])))) and |
342 ((cCloudsNumber > 0) or (ii <> sprCloud)) and |
334 ((cCloudsNumber > 0) or (ii <> sprCloud)) and |
343 ((vobCount > 0) or (ii <> sprFlake)) then |
335 ((vobCount > 0) or (ii <> sprFlake)) then |
344 begin |
336 begin |
345 if AltPath = ptNone then |
337 if reload then |
346 if ii in [sprHorizont, sprHorizontL, sprHorizontR, sprSky, sprSkyL, sprSkyR, sprChunk] then // FIXME: hack |
338 tmpsurf:= Surface |
347 begin |
|
348 if not reload then |
|
349 begin |
|
350 tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
|
351 if tmpsurf = nil then |
|
352 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent) |
|
353 end |
|
354 else |
|
355 tmpsurf:= Surface |
|
356 end |
|
357 else |
|
358 begin |
|
359 if not reload then |
|
360 begin |
|
361 tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
|
362 if tmpsurf = nil then |
|
363 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical) |
|
364 end |
|
365 else |
|
366 tmpsurf:= Surface |
|
367 end |
|
368 else |
339 else |
369 begin |
340 begin |
370 if not reload then |
341 imflags := (ifAlpha or ifTransparent); |
371 begin |
342 |
372 tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
343 // these sprites are optional |
373 if tmpsurf = nil then |
344 if not (ii in [sprHorizont, sprHorizontL, sprHorizontR, sprSky, sprSkyL, sprSkyR, sprChunk]) then // FIXME: hack |
374 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
345 imflags := (imflags or ifCritical); |
375 if tmpsurf = nil then |
346 |
376 tmpsurf:= LoadImage(UserPathz[AltPath] + '/' + FileName, ifAlpha or ifTransparent); |
347 // load the image |
377 if tmpsurf = nil then |
348 tmpsurf := LoadDataImageAltPath(Path, AltPath, FileName, imflags) |
378 tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent) |
|
379 end |
|
380 else |
|
381 tmpsurf:= Surface |
|
382 end; |
349 end; |
383 |
350 |
384 if tmpsurf <> nil then |
351 if tmpsurf <> nil then |
385 begin |
352 begin |
386 if getImageDimensions then |
353 if getImageDimensions then |
625 WriteLnToConsole(msgOK + ' (' + inttostr(tmpsurf^.w) + 'x' + inttostr(tmpsurf^.h) + ')'); |
590 WriteLnToConsole(msgOK + ' (' + inttostr(tmpsurf^.w) + 'x' + inttostr(tmpsurf^.h) + ')'); |
626 |
591 |
627 LoadImage:= tmpsurf //Result |
592 LoadImage:= tmpsurf //Result |
628 end; |
593 end; |
629 |
594 |
|
595 |
|
596 function LoadDataImage(const path: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
|
597 var tmpsurf: PSDL_Surface; |
|
598 begin |
|
599 // check for file in user dir (never critical) |
|
600 tmpsurf:= LoadImage(UserPathz[path] + '/' + filename, imageFlags and (not ifCritical)); |
|
601 |
|
602 // if unsuccessful check data dir |
|
603 if (tmpsurf = nil) then |
|
604 tmpsurf:= LoadImage(Pathz[path] + '/' + filename, imageFlags); |
|
605 |
|
606 LoadDataImage:= tmpsurf; |
|
607 end; |
|
608 |
|
609 |
|
610 function LoadDataImageAltPath(const path, altPath: TPathType; const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
|
611 var tmpsurf: PSDL_Surface; |
|
612 begin |
|
613 // if there is no alternative path, just forward and return result |
|
614 if (altPath = ptNone) then |
|
615 exit(LoadDataImage(path, filename, imageFlags)); |
|
616 |
|
617 // since we have a fallback path this search isn't critical yet |
|
618 tmpsurf:= LoadDataImage(path, filename, imageFlags and (not ifCritical)); |
|
619 |
|
620 // if image still not found try alternative path |
|
621 if (tmpsurf = nil) then |
|
622 tmpsurf:= LoadDataImage(altPath, filename, imageFlags); |
|
623 |
|
624 LoadDataImageAltPath:= tmpsurf; |
|
625 end; |
|
626 |
|
627 function LoadDataImageAltFile(const path: TPathType; const filename, altFile: shortstring; imageFlags: LongInt): PSDL_Surface; |
|
628 var tmpsurf: PSDL_Surface; |
|
629 begin |
|
630 // if there is no alternative filename, just forward and return result |
|
631 if (altFile = '') then |
|
632 exit(LoadDataImage(path, filename, imageFlags)); |
|
633 |
|
634 // since we have a fallback filename this search isn't critical yet |
|
635 tmpsurf:= LoadDataImage(path, filename, imageFlags and (not ifCritical)); |
|
636 |
|
637 // if image still not found try alternative filename |
|
638 if (tmpsurf = nil) then |
|
639 tmpsurf:= LoadDataImage(path, altFile, imageFlags); |
|
640 |
|
641 LoadDataImageAltFile:= tmpsurf; |
|
642 end; |
|
643 |
630 procedure LoadHedgehogHat(HHGear: PGear; newHat: shortstring); |
644 procedure LoadHedgehogHat(HHGear: PGear; newHat: shortstring); |
631 var texsurf: PSDL_Surface; |
645 var texsurf: PSDL_Surface; |
632 begin |
646 begin |
633 texsurf:= LoadImage(UserPathz[ptHats] + '/' + newHat, ifNone); |
647 texsurf:= LoadDataImage(ptHats, newHat, ifNone); |
634 if texsurf = nil then |
|
635 texsurf:= LoadImage(Pathz[ptHats] + '/' + newHat, ifNone); |
|
636 |
648 |
637 // only do something if the hat could be loaded |
649 // only do something if the hat could be loaded |
638 if texsurf <> nil then |
650 if texsurf <> nil then |
639 begin |
651 begin |
640 // free the mem of any previously assigned texture |
652 // free the mem of any previously assigned texture |
862 texsurf: PSDL_Surface; |
874 texsurf: PSDL_Surface; |
863 begin |
875 begin |
864 if Step = 0 then |
876 if Step = 0 then |
865 begin |
877 begin |
866 WriteToConsole(msgLoading + 'progress sprite: '); |
878 WriteToConsole(msgLoading + 'progress sprite: '); |
867 texsurf:= LoadImage(UserPathz[ptGraphics] + '/Progress', ifTransparent); |
879 texsurf:= LoadDataImage(ptGraphics, 'Progress', ifCritical or ifTransparent); |
868 if texsurf = nil then |
|
869 texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent); |
|
870 |
880 |
871 ProgrTex:= Surface2Tex(texsurf, false); |
881 ProgrTex:= Surface2Tex(texsurf, false); |
872 |
882 |
873 squaresize:= texsurf^.w shr 1; |
883 squaresize:= texsurf^.w shr 1; |
874 numsquares:= texsurf^.h div squaresize; |
884 numsquares:= texsurf^.h div squaresize; |
1133 WriteToConsole('Init SDL_image... '); |
1143 WriteToConsole('Init SDL_image... '); |
1134 SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true); |
1144 SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true); |
1135 WriteLnToConsole(msgOK); |
1145 WriteLnToConsole(msgOK); |
1136 // load engine icon |
1146 // load engine icon |
1137 {$IFNDEF DARWIN} |
1147 {$IFNDEF DARWIN} |
1138 ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine', ifIgnoreCaps); |
1148 ico:= LoadDataImage(ptGraphics, 'hwengine', ifIgnoreCaps); |
1139 if ico = nil then |
|
1140 ico:= LoadImage(Pathz[ptGraphics] + '/hwengine', ifIgnoreCaps); |
|
1141 if ico <> nil then |
1149 if ico <> nil then |
1142 begin |
1150 begin |
1143 SDL_WM_SetIcon(ico, 0); |
1151 SDL_WM_SetIcon(ico, 0); |
1144 SDL_FreeSurface(ico) |
1152 SDL_FreeSurface(ico) |
1145 end; |
1153 end; |