📄 ui_atoms.c
字号:
}
/*
=================
UI_DrawString2
=================
*/
static void UI_DrawString2( int x, int y, const char* str, vec4_t color, int charw, int charh )
{
const char* s;
char ch;
int forceColor = qfalse; //APSFIXME;
vec4_t tempcolor;
float ax;
float ay;
float aw;
float ah;
float frow;
float fcol;
if (y < -charh)
// offscreen
return;
// draw the colored text
trap_R_SetColor( color );
ax = x * uis.scale + uis.bias;
ay = y * uis.scale;
aw = charw * uis.scale;
ah = charh * uis.scale;
s = str;
while ( *s )
{
if ( Q_IsColorString( s ) )
{
if ( !forceColor )
{
memcpy( tempcolor, g_color_table[ColorIndex(s[1])], sizeof( tempcolor ) );
tempcolor[3] = color[3];
trap_R_SetColor( tempcolor );
}
s += 2;
continue;
}
ch = *s & 255;
if (ch != ' ')
{
frow = (ch>>4)*0.0625;
fcol = (ch&15)*0.0625;
trap_R_DrawStretchPic( ax, ay, aw, ah, fcol, frow, fcol + 0.0625, frow + 0.0625, uis.charset );
}
ax += aw;
s++;
}
trap_R_SetColor( NULL );
}
/*
=================
UI_DrawString
=================
*/
void UI_DrawString( int x, int y, const char* str, int style, vec4_t color )
{
int len;
int charw;
int charh;
vec4_t newcolor;
vec4_t lowlight;
float *drawcolor;
vec4_t dropcolor;
if( !str ) {
return;
}
if ((style & UI_BLINK) && ((uis.realtime/BLINK_DIVISOR) & 1))
return;
if (style & UI_SMALLFONT)
{
charw = SMALLCHAR_WIDTH;
charh = SMALLCHAR_HEIGHT;
}
else if (style & UI_GIANTFONT)
{
charw = GIANTCHAR_WIDTH;
charh = GIANTCHAR_HEIGHT;
}
else
{
charw = BIGCHAR_WIDTH;
charh = BIGCHAR_HEIGHT;
}
if (style & UI_PULSE)
{
lowlight[0] = 0.8*color[0];
lowlight[1] = 0.8*color[1];
lowlight[2] = 0.8*color[2];
lowlight[3] = 0.8*color[3];
UI_LerpColor(color,lowlight,newcolor,0.5+0.5*sin(uis.realtime/PULSE_DIVISOR));
drawcolor = newcolor;
}
else
drawcolor = color;
switch (style & UI_FORMATMASK)
{
case UI_CENTER:
// center justify at x
len = strlen(str);
x = x - len*charw/2;
break;
case UI_RIGHT:
// right justify at x
len = strlen(str);
x = x - len*charw;
break;
default:
// left justify at x
break;
}
if ( style & UI_DROPSHADOW )
{
dropcolor[0] = dropcolor[1] = dropcolor[2] = 0;
dropcolor[3] = drawcolor[3];
UI_DrawString2(x+2,y+2,str,dropcolor,charw,charh);
}
UI_DrawString2(x,y,str,drawcolor,charw,charh);
}
/*
=================
UI_DrawChar
=================
*/
void UI_DrawChar( int x, int y, int ch, int style, vec4_t color )
{
char buff[2];
buff[0] = ch;
buff[1] = '\0';
UI_DrawString( x, y, buff, style, color );
}
qboolean UI_IsFullscreen( void ) {
if ( uis.activemenu && ( trap_Key_GetCatcher() & KEYCATCH_UI ) ) {
return uis.activemenu->fullscreen;
}
return qfalse;
}
static void NeedCDAction( qboolean result ) {
if ( !result ) {
trap_Cmd_ExecuteText( EXEC_APPEND, "quit\n" );
}
}
static void NeedCDKeyAction( qboolean result ) {
if ( !result ) {
trap_Cmd_ExecuteText( EXEC_APPEND, "quit\n" );
}
}
void UI_SetActiveMenu( uiMenuCommand_t menu ) {
// this should be the ONLY way the menu system is brought up
// enusure minumum menu data is cached
Menu_Cache();
switch ( menu ) {
case UIMENU_NONE:
UI_ForceMenuOff();
return;
case UIMENU_MAIN:
UI_MainMenu();
return;
case UIMENU_NEED_CD:
UI_ConfirmMenu( "Insert the CD", (voidfunc_f)NULL, NeedCDAction );
return;
case UIMENU_BAD_CD_KEY:
UI_ConfirmMenu( "Bad CD Key", (voidfunc_f)NULL, NeedCDKeyAction );
return;
case UIMENU_INGAME:
/*
//GRank
UI_RankingsMenu();
return;
*/
trap_Cvar_Set( "cl_paused", "1" );
UI_InGameMenu();
return;
// bk001204
case UIMENU_TEAM:
case UIMENU_POSTGAME:
default:
#ifndef NDEBUG
Com_Printf("UI_SetActiveMenu: bad enum %d\n", menu );
#endif
break;
}
}
/*
=================
UI_KeyEvent
=================
*/
void UI_KeyEvent( int key, int down ) {
sfxHandle_t s;
if (!uis.activemenu) {
return;
}
if (!down) {
return;
}
if (uis.activemenu->key)
s = uis.activemenu->key( key );
else
s = Menu_DefaultKey( uis.activemenu, key );
if ((s > 0) && (s != menu_null_sound))
trap_S_StartLocalSound( s, CHAN_LOCAL_SOUND );
}
/*
=================
UI_MouseEvent
=================
*/
void UI_MouseEvent( int dx, int dy )
{
int i;
menucommon_s* m;
if (!uis.activemenu)
return;
// update mouse screen position
uis.cursorx += dx;
if (uis.cursorx < 0)
uis.cursorx = 0;
else if (uis.cursorx > SCREEN_WIDTH)
uis.cursorx = SCREEN_WIDTH;
uis.cursory += dy;
if (uis.cursory < 0)
uis.cursory = 0;
else if (uis.cursory > SCREEN_HEIGHT)
uis.cursory = SCREEN_HEIGHT;
// region test the active menu items
for (i=0; i<uis.activemenu->nitems; i++)
{
m = (menucommon_s*)uis.activemenu->items[i];
if (m->flags & (QMF_GRAYED|QMF_INACTIVE))
continue;
if ((uis.cursorx < m->left) ||
(uis.cursorx > m->right) ||
(uis.cursory < m->top) ||
(uis.cursory > m->bottom))
{
// cursor out of item bounds
continue;
}
// set focus to item at cursor
if (uis.activemenu->cursor != i)
{
Menu_SetCursor( uis.activemenu, i );
((menucommon_s*)(uis.activemenu->items[uis.activemenu->cursor_prev]))->flags &= ~QMF_HASMOUSEFOCUS;
if ( !(((menucommon_s*)(uis.activemenu->items[uis.activemenu->cursor]))->flags & QMF_SILENT ) ) {
trap_S_StartLocalSound( menu_move_sound, CHAN_LOCAL_SOUND );
}
}
((menucommon_s*)(uis.activemenu->items[uis.activemenu->cursor]))->flags |= QMF_HASMOUSEFOCUS;
return;
}
if (uis.activemenu->nitems > 0) {
// out of any region
((menucommon_s*)(uis.activemenu->items[uis.activemenu->cursor]))->flags &= ~QMF_HASMOUSEFOCUS;
}
}
char *UI_Argv( int arg ) {
static char buffer[MAX_STRING_CHARS];
trap_Argv( arg, buffer, sizeof( buffer ) );
return buffer;
}
char *UI_Cvar_VariableString( const char *var_name ) {
static char buffer[MAX_STRING_CHARS];
trap_Cvar_VariableStringBuffer( var_name, buffer, sizeof( buffer ) );
return buffer;
}
/*
=================
UI_Cache
=================
*/
void UI_Cache_f( void ) {
MainMenu_Cache();
InGame_Cache();
ConfirmMenu_Cache();
PlayerModel_Cache();
PlayerSettings_Cache();
Controls_Cache();
Demos_Cache();
UI_CinematicsMenu_Cache();
Preferences_Cache();
ServerInfo_Cache();
SpecifyServer_Cache();
ArenaServers_Cache();
StartServer_Cache();
ServerOptions_Cache();
DriverInfo_Cache();
GraphicsOptions_Cache();
UI_DisplayOptionsMenu_Cache();
UI_SoundOptionsMenu_Cache();
UI_NetworkOptionsMenu_Cache();
UI_SPLevelMenu_Cache();
UI_SPSkillMenu_Cache();
UI_SPPostgameMenu_Cache();
TeamMain_Cache();
UI_AddBots_Cache();
UI_RemoveBots_Cache();
UI_SetupMenu_Cache();
// UI_LoadConfig_Cache();
// UI_SaveConfigMenu_Cache();
UI_BotSelectMenu_Cache();
UI_CDKeyMenu_Cache();
UI_ModsMenu_Cache();
}
/*
=================
UI_ConsoleCommand
=================
*/
qboolean UI_ConsoleCommand( int realTime ) {
char *cmd;
cmd = UI_Argv( 0 );
// ensure minimum menu data is available
Menu_Cache();
if ( Q_stricmp (cmd, "levelselect") == 0 ) {
UI_SPLevelMenu_f();
return qtrue;
}
if ( Q_stricmp (cmd, "postgame") == 0 ) {
UI_SPPostgameMenu_f();
return qtrue;
}
if ( Q_stricmp (cmd, "ui_cache") == 0 ) {
UI_Cache_f();
return qtrue;
}
if ( Q_stricmp (cmd, "ui_cinematics") == 0 ) {
UI_CinematicsMenu_f();
return qtrue;
}
if ( Q_stricmp (cmd, "ui_teamOrders") == 0 ) {
UI_TeamOrdersMenu_f();
return qtrue;
}
if ( Q_stricmp (cmd, "iamacheater") == 0 ) {
UI_SPUnlock_f();
return qtrue;
}
if ( Q_stricmp (cmd, "iamamonkey") == 0 ) {
UI_SPUnlockMedals_f();
return qtrue;
}
if ( Q_stricmp (cmd, "ui_cdkey") == 0 ) {
UI_CDKeyMenu_f();
return qtrue;
}
return qfalse;
}
/*
=================
UI_Shutdown
=================
*/
void UI_Shutdown( void ) {
}
/*
=================
UI_Init
=================
*/
void UI_Init( void ) {
UI_RegisterCvars();
UI_InitGameinfo();
// cache redundant calulations
trap_GetGlconfig( &uis.glconfig );
// for 640x480 virtualized screen
uis.scale = uis.glconfig.vidHeight * (1.0/480.0);
if ( uis.glconfig.vidWidth * 480 > uis.glconfig.vidHeight * 640 ) {
// wide screen
uis.bias = 0.5 * ( uis.glconfig.vidWidth - ( uis.glconfig.vidHeight * (640.0/480.0) ) );
}
else {
// no wide screen
uis.bias = 0;
}
// initialize the menu system
Menu_Cache();
uis.activemenu = NULL;
uis.menusp = 0;
}
/*
================
UI_AdjustFrom640
Adjusted for resolution and screen aspect ratio
================
*/
void UI_AdjustFrom640( float *x, float *y, float *w, float *h ) {
// expect valid pointers
*x = *x * uis.scale + uis.bias;
*y *= uis.scale;
*w *= uis.scale;
*h *= uis.scale;
}
void UI_DrawNamedPic( float x, float y, float width, float height, const char *picname ) {
qhandle_t hShader;
hShader = trap_R_RegisterShaderNoMip( picname );
UI_AdjustFrom640( &x, &y, &width, &height );
trap_R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, hShader );
}
void UI_DrawHandlePic( float x, float y, float w, float h, qhandle_t hShader ) {
float s0;
float s1;
float t0;
float t1;
if( w < 0 ) { // flip about vertical
w = -w;
s0 = 1;
s1 = 0;
}
else {
s0 = 0;
s1 = 1;
}
if( h < 0 ) { // flip about horizontal
h = -h;
t0 = 1;
t1 = 0;
}
else {
t0 = 0;
t1 = 1;
}
UI_AdjustFrom640( &x, &y, &w, &h );
trap_R_DrawStretchPic( x, y, w, h, s0, t0, s1, t1, hShader );
}
/*
================
UI_FillRect
Coordinates are 640*480 virtual values
=================
*/
void UI_FillRect( float x, float y, float width, float height, const float *color ) {
trap_R_SetColor( color );
UI_AdjustFrom640( &x, &y, &width, &height );
trap_R_DrawStretchPic( x, y, width, height, 0, 0, 0, 0, uis.whiteShader );
trap_R_SetColor( NULL );
}
/*
================
UI_DrawRect
Coordinates are 640*480 virtual values
=================
*/
void UI_DrawRect( float x, float y, float width, float height, const float *color ) {
trap_R_SetColor( color );
UI_AdjustFrom640( &x, &y, &width, &height );
trap_R_DrawStretchPic( x, y, width, 1, 0, 0, 0, 0, uis.whiteShader );
trap_R_DrawStretchPic( x, y, 1, height, 0, 0, 0, 0, uis.whiteShader );
trap_R_DrawStretchPic( x, y + height - 1, width, 1, 0, 0, 0, 0, uis.whiteShader );
trap_R_DrawStretchPic( x + width - 1, y, 1, height, 0, 0, 0, 0, uis.whiteShader );
trap_R_SetColor( NULL );
}
void UI_SetColor( const float *rgba ) {
trap_R_SetColor( rgba );
}
void UI_UpdateScreen( void ) {
trap_UpdateScreen();
}
/*
=================
UI_Refresh
=================
*/
void UI_Refresh( int realtime )
{
uis.frametime = realtime - uis.realtime;
uis.realtime = realtime;
if ( !( trap_Key_GetCatcher() & KEYCATCH_UI ) ) {
return;
}
UI_UpdateCvars();
if ( uis.activemenu )
{
if (uis.activemenu->fullscreen)
{
// draw the background
if( uis.activemenu->showlogo ) {
UI_DrawHandlePic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, uis.menuBackShader );
}
else {
UI_DrawHandlePic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, uis.menuBackNoLogoShader );
}
}
if (uis.activemenu->draw)
uis.activemenu->draw();
else
Menu_Draw( uis.activemenu );
if( uis.firstdraw ) {
UI_MouseEvent( 0, 0 );
uis.firstdraw = qfalse;
}
}
// draw cursor
UI_SetColor( NULL );
UI_DrawHandlePic( uis.cursorx-16, uis.cursory-16, 32, 32, uis.cursor);
#ifndef NDEBUG
if (uis.debug)
{
// cursor coordinates
UI_DrawString( 0, 0, va("(%d,%d)",uis.cursorx,uis.cursory), UI_LEFT|UI_SMALLFONT, colorRed );
}
#endif
// delay playing the enter sound until after the
// menu has been drawn, to avoid delay while
// caching images
if (m_entersound)
{
trap_S_StartLocalSound( menu_in_sound, CHAN_LOCAL_SOUND );
m_entersound = qfalse;
}
}
void UI_DrawTextBox (int x, int y, int width, int lines)
{
UI_FillRect( x + BIGCHAR_WIDTH/2, y + BIGCHAR_HEIGHT/2, ( width + 1 ) * BIGCHAR_WIDTH, ( lines + 1 ) * BIGCHAR_HEIGHT, colorBlack );
UI_DrawRect( x + BIGCHAR_WIDTH/2, y + BIGCHAR_HEIGHT/2, ( width + 1 ) * BIGCHAR_WIDTH, ( lines + 1 ) * BIGCHAR_HEIGHT, colorWhite );
}
qboolean UI_CursorInRect (int x, int y, int width, int height)
{
if (uis.cursorx < x ||
uis.cursory < y ||
uis.cursorx > x+width ||
uis.cursory > y+height)
return qfalse;
return qtrue;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -