📄 cg_main.c
字号:
}
*/
}
/*
=======================
CG_BuildSpectatorString
=======================
*/
void CG_BuildSpectatorString() {
int i;
cg.spectatorList[0] = 0;
for (i = 0; i < MAX_CLIENTS; i++) {
if (cgs.clientinfo[i].infoValid && cgs.clientinfo[i].team == TEAM_SPECTATOR ) {
Q_strcat(cg.spectatorList, sizeof(cg.spectatorList), va("%s ", cgs.clientinfo[i].name));
}
}
i = strlen(cg.spectatorList);
if (i != cg.spectatorLen) {
cg.spectatorLen = i;
cg.spectatorWidth = -1;
}
}
/*
===================
CG_RegisterClients
===================
*/
static void CG_RegisterClients( void ) {
int i;
CG_LoadingClient(cg.clientNum);
CG_NewClientInfo(cg.clientNum);
for (i=0 ; i<MAX_CLIENTS ; i++) {
const char *clientInfo;
if (cg.clientNum == i) {
continue;
}
clientInfo = CG_ConfigString( CS_PLAYERS+i );
if ( !clientInfo[0]) {
continue;
}
CG_LoadingClient( i );
CG_NewClientInfo( i );
}
CG_BuildSpectatorString();
}
//===========================================================================
/*
=================
CG_ConfigString
=================
*/
const char *CG_ConfigString( int index ) {
if ( index < 0 || index >= MAX_CONFIGSTRINGS ) {
CG_Error( "CG_ConfigString: bad index: %i", index );
}
return cgs.gameState.stringData + cgs.gameState.stringOffsets[ index ];
}
//==================================================================
/*
======================
CG_StartMusic
======================
*/
void CG_StartMusic( void ) {
char *s;
char parm1[MAX_QPATH], parm2[MAX_QPATH];
// start the background music
s = (char *)CG_ConfigString( CS_MUSIC );
Q_strncpyz( parm1, COM_Parse( &s ), sizeof( parm1 ) );
Q_strncpyz( parm2, COM_Parse( &s ), sizeof( parm2 ) );
trap_S_StartBackgroundTrack( parm1, parm2 );
}
#ifdef MISSIONPACK
char *CG_GetMenuBuffer(const char *filename) {
int len;
fileHandle_t f;
static char buf[MAX_MENUFILE];
len = trap_FS_FOpenFile( filename, &f, FS_READ );
if ( !f ) {
trap_Print( va( S_COLOR_RED "menu file not found: %s, using default\n", filename ) );
return NULL;
}
if ( len >= MAX_MENUFILE ) {
trap_Print( va( S_COLOR_RED "menu file too large: %s is %i, max allowed is %i", filename, len, MAX_MENUFILE ) );
trap_FS_FCloseFile( f );
return NULL;
}
trap_FS_Read( buf, len, f );
buf[len] = 0;
trap_FS_FCloseFile( f );
return buf;
}
//
// ==============================
// new hud stuff ( mission pack )
// ==============================
//
qboolean CG_Asset_Parse(int handle) {
pc_token_t token;
const char *tempStr;
if (!trap_PC_ReadToken(handle, &token))
return qfalse;
if (Q_stricmp(token.string, "{") != 0) {
return qfalse;
}
while ( 1 ) {
if (!trap_PC_ReadToken(handle, &token))
return qfalse;
if (Q_stricmp(token.string, "}") == 0) {
return qtrue;
}
// font
if (Q_stricmp(token.string, "font") == 0) {
int pointSize;
if (!PC_String_Parse(handle, &tempStr) || !PC_Int_Parse(handle, &pointSize)) {
return qfalse;
}
cgDC.registerFont(tempStr, pointSize, &cgDC.Assets.textFont);
continue;
}
// smallFont
if (Q_stricmp(token.string, "smallFont") == 0) {
int pointSize;
if (!PC_String_Parse(handle, &tempStr) || !PC_Int_Parse(handle, &pointSize)) {
return qfalse;
}
cgDC.registerFont(tempStr, pointSize, &cgDC.Assets.smallFont);
continue;
}
// font
if (Q_stricmp(token.string, "bigfont") == 0) {
int pointSize;
if (!PC_String_Parse(handle, &tempStr) || !PC_Int_Parse(handle, &pointSize)) {
return qfalse;
}
cgDC.registerFont(tempStr, pointSize, &cgDC.Assets.bigFont);
continue;
}
// gradientbar
if (Q_stricmp(token.string, "gradientbar") == 0) {
if (!PC_String_Parse(handle, &tempStr)) {
return qfalse;
}
cgDC.Assets.gradientBar = trap_R_RegisterShaderNoMip(tempStr);
continue;
}
// enterMenuSound
if (Q_stricmp(token.string, "menuEnterSound") == 0) {
if (!PC_String_Parse(handle, &tempStr)) {
return qfalse;
}
cgDC.Assets.menuEnterSound = trap_S_RegisterSound( tempStr, qfalse );
continue;
}
// exitMenuSound
if (Q_stricmp(token.string, "menuExitSound") == 0) {
if (!PC_String_Parse(handle, &tempStr)) {
return qfalse;
}
cgDC.Assets.menuExitSound = trap_S_RegisterSound( tempStr, qfalse );
continue;
}
// itemFocusSound
if (Q_stricmp(token.string, "itemFocusSound") == 0) {
if (!PC_String_Parse(handle, &tempStr)) {
return qfalse;
}
cgDC.Assets.itemFocusSound = trap_S_RegisterSound( tempStr, qfalse );
continue;
}
// menuBuzzSound
if (Q_stricmp(token.string, "menuBuzzSound") == 0) {
if (!PC_String_Parse(handle, &tempStr)) {
return qfalse;
}
cgDC.Assets.menuBuzzSound = trap_S_RegisterSound( tempStr, qfalse );
continue;
}
if (Q_stricmp(token.string, "cursor") == 0) {
if (!PC_String_Parse(handle, &cgDC.Assets.cursorStr)) {
return qfalse;
}
cgDC.Assets.cursor = trap_R_RegisterShaderNoMip( cgDC.Assets.cursorStr);
continue;
}
if (Q_stricmp(token.string, "fadeClamp") == 0) {
if (!PC_Float_Parse(handle, &cgDC.Assets.fadeClamp)) {
return qfalse;
}
continue;
}
if (Q_stricmp(token.string, "fadeCycle") == 0) {
if (!PC_Int_Parse(handle, &cgDC.Assets.fadeCycle)) {
return qfalse;
}
continue;
}
if (Q_stricmp(token.string, "fadeAmount") == 0) {
if (!PC_Float_Parse(handle, &cgDC.Assets.fadeAmount)) {
return qfalse;
}
continue;
}
if (Q_stricmp(token.string, "shadowX") == 0) {
if (!PC_Float_Parse(handle, &cgDC.Assets.shadowX)) {
return qfalse;
}
continue;
}
if (Q_stricmp(token.string, "shadowY") == 0) {
if (!PC_Float_Parse(handle, &cgDC.Assets.shadowY)) {
return qfalse;
}
continue;
}
if (Q_stricmp(token.string, "shadowColor") == 0) {
if (!PC_Color_Parse(handle, &cgDC.Assets.shadowColor)) {
return qfalse;
}
cgDC.Assets.shadowFadeClamp = cgDC.Assets.shadowColor[3];
continue;
}
}
return qfalse; // bk001204 - why not?
}
void CG_ParseMenu(const char *menuFile) {
pc_token_t token;
int handle;
handle = trap_PC_LoadSource(menuFile);
if (!handle)
handle = trap_PC_LoadSource("ui/testhud.menu");
if (!handle)
return;
while ( 1 ) {
if (!trap_PC_ReadToken( handle, &token )) {
break;
}
//if ( Q_stricmp( token, "{" ) ) {
// Com_Printf( "Missing { in menu file\n" );
// break;
//}
//if ( menuCount == MAX_MENUS ) {
// Com_Printf( "Too many menus!\n" );
// break;
//}
if ( token.string[0] == '}' ) {
break;
}
if (Q_stricmp(token.string, "assetGlobalDef") == 0) {
if (CG_Asset_Parse(handle)) {
continue;
} else {
break;
}
}
if (Q_stricmp(token.string, "menudef") == 0) {
// start a new menu
Menu_New(handle);
}
}
trap_PC_FreeSource(handle);
}
qboolean CG_Load_Menu(char **p) {
char *token;
token = COM_ParseExt(p, qtrue);
if (token[0] != '{') {
return qfalse;
}
while ( 1 ) {
token = COM_ParseExt(p, qtrue);
if (Q_stricmp(token, "}") == 0) {
return qtrue;
}
if ( !token || token[0] == 0 ) {
return qfalse;
}
CG_ParseMenu(token);
}
return qfalse;
}
void CG_LoadMenus(const char *menuFile) {
char *token;
char *p;
int len, start;
fileHandle_t f;
static char buf[MAX_MENUDEFFILE];
start = trap_Milliseconds();
len = trap_FS_FOpenFile( menuFile, &f, FS_READ );
if ( !f ) {
trap_Error( va( S_COLOR_YELLOW "menu file not found: %s, using default\n", menuFile ) );
len = trap_FS_FOpenFile( "ui/hud.txt", &f, FS_READ );
if (!f) {
trap_Error( va( S_COLOR_RED "default menu file not found: ui/hud.txt, unable to continue!\n", menuFile ) );
}
}
if ( len >= MAX_MENUDEFFILE ) {
trap_Error( va( S_COLOR_RED "menu file too large: %s is %i, max allowed is %i", menuFile, len, MAX_MENUDEFFILE ) );
trap_FS_FCloseFile( f );
return;
}
trap_FS_Read( buf, len, f );
buf[len] = 0;
trap_FS_FCloseFile( f );
COM_Compress(buf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -