This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/engine/uimenu/ui_main.c

128 lines
3.0 KiB
C
Raw Normal View History

2007-11-20 22:00:00 +01:00
//=======================================================================
// Copyright XashXT Group 2007 <20>
// ui_main.c - progs user interface
//=======================================================================
#include "uimenu.h"
2007-11-23 22:00:00 +01:00
bool ui_active = false;
2007-11-20 22:00:00 +01:00
2007-11-21 22:00:00 +01:00
void UI_Error(const char *format, ...)
2007-11-20 22:00:00 +01:00
{
2007-11-21 22:00:00 +01:00
static bool processingError = false;
char errorstring[MAX_INPUTLINE];
va_list argptr;
2007-11-20 22:00:00 +01:00
2007-11-21 22:00:00 +01:00
va_start( argptr, format );
2007-11-30 22:00:00 +01:00
com.vsnprintf(errorstring, sizeof(errorstring), format, argptr);
2007-11-21 22:00:00 +01:00
va_end( argptr );
Host_Error( "Menu_Error: %s\n", errorstring );
2007-11-20 22:00:00 +01:00
2007-11-21 22:00:00 +01:00
if( !processingError )
{
2007-11-20 22:00:00 +01:00
processingError = true;
PRVM_Crash();
processingError = false;
}
2007-11-21 22:00:00 +01:00
else Host_Error( "Menu_RecursiveError: call to UI_Error (from PRVM_Crash)!\n" );
2007-11-20 22:00:00 +01:00
// fall back to the normal menu
2007-11-21 22:00:00 +01:00
Msg("Falling back to normal menu\n");
2007-11-20 22:00:00 +01:00
cls.key_dest = key_game;
// init the normal menu now -> this will also correct the menu router pointers
Host_AbortCurrentFrame();
}
2007-11-23 22:00:00 +01:00
void UI_KeyEvent( int key )
2007-11-20 22:00:00 +01:00
{
2007-11-23 22:00:00 +01:00
const char *ascii = Key_KeynumToString(key);
2007-11-20 22:00:00 +01:00
PRVM_Begin;
2007-11-21 22:00:00 +01:00
PRVM_SetProg( PRVM_MENUPROG );
2007-11-20 22:00:00 +01:00
// set time
*prog->time = cls.realtime;
2007-11-23 22:00:00 +01:00
// setup args
PRVM_G_FLOAT(OFS_PARM0) = key;
PRVM_G_INT(OFS_PARM1) = PRVM_SetEngineString(ascii);
PRVM_ExecuteProgram (prog->globals.ui->m_keydown, "QC function m_keydown is missing");
2007-11-20 22:00:00 +01:00
PRVM_End;
2007-11-23 22:00:00 +01:00
switch (key)
{
case K_ESCAPE:
UI_ToggleMenu_f();
break;
}
2007-11-20 22:00:00 +01:00
}
2007-11-21 22:00:00 +01:00
void UI_Draw( void )
2007-11-20 22:00:00 +01:00
{
PRVM_Begin;
PRVM_SetProg(PRVM_MENUPROG);
// set time
*prog->time = cls.realtime;
2007-11-23 22:00:00 +01:00
PRVM_ExecuteProgram (prog->globals.ui->m_draw, "QC function m_draw is missing");
2007-11-20 22:00:00 +01:00
PRVM_End;
}
2007-11-21 22:00:00 +01:00
void UI_ToggleMenu_f( void )
2007-11-20 22:00:00 +01:00
{
PRVM_Begin;
PRVM_SetProg(PRVM_MENUPROG);
// set time
*prog->time = cls.realtime;
2007-11-23 22:00:00 +01:00
ui_active = !ui_active;
2007-11-20 22:00:00 +01:00
2007-11-23 22:00:00 +01:00
PRVM_ExecuteProgram (prog->globals.ui->m_toggle, "QC function m_toggle is missing");
2007-11-20 22:00:00 +01:00
PRVM_End;
}
2007-11-21 22:00:00 +01:00
void UI_Shutdown( void )
2007-11-20 22:00:00 +01:00
{
PRVM_Begin;
PRVM_SetProg(PRVM_MENUPROG);
// set time
2007-11-21 22:00:00 +01:00
//*prog->time = cls.realtime;
2007-11-20 22:00:00 +01:00
2007-11-23 22:00:00 +01:00
PRVM_ExecuteProgram (prog->globals.ui->m_shutdown, "QC function m_shutdown is missing");
2007-11-20 22:00:00 +01:00
// reset key_dest
cls.key_dest = key_game;
// AK not using this cause Im not sure whether this is useful at all instead :
PRVM_ResetProg();
PRVM_End;
}
2007-11-21 22:00:00 +01:00
void UI_Init( void )
2007-11-20 22:00:00 +01:00
{
PRVM_Begin;
2007-11-21 22:00:00 +01:00
PRVM_InitProg( PRVM_MENUPROG );
2007-11-20 22:00:00 +01:00
2007-11-23 22:00:00 +01:00
prog->progs_mempool = Mem_AllocPool( "Uimenu Progs" );
prog->builtins = vm_ui_builtins;
prog->numbuiltins = vm_ui_numbuiltins;
prog->edictprivate_size = sizeof(ui_edict_t);
prog->limit_edicts = UI_MAX_EDICTS;
prog->name = "uimenu";
2007-11-20 22:00:00 +01:00
prog->num_edicts = 1;
2007-11-21 22:00:00 +01:00
prog->extensionstring = "";
2007-11-23 22:00:00 +01:00
prog->loadintoworld = false;
2007-11-21 22:00:00 +01:00
prog->init_cmd = VM_Cmd_Init;
prog->reset_cmd = VM_Cmd_Reset;
prog->error_cmd = UI_Error;
2007-11-20 22:00:00 +01:00
2007-11-23 22:00:00 +01:00
PRVM_LoadProgs( "uimenu.dat", 0, NULL, UI_NUM_REQFIELDS, ui_reqfields );
2007-11-20 22:00:00 +01:00
*prog->time = cls.realtime;
2007-11-23 22:00:00 +01:00
PRVM_ExecuteProgram (prog->globals.ui->m_init, "QC function m_init is missing");
2007-11-20 22:00:00 +01:00
PRVM_End;
}