75 procedure AddProgress; |
75 procedure AddProgress; |
76 procedure FinishProgress; |
76 procedure FinishProgress; |
77 function LoadImage(const filename: string; imageFlags: LongInt): PSDL_Surface; |
77 function LoadImage(const filename: string; imageFlags: LongInt): PSDL_Surface; |
78 procedure SetupOpenGL; |
78 procedure SetupOpenGL; |
79 procedure SetScale(f: GLfloat); |
79 procedure SetScale(f: GLfloat); |
80 |
80 procedure RenderWeaponTooltip(atype: TAmmoType); |
|
81 procedure ShowWeaponTooltip(x, y: LongInt); |
|
82 procedure FreeWeaponTooltip; |
81 |
83 |
82 implementation |
84 implementation |
83 uses uMisc, uConsole, uLand, uLocale, uWorld{$IFDEF IPHONEOS}, PascalExports{$ENDIF}; |
85 uses uMisc, uConsole, uLand, uLocale, uWorld{$IFDEF IPHONEOS}, PascalExports{$ENDIF}; |
84 |
86 |
85 type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple); |
87 type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple); |
143 finalRect.w:= w + FontBorder * 2 + 4; |
145 finalRect.w:= w + FontBorder * 2 + 4; |
144 finalRect.h:= h + FontBorder * 2; |
146 finalRect.h:= h + FontBorder * 2; |
145 WriteInRoundRect:= finalRect; |
147 WriteInRoundRect:= finalRect; |
146 end; |
148 end; |
147 |
149 |
|
150 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
|
151 var w, h: LongInt; |
|
152 tmpsurf: PSDL_Surface; |
|
153 clr: TSDL_Color; |
|
154 finalRect: TSDL_Rect; |
|
155 begin |
|
156 TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
|
157 finalRect.x:= X + FontBorder + 2; |
|
158 finalRect.y:= Y + FontBorder; |
|
159 finalRect.w:= w + FontBorder * 2 + 4; |
|
160 finalRect.h:= h + FontBorder * 2; |
|
161 clr.r:= Color shr 16; |
|
162 clr.g:= (Color shr 8) and $FF; |
|
163 clr.b:= Color and $FF; |
|
164 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr); |
|
165 tmpsurf:= doSurfaceConversion(tmpsurf); |
|
166 SDLTry(tmpsurf <> nil, true); |
|
167 SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect); |
|
168 SDL_FreeSurface(tmpsurf); |
|
169 finalRect.x:= X; |
|
170 finalRect.y:= Y; |
|
171 finalRect.w:= w + FontBorder * 2 + 4; |
|
172 finalRect.h:= h + FontBorder * 2; |
|
173 WriteInRect:= finalRect |
|
174 end; |
|
175 |
148 procedure StoreLoad; |
176 procedure StoreLoad; |
149 var s: string; |
177 var s: string; |
150 |
178 |
151 procedure WriteNames(Font: THWFont); |
179 procedure WriteNames(Font: THWFont); |
152 var t: LongInt; |
180 var t: LongInt; |
153 i: LongInt; |
181 i: LongInt; |
154 r, rr: TSDL_Rect; |
182 r, rr: TSDL_Rect; |
155 drY: LongInt; |
183 drY: LongInt; |
156 texsurf: PSDL_Surface; |
184 texsurf, flagsurf: PSDL_Surface; |
157 begin |
185 begin |
158 r.x:= 0; |
186 r.x:= 0; |
159 r.y:= 0; |
187 r.y:= 0; |
160 drY:= - 4; |
188 drY:= - 4; |
161 for t:= 0 to Pred(TeamsCount) do |
189 for t:= 0 to Pred(TeamsCount) do |
175 inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
203 inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
176 DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false); |
204 DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false); |
177 HealthTex:= Surface2Tex(texsurf, false); |
205 HealthTex:= Surface2Tex(texsurf, false); |
178 SDL_FreeSurface(texsurf); |
206 SDL_FreeSurface(texsurf); |
179 |
207 |
|
208 r.x:= 0; |
|
209 r.y:= 0; |
|
210 r.w:= 32; |
|
211 r.h:= 32; |
|
212 texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
|
213 TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
214 TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
215 |
|
216 r.w:= 26; |
|
217 r.h:= 19; |
|
218 |
|
219 DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true); |
|
220 |
|
221 flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone); |
|
222 if flagsurf = nil then |
|
223 flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone); |
|
224 TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true); |
|
225 copyToXY(flagsurf, texsurf, 2, 2); |
|
226 SDL_FreeSurface(flagsurf); |
|
227 |
|
228 // restore black border pixels inside the flag |
|
229 PLongwordArray(texsurf^.pixels)^[32 * 2 + 2]:= cNearBlackColor; |
|
230 PLongwordArray(texsurf^.pixels)^[32 * 2 + 23]:= cNearBlackColor; |
|
231 PLongwordArray(texsurf^.pixels)^[32 * 16 + 2]:= cNearBlackColor; |
|
232 PLongwordArray(texsurf^.pixels)^[32 * 16 + 23]:= cNearBlackColor; |
|
233 |
|
234 FlagTex:= Surface2Tex(texsurf, false); |
|
235 |
180 dec(drY, r.h + 2); |
236 dec(drY, r.h + 2); |
181 DrawHealthY:= drY; |
237 DrawHealthY:= drY; |
182 for i:= 0 to 7 do |
238 for i:= 0 to 7 do |
183 with Hedgehogs[i] do |
239 with Hedgehogs[i] do |
184 if Gear <> nil then |
240 if Gear <> nil then |
1314 destPixels^[j]:= srcPixels^[i]; |
1370 destPixels^[j]:= srcPixels^[i]; |
1315 inc(j) |
1371 inc(j) |
1316 end; |
1372 end; |
1317 end; |
1373 end; |
1318 |
1374 |
|
1375 function RenderHelpWindow(caption, subcaption, description, extra: shortstring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture; |
|
1376 var tmpsurf: PSDL_SURFACE; |
|
1377 w, h, i, j: LongInt; |
|
1378 font: THWFont; |
|
1379 r, r2: TSDL_Rect; |
|
1380 wa, ha: LongInt; |
|
1381 tmpline, tmpline2, tmpdesc: shortstring; |
|
1382 begin |
|
1383 font:= fnt16; |
|
1384 |
|
1385 // make sure there is a caption as well as a sub caption - description is optional |
|
1386 if caption = '' then caption:= '???'; |
|
1387 if subcaption = '' then subcaption:= ' '; |
|
1388 |
|
1389 w:= 0; |
|
1390 h:= 0; |
|
1391 wa:= FontBorder * 2 + 4; |
|
1392 ha:= FontBorder * 2; |
|
1393 |
|
1394 // TODO: Recheck height/position calculation |
|
1395 |
|
1396 // get caption's dimensions |
|
1397 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(caption), i, j); |
|
1398 // width adds 36 px (image + space) |
|
1399 w:= i + 36 + wa; |
|
1400 h:= j + ha; |
|
1401 |
|
1402 // get sub caption's dimensions |
|
1403 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(subcaption), i, j); |
|
1404 // width adds 36 px (image + space) |
|
1405 if w < (i + 36 + wa) then w:= i + 36 + wa; |
|
1406 inc(h, j + ha); |
|
1407 |
|
1408 // get description's dimensions |
|
1409 tmpdesc:= description; |
|
1410 while tmpdesc <> '' do |
|
1411 begin |
|
1412 tmpline:= tmpdesc; |
|
1413 SplitByChar(tmpline, tmpdesc, '|'); |
|
1414 if tmpline <> '' then |
|
1415 begin |
|
1416 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(tmpline), i, j); |
|
1417 if w < (i + wa) then w:= i + wa; |
|
1418 inc(h, j + ha) |
|
1419 end |
|
1420 end; |
|
1421 |
|
1422 if extra <> '' then |
|
1423 begin |
|
1424 // get extra label's dimensions |
|
1425 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(extra), i, j); |
|
1426 if w < (i + wa) then w:= i + wa; |
|
1427 inc(h, j + ha); |
|
1428 end; |
|
1429 |
|
1430 // add borders space |
|
1431 inc(w, wa); |
|
1432 inc(h, ha + 8); |
|
1433 |
|
1434 tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RMask, GMask, BMask, AMask); |
|
1435 TryDo(tmpsurf <> nil, 'RenderHelpWindow: fail to create surface', true); |
|
1436 |
|
1437 // render border and background |
|
1438 r.x:= 0; |
|
1439 r.y:= 0; |
|
1440 r.w:= w; |
|
1441 r.h:= h; |
|
1442 DrawRoundRect(@r, cWhiteColor, cNearBlackColor, tmpsurf, true); |
|
1443 |
|
1444 // render caption |
|
1445 r:= WriteInRect(tmpsurf, 36 + FontBorder + 2, ha, $ffffffff, font, caption); |
|
1446 // render sub caption |
|
1447 r:= WriteInRect(tmpsurf, 36 + FontBorder + 2, r.y + r.h, $ffc7c7c7, font, subcaption); |
|
1448 |
|
1449 // render all description lines |
|
1450 tmpdesc:= description; |
|
1451 while tmpdesc <> '' do |
|
1452 begin |
|
1453 tmpline:= tmpdesc; |
|
1454 SplitByChar(tmpline, tmpdesc, '|'); |
|
1455 r2:= r; |
|
1456 if tmpline <> '' then |
|
1457 begin |
|
1458 r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, $ff707070, font, tmpline); |
|
1459 |
|
1460 // render highlighted caption (if there's a ':') |
|
1461 SplitByChar(tmpline, tmpline2, ':'); |
|
1462 if tmpline2 <> '' then |
|
1463 WriteInRect(tmpsurf, FontBorder + 2, r2.y + r2.h, $ffc7c7c7, font, tmpline + ':'); |
|
1464 end |
|
1465 end; |
|
1466 |
|
1467 if extra <> '' then |
|
1468 r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, extracolor, font, extra); |
|
1469 |
|
1470 r.x:= FontBorder + 6; |
|
1471 r.y:= FontBorder + 4; |
|
1472 r.w:= 32; |
|
1473 r.h:= 32; |
|
1474 SDL_FillRect(tmpsurf, @r, $ffffffff); |
|
1475 SDL_UpperBlit(iconsurf, iconrect, tmpsurf, @r); |
|
1476 |
|
1477 RenderHelpWindow:= Surface2Tex(tmpsurf, true); |
|
1478 SDL_FreeSurface(tmpsurf) |
|
1479 end; |
|
1480 |
|
1481 procedure RenderWeaponTooltip(atype: TAmmoType); |
|
1482 var r: TSDL_Rect; |
|
1483 i: LongInt; |
|
1484 extra: string; |
|
1485 extracolor: LongInt; |
|
1486 begin |
|
1487 {$IFNDEF IPHONEOS} |
|
1488 // don't do anything if the window shouldn't be shown |
|
1489 if not cWeaponTooltips then |
|
1490 begin |
|
1491 {$ENDIF} |
|
1492 WeaponTooltipTex:= nil; |
|
1493 {$IFNDEF IPHONEOS} |
|
1494 exit |
|
1495 end; |
|
1496 |
|
1497 // free old texture |
|
1498 FreeWeaponTooltip; |
|
1499 |
|
1500 // image region |
|
1501 i:= LongInt(atype) - 1; |
|
1502 r.x:= (i shr 5) * 32; |
|
1503 r.y:= (i mod 32) * 32; |
|
1504 r.w:= 32; |
|
1505 r.h:= 32; |
|
1506 |
|
1507 // default (no extra text) |
|
1508 extra:= ''; |
|
1509 extracolor:= 0; |
|
1510 |
|
1511 if (CurrentTeam <> nil) and (Ammoz[atype].SkipTurns >= CurrentTeam^.Clan^.TurnNumber) then // weapon or utility is not yet available |
|
1512 begin |
|
1513 extra:= trmsg[sidNotYetAvailable]; |
|
1514 extracolor:= LongInt($ffc77070); |
|
1515 end |
|
1516 else if (Ammoz[atype].Ammo.Propz and ammoprop_NoRoundEndHint) <> 0 then // weapon or utility won't end your turn |
|
1517 begin |
|
1518 extra:= trmsg[sidNoEndTurn]; |
|
1519 extracolor:= LongInt($ff70c770); |
|
1520 end |
|
1521 else |
|
1522 begin |
|
1523 extra:= ''; |
|
1524 extracolor:= 0; |
|
1525 end; |
|
1526 |
|
1527 // render window and return the texture |
|
1528 WeaponTooltipTex:= RenderHelpWindow(trammo[Ammoz[atype].NameId], trammoc[Ammoz[atype].NameId], trammod[Ammoz[atype].NameId], extra, extracolor, SpritesData[sprAMAmmos].Surface, @r) |
|
1529 {$ENDIF} |
|
1530 end; |
|
1531 |
|
1532 procedure ShowWeaponTooltip(x, y: LongInt); |
|
1533 begin |
|
1534 {$IFNDEF IPHONEOS} |
|
1535 // draw the texture if it exists |
|
1536 if WeaponTooltipTex <> nil then |
|
1537 DrawTexture(x, y, WeaponTooltipTex) |
|
1538 {$ENDIF} |
|
1539 end; |
|
1540 |
|
1541 procedure FreeWeaponTooltip; |
|
1542 begin |
|
1543 {$IFNDEF IPHONEOS} |
|
1544 // free the existing texture (if there's any) |
|
1545 if WeaponTooltipTex = nil then |
|
1546 exit; |
|
1547 FreeTexture(WeaponTooltipTex); |
|
1548 WeaponTooltipTex:= nil |
|
1549 {$ENDIF} |
|
1550 end; |
|
1551 |
1319 procedure init_uStore; |
1552 procedure init_uStore; |
1320 begin |
1553 begin |
1321 PixelFormat:= nil; |
1554 PixelFormat:= nil; |
1322 SDLPrimSurface:= nil; |
1555 SDLPrimSurface:= nil; |
1323 {$IFNDEF IPHONEOS}cGPUVendor:= gvUnknown;{$ENDIF} |
1556 {$IFNDEF IPHONEOS}cGPUVendor:= gvUnknown;{$ENDIF} |