DEADSOFTWARE

gl: draw single stats
[d2df-sdl.git] / src / game / renders / opengl / r_render.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../../../shared/a_modes.inc}
16 unit r_render;
18 interface
20 uses
21 {$IFDEF ENABLE_MENU}
22 g_gui,
23 {$ENDIF}
24 g_base // TRectWH
25 ;
27 (* render startup *)
28 procedure r_Render_Initialize;
29 procedure r_Render_Finalize;
31 (* load globally used textures *)
32 procedure r_Render_Load;
33 procedure r_Render_Free;
35 (* load map specific textures *)
36 procedure r_Render_LoadTextures;
37 procedure r_Render_FreeTextures;
39 procedure r_Render_Update;
40 procedure r_Render_Draw;
42 procedure r_Render_Resize (w, h: Integer);
43 procedure r_Render_Apply;
45 function r_Render_WriteScreenShot (filename: String): Boolean;
47 {$IFDEF ENABLE_GIBS}
48 function r_Render_GetGibRect (m, id: Integer): TRectWH;
49 {$ENDIF}
51 {$IFDEF ENABLE_GFX}
52 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
53 {$ENDIF}
55 {$IFDEF ENABLE_TOUCH}
56 // touch screen button location and size
57 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
58 {$ENDIF}
60 {$IFDEF ENABLE_MENU}
61 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
62 procedure r_Render_GetLogoSize (out w, h: Integer);
63 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
64 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
65 {$ENDIF}
67 procedure r_Render_DrawLoading (force: Boolean); // !!! remove it
69 implementation
71 uses
72 {$IFDEF USE_GLES1}
73 GLES11,
74 {$ELSE}
75 GL, GLEXT,
76 {$ENDIF}
77 {$IFDEF ENABLE_MENU}
78 r_gui,
79 {$ENDIF}
80 {$IFDEF ENABLE_SYSTEM}
81 g_system,
82 {$ENDIF}
83 SysUtils, Classes, Math,
84 g_basic,
85 e_log, utils, wadreader,
86 g_game, g_map, g_options, g_console, g_player, g_weapons, g_language, g_triggers,
87 g_net, g_netmaster,
88 r_draw, r_textures, r_fonts, r_common, r_console, r_map
89 ;
91 type
92 TBasePoint = (
93 BP_LEFTUP, BP_UP, BP_RIGHTUP,
94 BP_LEFT, BP_CENTER, BP_RIGHT,
95 BP_LEFTDOWN, BP_DOWN, BP_RIGHTDOWN
96 );
98 var
99 BackgroundTexture: THereTexture;
101 hud, hudbg: TGLTexture;
102 hudhp: array [Boolean] of TGLTexture;
103 hudap: TGLTexture;
104 hudwp: array [0..WP_LAST] of TGLTexture;
105 hudkey: array [0..2] of TGLTexture;
106 hudair: TGLTexture;
107 hudjet: TGLTexture;
108 hudrflag, hudrflags, hudrflagd: TGLTexture;
109 hudbflag, hudbflags, hudbflagd: TGLTexture;
111 procedure r_Render_LoadTextures;
112 begin
113 r_Map_LoadTextures;
114 end;
116 procedure r_Render_FreeTextures;
117 begin
118 r_Map_FreeTextures;
119 end;
121 procedure r_Render_Load;
122 const
123 WeapName: array [0..WP_LAST] of AnsiString = ('KASTET', 'SAW', 'PISTOL', 'SHOTGUN1', 'SHOTGUN2', 'MGUN', 'RLAUNCHER', 'PGUN', 'BFG', 'SPULEMET', 'FLAMETHROWER');
124 var
125 i: Integer;
126 begin
127 r_Common_Load;
128 BackgroundTexture := DEFAULT(THereTexture);
129 hud := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUD');
130 hudbg := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUDBG');
131 hudhp[false] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/MED2');
132 hudhp[true] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/BMED');
133 hudap := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/ARMORHUD');
134 for i := 0 to WP_LAST do
135 hudwp[i] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/' + WeapName[i]);
136 hudkey[0] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYR');
137 hudkey[1] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYG');
138 hudkey[2] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYB');
139 hudair := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/AIRBAR');
140 hudjet := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/JETBAR');
141 hudrflag := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_BASE');
142 hudrflags := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_STOLEN');
143 hudrflagd := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_DROP');
144 hudbflag := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_BASE');
145 hudbflags := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_STOLEN');
146 hudbflagd := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_DROP');
147 r_Console_Load;
148 r_Map_Load;
149 {$IFDEF ENABLE_MENU}
150 r_GUI_Load;
151 {$ENDIF}
152 end;
154 procedure r_Render_Free;
155 var i: Integer;
156 begin
157 {$IFDEF ENABLE_MENU}
158 r_GUI_Free;
159 {$ENDIF}
160 r_Map_Free;
161 r_Console_Free;
162 hudbflagd.Free;
163 hudbflags.Free;
164 hudbflag.Free;
165 hudrflagd.Free;
166 hudrflags.Free;
167 hudrflag.Free;
168 hudjet.Free;
169 hudair.Free;
170 hudkey[0].Free;
171 hudkey[1].Free;
172 hudkey[2].Free;
173 for i := 0 to WP_LAST do
174 begin
175 if hudwp[i] <> nil then
176 hudwp[i].Free;
177 hudwp[i] := nil;
178 end;
179 hudap.Free;
180 hudhp[true].Free;
181 hudhp[false].Free;
182 hudbg.Free;
183 hud.Free;
184 r_Common_FreeThis(BackgroundTexture);
185 r_Common_Free;
186 end;
188 {$IFDEF ENABLE_SYSTEM}
189 function GetInfo (): TGLDisplayInfo;
190 var info: TGLDisplayInfo;
191 begin
192 info := Default(TGLDisplayInfo);
193 info.w := Max(1, gRC_Width);
194 info.h := Max(1, gRC_Height);
195 info.bpp := Max(1, gBPP);
196 info.fullscreen := gRC_FullScreen;
197 info.maximized := gRC_Maximized;
198 info.major := 1;
199 info.minor := 1;
200 info.profile := TGLProfile.Compat;
201 result := info;
202 end;
203 {$ENDIF}
205 procedure r_Render_Initialize;
206 begin
207 {$IFDEF ENABLE_SYSTEM}
208 if sys_SetDisplayModeGL(GetInfo()) = False then
209 raise Exception.Create('Failed to set videomode on startup.');
210 sys_EnableVSync(gVSync);
211 {$ENDIF}
212 r_Textures_Initialize;
213 r_Console_Initialize;
214 r_Map_Initialize;
215 end;
217 procedure r_Render_Finalize;
218 begin
219 r_Map_Finalize;
220 r_Console_Finalize;
221 r_Textures_Finalize;
222 end;
224 procedure r_Render_Update;
225 begin
226 r_Console_Update;
227 r_Map_Update;
228 end;
230 procedure r_Render_GetBasePoint (x, y, w, h: Integer; p: TBasePoint; out xx, yy: Integer);
231 begin
232 case p of
233 TBasePoint.BP_LEFTUP, TBasePoint.BP_LEFT, TBasePoint.BP_LEFTDOWN: xx := x;
234 TBasePoint.BP_UP, TBasePoint.BP_CENTER, TBasePoint.BP_DOWN: xx := x - w div 2;
235 TBasePoint.BP_RIGHTUP, TBasePoint.BP_RIGHT, TBasePoint.BP_RIGHTDOWN: xx := x - w;
236 end;
237 case p of
238 TBasePoint.BP_LEFTUP, TBasePoint.BP_UP, TBasePoint.BP_RIGHTUP: yy := y;
239 TBasePoint.BP_LEFT, TBasePoint.BP_CENTER, TBasePoint.BP_RIGHT: yy := y - h div 2;
240 TBasePoint.BP_LEFTDOWN, TBasePoint.BP_DOWN, TBasePoint.BP_RIGHTDOWN: yy := y - h;
241 end;
242 end;
244 procedure r_Render_DrawText (const text: AnsiString; x, y: Integer; r, g, b, a: Byte; f: TGLFont; p: TBasePoint);
245 var w, h: Integer;
246 begin
247 if p <> TBasePoint.BP_LEFTUP then
248 begin
249 r_Draw_GetTextSize(text, f, w, h);
250 r_Render_GetBasePoint(x, y, w, h, p, x, y);
251 end;
252 r_Draw_Text(text, x, y, r, g, b, a, f);
253 end;
255 procedure r_Render_DrawTexture (img: TGLTexture; x, y, w, h: Integer; p: TBasePoint);
256 begin
257 r_Render_GetBasePoint(x, y, w, h, p, x, y);
258 r_Draw_TextureRepeat(img, x, y, w, h, false, 255, 255, 255, 255, false);
259 end;
261 procedure r_Render_DrawHUD (x, y: Integer; p: TPlayer);
262 var t: TGLTexture; s: AnsiString;
263 begin
264 ASSERT(p <> nil);
266 // hud area is 196 x 240 pixels
267 r_Render_DrawTexture(hud, x, y, hud.width, hud.height, TBasePoint.BP_LEFTUP);
268 r_Render_DrawText(p.name, x + 98, y + 16, 255, 0, 0, 255, smallfont, TBasePoint.BP_CENTER);
270 t := hudhp[R_BERSERK in p.FRulez];
271 r_Render_DrawTexture(t, x + 51, y + 61, t.width, t.height, TBasePoint.BP_CENTER);
272 r_Render_DrawTexture(hudap, x + 50, y + 85, hudap.width, hudap.height, TBasePoint.BP_CENTER);
274 r_Render_DrawText(IntToStr(MAX(0, p.health)), x + 174, y + 56, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
275 r_Render_DrawText(IntToStr(MAX(0, p.armor)), x + 174, y + 84, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
277 case p.CurrWeap of
278 WEAPON_KASTET, WEAPON_SAW: s := '--';
279 else s := IntToStr(p.GetAmmoByWeapon(p.CurrWeap));
280 end;
281 r_Render_DrawText(s, x + 174, y + 174, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
283 if p.CurrWeap <= WP_LAST then
284 begin
285 t := hudwp[p.CurrWeap];
286 r_Render_DrawTexture(t, x + 18, y + 160, t.width, t.height, TBasePoint.BP_LEFTUP);
287 end;
289 if R_KEY_RED in p.FRulez then
290 r_Render_DrawTexture(hudkey[0], x + 76, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
291 if R_KEY_GREEN in p.FRulez then
292 r_Render_DrawTexture(hudkey[1], x + 93, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
293 if R_KEY_BLUE in p.FRulez then
294 r_Render_DrawTexture(hudkey[2], x + 110, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
296 if p.JetFuel > 0 then
297 begin
298 r_Render_DrawTexture(hudair, x, y + 116, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
299 if p.air > 0 then
300 r_Draw_FillRect(x + 14, y + 116 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 116 + 4 + 4, 0, 0, 196, 255);
301 r_Render_DrawTexture(hudjet, x, y + 126, hudjet.width, hudjet.height, TBasePoint.BP_LEFTUP);
302 r_Draw_FillRect(x + 14, y + 126 + 4, x + 14 + 168 * p.JetFuel div JET_MAX, y + 126 + 4 + 4, 208, 0, 0, 255);
303 end
304 else
305 begin
306 r_Render_DrawTexture(hudair, x, y + 124, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
307 if p.air > 0 then
308 r_Draw_FillRect(x + 14, y + 124 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 124 + 4 + 4, 0, 0, 196, 255);
309 end;
310 end;
312 procedure r_Render_DrawHUDArea (x, y, w, h: Integer; p: TPlayer);
313 var s: AnsiString;
314 begin
315 r_Render_DrawTexture(hudbg, x, y, w, h, TBasePoint.BP_LEFTUP);
317 if p <> nil then
318 r_Render_DrawHUD(x + w - 196 + 2, y, p);
320 if gShowPing and g_Game_IsClient then
321 begin
322 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
323 r_Render_DrawText(s, x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
324 end;
326 if p.Spectator then
327 begin
328 r_Render_DrawText(_lc[I_PLAYER_SPECT], x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
329 r_Render_DrawText(_lc[I_PLAYER_SPECT2], x + 4, y + 258, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
330 r_Render_DrawText(_lc[I_PLAYER_SPECT1], x + 4, y + 274, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
331 if p.NoRespawn then
332 r_Render_DrawText(_lc[I_PLAYER_SPECT1S], x + 4, y + 290, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
333 end;
334 end;
336 procedure r_Render_DrawStatsView (x, y, w, h: Integer; p: TPlayer);
337 var fw, i, maxFrags, top, totalPlayers: Integer; sign: Char; stat: TPlayerStatArray; f: TGLTexture;
338 begin
339 ASSERT(p <> nil);
341 if gShowScore and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
342 begin
343 (* RED TEAM GOALS *)
344 fw := 0;
345 if gGameSettings.GameMode = GM_CTF then
346 begin
347 case gFlags[FLAG_RED].State of
348 FLAG_STATE_CAPTURED: f := hudrflags;
349 FLAG_STATE_DROPPED: f := hudrflagd;
350 otherwise f := hudrflag;
351 end;
352 if f <> nil then
353 begin
354 fw := f.width + 8; (* + space *)
355 r_Render_DrawTexture(f, x + w - 16, y + 240 - 72 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
356 end;
357 end;
358 r_Render_DrawText(IntToStr(gTeamStat[TEAM_RED].Score), x + w - 16 - fw, y + 240 - 72 - 4, TEAMCOLOR[TEAM_RED].R, TEAMCOLOR[TEAM_RED].G, TEAMCOLOR[TEAM_RED].B, 255, menufont, TBasePoint.BP_RIGHTUP);
360 (* BLUE TEAM GOALS *)
361 fw := 0;
362 if gGameSettings.GameMode = GM_CTF then
363 begin
364 case gFlags[FLAG_BLUE].State of
365 FLAG_STATE_CAPTURED: f := hudbflags;
366 FLAG_STATE_DROPPED: f := hudbflagd;
367 otherwise f := hudbflag;
368 end;
369 if f <> nil then
370 begin
371 fw := f.width + 8; (* + space *)
372 r_Render_DrawTexture(f, x + w - 16, y + 240 - 32 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
373 end;
374 end;
375 r_Render_DrawText(IntToStr(gTeamStat[TEAM_BLUE].Score), x + w - 16 - fw, y + 240 - 32 - 4, TEAMCOLOR[TEAM_BLUE].R, TEAMCOLOR[TEAM_BLUE].G, TEAMCOLOR[TEAM_BLUE].B, 255, menufont, TBasePoint.BP_RIGHTUP);
376 end;
378 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
379 begin
380 if gShowStat then
381 begin
382 r_Render_DrawText(IntToStr(p.Frags), x + w - 16, y, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHTUP);
384 top := 1;
385 maxFrags := 0;
386 totalPlayers := 0;
387 stat := g_Player_GetStats();
388 if stat <> nil then
389 begin
390 totalPlayers := Length(stat);
391 for i := 0 to High(stat) do
392 begin
393 if stat[i].Name <> p.Name then
394 begin
395 maxFrags := MAX(maxFrags, stat[i].Frags);
396 if stat[i].Frags > p.Frags then
397 top := top + 1;
398 end;
399 end;
400 end;
401 if p.Frags >= maxFrags then sign := '+' else sign := '-';
402 r_Render_DrawText(IntToStr(top) + ' / ' + IntToStr(totalPlayers) + ' ' + sign + IntToStr(ABS(p.Frags - maxFrags)), x + w - 16, y + 32, 255, 0, 0, 255, smallfont, TBasePoint.BP_RIGHTUP);
403 end;
405 if gLMSRespawn > LMS_RESPAWN_NONE then
406 begin
407 r_Render_DrawText(_lc[I_GAME_WARMUP], x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
408 r_Render_DrawText(': ' + IntToStr((gLMSRespawnTime - gTime) div 1000), x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_LEFTDOWN);
409 end
410 else if gShowLives and (gGameSettings.MaxLives > 0) then
411 begin
412 r_Render_DrawText(IntToStr(p.Lives), x + w - 16, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
413 end;
414 end;
415 end;
417 procedure r_Render_DrawView (x, y, w, h: Integer; p: TPlayer);
418 var l, t, r, b: Integer;
419 begin
420 r_Draw_GetRect(l, t, r, b);
421 r_Draw_SetRect(x, y, x + w, y + h);
423 if p <> nil then
424 begin
425 r_Map_Draw(x, y, w, h, p.obj.x + PLAYER_RECT_CX, p.obj.y + PLAYER_RECT_CY, p);
426 r_Render_DrawStatsView(x, y, w, h, p);
427 if p.Spectator and p.NoRespawn then
428 r_Render_DrawText(_lc[I_PLAYER_SPECT4], x div 2 + w div 2, y div 2 + h div 2, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
429 end
430 else
431 begin
432 r_Map_Draw(x, y, w, h, 0, 0, nil);
433 end;
435 r_Draw_SetRect(l, t, r, b);
436 end;
438 procedure r_Render_DrawPlayerView (x, y, w, h: Integer; p: TPlayer);
439 var l, t, r, b: Integer;
440 begin
441 r_Draw_GetRect(l, t, r, b);
442 r_Draw_SetRect(x, y, x + w, y + h);
443 r_Render_DrawView(x, y, w - 196, h, p);
444 r_Render_DrawHUDArea(x + w - 196, y, 196, h, p);
445 r_Draw_SetRect(l, t, r, b);
446 end;
448 procedure r_Render_DrawBackgroundImage (img: TGLTexture);
449 var fw, w, h: LongInt;
450 begin
451 if img <> nil then
452 begin
453 img := BackgroundTexture.id;
454 if img.width = img.height then fw := img.width * 4 div 3 else fw := img.width; // fix aspect 4:3
455 r_Common_CalcAspect(fw, img.height, gScreenWidth, gScreenHeight, false, w, h);
456 r_Draw_Texture(img, gScreenWidth div 2 - w div 2, 0, w, h, false, 255, 255, 255, 255, false);
457 end
458 end;
460 procedure r_Render_DrawBackground (const name: AnsiString);
461 begin
462 if r_Common_LoadThis(name, BackgroundTexture) then
463 r_Render_DrawBackgroundImage(BackgroundTexture.id)
464 end;
466 procedure r_Render_DrawServerList (var SL: TNetServerList; var ST: TNetServerTable);
467 var ip: AnsiString; ww, hh, cw, ch, mw, mh, motdh, scrx, scry, i, mx, y: Integer; msg: SSArray; Srv: TNetServer;
468 begin
469 scrx := gScreenWidth div 2;
470 scry := gScreenHeight div 2;
472 r_Draw_GetTextSize(_lc[I_NET_SLIST], menufont, ww, hh);
473 r_Render_DrawText(_lc[I_NET_SLIST], gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
475 r_Draw_GetTextSize('W', stdfont, cw, ch);
476 motdh := gScreenHeight - 49 - ch * b_Text_LineCount(slMOTD);
478 r_Draw_FillRect(16, 64, gScreenWidth - 16, motdh, 64, 64, 64, 145);
479 r_Draw_Rect(16, 64, gScreenWidth - 16, motdh, 255, 127, 0, 255);
481 r_Render_DrawText(_lc[I_NET_SLIST_HELP], gScreenWidth div 2, gScreenHeight - 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
483 if slMOTD <> '' then
484 begin
485 r_Draw_FillRect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 64, 64, 64, 110);
486 r_Draw_Rect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 255, 127, 0, 255);
487 msg := Parse2(slMOTD, #10);
488 for i := 0 to High(msg) do
489 r_Render_DrawText(msg[i], 20, motdh + 3 + ch * i, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
490 end;
492 if not slReadUrgent and (slUrgent <> '') then
493 begin
494 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
495 r_Draw_FillRect(scrx - 256, scry - 60, scrx + 256, scry + 60, 64, 64, 64, 127);
496 r_Draw_Rect(scrx - 256, scry - 60, scrx + 256, scry + 60, 255, 127, 0, 255);
497 r_Draw_FillRect(scrx - 256, scry - 40, scrx + 256, scry - 40, 255, 127, 0, 255);
498 r_Render_DrawText(_lc[I_NET_SLIST_URGENT], scrx, scry - 58, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
499 msg := Parse2(slUrgent, #10);
500 for i := 0 to High(msg) do
501 r_Render_DrawText(msg[i], scrx - 253, scry - 38 + ch * i, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
502 r_Render_DrawText(_lc[I_NET_SLIST_URGENT_CONT], scrx, scry + 41, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
503 r_Draw_FillRect(scrx - 256, scry + 40, scrx + 256, scry + 40, 255, 127, 0, 255);
504 end
505 else if SL = nil then
506 begin
507 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
508 r_Draw_Rect(scrx - 192, scry - 10, scrx + 192, scry + 11, 255, 127, 0, 255);
509 r_Render_DrawText(slWaitStr, scrx, scry, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
510 end
511 else
512 begin
513 y := 90;
514 if slSelection < Length(ST) then
515 begin
516 sy := y + 42 * slSelection - 4;
517 Srv := GetServerFromTable(slSelection, SL, ST);
518 ip := _lc[I_NET_ADDRESS] + ' ' + Srv.IP + ':' + IntToStr(Srv.Port);
519 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ';
520 if Srv.Password then ip := ip + _lc[I_MENU_YES] else ip := ip +_lc[I_MENU_NO];
521 end;
523 mw := gScreenWidth - 188;
524 mx := 16 + mw;
526 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy + 40, 64, 64, 64, 255);
527 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy, 205, 205, 205, 255);
528 r_Draw_FillRect(16 + 1, sy + 41, gScreenWidth - 16 - 1, sy + 41, 255, 255, 255, 255);
530 r_Draw_FillRect(16, 85, gScreenWidth - 16, 85, 255, 127, 0, 255);
531 r_Draw_FillRect(16, motdh - 20, gScreenWidth - 16, motdh - 20, 255, 127, 0, 255);
533 r_Draw_FillRect(mx - 70, 64, mx - 70, motdh, 255, 127, 0, 255);
534 r_Draw_FillRect(mx, 64, mx, motdh - 20, 255, 127, 0, 255);
535 r_Draw_FillRect(mx + 52, 64, mx + 52, motdh - 20, 255, 127, 0, 255);
536 r_Draw_FillRect(mx + 104, 64, mx + 104, motdh - 20, 255, 127, 0, 255);
538 r_Render_DrawText('NAME/MAP', 18, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
539 r_Render_DrawText('PING', mx - 68, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
540 r_Render_DrawText('MODE', mx + 2, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
541 r_Render_DrawText('PLRS', mx + 54, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
542 r_Render_DrawText('VER', mx + 106, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
544 for i := 0 to High(ST) do
545 begin
546 Srv := GetServerFromTable(i, SL, ST);
547 r_Render_DrawText(Srv.Name, 18, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
548 r_Render_DrawText(Srv.Map, 18, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
550 if Srv.Ping = 0 then
551 r_Render_DrawText('<1' + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
552 else if (Srv.Ping >= 0) and (Srv.Ping <= 999) then
553 r_Render_DrawText(IntToStr(Srv.Ping) + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
554 else
555 r_Render_DrawText(_lc[I_NET_SLIST_NO_ACCESS], mx - 68, y, 255, 0, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
556 if Length(ST[I].Indices) > 1 then
557 r_Render_DrawText('<' + IntToStr(Length(ST[I].Indices)) + '>', mx - 68, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
559 r_Render_DrawText(g_Game_ModeToText(Srv.GameMode), mx + 2, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
561 r_Render_DrawText(IntToStr(Srv.Players) + '/' + IntToStr(Srv.MaxPlayers), mx + 54, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
562 r_Render_DrawText(IntToStr(Srv.LocalPl) + '+' + IntToStr(Srv.Bots), mx + 54, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
564 r_Render_DrawText(IntToStr(Srv.Protocol), mx + 106, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
566 y := y + 42;
567 end;
569 r_Render_DrawText(ip, 20, motdh - 20 + 3, 205, 205, 205, 255, stdfont, TBasePoint.BP_LEFTUP);
570 r_Render_DrawText(IntToStr(Length(ST)) + _lc[I_NET_SLIST_SERVERS], gScreenWidth - 48, motdh - 20 + 3, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
571 end;
572 end;
574 function r_Render_TimeToStr (t: LongWord): AnsiString;
575 var h, m, s: Integer;
576 begin
577 h := t div 1000 div 3600;
578 m := t div 1000 div 60 mod 60;
579 s := t div 1000 mod 60;
580 result := Format('%d:%.2d:%.2d', [h, m, s]);
581 end;
583 procedure r_Render_DrawStatsColumns (constref cs: TEndCustomGameStat; x, y, w: Integer; endview: Boolean);
584 var i, cw, ch, yy, team, players, w1, w2, w3, w4, tw: Integer; r, g, b, rr, gg, bb: Byte; s: AnsiString;
585 begin
586 r_Draw_GetTextSize('W', stdfont, cw, ch);
587 w4 := cw * 6; (* deaths width *)
588 w3 := cw * 8; (* frags width *)
589 w2 := cw * 12; (* ping/loss width *)
590 w1 := w - w2 - w3 - w4; (* name width *)
591 tw := w1 - cw * 2 - w2; (* team goals *)
592 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
593 yy := y;
594 if cs.GameMode in [GM_TDM, GM_CTF] then
595 begin
596 for team := TEAM_RED to TEAM_BLUE do
597 begin
598 case team of
599 TEAM_RED:
600 begin
601 s := _lc[I_GAME_TEAM_RED];
602 r := 255; g := 0; b := 0;
603 end;
604 TEAM_BLUE:
605 begin
606 s := _lc[I_GAME_TEAM_BLUE];
607 r := 0; g := 0; b := 255;
608 end;
609 end;
610 r_Render_DrawText(s, x, yy, r, g, b, 255, stdfont, TBasePoint.BP_LEFTUP);
611 r_Render_DrawText(IntToStr(cs.TeamStat[team].Score), x + tw, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
612 if endview = false then
613 r_Render_DrawText(_lc[I_GAME_PING], x + w1, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
614 r_Render_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
615 r_Render_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
616 INC(yy, ch);
618 INC(yy, ch div 4);
619 r_Draw_FillRect(x, yy, x + w - 1, yy, r, g, b, 255);
620 INC(yy, ch div 4);
622 for i := 0 to players - 1 do
623 begin
624 if cs.PlayerStat[i].Team = team then
625 begin
626 rr := r; gg := g; bb := b;
627 if cs.PlayerStat[i].Spectator then
628 begin
629 rr := r div 2; gg := g div 2; bb := b div 2;
630 end;
632 // Player name
633 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
634 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
635 r_Render_DrawText(s, x, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
636 if endview = false then
637 begin
638 // Player ping/loss
639 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
640 r_Render_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
641 end;
642 // Player frags
643 s := IntToStr(cs.PlayerStat[i].Frags);
644 r_Render_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
645 // Player deaths
646 s := IntToStr(cs.PlayerStat[i].Deaths);
647 r_Render_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
649 INC(yy, ch);
650 end;
651 end;
652 INC(yy, ch);
653 end;
654 end
655 else if cs.GameMode in [GM_DM, GM_COOP] then
656 begin
657 r_Render_DrawText(_lc[I_GAME_PLAYER_NAME], x, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
658 if endview = false then
659 r_Render_DrawText(_lc[I_GAME_PING], x + w1, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
660 r_Render_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
661 r_Render_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
662 INC(yy, ch + ch div 2);
663 for i := 0 to players - 1 do
664 begin
665 // rr := 255; gg := 127; bb := 0;
666 rr := 255; gg := 255; bb := 255;
667 if cs.PlayerStat[i].Spectator then
668 begin
669 rr := rr div 2; gg := gg div 2; bb := bb div 2;
670 end;
672 // Player color
673 r_Draw_Rect(x, yy, x + 16 - 1, yy + 16 - 1, 192, 192, 192, 255);
674 r_Draw_FillRect(x + 1, yy + 1, x + 16 - 1, yy + 16 - 1, cs.PlayerStat[i].Color.R, cs.PlayerStat[i].Color.G, cs.PlayerStat[i].Color.B, 255);
675 // Player name
676 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
677 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
678 r_Render_DrawText(s, x + 16 + 8, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
679 if endview = false then
680 begin
681 // Player ping/loss
682 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
683 r_Render_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
684 end;
685 // Player frags
686 s := IntToStr(cs.PlayerStat[i].Frags);
687 r_Render_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
688 // Player deaths
689 s := IntToStr(cs.PlayerStat[i].Deaths);
690 r_Render_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
692 INC(yy, ch + ch div 2);
693 end;
694 end;
695 end;
697 procedure r_Render_DrawStatsWindow (x, y, w, h: Integer; cs: TEndCustomGameStat; endview: Boolean);
698 var xoff, yoff, cw, ch: Integer; s: AnsiString;
699 begin
700 xoff := 0; yoff := 8;
701 r_Draw_GetTextSize('W', stdfont, cw, ch);
702 r_Draw_FillRect(x, y, x + w - 1, y + h - 1, 64, 64, 64, 224);
703 r_Draw_Rect(x, y, x + w - 1, y + h - 1, 255, 127, 0, 255);
705 (* LINE 1 *)
707 if endview = false then
708 begin
709 case NetMode of
710 NET_SERVER: s := _lc[I_NET_SERVER];
711 NET_CLIENT: s := NetClientIP + ':' + IntToStr(NetClientPort);
712 otherwise s := '';
713 end;
714 r_Render_DrawText(s, x + 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
715 end;
717 case cs.GameMode of
718 GM_DM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_DM] else s := _lc[I_GAME_LMS];
719 GM_TDM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_TDM] else s := _lc[I_GAME_TLMS];
720 GM_CTF: s := _lc[I_GAME_CTF];
721 GM_COOP: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_COOP] else s := _lc[I_GAME_SURV];
722 otherwise s := 'GAME MODE ' + IntToStr(gGameSettings.GameMode);
723 end;
724 r_Render_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
726 if endview = false then
727 begin
728 s := r_Render_TimeToStr(cs.GameTime);
729 r_Render_DrawText(s, x + w - 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
730 end;
732 INC(yoff, ch + ch div 2);
734 (* LINE 2/3 *)
736 s := cs.Map;
737 if cs.MapName <> '' then
738 s := s + ' - ' + cs.MapName;
740 if endview = false then
741 begin
742 r_Render_DrawText(s, x + w div 2, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_UP);
743 INC(yoff, ch + ch div 2);
744 case cs.GameMode of
745 GM_DM, GM_TDM: s := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
746 GM_CTF: s := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]);
747 GM_COOP: s := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
748 otherwise s := '';
749 end;
750 r_Render_DrawText(s, x + 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_LEFTUP);
751 case cs.GameMode of
752 GM_DM, GM_TDM, GM_CTF: s := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
753 GM_COOP: s := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
754 otherwise s := '';
755 end;
756 r_Render_DrawText(s, x + w - 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_RIGHTUP);
757 INC(yoff, ch);
758 end
759 else
760 begin
761 xoff := MAX(Length(_lc[I_MENU_MAP]) + 1, Length(_lc[I_GAME_GAME_TIME]) + 1) * cw;
762 r_Render_DrawText(_lc[I_MENU_MAP], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
763 r_Render_DrawText(s, x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
764 INC(yoff, ch);
765 r_Render_DrawText(_lc[I_GAME_GAME_TIME], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
766 r_Render_DrawText(r_Render_TimeToStr(cs.GameTime), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
767 INC(yoff, ch);
768 end;
770 INC(yoff, ch);
772 (* LINE 4/5 *)
774 if endview and (cs.GameMode = GM_COOP) then
775 begin
776 xoff := MAX(Length(_lc[I_GAME_MONSTERS]) + 1, Length(_lc[I_GAME_SECRETS]) + 1) * cw;
777 r_Render_DrawText(_lc[I_GAME_MONSTERS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
778 r_Render_DrawText(IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
779 INC(yoff, ch);
780 r_Render_DrawText(_lc[I_GAME_SECRETS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
781 r_Render_DrawText(IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
782 INC(yoff, ch);
783 INC(yoff, ch);
784 end;
786 (* LINE 6/7 *)
788 if endview and (cs.GameMode = GM_COOP) and gLastMap then
789 begin
790 xoff := MAX(Length(_lc[I_GAME_MONSTERS_TOTAL]) + 1, Length(_lc[I_GAME_SECRETS_TOTAL]) + 1) * cw;
791 r_Render_DrawText(_lc[I_GAME_MONSTERS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
792 r_Render_DrawText(IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
793 INC(yoff, ch);
794 r_Render_DrawText(_lc[I_GAME_SECRETS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
795 r_Render_DrawText(IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
796 INC(yoff, ch);
797 INC(yoff, ch);
798 end;
800 (* LINE *)
802 if endview and (cs.GameMode in [GM_TDM, GM_CTF]) then
803 begin
804 if cs.TeamStat[TEAM_RED].Score > cs.TeamStat[TEAM_BLUE].Score then s := _lc[I_GAME_WIN_RED]
805 else if cs.TeamStat[TEAM_BLUE].Score > cs.TeamStat[TEAM_RED].Score then s := _lc[I_GAME_WIN_BLUE]
806 else s := _lc[I_GAME_WIN_DRAW];
807 r_Render_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
808 INC(yoff, ch);
809 INC(yoff, ch);
810 end;
812 (* LINE n *)
814 r_Render_DrawStatsColumns(cs, x + 16, y + yoff, w - 16 - 16, endview);
815 end;
817 function r_Render_StatsHeight (players: Integer): Integer;
818 var cw, ch: Integer;
819 begin
820 ASSERT(players >= 0);
821 r_Draw_GetTextSize('W', stdfont, cw, ch);
822 case gGameSettings.GameMode of
823 GM_TDM, GM_CTF: result := 32 + ch * (11 + players);
824 otherwise result := 40 + ch * 5 + (ch + 8) * players;
825 end;
826 end;
828 procedure r_Render_DrawStats;
829 var x, y, w, h, players: Integer; cs: TEndCustomGameStat;
830 begin
831 cs.PlayerStat := g_Player_GetStats();
832 SortGameStat(cs.PlayerStat);
833 cs.TeamStat := gTeamStat;
834 cs.GameTime := gTime;
835 cs.GameMode := gGameSettings.GameMode;
836 cs.Map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':' + g_ExtractFileName(gMapInfo.Map);
837 cs.MapName := gMapInfo.Name;
838 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
839 w := gScreenWidth - (gScreenWidth div 5);
840 h := r_Render_StatsHeight(players);
841 x := (gScreenWidth div 2) - (w div 2);
842 y := (gScreenHeight div 2) - (h div 2);
843 r_Render_DrawStatsWindow(x, y, w, h, cs, false);
844 end;
846 procedure r_Render_DrawCustomStats;
847 var cw, ch, s: AnsiString;
848 begin
849 if gStatsOff then
850 begin
851 r_Render_DrawText(_lc[I_MENU_INTER_NOTICE_TAB], gScreenWidth div 2, 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
852 end
853 else
854 begin
855 case gGameSettings.GameMode of
856 GM_COOP: if gMissionFailed then s := _lc[I_MENU_INTER_MISSION_FAIL] else s := _lc[I_MENU_INTER_LEVEL_COMPLETE];
857 otherwise s := _lc[I_MENU_INTER_ROUND_OVER];
858 end;
859 r_Render_DrawText(s, gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
861 if gChatShow = false then
862 begin
863 if g_Game_IsClient then s := _lc[I_MENU_INTER_NOTICE_MAP] else s := _lc[I_MENU_INTER_NOTICE_SPACE];
864 r_Render_DrawText(s, gScreenWidth div 2, gScreenHeight - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
865 if g_Game_IsNet then
866 begin
867 s := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
868 r_Render_DrawText(s, gScreenWidth div 2, gScreenHeight - 16 - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
869 end;
870 end;
872 r_Render_DrawStatsWindow(32, 64, gScreenWidth - 32 * 2, gScreenHeight - 64 * 2, CustomStat, true);
873 end;
874 end;
876 procedure r_Render_DrawValueOf (a, b, x, y: Integer; f: TGLFont);
877 var wa, wb, ch: Integer; sa, sb: AnsiString;
878 begin
879 sa := IntToStr(a);
880 sb := IntToStr(b);
881 r_Draw_GetTextSize(sa, f, wa, ch);
882 r_Draw_GetTextSize(sa + ' / ', f, wb, ch);
883 r_Render_DrawText(sa, x, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
884 r_Render_DrawText(' / ', x + wa, y, 255, 255, 255, 255, f, TBasePoint.BP_LEFTUP);
885 r_Render_DrawText(sb, x + wb, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
886 end;
888 procedure r_Render_DrawSinglStatsPlayer (player, x, y, w1: Integer);
889 var time, kpm: Single;
890 begin
891 r_Render_DrawText(_lc[I_MENU_INTER_KILLS], x, y, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
892 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Kills, gTotalMonsters, x + w1, y, MenuFont);
893 r_Render_DrawText(_lc[I_MENU_INTER_KPM], x, y + 32, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
894 time := SingleStat.GameTime / 1000;
895 kpm := SingleStat.PlayerStat[player].Kills;
896 if time > 0 then kpm := kpm / time * 60;
897 r_Render_DrawText(Format('%.1f', [kpm]), x + w1, y + 32, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
898 r_Render_DrawText(_lc[I_MENU_INTER_SECRETS], x, y + 64, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
899 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Secrets, SingleStat.TotalSecrets, x + w1, y + 64, MenuFont);
900 end;
902 procedure r_Render_DrawSingleStats;
903 var xx, wa, wb, ww, ch: Integer; s: AnsiString;
904 begin
905 r_Render_DrawText(_lc[I_MENU_INTER_LEVEL_COMPLETE], gScreenWidth div 2, 32, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
907 r_Draw_GetTextSize(_lc[I_MENU_INTER_KPM] + ' ', menufont, wa, ch);
908 r_Draw_GetTextSize(' 9999.9', menufont, wb, ch);
909 ww := wa + wb;
910 xx := gScreenWidth div 2 - ww div 2;
912 s := r_Render_TimeToStr(SingleStat.GameTime);
913 r_Render_DrawText(_lc[I_MENU_INTER_TIME], xx, 80, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
914 r_Render_DrawText(s, xx + wa, 80, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
916 if SingleStat.TwoPlayers then
917 begin
918 r_Render_DrawText(_lc[I_MENU_PLAYER_1], gScreenWidth div 2, 128, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
919 r_Render_DrawSinglStatsPlayer(0, xx, 176, wa);
920 r_Render_DrawText(_lc[I_MENU_PLAYER_2], gScreenWidth div 2, 288, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
921 r_Render_DrawSinglStatsPlayer(1, xx, 336, wa);
922 end
923 else
924 begin
925 r_Render_DrawSinglStatsPlayer(0, xx, 128, wa);
926 end;
927 end;
929 procedure r_Render_Draw;
930 begin
931 if gExit = EXIT_QUIT then
932 exit;
934 r_Draw_Setup(gScreenWidth, gScreenHeight);
936 glClearColor(0.0, 0.0, 0.0, 0.0);
937 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
939 glColor4ub(255, 255, 255, 255);
940 glEnable(GL_SCISSOR_TEST);
941 r_Draw_SetRect(0, 0, gScreenWidth, gScreenHeight);
943 //e_LogWritefln('r_render_draw: %sx%s', [gScreenWidth, gScreenHeight]);
945 if gGameOn or ((gState in [STATE_FOLD]) and (EndingGameCounter < 255)) then
946 begin
947 // TODO setup sectator mode
948 // TODO setup player hear point
950 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
951 begin
952 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight div 2 - 2, gPlayer1);
953 r_Render_DrawPlayerView(0, gScreenHeight div 2 + 2, gScreenWidth, gScreenHeight div 2, gPlayer2);
954 end
955 else
956 begin
957 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, gPlayer1);
958 end;
960 // TODO draw holmes inspector
962 // TODO draw messages
963 if IsDrawStat or (gSpectMode = SPECT_STATS) then
964 r_Render_DrawStats;
965 // TODO draw spectator hud
966 end;
968 if gPauseMain and gGameOn {$IFDEF ENABLE_MENU}and (g_ActiveWindow = nil){$ENDIF} then
969 begin
970 // TODO draw pause screen
971 end;
973 if not gGameOn then
974 begin
975 case gState of
976 STATE_NONE: (* do nothing *) ;
977 STATE_MENU: r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
978 STATE_FOLD:
979 begin
980 if EndingGameCounter > 0 then
981 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
982 end;
983 STATE_INTERCUSTOM:
984 begin
985 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
986 if EndPicPath <> '' then
987 r_Render_DrawBackground(EndPicPath)
988 else
989 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC])
990 else
991 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
993 r_Render_DrawCustomStats;
995 {$IFDEF ENABLE_MENU}
996 if g_ActiveWindow <> nil then
997 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
998 {$ENDIF}
999 end;
1000 STATE_INTERSINGLE, STATE_INTERTEXT, STATE_INTERPIC:
1001 begin
1002 if EndingGameCounter > 0 then
1003 begin
1004 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1005 end
1006 else
1007 begin
1008 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
1009 r_Render_DrawSingleStats;
1010 {$IFDEF ENABLE_MENU}
1011 if g_ActiveWindow <> nil then
1012 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1013 {$ENDIF}
1014 end;
1015 end;
1016 STATE_ENDPIC:
1017 begin
1018 if EndPicPath <> '' then
1019 r_Render_DrawBackground(EndPicPath)
1020 else
1021 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC]);
1022 {$IFDEF ENABLE_MENU}
1023 if g_ActiveWindow <> nil then
1024 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1025 {$ENDIF}
1026 end;
1027 STATE_SLIST:
1028 begin
1029 r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
1030 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1031 r_Render_DrawServerList(slCurrent, slTable);
1032 end;
1033 end;
1034 end;
1036 {$IFDEF ENABLE_MENU}
1037 if g_ActiveWindow <> nil then
1038 begin
1039 if gGameOn then
1040 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1041 r_GUI_Draw_Window(g_ActiveWindow);
1042 end;
1043 {$ENDIF}
1045 r_Console_Draw(false);
1047 // TODO draw holmes interface
1049 glFlush();
1050 glFinish();
1051 sys_Repaint;
1052 end;
1054 procedure r_Render_Resize (w, h: Integer);
1055 begin
1056 gWinSizeX := w;
1057 gWinSizeY := h;
1058 gRC_Width := w;
1059 gRC_Height := h;
1060 gScreenWidth := w;
1061 gScreenHeight := h;
1062 end;
1064 procedure r_Render_Apply;
1065 begin
1066 {$IFDEF ENABLE_SYSTEM}
1067 if sys_SetDisplayModeGL(GetInfo()) then
1068 e_LogWriteln('resolution changed')
1069 else
1070 e_LogWriteln('resolution not changed');
1071 sys_EnableVSync(gVSync)
1072 {$ENDIF}
1073 end;
1075 function r_Render_WriteScreenShot (filename: String): Boolean;
1076 begin
1077 Result := False;
1078 end;
1080 {$IFDEF ENABLE_GIBS}
1081 function r_Render_GetGibRect (m, id: Integer): TRectWH;
1082 begin
1083 result := r_Map_GetGibSize(m, id);
1084 end;
1085 {$ENDIF}
1087 {$IFDEF ENABLE_GFX}
1088 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
1089 begin
1090 r_Map_NewGFX(AnimType, X, Y);
1091 end;
1092 {$ENDIF}
1094 {$IFDEF ENABLE_TOUCH}
1095 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
1096 begin
1097 founded := False;
1098 end;
1099 {$ENDIF}
1101 {$IFDEF ENABLE_MENU}
1102 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
1103 begin
1104 r_GUI_GetSize(ctrl, w, h);
1105 end;
1107 procedure r_Render_GetLogoSize (out w, h: Integer);
1108 begin
1109 r_GUI_GetLogoSize(w, h);
1110 end;
1112 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
1113 begin
1114 r_GUI_GetMaxFontSize(BigFont, w, h);
1115 end;
1117 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
1118 begin
1119 r_GUI_GetStringSize(BigFont, str, w, h);
1120 end;
1121 {$ENDIF}
1123 procedure r_Render_DrawLoading (force: Boolean);
1124 begin
1125 // TODO draw loading screen
1126 end;
1128 end.