103 if SDL_MustLock(texsurf) then |
103 if SDL_MustLock(texsurf) then |
104 SDLTry(SDL_LockSurface(texsurf) >= 0, true); |
104 SDLTry(SDL_LockSurface(texsurf) >= 0, true); |
105 |
105 |
106 // make black pixel be alpha-transparent |
106 // make black pixel be alpha-transparent |
107 for i:= 0 to texsurf^.w * texsurf^.h - 1 do |
107 for i:= 0 to texsurf^.w * texsurf^.h - 1 do |
108 if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= (RMask or GMask or BMask) and Color; |
108 if PLongwordArray(texsurf^.pixels)^[i] = AMask then |
|
109 PLongwordArray(texsurf^.pixels)^[i]:= (RMask or GMask or BMask) and Color; |
109 |
110 |
110 if SDL_MustLock(texsurf) then |
111 if SDL_MustLock(texsurf) then |
111 SDL_UnlockSurface(texsurf); |
112 SDL_UnlockSurface(texsurf); |
112 |
113 |
113 FreeTexture(CrosshairTex); |
114 FreeTexture(CrosshairTex); |
162 |
163 |
163 DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true); |
164 DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true); |
164 |
165 |
165 // overwrite flag for cpu teams and keep players from using it |
166 // overwrite flag for cpu teams and keep players from using it |
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 |
|
169 Flag:= 'cpu' |
168 else if Flag = 'cpu' then |
170 else if Flag = 'cpu' then |
169 Flag:= 'hedgewars'; |
171 Flag:= 'hedgewars'; |
170 |
172 |
171 flagsurf:= LoadImage(UserPathz[ptFlags] + '/' + Flag, ifNone); |
173 flagsurf:= LoadImage(UserPathz[ptFlags] + '/' + Flag, ifNone); |
172 if flagsurf = nil then flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone); |
174 if flagsurf = nil then |
173 if flagsurf = nil then flagsurf:= LoadImage(UserPathz[ptFlags] + '/hedgewars', ifNone); |
175 flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone); |
174 if flagsurf = nil then flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone); |
176 if flagsurf = nil then |
|
177 flagsurf:= LoadImage(UserPathz[ptFlags] + '/hedgewars', ifNone); |
|
178 if flagsurf = nil then |
|
179 flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone); |
175 TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true); |
180 TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true); |
176 copyToXY(flagsurf, texsurf, 2, 2); |
181 copyToXY(flagsurf, texsurf, 2, 2); |
177 SDL_FreeSurface(flagsurf); |
182 SDL_FreeSurface(flagsurf); |
178 flagsurf:= nil; |
183 flagsurf:= nil; |
179 |
184 |
204 LoadHedgehogHat(Gear, Hat); |
209 LoadHedgehogHat(Gear, Hat); |
205 end |
210 end |
206 end; |
211 end; |
207 end; |
212 end; |
208 MissionIcons:= LoadImage(UserPathz[ptGraphics] + '/missions', ifNone); |
213 MissionIcons:= LoadImage(UserPathz[ptGraphics] + '/missions', ifNone); |
209 if MissionIcons = nil then MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical); |
214 if MissionIcons = nil then |
|
215 MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical); |
210 iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask); |
216 iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask); |
211 if iconsurf <> nil then |
217 if iconsurf <> nil then |
212 begin |
218 begin |
213 r.x:= 0; |
219 r.x:= 0; |
214 r.y:= 0; |
220 r.y:= 0; |
222 end; |
228 end; |
223 |
229 |
224 procedure InitHealth; |
230 procedure InitHealth; |
225 var i, t: LongInt; |
231 var i, t: LongInt; |
226 begin |
232 begin |
227 for t:= 0 to Pred(TeamsCount) do |
233 for t:= 0 to Pred(TeamsCount) do |
228 if TeamsArray[t] <> nil then |
234 if TeamsArray[t] <> nil then |
229 with TeamsArray[t]^ do |
235 with TeamsArray[t]^ do |
230 begin |
236 begin |
231 for i:= 0 to cMaxHHIndex do |
237 for i:= 0 to cMaxHHIndex do |
232 if Hedgehogs[i].Gear <> nil then |
238 if Hedgehogs[i].Gear <> nil then |
233 RenderHealth(Hedgehogs[i]); |
239 RenderHealth(Hedgehogs[i]); |
234 end |
240 end |
235 end; |
241 end; |
236 |
242 |
237 procedure LoadGraves; |
243 procedure LoadGraves; |
238 var t: LongInt; |
244 var t: LongInt; |
239 texsurf: PSDL_Surface; |
245 texsurf: PSDL_Surface; |
240 begin |
246 begin |
241 for t:= 0 to Pred(TeamsCount) do |
247 for t:= 0 to Pred(TeamsCount) do |
242 if TeamsArray[t] <> nil then |
248 if TeamsArray[t] <> nil then |
243 with TeamsArray[t]^ do |
249 with TeamsArray[t]^ do |
244 begin |
250 begin |
245 if GraveName = '' then GraveName:= 'Statue'; |
251 if GraveName = '' then |
|
252 GraveName:= 'Statue'; |
246 texsurf:= LoadImage(UserPathz[ptGraves] + '/' + GraveName, ifTransparent); |
253 texsurf:= LoadImage(UserPathz[ptGraves] + '/' + GraveName, ifTransparent); |
247 if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent); |
254 if texsurf = nil then |
248 if texsurf = nil then texsurf:= LoadImage(UserPathz[ptGraves] + '/Statue', ifTransparent); |
255 texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent); |
249 if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent); |
256 if texsurf = nil then |
|
257 texsurf:= LoadImage(UserPathz[ptGraves] + '/Statue', ifTransparent); |
|
258 if texsurf = nil then |
|
259 texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent); |
250 GraveTex:= Surface2Tex(texsurf, false); |
260 GraveTex:= Surface2Tex(texsurf, false); |
251 SDL_FreeSurface(texsurf) |
261 SDL_FreeSurface(texsurf) |
252 end |
262 end |
253 end; |
263 end; |
254 |
264 |
265 if not reload then |
275 if not reload then |
266 for fi:= Low(THWFont) to High(THWFont) do |
276 for fi:= Low(THWFont) to High(THWFont) do |
267 with Fontz[fi] do |
277 with Fontz[fi] do |
268 begin |
278 begin |
269 s:= UserPathz[ptFonts] + '/' + Name; |
279 s:= UserPathz[ptFonts] + '/' + Name; |
270 if not FileExists(s) then s:= Pathz[ptFonts] + '/' + Name; |
280 if not FileExists(s) then |
|
281 s:= Pathz[ptFonts] + '/' + Name; |
271 WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... '); |
282 WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... '); |
272 Handle:= TTF_OpenFont(Str2PChar(s), Height); |
283 Handle:= TTF_OpenFont(Str2PChar(s), Height); |
273 SDLTry(Handle <> nil, true); |
284 SDLTry(Handle <> nil, true); |
274 TTF_SetFontStyle(Handle, style); |
285 TTF_SetFontStyle(Handle, style); |
275 WriteLnToConsole(msgOK) |
286 WriteLnToConsole(msgOK) |
288 (not (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]))) and |
299 (not (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]))) and |
289 (((cReducedQuality and rqPlainSplash) = 0) or ((not (ii in [sprSplash, sprDroplet, sprSDSplash, sprSDDroplet])))) and |
300 (((cReducedQuality and rqPlainSplash) = 0) or ((not (ii in [sprSplash, sprDroplet, sprSDSplash, sprSDDroplet])))) and |
290 (((cReducedQuality and rqKillFlakes) = 0) or (Theme = 'Snow') or (Theme = 'Christmas') or ((not (ii in [sprFlake, sprSDFlake])))) and |
301 (((cReducedQuality and rqKillFlakes) = 0) or (Theme = 'Snow') or (Theme = 'Christmas') or ((not (ii in [sprFlake, sprSDFlake])))) and |
291 ((cCloudsNumber > 0) or (ii <> sprCloud)) and |
302 ((cCloudsNumber > 0) or (ii <> sprCloud)) and |
292 ((vobCount > 0) or (ii <> sprFlake)) then |
303 ((vobCount > 0) or (ii <> sprFlake)) then |
293 begin |
304 begin |
294 if AltPath = ptNone then |
305 if AltPath = ptNone then |
295 if ii in [sprHorizont, sprHorizontL, sprHorizontR, sprSky, sprSkyL, sprSkyR, sprChunk, sprFireButton] then // FIXME: hack |
306 if ii in [sprHorizont, sprHorizontL, sprHorizontR, sprSky, sprSkyL, sprSkyR, sprChunk, sprFireButton] then // FIXME: hack |
296 begin |
307 begin |
297 if not reload then |
308 if not reload then |
298 begin |
309 begin |
299 tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
310 tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
300 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent) |
311 if tmpsurf = nil then |
|
312 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent) |
301 end |
313 end |
302 else tmpsurf:= Surface |
314 else |
|
315 tmpsurf:= Surface |
303 end |
316 end |
304 else |
317 else |
305 begin |
318 begin |
306 if not reload then |
319 if not reload then |
307 begin |
320 begin |
308 tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
321 tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
309 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical) |
322 if tmpsurf = nil then |
|
323 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical) |
310 end |
324 end |
311 else tmpsurf:= Surface |
325 else |
|
326 tmpsurf:= Surface |
312 end |
327 end |
313 else begin |
328 else |
|
329 begin |
314 if not reload then |
330 if not reload then |
315 begin |
331 begin |
316 tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
332 tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
317 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
333 if tmpsurf = nil then |
318 if tmpsurf = nil then tmpsurf:= LoadImage(UserPathz[AltPath] + '/' + FileName, ifAlpha or ifTransparent); |
334 tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
319 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent) |
335 if tmpsurf = nil then |
|
336 tmpsurf:= LoadImage(UserPathz[AltPath] + '/' + FileName, ifAlpha or ifTransparent); |
|
337 if tmpsurf = nil then |
|
338 tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent) |
320 end |
339 end |
321 else tmpsurf:= Surface |
340 else |
|
341 tmpsurf:= Surface |
322 end; |
342 end; |
323 |
343 |
324 if tmpsurf <> nil then |
344 if tmpsurf <> nil then |
325 begin |
345 begin |
326 if getImageDimensions then |
346 if getImageDimensions then |
350 if not reload then |
370 if not reload then |
351 begin |
371 begin |
352 {$IF DEFINED(DARWIN) OR DEFINED(WIN32)} |
372 {$IF DEFINED(DARWIN) OR DEFINED(WIN32)} |
353 Surface:= tmpsurf |
373 Surface:= tmpsurf |
354 {$ELSE} |
374 {$ELSE} |
355 if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) |
375 if saveSurf then |
|
376 Surface:= tmpsurf |
|
377 else |
|
378 SDL_FreeSurface(tmpsurf) |
356 {$ENDIF} |
379 {$ENDIF} |
357 end |
380 end |
358 end |
381 end |
359 else |
382 else |
360 Surface:= nil |
383 Surface:= nil |
361 end; |
384 end; |
362 |
385 |
363 if not reload then |
386 if not reload then |
364 AddProgress; |
387 AddProgress; |
365 |
388 |
366 tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifTransparent); |
389 tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifTransparent); |
367 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent); |
390 if tmpsurf = nil then |
|
391 tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent); |
|
392 |
368 HHTexture:= Surface2Tex(tmpsurf, false); |
393 HHTexture:= Surface2Tex(tmpsurf, false); |
369 SDL_FreeSurface(tmpsurf); |
394 SDL_FreeSurface(tmpsurf); |
370 |
395 |
371 InitHealth; |
396 InitHealth; |
372 |
397 |
390 SDL_FreeSurface(tmpsurf) |
415 SDL_FreeSurface(tmpsurf) |
391 end; |
416 end; |
392 |
417 |
393 // number of weapons in ammo menu |
418 // number of weapons in ammo menu |
394 for i:= Low(CountTexz) to High(CountTexz) do |
419 for i:= Low(CountTexz) to High(CountTexz) do |
395 begin |
420 begin |
396 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels); |
421 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels); |
397 tmpsurf:= doSurfaceConversion(tmpsurf); |
422 tmpsurf:= doSurfaceConversion(tmpsurf); |
398 FreeTexture(CountTexz[i]); |
423 FreeTexture(CountTexz[i]); |
399 CountTexz[i]:= Surface2Tex(tmpsurf, false); |
424 CountTexz[i]:= Surface2Tex(tmpsurf, false); |
400 SDL_FreeSurface(tmpsurf) |
425 SDL_FreeSurface(tmpsurf) |
401 end; |
426 end; |
402 |
427 |
403 if not reload then |
428 if not reload then |
404 AddProgress; |
429 AddProgress; |
405 IMG_Quit(); |
430 IMG_Quit(); |
406 end; |
431 end; |
408 procedure StoreRelease(reload: boolean); |
433 procedure StoreRelease(reload: boolean); |
409 var ii: TSprite; |
434 var ii: TSprite; |
410 ai: TAmmoType; |
435 ai: TAmmoType; |
411 i, t: LongInt; |
436 i, t: LongInt; |
412 begin |
437 begin |
413 for ii:= Low(TSprite) to High(TSprite) do |
438 for ii:= Low(TSprite) to High(TSprite) do |
414 begin |
439 begin |
415 FreeTexture(SpritesData[ii].Texture); |
440 FreeTexture(SpritesData[ii].Texture); |
416 SpritesData[ii].Texture:= nil; |
441 SpritesData[ii].Texture:= nil; |
417 if (SpritesData[ii].Surface <> nil) and (not reload) then |
442 if (SpritesData[ii].Surface <> nil) and (not reload) then |
418 begin |
443 begin |
419 SDL_FreeSurface(SpritesData[ii].Surface); |
444 SDL_FreeSurface(SpritesData[ii].Surface); |
420 SpritesData[ii].Surface:= nil |
445 SpritesData[ii].Surface:= nil |
421 end |
446 end |
422 end; |
447 end; |
423 SDL_FreeSurface(MissionIcons); |
448 SDL_FreeSurface(MissionIcons); |
424 |
449 |
425 // free the textures declared in uVariables |
450 // free the textures declared in uVariables |
426 FreeTexture(WeaponTooltipTex); |
451 FreeTexture(WeaponTooltipTex); |
427 WeaponTooltipTex:= nil; |
452 WeaponTooltipTex:= nil; |
428 FreeTexture(PauseTexture); |
453 FreeTexture(PauseTexture); |
429 PauseTexture:= nil; |
454 PauseTexture:= nil; |
430 FreeTexture(SyncTexture); |
455 FreeTexture(SyncTexture); |
431 SyncTexture:= nil; |
456 SyncTexture:= nil; |
432 FreeTexture(ConfirmTexture); |
457 FreeTexture(ConfirmTexture); |
433 ConfirmTexture:= nil; |
458 ConfirmTexture:= nil; |
434 FreeTexture(ropeIconTex); |
459 FreeTexture(ropeIconTex); |
435 ropeIconTex:= nil; |
460 ropeIconTex:= nil; |
436 FreeTexture(HHTexture); |
461 FreeTexture(HHTexture); |
437 HHTexture:= nil; |
462 HHTexture:= nil; |
438 |
463 |
439 // free all ammo name textures |
464 // free all ammo name textures |
440 for ai:= Low(TAmmoType) to High(TAmmoType) do |
465 for ai:= Low(TAmmoType) to High(TAmmoType) do |
441 begin |
466 begin |
442 FreeTexture(Ammoz[ai].NameTex); |
467 FreeTexture(Ammoz[ai].NameTex); |
443 Ammoz[ai].NameTex:= nil |
468 Ammoz[ai].NameTex:= nil |
444 end; |
469 end; |
445 |
470 |
446 // free all count textures |
471 // free all count textures |
447 for i:= Low(CountTexz) to High(CountTexz) do |
472 for i:= Low(CountTexz) to High(CountTexz) do |
448 begin |
473 begin |
449 FreeTexture(CountTexz[i]); |
474 FreeTexture(CountTexz[i]); |
450 CountTexz[i]:= nil |
475 CountTexz[i]:= nil |
451 end; |
476 end; |
452 |
477 |
453 // free all team and hedgehog textures |
478 // free all team and hedgehog textures |
454 for t:= 0 to Pred(TeamsCount) do |
479 for t:= 0 to Pred(TeamsCount) do |
455 begin |
480 begin |
456 if TeamsArray[t] <> nil then |
481 if TeamsArray[t] <> nil then |
493 |
518 |
494 |
519 |
495 procedure RenderHealth(var Hedgehog: THedgehog); |
520 procedure RenderHealth(var Hedgehog: THedgehog); |
496 var s: shortstring; |
521 var s: shortstring; |
497 begin |
522 begin |
498 str(Hedgehog.Gear^.Health, s); |
523 str(Hedgehog.Gear^.Health, s); |
499 FreeTexture(Hedgehog.HealthTagTex); |
524 FreeTexture(Hedgehog.HealthTagTex); |
500 Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
525 Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
501 end; |
526 end; |
502 |
527 |
503 function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
528 function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
504 var tmpsurf: PSDL_Surface; |
529 var tmpsurf: PSDL_Surface; |
505 s: shortstring; |
530 s: shortstring; |
506 begin |
531 begin |
507 WriteToConsole(msgLoading + filename + '.png [flags: ' + inttostr(imageFlags) + '] '); |
532 WriteToConsole(msgLoading + filename + '.png [flags: ' + inttostr(imageFlags) + '] '); |
508 |
533 |
509 s:= filename + '.png'; |
534 s:= filename + '.png'; |
510 tmpsurf:= IMG_Load(Str2PChar(s)); |
535 tmpsurf:= IMG_Load(Str2PChar(s)); |
511 |
536 |
512 if tmpsurf = nil then |
537 if tmpsurf = nil then |
513 begin |
538 begin |
514 OutError(msgFailed, (imageFlags and ifCritical) <> 0); |
539 OutError(msgFailed, (imageFlags and ifCritical) <> 0); |
515 exit(nil) |
540 exit(nil) |
516 end; |
541 end; |
517 |
542 |
518 if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
543 if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
519 begin |
544 begin |
520 SDL_FreeSurface(tmpsurf); |
545 SDL_FreeSurface(tmpsurf); |
521 OutError(msgFailedSize, (imageFlags and ifCritical) <> 0); |
546 OutError(msgFailedSize, (imageFlags and ifCritical) <> 0); |
522 // dummy surface to replace non-critical textures that failed to load due to their size |
547 // dummy surface to replace non-critical textures that failed to load due to their size |
523 exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 2, 2, 32, RMask, GMask, BMask, AMask)); |
548 exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 2, 2, 32, RMask, GMask, BMask, AMask)); |
524 end; |
549 end; |
525 |
550 |
526 tmpsurf:= doSurfaceConversion(tmpsurf); |
551 tmpsurf:= doSurfaceConversion(tmpsurf); |
527 |
552 |
528 if (imageFlags and ifTransparent) <> 0 then |
553 if (imageFlags and ifTransparent) <> 0 then |
529 TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
554 TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
534 end; |
559 end; |
535 |
560 |
536 procedure LoadHedgehogHat(HHGear: PGear; newHat: shortstring); |
561 procedure LoadHedgehogHat(HHGear: PGear; newHat: shortstring); |
537 var texsurf: PSDL_Surface; |
562 var texsurf: PSDL_Surface; |
538 begin |
563 begin |
539 texsurf:= LoadImage(UserPathz[ptHats] + '/' + newHat, ifNone); |
564 texsurf:= LoadImage(UserPathz[ptHats] + '/' + newHat, ifNone); |
540 if texsurf = nil then texsurf:= LoadImage(Pathz[ptHats] + '/' + newHat, ifNone); |
565 if texsurf = nil then |
|
566 texsurf:= LoadImage(Pathz[ptHats] + '/' + newHat, ifNone); |
541 |
567 |
542 // only do something if the hat could be loaded |
568 // only do something if the hat could be loaded |
543 if texsurf <> nil then |
569 if texsurf <> nil then |
544 begin |
570 begin |
545 // free the mem of any previously assigned texture |
571 // free the mem of any previously assigned texture |
644 {$IFNDEF S3D_DISABLED} |
670 {$IFNDEF S3D_DISABLED} |
645 if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then |
671 if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then |
646 begin |
672 begin |
647 // prepare left and right frame buffers and associated textures |
673 // prepare left and right frame buffers and associated textures |
648 if glLoadExtension('GL_EXT_framebuffer_object') then |
674 if glLoadExtension('GL_EXT_framebuffer_object') then |
649 begin |
675 begin |
650 // left |
676 // left |
651 glGenFramebuffersEXT(1, @framel); |
677 glGenFramebuffersEXT(1, @framel); |
652 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framel); |
678 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framel); |
653 glGenRenderbuffersEXT(1, @depthl); |
679 glGenRenderbuffersEXT(1, @depthl); |
654 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthl); |
680 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthl); |
675 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
701 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
676 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texr, 0); |
702 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texr, 0); |
677 |
703 |
678 // reset |
704 // reset |
679 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0) |
705 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0) |
680 end |
706 end |
681 else |
707 else |
682 cStereoMode:= smNone; |
708 cStereoMode:= smNone; |
683 end; |
709 end; |
684 {$ENDIF} |
710 {$ENDIF} |
685 |
711 |
709 glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
735 glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
710 end; |
736 end; |
711 |
737 |
712 procedure SetScale(f: GLfloat); |
738 procedure SetScale(f: GLfloat); |
713 begin |
739 begin |
714 // leave immediately if scale factor did not change |
740 // leave immediately if scale factor did not change |
715 if f = cScaleFactor then exit; |
741 if f = cScaleFactor then |
|
742 exit; |
716 |
743 |
717 if f = cDefaultZoomLevel then |
744 if f = cDefaultZoomLevel then |
718 glPopMatrix // "return" to default scaling |
745 glPopMatrix // "return" to default scaling |
719 else // other scaling |
746 else // other scaling |
720 begin |
747 begin |
721 glPushMatrix; // save default scaling |
748 glPushMatrix; // save default scaling |
722 glLoadIdentity; |
749 glLoadIdentity; |
723 glRotatef(rotationQt, 0, 0, 1); |
750 glRotatef(rotationQt, 0, 0, 1); |
724 glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
751 glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
725 glTranslatef(0, -cScreenHeight / 2, 0); |
752 glTranslatef(0, -cScreenHeight / 2, 0); |
726 end; |
753 end; |
727 |
754 |
728 cScaleFactor:= f; |
755 cScaleFactor:= f; |
729 end; |
756 end; |
730 |
757 |
731 //////////////////////////////////////////////////////////////////////////////// |
758 //////////////////////////////////////////////////////////////////////////////// |
735 begin |
762 begin |
736 if Step = 0 then |
763 if Step = 0 then |
737 begin |
764 begin |
738 WriteToConsole(msgLoading + 'progress sprite: '); |
765 WriteToConsole(msgLoading + 'progress sprite: '); |
739 texsurf:= LoadImage(UserPathz[ptGraphics] + '/Progress', ifTransparent); |
766 texsurf:= LoadImage(UserPathz[ptGraphics] + '/Progress', ifTransparent); |
740 if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent); |
767 if texsurf = nil then |
|
768 texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent); |
741 |
769 |
742 ProgrTex:= Surface2Tex(texsurf, false); |
770 ProgrTex:= Surface2Tex(texsurf, false); |
743 |
771 |
744 squaresize:= texsurf^.w shr 1; |
772 squaresize:= texsurf^.w shr 1; |
745 numsquares:= texsurf^.h div squaresize; |
773 numsquares:= texsurf^.h div squaresize; |
746 SDL_FreeSurface(texsurf); |
774 SDL_FreeSurface(texsurf); |
747 |
775 |
748 uMobile.GameLoading(); |
776 uMobile.GameLoading(); |
749 end; |
777 end; |
750 |
778 |
751 TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true); |
779 TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true); |
752 |
780 |
753 glClear(GL_COLOR_BUFFER_BIT); |
781 glClear(GL_COLOR_BUFFER_BIT); |
754 if Step < numsquares then r.x:= 0 |
782 if Step < numsquares then |
755 else r.x:= squaresize; |
783 r.x:= 0 |
|
784 else |
|
785 r.x:= squaresize; |
756 |
786 |
757 r.y:= (Step mod numsquares) * squaresize; |
787 r.y:= (Step mod numsquares) * squaresize; |
758 r.w:= squaresize; |
788 r.w:= squaresize; |
759 r.h:= squaresize; |
789 r.h:= squaresize; |
760 |
790 |
784 r, r2: TSDL_Rect; |
814 r, r2: TSDL_Rect; |
785 wa, ha: LongInt; |
815 wa, ha: LongInt; |
786 tmpline, tmpline2, tmpdesc: ansistring; |
816 tmpline, tmpline2, tmpdesc: ansistring; |
787 begin |
817 begin |
788 // make sure there is a caption as well as a sub caption - description is optional |
818 // make sure there is a caption as well as a sub caption - description is optional |
789 if caption = '' then caption:= '???'; |
819 if caption = '' then |
790 if subcaption = '' then subcaption:= ' '; |
820 caption:= '???'; |
|
821 if subcaption = '' then |
|
822 subcaption:= ' '; |
791 |
823 |
792 font:= CheckCJKFont(caption,fnt16); |
824 font:= CheckCJKFont(caption,fnt16); |
793 font:= CheckCJKFont(subcaption,font); |
825 font:= CheckCJKFont(subcaption,font); |
794 font:= CheckCJKFont(description,font); |
826 font:= CheckCJKFont(description,font); |
795 font:= CheckCJKFont(extra,font); |
827 font:= CheckCJKFont(extra,font); |
810 h:= j + ha; |
842 h:= j + ha; |
811 |
843 |
812 // get sub caption's dimensions |
844 // get sub caption's dimensions |
813 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(subcaption), @i, @j); |
845 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(subcaption), @i, @j); |
814 // width adds 36 px (image + space) |
846 // width adds 36 px (image + space) |
815 if w < (i + 36 + wa) then w:= i + 36 + wa; |
847 if w < (i + 36 + wa) then |
|
848 w:= i + 36 + wa; |
816 inc(h, j + ha); |
849 inc(h, j + ha); |
817 |
850 |
818 // get description's dimensions |
851 // get description's dimensions |
819 tmpdesc:= description; |
852 tmpdesc:= description; |
820 while tmpdesc <> '' do |
853 while tmpdesc <> '' do |
822 tmpline:= tmpdesc; |
855 tmpline:= tmpdesc; |
823 SplitByChar(tmpline, tmpdesc, '|'); |
856 SplitByChar(tmpline, tmpdesc, '|'); |
824 if tmpline <> '' then |
857 if tmpline <> '' then |
825 begin |
858 begin |
826 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(tmpline), @i, @j); |
859 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(tmpline), @i, @j); |
827 if w < (i + wa) then w:= i + wa; |
860 if w < (i + wa) then |
|
861 w:= i + wa; |
828 inc(h, j + ha) |
862 inc(h, j + ha) |
829 end |
863 end |
830 end; |
864 end; |
831 |
865 |
832 if extra <> '' then |
866 if extra <> '' then |
833 begin |
867 begin |
834 // get extra label's dimensions |
868 // get extra label's dimensions |
835 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(extra), @i, @j); |
869 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(extra), @i, @j); |
836 if w < (i + wa) then w:= i + wa; |
870 if w < (i + wa) then |
|
871 w:= i + wa; |
837 inc(h, j + ha); |
872 inc(h, j + ha); |
838 end; |
873 end; |
839 |
874 |
840 // add borders space |
875 // add borders space |
841 inc(w, wa); |
876 inc(w, wa); |
954 var flags: Longword = 0; |
989 var flags: Longword = 0; |
955 reinit: boolean = false; |
990 reinit: boolean = false; |
956 {$IFNDEF DARWIN}ico: PSDL_Surface;{$ENDIF} |
991 {$IFNDEF DARWIN}ico: PSDL_Surface;{$ENDIF} |
957 {$IFDEF SDL13}x, y: LongInt;{$ENDIF} |
992 {$IFDEF SDL13}x, y: LongInt;{$ENDIF} |
958 begin |
993 begin |
959 if Length(s) = 0 then cFullScreen:= (not cFullScreen) |
994 if Length(s) = 0 then |
960 else cFullScreen:= s = '1'; |
995 cFullScreen:= (not cFullScreen) |
|
996 else |
|
997 cFullScreen:= s = '1'; |
961 |
998 |
962 AddFileLog('Preparing to change video parameters...'); |
999 AddFileLog('Preparing to change video parameters...'); |
963 {$IFNDEF IPHONEOS} |
1000 {$IFNDEF IPHONEOS} |
964 if SDLPrimSurface = nil then |
1001 if SDLPrimSurface = nil then |
965 begin |
1002 begin |
969 SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true); |
1006 SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true); |
970 WriteLnToConsole(msgOK); |
1007 WriteLnToConsole(msgOK); |
971 // load engine icon |
1008 // load engine icon |
972 {$IFNDEF DARWIN} |
1009 {$IFNDEF DARWIN} |
973 ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine', ifIgnoreCaps); |
1010 ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine', ifIgnoreCaps); |
974 if ico = nil then ico:= LoadImage(Pathz[ptGraphics] + '/hwengine', ifIgnoreCaps); |
1011 if ico = nil then |
|
1012 ico:= LoadImage(Pathz[ptGraphics] + '/hwengine', ifIgnoreCaps); |
975 if ico <> nil then |
1013 if ico <> nil then |
976 begin |
1014 begin |
977 SDL_WM_SetIcon(ico, 0); |
1015 SDL_WM_SetIcon(ico, 0); |
978 SDL_FreeSurface(ico) |
1016 SDL_FreeSurface(ico) |
979 end; |
1017 end; |
1017 SDL_SetHint('SDL_IOS_ORIENTATIONS','LandscapeLeft LandscapeRight'); |
1055 SDL_SetHint('SDL_IOS_ORIENTATIONS','LandscapeLeft LandscapeRight'); |
1018 flags:= flags or SDL_WINDOW_BORDERLESS or SDL_WINDOW_RESIZABLE; |
1056 flags:= flags or SDL_WINDOW_BORDERLESS or SDL_WINDOW_RESIZABLE; |
1019 {$ENDIF} |
1057 {$ENDIF} |
1020 |
1058 |
1021 if SDLwindow = nil then |
1059 if SDLwindow = nil then |
1022 if cFullScreen then SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cOrigScreenWidth, cOrigScreenHeight, flags or SDL_WINDOW_FULLSCREEN) |
1060 if cFullScreen then |
1023 else SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags); |
1061 SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cOrigScreenWidth, cOrigScreenHeight, flags or SDL_WINDOW_FULLSCREEN) |
|
1062 else |
|
1063 SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags); |
1024 SDLTry(SDLwindow <> nil, true); |
1064 SDLTry(SDLwindow <> nil, true); |
1025 {$ELSE} |
1065 {$ELSE} |
1026 flags:= SDL_OPENGL or SDL_RESIZABLE; |
1066 flags:= SDL_OPENGL or SDL_RESIZABLE; |
1027 if cFullScreen then |
1067 if cFullScreen then |
1028 flags:= flags or SDL_FULLSCREEN; |
1068 flags:= flags or SDL_FULLSCREEN; |
1043 if reinit then |
1083 if reinit then |
1044 begin |
1084 begin |
1045 // clean the window from any previous content |
1085 // clean the window from any previous content |
1046 glClear(GL_COLOR_BUFFER_BIT); |
1086 glClear(GL_COLOR_BUFFER_BIT); |
1047 if SuddenDeathDmg then |
1087 if SuddenDeathDmg then |
1048 glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99) |
1088 glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99) |
1049 else if ((cReducedQuality and rqNoBackground) = 0) then |
1089 else if ((cReducedQuality and rqNoBackground) = 0) then |
1050 glClearColor(SkyColor.r / 255, SkyColor.g / 255, SkyColor.b / 255, 0.99) |
1090 glClearColor(SkyColor.r / 255, SkyColor.g / 255, SkyColor.b / 255, 0.99) |
1051 else glClearColor(RQSkyColor.r / 255, RQSkyColor.g / 255, RQSkyColor.b / 255, 0.99); |
1091 else |
|
1092 glClearColor(RQSkyColor.r / 255, RQSkyColor.g / 255, RQSkyColor.b / 255, 0.99); |
1052 |
1093 |
1053 // reload everything we had before |
1094 // reload everything we had before |
1054 ReloadCaptions(false); |
1095 ReloadCaptions(false); |
1055 ReloadLines; |
1096 ReloadLines; |
1056 StoreLoad(true); |
1097 StoreLoad(true); |