2019-08-31 19:18:15 -07:00
|
|
|
/*
|
2020-04-07 05:46:23 -07:00
|
|
|
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
|
2019-08-31 19:18:15 -07:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
2018-12-27 14:53:24 -08:00
|
|
|
|
2019-01-18 16:37:31 -08:00
|
|
|
var int g_initialized = FALSE;
|
|
|
|
|
2020-04-12 06:50:42 -07:00
|
|
|
#define FN_UPDATE_PKGLIST "http://www.frag-net.com/dl/%s_packages"
|
|
|
|
|
2019-08-31 19:18:15 -07:00
|
|
|
const string LICENSE_TEXT = "\
|
2019-09-04 09:11:55 -07:00
|
|
|
==============================================================================\
|
2020-04-07 05:46:23 -07:00
|
|
|
Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>\
|
2019-03-19 12:01:24 -07:00
|
|
|
\
|
2019-08-31 19:18:15 -07:00
|
|
|
Permission to use, copy, modify, and distribute this software for any\
|
|
|
|
purpose with or without fee is hereby granted, provided that the above\
|
|
|
|
copyright notice and this permission notice appear in all copies.\
|
2019-03-19 12:01:24 -07:00
|
|
|
\
|
2019-08-31 19:18:15 -07:00
|
|
|
THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER\
|
|
|
|
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING\
|
|
|
|
OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\
|
2019-09-04 09:11:55 -07:00
|
|
|
==============================================================================";
|
2019-03-19 12:01:24 -07:00
|
|
|
|
2021-01-22 13:37:06 -08:00
|
|
|
/* r_autoscale forces vid_conautoscale to be one of 4 integer values.
|
|
|
|
* this is due to vid_conautoscale 0 scaling with in floating point... which
|
|
|
|
* in turns results in skipped rows/columns and shimmering. */
|
2020-04-12 06:50:42 -07:00
|
|
|
var int autocvar_r_autoscale = TRUE;
|
|
|
|
void
|
|
|
|
Menu_AutoScale(void)
|
|
|
|
{
|
|
|
|
if (autocvar_r_autoscale) {
|
|
|
|
vector psize = getproperty(VF_SCREENPSIZE);
|
|
|
|
if (psize[1] >= (480 * 4)) {
|
|
|
|
cvar_set("vid_conautoscale", "4");
|
|
|
|
} else if (psize[1] >= (480 * 3)) {
|
|
|
|
cvar_set("vid_conautoscale", "3");
|
|
|
|
} else if (psize[1] >= (480 * 2)) {
|
|
|
|
cvar_set("vid_conautoscale", "2");
|
|
|
|
} else {
|
|
|
|
cvar_set("vid_conautoscale", "1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-22 13:37:06 -08:00
|
|
|
/* old Half-Life configs that have a completely different gamma model would
|
|
|
|
* mess up visibility on initial launch - so we catch that and and force
|
|
|
|
* our default to fix it */
|
2020-08-08 15:53:18 -07:00
|
|
|
void
|
|
|
|
Menu_GammaHack(void)
|
|
|
|
{
|
|
|
|
if (cvar("brightness") != cvar("vid_brightness")) {
|
|
|
|
cvar_set("brightness", "0");
|
|
|
|
print("^1Menu_RendererRestarted^7: Brightness hack.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cvar("gamma") != cvar("vid_gamma")) {
|
|
|
|
cvar_set("gamma", "1");
|
|
|
|
print("^1Menu_RendererRestarted^7: Gamma hack.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-22 13:37:06 -08:00
|
|
|
/* called upon menu init/restart */
|
2020-04-12 06:50:42 -07:00
|
|
|
void
|
|
|
|
m_init(void)
|
2018-12-27 14:53:24 -08:00
|
|
|
{
|
|
|
|
vector g_btnsize;
|
|
|
|
|
2019-08-31 19:18:15 -07:00
|
|
|
print(LICENSE_TEXT);
|
2019-03-19 12:01:24 -07:00
|
|
|
print("\n\n");
|
|
|
|
|
2021-01-23 05:54:31 -08:00
|
|
|
registercommand("menu_updates");
|
2019-01-18 20:50:25 -08:00
|
|
|
registercommand("menu_customgame");
|
2020-09-27 05:25:10 -07:00
|
|
|
registercommand("map_background");
|
2020-10-06 05:27:44 -07:00
|
|
|
registercommand("menu_musicstart");
|
|
|
|
|
2020-04-12 06:50:42 -07:00
|
|
|
font_console = loadfont("font", "", "12", -1);
|
|
|
|
font_label = loadfont("label", "gfx/shell/mssansserif.ttf", "10 12 14", -1);
|
|
|
|
font_arial = loadfont("label", "gfx/shell/arial.ttf", "14 11 12", -1);
|
|
|
|
font_label_b = loadfont("label_b", "gfx/shell/arialbd.ttf", "14 12", -1);
|
|
|
|
font_label_p = loadfont("label_p", "gfx/shell/arialbd.ttf", "16 21", -1);
|
2018-12-27 14:53:24 -08:00
|
|
|
|
2019-01-15 16:14:54 -08:00
|
|
|
localcmd("plug_load ffmpeg\n");
|
2019-01-18 16:37:31 -08:00
|
|
|
|
2019-01-15 16:14:54 -08:00
|
|
|
shaderforname("logo_avi", "{\n{\nvideomap av:media/logo.avi\n}\n}");
|
|
|
|
|
2018-12-27 14:53:24 -08:00
|
|
|
for (int i = 0; i < g_bmp.length; i++) {
|
|
|
|
precache_pic(g_bmp[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_btnsize = drawgetimagesize(g_bmp[BTNS_MAIN]);
|
|
|
|
g_btnofs = 26 / g_btnsize[1];
|
2020-03-31 16:08:01 -07:00
|
|
|
precache_pic("gfx/shell/fragnet");
|
2018-12-27 14:53:24 -08:00
|
|
|
|
2019-01-18 12:05:42 -08:00
|
|
|
games_init();
|
2018-12-27 14:53:24 -08:00
|
|
|
main_init();
|
2019-01-18 20:50:25 -08:00
|
|
|
|
|
|
|
Colors_Init();
|
|
|
|
Strings_Init();
|
2019-01-18 16:37:31 -08:00
|
|
|
g_initialized = TRUE;
|
2020-03-30 05:46:55 -07:00
|
|
|
|
2020-10-07 02:38:32 -07:00
|
|
|
if (cvar_string("gameinfo_gamedir") != "valve") {
|
2020-03-30 05:46:55 -07:00
|
|
|
m_intro_skip();
|
2020-04-03 06:01:55 -07:00
|
|
|
Music_MenuStart();
|
2020-03-30 05:46:55 -07:00
|
|
|
}
|
2020-09-05 23:37:36 -07:00
|
|
|
|
2021-01-23 15:11:08 -08:00
|
|
|
if (game_updateinstallcount() == 0 || autocvar_menu_updating) {
|
2021-01-23 05:54:31 -08:00
|
|
|
shaderforname("logo_avi", "{\n{\nvideomap av:media/logo.avi\n}\n}");
|
2020-04-12 06:50:42 -07:00
|
|
|
g_menupage = PAGE_UPDATES;
|
|
|
|
}
|
2020-09-05 23:37:36 -07:00
|
|
|
|
2020-04-12 06:50:42 -07:00
|
|
|
Menu_AutoScale();
|
2020-08-08 15:53:18 -07:00
|
|
|
Menu_GammaHack();
|
2018-12-27 14:53:24 -08:00
|
|
|
}
|
|
|
|
|
2021-01-22 13:37:06 -08:00
|
|
|
/* called upon vid_reload, vid_restart, but not menu init/restart */
|
2020-04-12 06:50:42 -07:00
|
|
|
void
|
2020-05-31 03:54:04 -07:00
|
|
|
Menu_RendererRestarted(string rendererdesc)
|
2020-04-12 06:50:42 -07:00
|
|
|
{
|
|
|
|
Menu_AutoScale();
|
2020-08-08 15:53:18 -07:00
|
|
|
Menu_GammaHack();
|
2020-04-12 06:50:42 -07:00
|
|
|
}
|
|
|
|
|
2021-01-22 13:37:06 -08:00
|
|
|
/* called, in theory, whenever the menu gets killed */
|
2020-04-12 06:50:42 -07:00
|
|
|
void
|
|
|
|
m_shutdown(void)
|
2018-12-27 14:53:24 -08:00
|
|
|
{
|
2019-01-18 16:37:31 -08:00
|
|
|
g_initialized = FALSE;
|
2019-01-18 12:05:42 -08:00
|
|
|
/*int i = 0;
|
|
|
|
for (i = 0; i < g_bmp.length; i++) {
|
|
|
|
freepic(g_bmp[i]);
|
2019-01-18 16:37:31 -08:00
|
|
|
}*/
|
|
|
|
|
2019-01-18 12:05:42 -08:00
|
|
|
entity e;
|
2019-01-18 16:37:31 -08:00
|
|
|
while((e=nextent(__NULL__)))
|
2019-01-18 12:05:42 -08:00
|
|
|
remove(e);
|
|
|
|
|
|
|
|
memfree(g_sprays);
|
|
|
|
memfree(g_models);
|
|
|
|
memfree(games);
|
2018-12-27 14:53:24 -08:00
|
|
|
}
|
|
|
|
|
2021-01-22 13:37:06 -08:00
|
|
|
/* called every frame, influenced by cl_idlefps */
|
2020-04-12 06:50:42 -07:00
|
|
|
void
|
|
|
|
m_draw(vector screensize)
|
2018-12-27 14:53:24 -08:00
|
|
|
{
|
2020-04-12 06:50:42 -07:00
|
|
|
static float oldtime;
|
2018-12-27 14:53:24 -08:00
|
|
|
frametime = time - oldtime;
|
2019-01-18 16:37:31 -08:00
|
|
|
|
|
|
|
if (g_initialized == FALSE) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-27 14:53:24 -08:00
|
|
|
|
|
|
|
if ((screensize[0] != g_vidsize[0]) || (screensize[1] != g_vidsize[1])) {
|
|
|
|
g_vidsize[0] = screensize[0];
|
|
|
|
g_vidsize[1] = screensize[1];
|
|
|
|
g_menuofs[0] = (g_vidsize[0] / 2) - 320;
|
|
|
|
g_menuofs[1] = (g_vidsize[1] / 2) - 240;
|
2020-04-12 06:50:42 -07:00
|
|
|
Menu_AutoScale();
|
|
|
|
}
|
|
|
|
|
2020-09-27 05:25:10 -07:00
|
|
|
g_background = cvar("_background");
|
|
|
|
|
2020-09-29 05:24:21 -07:00
|
|
|
/* make sure input carries over when a map background is active */
|
2020-09-27 05:25:10 -07:00
|
|
|
if (g_background) {
|
2020-09-29 05:24:21 -07:00
|
|
|
if (getkeydest() != KEY_MENU) {
|
|
|
|
setkeydest(KEY_MENU);
|
|
|
|
setmousetarget(TARGET_MENU);
|
|
|
|
setcursormode(TRUE, "gfx/cursor");
|
|
|
|
}
|
2020-09-27 05:25:10 -07:00
|
|
|
}
|
|
|
|
|
2020-06-30 08:14:06 -07:00
|
|
|
/* to prevent TCP timeouts */
|
|
|
|
menu_chatrooms_keepalive();
|
|
|
|
|
2020-09-27 05:25:10 -07:00
|
|
|
if (!g_active && !g_background) {
|
2020-09-29 05:24:21 -07:00
|
|
|
/* make sure we're redirecting input when the background's gone */
|
|
|
|
if (getkeydest() != KEY_GAME) {
|
|
|
|
setkeydest(KEY_GAME);
|
|
|
|
setmousetarget(TARGET_CLIENT);
|
|
|
|
setcursormode(FALSE);
|
|
|
|
}
|
2020-04-12 06:50:42 -07:00
|
|
|
return;
|
2018-12-27 14:53:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (clientstate() == 2) {
|
2020-09-27 05:25:10 -07:00
|
|
|
if (!g_background)
|
|
|
|
drawfill([0,0], screensize, [0,0,0], 0.75f);
|
2018-12-27 14:53:24 -08:00
|
|
|
} else {
|
|
|
|
drawfill([0,0], screensize, [0,0,0], 1.0f);
|
|
|
|
drawpic([g_menuofs[0],g_menuofs[1]], g_bmp[SPLASH],
|
|
|
|
[640,480], [1,1,1], 1.0f);
|
|
|
|
}
|
|
|
|
|
2020-07-11 11:59:45 -07:00
|
|
|
const string ver = "Nuclide (build " __DATE__ ")";
|
2020-09-10 10:28:36 -07:00
|
|
|
drawfont = font_console;
|
2020-07-11 11:59:45 -07:00
|
|
|
|
2020-09-10 10:28:36 -07:00
|
|
|
WLabel_Static(640 - 8 - stringwidth(ver, TRUE, [12,12]),
|
2020-07-24 15:50:51 -07:00
|
|
|
466,
|
2020-07-11 11:59:45 -07:00
|
|
|
ver,
|
2020-09-10 10:28:36 -07:00
|
|
|
12, 12,
|
|
|
|
[1.0f,1.0f,1.0f],
|
|
|
|
0.5f, 0, font_console);
|
2020-07-11 11:59:45 -07:00
|
|
|
|
2018-12-27 14:53:24 -08:00
|
|
|
main_draw();
|
2021-01-23 05:54:31 -08:00
|
|
|
|
|
|
|
/* HACK! after a custom game switches .fmf files, we need to force restart
|
|
|
|
* our menu. I'm so, so sorry. No, RendererRestarted doesn't see fs_game
|
|
|
|
* fast enough either. */
|
|
|
|
if (cvar_string("fs_game") != games[gameinfo_current].gamedir) {
|
2021-01-23 06:24:49 -08:00
|
|
|
localcmd(sprintf("gameinfo_gamedir %s\nmenu_restart\n", cvar_string("fs_game")));
|
2021-01-23 05:54:31 -08:00
|
|
|
}
|
2018-12-27 14:53:24 -08:00
|
|
|
|
|
|
|
oldtime = time;
|
|
|
|
}
|
|
|
|
|
2020-04-12 06:50:42 -07:00
|
|
|
void
|
|
|
|
m_drawloading(vector screensize, float opaque)
|
2018-12-27 14:53:24 -08:00
|
|
|
{
|
2019-09-04 09:11:55 -07:00
|
|
|
vector pos;
|
|
|
|
pos = (screensize / 2) - [32,32];
|
2020-04-12 06:50:42 -07:00
|
|
|
drawfill([0,0], screensize, [0.5,0.5,0.5], 1.0f);
|
2019-09-04 09:11:55 -07:00
|
|
|
drawpic(pos, "gfx/lambda64", [64,64], [1,1,1], 1.0f);
|
|
|
|
}
|
2018-12-27 14:53:24 -08:00
|
|
|
|
2020-04-12 06:50:42 -07:00
|
|
|
float
|
|
|
|
Menu_InputEvent(float evtype, float scanx, float chary, float devid)
|
2018-12-27 14:53:24 -08:00
|
|
|
{
|
|
|
|
switch (evtype) {
|
|
|
|
case IE_KEYDOWN:
|
|
|
|
if (chary == K_ESCAPE) {
|
2020-09-27 05:25:10 -07:00
|
|
|
if (clientstate() == 2 && !g_background) {
|
2018-12-27 14:53:24 -08:00
|
|
|
m_toggle(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IE_MOUSEABS:
|
|
|
|
g_mousepos[0] = scanx;
|
|
|
|
g_mousepos[1] = chary;
|
|
|
|
break;
|
|
|
|
case IE_MOUSEDELTA:
|
|
|
|
g_mousepos[0] += scanx;
|
|
|
|
g_mousepos[1] += chary;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
main_input(evtype, scanx, chary, devid);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-04-12 06:50:42 -07:00
|
|
|
void
|
|
|
|
m_display(void)
|
2018-12-27 14:53:24 -08:00
|
|
|
{
|
|
|
|
g_active = TRUE;
|
|
|
|
setkeydest(KEY_MENU);
|
|
|
|
setmousetarget(TARGET_MENU);
|
|
|
|
setcursormode(TRUE, "gfx/cursor");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
m_hide
|
|
|
|
=================
|
|
|
|
*/
|
2020-04-12 06:50:42 -07:00
|
|
|
void
|
|
|
|
m_hide(void)
|
2018-12-27 14:53:24 -08:00
|
|
|
{
|
|
|
|
g_active = FALSE;
|
|
|
|
setkeydest(KEY_GAME);
|
|
|
|
setmousetarget(TARGET_CLIENT);
|
|
|
|
setcursormode(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
m_toggle
|
|
|
|
=================
|
|
|
|
*/
|
2020-04-12 06:50:42 -07:00
|
|
|
void
|
|
|
|
m_toggle(float fMode)
|
2018-12-27 14:53:24 -08:00
|
|
|
{
|
|
|
|
if (fMode == FALSE) {
|
|
|
|
m_hide();
|
|
|
|
} else {
|
|
|
|
m_display();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-12 06:50:42 -07:00
|
|
|
float
|
|
|
|
m_consolecommand(string cmd)
|
2018-12-27 14:53:24 -08:00
|
|
|
{
|
|
|
|
tokenize(cmd);
|
|
|
|
switch (argv(0)) {
|
2020-10-06 05:27:44 -07:00
|
|
|
case "menu_musicstart":
|
|
|
|
Music_MenuStart();
|
|
|
|
break;
|
2020-04-03 06:01:55 -07:00
|
|
|
case "menu_musictrack":
|
|
|
|
Music_ParseTrack(argv(1));
|
|
|
|
break;
|
|
|
|
case "menu_musicloop":
|
|
|
|
Music_ParseLoop(argv(1));
|
|
|
|
break;
|
2021-01-23 05:54:31 -08:00
|
|
|
case "menu_updates":
|
|
|
|
g_menupage = PAGE_UPDATES;
|
|
|
|
m_intro_skip();
|
|
|
|
break;
|
2019-01-18 17:21:44 -08:00
|
|
|
case "menu_customgame":
|
|
|
|
g_menupage = PAGE_CUSTOMGAME;
|
2020-03-30 05:46:55 -07:00
|
|
|
m_intro_skip();
|
2019-01-18 17:21:44 -08:00
|
|
|
break;
|
2018-12-27 14:53:24 -08:00
|
|
|
case "togglemenu":
|
|
|
|
m_display();
|
|
|
|
break;
|
2020-09-27 05:25:10 -07:00
|
|
|
case "map_background":
|
|
|
|
localcmd(sprintf("maxplayers 2\nset coop 1\nset sv_background 1\nmap %s\n",
|
|
|
|
argv(1)));
|
|
|
|
break;
|
2018-12-27 14:53:24 -08:00
|
|
|
default:
|
2019-01-05 15:22:06 -08:00
|
|
|
return FALSE;
|
2018-12-27 14:53:24 -08:00
|
|
|
}
|
2019-01-05 15:22:06 -08:00
|
|
|
return TRUE;
|
2018-12-27 14:53:24 -08:00
|
|
|
}
|