DEADSOFTWARE

gl: draw spectator interface
[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 begin
319 r_Render_DrawHUD(x + w - 196 + 2, y, p);
320 if p.Spectator then
321 begin
322 r_Render_DrawText(_lc[I_PLAYER_SPECT], x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
323 r_Render_DrawText(_lc[I_PLAYER_SPECT2], x + 4, y + 258, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
324 r_Render_DrawText(_lc[I_PLAYER_SPECT1], x + 4, y + 274, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
325 if p.NoRespawn then
326 r_Render_DrawText(_lc[I_PLAYER_SPECT1S], x + 4, y + 290, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
327 end;
328 end;
330 if gShowPing and g_Game_IsClient then
331 begin
332 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
333 r_Render_DrawText(s, x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
334 end;
335 end;
337 procedure r_Render_DrawStatsView (x, y, w, h: Integer; p: TPlayer);
338 var fw, i, maxFrags, top, totalPlayers: Integer; sign: Char; stat: TPlayerStatArray; f: TGLTexture;
339 begin
340 ASSERT(p <> nil);
342 if gShowScore and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
343 begin
344 (* RED TEAM GOALS *)
345 fw := 0;
346 if gGameSettings.GameMode = GM_CTF then
347 begin
348 case gFlags[FLAG_RED].State of
349 FLAG_STATE_CAPTURED: f := hudrflags;
350 FLAG_STATE_DROPPED: f := hudrflagd;
351 otherwise f := hudrflag;
352 end;
353 if f <> nil then
354 begin
355 fw := f.width + 8; (* + space *)
356 r_Render_DrawTexture(f, x + w - 16, y + 240 - 72 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
357 end;
358 end;
359 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);
361 (* BLUE TEAM GOALS *)
362 fw := 0;
363 if gGameSettings.GameMode = GM_CTF then
364 begin
365 case gFlags[FLAG_BLUE].State of
366 FLAG_STATE_CAPTURED: f := hudbflags;
367 FLAG_STATE_DROPPED: f := hudbflagd;
368 otherwise f := hudbflag;
369 end;
370 if f <> nil then
371 begin
372 fw := f.width + 8; (* + space *)
373 r_Render_DrawTexture(f, x + w - 16, y + 240 - 32 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
374 end;
375 end;
376 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);
377 end;
379 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
380 begin
381 if gShowStat then
382 begin
383 r_Render_DrawText(IntToStr(p.Frags), x + w - 16, y, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHTUP);
385 top := 1;
386 maxFrags := 0;
387 totalPlayers := 0;
388 stat := g_Player_GetStats();
389 if stat <> nil then
390 begin
391 totalPlayers := Length(stat);
392 for i := 0 to High(stat) do
393 begin
394 if stat[i].Name <> p.Name then
395 begin
396 maxFrags := MAX(maxFrags, stat[i].Frags);
397 if stat[i].Frags > p.Frags then
398 top := top + 1;
399 end;
400 end;
401 end;
402 if p.Frags >= maxFrags then sign := '+' else sign := '-';
403 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);
404 end;
406 if gLMSRespawn > LMS_RESPAWN_NONE then
407 begin
408 r_Render_DrawText(_lc[I_GAME_WARMUP], x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
409 r_Render_DrawText(': ' + IntToStr((gLMSRespawnTime - gTime) div 1000), x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_LEFTDOWN);
410 end
411 else if gShowLives and (gGameSettings.MaxLives > 0) then
412 begin
413 r_Render_DrawText(IntToStr(p.Lives), x + w - 16, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
414 end;
415 end;
416 end;
418 procedure r_Render_DrawView (x, y, w, h: Integer; p: TPlayer);
419 var l, t, r, b: Integer;
420 begin
421 r_Draw_GetRect(l, t, r, b);
422 r_Draw_SetRect(x, y, x + w, y + h);
424 if p <> nil then
425 begin
426 r_Map_Draw(x, y, w, h, p.obj.x + PLAYER_RECT_CX, p.obj.y + PLAYER_RECT_CY, p);
427 r_Render_DrawStatsView(x, y, w, h, p);
428 if p.Spectator and p.NoRespawn then
429 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);
430 end
431 else
432 begin
433 r_Map_Draw(x, y, w, h, 0, 0, nil);
434 end;
436 r_Draw_SetRect(l, t, r, b);
437 end;
439 procedure r_Render_DrawMapView (x, y, w, h, camx, camy: Integer);
440 var l, t, r, b: Integer;
441 begin
442 r_Draw_GetRect(l, t, r, b);
443 r_Draw_SetRect(x, y, x + w, y + h);
444 r_Map_Draw(x, y, w, h, camx, camy, nil);
445 r_Draw_SetRect(l, t, r, b);
446 end;
448 procedure r_Render_DrawPlayerView (x, y, w, h: Integer; p: TPlayer);
449 var l, t, r, b: Integer;
450 begin
451 r_Draw_GetRect(l, t, r, b);
452 r_Draw_SetRect(x, y, x + w, y + h);
453 r_Render_DrawView(x, y, w - 196, h, p);
454 r_Render_DrawHUDArea(x + w - 196, y, 196, h, p);
455 r_Draw_SetRect(l, t, r, b);
456 end;
458 procedure r_Render_DrawBackgroundImage (img: TGLTexture);
459 var fw, w, h: LongInt;
460 begin
461 if img <> nil then
462 begin
463 img := BackgroundTexture.id;
464 if img.width = img.height then fw := img.width * 4 div 3 else fw := img.width; // fix aspect 4:3
465 r_Common_CalcAspect(fw, img.height, gScreenWidth, gScreenHeight, false, w, h);
466 r_Draw_Texture(img, gScreenWidth div 2 - w div 2, 0, w, h, false, 255, 255, 255, 255, false);
467 end
468 end;
470 procedure r_Render_DrawBackground (const name: AnsiString);
471 begin
472 if r_Common_LoadThis(name, BackgroundTexture) then
473 r_Render_DrawBackgroundImage(BackgroundTexture.id)
474 end;
476 procedure r_Render_DrawServerList (var SL: TNetServerList; var ST: TNetServerTable);
477 var ip: AnsiString; ww, hh, cw, ch, mw, mh, motdh, scrx, scry, i, mx, y: Integer; msg: SSArray; Srv: TNetServer;
478 begin
479 scrx := gScreenWidth div 2;
480 scry := gScreenHeight div 2;
482 r_Draw_GetTextSize(_lc[I_NET_SLIST], menufont, ww, hh);
483 r_Render_DrawText(_lc[I_NET_SLIST], gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
485 r_Draw_GetTextSize('W', stdfont, cw, ch);
486 motdh := gScreenHeight - 49 - ch * b_Text_LineCount(slMOTD);
488 r_Draw_FillRect(16, 64, gScreenWidth - 16, motdh, 64, 64, 64, 145);
489 r_Draw_Rect(16, 64, gScreenWidth - 16, motdh, 255, 127, 0, 255);
491 r_Render_DrawText(_lc[I_NET_SLIST_HELP], gScreenWidth div 2, gScreenHeight - 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
493 if slMOTD <> '' then
494 begin
495 r_Draw_FillRect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 64, 64, 64, 110);
496 r_Draw_Rect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 255, 127, 0, 255);
497 msg := Parse2(slMOTD, #10);
498 for i := 0 to High(msg) do
499 r_Render_DrawText(msg[i], 20, motdh + 3 + ch * i, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
500 end;
502 if not slReadUrgent and (slUrgent <> '') then
503 begin
504 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
505 r_Draw_FillRect(scrx - 256, scry - 60, scrx + 256, scry + 60, 64, 64, 64, 127);
506 r_Draw_Rect(scrx - 256, scry - 60, scrx + 256, scry + 60, 255, 127, 0, 255);
507 r_Draw_FillRect(scrx - 256, scry - 40, scrx + 256, scry - 40, 255, 127, 0, 255);
508 r_Render_DrawText(_lc[I_NET_SLIST_URGENT], scrx, scry - 58, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
509 msg := Parse2(slUrgent, #10);
510 for i := 0 to High(msg) do
511 r_Render_DrawText(msg[i], scrx - 253, scry - 38 + ch * i, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
512 r_Render_DrawText(_lc[I_NET_SLIST_URGENT_CONT], scrx, scry + 41, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
513 r_Draw_FillRect(scrx - 256, scry + 40, scrx + 256, scry + 40, 255, 127, 0, 255);
514 end
515 else if SL = nil then
516 begin
517 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
518 r_Draw_Rect(scrx - 192, scry - 10, scrx + 192, scry + 11, 255, 127, 0, 255);
519 r_Render_DrawText(slWaitStr, scrx, scry, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
520 end
521 else
522 begin
523 y := 90;
524 if slSelection < Length(ST) then
525 begin
526 sy := y + 42 * slSelection - 4;
527 Srv := GetServerFromTable(slSelection, SL, ST);
528 ip := _lc[I_NET_ADDRESS] + ' ' + Srv.IP + ':' + IntToStr(Srv.Port);
529 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ';
530 if Srv.Password then ip := ip + _lc[I_MENU_YES] else ip := ip +_lc[I_MENU_NO];
531 end;
533 mw := gScreenWidth - 188;
534 mx := 16 + mw;
536 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy + 40, 64, 64, 64, 255);
537 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy, 205, 205, 205, 255);
538 r_Draw_FillRect(16 + 1, sy + 41, gScreenWidth - 16 - 1, sy + 41, 255, 255, 255, 255);
540 r_Draw_FillRect(16, 85, gScreenWidth - 16, 85, 255, 127, 0, 255);
541 r_Draw_FillRect(16, motdh - 20, gScreenWidth - 16, motdh - 20, 255, 127, 0, 255);
543 r_Draw_FillRect(mx - 70, 64, mx - 70, motdh, 255, 127, 0, 255);
544 r_Draw_FillRect(mx, 64, mx, motdh - 20, 255, 127, 0, 255);
545 r_Draw_FillRect(mx + 52, 64, mx + 52, motdh - 20, 255, 127, 0, 255);
546 r_Draw_FillRect(mx + 104, 64, mx + 104, motdh - 20, 255, 127, 0, 255);
548 r_Render_DrawText('NAME/MAP', 18, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
549 r_Render_DrawText('PING', mx - 68, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
550 r_Render_DrawText('MODE', mx + 2, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
551 r_Render_DrawText('PLRS', mx + 54, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
552 r_Render_DrawText('VER', mx + 106, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
554 for i := 0 to High(ST) do
555 begin
556 Srv := GetServerFromTable(i, SL, ST);
557 r_Render_DrawText(Srv.Name, 18, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
558 r_Render_DrawText(Srv.Map, 18, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
560 if Srv.Ping = 0 then
561 r_Render_DrawText('<1' + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
562 else if (Srv.Ping >= 0) and (Srv.Ping <= 999) then
563 r_Render_DrawText(IntToStr(Srv.Ping) + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
564 else
565 r_Render_DrawText(_lc[I_NET_SLIST_NO_ACCESS], mx - 68, y, 255, 0, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
566 if Length(ST[I].Indices) > 1 then
567 r_Render_DrawText('<' + IntToStr(Length(ST[I].Indices)) + '>', mx - 68, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
569 r_Render_DrawText(g_Game_ModeToText(Srv.GameMode), mx + 2, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
571 r_Render_DrawText(IntToStr(Srv.Players) + '/' + IntToStr(Srv.MaxPlayers), mx + 54, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
572 r_Render_DrawText(IntToStr(Srv.LocalPl) + '+' + IntToStr(Srv.Bots), mx + 54, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
574 r_Render_DrawText(IntToStr(Srv.Protocol), mx + 106, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
576 y := y + 42;
577 end;
579 r_Render_DrawText(ip, 20, motdh - 20 + 3, 205, 205, 205, 255, stdfont, TBasePoint.BP_LEFTUP);
580 r_Render_DrawText(IntToStr(Length(ST)) + _lc[I_NET_SLIST_SERVERS], gScreenWidth - 48, motdh - 20 + 3, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
581 end;
582 end;
584 function r_Render_TimeToStr (t: LongWord): AnsiString;
585 var h, m, s: Integer;
586 begin
587 h := t div 1000 div 3600;
588 m := t div 1000 div 60 mod 60;
589 s := t div 1000 mod 60;
590 result := Format('%d:%.2d:%.2d', [h, m, s]);
591 end;
593 procedure r_Render_DrawStatsColumns (constref cs: TEndCustomGameStat; x, y, w: Integer; endview: Boolean);
594 var i, cw, ch, yy, team, players, w1, w2, w3, w4, tw: Integer; r, g, b, rr, gg, bb: Byte; s: AnsiString;
595 begin
596 r_Draw_GetTextSize('W', stdfont, cw, ch);
597 w4 := cw * 6; (* deaths width *)
598 w3 := cw * 8; (* frags width *)
599 w2 := cw * 12; (* ping/loss width *)
600 w1 := w - w2 - w3 - w4; (* name width *)
601 tw := w1 - cw * 2 - w2; (* team goals *)
602 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
603 yy := y;
604 if cs.GameMode in [GM_TDM, GM_CTF] then
605 begin
606 for team := TEAM_RED to TEAM_BLUE do
607 begin
608 case team of
609 TEAM_RED:
610 begin
611 s := _lc[I_GAME_TEAM_RED];
612 r := 255; g := 0; b := 0;
613 end;
614 TEAM_BLUE:
615 begin
616 s := _lc[I_GAME_TEAM_BLUE];
617 r := 0; g := 0; b := 255;
618 end;
619 end;
620 r_Render_DrawText(s, x, yy, r, g, b, 255, stdfont, TBasePoint.BP_LEFTUP);
621 r_Render_DrawText(IntToStr(cs.TeamStat[team].Score), x + tw, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
622 if endview = false then
623 r_Render_DrawText(_lc[I_GAME_PING], x + w1, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
624 r_Render_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
625 r_Render_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, r, g, b, 255, stdfont, TBasePoint.BP_UP);
626 INC(yy, ch);
628 INC(yy, ch div 4);
629 r_Draw_FillRect(x, yy, x + w - 1, yy, r, g, b, 255);
630 INC(yy, ch div 4);
632 for i := 0 to players - 1 do
633 begin
634 if cs.PlayerStat[i].Team = team then
635 begin
636 rr := r; gg := g; bb := b;
637 if cs.PlayerStat[i].Spectator then
638 begin
639 rr := r div 2; gg := g div 2; bb := b div 2;
640 end;
642 // Player name
643 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
644 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
645 r_Render_DrawText(s, x, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
646 if endview = false then
647 begin
648 // Player ping/loss
649 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
650 r_Render_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
651 end;
652 // Player frags
653 s := IntToStr(cs.PlayerStat[i].Frags);
654 r_Render_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
655 // Player deaths
656 s := IntToStr(cs.PlayerStat[i].Deaths);
657 r_Render_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
659 INC(yy, ch);
660 end;
661 end;
662 INC(yy, ch);
663 end;
664 end
665 else if cs.GameMode in [GM_DM, GM_COOP] then
666 begin
667 r_Render_DrawText(_lc[I_GAME_PLAYER_NAME], x, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
668 if endview = false then
669 r_Render_DrawText(_lc[I_GAME_PING], x + w1, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
670 r_Render_DrawText(_lc[I_GAME_FRAGS], x + w1 + w2, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
671 r_Render_DrawText(_lc[I_GAME_DEATHS], x + w1 + w2 + w3, yy, 255, 127, 0, 255, stdfont, TBasePoint.BP_UP);
672 INC(yy, ch + ch div 2);
673 for i := 0 to players - 1 do
674 begin
675 // rr := 255; gg := 127; bb := 0;
676 rr := 255; gg := 255; bb := 255;
677 if cs.PlayerStat[i].Spectator then
678 begin
679 rr := rr div 2; gg := gg div 2; bb := bb div 2;
680 end;
682 // Player color
683 r_Draw_Rect(x, yy, x + 16 - 1, yy + 16 - 1, 192, 192, 192, 255);
684 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);
685 // Player name
686 if gShowPIDs then s := Format('[%5d] %s', [cs.PlayerStat[i].UID, cs.PlayerStat[i].Name]) else s := cs.PlayerStat[i].Name;
687 if (gPlayers[cs.PlayerStat[i].Num] <> nil) and (gPlayers[cs.PlayerStat[i].Num].FReady) then s := s + ' *';
688 r_Render_DrawText(s, x + 16 + 8, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_LEFTUP);
689 if endview = false then
690 begin
691 // Player ping/loss
692 s := Format(_lc[I_GAME_PING_MS], [cs.PlayerStat[i].Ping, cs.PlayerStat[i].Loss]);
693 r_Render_DrawText(s, x + w1, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
694 end;
695 // Player frags
696 s := IntToStr(cs.PlayerStat[i].Frags);
697 r_Render_DrawText(s, x + w1 + w2, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
698 // Player deaths
699 s := IntToStr(cs.PlayerStat[i].Deaths);
700 r_Render_DrawText(s, x + w1 + w2 + w3, yy, rr, gg, bb, 255, stdfont, TBasePoint.BP_UP);
702 INC(yy, ch + ch div 2);
703 end;
704 end;
705 end;
707 procedure r_Render_DrawStatsWindow (x, y, w, h: Integer; cs: TEndCustomGameStat; endview: Boolean);
708 var xoff, yoff, cw, ch: Integer; s: AnsiString;
709 begin
710 xoff := 0; yoff := 8;
711 r_Draw_GetTextSize('W', stdfont, cw, ch);
712 r_Draw_FillRect(x, y, x + w - 1, y + h - 1, 64, 64, 64, 224);
713 r_Draw_Rect(x, y, x + w - 1, y + h - 1, 255, 127, 0, 255);
715 (* LINE 1 *)
717 if endview = false then
718 begin
719 case NetMode of
720 NET_SERVER: s := _lc[I_NET_SERVER];
721 NET_CLIENT: s := NetClientIP + ':' + IntToStr(NetClientPort);
722 otherwise s := '';
723 end;
724 r_Render_DrawText(s, x + 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
725 end;
727 case cs.GameMode of
728 GM_DM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_DM] else s := _lc[I_GAME_LMS];
729 GM_TDM: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_TDM] else s := _lc[I_GAME_TLMS];
730 GM_CTF: s := _lc[I_GAME_CTF];
731 GM_COOP: if gGameSettings.MaxLives = 0 then s := _lc[I_GAME_COOP] else s := _lc[I_GAME_SURV];
732 otherwise s := 'GAME MODE ' + IntToStr(gGameSettings.GameMode);
733 end;
734 r_Render_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
736 if endview = false then
737 begin
738 s := r_Render_TimeToStr(cs.GameTime);
739 r_Render_DrawText(s, x + w - 16, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
740 end;
742 INC(yoff, ch + ch div 2);
744 (* LINE 2/3 *)
746 s := cs.Map;
747 if cs.MapName <> '' then
748 s := s + ' - ' + cs.MapName;
750 if endview = false then
751 begin
752 r_Render_DrawText(s, x + w div 2, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_UP);
753 INC(yoff, ch + ch div 2);
754 case cs.GameMode of
755 GM_DM, GM_TDM: s := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
756 GM_CTF: s := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]);
757 GM_COOP: s := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
758 otherwise s := '';
759 end;
760 r_Render_DrawText(s, x + 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_LEFTUP);
761 case cs.GameMode of
762 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]);
763 GM_COOP: s := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
764 otherwise s := '';
765 end;
766 r_Render_DrawText(s, x + w - 16, y + yoff, 200, 200, 200, 255, stdfont, TBasePoint.BP_RIGHTUP);
767 INC(yoff, ch);
768 end
769 else
770 begin
771 xoff := MAX(Length(_lc[I_MENU_MAP]) + 1, Length(_lc[I_GAME_GAME_TIME]) + 1) * cw;
772 r_Render_DrawText(_lc[I_MENU_MAP], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
773 r_Render_DrawText(s, x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
774 INC(yoff, ch);
775 r_Render_DrawText(_lc[I_GAME_GAME_TIME], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
776 r_Render_DrawText(r_Render_TimeToStr(cs.GameTime), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
777 INC(yoff, ch);
778 end;
780 INC(yoff, ch);
782 (* LINE 4/5 *)
784 if endview and (cs.GameMode = GM_COOP) then
785 begin
786 xoff := MAX(Length(_lc[I_GAME_MONSTERS]) + 1, Length(_lc[I_GAME_SECRETS]) + 1) * cw;
787 r_Render_DrawText(_lc[I_GAME_MONSTERS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
788 r_Render_DrawText(IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
789 INC(yoff, ch);
790 r_Render_DrawText(_lc[I_GAME_SECRETS], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
791 r_Render_DrawText(IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
792 INC(yoff, ch);
793 INC(yoff, ch);
794 end;
796 (* LINE 6/7 *)
798 if endview and (cs.GameMode = GM_COOP) and gLastMap then
799 begin
800 xoff := MAX(Length(_lc[I_GAME_MONSTERS_TOTAL]) + 1, Length(_lc[I_GAME_SECRETS_TOTAL]) + 1) * cw;
801 r_Render_DrawText(_lc[I_GAME_MONSTERS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
802 r_Render_DrawText(IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
803 INC(yoff, ch);
804 r_Render_DrawText(_lc[I_GAME_SECRETS_TOTAL], x + 16, y + yoff, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
805 r_Render_DrawText(IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), x + 16 + xoff, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
806 INC(yoff, ch);
807 INC(yoff, ch);
808 end;
810 (* LINE *)
812 if endview and (cs.GameMode in [GM_TDM, GM_CTF]) then
813 begin
814 if cs.TeamStat[TEAM_RED].Score > cs.TeamStat[TEAM_BLUE].Score then s := _lc[I_GAME_WIN_RED]
815 else if cs.TeamStat[TEAM_BLUE].Score > cs.TeamStat[TEAM_RED].Score then s := _lc[I_GAME_WIN_BLUE]
816 else s := _lc[I_GAME_WIN_DRAW];
817 r_Render_DrawText(s, x + w div 2, y + yoff, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
818 INC(yoff, ch);
819 INC(yoff, ch);
820 end;
822 (* LINE n *)
824 r_Render_DrawStatsColumns(cs, x + 16, y + yoff, w - 16 - 16, endview);
825 end;
827 function r_Render_StatsHeight (players: Integer): Integer;
828 var cw, ch: Integer;
829 begin
830 ASSERT(players >= 0);
831 r_Draw_GetTextSize('W', stdfont, cw, ch);
832 case gGameSettings.GameMode of
833 GM_TDM, GM_CTF: result := 32 + ch * (11 + players);
834 otherwise result := 40 + ch * 5 + (ch + 8) * players;
835 end;
836 end;
838 procedure r_Render_DrawStats;
839 var x, y, w, h, players: Integer; cs: TEndCustomGameStat;
840 begin
841 cs.PlayerStat := g_Player_GetStats();
842 SortGameStat(cs.PlayerStat);
843 cs.TeamStat := gTeamStat;
844 cs.GameTime := gTime;
845 cs.GameMode := gGameSettings.GameMode;
846 cs.Map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':' + g_ExtractFileName(gMapInfo.Map);
847 cs.MapName := gMapInfo.Name;
848 if cs.PlayerStat = nil then players := 0 else players := Length(cs.PlayerStat);
849 w := gScreenWidth - (gScreenWidth div 5);
850 h := r_Render_StatsHeight(players);
851 x := (gScreenWidth div 2) - (w div 2);
852 y := (gScreenHeight div 2) - (h div 2);
853 r_Render_DrawStatsWindow(x, y, w, h, cs, false);
854 end;
856 procedure r_Render_DrawCustomStats;
857 var cw, ch, s: AnsiString;
858 begin
859 if gStatsOff then
860 begin
861 r_Render_DrawText(_lc[I_MENU_INTER_NOTICE_TAB], gScreenWidth div 2, 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
862 end
863 else
864 begin
865 case gGameSettings.GameMode of
866 GM_COOP: if gMissionFailed then s := _lc[I_MENU_INTER_MISSION_FAIL] else s := _lc[I_MENU_INTER_LEVEL_COMPLETE];
867 otherwise s := _lc[I_MENU_INTER_ROUND_OVER];
868 end;
869 r_Render_DrawText(s, gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
871 if gChatShow = false then
872 begin
873 if g_Game_IsClient then s := _lc[I_MENU_INTER_NOTICE_MAP] else s := _lc[I_MENU_INTER_NOTICE_SPACE];
874 r_Render_DrawText(s, gScreenWidth div 2, gScreenHeight - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
875 if g_Game_IsNet then
876 begin
877 s := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
878 r_Render_DrawText(s, gScreenWidth div 2, gScreenHeight - 16 - 4, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
879 end;
880 end;
882 r_Render_DrawStatsWindow(32, 64, gScreenWidth - 32 * 2, gScreenHeight - 64 * 2, CustomStat, true);
883 end;
884 end;
886 procedure r_Render_DrawValueOf (a, b, x, y: Integer; f: TGLFont);
887 var wa, wb, ch: Integer; sa, sb: AnsiString;
888 begin
889 sa := IntToStr(a);
890 sb := IntToStr(b);
891 r_Draw_GetTextSize(sa, f, wa, ch);
892 r_Draw_GetTextSize(sa + ' / ', f, wb, ch);
893 r_Render_DrawText(sa, x, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
894 r_Render_DrawText(' / ', x + wa, y, 255, 255, 255, 255, f, TBasePoint.BP_LEFTUP);
895 r_Render_DrawText(sb, x + wb, y, 255, 0, 0, 255, f, TBasePoint.BP_LEFTUP);
896 end;
898 procedure r_Render_DrawSinglStatsPlayer (player, x, y, w1: Integer);
899 var time, kpm: Single;
900 begin
901 r_Render_DrawText(_lc[I_MENU_INTER_KILLS], x, y, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
902 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Kills, gTotalMonsters, x + w1, y, MenuFont);
903 r_Render_DrawText(_lc[I_MENU_INTER_KPM], x, y + 32, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
904 time := SingleStat.GameTime / 1000;
905 kpm := SingleStat.PlayerStat[player].Kills;
906 if time > 0 then kpm := kpm / time * 60;
907 r_Render_DrawText(Format('%.1f', [kpm]), x + w1, y + 32, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
908 r_Render_DrawText(_lc[I_MENU_INTER_SECRETS], x, y + 64, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
909 r_Render_DrawValueOf(SingleStat.PlayerStat[player].Secrets, SingleStat.TotalSecrets, x + w1, y + 64, MenuFont);
910 end;
912 procedure r_Render_DrawSingleStats;
913 var xx, wa, wb, ww, ch: Integer; s: AnsiString;
914 begin
915 r_Render_DrawText(_lc[I_MENU_INTER_LEVEL_COMPLETE], gScreenWidth div 2, 32, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
917 r_Draw_GetTextSize(_lc[I_MENU_INTER_KPM] + ' ', menufont, wa, ch);
918 r_Draw_GetTextSize(' 9999.9', menufont, wb, ch);
919 ww := wa + wb;
920 xx := gScreenWidth div 2 - ww div 2;
922 s := r_Render_TimeToStr(SingleStat.GameTime);
923 r_Render_DrawText(_lc[I_MENU_INTER_TIME], xx, 80, 255, 255, 255, 255, menufont, TBasePoint.BP_LEFTUP);
924 r_Render_DrawText(s, xx + wa, 80, 255, 0, 0, 255, menufont, TBasePoint.BP_LEFTUP);
926 if SingleStat.TwoPlayers then
927 begin
928 r_Render_DrawText(_lc[I_MENU_PLAYER_1], gScreenWidth div 2, 128, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
929 r_Render_DrawSinglStatsPlayer(0, xx, 176, wa);
930 r_Render_DrawText(_lc[I_MENU_PLAYER_2], gScreenWidth div 2, 288, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
931 r_Render_DrawSinglStatsPlayer(1, xx, 336, wa);
932 end
933 else
934 begin
935 r_Render_DrawSinglStatsPlayer(0, xx, 128, wa);
936 end;
937 end;
939 procedure r_Render_DrawSpectHud;
940 var xoff: Integer; s: AnsiString;
942 procedure AddText (s1, s2: AnsiString);
943 var w1, w2, ww, ch: Integer;
944 begin
945 r_Draw_GetTextSize(s1, stdfont, w1, ch);
946 r_Draw_GetTextSize(s2, stdfont, w2, ch);
947 ww := MAX(w1, w2);
948 r_Render_DrawText(s1, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
949 r_Render_DrawText(s2, xoff + ww div 2, gScreenHeight - ch, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
950 xoff := xoff + ww + 16;
951 end;
953 begin
954 xoff := 0;
955 case gSpectMode of
956 SPECT_STATS: s := 'MODE: Stats';
957 SPECT_MAPVIEW: s := 'MODE: Observe Map';
958 SPECT_PLAYERS: s := 'MODE: Watch Players';
959 otherwise s := 'MODE: ' + IntToStr(gSpectMode);
960 end;
961 AddText(s, '< jump >');
962 if gSpectMode = SPECT_STATS then
963 AddText('Autoview', '< fire >');
964 if gSpectMode = SPECT_MAPVIEW then
965 AddText('[-] Step ' + IntToStr(gSpectStep) + ' [+]', '<prev weap> <next weap>');
966 if gSpectMode = SPECT_PLAYERS then
967 begin
968 AddText('Player 1', '<left/right>');
969 if gSpectViewTwo then
970 AddText('Player 2', '<prev w/next w>');
971 AddText('2x View', '<up/down>');
972 end;
973 end;
975 function GetActivePlayer_ByID (id: Integer): TPlayer;
976 var i, len: Integer; p: TPlayer;
977 begin
978 p := nil;
979 if (id >= 0) and (gPlayers <> nil) then
980 begin
981 i := 0; len := Length(gPlayers);
982 while (i < len) and ((IsActivePlayer(gPlayers[i]) = false) or (gPlayers[i].UID <> id)) do INC(i);
983 if i < len then p := gPlayers[i];
984 end;
985 result := p;
986 end;
988 procedure r_Render_Draw;
989 var p1, p2: TPlayer;
990 begin
991 if gExit = EXIT_QUIT then
992 exit;
994 r_Draw_Setup(gScreenWidth, gScreenHeight);
996 glClearColor(0.0, 0.0, 0.0, 0.0);
997 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
999 glColor4ub(255, 255, 255, 255);
1000 glEnable(GL_SCISSOR_TEST);
1001 r_Draw_SetRect(0, 0, gScreenWidth, gScreenHeight);
1003 //e_LogWritefln('r_render_draw: %sx%s', [gScreenWidth, gScreenHeight]);
1005 p1 := nil;
1006 p2 := nil;
1007 if gGameOn or (gState = STATE_FOLD) then
1008 begin
1009 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
1010 begin
1011 if gRevertPlayers then
1012 begin
1013 p1 := gPlayer2;
1014 p2 := gPlayer1;
1015 end
1016 else
1017 begin
1018 p1 := gPlayer1;
1019 p2 := gPlayer2;
1020 end;
1021 end
1022 else if gPlayer1 <> nil then
1023 begin
1024 p1 := gPlayer1;
1025 end
1026 else if gPlayer2 <> nil then
1027 begin
1028 p1 := gPlayer2;
1029 end;
1030 if (gSpectMode = SPECT_PLAYERS) and (gPlayers <> nil) then
1031 begin
1032 p1 := GetActivePlayer_ByID(gSpectPID1);
1033 if p1 = nil then
1034 p1 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1035 if gSpectViewTwo then
1036 begin
1037 p2 := GetActivePlayer_ByID(gSpectPID2);
1038 if p2 = nil then
1039 p2 := GetActivePlayer_ByID(GetActivePlayerID_Next());
1040 end;
1041 end;
1042 end;
1044 if gGameOn or ((gState in [STATE_FOLD]) and (EndingGameCounter < 255)) then
1045 begin
1046 // TODO setup player hear point
1048 if gSpectMode = SPECT_MAPVIEW then
1049 begin
1050 r_Render_DrawMapView(0, 0, gScreenWidth, gScreenHeight, gSpectX + gScreenWidth div 2, gSpectY + gScreenHeight div 2);
1051 end
1052 else if (p1 <> nil) and (p2 <> nil) then
1053 begin
1054 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight div 2 - 2, p1);
1055 r_Render_DrawPlayerView(0, gScreenHeight div 2 + 2, gScreenWidth, gScreenHeight div 2, p2);
1056 end
1057 else if p1 <> nil then
1058 begin
1059 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p1);
1060 end
1061 else if p2 <> nil then
1062 begin
1063 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, p2);
1064 end;
1066 // TODO draw holmes inspector
1068 // TODO draw messages
1069 if IsDrawStat or (gSpectMode = SPECT_STATS) then
1070 r_Render_DrawStats;
1072 if gSpectHUD and (gChatShow = false) and (gSpectMode <> SPECT_NONE) and (gSpectAuto = false) then
1073 r_Render_DrawSpectHud;
1074 end;
1076 if gPauseMain and gGameOn {$IFDEF ENABLE_MENU}and (g_ActiveWindow = nil){$ENDIF} then
1077 begin
1078 // TODO draw pause screen
1079 end;
1081 if not gGameOn then
1082 begin
1083 case gState of
1084 STATE_NONE: (* do nothing *) ;
1085 STATE_MENU: r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
1086 STATE_FOLD:
1087 begin
1088 if EndingGameCounter > 0 then
1089 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1090 end;
1091 STATE_INTERCUSTOM:
1092 begin
1093 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1094 if EndPicPath <> '' then
1095 r_Render_DrawBackground(EndPicPath)
1096 else
1097 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC])
1098 else
1099 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
1101 r_Render_DrawCustomStats;
1103 {$IFDEF ENABLE_MENU}
1104 if g_ActiveWindow <> nil then
1105 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1106 {$ENDIF}
1107 end;
1108 STATE_INTERSINGLE, STATE_INTERTEXT, STATE_INTERPIC:
1109 begin
1110 if EndingGameCounter > 0 then
1111 begin
1112 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
1113 end
1114 else
1115 begin
1116 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
1117 r_Render_DrawSingleStats;
1118 {$IFDEF ENABLE_MENU}
1119 if g_ActiveWindow <> nil then
1120 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1121 {$ENDIF}
1122 end;
1123 end;
1124 STATE_ENDPIC:
1125 begin
1126 if EndPicPath <> '' then
1127 r_Render_DrawBackground(EndPicPath)
1128 else
1129 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC]);
1130 {$IFDEF ENABLE_MENU}
1131 if g_ActiveWindow <> nil then
1132 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1133 {$ENDIF}
1134 end;
1135 STATE_SLIST:
1136 begin
1137 r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
1138 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1139 r_Render_DrawServerList(slCurrent, slTable);
1140 end;
1141 end;
1142 end;
1144 {$IFDEF ENABLE_MENU}
1145 if g_ActiveWindow <> nil then
1146 begin
1147 if gGameOn then
1148 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
1149 r_GUI_Draw_Window(g_ActiveWindow);
1150 end;
1151 {$ENDIF}
1153 r_Console_Draw(false);
1155 // TODO draw holmes interface
1157 glFlush();
1158 glFinish();
1159 sys_Repaint;
1160 end;
1162 procedure r_Render_Resize (w, h: Integer);
1163 begin
1164 gWinSizeX := w;
1165 gWinSizeY := h;
1166 gRC_Width := w;
1167 gRC_Height := h;
1168 gScreenWidth := w;
1169 gScreenHeight := h;
1170 end;
1172 procedure r_Render_Apply;
1173 begin
1174 {$IFDEF ENABLE_SYSTEM}
1175 if sys_SetDisplayModeGL(GetInfo()) then
1176 e_LogWriteln('resolution changed')
1177 else
1178 e_LogWriteln('resolution not changed');
1179 sys_EnableVSync(gVSync)
1180 {$ENDIF}
1181 end;
1183 function r_Render_WriteScreenShot (filename: String): Boolean;
1184 begin
1185 Result := False;
1186 end;
1188 {$IFDEF ENABLE_GIBS}
1189 function r_Render_GetGibRect (m, id: Integer): TRectWH;
1190 begin
1191 result := r_Map_GetGibSize(m, id);
1192 end;
1193 {$ENDIF}
1195 {$IFDEF ENABLE_GFX}
1196 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
1197 begin
1198 r_Map_NewGFX(AnimType, X, Y);
1199 end;
1200 {$ENDIF}
1202 {$IFDEF ENABLE_TOUCH}
1203 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
1204 begin
1205 founded := False;
1206 end;
1207 {$ENDIF}
1209 {$IFDEF ENABLE_MENU}
1210 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
1211 begin
1212 r_GUI_GetSize(ctrl, w, h);
1213 end;
1215 procedure r_Render_GetLogoSize (out w, h: Integer);
1216 begin
1217 r_GUI_GetLogoSize(w, h);
1218 end;
1220 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
1221 begin
1222 r_GUI_GetMaxFontSize(BigFont, w, h);
1223 end;
1225 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
1226 begin
1227 r_GUI_GetStringSize(BigFont, str, w, h);
1228 end;
1229 {$ENDIF}
1231 procedure r_Render_DrawLoading (force: Boolean);
1232 begin
1233 // TODO draw loading screen
1234 end;
1236 end.