nuclide/Source/menu-fn/entry.cpp

188 lines
3.5 KiB
C++
Raw Normal View History

2018-12-27 14:53:24 -08:00
/***
*
2019-01-16 08:43:50 -08:00
* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved.
*
* See the file LICENSE attached with the sources for usage details.
2018-12-27 14:53:24 -08:00
*
****/
2019-01-18 16:37:31 -08:00
var int g_initialized = FALSE;
void cvar_init(void)
{
/* TODO: Shove these into defaults.cfg instead of forcing them */
localcmd("seta con_textsize -12\n");
localcmd("seta scr_conalpha 1\n");
localcmd("seta cl_idlefps 0\n");
localcmd("seta allow_download_packages 0\n");
localcmd("seta r_shadow_realtime_dlight 0\n");
localcmd("seta gl_mindist 4\n"); // Thanks Valve for v_shotgun.mdl
localcmd("seta _pext_infoblobs 1\n");
/* Hack! */
localcmd("seta gl_font 0\n");
localcmd("seta gl_font CONCHARS?fmt=h\n");
}
2018-12-27 14:53:24 -08:00
void m_init(void)
{
vector g_btnsize;
registercommand("menu_customgame");
2018-12-27 14:53:24 -08: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", -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", -1 );
2018-12-27 14:53:24 -08:00
localcmd("plug_load ffmpeg\n");
2019-01-18 16:37:31 -08:00
cvar_init();
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];
games_init();
2018-12-27 14:53:24 -08:00
main_init();
Colors_Init();
Strings_Init();
2019-01-18 16:37:31 -08:00
g_initialized = TRUE;
2018-12-27 14:53:24 -08:00
}
void m_shutdown(void)
{
2019-01-18 16:37:31 -08:00
g_initialized = FALSE;
/*int i = 0;
for (i = 0; i < g_bmp.length; i++) {
freepic(g_bmp[i]);
2019-01-18 16:37:31 -08:00
}*/
entity e;
2019-01-18 16:37:31 -08:00
while((e=nextent(__NULL__)))
remove(e);
memfree(g_sprays);
memfree(g_models);
memfree(g_maps);
memfree(games);
2018-12-27 14:53:24 -08:00
}
void m_draw(vector screensize)
{
static float oldtime;
frametime = time - oldtime;
if (!g_active) {
return;
}
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;
}
if (clientstate() == 2) {
drawfill([0,0], screensize, [0,0,0], 0.75f);
} 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);
}
main_draw();
oldtime = time;
}
/*void m_drawloading(vector screensize, float opaque)
2018-12-27 14:53:24 -08:00
{
}*/
2018-12-27 14:53:24 -08:00
float Menu_InputEvent(float evtype, float scanx, float chary, float devid)
{
switch (evtype) {
case IE_KEYDOWN:
if (chary == K_ESCAPE) {
if (clientstate() == 2) {
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;
}
void m_display(void)
{
g_active = TRUE;
setkeydest(KEY_MENU);
setmousetarget(TARGET_MENU);
setcursormode(TRUE, "gfx/cursor");
}
/*
=================
m_hide
=================
*/
void m_hide(void)
{
g_active = FALSE;
setkeydest(KEY_GAME);
setmousetarget(TARGET_CLIENT);
setcursormode(FALSE);
}
/*
=================
m_toggle
=================
*/
void m_toggle(float fMode)
{
if (fMode == FALSE) {
m_hide();
} else {
m_display();
}
}
float m_consolecommand(string cmd)
{
tokenize(cmd);
switch (argv(0)) {
2019-01-18 17:21:44 -08:00
case "menu_customgame":
g_menupage = PAGE_CUSTOMGAME;
break;
2018-12-27 14:53:24 -08:00
case "togglemenu":
m_display();
break;
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
}