📄 ui_main.c
字号:
}
void UI_Report() {
String_Report();
//Font_Report();
}
void UI_ParseMenu(const char *menuFile) {
int handle;
pc_token_t token;
Com_Printf("Parsing menu file:%s\n", menuFile);
handle = trap_PC_LoadSource(menuFile);
if (!handle) {
return;
}
while ( 1 ) {
memset(&token, 0, sizeof(pc_token_t));
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 (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 Load_Menu(int handle) {
pc_token_t token;
if (!trap_PC_ReadToken(handle, &token))
return qfalse;
if (token.string[0] != '{') {
return qfalse;
}
while ( 1 ) {
if (!trap_PC_ReadToken(handle, &token))
return qfalse;
if ( token.string[0] == 0 ) {
return qfalse;
}
if ( token.string[0] == '}' ) {
return qtrue;
}
UI_ParseMenu(token.string);
}
return qfalse;
}
void UI_LoadMenus(const char *menuFile, qboolean reset) {
pc_token_t token;
int handle;
int start;
start = trap_Milliseconds();
handle = trap_PC_LoadSource( menuFile );
if (!handle) {
trap_Error( va( S_COLOR_YELLOW "menu file not found: %s, using default\n", menuFile ) );
handle = trap_PC_LoadSource( "ui/menus.txt" );
if (!handle) {
trap_Error( va( S_COLOR_RED "default menu file not found: ui/menus.txt, unable to continue!\n", menuFile ) );
}
}
ui_new.integer = 1;
if (reset) {
Menu_Reset();
}
while ( 1 ) {
if (!trap_PC_ReadToken(handle, &token))
break;
if( token.string[0] == 0 || token.string[0] == '}') {
break;
}
if ( token.string[0] == '}' ) {
break;
}
if (Q_stricmp(token.string, "loadmenu") == 0) {
if (Load_Menu(handle)) {
continue;
} else {
break;
}
}
}
Com_Printf("UI menu load time = %d milli seconds\n", trap_Milliseconds() - start);
trap_PC_FreeSource( handle );
}
void UI_Load() {
char lastName[1024];
menuDef_t *menu = Menu_GetFocused();
char *menuSet = UI_Cvar_VariableString("ui_menuFiles");
if (menu && menu->window.name) {
strcpy(lastName, menu->window.name);
}
if (menuSet == NULL || menuSet[0] == '\0') {
menuSet = "ui/menus.txt";
}
String_Init();
#ifdef PRE_RELEASE_TADEMO
UI_ParseGameInfo("demogameinfo.txt");
#else
UI_ParseGameInfo("gameinfo.txt");
UI_LoadArenas();
#endif
UI_LoadMenus(menuSet, qtrue);
Menus_CloseAll();
Menus_ActivateByName(lastName);
}
static const char *handicapValues[] = {"None","95","90","85","80","75","70","65","60","55","50","45","40","35","30","25","20","15","10","5",NULL};
#ifndef MISSIONPACK // bk001206
static int numHandicaps = sizeof(handicapValues) / sizeof(const char*);
#endif
static void UI_DrawHandicap(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
int i, h;
h = Com_Clamp( 5, 100, trap_Cvar_VariableValue("handicap") );
i = 20 - h / 5;
Text_Paint(rect->x, rect->y, scale, color, handicapValues[i], 0, 0, textStyle);
}
static void UI_DrawClanName(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
Text_Paint(rect->x, rect->y, scale, color, UI_Cvar_VariableString("ui_teamName"), 0, 0, textStyle);
}
static void UI_SetCapFragLimits(qboolean uiVars) {
int cap = 5;
int frag = 10;
if (uiInfo.gameTypes[ui_gameType.integer].gtEnum == GT_OBELISK) {
cap = 4;
} else if (uiInfo.gameTypes[ui_gameType.integer].gtEnum == GT_HARVESTER) {
cap = 15;
}
if (uiVars) {
trap_Cvar_Set("ui_captureLimit", va("%d", cap));
trap_Cvar_Set("ui_fragLimit", va("%d", frag));
} else {
trap_Cvar_Set("capturelimit", va("%d", cap));
trap_Cvar_Set("fraglimit", va("%d", frag));
}
}
// ui_gameType assumes gametype 0 is -1 ALL and will not show
static void UI_DrawGameType(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
Text_Paint(rect->x, rect->y, scale, color, uiInfo.gameTypes[ui_gameType.integer].gameType, 0, 0, textStyle);
}
static void UI_DrawNetGameType(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
if (ui_netGameType.integer < 0 || ui_netGameType.integer > uiInfo.numGameTypes) {
trap_Cvar_Set("ui_netGameType", "0");
trap_Cvar_Set("ui_actualNetGameType", "0");
}
Text_Paint(rect->x, rect->y, scale, color, uiInfo.gameTypes[ui_netGameType.integer].gameType , 0, 0, textStyle);
}
static void UI_DrawJoinGameType(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
if (ui_joinGameType.integer < 0 || ui_joinGameType.integer > uiInfo.numJoinGameTypes) {
trap_Cvar_Set("ui_joinGameType", "0");
}
Text_Paint(rect->x, rect->y, scale, color, uiInfo.joinGameTypes[ui_joinGameType.integer].gameType , 0, 0, textStyle);
}
static int UI_TeamIndexFromName(const char *name) {
int i;
if (name && *name) {
for (i = 0; i < uiInfo.teamCount; i++) {
if (Q_stricmp(name, uiInfo.teamList[i].teamName) == 0) {
return i;
}
}
}
return 0;
}
static void UI_DrawClanLogo(rectDef_t *rect, float scale, vec4_t color) {
int i;
i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
if (i >= 0 && i < uiInfo.teamCount) {
trap_R_SetColor( color );
if (uiInfo.teamList[i].teamIcon == -1) {
uiInfo.teamList[i].teamIcon = trap_R_RegisterShaderNoMip(uiInfo.teamList[i].imageName);
uiInfo.teamList[i].teamIcon_Metal = trap_R_RegisterShaderNoMip(va("%s_metal",uiInfo.teamList[i].imageName));
uiInfo.teamList[i].teamIcon_Name = trap_R_RegisterShaderNoMip(va("%s_name", uiInfo.teamList[i].imageName));
}
UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.teamList[i].teamIcon);
trap_R_SetColor(NULL);
}
}
static void UI_DrawClanCinematic(rectDef_t *rect, float scale, vec4_t color) {
int i;
i = UI_TeamIndexFromName(UI_Cvar_VariableString("ui_teamName"));
if (i >= 0 && i < uiInfo.teamCount) {
if (uiInfo.teamList[i].cinematic >= -2) {
if (uiInfo.teamList[i].cinematic == -1) {
uiInfo.teamList[i].cinematic = trap_CIN_PlayCinematic(va("%s.roq", uiInfo.teamList[i].imageName), 0, 0, 0, 0, (CIN_loop | CIN_silent) );
}
if (uiInfo.teamList[i].cinematic >= 0) {
trap_CIN_RunCinematic(uiInfo.teamList[i].cinematic);
trap_CIN_SetExtents(uiInfo.teamList[i].cinematic, rect->x, rect->y, rect->w, rect->h);
trap_CIN_DrawCinematic(uiInfo.teamList[i].cinematic);
} else {
trap_R_SetColor( color );
UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.teamList[i].teamIcon_Metal);
trap_R_SetColor(NULL);
uiInfo.teamList[i].cinematic = -2;
}
} else {
trap_R_SetColor( color );
UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.teamList[i].teamIcon);
trap_R_SetColor(NULL);
}
}
}
static void UI_DrawPreviewCinematic(rectDef_t *rect, float scale, vec4_t color) {
if (uiInfo.previewMovie > -2) {
uiInfo.previewMovie = trap_CIN_PlayCinematic(va("%s.roq", uiInfo.movieList[uiInfo.movieIndex]), 0, 0, 0, 0, (CIN_loop | CIN_silent) );
if (uiInfo.previewMovie >= 0) {
trap_CIN_RunCinematic(uiInfo.previewMovie);
trap_CIN_SetExtents(uiInfo.previewMovie, rect->x, rect->y, rect->w, rect->h);
trap_CIN_DrawCinematic(uiInfo.previewMovie);
} else {
uiInfo.previewMovie = -2;
}
}
}
static void UI_DrawSkill(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
int i;
i = trap_Cvar_VariableValue( "g_spSkill" );
if (i < 1 || i > numSkillLevels) {
i = 1;
}
Text_Paint(rect->x, rect->y, scale, color, skillLevels[i-1],0, 0, textStyle);
}
static void UI_DrawTeamName(rectDef_t *rect, float scale, vec4_t color, qboolean blue, int textStyle) {
int i;
i = UI_TeamIndexFromName(UI_Cvar_VariableString((blue) ? "ui_blueTeam" : "ui_redTeam"));
if (i >= 0 && i < uiInfo.teamCount) {
Text_Paint(rect->x, rect->y, scale, color, va("%s: %s", (blue) ? "Blue" : "Red", uiInfo.teamList[i].teamName),0, 0, textStyle);
}
}
static void UI_DrawTeamMember(rectDef_t *rect, float scale, vec4_t color, qboolean blue, int num, int textStyle) {
// 0 - None
// 1 - Human
// 2..NumCharacters - Bot
int value = trap_Cvar_VariableValue(va(blue ? "ui_blueteam%i" : "ui_redteam%i", num));
const char *text;
if (value <= 0) {
text = "Closed";
} else if (value == 1) {
text = "Human";
} else {
value -= 2;
if (ui_actualNetGameType.integer >= GT_TEAM) {
if (value >= uiInfo.characterCount) {
value = 0;
}
text = uiInfo.characterList[value].name;
} else {
if (value >= UI_GetNumBots()) {
value = 0;
}
text = UI_GetBotNameByNumber(value);
}
}
Text_Paint(rect->x, rect->y, scale, color, text, 0, 0, textStyle);
}
static void UI_DrawEffects(rectDef_t *rect, float scale, vec4_t color) {
UI_DrawHandlePic( rect->x, rect->y - 14, 128, 8, uiInfo.uiDC.Assets.fxBasePic );
UI_DrawHandlePic( rect->x + uiInfo.effectsColor * 16 + 8, rect->y - 16, 16, 12, uiInfo.uiDC.Assets.fxPic[uiInfo.effectsColor] );
}
static void UI_DrawMapPreview(rectDef_t *rect, float scale, vec4_t color, qboolean net) {
int map = (net) ? ui_currentNetMap.integer : ui_currentMap.integer;
if (map < 0 || map > uiInfo.mapCount) {
if (net) {
ui_currentNetMap.integer = 0;
trap_Cvar_Set("ui_currentNetMap", "0");
} else {
ui_currentMap.integer = 0;
trap_Cvar_Set("ui_currentMap", "0");
}
map = 0;
}
if (uiInfo.mapList[map].levelShot == -1) {
uiInfo.mapList[map].levelShot = trap_R_RegisterShaderNoMip(uiInfo.mapList[map].imageName);
}
if (uiInfo.mapList[map].levelShot > 0) {
UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, uiInfo.mapList[map].levelShot);
} else {
UI_DrawHandlePic( rect->x, rect->y, rect->w, rect->h, trap_R_RegisterShaderNoMip("menu/art/unknownmap"));
}
}
static void UI_DrawMapTimeToBeat(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
int minutes, seconds, time;
if (ui_currentMap.integer < 0 || ui_currentMap.integer > uiInfo.mapCount) {
ui_currentMap.integer = 0;
trap_Cvar_Set("ui_currentMap", "0");
}
time = uiInfo.mapList[ui_currentMap.integer].timeToBeat[uiInfo.gameTypes[ui_gameType.integer].gtEnum];
minutes = time / 60;
seconds = time % 60;
Text_Paint(rect->x, rect->y, scale, color, va("%02i:%02i", minutes, seconds), 0, 0, textStyle);
}
static void UI_DrawMapCinematic(rectDef_t *rect, float scale, vec4_t color, qboolean net) {
int map = (net) ? ui_currentNetMap.integer : ui_currentMap.integer;
if (map < 0 || map > uiInfo.mapCount) {
if (net) {
ui_currentNetMap.integer = 0;
trap_Cvar_Set("ui_currentNetMap", "0");
} else {
ui_currentMap.integer = 0;
trap_Cvar_Set("ui_currentMap", "0");
}
map = 0;
}
if (uiInfo.mapList[map].cinematic >= -1) {
if (uiInfo.mapList[map].cinematic == -1) {
uiInfo.mapList[map].cinematic = trap_CIN_PlayCinematic(va("%s.roq", uiInfo.mapList[map].mapLoadName), 0, 0, 0, 0, (CIN_loop | CIN_silent) );
}
if (uiInfo.mapList[map].cinematic >= 0) {
trap_CIN_RunCinematic(uiInfo.mapList[map].cinematic);
trap_CIN_SetExtents(uiInfo.mapList[map].cinematic, rect->x, rect->y, rect->w, rect->h);
trap_CIN_DrawCinematic(uiInfo.mapList[map].cinematic);
} else {
uiInfo.mapList[map].cinematic = -2;
}
} else {
UI_DrawMapPreview(rect, scale, color, net);
}
}
static qboolean updateModel = qtrue;
static qboolean q3Model = qfalse;
static void UI_DrawPlayerModel(rectDef_t *rect) {
static playerInfo_t info;
char model[MAX_QPATH];
char team[256];
char head[256];
vec3_t viewangles;
vec3_t moveangles;
if (trap_Cvar_VariableValue("ui_Q3Model")) {
strcpy(model, UI_Cvar_VariableString("model"));
strcpy(head, UI_Cvar_VariableString("headmodel"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -