DEADSOFTWARE

gl: draw pause screen
[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 var
92 BackgroundTexture: THereTexture;
94 hud, hudbg: TGLTexture;
95 hudhp: array [Boolean] of TGLTexture;
96 hudap: TGLTexture;
97 hudwp: array [0..WP_LAST] of TGLTexture;
98 hudkey: array [0..2] of TGLTexture;
99 hudair: TGLTexture;
100 hudjet: TGLTexture;
101 hudrflag, hudrflags, hudrflagd: TGLTexture;
102 hudbflag, hudbflags, hudbflagd: TGLTexture;
104 procedure r_Render_LoadTextures;
105 begin
106 r_Map_LoadTextures;
107 end;
109 procedure r_Render_FreeTextures;
110 begin
111 r_Map_FreeTextures;
112 end;
114 procedure r_Render_Load;
115 const
116 WeapName: array [0..WP_LAST] of AnsiString = ('KASTET', 'SAW', 'PISTOL', 'SHOTGUN1', 'SHOTGUN2', 'MGUN', 'RLAUNCHER', 'PGUN', 'BFG', 'SPULEMET', 'FLAMETHROWER');
117 var
118 i: Integer;
119 begin
120 r_Common_Load;
121 BackgroundTexture := DEFAULT(THereTexture);
122 hud := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUD');
123 hudbg := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUDBG');
124 hudhp[false] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/MED2');
125 hudhp[true] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/BMED');
126 hudap := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/ARMORHUD');
127 for i := 0 to WP_LAST do
128 hudwp[i] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/' + WeapName[i]);
129 hudkey[0] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYR');
130 hudkey[1] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYG');
131 hudkey[2] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYB');
132 hudair := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/AIRBAR');
133 hudjet := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/JETBAR');
134 hudrflag := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_BASE');
135 hudrflags := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_STOLEN');
136 hudrflagd := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_DROP');
137 hudbflag := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_BASE');
138 hudbflags := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_STOLEN');
139 hudbflagd := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_DROP');
140 r_Console_Load;
141 r_Map_Load;
142 {$IFDEF ENABLE_MENU}
143 r_GUI_Load;
144 {$ENDIF}
145 end;
147 procedure r_Render_Free;
148 var i: Integer;
149 begin
150 {$IFDEF ENABLE_MENU}
151 r_GUI_Free;
152 {$ENDIF}
153 r_Map_Free;
154 r_Console_Free;
155 hudbflagd.Free;
156 hudbflags.Free;
157 hudbflag.Free;
158 hudrflagd.Free;
159 hudrflags.Free;
160 hudrflag.Free;
161 hudjet.Free;
162 hudair.Free;
163 hudkey[0].Free;
164 hudkey[1].Free;
165 hudkey[2].Free;
166 for i := 0 to WP_LAST do
167 begin
168 if hudwp[i] <> nil then
169 hudwp[i].Free;
170 hudwp[i] := nil;
171 end;
172 hudap.Free;
173 hudhp[true].Free;
174 hudhp[false].Free;
175 hudbg.Free;
176 hud.Free;
177 r_Common_FreeThis(BackgroundTexture);
178 r_Common_Free;
179 end;
181 {$IFDEF ENABLE_SYSTEM}
182 function GetInfo (): TGLDisplayInfo;
183 var info: TGLDisplayInfo;
184 begin
185 info := Default(TGLDisplayInfo);
186 info.w := Max(1, gRC_Width);
187 info.h := Max(1, gRC_Height);
188 info.bpp := Max(1, gBPP);
189 info.fullscreen := gRC_FullScreen;
190 info.maximized := gRC_Maximized;
191 info.major := 1;
192 info.minor := 1;
193 info.profile := TGLProfile.Compat;
194 result := info;
195 end;
196 {$ENDIF}
198 procedure r_Render_Initialize;
199 begin
200 {$IFDEF ENABLE_SYSTEM}
201 if sys_SetDisplayModeGL(GetInfo()) = False then
202 raise Exception.Create('Failed to set videomode on startup.');
203 sys_EnableVSync(gVSync);
204 {$ENDIF}
205 r_Textures_Initialize;
206 r_Console_Initialize;
207 r_Map_Initialize;
208 end;
210 procedure r_Render_Finalize;
211 begin
212 r_Map_Finalize;
213 r_Console_Finalize;
214 r_Textures_Finalize;
215 end;
217 procedure r_Render_Update;
218 begin
219 r_Console_Update;
220 r_Map_Update;
221 end;
223 procedure r_Render_DrawHUD (x, y: Integer; p: TPlayer);
224 var t: TGLTexture; s: AnsiString;
225 begin
226 ASSERT(p <> nil);
228 // hud area is 196 x 240 pixels
229 r_Common_DrawTexture(hud, x, y, hud.width, hud.height, TBasePoint.BP_LEFTUP);
230 r_Common_DrawText(p.name, x + 98, y + 16, 255, 0, 0, 255, smallfont, TBasePoint.BP_CENTER);
232 t := hudhp[R_BERSERK in p.FRulez];
233 r_Common_DrawTexture(t, x + 51, y + 61, t.width, t.height, TBasePoint.BP_CENTER);
234 r_Common_DrawTexture(hudap, x + 50, y + 85, hudap.width, hudap.height, TBasePoint.BP_CENTER);
236 r_Common_DrawText(IntToStr(MAX(0, p.health)), x + 174, y + 56, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
237 r_Common_DrawText(IntToStr(MAX(0, p.armor)), x + 174, y + 84, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
239 case p.CurrWeap of
240 WEAPON_KASTET, WEAPON_SAW: s := '--';
241 else s := IntToStr(p.GetAmmoByWeapon(p.CurrWeap));
242 end;
243 r_Common_DrawText(s, x + 174, y + 174, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
245 if p.CurrWeap <= WP_LAST then
246 begin
247 t := hudwp[p.CurrWeap];
248 r_Common_DrawTexture(t, x + 18, y + 160, t.width, t.height, TBasePoint.BP_LEFTUP);
249 end;
251 if R_KEY_RED in p.FRulez then
252 r_Common_DrawTexture(hudkey[0], x + 76, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
253 if R_KEY_GREEN in p.FRulez then
254 r_Common_DrawTexture(hudkey[1], x + 93, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
255 if R_KEY_BLUE in p.FRulez then
256 r_Common_DrawTexture(hudkey[2], x + 110, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
258 if p.JetFuel > 0 then
259 begin
260 r_Common_DrawTexture(hudair, x, y + 116, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
261 if p.air > 0 then
262 r_Draw_FillRect(x + 14, y + 116 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 116 + 4 + 4, 0, 0, 196, 255);
263 r_Common_DrawTexture(hudjet, x, y + 126, hudjet.width, hudjet.height, TBasePoint.BP_LEFTUP);
264 r_Draw_FillRect(x + 14, y + 126 + 4, x + 14 + 168 * p.JetFuel div JET_MAX, y + 126 + 4 + 4, 208, 0, 0, 255);
265 end
266 else
267 begin
268 r_Common_DrawTexture(hudair, x, y + 124, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
269 if p.air > 0 then
270 r_Draw_FillRect(x + 14, y + 124 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 124 + 4 + 4, 0, 0, 196, 255);
271 end;
272 end;
274 procedure r_Render_DrawHUDArea (x, y, w, h: Integer; p: TPlayer);
275 var s: AnsiString;
276 begin
277 r_Common_DrawTexture(hudbg, x, y, w, h, TBasePoint.BP_LEFTUP);
279 if p <> nil then
280 begin
281 r_Render_DrawHUD(x + w - 196 + 2, y, p);
282 if p.Spectator then
283 begin
284 r_Common_DrawText(_lc[I_PLAYER_SPECT], x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
285 r_Common_DrawText(_lc[I_PLAYER_SPECT2], x + 4, y + 258, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
286 r_Common_DrawText(_lc[I_PLAYER_SPECT1], x + 4, y + 274, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
287 if p.NoRespawn then
288 r_Common_DrawText(_lc[I_PLAYER_SPECT1S], x + 4, y + 290, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
289 end;
290 end;
292 if gShowPing and g_Game_IsClient then
293 begin
294 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
295 r_Common_DrawText(s, x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
296 end;
297 end;
299 procedure r_Render_DrawStatsView (x, y, w, h: Integer; p: TPlayer);
300 var fw, i, maxFrags, top, totalPlayers: Integer; sign: Char; stat: TPlayerStatArray; f: TGLTexture;
301 begin
302 ASSERT(p <> nil);
304 if gShowScore and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
305 begin
306 (* RED TEAM GOALS *)
307 fw := 0;
308 if gGameSettings.GameMode = GM_CTF then
309 begin
310 case gFlags[FLAG_RED].State of
311 FLAG_STATE_CAPTURED: f := hudrflags;
312 FLAG_STATE_DROPPED: f := hudrflagd;
313 otherwise f := hudrflag;
314 end;
315 if f <> nil then
316 begin
317 fw := f.width + 8; (* + space *)
318 r_Common_DrawTexture(f, x + w - 16, y + 240 - 72 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
319 end;
320 end;
321 r_Common_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);
323 (* BLUE TEAM GOALS *)
324 fw := 0;
325 if gGameSettings.GameMode = GM_CTF then
326 begin
327 case gFlags[FLAG_BLUE].State of
328 FLAG_STATE_CAPTURED: f := hudbflags;
329 FLAG_STATE_DROPPED: f := hudbflagd;
330 otherwise f := hudbflag;
331 end;
332 if f <> nil then
333 begin
334 fw := f.width + 8; (* + space *)
335 r_Common_DrawTexture(f, x + w - 16, y + 240 - 32 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
336 end;
337 end;
338 r_Common_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);
339 end;
341 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
342 begin
343 if gShowStat then
344 begin
345 r_Common_DrawText(IntToStr(p.Frags), x + w - 16, y, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHTUP);
347 top := 1;
348 maxFrags := 0;
349 totalPlayers := 0;
350 stat := g_Player_GetStats();
351 if stat <> nil then
352 begin
353 totalPlayers := Length(stat);
354 for i := 0 to High(stat) do
355 begin
356 if stat[i].Name <> p.Name then
357 begin
358 maxFrags := MAX(maxFrags, stat[i].Frags);
359 if stat[i].Frags > p.Frags then
360 top := top + 1;
361 end;
362 end;
363 end;
364 if p.Frags >= maxFrags then sign := '+' else sign := '-';
365 r_Common_DrawText(IntToStr(top) + ' / ' + IntToStr(totalPlayers) + ' ' + sign + IntToStr(ABS(p.Frags - maxFrags)), x + w - 16, y + 32, 255, 0, 0, 255, smallfont, TBasePoint.BP_RIGHTUP);
366 end;
368 if gLMSRespawn > LMS_RESPAWN_NONE then
369 begin
370 r_Common_DrawText(_lc[I_GAME_WARMUP], x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
371 r_Common_DrawText(': ' + IntToStr((gLMSRespawnTime - gTime) div 1000), x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_LEFTDOWN);
372 end
373 else if gShowLives and (gGameSettings.MaxLives > 0) then
374 begin
375 r_Common_DrawText(IntToStr(p.Lives), x + w - 16, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
376 end;
377 end;
378 end;
380 procedure r_Render_DrawView (x, y, w, h: Integer; p: TPlayer);
381 var l, t, r, b: Integer;
382 begin
383 r_Draw_GetRect(l, t, r, b);
384 r_Draw_SetRect(x, y, x + w, y + h);
386 if p <> nil then
387 begin
388 r_Map_Draw(x, y, w, h, p.obj.x + PLAYER_RECT_CX, p.obj.y + PLAYER_RECT_CY, p);
389 r_Render_DrawStatsView(x, y, w, h, p);
390 if p.Spectator and p.NoRespawn then
391 r_Common_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);
392 end
393 else
394 begin
395 r_Map_Draw(x, y, w, h, 0, 0, nil);
396 end;
398 r_Draw_SetRect(l, t, r, b);
399 end;
401 procedure r_Render_DrawMapView (x, y, w, h, camx, camy: Integer);
402 var l, t, r, b: Integer;
403 begin
404 r_Draw_GetRect(l, t, r, b);
405 r_Draw_SetRect(x, y, x + w, y + h);
406 r_Map_Draw(x, y, w, h, camx, camy, nil);
407 r_Draw_SetRect(l, t, r, b);
408 end;
410 procedure r_Render_DrawPlayerView (x, y, w, h: Integer; p: TPlayer);
411 var l, t, r, b: Integer;
412 begin
413 r_Draw_GetRect(l, t, r, b);
414 r_Draw_SetRect(x, y, x + w, y + h);
415 r_Render_DrawView(x, y, w - 196, h, p);
416 r_Render_DrawHUDArea(x + w - 196, y, 196, h, p);
417 r_Draw_SetRect(l, t, r, b);
418 end;
420 procedure r_Render_DrawBackgroundImage (img: TGLTexture);
421 var fw, w, h: LongInt;
422 begin
423 if img <> nil then
424 begin
425 img := BackgroundTexture.id;
426 if img.width = img.height then fw := img.width * 4 div 3 else fw := img.width; // fix aspect 4:3
427 r_Common_CalcAspect(fw, img.height, gScreenWidth, gScreenHeight, false, w, h);
428 r_Draw_Texture(img, gScreenWidth div 2 - w div 2, 0, w, h, false, 255, 255, 255, 255, false);
429 end
430 end;
432 procedure r_Render_DrawBackground (const name: AnsiString);
433 begin
434 if r_Common_LoadThis(name, BackgroundTexture) then
435 r_Render_DrawBackgroundImage(BackgroundTexture.id)
436 end;
438 procedure r_Render_DrawServerList (var SL: TNetServerList; var ST: TNetServerTable);
439 var ip: AnsiString; ww, hh, cw, ch, mw, mh, motdh, scrx, scry, i, mx, y: Integer; msg: SSArray; Srv: TNetServer;
440 begin
441 scrx := gScreenWidth div 2;
442 scry := gScreenHeight div 2;
444 r_Draw_GetTextSize(_lc[I_NET_SLIST], menufont, ww, hh);
445 r_Common_DrawText(_lc[I_NET_SLIST], gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
447 r_Draw_GetTextSize('W', stdfont, cw, ch);
448 motdh := gScreenHeight - 49 - ch * b_Text_LineCount(slMOTD);
450 r_Draw_FillRect(16, 64, gScreenWidth - 16, motdh, 64, 64, 64, 145);
451 r_Draw_Rect(16, 64, gScreenWidth - 16, motdh, 255, 127, 0, 255);
453 r_Common_DrawText(_lc[I_NET_SLIST_HELP], gScreenWidth div 2, gScreenHeight - 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
455 if slMOTD <> '' then
456 begin
457 r_Draw_FillRect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 64, 64, 64, 110);
458 r_Draw_Rect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 255, 127, 0, 255);
459 r_Common_DrawFormatText(slMOTD, 20, motdh + 3 + ch * i, 255, stdfont, TBasePoint.BP_LEFTUP);
460 end;
462 if not slReadUrgent and (slUrgent <> '') then
463 begin
464 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
465 r_Draw_FillRect(scrx - 256, scry - 60, scrx + 256, scry + 60, 64, 64, 64, 127);
466 r_Draw_Rect(scrx - 256, scry - 60, scrx + 256, scry + 60, 255, 127, 0, 255);
467 r_Draw_FillRect(scrx - 256, scry - 40, scrx + 256, scry - 40, 255, 127, 0, 255);
468 r_Common_DrawText(_lc[I_NET_SLIST_URGENT], scrx, scry - 58, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
469 r_Common_DrawFormatText(slUrgent, scrx - 253, scry - 38 + ch * i, 255, stdfont, TBasePoint.BP_LEFTUP);
470 r_Common_DrawText(_lc[I_NET_SLIST_URGENT_CONT], scrx, scry + 41, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
471 r_Draw_FillRect(scrx - 256, scry + 40, scrx + 256, scry + 40, 255, 127, 0, 255);
472 end
473 else if SL = nil then
474 begin
475 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
476 r_Draw_Rect(scrx - 192, scry - 10, scrx + 192, scry + 11, 255, 127, 0, 255);
477 r_Common_DrawText(slWaitStr, scrx, scry, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
478 end
479 else
480 begin
481 y := 90;
482 if slSelection < Length(ST) then
483 begin
484 sy := y + 42 * slSelection - 4;
485 Srv := GetServerFromTable(slSelection, SL, ST);
486 ip := _lc[I_NET_ADDRESS] + ' ' + Srv.IP + ':' + IntToStr(Srv.Port);
487 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ';
488 if Srv.Password then ip := ip + _lc[I_MENU_YES] else ip := ip +_lc[I_MENU_NO];
489 end;
491 mw := gScreenWidth - 188;
492 mx := 16 + mw;
494 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy + 40, 64, 64, 64, 255);
495 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy, 205, 205, 205, 255);
496 r_Draw_FillRect(16 + 1, sy + 41, gScreenWidth - 16 - 1, sy + 41, 255, 255, 255, 255);
498 r_Draw_FillRect(16, 85, gScreenWidth - 16, 85, 255, 127, 0, 255);
499 r_Draw_FillRect(16, motdh - 20, gScreenWidth - 16, motdh - 20, 255, 127, 0, 255);
501 r_Draw_FillRect(mx - 70, 64, mx - 70, motdh, 255, 127, 0, 255);
502 r_Draw_FillRect(mx, 64, mx, motdh - 20, 255, 127, 0, 255);
503 r_Draw_FillRect(mx + 52, 64, mx + 52, motdh - 20, 255, 127, 0, 255);
504 r_Draw_FillRect(mx + 104, 64, mx + 104, motdh - 20, 255, 127, 0, 255);
506 r_Common_DrawText('NAME/MAP', 18, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
507 r_Common_DrawText('PING', mx - 68, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
508 r_Common_DrawText('MODE', mx + 2, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
509 r_Common_DrawText('PLRS', mx + 54, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
510 r_Common_DrawText('VER', mx + 106, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
512 for i := 0 to High(ST) do
513 begin
514 Srv := GetServerFromTable(i, SL, ST);
515 r_Common_DrawText(Srv.Name, 18, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
516 r_Common_DrawText(Srv.Map, 18, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
518 if Srv.Ping = 0 then
519 r_Common_DrawText('<1' + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
520 else if (Srv.Ping >= 0) and (Srv.Ping <= 999) then
521 r_Common_DrawText(IntToStr(Srv.Ping) + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
522 else
523 r_Common_DrawText(_lc[I_NET_SLIST_NO_ACCESS], mx - 68, y, 255, 0, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
524 if Length(ST[I].Indices) > 1 then
525 r_Common_DrawText('<' + IntToStr(Length(ST[I].Indices)) + '>', mx - 68, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
527 r_Common_DrawText(g_Game_ModeToText(Srv.GameMode), mx + 2, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
529 r_Common_DrawText(IntToStr(Srv.Players) + '/' + IntToStr(Srv.MaxPlayers), mx + 54, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
530 r_Common_DrawText(IntToStr(Srv.LocalPl) + '+' + IntToStr(Srv.Bots), mx + 54, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
532 r_Common_DrawText(IntToStr(Srv.Protocol), mx + 106, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
534 y := y + 42;
535 end;
537 r_Common_DrawText(ip, 20, motdh - 20 + 3, 205, 205, 205, 255, stdfont, TBasePoint.BP_LEFTUP);
538 r_Common_DrawText(IntToStr(Length(ST)) + _lc[I_NET_SLIST_SERVERS], gScreenWidth - 48, motdh - 20 + 3, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
539 end;
540 end;
542 procedure r_Render_DrawStatsColumns (constref cs: TEndCustomGameStat; x, y, w: Integer; endview: Boolean);
543 var i, cw, ch, yy, team, players, w1, w2, w3, w4, tw: Integer; r, g, b, rr, gg, bb: Byte; s: AnsiString;
544 begin
545 r_Draw_GetTextSize('W', stdfont, cw, ch);
546 w4 := cw * 6; (* deaths width *)
547 w3 := cw * 8; (* frags width *)
548 w2 := cw * 12; (* ping/loss width *)
549 w1 := w - w2 - w3 - w4; (* name width *)
550 tw := w1 - cw * 2 - w2; (* team goals *)
551 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
552 yy := y;
553 if cs.GameMode in [GM_TDM, GM_CTF] then
554 begin
555 for team := TEAM_RED to TEAM_BLUE do
556 begin
557 case team of
558 TEAM_RED:
559 begin
560 s := _lc[I_GAME_TEAM_RED];
561 r := 255; g := 0; b := 0;
562 end;
563 TEAM_BLUE:
564 begin
565 s := _lc[I_GAME_TEAM_BLUE];
566 r := 0; g := 0; b := 255;
567 end;
568 end;
569 r_Common_DrawText(s, x, yy, r, g, b, 255, stdfont, TBasePoint.BP_LEFTUP);
570 r_Common_DrawText(IntToStr(cs.TeamStat[team].Score), x + tw, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
571 if endview = false then
572 r_Common_DrawText(_lc[I_GAME_PING], x + w1, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
573 r_Common_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
574 r_Common_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
575 INC(yy, ch);
577 INC(yy, ch div 4);
578 r_Draw_FillRect(x, yy, x + w - 1, yy, r, g, b, 255);
579 INC(yy, ch div 4);
581 for i := 0 to players - 1 do
582 begin
583 if cs.PlayerStat[i].Team = team then
584 begin
585 rr := r; gg := g; bb := b;
586 if cs.PlayerStat[i].Spectator then
587 begin
588 rr := r div 2; gg := g div 2; bb := b div 2;
589 end;
591 // Player name
592 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
593 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
594 r_Common_DrawText(s, x, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
595 if endview = false then
596 begin
597 // Player ping/loss
598 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
599 r_Common_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
600 end;
601 // Player frags
602 s := IntToStr(cs.PlayerStat[i].Frags);
603 r_Common_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
604 // Player deaths
605 s := IntToStr(cs.PlayerStat[i].Deaths);
606 r_Common_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
608 INC(yy, ch);
609 end;
610 end;
611 INC(yy, ch);
612 end;
613 end
614 else if cs.GameMode in [GM_DM, GM_COOP] then
615 begin
616 r_Common_DrawText(_lc[I_GAME_PLAYER_NAME], x, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
617 if endview = false then
618 r_Common_DrawText(_lc[I_GAME_PING], x + w1, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
619 r_Common_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
620 r_Common_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
621 INC(yy, ch + ch div 2);
622 for i := 0 to players - 1 do
623 begin
624 // rr := 255; gg := 127; bb := 0;
625 rr := 255; gg := 255; bb := 255;
626 if cs.PlayerStat[i].Spectator then
627 begin
628 rr := rr div 2; gg := gg div 2; bb := bb div 2;
629 end;
631 // Player color
632 r_Draw_Rect(x, yy, x + 16 - 1, yy + 16 - 1, 192, 192, 192, 255);
633 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);
634 // Player name
635 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
636 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
637 r_Common_DrawText(s, x + 16 + 8, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
638 if endview = false then
639 begin
640 // Player ping/loss
641 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
642 r_Common_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
643 end;
644 // Player frags
645 s := IntToStr(cs.PlayerStat[i].Frags);
646 r_Common_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
647 // Player deaths
648 s := IntToStr(cs.PlayerStat[i].Deaths);
649 r_Common_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
651 INC(yy, ch + ch div 2);
652 end;
653 end;
654 end;
656 procedure r_Render_DrawStatsWindow (x, y, w, h: Integer; cs: TEndCustomGameStat; endview: Boolean);
657 var xoff, yoff, cw, ch: Integer; s: AnsiString;
658 begin
659 xoff := 0; yoff := 8;
660 r_Draw_GetTextSize('W', stdfont, cw, ch);
661 r_Draw_FillRect(x, y, x + w - 1, y + h - 1, 64, 64, 64, 224);
662 r_Draw_Rect(x, y, x + w - 1, y + h - 1, 255, 127, 0, 255);
664 (* LINE 1 *)
666 if endview = false then
667 begin
668 case NetMode of
669 NET_SERVER: s := _lc[I_NET_SERVER];
670 NET_CLIENT: s := NetClientIP + ':' + IntToStr(NetClientPort);
671 otherwise s := '';
672 end;
673 r_Common_DrawText(s, x + 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
674 end;
676 case cs.GameMode of
677 GM_DM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_DM] else s := _lc[I_GAME_LMS];
678 GM_TDM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_TDM] else s := _lc[I_GAME_TLMS];
679 GM_CTF: s := _lc[I_GAME_CTF];
680 GM_COOP: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_COOP] else s := _lc[I_GAME_SURV];
681 otherwise s := 'GAME MODE ' + IntToStr(gGameSettings.GameMode);
682 end;
683 r_Common_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
685 if endview = false then
686 begin
687 s := r_Common_TimeToStr(cs.GameTime);
688 r_Common_DrawText(s, x + w - 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
689 end;
691 INC(yoff, ch + ch div 2);
693 (* LINE 2/3 *)
695 s := cs.Map;
696 if cs.MapName <> '' then
697 s := s + ' - ' + cs.MapName;
699 if endview = false then
700 begin
701 r_Common_DrawText(s, x + w div 2, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_UP);
702 INC(yoff, ch + ch div 2);
703 case cs.GameMode of
704 GM_DM, GM_TDM: s := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
705 GM_CTF: s := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]);
706 GM_COOP: s := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
707 otherwise s := '';
708 end;
709 r_Common_DrawText(s, x + 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_LEFTUP);
710 case cs.GameMode of
711 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]);
712 GM_COOP: s := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
713 otherwise s := '';
714 end;
715 r_Common_DrawText(s, x + w - 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_RIGHTUP);
716 INC(yoff, ch);
717 end
718 else
719 begin
720 xoff := MAX(Length(_lc[I_MENU_MAP]) + 1, Length(_lc[I_GAME_GAME_TIME]) + 1) * cw;
721 r_Common_DrawText(_lc[I_MENU_MAP], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
722 r_Common_DrawText(s, x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
723 INC(yoff, ch);
724 r_Common_DrawText(_lc[I_GAME_GAME_TIME], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
725 r_Common_DrawText(r_Common_TimeToStr(cs.GameTime), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
726 INC(yoff, ch);
727 end;
729 INC(yoff, ch);
731 (* LINE 4/5 *)
733 if endview and (cs.GameMode = GM_COOP) then
734 begin
735 xoff := MAX(Length(_lc[I_GAME_MONSTERS]) + 1, Length(_lc[I_GAME_SECRETS]) + 1) * cw;
736 r_Common_DrawText(_lc[I_GAME_MONSTERS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
737 r_Common_DrawText(IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
738 INC(yoff, ch);
739 r_Common_DrawText(_lc[I_GAME_SECRETS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
740 r_Common_DrawText(IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
741 INC(yoff, ch);
742 INC(yoff, ch);
743 end;
745 (* LINE 6/7 *)
747 if endview and (cs.GameMode = GM_COOP) and gLastMap then
748 begin
749 xoff := MAX(Length(_lc[I_GAME_MONSTERS_TOTAL]) + 1, Length(_lc[I_GAME_SECRETS_TOTAL]) + 1) * cw;
750 r_Common_DrawText(_lc[I_GAME_MONSTERS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
751 r_Common_DrawText(IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
752 INC(yoff, ch);
753 r_Common_DrawText(_lc[I_GAME_SECRETS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
754 r_Common_DrawText(IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
755 INC(yoff, ch);
756 INC(yoff, ch);
757 end;
759 (* LINE *)
761 if endview and (cs.GameMode in [GM_TDM, GM_CTF]) then
762 begin
763 if cs.TeamStat[TEAM_RED].Score > cs.TeamStat[TEAM_BLUE].Score then s := _lc[I_GAME_WIN_RED]
764 else if cs.TeamStat[TEAM_BLUE].Score > cs.TeamStat[TEAM_RED].Score then s := _lc[I_GAME_WIN_BLUE]
765 else s := _lc[I_GAME_WIN_DRAW];
766 r_Common_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
767 INC(yoff, ch);
768 INC(yoff, ch);
769 end;
771 (* LINE n *)
773 r_Render_DrawStatsColumns(cs, x + 16, y + yoff, w - 16 - 16, endview);
774 end;
776 function r_Render_StatsHeight (players: Integer): Integer;
777 var cw, ch: Integer;
778 begin
779 ASSERT(players >= 0);
780 r_Draw_GetTextSize('W', stdfont, cw, ch);
781 case gGameSettings.GameMode of
782 GM_TDM, GM_CTF: result := 32 + ch * (11 + players);
783 otherwise result := 40 + ch * 5 + (ch + 8) * players;
784 end;
785 end;
787 procedure r_Render_DrawStats;
788 var x, y, w, h, players: Integer; cs: TEndCustomGameStat;
789 begin
790 cs.PlayerStat := g_Player_GetStats();
791 SortGameStat(cs.PlayerStat);
792 cs.TeamStat := gTeamStat;
793 cs.GameTime := gTime;
794 cs.GameMode := gGameSettings.GameMode;
795 cs.Map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':' + g_ExtractFileName(gMapInfo.Map);
796 cs.MapName := gMapInfo.Name;
797 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
798 w := gScreenWidth - (gScreenWidth div 5);
799 h := r_Render_StatsHeight(players);
800 x := (gScreenWidth div 2) - (w div 2);
801 y := (gScreenHeight div 2) - (h div 2);
802 r_Render_DrawStatsWindow(x, y, w, h, cs, false);
803 end;
805 procedure r_Render_DrawCustomStats;
806 var cw, ch, s: AnsiString;
807 begin
808 if gStatsOff then
809 begin
810 r_Common_DrawText(_lc[I_MENU_INTER_NOTICE_TAB], gScreenWidth div 2, 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
811 end
812 else
813 begin
814 case gGameSettings.GameMode of
815 GM_COOP: if gMissionFailed then s := _lc[I_MENU_INTER_MISSION_FAIL] else s := _lc[I_MENU_INTER_LEVEL_COMPLETE];
816 otherwise s := _lc[I_MENU_INTER_ROUND_OVER];
817 end;
818 r_Common_DrawText(s, gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
820 if gChatShow = false then
821 begin
822 if g_Game_IsClient then s := _lc[I_MENU_INTER_NOTICE_MAP] else s := _lc[I_MENU_INTER_NOTICE_SPACE];
823 r_Common_DrawText(s, gScreenWidth div 2, gScreenHeight - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
824 if g_Game_IsNet then
825 begin
826 s := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
827 r_Common_DrawText(s, gScreenWidth div 2, gScreenHeight - 16 - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
828 end;
829 end;
831 r_Render_DrawStatsWindow(32, 64, gScreenWidth - 32 * 2, gScreenHeight - 64 * 2, CustomStat, true);
832 end;
833 end;
835 procedure r_Render_DrawValueOf (a, b, x, y: Integer; f: TGLFont);
836 var wa, wb, ch: Integer; sa, sb: AnsiString;
837 begin
838 sa := IntToStr(a);
839 sb := IntToStr(b);
840 r_Draw_GetTextSize(sa, f, wa, ch);
841 r_Draw_GetTextSize(sa + ' / ', f, wb, ch);
842 r_Common_DrawText(sa, x, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
843 r_Common_DrawText(' / ', x + wa, y, 255, 255, 255, 255, f, TBasePoint.BP_LEFTUP);
844 r_Common_DrawText(sb, x + wb, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
845 end;
847 procedure r_Render_DrawSinglStatsPlayer (player, x, y, w1: Integer);
848 var time, kpm: Single;
849 begin
850 r_Common_DrawText(_lc[I_MENU_INTER_KILLS], x, y, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
851 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Kills, gTotalMonsters, x + w1, y, MenuFont);
852 r_Common_DrawText(_lc[I_MENU_INTER_KPM], x, y + 32, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
853 time := SingleStat.GameTime / 1000;
854 kpm := SingleStat.PlayerStat[player].Kills;
855 if time > 0 then kpm := kpm / time * 60;
856 r_Common_DrawText(Format('%.1f', [kpm]), x + w1, y + 32, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
857 r_Common_DrawText(_lc[I_MENU_INTER_SECRETS], x, y + 64, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
858 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Secrets, SingleStat.TotalSecrets, x + w1, y + 64, MenuFont);
859 end;
861 procedure r_Render_DrawSingleStats;
862 var xx, wa, wb, ww, ch: Integer; s: AnsiString;
863 begin
864 r_Common_DrawText(_lc[I_MENU_INTER_LEVEL_COMPLETE], gScreenWidth div 2, 32, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
866 r_Draw_GetTextSize(_lc[I_MENU_INTER_KPM] + ' ', menufont, wa, ch);
867 r_Draw_GetTextSize(' 9999.9', menufont, wb, ch);
868 ww := wa + wb;
869 xx := gScreenWidth div 2 - ww div 2;
871 s := r_Common_TimeToStr(SingleStat.GameTime);
872 r_Common_DrawText(_lc[I_MENU_INTER_TIME], xx, 80, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
873 r_Common_DrawText(s, xx + wa, 80, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
875 if SingleStat.TwoPlayers then
876 begin
877 r_Common_DrawText(_lc[I_MENU_PLAYER_1], gScreenWidth div 2, 128, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
878 r_Render_DrawSinglStatsPlayer(0, xx, 176, wa);
879 r_Common_DrawText(_lc[I_MENU_PLAYER_2], gScreenWidth div 2, 288, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
880 r_Render_DrawSinglStatsPlayer(1, xx, 336, wa);
881 end
882 else
883 begin
884 r_Render_DrawSinglStatsPlayer(0, xx, 128, wa);
885 end;
886 end;
888 procedure r_Render_DrawSpectHud;
889 var xoff: Integer; s: AnsiString;
891 procedure AddText (s1, s2: AnsiString);
892 var w1, w2, ww, ch: Integer;
893 begin
894 r_Draw_GetTextSize(s1, stdfont, w1, ch);
895 r_Draw_GetTextSize(s2, stdfont, w2, ch);
896 ww := MAX(w1, w2);
897 r_Common_DrawText(s1, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
898 r_Common_DrawText(s2, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
899 xoff := xoff + ww + 16;
900 end;
902 begin
903 xoff := 0;
904 case gSpectMode of
905 SPECT_STATS: s := 'MODE: Stats';
906 SPECT_MAPVIEW: s := 'MODE: Observe Map';
907 SPECT_PLAYERS: s := 'MODE: Watch Players';
908 otherwise s := 'MODE: ' + IntToStr(gSpectMode);
909 end;
910 AddText(s, '< jump >');
911 if gSpectMode = SPECT_STATS then
912 AddText('Autoview', '< fire >');
913 if gSpectMode = SPECT_MAPVIEW then
914 AddText('[-] Step ' + IntToStr(gSpectStep) + ' [+]', '<prev weap> <next weap>');
915 if gSpectMode = SPECT_PLAYERS then
916 begin
917 AddText('Player 1', '<left/right>');
918 if gSpectViewTwo then
919 AddText('Player 2', '<prev w/next w>');
920 AddText('2x View', '<up/down>');
921 end;
922 end;
924 function GetActivePlayer_ByID (id: Integer): TPlayer;
925 var i, len: Integer; p: TPlayer;
926 begin
927 p := nil;
928 if (id >= 0) and (gPlayers <> nil) then
929 begin
930 i := 0; len := Length(gPlayers);
931 while (i < len) and ((IsActivePlayer(gPlayers[i]) = false) or (gPlayers[i].UID <> id)) do INC(i);
932 if i < len then p := gPlayers[i];
933 end;
934 result := p;
935 end;
937 procedure r_Render_Draw;
938 var p1, p2: TPlayer;
939 begin
940 if gExit = EXIT_QUIT then
941 exit;
943 r_Draw_Setup(gScreenWidth, gScreenHeight);
945 glClearColor(0.0, 0.0, 0.0, 0.0);
946 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
948 glColor4ub(255, 255, 255, 255);
949 glEnable(GL_SCISSOR_TEST);
950 r_Draw_SetRect(0, 0, gScreenWidth, gScreenHeight);
952 //e_LogWritefln('r_render_draw: %sx%s', [gScreenWidth, gScreenHeight]);
954 p1 := nil;
955 p2 := nil;
956 if gGameOn or (gState = STATE_FOLD) then
957 begin
958 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
959 begin
960 if gRevertPlayers then
961 begin
962 p1 := gPlayer2;
963 p2 := gPlayer1;
964 end
965 else
966 begin
967 p1 := gPlayer1;
968 p2 := gPlayer2;
969 end;
970 end
971 else if gPlayer1 <> nil then
972 begin
973 p1 := gPlayer1;
974 end
975 else if gPlayer2 <> nil then
976 begin
977 p1 := gPlayer2;
978 end;
979 if (gSpectMode = SPECT_PLAYERS) and (gPlayers <> nil) then
980 begin
981 p1 := GetActivePlayer_ByID(gSpectPID1);
982 if p1 = nil then
983 p1 := GetActivePlayer_ByID(GetActivePlayerID_Next());
984 if gSpectViewTwo then
985 begin
986 p2 := GetActivePlayer_ByID(gSpectPID2);
987 if p2 = nil then
988 p2 := GetActivePlayer_ByID(GetActivePlayerID_Next());
989 end;
990 end;
991 end;
993 if gGameOn or ((gState in [STATE_FOLD]) and (EndingGameCounter < 255)) then
994 begin
995 // TODO setup player hear point
997 if gSpectMode = SPECT_MAPVIEW then
998 begin
999 r_Render_DrawMapView(0, 0, gScreenWidth, gScreenHeight, gSpectX + gScreenWidth div 2, gSpectY + gScreenHeight div 2);
1000 end
1001 else if (p1 <> nil) and (p2 <> nil) then
1002 begin
1003 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight div 2 - 2, p1);
1004 r_Render_DrawPlayerView(0, gScreenHeight div 2 + 2, gScreenWidth, gScreenHeight div 2, p2);
1005 end
1006 else if p1 <> nil then
1007 begin
1008 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p1);
1009 end
1010 else if p2 <> nil then
1011 begin
1012 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p2);
1013 end;
1015 // TODO draw holmes inspector
1017 if MessageText <> '' then
1018 r_Common_DrawFormatText(MessageText, (gScreenWidth - 196) div 2, gScreenHeight div 2, 255, menufont, TBasePoint.BP_CENTER);
1020 if IsDrawStat or (gSpectMode = SPECT_STATS) then
1021 r_Render_DrawStats;
1023 if gSpectHUD and (gChatShow = false) and (gSpectMode <> SPECT_NONE) and (gSpectAuto = false) then
1024 r_Render_DrawSpectHud;
1025 end;
1027 if gPauseMain and gGameOn {$IFDEF ENABLE_MENU}and (g_ActiveWindow = nil){$ENDIF} then
1028 begin
1029 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1030 r_Common_DrawText(_lc[I_MENU_PAUSE], gScreenWidth div 2, gScreenHeight div 2, 255, 255, 255, 255, menufont, TBasePoint.BP_CENTER);
1031 end;
1033 if not gGameOn then
1034 begin
1035 case gState of
1036 STATE_NONE: (* do nothing *) ;
1037 STATE_MENU: r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
1038 STATE_FOLD:
1039 begin
1040 if EndingGameCounter > 0 then
1041 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1042 end;
1043 STATE_INTERCUSTOM:
1044 begin
1045 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1046 if EndPicPath <> '' then
1047 r_Render_DrawBackground(EndPicPath)
1048 else
1049 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC])
1050 else
1051 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
1053 r_Render_DrawCustomStats;
1055 {$IFDEF ENABLE_MENU}
1056 if g_ActiveWindow <> nil then
1057 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1058 {$ENDIF}
1059 end;
1060 STATE_INTERSINGLE, STATE_INTERTEXT, STATE_INTERPIC:
1061 begin
1062 if EndingGameCounter > 0 then
1063 begin
1064 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1065 end
1066 else
1067 begin
1068 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
1069 r_Render_DrawSingleStats;
1070 {$IFDEF ENABLE_MENU}
1071 if g_ActiveWindow <> nil then
1072 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1073 {$ENDIF}
1074 end;
1075 end;
1076 STATE_ENDPIC:
1077 begin
1078 if EndPicPath <> '' then
1079 r_Render_DrawBackground(EndPicPath)
1080 else
1081 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC]);
1082 {$IFDEF ENABLE_MENU}
1083 if g_ActiveWindow <> nil then
1084 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1085 {$ENDIF}
1086 end;
1087 STATE_SLIST:
1088 begin
1089 r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
1090 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1091 r_Render_DrawServerList(slCurrent, slTable);
1092 end;
1093 end;
1094 end;
1096 {$IFDEF ENABLE_MENU}
1097 if g_ActiveWindow <> nil then
1098 begin
1099 if gGameOn then
1100 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1101 r_GUI_Draw_Window(g_ActiveWindow);
1102 end;
1103 {$ENDIF}
1105 r_Console_Draw(false);
1107 // TODO draw holmes interface
1109 glFlush();
1110 glFinish();
1111 sys_Repaint;
1112 end;
1114 procedure r_Render_Resize (w, h: Integer);
1115 begin
1116 gWinSizeX := w;
1117 gWinSizeY := h;
1118 gRC_Width := w;
1119 gRC_Height := h;
1120 gScreenWidth := w;
1121 gScreenHeight := h;
1122 end;
1124 procedure r_Render_Apply;
1125 begin
1126 {$IFDEF ENABLE_SYSTEM}
1127 if sys_SetDisplayModeGL(GetInfo()) then
1128 e_LogWriteln('resolution changed')
1129 else
1130 e_LogWriteln('resolution not changed');
1131 sys_EnableVSync(gVSync)
1132 {$ENDIF}
1133 end;
1135 function r_Render_WriteScreenShot (filename: String): Boolean;
1136 begin
1137 Result := False;
1138 end;
1140 {$IFDEF ENABLE_GIBS}
1141 function r_Render_GetGibRect (m, id: Integer): TRectWH;
1142 begin
1143 result := r_Map_GetGibSize(m, id);
1144 end;
1145 {$ENDIF}
1147 {$IFDEF ENABLE_GFX}
1148 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
1149 begin
1150 r_Map_NewGFX(AnimType, X, Y);
1151 end;
1152 {$ENDIF}
1154 {$IFDEF ENABLE_TOUCH}
1155 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
1156 begin
1157 founded := False;
1158 end;
1159 {$ENDIF}
1161 {$IFDEF ENABLE_MENU}
1162 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
1163 begin
1164 r_GUI_GetSize(ctrl, w, h);
1165 end;
1167 procedure r_Render_GetLogoSize (out w, h: Integer);
1168 begin
1169 r_GUI_GetLogoSize(w, h);
1170 end;
1172 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
1173 begin
1174 r_GUI_GetMaxFontSize(BigFont, w, h);
1175 end;
1177 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
1178 begin
1179 r_GUI_GetStringSize(BigFont, str, w, h);
1180 end;
1181 {$ENDIF}
1183 procedure r_Render_DrawLoading (force: Boolean);
1184 begin
1185 // TODO draw loading screen
1186 end;
1188 end.