hedgewars/uStore.pas
changeset 5238 46ddaf14509d
parent 5215 d4c529624460
child 5284 34abd278344e
equal deleted inserted replaced
5237:963d787a25c2 5238:46ddaf14509d
    80 var t: LongInt;
    80 var t: LongInt;
    81     tmpsurf, texsurf: PSDL_Surface;
    81     tmpsurf, texsurf: PSDL_Surface;
    82     Color, i: Longword;
    82     Color, i: Longword;
    83     s : shortstring;
    83     s : shortstring;
    84 begin
    84 begin
    85 s:= Pathz[ptGraphics] + '/' + cCHFileName;
    85 s:= UserPathz[ptGraphics] + '/' + cCHFileName;
       
    86 if not FileExists(s+'.png') then s:= Pathz[ptGraphics] + '/' + cCHFileName;
    86 tmpsurf:= LoadImage(s, ifAlpha or ifCritical);
    87 tmpsurf:= LoadImage(s, ifAlpha or ifCritical);
    87 
    88 
    88 for t:= 0 to Pred(TeamsCount) do
    89 for t:= 0 to Pred(TeamsCount) do
    89     with TeamsArray[t]^ do
    90     with TeamsArray[t]^ do
    90     begin
    91     begin
   166         if (Hedgehogs[0].Gear <> nil) and (Hedgehogs[0].BotLevel > 0) then
   167         if (Hedgehogs[0].Gear <> nil) and (Hedgehogs[0].BotLevel > 0) then
   167             if Flag = 'hedgewars' then Flag:= 'cpu'
   168             if Flag = 'hedgewars' then Flag:= 'cpu'
   168         else if Flag = 'cpu' then
   169         else if Flag = 'cpu' then
   169             Flag:= 'hedgewars';
   170             Flag:= 'hedgewars';
   170 
   171 
   171         flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone);
   172         flagsurf:= LoadImage(UserPathz[ptFlags] + '/' + Flag, ifNone);
   172         if flagsurf = nil then
   173         if flagsurf = nil then flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone);
   173             flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone);
   174         if flagsurf = nil then flagsurf:= LoadImage(UserPathz[ptFlags] + '/hedgewars', ifNone);
       
   175         if flagsurf = nil then flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone);
   174         TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true);
   176         TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true);
   175         copyToXY(flagsurf, texsurf, 2, 2);
   177         copyToXY(flagsurf, texsurf, 2, 2);
   176         SDL_FreeSurface(flagsurf);
   178         SDL_FreeSurface(flagsurf);
   177         flagsurf:= nil;
   179         flagsurf:= nil;
   178 
   180 
   202                         else
   204                         else
   203                             LoadHedgehogHat(Gear, Hat);
   205                             LoadHedgehogHat(Gear, Hat);
   204                         end
   206                         end
   205                     end;
   207                     end;
   206         end;
   208         end;
   207     MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical);
   209     MissionIcons:= LoadImage(UserPathz[ptGraphics] + '/missions', ifNone);
       
   210     if MissionIcons = nil then MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical);
   208     iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask);
   211     iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask);
   209     if iconsurf <> nil then
   212     if iconsurf <> nil then
   210         begin
   213         begin
   211         r.x:= 0;
   214         r.x:= 0;
   212         r.y:= 0;
   215         r.y:= 0;
   239     for t:= 0 to Pred(TeamsCount) do
   242     for t:= 0 to Pred(TeamsCount) do
   240     if TeamsArray[t] <> nil then
   243     if TeamsArray[t] <> nil then
   241         with TeamsArray[t]^ do
   244         with TeamsArray[t]^ do
   242             begin
   245             begin
   243             if GraveName = '' then GraveName:= 'Statue';
   246             if GraveName = '' then GraveName:= 'Statue';
   244             texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent);
   247             texsurf:= LoadImage(UserPathz[ptGraves] + '/' + GraveName, ifTransparent);
       
   248             if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent);
       
   249             if texsurf = nil then texsurf:= LoadImage(UserPathz[ptGraves] + '/Statue', ifTransparent);
   245             if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent);
   250             if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent);
   246             GraveTex:= Surface2Tex(texsurf, false);
   251             GraveTex:= Surface2Tex(texsurf, false);
   247             SDL_FreeSurface(texsurf)
   252             SDL_FreeSurface(texsurf)
   248             end
   253             end
   249     end;
   254     end;
   256 begin
   261 begin
   257 
   262 
   258 for fi:= Low(THWFont) to High(THWFont) do
   263 for fi:= Low(THWFont) to High(THWFont) do
   259     with Fontz[fi] do
   264     with Fontz[fi] do
   260         begin
   265         begin
   261         s:= Pathz[ptFonts] + '/' + Name;
   266         s:= UserPathz[ptFonts] + '/' + Name;
       
   267         if not FileExists(s) then s:= Pathz[ptFonts] + '/' + Name;
   262         WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... ');
   268         WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... ');
   263         Handle:= TTF_OpenFont(Str2PChar(s), Height);
   269         Handle:= TTF_OpenFont(Str2PChar(s), Height);
   264         SDLTry(Handle <> nil, true);
   270         SDLTry(Handle <> nil, true);
   265         TTF_SetFontStyle(Handle, style);
   271         TTF_SetFontStyle(Handle, style);
   266         WriteLnToConsole(msgOK)
   272         WriteLnToConsole(msgOK)
   279            (((cReducedQuality and rqPlainSplash) = 0) or ((not (ii in [sprSplash, sprDroplet, sprSDSplash, sprSDDroplet])))) and
   285            (((cReducedQuality and rqPlainSplash) = 0) or ((not (ii in [sprSplash, sprDroplet, sprSDSplash, sprSDDroplet])))) and
   280            (((cReducedQuality and rqKillFlakes) = 0) or (Theme = 'Snow') or (Theme = 'Christmas') or ((not (ii in [sprFlake, sprSDFlake])))) then
   286            (((cReducedQuality and rqKillFlakes) = 0) or (Theme = 'Snow') or (Theme = 'Christmas') or ((not (ii in [sprFlake, sprSDFlake])))) then
   281         begin
   287         begin
   282             if AltPath = ptNone then
   288             if AltPath = ptNone then
   283                 if ii in [sprHorizontL, sprHorizontR, sprSkyL, sprSkyR] then // FIXME: hack
   289                 if ii in [sprHorizontL, sprHorizontR, sprSkyL, sprSkyR] then // FIXME: hack
   284                     tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent)
   290                     begin
       
   291                     tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
       
   292                     if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent)
       
   293                     end
   285                 else
   294                 else
   286                     tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical)
   295                     begin
       
   296                     tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
       
   297                     if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical)
       
   298                     end
   287             else begin
   299             else begin
   288                 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
   300                 tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
   289                 if tmpsurf = nil then
   301                 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
   290                     tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent);
   302                 if tmpsurf = nil then tmpsurf:= LoadImage(UserPathz[AltPath] + '/' + FileName, ifAlpha or ifTransparent);
       
   303                 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent);
   291                 end;
   304                 end;
   292 
   305 
   293             if tmpsurf <> nil then
   306             if tmpsurf <> nil then
   294             begin
   307             begin
   295                 if getImageDimensions then
   308                 if getImageDimensions then
   322                 Surface:= nil
   335                 Surface:= nil
   323         end;
   336         end;
   324 
   337 
   325 AddProgress;
   338 AddProgress;
   326 
   339 
   327 tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent);
   340 tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifTransparent);
       
   341 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent);
   328 HHTexture:= Surface2Tex(tmpsurf, false);
   342 HHTexture:= Surface2Tex(tmpsurf, false);
   329 SDL_FreeSurface(tmpsurf);
   343 SDL_FreeSurface(tmpsurf);
   330 
   344 
   331 InitHealth;
   345 InitHealth;
   332 
   346 
   473 end;
   487 end;
   474 
   488 
   475 procedure LoadHedgehogHat(HHGear: PGear; newHat: shortstring);
   489 procedure LoadHedgehogHat(HHGear: PGear; newHat: shortstring);
   476 var texsurf: PSDL_Surface;
   490 var texsurf: PSDL_Surface;
   477 begin
   491 begin
   478     texsurf:= LoadImage(Pathz[ptHats] + '/' + newHat, ifNone);
   492     texsurf:= LoadImage(UserPathz[ptHats] + '/' + newHat, ifNone);
       
   493     if texsurf = nil then texsurf:= LoadImage(Pathz[ptHats] + '/' + newHat, ifNone);
   479 
   494 
   480     // only do something if the hat could be loaded
   495     // only do something if the hat could be loaded
   481     if texsurf <> nil then
   496     if texsurf <> nil then
   482         begin
   497         begin
   483         // free the mem of any previously assigned texture
   498         // free the mem of any previously assigned texture
   665     texsurf: PSDL_Surface;
   680     texsurf: PSDL_Surface;
   666 begin
   681 begin
   667     if Step = 0 then
   682     if Step = 0 then
   668     begin
   683     begin
   669         WriteToConsole(msgLoading + 'progress sprite: ');
   684         WriteToConsole(msgLoading + 'progress sprite: ');
   670         texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent);
   685         texsurf:= LoadImage(UserPathz[ptGraphics] + '/Progress', ifTransparent);
       
   686         if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent);
   671 
   687 
   672         ProgrTex:= Surface2Tex(texsurf, false);
   688         ProgrTex:= Surface2Tex(texsurf, false);
   673 
   689 
   674         squaresize:= texsurf^.w shr 1;
   690         squaresize:= texsurf^.w shr 1;
   675         numsquares:= texsurf^.h div squaresize;
   691         numsquares:= texsurf^.h div squaresize;
   904     SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
   920     SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
   905     WriteLnToConsole(msgOK);
   921     WriteLnToConsole(msgOK);
   906 {$ENDIF}
   922 {$ENDIF}
   907     // load engine icon
   923     // load engine icon
   908 {$IFDEF DARWIN}
   924 {$IFDEF DARWIN}
   909     ico:= LoadImage(Pathz[ptGraphics] + '/hwengine_mac', ifIgnoreCaps);
   925     ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine_mac', ifIgnoreCaps);
       
   926     if ico = nil then ico:= LoadImage(Pathz[ptGraphics] + '/hwengine_mac', ifIgnoreCaps);
   910 {$ELSE}
   927 {$ELSE}
   911     ico:= LoadImage(Pathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
   928     ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
       
   929     if ico = nil then ico:= LoadImage(Pathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
   912 {$ENDIF}
   930 {$ENDIF}
   913     if ico <> nil then
   931     if ico <> nil then
   914     begin
   932     begin
   915         SDL_WM_SetIcon(ico, 0);
   933         SDL_WM_SetIcon(ico, 0);
   916         SDL_FreeSurface(ico)
   934         SDL_FreeSurface(ico)