📄 ui_main.c
字号:
}
s = va("Source: %s", netSources[ui_netSource.integer]);
break;
case UI_NETFILTER:
if (ui_serverFilterType.integer < 0 || ui_serverFilterType.integer > numServerFilters) {
ui_serverFilterType.integer = 0;
}
s = va("Filter: %s", serverFilters[ui_serverFilterType.integer].description );
break;
case UI_TIER:
break;
case UI_TIER_MAPNAME:
break;
case UI_TIER_GAMETYPE:
break;
case UI_ALLMAPS_SELECTION:
break;
case UI_OPPONENT_NAME:
break;
case UI_KEYBINDSTATUS:
if (Display_KeyBindPending()) {
s = "Waiting for new key... Press ESCAPE to cancel";
} else {
s = "Press ENTER or CLICK to change, Press BACKSPACE to clear";
}
break;
case UI_SERVERREFRESHDATE:
s = UI_Cvar_VariableString(va("ui_lastServerRefresh_%i", ui_netSource.integer));
break;
default:
break;
}
if (s) {
return Text_Width(s, scale, 0);
}
return 0;
}
static void UI_DrawBotName(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
int value = uiInfo.botIndex;
int game = trap_Cvar_VariableValue("g_gametype");
const char *text = "";
if (game >= 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_DrawBotSkill(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
if (uiInfo.skillIndex >= 0 && uiInfo.skillIndex < numSkillLevels) {
Text_Paint(rect->x, rect->y, scale, color, skillLevels[uiInfo.skillIndex], 0, 0, textStyle);
}
}
static void UI_DrawRedBlue(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
Text_Paint(rect->x, rect->y, scale, color, (uiInfo.redBlue == 0) ? "Red" : "Blue", 0, 0, textStyle);
}
static void UI_DrawCrosshair(rectDef_t *rect, float scale, vec4_t color) {
trap_R_SetColor( color );
if (uiInfo.currentCrosshair < 0 || uiInfo.currentCrosshair >= NUM_CROSSHAIRS) {
uiInfo.currentCrosshair = 0;
}
UI_DrawHandlePic( rect->x, rect->y - rect->h, rect->w, rect->h, uiInfo.uiDC.Assets.crosshairShader[uiInfo.currentCrosshair]);
trap_R_SetColor( NULL );
}
/*
===============
UI_BuildPlayerList
===============
*/
static void UI_BuildPlayerList() {
uiClientState_t cs;
int n, count, team, team2, playerTeamNumber;
char info[MAX_INFO_STRING];
trap_GetClientState( &cs );
trap_GetConfigString( CS_PLAYERS + cs.clientNum, info, MAX_INFO_STRING );
uiInfo.playerNumber = cs.clientNum;
uiInfo.teamLeader = atoi(Info_ValueForKey(info, "tl"));
team = atoi(Info_ValueForKey(info, "t"));
trap_GetConfigString( CS_SERVERINFO, info, sizeof(info) );
count = atoi( Info_ValueForKey( info, "sv_maxclients" ) );
uiInfo.playerCount = 0;
uiInfo.myTeamCount = 0;
playerTeamNumber = 0;
for( n = 0; n < count; n++ ) {
trap_GetConfigString( CS_PLAYERS + n, info, MAX_INFO_STRING );
if (info[0]) {
Q_strncpyz( uiInfo.playerNames[uiInfo.playerCount], Info_ValueForKey( info, "n" ), MAX_NAME_LENGTH );
Q_CleanStr( uiInfo.playerNames[uiInfo.playerCount] );
uiInfo.playerCount++;
team2 = atoi(Info_ValueForKey(info, "t"));
if (team2 == team) {
Q_strncpyz( uiInfo.teamNames[uiInfo.myTeamCount], Info_ValueForKey( info, "n" ), MAX_NAME_LENGTH );
Q_CleanStr( uiInfo.teamNames[uiInfo.myTeamCount] );
uiInfo.teamClientNums[uiInfo.myTeamCount] = n;
if (uiInfo.playerNumber == n) {
playerTeamNumber = uiInfo.myTeamCount;
}
uiInfo.myTeamCount++;
}
}
}
if (!uiInfo.teamLeader) {
trap_Cvar_Set("cg_selectedPlayer", va("%d", playerTeamNumber));
}
n = trap_Cvar_VariableValue("cg_selectedPlayer");
if (n < 0 || n > uiInfo.myTeamCount) {
n = 0;
}
if (n < uiInfo.myTeamCount) {
trap_Cvar_Set("cg_selectedPlayerName", uiInfo.teamNames[n]);
}
}
static void UI_DrawSelectedPlayer(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
if (uiInfo.uiDC.realTime > uiInfo.playerRefresh) {
uiInfo.playerRefresh = uiInfo.uiDC.realTime + 3000;
UI_BuildPlayerList();
}
Text_Paint(rect->x, rect->y, scale, color, (uiInfo.teamLeader) ? UI_Cvar_VariableString("cg_selectedPlayerName") : UI_Cvar_VariableString("name") , 0, 0, textStyle);
}
static void UI_DrawServerRefreshDate(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
if (uiInfo.serverStatus.refreshActive) {
vec4_t lowLight, newColor;
lowLight[0] = 0.8 * color[0];
lowLight[1] = 0.8 * color[1];
lowLight[2] = 0.8 * color[2];
lowLight[3] = 0.8 * color[3];
LerpColor(color,lowLight,newColor,0.5+0.5*sin(uiInfo.uiDC.realTime / PULSE_DIVISOR));
Text_Paint(rect->x, rect->y, scale, newColor, va("Getting info for %d servers (ESC to cancel)", trap_LAN_GetServerCount(ui_netSource.integer)), 0, 0, textStyle);
} else {
char buff[64];
Q_strncpyz(buff, UI_Cvar_VariableString(va("ui_lastServerRefresh_%i", ui_netSource.integer)), 64);
Text_Paint(rect->x, rect->y, scale, color, va("Refresh Time: %s", buff), 0, 0, textStyle);
}
}
static void UI_DrawServerMOTD(rectDef_t *rect, float scale, vec4_t color) {
if (uiInfo.serverStatus.motdLen) {
float maxX;
if (uiInfo.serverStatus.motdWidth == -1) {
uiInfo.serverStatus.motdWidth = 0;
uiInfo.serverStatus.motdPaintX = rect->x + 1;
uiInfo.serverStatus.motdPaintX2 = -1;
}
if (uiInfo.serverStatus.motdOffset > uiInfo.serverStatus.motdLen) {
uiInfo.serverStatus.motdOffset = 0;
uiInfo.serverStatus.motdPaintX = rect->x + 1;
uiInfo.serverStatus.motdPaintX2 = -1;
}
if (uiInfo.uiDC.realTime > uiInfo.serverStatus.motdTime) {
uiInfo.serverStatus.motdTime = uiInfo.uiDC.realTime + 10;
if (uiInfo.serverStatus.motdPaintX <= rect->x + 2) {
if (uiInfo.serverStatus.motdOffset < uiInfo.serverStatus.motdLen) {
uiInfo.serverStatus.motdPaintX += Text_Width(&uiInfo.serverStatus.motd[uiInfo.serverStatus.motdOffset], scale, 1) - 1;
uiInfo.serverStatus.motdOffset++;
} else {
uiInfo.serverStatus.motdOffset = 0;
if (uiInfo.serverStatus.motdPaintX2 >= 0) {
uiInfo.serverStatus.motdPaintX = uiInfo.serverStatus.motdPaintX2;
} else {
uiInfo.serverStatus.motdPaintX = rect->x + rect->w - 2;
}
uiInfo.serverStatus.motdPaintX2 = -1;
}
} else {
//serverStatus.motdPaintX--;
uiInfo.serverStatus.motdPaintX -= 2;
if (uiInfo.serverStatus.motdPaintX2 >= 0) {
//serverStatus.motdPaintX2--;
uiInfo.serverStatus.motdPaintX2 -= 2;
}
}
}
maxX = rect->x + rect->w - 2;
Text_Paint_Limit(&maxX, uiInfo.serverStatus.motdPaintX, rect->y + rect->h - 3, scale, color, &uiInfo.serverStatus.motd[uiInfo.serverStatus.motdOffset], 0, 0);
if (uiInfo.serverStatus.motdPaintX2 >= 0) {
float maxX2 = rect->x + rect->w - 2;
Text_Paint_Limit(&maxX2, uiInfo.serverStatus.motdPaintX2, rect->y + rect->h - 3, scale, color, uiInfo.serverStatus.motd, 0, uiInfo.serverStatus.motdOffset);
}
if (uiInfo.serverStatus.motdOffset && maxX > 0) {
// if we have an offset ( we are skipping the first part of the string ) and we fit the string
if (uiInfo.serverStatus.motdPaintX2 == -1) {
uiInfo.serverStatus.motdPaintX2 = rect->x + rect->w - 2;
}
} else {
uiInfo.serverStatus.motdPaintX2 = -1;
}
}
}
static void UI_DrawKeyBindStatus(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
// int ofs = 0; TTimo: unused
if (Display_KeyBindPending()) {
Text_Paint(rect->x, rect->y, scale, color, "Waiting for new key... Press ESCAPE to cancel", 0, 0, textStyle);
} else {
Text_Paint(rect->x, rect->y, scale, color, "Press ENTER or CLICK to change, Press BACKSPACE to clear", 0, 0, textStyle);
}
}
static void UI_DrawGLInfo(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
char * eptr;
char buff[1024];
const char *lines[64];
int y, numLines, i;
Text_Paint(rect->x + 2, rect->y, scale, color, va("VENDOR: %s", uiInfo.uiDC.glconfig.vendor_string), 0, 30, textStyle);
Text_Paint(rect->x + 2, rect->y + 15, scale, color, va("VERSION: %s: %s", uiInfo.uiDC.glconfig.version_string,uiInfo.uiDC.glconfig.renderer_string), 0, 30, textStyle);
Text_Paint(rect->x + 2, rect->y + 30, scale, color, va ("PIXELFORMAT: color(%d-bits) Z(%d-bits) stencil(%d-bits)", uiInfo.uiDC.glconfig.colorBits, uiInfo.uiDC.glconfig.depthBits, uiInfo.uiDC.glconfig.stencilBits), 0, 30, textStyle);
// build null terminated extension strings
// TTimo: https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=399
// in TA this was not directly crashing, but displaying a nasty broken shader right in the middle
// brought down the string size to 1024, there's not much that can be shown on the screen anyway
Q_strncpyz(buff, uiInfo.uiDC.glconfig.extensions_string, 1024);
eptr = buff;
y = rect->y + 45;
numLines = 0;
while ( y < rect->y + rect->h && *eptr )
{
while ( *eptr && *eptr == ' ' )
*eptr++ = '\0';
// track start of valid string
if (*eptr && *eptr != ' ') {
lines[numLines++] = eptr;
}
while ( *eptr && *eptr != ' ' )
eptr++;
}
i = 0;
while (i < numLines) {
Text_Paint(rect->x + 2, y, scale, color, lines[i++], 0, 20, textStyle);
if (i < numLines) {
Text_Paint(rect->x + rect->w / 2, y, scale, color, lines[i++], 0, 20, textStyle);
}
y += 10;
if (y > rect->y + rect->h - 11) {
break;
}
}
}
// FIXME: table drive
//
static void UI_OwnerDraw(float x, float y, float w, float h, float text_x, float text_y, int ownerDraw, int ownerDrawFlags, int align, float special, float scale, vec4_t color, qhandle_t shader, int textStyle) {
rectDef_t rect;
rect.x = x + text_x;
rect.y = y + text_y;
rect.w = w;
rect.h = h;
switch (ownerDraw) {
case UI_HANDICAP:
UI_DrawHandicap(&rect, scale, color, textStyle);
break;
case UI_EFFECTS:
UI_DrawEffects(&rect, scale, color);
break;
case UI_PLAYERMODEL:
UI_DrawPlayerModel(&rect);
break;
case UI_CLANNAME:
UI_DrawClanName(&rect, scale, color, textStyle);
break;
case UI_CLANLOGO:
UI_DrawClanLogo(&rect, scale, color);
break;
case UI_CLANCINEMATIC:
UI_DrawClanCinematic(&rect, scale, color);
break;
case UI_PREVIEWCINEMATIC:
UI_DrawPreviewCinematic(&rect, scale, color);
break;
case UI_GAMETYPE:
UI_DrawGameType(&rect, scale, color, textStyle);
break;
case UI_NETGAMETYPE:
UI_DrawNetGameType(&rect, scale, color, textStyle);
break;
case UI_JOINGAMETYPE:
UI_DrawJoinGameType(&rect, scale, color, textStyle);
break;
case UI_MAPPREVIEW:
UI_DrawMapPreview(&rect, scale, color, qtrue);
break;
case UI_MAP_TIMETOBEAT:
UI_DrawMapTimeToBeat(&rect, scale, color, textStyle);
break;
case UI_MAPCINEMATIC:
UI_DrawMapCinematic(&rect, scale, color, qfalse);
break;
case UI_STARTMAPCINEMATIC:
UI_DrawMapCinematic(&rect, scale, color, qtrue);
break;
case UI_SKILL:
UI_DrawSkill(&rect, scale, color, textStyle);
break;
case UI_BLUETEAMNAME:
UI_DrawTeamName(&rect, scale, color, qtrue, textStyle);
break;
case UI_REDTEAMNAME:
UI_DrawTeamName(&rect, scale, color, qfalse, textStyle);
break;
case UI_BLUETEAM1:
case UI_BLUETEAM2:
case UI_BLUETEAM3:
case UI_BLUETEAM4:
case UI_BLUETEAM5:
UI_DrawTeamMember(&rect, scale, color, qtrue, ownerDraw - UI_BLUETEAM1 + 1, textStyle);
break;
case UI_REDTEAM1:
case UI_REDTEAM2:
case UI_REDTEAM3:
case UI_REDTEAM4:
case UI_REDTEAM5:
UI_DrawTeamMember(&rect, scale, color, qfalse, ownerDraw - UI_REDTEAM1 + 1, textStyle);
break;
case UI_NETSOURCE:
UI_DrawNetSource(&rect, scale, color, textStyle);
break;
case UI_NETMAPPREVIEW:
UI_DrawNetMapPreview(&rect, scale, color);
break;
case UI_NETMAPCINEMATIC:
UI_DrawNetMapCinematic(&rect, scale, color);
break;
case UI_NETFILTER:
UI_DrawNetFilter(&rect, scale, color, textStyle);
break;
case UI_TIER:
UI_DrawTier(&rect, scale, color, textStyle);
break;
case UI_OPPONENTMODEL:
UI_DrawOpponent(&rect);
break;
case UI_TIERMAP1:
UI_DrawTierMap(&rect, 0);
break;
case UI_TIERMAP2:
UI_DrawTierMap(&rect, 1);
break;
case UI_TIERMAP3:
UI_DrawTierMap(&rect, 2);
break;
case UI_PLAYERLOGO:
UI_DrawPlayerLogo(&rect, color);
break;
case UI_PLAYERLOGO_METAL:
UI_DrawPlayerLogoMetal(&rect, color);
break;
case UI_PLAYERLOGO_NAME:
UI_DrawPlayerLogoName(&rect, color);
break;
case UI_OPPONENTLOGO:
UI_DrawOpponentLogo(&rect, color);
break;
case UI_OPPONENTLOGO_METAL:
UI_DrawOpponentLogoMetal(&rect, color);
break;
case UI_OPPONENTLOGO_NAME:
UI_DrawOpponentLogoName(&rect, color);
break;
case UI_TIER_MAPNAME:
UI_DrawTierMapName(&rect, scale, color, textStyle);
break;
case UI_TIER_GAMETYPE:
UI_DrawTierGameType(&rect, scale, color, textStyle);
break;
case UI_ALLMAPS_SELECTION:
UI_DrawAllMapsSelection(&rect, scale, color, textStyle, qtrue);
break;
case UI_MAPS_SELECTION:
UI_DrawAllMapsSelection(&rect, scale, color, textStyle, qfalse);
break;
case UI_OPPONENT_NAME:
UI_DrawOpponentName(&rect, scale, color, textStyle);
break;
case UI_BOTNAME:
UI_DrawBotName(&rect, scale, color, textStyle);
break;
case UI_BOTSKILL:
UI_DrawBotSkill(&rect, scale, color, textStyle);
break;
case UI_REDBLUE:
UI_DrawRedBlue(&rect, scale, color, textStyle);
break;
case UI_CROSSHAIR:
UI_DrawCrosshair(&rect, scale, color);
break;
case UI_SELECTEDPLAYER:
UI_DrawSelectedPlayer(&rect, scale, color, textStyle);
break;
case UI_SERVERREFRESHDATE:
UI_DrawServerRefreshDate(&rect, scale, color, textStyle);
break;
case UI_SERVERMOTD:
UI_DrawServer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -