//---------------------------------------------------------
// Purpose: Compute the proper position on the radar screen
//			for this object's position relative to the player.
//			Then draw the icon in the proper location on the
//			radar screen.
//---------------------------------------------------------
void CGERadar::DrawIconOnRadar( CGERadarContact *contact, Color col )
{
	float x = contact->m_vScaledPos.x, 
		y = contact->m_vScaledPos.y,
		z_delta = contact->m_vScaledPos.z;

	int width, height;

	float floorheight = GEMPRules()->GetMapFloorHeight();

	// Get the correct icon for this type of contact
	CHudTexture *icon = NULL;

	if ( contact->m_Icon )
	{
		// We have a custom icon!
		if (z_delta > floorheight && contact->m_IconAbove)
			icon = contact->m_IconAbove;
		else if (z_delta < floorheight * -1 && contact->m_IconBelow)
			icon = contact->m_IconBelow;
		else
			icon = contact->m_Icon;

		width = max( icon->EffectiveWidth(m_flScaleX), 16 );
		height = max( icon->EffectiveHeight(m_flScaleY), 16 );
	}
	else if ( contact->m_iType == RADAR_TYPE_TOKEN )
	{
		if ( z_delta > floorheight )
			icon = m_IconTokenAbove;
		else if ( z_delta < floorheight * -1 )
			icon = m_IconTokenBelow;
		else
			icon = m_IconToken;

		width = max( icon->EffectiveWidth(m_flScaleX), 8 );
		height = max( icon->EffectiveHeight(m_flScaleY), 8 );
	}
	else
	{
		if ( z_delta > floorheight )
			icon = m_IconBlipAbove;
		else if ( z_delta < floorheight * -1 )
			icon = m_IconBlipBelow;
		else
			icon = m_IconBlip;

		width = max( icon->EffectiveWidth(m_flScaleX), 8 );
		height = max( icon->EffectiveHeight(m_flScaleY), 8 );
	}

	// Double check we are inside the radar bounds
	if ( x >= m_iSideBuff && y >= m_iSideBuff )
	{
		// Center the icon around its position.
		x -= (width >> 1);
		y -= (height >> 1);

		vgui::surface()->DrawSetColor( col[0], col[1], col[2], col[3]*contact->m_flAlphaMod );
		vgui::surface()->DrawSetTexture( icon->textureId );
		vgui::surface()->DrawTexturedRect(x, y, x + width, y + height);
	}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CHudBaseDeathNotice::Paint()
{
	// Retire any death notices that have expired
	RetireExpiredDeathNotices();

	CBaseViewport *pViewport = dynamic_cast<CBaseViewport *>( GetClientModeNormal()->GetViewport() );
	int yStart = pViewport->GetDeathMessageStartHeight();

	surface()->DrawSetTextFont( m_hTextFont );

	int xMargin = XRES( 10 );
	int xSpacing = UTIL_ComputeStringWidth( m_hTextFont, L" " );

	int iCount = m_DeathNotices.Count();
	for ( int i = 0; i < iCount; i++ )
	{
		DeathNoticeItem &msg = m_DeathNotices[i];
		
		CHudTexture *icon = msg.iconDeath;
		CHudTexture *iconPrekiller = msg.iconPreKiller;

		wchar_t victim[256]=L"";
		wchar_t killer[256]=L"";

		// TEMP - print the death icon name if we don't have a material for it

		g_pVGuiLocalize->ConvertANSIToUnicode( msg.Victim.szName, victim, sizeof( victim ) );
		g_pVGuiLocalize->ConvertANSIToUnicode( msg.Killer.szName, killer, sizeof( killer ) );

		int iVictimTextWide = UTIL_ComputeStringWidth( m_hTextFont, victim ) + xSpacing;
		int iDeathInfoTextWide= msg.wzInfoText[0] ? UTIL_ComputeStringWidth( m_hTextFont, msg.wzInfoText ) + xSpacing : 0;
		int iDeathInfoEndTextWide= msg.wzInfoTextEnd[0] ? UTIL_ComputeStringWidth( m_hTextFont, msg.wzInfoTextEnd ) + xSpacing : 0;

		int iKillerTextWide = killer[0] ? UTIL_ComputeStringWidth( m_hTextFont, killer ) + xSpacing : 0;
		int iLineTall = m_flLineHeight;
		int iTextTall = surface()->GetFontTall( m_hTextFont );
		int iconWide = 0, iconTall = 0, iDeathInfoOffset = 0, iVictimTextOffset = 0, iconActualWide = 0;
		
		int iPreKillerTextWide = msg.wzPreKillerText[0] ? UTIL_ComputeStringWidth( m_hTextFont, msg.wzPreKillerText ) - xSpacing : 0;
		int iconPrekillerWide = 0, iconPrekillerActualWide = 0, iconPreKillerTall = 0;

		// Get the local position for this notice
		if ( icon )
		{			
			iconActualWide = icon->EffectiveWidth( 1.0f );
			iconWide = iconActualWide + xSpacing;
			iconTall = icon->EffectiveHeight( 1.0f );
			
			int iconTallDesired = iLineTall-YRES(2);
			Assert( 0 != iconTallDesired );
			float flScale = (float) iconTallDesired / (float) iconTall;

			iconActualWide *= flScale;
			iconTall *= flScale;
			iconWide *= flScale;
		}

		if ( iconPrekiller )
		{
			iconPrekillerActualWide = iconPrekiller->EffectiveWidth( 1.0f );
			iconPrekillerWide = iconPrekillerActualWide;
			iconPreKillerTall = iconPrekiller->EffectiveHeight( 1.0f );

			int iconTallDesired = iLineTall-YRES(2);
			Assert( 0 != iconTallDesired );
			float flScale = (float) iconTallDesired / (float) iconPreKillerTall;

			iconPrekillerActualWide *= flScale;
			iconPreKillerTall *= flScale;
			iconPrekillerWide *= flScale;
		}

		int iTotalWide = iKillerTextWide + iconWide + iVictimTextWide + iDeathInfoTextWide + iDeathInfoEndTextWide + ( xMargin * 2 );
		iTotalWide += iconPrekillerWide + iPreKillerTextWide;

		int y = yStart + ( ( iLineTall + m_flLineSpacing ) * i );				
		int yText = y + ( ( iLineTall - iTextTall ) / 2 );
		int yIcon = y + ( ( iLineTall - iconTall ) / 2 );

		int x=0;
		if ( m_bRightJustify )
		{
			x =	GetWide() - iTotalWide;
		}

		// draw a background panel for the message
		Vertex_t vert[NUM_BACKGROUND_COORD];
		GetBackgroundPolygonVerts( x, y+1, x+iTotalWide, y+iLineTall-1, ARRAYSIZE( vert ), vert );		
		surface()->DrawSetTexture( -1 );
		surface()->DrawSetColor( GetBackgroundColor ( i ) );
		surface()->DrawTexturedPolygon( ARRAYSIZE( vert ), vert );

		x += xMargin;
	
		if ( killer[0] )
		{
			// Draw killer's name
			DrawText( x, yText, m_hTextFont, GetTeamColor( msg.Killer.iTeam, msg.bLocalPlayerInvolved ), killer );
			x += iKillerTextWide;
		}

		// prekiller text
		if ( msg.wzPreKillerText[0] )
		{
			x += xSpacing;
			DrawText( x + iDeathInfoOffset, yText, m_hTextFont, GetInfoTextColor( i ), msg.wzPreKillerText );
			x += iPreKillerTextWide;
		}

		// Prekiller icon
		if ( iconPrekiller )
		{
			int yPreIconTall = y + ( ( iLineTall - iconPreKillerTall ) / 2 );
			iconPrekiller->DrawSelf( x, yPreIconTall, iconPrekillerActualWide, iconPreKillerTall, m_clrIcon );
			x += iconPrekillerWide + xSpacing;
		}

		// Draw glow behind weapon icon to show it was a crit death
		if ( msg.bCrit && msg.iconCritDeath )
		{
			msg.iconCritDeath->DrawSelf( x, yIcon, iconActualWide, iconTall, m_clrIcon );
		}

		// Draw death icon
		if ( icon )
		{
			icon->DrawSelf( x, yIcon, iconActualWide, iconTall, m_clrIcon );
			x += iconWide;
		}

		// Draw additional info text next to death icon 
		if ( msg.wzInfoText[0] )
		{
			if ( msg.bSelfInflicted )
			{
				iDeathInfoOffset += iVictimTextWide;
				iVictimTextOffset -= iDeathInfoTextWide;
			}

			DrawText( x + iDeathInfoOffset, yText, m_hTextFont, GetInfoTextColor( i ), msg.wzInfoText );
			x += iDeathInfoTextWide;
		}

		// Draw victims name
		DrawText( x + iVictimTextOffset, yText, m_hTextFont, GetTeamColor( msg.Victim.iTeam, msg.bLocalPlayerInvolved ), victim );
		x += iVictimTextWide;

		// Draw Additional Text on the end of the victims name
		if ( msg.wzInfoTextEnd[0] )
		{
			DrawText( x , yText, m_hTextFont, GetInfoTextColor( i ), msg.wzInfoTextEnd );
		}
	}
}
void CHudStyleBar::Paint()
{
	C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer();
	if ( !pPlayer )
		return;

	if (!pPlayer->IsAlive())
		return;

	for (int i = 0; i < TOTAL_ANNOUNCEMENTS; i++)
	{
		if (!m_apAnnouncements[i])
			m_apAnnouncements[i] = gHUD.GetIcon(g_apszAnnouncementTextures[i]);
	}

	if (!m_apActiveSkillIcons[SKILL_BOUNCER])
	{
		m_apActiveSkillIcons[SKILL_BOUNCER] = gHUD.GetIcon("bouncer");
		m_apActiveSkillIcons[SKILL_ATHLETIC] = gHUD.GetIcon("athletic");
		m_apActiveSkillIcons[SKILL_REFLEXES] = gHUD.GetIcon("reflexes");
		m_apActiveSkillIcons[SKILL_MARKSMAN] = gHUD.GetIcon("marksman");
		m_apActiveSkillIcons[SKILL_TROLL] = gHUD.GetIcon("troll");
		m_apActiveSkillIcons[SKILL_SUPER] = gHUD.GetIcon("super");
		//m_apActiveSkillIcons[SKILL_RESILIENT] = gHUD.GetIcon("resilient");

		m_pGoldStar = gHUD.GetIcon("star_gold");
		m_pSilverStar = gHUD.GetIcon("star_silver");
		m_pBronzeStar = gHUD.GetIcon("star_bronze");

		m_pBriefcase = gHUD.GetIcon("briefcase");
	}

	CHudTexture* pStyleTexture = m_apActiveSkillIcons[pPlayer->m_Shared.m_iStyleSkill];

	if (pPlayer->m_Shared.m_bSuperSkill || SDKGameRules()->GetBountyPlayer() == pPlayer)
		pStyleTexture = m_apActiveSkillIcons[SKILL_SUPER];

	float flStyleTextureWidth = 0;
	float flStyleTextureHeight = 0;

	if (pStyleTexture)
	{
		flStyleTextureWidth = scheme()->GetProportionalScaledValueEx(GetScheme(), pStyleTexture->EffectiveWidth(0.5f)) * 0.8f;
		flStyleTextureHeight = scheme()->GetProportionalScaledValueEx(GetScheme(), pStyleTexture->EffectiveHeight(0.5f)) * 0.8f;
	}

	int iWidth = m_flElementWide;
	int iHeight = m_flElementTall;

	int flScreenWide, flScreenTall;
	surface()->GetScreenSize(flScreenWide, flScreenTall);

	float flBarLeft = m_flElementXPos + iWidth - flStyleTextureWidth/2 - m_flBarWidth/2;
	surface()->DrawSetColor( Color(0, 0, 0, 100) );
	surface()->DrawFilledRect(
		flBarLeft,
		m_flElementYPos,
		m_flElementXPos + iWidth - flStyleTextureWidth/2 + m_flBarWidth/2,
		m_flElementYPos + iHeight - flStyleTextureHeight - m_flGap
		);

	Color clrActivated = Color(255, 190, 20, 255);
	Color clrNormal = Color(170, 140, 33, 255);

	Color clrZeroStyle = Color(100, 100, 100, 255);

	wchar_t* pwszStyle = L"Style!";
	if (pPlayer->IsStyleSkillActive())
		pwszStyle = g_pVGuiLocalize->Find("#DA_Style_Active");
	else if (m_flCurrentStyle/da_stylemeteractivationcost.GetFloat() > 0.6)
		pwszStyle = g_pVGuiLocalize->Find("#DA_Style_High");
	else if (m_flCurrentStyle/da_stylemeteractivationcost.GetFloat() > 0.3)
		pwszStyle = g_pVGuiLocalize->Find("#DA_Style_Med");
	else
		pwszStyle = g_pVGuiLocalize->Find("#DA_Style_Low");

	if (!pwszStyle)
		pwszStyle = L"Style!";

	int iStyleTextWide, iStyleTextTall;
	surface()->GetTextSize(m_hStyleFont, pwszStyle, iStyleTextWide, iStyleTextTall);

	Color clrStyleText;
	if (pPlayer->IsStyleSkillActive())
		clrStyleText = Color(
			RemapValClamped(Oscillate(gpGlobals->curtime, 1), 0, 1, clrActivated.r(), clrNormal.r()),
			RemapValClamped(Oscillate(gpGlobals->curtime, 1), 0, 1, clrActivated.g(), clrNormal.g()),
			RemapValClamped(Oscillate(gpGlobals->curtime, 1), 0, 1, clrActivated.b(), clrNormal.b()),
			255);
	else
		clrStyleText = Color(
			RemapValClamped(m_flCurrentStyle, 0, da_stylemeteractivationcost.GetFloat(), clrZeroStyle.r(), clrNormal.r()),
			RemapValClamped(m_flCurrentStyle, 0, da_stylemeteractivationcost.GetFloat(), clrZeroStyle.g(), clrNormal.g()),
			RemapValClamped(m_flCurrentStyle, 0, da_stylemeteractivationcost.GetFloat(), clrZeroStyle.b(), clrNormal.b()),
			255);

	vgui::surface()->DrawSetTextFont( m_hStyleFont );
	vgui::surface()->DrawSetTextPos( flBarLeft + m_flBarWidth/2 - iStyleTextWide/2, m_flElementYPos - iStyleTextTall );
	vgui::surface()->DrawSetTextColor( clrStyleText );
	vgui::surface()->DrawPrintText( pwszStyle, wcslen(pwszStyle) );

	Color clrBar;
	if (pPlayer->IsStyleSkillActive())
	{
		clrBar = clrActivated;
		clrBar.SetColor(clrBar.r(), clrBar.g(), clrBar.b(), RemapValClamped(Gain(Oscillate(gpGlobals->curtime, 1), 0.7f), 0, 1, 0.1f, 1)*255);
	}
	else
	{
		int r = Lerp(m_flCurrentStyle/da_stylemeteractivationcost.GetFloat(), clrNormal.r()/2, clrNormal.r());
		int g = Lerp(m_flCurrentStyle/da_stylemeteractivationcost.GetFloat(), clrNormal.g()/2, clrNormal.g());
		int b = Lerp(m_flCurrentStyle/da_stylemeteractivationcost.GetFloat(), clrNormal.b()/2, clrNormal.b());
		clrBar.SetColor(r, g, b, clrNormal.a());
	}

	surface()->DrawSetColor( clrBar );

	float flPercent;
	if (pPlayer->IsStyleSkillActive())
		flPercent = min(pPlayer->GetStyleSkillCharge() / 100, 1);
	else
		flPercent = m_flCurrentStyle / da_stylemeteractivationcost.GetFloat();

	float flBarHeight = iHeight - flStyleTextureHeight - m_flGap*2;

	int iBarLeft = m_flElementXPos + iWidth - flStyleTextureWidth/2 - m_flBarWidth/2 + m_flGap;
	int iBarRight = m_flElementXPos + iWidth - flStyleTextureWidth/2 + m_flBarWidth/2 - m_flGap;
	surface()->DrawFilledRect( iBarLeft, m_flElementYPos + m_flGap + flBarHeight*(1-flPercent), iBarRight, m_flElementYPos + flBarHeight );

	float flPulseTime = 0.6f;
	float flAlphaRamp = RemapValClamped(fmod(gpGlobals->curtime, flPulseTime), 0, flPulseTime, 0, 1);
	int iPulseAlpha = RemapValClamped(Bias(flAlphaRamp, 0.1f), 0, flPulseTime, 50, 10);
	surface()->DrawSetColor( Color(255, 255, 255, iPulseAlpha) );

	float flWidth = 0.1f;
	float flBottom = RemapValClamped(fmod(gpGlobals->curtime, flPulseTime), 0, flPulseTime, -flWidth, 1);
	float flTop = flBottom + flWidth;

	flBottom = clamp(flBottom, 0, flPercent);
	flTop = clamp(flTop, 0, flPercent);

	surface()->DrawFilledRect( iBarLeft + 2, m_flElementYPos + m_flGap + flBarHeight*(1-flTop), iBarRight - 2, m_flElementYPos + flBarHeight*(1-flBottom) );

	if (pStyleTexture)
	{
		float flAlpha = 1;
		float flNonRed = 0;
		float flRed = 0;

		if (pPlayer->IsStyleSkillActive())
		{
			flAlpha = RemapValClamped(Gain(Oscillate(gpGlobals->curtime, 1), 0.7f), 0, 1, 0.5f, 1);
			flNonRed = Gain(1-Oscillate(gpGlobals->curtime, 1), 0.7f);
			flRed = 1;
		}

		float flBarIconX = m_flElementXPos + iWidth - flStyleTextureWidth;
		float flBarIconY = m_flElementYPos + iHeight - flStyleTextureHeight;
		pStyleTexture->DrawSelf(
				flBarIconX, flBarIconY,
				flStyleTextureWidth, flStyleTextureHeight,
				Color(
					Lerp(flRed, 255, clrActivated.r()),
					Lerp(flNonRed, 255, clrActivated.g()),
					Lerp(flNonRed, 255, clrActivated.b()),
					255*flAlpha
				)
			);

		float flIconXPos = GetIconX();
		float flIconYPos = GetIconY();
		float flIconWide = GetIconW();
		float flIconTall = GetIconH();

		if (pPlayer->IsStyleSkillActive())
		{
			pStyleTexture->DrawSelf(
					flIconXPos, flIconYPos,
					flIconWide, flIconTall,
					Color( 255, 255, 255, 255 )
				);
		}

		if (m_pBriefcase && pPlayer->HasBriefcase())
		{
			m_pBriefcase->DrawSelf(
					flIconXPos + flIconWide + 20, flIconYPos,
					flIconWide, flIconTall,
					Color( 255, 255, 255, 255 )
				);
		}

		float flLerpTime = 1.0f;
		float flFadeTime = 1.0f;
		if (m_flStyleIconLerpStart && gpGlobals->curtime < m_flStyleIconLerpStart + flLerpTime + flFadeTime)
		{
			float flRamp = Bias(RemapValClamped(gpGlobals->curtime, m_flStyleIconLerpStart, m_flStyleIconLerpStart + flLerpTime, 0, 1), 0.7f);

			if (pPlayer->m_Shared.m_iStyleSkill == SKILL_TROLL)
			{
				CHudAmmo* pElement = dynamic_cast<CHudAmmo*>(gHUD.FindElement("CHudAmmo"));
				if (pElement)
				{
					Vector4D vecGrenade = pElement->GetGrenadePosition(pPlayer->GetAmmoCount("grenades")-1);
					flIconXPos = vecGrenade.x;
					flIconYPos = vecGrenade.y;
					flIconWide = vecGrenade.z;
					flIconTall = vecGrenade.w;
				}
			}
			else if (pPlayer->m_Shared.m_iStyleSkill == SKILL_REFLEXES)
			{
				CHudNumericDisplay* pElement = dynamic_cast<CHudNumericDisplay*>(gHUD.FindElement("CHudSlowMo"));
				if (pElement)
				{
					int x, y;
					pElement->GetPos(x, y);
					flIconXPos = x;
					flIconYPos = y;

					int w, h;
					pElement->GetSize(w, h);
					flIconWide = flIconTall = (w + h)/2;
				}
			}

			float flAlpha = RemapValClamped(gpGlobals->curtime, m_flStyleIconLerpStart + flLerpTime, m_flStyleIconLerpStart + flLerpTime + flFadeTime, 1, 0);

			pStyleTexture->DrawSelf(
					RemapVal(flRamp, 0, 1, flBarIconX, flIconXPos), RemapVal(flRamp, 0, 1, flBarIconY, flIconYPos),
					RemapVal(flRamp, 0, 1, flStyleTextureWidth, flIconWide), RemapVal(flRamp, 0, 1, flStyleTextureHeight, flIconTall),
					Color( clrActivated.r(), clrActivated.g(), clrActivated.b(), 255*flAlpha )
				);
		}
	}

	int iNext;
	for (int i = m_aAnnouncements.Head(); i != m_aAnnouncements.InvalidIndex(); i = iNext)
	{
		iNext = m_aAnnouncements.Next( i );

		CAnnouncement* pAnnouncement = &m_aAnnouncements[i];

		if (pAnnouncement->m_eAnnouncement < 0)
			continue;

		if (pAnnouncement->m_eAnnouncement >= TOTAL_ANNOUNCEMENTS)
			continue;

		if (!m_apAnnouncements[pAnnouncement->m_eAnnouncement])
			continue;

		if (gpGlobals->curtime < pAnnouncement->m_flStartTime)
			continue;

		CHudTexture* pTexture = m_apAnnouncements[pAnnouncement->m_eAnnouncement];

		float flScale = 1.2;
		if (pAnnouncement->m_ePointStyle == STYLE_POINT_LARGE)
			flScale = 0.8f;
		else if (pAnnouncement->m_ePointStyle == STYLE_POINT_SMALL)
			flScale = 0.6f;

		float flStarWidth = pTexture->EffectiveHeight(flScale);

		float flSlideInLerp = RemapValClamped(gpGlobals->curtime, pAnnouncement->m_flStartTime, pAnnouncement->m_flStartTime + 0.3f, 0, 1);
		float flSlideIn = RemapVal(Bias(flSlideInLerp, 0.75), 0, 1, -1000, 0);

		float flEndTime = pAnnouncement->m_flStartTime + hud_announcementtime.GetFloat();

		float flAlpha = 1;
		if (gpGlobals->curtime < pAnnouncement->m_flStartTime + 0.3f)
			flAlpha = RemapValClamped(gpGlobals->curtime, pAnnouncement->m_flStartTime, pAnnouncement->m_flStartTime + 0.3f, 0, 1);
		else if (gpGlobals->curtime > flEndTime-0.5f)
			flAlpha = RemapValClamped(gpGlobals->curtime, flEndTime-0.5f, flEndTime, 1, 0);

		pTexture->DrawSelf(
			flBarLeft - pTexture->EffectiveWidth(flScale) - flStarWidth + flSlideIn, m_flElementYPos + RemapValClamped(pAnnouncement->m_flBarPosition, 0, 1, m_flGap + flBarHeight - pTexture->EffectiveHeight(flScale), m_flGap),
			pTexture->EffectiveWidth(flScale), pTexture->EffectiveHeight(flScale),
			Color(255, 255, 255, 255 * flAlpha)
		);

		int iGold, iSilver, iBronze;
		C_SDKPlayer::GetStyleStars(pAnnouncement->m_flStylePoints, iGold, iSilver, iBronze);

		CHudTexture* pStarTexture;
		int iStars;
		if (iGold)
		{
			pStarTexture = m_pGoldStar;
			iStars = iGold;
		}
		else if (iSilver)
		{
			pStarTexture = m_pSilverStar;
			iStars = iSilver;
		}
		else
		{
			pStarTexture = m_pBronzeStar;
			iStars = iBronze;
		}

		if (pStarTexture)
		{
			pStarTexture->DrawSelf(
				flBarLeft - flStarWidth + flSlideIn, m_flElementYPos + RemapValClamped(pAnnouncement->m_flBarPosition, 0, 1, m_flGap + flBarHeight - pTexture->EffectiveHeight(flScale), m_flGap),
				flStarWidth, flStarWidth,
				Color(255, 255, 255, 255 * flAlpha)
			);
		}
	}
}