Пример #1
0
int CHudStatusBar :: Draw( float fTime )
{
 
	this->ReparseStringIfNeeded();

	// Draw the status bar lines
	for ( int i = 0; i < MAX_STATUSBAR_LINES; i++ )
	{
		int TextHeight, TextWidth;
		GetConsoleStringSize( m_szStatusBar[i], &TextWidth, &TextHeight );

		int Y_START;
		if ( ScreenHeight() >= 480 )
			Y_START = ScreenHeight() - 55;
		else
			Y_START = ScreenHeight() - 45;

		int x = 5;
		int y = Y_START - ( TextHeight * i ); // draw along bottom of screen

		// let user set status ID bar centering
		if ( (i == STATUSBAR_ID_LINE) && CVAR_GET_FLOAT("hud_centerid") )
		{
			x = max( 0, max(2, (ScreenWidth() - TextWidth)) / 2 );
			y = (ScreenHeight() / 2) + (TextHeight*CVAR_GET_FLOAT("hud_centerid"));
		}

		if ( m_pflNameColors[i] )
			DrawSetTextColor( m_pflNameColors[i][0], m_pflNameColors[i][1], m_pflNameColors[i][2] );

		DrawConsoleString( x, y, m_szStatusBar[i] );
	}

	return 1;
}
Пример #2
0
int CHudStatusBar :: Draw( float fTime )
{
	if( m_bReparseString )
	{
		for( int i = 0; i < MAX_STATUSBAR_LINES; i++ )
		{
			m_pflNameColors[i] = g_ColorYellow;
			ParseStatusString( i );
		}
		m_bReparseString = FALSE;
	}

	int Y_START = ScreenHeight - YRES( 32 + 4 );

	// Draw the status bar lines
	for( int i = 0; i < MAX_STATUSBAR_LINES; i++ )
	{
		int TextHeight, TextWidth;
		GetConsoleStringSize( m_szStatusBar[i], &TextWidth, &TextHeight );

		int x = 4;
		int y = Y_START - ( 4 + TextHeight * i ); // draw along bottom of screen

		// let user set status ID bar centering
		if(( i == STATUSBAR_ID_LINE ) && CVAR_GET_FLOAT( "hud_centerid" ))
		{
			x = max( 0, max( 2, (ScreenWidth - TextWidth)) / 2 );
			y = (ScreenHeight / 2) + (TextHeight * CVAR_GET_FLOAT( "hud_centerid" ));
		}

		if( m_pflNameColors[i] )
			DrawSetTextColor( m_pflNameColors[i][0], m_pflNameColors[i][1], m_pflNameColors[i][2] );

		DrawConsoleString( x, y, m_szStatusBar[i] );
	}

	return 1;
}
Пример #3
0
void CHudSayText :: EnsureTextFitsInOneLineAndWrapIfHaveTo( int line )
{
	int line_width = 0;
	GetConsoleStringSize( g_szLineBuffer[line], &line_width, &line_height );

	if ( (line_width + LINE_START) > MAX_LINE_WIDTH )
	{ // string is too long to fit on line
		// scan the string until we find what word is too long,  and wrap the end of the sentence after the word
		int length = LINE_START;
		int tmp_len = 0;
		char *last_break = NULL;
		for ( char *x = g_szLineBuffer[line]; *x != 0; x++ )
		{
			// check for a color change, if so skip past it
			if ( x[0] == '/' && x[1] == '(' )
			{
				x += 2;
				// skip forward until past mode specifier
				while ( *x != 0 && *x != ')' )
					x++;

				if ( *x != 0 )
					x++;

				if ( *x == 0 )
					break;
			}

			char buf[2];
			buf[1] = 0;

			if ( *x == ' ' && x != g_szLineBuffer[line] )  // store each line break,  except for the very first character
				last_break = x;

			buf[0] = *x;  // get the length of the current character
			GetConsoleStringSize( buf, &tmp_len, &line_height );
			length += tmp_len;

			if ( length > MAX_LINE_WIDTH )
			{  // needs to be broken up
				if ( !last_break )
					last_break = x-1;

				x = last_break;

				// find an empty string slot
				int j;
				do 
				{
					for ( j = 0; j < MAX_LINES; j++ )
					{
						if ( ! *g_szLineBuffer[j] )
							break;
					}
					if ( j == MAX_LINES )
					{
						// need to make more room to display text, scroll stuff up then fix the pointers
						int linesmoved = ScrollTextUp();
						line -= linesmoved;
						last_break = last_break - (sizeof(g_szLineBuffer[0]) * linesmoved);
					}
				}
				while ( j == MAX_LINES );

				// copy remaining string into next buffer,  making sure it starts with a space character
				if ( (char)*last_break == (char)' ' )
				{
					int linelen = strlen(g_szLineBuffer[j]);
					int remaininglen = strlen(last_break);

					if ( (linelen - remaininglen) <= MAX_CHARS_PER_LINE )
						strcat( g_szLineBuffer[j], last_break );
				}
				else
				{
					if ( (strlen(g_szLineBuffer[j]) - strlen(last_break) - 2) < MAX_CHARS_PER_LINE )
					{
						strcat( g_szLineBuffer[j], " " );
						strcat( g_szLineBuffer[j], last_break );
					}
				}

				*last_break = 0; // cut off the last string

				EnsureTextFitsInOneLineAndWrapIfHaveTo( j );
				break;
			}
		}
	}
}
Пример #4
0
/*
=================
UI_DrawMenu
=================
*/
void UI_DrawMenu( menuFramework_s *menu )
{
	static long	statusFadeTime;
	static menuCommon_s	*lastItem;
	menuCommon_s	*item;
	int		i;

	// draw contents
	for( i = 0; i < menu->numItems; i++ )
	{
		item = (menuCommon_s *)menu->items[i];

		if( item->flags & QMF_HIDDEN )
			continue;

		if( item->ownerdraw )
		{
			// total subclassing, owner draws everything
			item->ownerdraw( item );
			continue;
		}

		switch( item->type )
		{
		case QMTYPE_SCROLLLIST:
			UI_ScrollList_Draw((menuScrollList_s *)item );
			break;
		case QMTYPE_SPINCONTROL:
			UI_SpinControl_Draw((menuSpinControl_s *)item );
			break;
		case QMTYPE_CHECKBOX:
			UI_CheckBox_Draw((menuCheckBox_s *)item );
			break;
		case QMTYPE_SLIDER:
			UI_Slider_Draw((menuSlider_s *)item );
			break;
		case QMTYPE_FIELD:
			UI_Field_Draw((menuField_s *)item );
			break;
		case QMTYPE_ACTION:
			UI_Action_Draw((menuAction_s *)item );
			break;
		case QMTYPE_BITMAP:
			UI_Bitmap_Draw((menuBitmap_s *)item );
			break;
		case QMTYPE_BM_BUTTON:
			UI_PicButton_Draw((menuPicButton_s *)item );
			break;
		}
	}

	// draw status bar
	item = (menuCommon_s *)UI_ItemAtCursor( menu );
	if( item != lastItem )
	{
		// flash on selected button (like in GoldSrc)
		if( item ) item->lastFocusTime = uiStatic.realTime;
		statusFadeTime = uiStatic.realTime;
		lastItem = item;
	}

	if( item && ( item->flags & QMF_HASMOUSEFOCUS && !( item->flags & QMF_NOTIFY )) && ( item->statusText != NULL ))
	{
		// fade it in, but wait a second
		int alpha = bound( 0, ((( uiStatic.realTime - statusFadeTime ) - 1000 ) * 0.001f ) * 255, 255 );
		int r, g, b, x, len;

		GetConsoleStringSize( item->statusText, &len, NULL );

		UnpackRGB( r, g, b, uiColorHelp );
		TextMessageSetColor( r, g, b, alpha );
		x = ( ScreenWidth - len ) * 0.5; // centering

		DrawConsoleString( x, 720 * uiStatic.scaleY, item->statusText );
	}
	else statusFadeTime = uiStatic.realTime;
}
Пример #5
0
int CHudRadar::Draw(float flTime)
{	if ( (gHUD.m_iHideHUDDisplay & HIDEHUD_HEALTH) || gEngfuncs.IsSpectateOnly() || !(gHUD.m_iWeaponBits & (1<<(WEAPON_SUIT))))
	{	return 1;
	}

	cl_entity_t *pLocal = gEngfuncs.GetLocalPlayer();
	if(!pLocal)
	{	return 1;
	}

	float flPlayerAngles, flLength, flAngle, flRadians, pos_x, pos_y;
	vec3_t vecViewAngles, v_right, vecPlayerOrigin, vecOtherOrigin, vecDifference, vecAngles;

	/*
	* Draw Background radar
	*/

	// Get origin for radar
	int x = ScreenWidth;
	int y = 0;

	int iRadarWidth = gHUD.GetSpriteRect(m_HUD_radar).right - gHUD.GetSpriteRect(m_HUD_radar).left;
	int iRadarHeight = gHUD.GetSpriteRect(m_HUD_radar).bottom - gHUD.GetSpriteRect(m_HUD_radar).top;

	int infox = ScreenWidth - INFO_WIDTH;
	int infoy = iRadarHeight;
	int infoheight = gHUD.GetSpriteRect(m_HUD_radar_info).bottom - gHUD.GetSpriteRect(m_HUD_radar_info).top;

	x -= iRadarWidth;
	
	// Slide radar + info bar in/out when we enable/disable
	if(m_blPrevRadar != m_blRadar && !m_blSliding)
	{	m_blSliding = true;
		m_flSlideTime = flTime;
	}
	// We switched the radar on/off while in the middle of sliding
	else if(m_blPrevRadar == m_blRadar && m_blSliding)
	{	m_blPrevRadar = !m_blPrevRadar;
		// Invert time
		float flSlideTime = flTime - m_flSlideTime;
		flSlideTime = SLIDETIME - flSlideTime;
		m_flSlideTime = flTime - flSlideTime;
	}

	if(m_blSliding)
	{	// Sliding is done, disable
		if((m_flSlideTime + SLIDETIME) < flTime)
		{	m_blSliding = false;
			m_flSlideTime = 0;
			m_blPrevRadar = m_blRadar;

			// Done sliding and radar is off, disable
			if(!m_blRadar)
			{	return 1;
			}
		}
		// we're still sliding
		else
		{	float flPercent;
			if(m_blRadar)
				flPercent = (SLIDETIME-(flTime - m_flSlideTime))/SLIDETIME;
			else
				flPercent = (flTime - m_flSlideTime)/SLIDETIME;
			
			// Slide Radar
			y = -iRadarHeight * flPercent;
			// Slide Infobox
			infox += INFO_WIDTH * flPercent;
		}
	}

	// Done sliding and radar is off, disable
	if(!m_blRadar && !m_blSliding)
	{	return 1;
	}
	// Draw Radar
	SPR_Set(gHUD.GetSprite(m_HUD_radar), 255, 255, 255);
	SPR_DrawHoles(0, x,y, &gHUD.GetSpriteRect(m_HUD_radar));

	// Draw info box
	SPR_Set(gHUD.GetSprite(m_HUD_radar_info), 255,255,255);
	SPR_DrawHoles(0, infox,infoy, &gHUD.GetSpriteRect(m_HUD_radar_info));

	if(m_blSliding)
		m_iyBottomRadar = y + iRadarHeight;
	else
		m_iyBottomRadar = infoy + infoheight;

	// Sliding or radar is just off, dont display information
	if(m_blSliding || !m_blRadar)
	{	return 1;
	}
	/*
	* Get Player Angles
	*/

	// Setting player angles
	gEngfuncs.GetViewAngles((float *)vecViewAngles);
	AngleVectors(vecViewAngles, NULL, v_right, NULL );
	// Inverse vector
	VectorInverse(v_right);
	v_right.z = 0;

	// Get angles
	VectorAngles(v_right,vecAngles);
	flPlayerAngles = vecAngles.y;

	// strictly 0 to 360
	if(flPlayerAngles < 0)
		flPlayerAngles += 360;

	// Move x and y to the middle of the radar
	x += OFFSET_RAD_WIDTH;
	y += OFFSET_RAD_HEIGHT;

	/*
	* Loop and draw dots
	*/
	for(int i=0; i<MAX_PLAYERS; i++)
	{	int r=255,g=255,b=255;
		bool blDrawInfo = false;
		cl_entity_t *pPlayer = gEngfuncs.GetEntityByIndex(i);
		// Invalid
		if(!pPlayer)
		{	continue;
		}

		// Not player
		if(!pPlayer->player)
		{	continue;
		}

		// Render check, make sure player is being rendered
		if(!g_RenderCheck[i].blRendered)
		{	continue;
		}

		// Draw yourself as a orange dot
		if(pPlayer == pLocal)
		{	r=255;
			g=255;
			b=0;
		}

		// Get Origins
		vecPlayerOrigin = pLocal->origin;
		vecOtherOrigin = pPlayer->origin;
		vecPlayerOrigin.z = 0;
		vecOtherOrigin.z = 0;
		vecDifference = vecPlayerOrigin - vecOtherOrigin;

		flLength = vecDifference.Length();

		// Player is too far away, dont draw
		if(flLength > MAX_RADAR_DIST)
			continue;

		vecDifference = vecDifference.Normalize();

		// Set 0 to 360
		VectorAngles(vecDifference, vecAngles);
		flAngle = vecAngles.y;

		if(flAngle < 0)
			flAngle += 360;

		// Subtract Angles
		flAngle = flPlayerAngles - flAngle;

		// Set length according to the size of the radar
		flLength = (flLength/(float)MAX_RADAR_DIST) * RAD_DIAM;

		// Angles to radians
		flRadians = flAngle * PI_180;
		pos_x = int(cos(flRadians)*flLength);
		pos_y = int(sin(flRadians)*flLength);

		// Set positions + draw radar
		pos_x += x;
		pos_y += y;

		// Shift dot over so it's drawn in the correct position
		int iDotWidth = (gHUD.GetSpriteRect(m_HUD_radardot).right - gHUD.GetSpriteRect(m_HUD_radardot).left)/2;
		int iDotHeight = (gHUD.GetSpriteRect(m_HUD_radardot).bottom - gHUD.GetSpriteRect(m_HUD_radardot).top)/2;
		pos_x -= iDotWidth;
		pos_y -= iDotHeight;

		// Person is targeted by our missles, color them red
		if( gHUD.m_Lockon.FindLock( pPlayer->index ) != -1 )
		{	r=255;
			g=0;
			b=0;
		}

		// Yellow if our crosshair is/was over the player
		if(	gHUD.m_Crosshair.m_iMouseOverEnt == pPlayer->index && ((flTime - gHUD.m_Crosshair.m_flMouseOverTime) < 3) )
		{	UnpackRGB(r,g,b, RGB_YELLOWISH);
			blDrawInfo = true;
		}

		// Draw
		SPR_Set(gHUD.GetSprite(m_HUD_radardot), r,g,b);
		SPR_DrawAdditive(0, pos_x,pos_y, &gHUD.GetSpriteRect(m_HUD_radardot));

		// Draw information if specified
		if(blDrawInfo)
		{	int line_height=0,line_width=0;
			pos_x = ScreenWidth - INFO_WIDTH + INFO_OFFSET_WIDTH;
			pos_y = iRadarHeight + INFO_OFFSET_HEIGHT;

			hud_player_info_t *pl_info = &g_PlayerInfoList[i];
			char szName[128];

			// Get colors
			float flTeamR,flTeamG,flTeamB;
			if((g_PlayerExtraInfo[i].teamnumber == g_PlayerExtraInfo[pLocal->index].teamnumber) && gHUD.m_Teamplay)
			{	flTeamR=0;
				flTeamG=0.9;
				flTeamB=0;
			}
			else
			{	flTeamR=1.0;
				flTeamG=0.2;
				flTeamB=0.2;
			}
			
			// Draw player name
			strcpy(szName,"Name: ");
			int iNameX = DrawConsoleString( pos_x, pos_y, szName );
			// Draw name in color, depending if player is on your team
			strcpy(szName, pl_info->name);
			// Set color
			gEngfuncs.pfnDrawSetTextColor(flTeamR,flTeamG,flTeamB);
			// Draw
			DrawConsoleString( iNameX, pos_y, szName );


			// Adjust offset
			GetConsoleStringSize( szName, &line_width, &line_height );
			pos_y += line_height + INFO_OFFSET_LINE;
			// Draw Label
			strcpy(szName,"Mech: ");
			iNameX = DrawConsoleString( pos_x, pos_y, szName );
			// Get Mech Name
			int iClass = g_PlayerExtraInfo[i].playerclass;
			if(iClass < 0)
				iClass = 0;
			else if(iClass >= PC_LASTCLASS)
				iClass = PC_LASTCLASS-1;
			strcpy(szName, szClassNames[iClass] );
			// Set Color
			gEngfuncs.pfnDrawSetTextColor(flTeamR,flTeamG,flTeamB);
			// Draw Mech Name
			DrawConsoleString( iNameX, pos_y, szName );
		}
	}

	return 1;
}