hedgewars/uStore.pas
changeset 2948 3f21a9dc93d0
parent 2910 d5051cc8a313
child 2958 e6f7620da87e
equal deleted inserted replaced
2947:803b277e4894 2948:3f21a9dc93d0
    20 
    20 
    21 unit uStore;
    21 unit uStore;
    22 interface
    22 interface
    23 uses sysutils, uConsts, uTeams, SDLh, uFloat,
    23 uses sysutils, uConsts, uTeams, SDLh, uFloat,
    24 {$IFDEF GLES11}
    24 {$IFDEF GLES11}
    25 	gles11;
    25     gles11;
    26 {$ELSE}
    26 {$ELSE}
    27 	GL, GLext;
    27     GL, GLext;
    28 {$ENDIF}
    28 {$ENDIF}
    29 
    29 
    30 
    30 
    31 var PixelFormat: PSDL_PixelFormat;
    31 var PixelFormat: PSDL_PixelFormat;
    32     SDLPrimSurface: PSDL_Surface;
    32     SDLPrimSurface: PSDL_Surface;
   173 end;
   173 end;
   174 
   174 
   175 procedure StoreLoad;
   175 procedure StoreLoad;
   176 var s: shortstring;
   176 var s: shortstring;
   177 
   177 
   178 	procedure WriteNames(Font: THWFont);
   178     procedure WriteNames(Font: THWFont);
   179 	var t: LongInt;
   179     var t: LongInt;
   180 		i: LongInt;
   180         i: LongInt;
   181 		r, rr: TSDL_Rect;
   181         r, rr: TSDL_Rect;
   182 		drY: LongInt;
   182         drY: LongInt;
   183 		texsurf, flagsurf, iconsurf: PSDL_Surface;
   183         texsurf, flagsurf, iconsurf: PSDL_Surface;
   184 	begin
   184     begin
   185 	r.x:= 0;
   185     r.x:= 0;
   186 	r.y:= 0;
   186     r.y:= 0;
   187 	drY:= - 4;
   187     drY:= - 4;
   188 	for t:= 0 to Pred(TeamsCount) do
   188     for t:= 0 to Pred(TeamsCount) do
   189 		with TeamsArray[t]^ do
   189         with TeamsArray[t]^ do
   190 		begin
   190         begin
   191 		NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font);
   191         NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font);
   192 
   192 
   193 		r.w:= cTeamHealthWidth + 5;
   193         r.w:= cTeamHealthWidth + 5;
   194 		r.h:= NameTagTex^.h;
   194         r.h:= NameTagTex^.h;
   195 
   195 
   196 		texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask);
   196         texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask);
   197 		TryDo(texsurf <> nil, errmsgCreateSurface, true);
   197         TryDo(texsurf <> nil, errmsgCreateSurface, true);
   198 		TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
   198         TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
   199 
   199 
   200 		DrawRoundRect(@r, cWhiteColor, cNearBlackColorChannels.value, texsurf, true);
   200         DrawRoundRect(@r, cWhiteColor, cNearBlackColorChannels.value, texsurf, true);
   201 		rr:= r;
   201         rr:= r;
   202 		inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4);
   202         inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4);
   203 		DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false);
   203         DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false);
   204 		HealthTex:= Surface2Tex(texsurf, false);
   204         HealthTex:= Surface2Tex(texsurf, false);
   205 		SDL_FreeSurface(texsurf);
   205         SDL_FreeSurface(texsurf);
   206 
   206 
   207 		r.x:= 0;
   207         r.x:= 0;
   208 		r.y:= 0;
   208         r.y:= 0;
   209 		r.w:= 32;
   209         r.w:= 32;
   210 		r.h:= 32;
   210         r.h:= 32;
   211 		texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask);
   211         texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask);
   212 		TryDo(texsurf <> nil, errmsgCreateSurface, true);
   212         TryDo(texsurf <> nil, errmsgCreateSurface, true);
   213 		TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
   213         TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
   214 
   214 
   215 		r.w:= 26;
   215         r.w:= 26;
   216 		r.h:= 19;
   216         r.h:= 19;
   217 
   217 
   218 		DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true);
   218         DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true);
   219 
   219 
   220 		// overwrite flag for cpu teams and keep players from using it
   220         // overwrite flag for cpu teams and keep players from using it
   221 		if (Hedgehogs[0].Gear <> nil) and (Hedgehogs[0].BotLevel > 0) then
   221         if (Hedgehogs[0].Gear <> nil) and (Hedgehogs[0].BotLevel > 0) then
   222 			Flag:= 'cpu'
   222             Flag:= 'cpu'
   223 		else if Flag = 'cpu' then
   223         else if Flag = 'cpu' then
   224 			Flag:= 'hedgewars';
   224             Flag:= 'hedgewars';
   225 		
   225         
   226 		flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone);
   226         flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone);
   227 		if flagsurf = nil then
   227         if flagsurf = nil then
   228 			flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone);
   228             flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone);
   229 		TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true);
   229         TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true);
   230 		copyToXY(flagsurf, texsurf, 2, 2);
   230         copyToXY(flagsurf, texsurf, 2, 2);
   231 		SDL_FreeSurface(flagsurf);
   231         SDL_FreeSurface(flagsurf);
   232 		
   232         
   233 		// restore black border pixels inside the flag
   233         // restore black border pixels inside the flag
   234 		PLongwordArray(texsurf^.pixels)^[32 * 2 +  2]:= cNearBlackColor;
   234         PLongwordArray(texsurf^.pixels)^[32 * 2 +  2]:= cNearBlackColor;
   235 		PLongwordArray(texsurf^.pixels)^[32 * 2 + 23]:= cNearBlackColor;
   235         PLongwordArray(texsurf^.pixels)^[32 * 2 + 23]:= cNearBlackColor;
   236 		PLongwordArray(texsurf^.pixels)^[32 * 16 +  2]:= cNearBlackColor;
   236         PLongwordArray(texsurf^.pixels)^[32 * 16 +  2]:= cNearBlackColor;
   237 		PLongwordArray(texsurf^.pixels)^[32 * 16 + 23]:= cNearBlackColor;
   237         PLongwordArray(texsurf^.pixels)^[32 * 16 + 23]:= cNearBlackColor;
   238 
   238 
   239 		FlagTex:= Surface2Tex(texsurf, false);
   239         FlagTex:= Surface2Tex(texsurf, false);
   240 		
   240         
   241 		dec(drY, r.h + 2);
   241         dec(drY, r.h + 2);
   242 		DrawHealthY:= drY;
   242         DrawHealthY:= drY;
   243 		for i:= 0 to 7 do
   243         for i:= 0 to 7 do
   244 			with Hedgehogs[i] do
   244             with Hedgehogs[i] do
   245 				if Gear <> nil then
   245                 if Gear <> nil then
   246 					begin
   246                     begin
   247 					NameTagTex:= RenderStringTex(Name, Clan^.Color, CheckCJKFont(Name,fnt16));
   247                     NameTagTex:= RenderStringTex(Name, Clan^.Color, CheckCJKFont(Name,fnt16));
   248 					if Hat <> 'NoHat' then
   248                     if Hat <> 'NoHat' then
   249 						begin
   249                         begin
   250                         texsurf:= nil;
   250                         texsurf:= nil;
   251                         if (Length(Hat) > 39) and (Copy(Hat,1,8) = 'Reserved') and (Copy(Hat,9,32) = PlayerHash) then
   251                         if (Length(Hat) > 39) and (Copy(Hat,1,8) = 'Reserved') and (Copy(Hat,9,32) = PlayerHash) then
   252 						   texsurf:= LoadImage(Pathz[ptHats] + '/Reserved/' + Copy(Hat,9,Length(s)-8), ifNone)
   252                            texsurf:= LoadImage(Pathz[ptHats] + '/Reserved/' + Copy(Hat,9,Length(s)-8), ifNone)
   253                         else
   253                         else
   254 						   texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, ifNone);
   254                            texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, ifNone);
   255 						if texsurf <> nil then
   255                         if texsurf <> nil then
   256 							begin
   256                             begin
   257 							HatTex:= Surface2Tex(texsurf, true);
   257                             HatTex:= Surface2Tex(texsurf, true);
   258 							SDL_FreeSurface(texsurf)
   258                             SDL_FreeSurface(texsurf)
   259 							end
   259                             end
   260 						end
   260                         end
   261 					end;
   261                     end;
   262 		end;
   262         end;
   263 	MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical);
   263     MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical);
   264 	iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask);
   264     iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask);
   265 	if iconsurf <> nil then
   265     if iconsurf <> nil then
   266 		begin
   266         begin
   267 		r.x:= 0;
   267         r.x:= 0;
   268 		r.y:= 0;
   268         r.y:= 0;
   269 		r.w:= 28;
   269         r.w:= 28;
   270 		r.h:= 28;
   270         r.h:= 28;
   271 		DrawRoundRect(@r, cWhiteColor, cNearBlackColor, iconsurf, true);
   271         DrawRoundRect(@r, cWhiteColor, cNearBlackColor, iconsurf, true);
   272 		ropeIconTex:= Surface2Tex(iconsurf, false);
   272         ropeIconTex:= Surface2Tex(iconsurf, false);
   273 		SDL_FreeSurface(iconsurf)
   273         SDL_FreeSurface(iconsurf)
   274 		end;
   274         end;
   275 	end;
   275     end;
   276 
   276 
   277 	procedure MakeCrossHairs;
   277     procedure MakeCrossHairs;
   278 	var t: LongInt;
   278     var t: LongInt;
   279 		tmpsurf, texsurf: PSDL_Surface;
   279         tmpsurf, texsurf: PSDL_Surface;
   280 		Color, i: Longword;
   280         Color, i: Longword;
   281 	begin
   281     begin
   282 	s:= Pathz[ptGraphics] + '/' + cCHFileName;
   282     s:= Pathz[ptGraphics] + '/' + cCHFileName;
   283 	tmpsurf:= LoadImage(s, ifAlpha or ifCritical);
   283     tmpsurf:= LoadImage(s, ifAlpha or ifCritical);
   284 
   284 
   285 	for t:= 0 to Pred(TeamsCount) do
   285     for t:= 0 to Pred(TeamsCount) do
   286 		with TeamsArray[t]^ do
   286         with TeamsArray[t]^ do
   287 		begin
   287         begin
   288 		texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask);
   288         texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask);
   289 		TryDo(texsurf <> nil, errmsgCreateSurface, true);
   289         TryDo(texsurf <> nil, errmsgCreateSurface, true);
   290 
   290 
   291 		Color:= Clan^.Color;
   291         Color:= Clan^.Color;
   292 		Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF);
   292         Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF);
   293 		SDL_FillRect(texsurf, nil, Color);
   293         SDL_FillRect(texsurf, nil, Color);
   294 
   294 
   295 		SDL_UpperBlit(tmpsurf, nil, texsurf, nil);
   295         SDL_UpperBlit(tmpsurf, nil, texsurf, nil);
   296 
   296 
   297 		TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true);
   297         TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true);
   298 
   298 
   299 		if SDL_MustLock(texsurf) then
   299         if SDL_MustLock(texsurf) then
   300 			SDLTry(SDL_LockSurface(texsurf) >= 0, true);
   300             SDLTry(SDL_LockSurface(texsurf) >= 0, true);
   301 
   301 
   302 		// make black pixel be alpha-transparent
   302         // make black pixel be alpha-transparent
   303 		for i:= 0 to texsurf^.w * texsurf^.h - 1 do
   303         for i:= 0 to texsurf^.w * texsurf^.h - 1 do
   304 			if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= 0;
   304             if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= 0;
   305 
   305 
   306 		if SDL_MustLock(texsurf) then
   306         if SDL_MustLock(texsurf) then
   307 			SDL_UnlockSurface(texsurf);
   307             SDL_UnlockSurface(texsurf);
   308 
   308 
   309 		CrosshairTex:= Surface2Tex(texsurf, false);
   309         CrosshairTex:= Surface2Tex(texsurf, false);
   310 		SDL_FreeSurface(texsurf)
   310         SDL_FreeSurface(texsurf)
   311 		end;
   311         end;
   312 
   312 
   313 	SDL_FreeSurface(tmpsurf)
   313     SDL_FreeSurface(tmpsurf)
   314 	end;
   314     end;
   315 
   315 
   316 	procedure InitHealth;
   316     procedure InitHealth;
   317 	var i, t: LongInt;
   317     var i, t: LongInt;
   318 	begin
   318     begin
   319 	for t:= 0 to Pred(TeamsCount) do
   319     for t:= 0 to Pred(TeamsCount) do
   320 		if TeamsArray[t] <> nil then
   320         if TeamsArray[t] <> nil then
   321 			with TeamsArray[t]^ do
   321             with TeamsArray[t]^ do
   322 				begin
   322                 begin
   323 				for i:= 0 to cMaxHHIndex do
   323                 for i:= 0 to cMaxHHIndex do
   324 					if Hedgehogs[i].Gear <> nil then
   324                     if Hedgehogs[i].Gear <> nil then
   325 						RenderHealth(Hedgehogs[i]);
   325                         RenderHealth(Hedgehogs[i]);
   326 				end
   326                 end
   327 	end;
   327     end;
   328 
   328 
   329 	procedure LoadGraves;
   329     procedure LoadGraves;
   330 	var t: LongInt;
   330     var t: LongInt;
   331 		texsurf: PSDL_Surface;
   331         texsurf: PSDL_Surface;
   332 	begin
   332     begin
   333 	for t:= 0 to Pred(TeamsCount) do
   333     for t:= 0 to Pred(TeamsCount) do
   334 	if TeamsArray[t] <> nil then
   334     if TeamsArray[t] <> nil then
   335 		with TeamsArray[t]^ do
   335         with TeamsArray[t]^ do
   336 			begin
   336             begin
   337 			if GraveName = '' then GraveName:= 'Simple';
   337             if GraveName = '' then GraveName:= 'Simple';
   338 			texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifCritical or ifTransparent);
   338             texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifCritical or ifTransparent);
   339 			GraveTex:= Surface2Tex(texsurf, false);
   339             GraveTex:= Surface2Tex(texsurf, false);
   340 			SDL_FreeSurface(texsurf)
   340             SDL_FreeSurface(texsurf)
   341 			end
   341             end
   342 	end;
   342     end;
   343 
   343 
   344 var ii: TSprite;
   344 var ii: TSprite;
   345     fi: THWFont;
   345     fi: THWFont;
   346     ai: TAmmoType;
   346     ai: TAmmoType;
   347     tmpsurf: PSDL_Surface;
   347     tmpsurf: PSDL_Surface;
   348     i: LongInt;
   348     i: LongInt;
   349 begin
   349 begin
   350 
   350 
   351 for fi:= Low(THWFont) to High(THWFont) do
   351 for fi:= Low(THWFont) to High(THWFont) do
   352 	with Fontz[fi] do
   352     with Fontz[fi] do
   353 		begin
   353         begin
   354 		s:= Pathz[ptFonts] + '/' + Name;
   354         s:= Pathz[ptFonts] + '/' + Name;
   355 		WriteToConsole(msgLoading + s + '... ');
   355         WriteToConsole(msgLoading + s + '... ');
   356 		Handle:= TTF_OpenFont(Str2PChar(s), Height);
   356         Handle:= TTF_OpenFont(Str2PChar(s), Height);
   357 		SDLTry(Handle <> nil, true);
   357         SDLTry(Handle <> nil, true);
   358 		TTF_SetFontStyle(Handle, style);
   358         TTF_SetFontStyle(Handle, style);
   359 		WriteLnToConsole(msgOK)
   359         WriteLnToConsole(msgOK)
   360 		end;
   360         end;
   361 
   361 
   362 WriteNames(fnt16);
   362 WriteNames(fnt16);
   363 MakeCrossHairs;
   363 MakeCrossHairs;
   364 LoadGraves;
   364 LoadGraves;
   365 
   365 
   366 AddProgress;
   366 AddProgress;
   367 for ii:= Low(TSprite) to High(TSprite) do
   367 for ii:= Low(TSprite) to High(TSprite) do
   368 	with SpritesData[ii] do
   368     with SpritesData[ii] do
   369         // FIXME - add a sprite attribute
   369         // FIXME - add a sprite attribute
   370         if (not cReducedQuality) or (not (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR, sprFlake])) then // FIXME: hack
   370         if (not cReducedQuality) or (not (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR, sprFlake])) then // FIXME: hack
   371 		begin
   371         begin
   372 			if AltPath = ptNone then
   372             if AltPath = ptNone then
   373 				if ii in [sprHorizontL, sprHorizontR, sprSkyL, sprSkyR] then // FIXME: hack
   373                 if ii in [sprHorizontL, sprHorizontR, sprSkyL, sprSkyR] then // FIXME: hack
   374 					tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifLowRes)
   374                     tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifLowRes)
   375 				else
   375                 else
   376 					tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical or ifLowRes)
   376                     tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical or ifLowRes)
   377 			else begin
   377             else begin
   378 				tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
   378                 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
   379 				if tmpsurf = nil then
   379                 if tmpsurf = nil then
   380 					tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent);
   380                     tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent);
   381 				end;
   381                 end;
   382 
   382 
   383 			if tmpsurf <> nil then
   383             if tmpsurf <> nil then
   384 			begin
   384             begin
   385 				if imageWidth = 0 then imageWidth:= tmpsurf^.w;
   385                 if imageWidth = 0 then imageWidth:= tmpsurf^.w;
   386 				if imageHeight = 0 then imageHeight:= tmpsurf^.h;
   386                 if imageHeight = 0 then imageHeight:= tmpsurf^.h;
   387 				if Width = 0 then Width:= tmpsurf^.w;
   387                 if Width = 0 then Width:= tmpsurf^.w;
   388 				if Height = 0 then Height:= tmpsurf^.h;
   388                 if Height = 0 then Height:= tmpsurf^.h;
   389 				if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then
   389                 if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then
   390 					Texture:= Surface2Tex(tmpsurf, true)
   390                     Texture:= Surface2Tex(tmpsurf, true)
   391 				else
   391                 else
   392 					begin
   392                     begin
   393 					Texture:= Surface2Tex(tmpsurf, false);
   393                     Texture:= Surface2Tex(tmpsurf, false);
   394 					if (ii = sprWater) and not cReducedQuality then // HACK: We should include some sprite attribute to define the texture wrap directions
   394                     if (ii = sprWater) and not cReducedQuality then // HACK: We should include some sprite attribute to define the texture wrap directions
   395 					begin
   395                     begin
   396 						glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   396                         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   397 					end;
   397                     end;
   398 				end;
   398                 end;
   399 				if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf)
   399                 if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf)
   400 				end
   400                 end
   401 			else
   401             else
   402 				Surface:= nil
   402                 Surface:= nil
   403 		end;
   403         end;
   404 
   404 
   405 AddProgress;
   405 AddProgress;
   406 
   406 
   407 tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent);
   407 tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent);
   408 HHTexture:= Surface2Tex(tmpsurf, false);
   408 HHTexture:= Surface2Tex(tmpsurf, false);
   416 
   416 
   417 AddProgress;
   417 AddProgress;
   418 
   418 
   419 // name of weapons in ammo menu
   419 // name of weapons in ammo menu
   420 for ai:= Low(TAmmoType) to High(TAmmoType) do
   420 for ai:= Low(TAmmoType) to High(TAmmoType) do
   421 	with Ammoz[ai] do
   421     with Ammoz[ai] do
   422 		begin
   422         begin
   423 		tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(trAmmo[NameId],fnt16)].Handle, Str2PChar(trAmmo[NameId]), cWhiteColorChannels);
   423         tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(trAmmo[NameId],fnt16)].Handle, Str2PChar(trAmmo[NameId]), cWhiteColorChannels);
   424 		tmpsurf:= doSurfaceConversion(tmpsurf);
   424         tmpsurf:= doSurfaceConversion(tmpsurf);
   425 		NameTex:= Surface2Tex(tmpsurf, false);
   425         NameTex:= Surface2Tex(tmpsurf, false);
   426 		SDL_FreeSurface(tmpsurf)
   426         SDL_FreeSurface(tmpsurf)
   427 		end;
   427         end;
   428 
   428 
   429 // number of weapons in ammo menu
   429 // number of weapons in ammo menu
   430 for i:= Low(CountTexz) to High(CountTexz) do
   430 for i:= Low(CountTexz) to High(CountTexz) do
   431 	begin
   431     begin
   432 	tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels);
   432     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels);
   433 	tmpsurf:= doSurfaceConversion(tmpsurf);
   433     tmpsurf:= doSurfaceConversion(tmpsurf);
   434 	CountTexz[i]:= Surface2Tex(tmpsurf, false);
   434     CountTexz[i]:= Surface2Tex(tmpsurf, false);
   435 	SDL_FreeSurface(tmpsurf)
   435     SDL_FreeSurface(tmpsurf)
   436 	end;
   436     end;
   437 
   437 
   438 {$IFDEF DUMP}
   438 {$IFDEF DUMP}
   439 //not working anymore, where are LandSurface and StoreSurface defined?
   439 //not working anymore, where are LandSurface and StoreSurface defined?
   440 //SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1);
   440 //SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1);
   441 //SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1);
   441 //SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1);
   514 glPopMatrix
   514 glPopMatrix
   515 end;
   515 end;
   516 
   516 
   517 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
   517 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
   518 begin
   518 begin
   519 	DrawRotatedTextureF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
   519     DrawRotatedTextureF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
   520 end;
   520 end;
   521 
   521 
   522 procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
   522 procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
   523 var ft, fb, fl, fr: GLfloat;
   523 var ft, fb, fl, fr: GLfloat;
   524     hw, nx, ny: LongInt;
   524     hw, nx, ny: LongInt;
   536 glScalef(Scale, Scale, 1);
   536 glScalef(Scale, Scale, 1);
   537 
   537 
   538 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   538 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   539 
   539 
   540 if Dir < 0 then
   540 if Dir < 0 then
   541 	hw:= w div -2
   541     hw:= w div -2
   542 else
   542 else
   543 	hw:= w div 2;
   543     hw:= w div 2;
   544 
   544 
   545 nx:= round(Texture^.w / w); // number of horizontal frames
   545 nx:= round(Texture^.w / w); // number of horizontal frames
   546 ny:= round(Texture^.h / h); // number of vertical frames
   546 ny:= round(Texture^.h / h); // number of vertical frames
   547 
   547 
   548 ft:= (Frame mod ny) * Texture^.ry / ny;
   548 ft:= (Frame mod ny) * Texture^.ry / ny;
   585 end;
   585 end;
   586 
   586 
   587 procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
   587 procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
   588 begin
   588 begin
   589 DrawRotatedTex(SpritesData[Sprite].Texture,
   589 DrawRotatedTex(SpritesData[Sprite].Texture,
   590 		SpritesData[Sprite].Width,
   590         SpritesData[Sprite].Width,
   591 		SpritesData[Sprite].Height,
   591         SpritesData[Sprite].Height,
   592 		X, Y, Dir, Angle)
   592         X, Y, Dir, Angle)
   593 end;
   593 end;
   594 
   594 
   595 procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
   595 procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
   596 begin
   596 begin
   597 glPushMatrix;
   597 glPushMatrix;
   701 DrawTexture(X - Source^.w shr 1, Top, Source)
   701 DrawTexture(X - Source^.w shr 1, Top, Source)
   702 end;
   702 end;
   703 
   703 
   704 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
   704 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
   705 const VertexBuffer: array [0..3] of TVertex2f = (
   705 const VertexBuffer: array [0..3] of TVertex2f = (
   706 		(x: -16; y: -16),
   706         (x: -16; y: -16),
   707 		(x:  16; y: -16),
   707         (x:  16; y: -16),
   708 		(x:  16; y:  16),
   708         (x:  16; y:  16),
   709 		(x: -16; y:  16));
   709         (x: -16; y:  16));
   710 var l, r, t, b: real;
   710 var l, r, t, b: real;
   711     TextureBuffer: array [0..3] of TVertex2f;
   711     TextureBuffer: array [0..3] of TVertex2f;
   712 begin
   712 begin
   713 
   713 
   714 t:= Pos * 32 / HHTexture^.h;
   714 t:= Pos * 32 / HHTexture^.h;
  1030 end;
  1030 end;
  1031 
  1031 
  1032 procedure RenderHealth(var Hedgehog: THedgehog);
  1032 procedure RenderHealth(var Hedgehog: THedgehog);
  1033 var s: shortstring;
  1033 var s: shortstring;
  1034 begin
  1034 begin
  1035 	str(Hedgehog.Gear^.Health, s);
  1035     str(Hedgehog.Gear^.Health, s);
  1036 	if Hedgehog.HealthTagTex <> nil then
  1036     if Hedgehog.HealthTagTex <> nil then
  1037 		FreeTexture(Hedgehog.HealthTagTex);
  1037         FreeTexture(Hedgehog.HealthTagTex);
  1038 	Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16)
  1038     Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16)
  1039 end;
  1039 end;
  1040 
  1040 
  1041 function  LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
  1041 function  LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
  1042 var tmpsurf: PSDL_Surface;
  1042 var tmpsurf: PSDL_Surface;
  1043     s: shortstring;
  1043     s: shortstring;
  1044 begin
  1044 begin
  1045 	WriteToConsole(msgLoading + filename + ' [flags: ' + inttostr(imageFlags) + ']... ');
  1045     WriteToConsole(msgLoading + filename + ' [flags: ' + inttostr(imageFlags) + ']... ');
  1046 
  1046 
  1047 	s:= filename + '.png';
  1047     s:= filename + '.png';
  1048 	tmpsurf:= IMG_Load(Str2PChar(s));
  1048     tmpsurf:= IMG_Load(Str2PChar(s));
  1049 
  1049 
  1050 	if (imageFlags and ifLowRes) <> 0 then
  1050     if (imageFlags and ifLowRes) <> 0 then
  1051 	begin
  1051     begin
  1052 		s:= filename + '-lowres.png';
  1052         s:= filename + '-lowres.png';
  1053 		if (tmpsurf <> nil) then
  1053         if (tmpsurf <> nil) then
  1054 		begin
  1054         begin
  1055 			if ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then
  1055             if ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then
  1056 			begin
  1056             begin
  1057 				SDL_FreeSurface(tmpsurf);
  1057                 SDL_FreeSurface(tmpsurf);
  1058 				{$IFDEF DEBUGFILE}
  1058                 {$IFDEF DEBUGFILE}
  1059 				AddFileLog('...image too big, trying to load lowres version: ' + s + '...');
  1059                 AddFileLog('...image too big, trying to load lowres version: ' + s + '...');
  1060 				{$ENDIF}
  1060                 {$ENDIF}
  1061 				tmpsurf:= IMG_Load(Str2PChar(s))
  1061                 tmpsurf:= IMG_Load(Str2PChar(s))
  1062 			end;
  1062             end;
  1063 		end
  1063         end
  1064 		else
  1064         else
  1065 		begin
  1065         begin
  1066 			{$IFDEF DEBUGFILE}
  1066             {$IFDEF DEBUGFILE}
  1067 			AddFileLog('...image not found, trying to load lowres version: ' + s + '...');
  1067             AddFileLog('...image not found, trying to load lowres version: ' + s + '...');
  1068 			{$ENDIF}
  1068             {$ENDIF}
  1069 			tmpsurf:= IMG_Load(Str2PChar(s))
  1069             tmpsurf:= IMG_Load(Str2PChar(s))
  1070 		end;
  1070         end;
  1071 	end;
  1071     end;
  1072 
  1072 
  1073 	if tmpsurf = nil then
  1073     if tmpsurf = nil then
  1074 	begin
  1074     begin
  1075 		OutError(msgFailed, (imageFlags and ifCritical) <> 0);
  1075         OutError(msgFailed, (imageFlags and ifCritical) <> 0);
  1076 		exit(nil)
  1076         exit(nil)
  1077 	end;
  1077     end;
  1078 
  1078 
  1079 	if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then
  1079     if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then
  1080 	begin
  1080     begin
  1081 		SDL_FreeSurface(tmpsurf);
  1081         SDL_FreeSurface(tmpsurf);
  1082 		OutError(msgFailedSize, (imageFlags and ifCritical) <> 0);
  1082         OutError(msgFailedSize, (imageFlags and ifCritical) <> 0);
  1083 		// dummy surface to replace non-critical textures that failed to load due to their size
  1083         // dummy surface to replace non-critical textures that failed to load due to their size
  1084 		exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask));
  1084         exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask));
  1085 	end;
  1085     end;
  1086 
  1086 
  1087 	tmpsurf:= doSurfaceConversion(tmpsurf);
  1087     tmpsurf:= doSurfaceConversion(tmpsurf);
  1088 
  1088 
  1089 	if (imageFlags and ifTransparent) <> 0 then
  1089     if (imageFlags and ifTransparent) <> 0 then
  1090 		TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
  1090         TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
  1091 
  1091 
  1092 	WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');
  1092     WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');
  1093 	WriteLnToConsole(msgOK);
  1093     WriteLnToConsole(msgOK);
  1094 
  1094 
  1095 	LoadImage:= tmpsurf //Result
  1095     LoadImage:= tmpsurf //Result
  1096 end;
  1096 end;
  1097 
  1097 
  1098 function glLoadExtension(extension : shortstring) : boolean;
  1098 function glLoadExtension(extension : shortstring) : boolean;
  1099 begin
  1099 begin
  1100 {$IFDEF IPHONEOS}
  1100 {$IFDEF IPHONEOS}
  1101 	glLoadExtension:= false;
  1101     glLoadExtension:= false;
  1102 {$ELSE}
  1102 {$ELSE}
  1103 	glLoadExtension:= glext_LoadExtension(extension);
  1103     glLoadExtension:= glext_LoadExtension(extension);
  1104 {$ENDIF}
  1104 {$ENDIF}
  1105 {$IFDEF DEBUGFILE}
  1105 {$IFDEF DEBUGFILE}
  1106 	if not glLoadExtension then
  1106     if not glLoadExtension then
  1107 		AddFileLog('OpenGL - "' + extension + '" failed to load')
  1107         AddFileLog('OpenGL - "' + extension + '" failed to load')
  1108 	else
  1108     else
  1109 		AddFileLog('OpenGL - "' + extension + '" loaded');
  1109         AddFileLog('OpenGL - "' + extension + '" loaded');
  1110 {$ENDIF}
  1110 {$ENDIF}
  1111 end;
  1111 end;
  1112 
  1112 
  1113 procedure SetupOpenGL;
  1113 procedure SetupOpenGL;
  1114 var vendor: shortstring;
  1114 var vendor: shortstring;
  1115 begin
  1115 begin
  1116 {$IFDEF IPHONEOS}
  1116 {$IFDEF IPHONEOS}
  1117 //these are good performance savers, perhaps we could enable them by default
  1117 //these are good performance savers, perhaps we could enable them by default
  1118 	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
  1118     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
  1119 	SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
  1119     SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
  1120 	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
  1120     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
  1121 	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
  1121     SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
  1122 	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
  1122     SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
  1123 	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
  1123     SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
  1124 	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
  1124     SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
  1125 	SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
  1125     SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
  1126 	//SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
  1126     //SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
  1127 {$ELSE}
  1127 {$ELSE}
  1128 	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  1128     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  1129 {$ENDIF}
  1129 {$ENDIF}
  1130 
  1130 
  1131 {$IFNDEF SDL13}
  1131 {$IFNDEF SDL13}
  1132 // this attribute is default in 1.3 and must be enabled in MacOSX
  1132 // this attribute is default in 1.3 and must be enabled in MacOSX
  1133 {$IFNDEF DARWIN}
  1133 {$IFNDEF DARWIN}
  1134 	if cVSyncInUse then
  1134     if cVSyncInUse then
  1135 {$ENDIF}
  1135 {$ENDIF}
  1136 		SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
  1136         SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
  1137 {$ENDIF}
  1137 {$ENDIF}
  1138 
  1138 
  1139 	glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
  1139     glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
  1140 
  1140 
  1141 	vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR))));
  1141     vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR))));
  1142 {$IFDEF DEBUGFILE}
  1142 {$IFDEF DEBUGFILE}
  1143 	AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER))));
  1143     AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER))));
  1144 	AddFileLog('  |----- Vendor: ' + vendor);
  1144     AddFileLog('  |----- Vendor: ' + vendor);
  1145 	AddFileLog('  |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION))));
  1145     AddFileLog('  |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION))));
  1146 	AddFileLog('  \----- GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize));
  1146     AddFileLog('  \----- GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize));
  1147 {$ENDIF}
  1147 {$ENDIF}
  1148 
  1148 
  1149 	if MaxTextureSize <= 0 then
  1149     if MaxTextureSize <= 0 then
  1150 	begin
  1150     begin
  1151 		MaxTextureSize:= 1024;
  1151         MaxTextureSize:= 1024;
  1152 {$IFDEF DEBUGFILE}
  1152 {$IFDEF DEBUGFILE}
  1153 		AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024');
  1153         AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024');
  1154 {$ENDIF}
  1154 {$ENDIF}
  1155 	end;
  1155     end;
  1156 
  1156 
  1157 {$IFNDEF IPHONEOS}
  1157 {$IFNDEF IPHONEOS}
  1158 	if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then
  1158     if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then
  1159 		cGPUVendor:= gvNVIDIA
  1159         cGPUVendor:= gvNVIDIA
  1160 	else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then
  1160     else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then
  1161 		cGPUVendor:= gvATI
  1161         cGPUVendor:= gvATI
  1162 	else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then
  1162     else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then
  1163 		cGPUVendor:= gvIntel;
  1163         cGPUVendor:= gvIntel;
  1164 //SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two');
  1164 //SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two');
  1165 {$ELSE}
  1165 {$ELSE}
  1166 	cGPUVendor:= gvApple;
  1166     cGPUVendor:= gvApple;
  1167 {$ENDIF}
  1167 {$ENDIF}
  1168 
  1168 
  1169 {$IFDEF DEBUGFILE}
  1169 {$IFDEF DEBUGFILE}
  1170 	if cGPUVendor = gvUnknown then
  1170     if cGPUVendor = gvUnknown then
  1171 		AddFileLog('OpenGL Warning - unknown hardware vendor; please report');
  1171         AddFileLog('OpenGL Warning - unknown hardware vendor; please report');
  1172 {$ELSE}
  1172 {$ELSE}
  1173 	// just avoid 'never used' compiler warning for now
  1173     // just avoid 'never used' compiler warning for now
  1174 	if cGPUVendor = gvUnknown then cGPUVendor:= gvUnknown;
  1174     if cGPUVendor = gvUnknown then cGPUVendor:= gvUnknown;
  1175 {$ENDIF}
  1175 {$ENDIF}
  1176 
  1176 
  1177 	// set view port to whole window
  1177     // set view port to whole window
  1178 {$IFDEF IPHONEOS}
  1178 {$IFDEF IPHONEOS}
  1179 	glViewport(0, 0, cScreenHeight, cScreenWidth);
  1179     glViewport(0, 0, cScreenHeight, cScreenWidth);
  1180 {$ELSE}
  1180 {$ELSE}
  1181 	glViewport(0, 0, cScreenWidth, cScreenHeight);
  1181     glViewport(0, 0, cScreenWidth, cScreenHeight);
  1182 {$ENDIF}
  1182 {$ENDIF}
  1183 
  1183 
  1184 	glMatrixMode(GL_MODELVIEW);
  1184     glMatrixMode(GL_MODELVIEW);
  1185 	// prepare default translation/scaling
  1185     // prepare default translation/scaling
  1186 	glLoadIdentity();
  1186     glLoadIdentity();
  1187 {$IFDEF IPHONEOS}
  1187 {$IFDEF IPHONEOS}
  1188 	glRotatef(-90, 0, 0, 1);
  1188     glRotatef(-90, 0, 0, 1);
  1189 {$ENDIF}
  1189 {$ENDIF}
  1190 	glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
  1190     glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
  1191 	glTranslatef(0, -cScreenHeight / 2, 0);
  1191     glTranslatef(0, -cScreenHeight / 2, 0);
  1192 
  1192 
  1193 	// enable alpha blending
  1193     // enable alpha blending
  1194 	glEnable(GL_BLEND);
  1194     glEnable(GL_BLEND);
  1195 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1195     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1196 end;
  1196 end;
  1197 
  1197 
  1198 procedure SetScale(f: GLfloat);
  1198 procedure SetScale(f: GLfloat);
  1199 var
  1199 var
  1200 {$IFDEF IPHONEOS}
  1200 {$IFDEF IPHONEOS}
  1201 scale: GLfloat = 1.5;
  1201 scale: GLfloat = 1.5;
  1202 {$ELSE}
  1202 {$ELSE}
  1203 scale: GLfloat = 2.0;
  1203 scale: GLfloat = 2.0;
  1204 {$ENDIF}
  1204 {$ENDIF}
  1205 begin
  1205 begin
  1206 	// leave immediately if scale factor did not change
  1206     // leave immediately if scale factor did not change
  1207 	if f = cScaleFactor then exit;
  1207     if f = cScaleFactor then exit;
  1208 
  1208 
  1209 	if f = scale then glPopMatrix	// "return" to default scaling
  1209     if f = scale then glPopMatrix   // "return" to default scaling
  1210 	else				// other scaling
  1210     else                // other scaling
  1211 	begin
  1211     begin
  1212 		glPushMatrix;		// save default scaling
  1212         glPushMatrix;       // save default scaling
  1213 		glLoadIdentity;
  1213         glLoadIdentity;
  1214 {$IFDEF IPHONEOS}
  1214 {$IFDEF IPHONEOS}
  1215 		glRotatef(-90, 0, 0, 1);
  1215         glRotatef(-90, 0, 0, 1);
  1216 {$ENDIF}
  1216 {$ENDIF}
  1217 		glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
  1217         glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
  1218 		glTranslatef(0, -cScreenHeight / 2, 0);
  1218         glTranslatef(0, -cScreenHeight / 2, 0);
  1219 	end;
  1219     end;
  1220 
  1220 
  1221 	cScaleFactor:= f;
  1221     cScaleFactor:= f;
  1222 end;
  1222 end;
  1223 
  1223 
  1224 ////////////////////////////////////////////////////////////////////////////////
  1224 ////////////////////////////////////////////////////////////////////////////////
  1225 procedure AddProgress;
  1225 procedure AddProgress;
  1226 var r: TSDL_Rect;
  1226 var r: TSDL_Rect;
  1227     texsurf: PSDL_Surface;
  1227     texsurf: PSDL_Surface;
  1228 begin
  1228 begin
  1229 	if Step = 0 then
  1229     if Step = 0 then
  1230 	begin
  1230     begin
  1231 {$IFDEF SDL_IMAGE_NEWER}
  1231 {$IFDEF SDL_IMAGE_NEWER}
  1232 		WriteToConsole('Init SDL_image... ');
  1232         WriteToConsole('Init SDL_image... ');
  1233 		SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
  1233         SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
  1234 		WriteLnToConsole(msgOK);
  1234         WriteLnToConsole(msgOK);
  1235 {$ENDIF}
  1235 {$ENDIF}
  1236 	
  1236     
  1237 		WriteToConsole(msgLoading + 'progress sprite: ');
  1237         WriteToConsole(msgLoading + 'progress sprite: ');
  1238 		texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent);
  1238         texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent);
  1239 
  1239 
  1240 		ProgrTex:= Surface2Tex(texsurf, false);
  1240         ProgrTex:= Surface2Tex(texsurf, false);
  1241 		
  1241         
  1242 		squaresize:= texsurf^.w shr 1;
  1242         squaresize:= texsurf^.w shr 1;
  1243 		numsquares:= texsurf^.h div squaresize;
  1243         numsquares:= texsurf^.h div squaresize;
  1244 		SDL_FreeSurface(texsurf);
  1244         SDL_FreeSurface(texsurf);
  1245 	end;
  1245     end;
  1246 
  1246 
  1247 	TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
  1247     TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
  1248 
  1248 
  1249 	glClear(GL_COLOR_BUFFER_BIT);
  1249     glClear(GL_COLOR_BUFFER_BIT);
  1250 	glEnable(GL_TEXTURE_2D);
  1250     glEnable(GL_TEXTURE_2D);
  1251 	if Step < numsquares then r.x:= 0
  1251     if Step < numsquares then r.x:= 0
  1252 	else r.x:= squaresize;
  1252     else r.x:= squaresize;
  1253 	
  1253     
  1254 	r.y:= (Step mod numsquares) * squaresize;
  1254     r.y:= (Step mod numsquares) * squaresize;
  1255 	r.w:= squaresize;
  1255     r.w:= squaresize;
  1256 	r.h:= squaresize;
  1256     r.h:= squaresize;
  1257 	
  1257     
  1258 	DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex);
  1258     DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex);
  1259 
  1259 
  1260 	glDisable(GL_TEXTURE_2D);
  1260     glDisable(GL_TEXTURE_2D);
  1261 	SDL_GL_SwapBuffers();
  1261     SDL_GL_SwapBuffers();
  1262 {$IFDEF SDL13}
  1262 {$IFDEF SDL13}
  1263 	SDL_RenderPresent();
  1263     SDL_RenderPresent();
  1264 {$ENDIF}
  1264 {$ENDIF}
  1265 	inc(Step);
  1265     inc(Step);
  1266 
  1266 
  1267 end;
  1267 end;
  1268 
  1268 
  1269 
  1269 
  1270 procedure FinishProgress;
  1270 procedure FinishProgress;
  1271 begin
  1271 begin
  1272 	WriteLnToConsole('Freeing progress surface... ');
  1272     WriteLnToConsole('Freeing progress surface... ');
  1273 	FreeTexture(ProgrTex);
  1273     FreeTexture(ProgrTex);
  1274 
  1274 
  1275 {$IFDEF IPHONEOS}
  1275 {$IFDEF IPHONEOS}
  1276 	// show overlay buttons
  1276     // show overlay buttons
  1277 	IPH_showControls;
  1277     IPH_showControls;
  1278 {$ENDIF}
  1278 {$ENDIF}
  1279 end;
  1279 end;
  1280 
  1280 
  1281 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);
  1281 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);
  1282 var y, x, i, j: LongInt;
  1282 var y, x, i, j: LongInt;
  1345         end;
  1345         end;
  1346 end;
  1346 end;
  1347 
  1347 
  1348 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
  1348 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
  1349 var tmpsurf: PSDL_SURFACE;
  1349 var tmpsurf: PSDL_SURFACE;
  1350 	w, h, i, j: LongInt;
  1350     w, h, i, j: LongInt;
  1351 	font: THWFont;
  1351     font: THWFont;
  1352 	r, r2: TSDL_Rect;
  1352     r, r2: TSDL_Rect;
  1353 	wa, ha: LongInt;
  1353     wa, ha: LongInt;
  1354 	tmpline, tmpline2, tmpdesc: ansistring;
  1354     tmpline, tmpline2, tmpdesc: ansistring;
  1355 begin
  1355 begin
  1356 // make sure there is a caption as well as a sub caption - description is optional
  1356 // make sure there is a caption as well as a sub caption - description is optional
  1357 if caption = '' then caption:= '???';
  1357 if caption = '' then caption:= '???';
  1358 if subcaption = '' then subcaption:= ' ';
  1358 if subcaption = '' then subcaption:= ' ';
  1359 
  1359 
  1382 inc(h, j + ha);
  1382 inc(h, j + ha);
  1383 
  1383 
  1384 // get description's dimensions
  1384 // get description's dimensions
  1385 tmpdesc:= description;
  1385 tmpdesc:= description;
  1386 while tmpdesc <> '' do
  1386 while tmpdesc <> '' do
  1387 	begin
  1387     begin
  1388 	tmpline:= tmpdesc;
  1388     tmpline:= tmpdesc;
  1389 	SplitByChar(tmpline, tmpdesc, '|');
  1389     SplitByChar(tmpline, tmpdesc, '|');
  1390 	if tmpline <> '' then
  1390     if tmpline <> '' then
  1391 		begin
  1391         begin
  1392 		TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(tmpline), i, j);
  1392         TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(tmpline), i, j);
  1393 		if w < (i + wa) then w:= i + wa;
  1393         if w < (i + wa) then w:= i + wa;
  1394 		inc(h, j + ha)
  1394         inc(h, j + ha)
  1395 		end
  1395         end
  1396 	end;
  1396     end;
  1397 
  1397 
  1398 if extra <> '' then
  1398 if extra <> '' then
  1399 	begin
  1399     begin
  1400 	// get extra label's dimensions
  1400     // get extra label's dimensions
  1401 	TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(extra), i, j);
  1401     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(extra), i, j);
  1402 	if w < (i + wa) then w:= i + wa;
  1402     if w < (i + wa) then w:= i + wa;
  1403 	inc(h, j + ha);
  1403     inc(h, j + ha);
  1404 	end;
  1404     end;
  1405 	
  1405     
  1406 // add borders space
  1406 // add borders space
  1407 inc(w, wa);
  1407 inc(w, wa);
  1408 inc(h, ha + 8);
  1408 inc(h, ha + 8);
  1409 
  1409 
  1410 tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RMask, GMask, BMask, AMask);
  1410 tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RMask, GMask, BMask, AMask);
  1423 r:= WriteInRect(tmpsurf, 36 + FontBorder + 2, r.y + r.h, $ffc7c7c7, font, subcaption);
  1423 r:= WriteInRect(tmpsurf, 36 + FontBorder + 2, r.y + r.h, $ffc7c7c7, font, subcaption);
  1424 
  1424 
  1425 // render all description lines
  1425 // render all description lines
  1426 tmpdesc:= description;
  1426 tmpdesc:= description;
  1427 while tmpdesc <> '' do
  1427 while tmpdesc <> '' do
  1428 	begin
  1428     begin
  1429 	tmpline:= tmpdesc;
  1429     tmpline:= tmpdesc;
  1430 	SplitByChar(tmpline, tmpdesc, '|');
  1430     SplitByChar(tmpline, tmpdesc, '|');
  1431 	r2:= r;
  1431     r2:= r;
  1432 	if tmpline <> '' then
  1432     if tmpline <> '' then
  1433 		begin
  1433         begin
  1434 		r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, $ff707070, font, tmpline);
  1434         r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, $ff707070, font, tmpline);
  1435 		
  1435         
  1436 		// render highlighted caption (if there's a ':')
  1436         // render highlighted caption (if there's a ':')
  1437 		SplitByChar(tmpline, tmpline2, ':');
  1437         SplitByChar(tmpline, tmpline2, ':');
  1438 		if tmpline2 <> '' then
  1438         if tmpline2 <> '' then
  1439 			WriteInRect(tmpsurf, FontBorder + 2, r2.y + r2.h, $ffc7c7c7, font, tmpline + ':');
  1439             WriteInRect(tmpsurf, FontBorder + 2, r2.y + r2.h, $ffc7c7c7, font, tmpline + ':');
  1440 		end
  1440         end
  1441 	end;
  1441     end;
  1442 
  1442 
  1443 if extra <> '' then
  1443 if extra <> '' then
  1444 	r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, extracolor, font, extra);
  1444     r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, extracolor, font, extra);
  1445 
  1445 
  1446 r.x:= FontBorder + 6;
  1446 r.x:= FontBorder + 6;
  1447 r.y:= FontBorder + 4;
  1447 r.y:= FontBorder + 4;
  1448 r.w:= 32;
  1448 r.w:= 32;
  1449 r.h:= 32;
  1449 r.h:= 32;
  1450 SDL_FillRect(tmpsurf, @r, $ffffffff);
  1450 SDL_FillRect(tmpsurf, @r, $ffffffff);
  1451 SDL_UpperBlit(iconsurf, iconrect, tmpsurf, @r);
  1451 SDL_UpperBlit(iconsurf, iconrect, tmpsurf, @r);
  1452 	
  1452     
  1453 RenderHelpWindow:=  Surface2Tex(tmpsurf, true);
  1453 RenderHelpWindow:=  Surface2Tex(tmpsurf, true);
  1454 SDL_FreeSurface(tmpsurf)
  1454 SDL_FreeSurface(tmpsurf)
  1455 end;
  1455 end;
  1456 
  1456 
  1457 procedure RenderWeaponTooltip(atype: TAmmoType);
  1457 procedure RenderWeaponTooltip(atype: TAmmoType);
  1458 {$IFNDEF IPHONEOS}
  1458 {$IFNDEF IPHONEOS}
  1459 var r: TSDL_Rect;
  1459 var r: TSDL_Rect;
  1460 	i: LongInt;
  1460     i: LongInt;
  1461 	extra: ansistring;
  1461     extra: ansistring;
  1462 	extracolor: LongInt;
  1462     extracolor: LongInt;
  1463 begin
  1463 begin
  1464 // don't do anything if the window shouldn't be shown
  1464 // don't do anything if the window shouldn't be shown
  1465 if not cWeaponTooltips then
  1465 if not cWeaponTooltips then
  1466 	begin
  1466     begin
  1467 	WeaponTooltipTex:= nil;
  1467     WeaponTooltipTex:= nil;
  1468 	exit
  1468     exit
  1469 	end;
  1469     end;
  1470 
  1470 
  1471 // free old texture
  1471 // free old texture
  1472 FreeWeaponTooltip;
  1472 FreeWeaponTooltip;
  1473 
  1473 
  1474 // image region
  1474 // image region
  1481 // default (no extra text)
  1481 // default (no extra text)
  1482 extra:= '';
  1482 extra:= '';
  1483 extracolor:= 0;
  1483 extracolor:= 0;
  1484 
  1484 
  1485 if (CurrentTeam <> nil) and (Ammoz[atype].SkipTurns >= CurrentTeam^.Clan^.TurnNumber) then // weapon or utility is not yet available
  1485 if (CurrentTeam <> nil) and (Ammoz[atype].SkipTurns >= CurrentTeam^.Clan^.TurnNumber) then // weapon or utility is not yet available
  1486 	begin
  1486     begin
  1487 	extra:= trmsg[sidNotYetAvailable];
  1487     extra:= trmsg[sidNotYetAvailable];
  1488 	extracolor:= LongInt($ffc77070);
  1488     extracolor:= LongInt($ffc77070);
  1489 	end
  1489     end
  1490 else if (Ammoz[atype].Ammo.Propz and ammoprop_NoRoundEndHint) <> 0 then // weapon or utility won't end your turn
  1490 else if (Ammoz[atype].Ammo.Propz and ammoprop_NoRoundEndHint) <> 0 then // weapon or utility won't end your turn
  1491 	begin
  1491     begin
  1492 	extra:= trmsg[sidNoEndTurn];
  1492     extra:= trmsg[sidNoEndTurn];
  1493 	extracolor:= LongInt($ff70c770);
  1493     extracolor:= LongInt($ff70c770);
  1494 	end
  1494     end
  1495 else 
  1495 else 
  1496 	begin
  1496     begin
  1497 	extra:= '';
  1497     extra:= '';
  1498 	extracolor:= 0;
  1498     extracolor:= 0;
  1499 	end;
  1499     end;
  1500 
  1500 
  1501 // render window and return the texture
  1501 // render window and return the texture
  1502 WeaponTooltipTex:= RenderHelpWindow(trammo[Ammoz[atype].NameId], trammoc[Ammoz[atype].NameId], trammod[Ammoz[atype].NameId], extra, extracolor, SpritesData[sprAMAmmos].Surface, @r)
  1502 WeaponTooltipTex:= RenderHelpWindow(trammo[Ammoz[atype].NameId], trammoc[Ammoz[atype].NameId], trammod[Ammoz[atype].NameId], extra, extracolor, SpritesData[sprAMAmmos].Surface, @r)
  1503 end;
  1503 end;
  1504 {$ELSE}
  1504 {$ELSE}
  1508 procedure ShowWeaponTooltip(x, y: LongInt);
  1508 procedure ShowWeaponTooltip(x, y: LongInt);
  1509 begin
  1509 begin
  1510 {$IFNDEF IPHONEOS}
  1510 {$IFNDEF IPHONEOS}
  1511 // draw the texture if it exists
  1511 // draw the texture if it exists
  1512 if WeaponTooltipTex <> nil then
  1512 if WeaponTooltipTex <> nil then
  1513 	DrawTexture(x, y, WeaponTooltipTex)
  1513     DrawTexture(x, y, WeaponTooltipTex)
  1514 {$ENDIF}
  1514 {$ENDIF}
  1515 end;
  1515 end;
  1516 
  1516 
  1517 procedure FreeWeaponTooltip;
  1517 procedure FreeWeaponTooltip;
  1518 begin
  1518 begin
  1519 {$IFNDEF IPHONEOS}
  1519 {$IFNDEF IPHONEOS}
  1520 // free the existing texture (if there's any)
  1520 // free the existing texture (if there's any)
  1521 if WeaponTooltipTex = nil then
  1521 if WeaponTooltipTex = nil then
  1522 	exit;
  1522     exit;
  1523 FreeTexture(WeaponTooltipTex);
  1523 FreeTexture(WeaponTooltipTex);
  1524 WeaponTooltipTex:= nil
  1524 WeaponTooltipTex:= nil
  1525 {$ENDIF}
  1525 {$ENDIF}
  1526 end;
  1526 end;
  1527 
  1527