Exemple #1
0
void CHudAmmo::Paint()
{
	C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer();
	if ( !pPlayer )
		return;

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

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

	int iWidth, iHeight;
	GetSize(iWidth, iHeight);

	float flScale = 480.0f/(float)iHeight * hud_ammoscale.GetFloat();

	int iGrenades = 0;
	int iTotalGrenades = GetAmmoDef()->MaxCarry(GetAmmoDef()->Index("grenades"));
	if (pPlayer->m_Shared.m_iStyleSkill != SKILL_TROLL)
		iTotalGrenades = ConVarRef("da_max_grenades").GetInt();

	CWeaponSDKBase* pGrenade = pPlayer->FindWeapon(SDK_WEAPON_GRENADE);
	if (pGrenade)
		iGrenades = pPlayer->GetAmmoCount(pGrenade->GetPrimaryAmmoType());

	if (m_pGrenadeIcon)
	{
		for (int i = 0; i < iGrenades; i++)
		{
			Vector4D vecGrenade = GetGrenadePosition(i);
			m_pGrenadeIcon->DrawSelf(vecGrenade.x, vecGrenade.y, vecGrenade.z, vecGrenade.w, Color(255, 255, 255, 255));
		}
	}

	if (m_pGrenadeEmptyIcon)
	{
		for (int i = iGrenades; i < iTotalGrenades; i++)
		{
			Vector4D vecGrenade = GetGrenadePosition(i);
			m_pGrenadeEmptyIcon->DrawSelf(vecGrenade.x, vecGrenade.y, vecGrenade.z, vecGrenade.w, Color(255, 255, 255, 255));
		}
	}

	if (pPlayer->UseVRHUD())
		return;

	CHudTexture* pTexture = GetTexture();

	if (!pTexture)
		return;

	for (int i = 0; i < m_iAmmo; i++)
	{
		Vector2D vecRound = GetRoundPosition(i);
		pTexture->DrawSelf( vecRound.x, vecRound.y, GetTextureDrawWidth(pTexture, flScale), GetTextureDrawHeight(pTexture, flScale), Color(255, 255, 255, 255) );
	}

	float flFrameTime = gpGlobals->frametime * pPlayer->GetSlowMoMultiplier();

	for (int i = 0; i < m_aRounds.Count(); i++)
	{
		CFlyingRound& oRound = m_aRounds[i];

		if (!oRound.bActive)
			continue;

		if (oRound.vecPosition.y > iHeight+1000)
		{
			oRound.bActive = false;
			continue;
		}

		if (!oRound.pTexture)
		{
			oRound.bActive = false;
			continue;
		}

		oRound.vecPosition += flFrameTime * oRound.vecVelocity;
		oRound.vecVelocity.y += flFrameTime * 2000;
		oRound.flAngle += flFrameTime * oRound.flAngularVelocity;

		SDKViewport::DrawPolygon(oRound.pTexture,
			oRound.vecPosition.x, oRound.vecPosition.y,
			GetTextureDrawWidth(oRound.pTexture, flScale), GetTextureDrawHeight(oRound.pTexture, flScale), oRound.flAngle);
	}

	wchar_t* pszActivate = g_pVGuiLocalize->Find("#DA_HUD_Ammo_Reload");

	if (pszActivate && m_iAmmo == 0 && !pPlayer->GetActiveSDKWeapon()->m_bInReload)
	{
#define WSTRLEN 512
		// replace any key references with bound keys
		wchar_t wszHintLabel[WSTRLEN];
		UTIL_ReplaceKeyBindings( pszActivate, 0, wszHintLabel, sizeof( wszHintLabel ) );

		int iTextWide, iTextTall;
		surface()->GetTextSize( m_hHintFont, wszHintLabel, iTextWide, iTextTall );

		int iWidth, iHeight;
		GetSize(iWidth, iHeight);

		float flRightPadding = scheme()->GetProportionalScaledValueEx(GetScheme(), 40);
		float flBottomPadding = scheme()->GetProportionalScaledValueEx(GetScheme(), 40);

		surface()->DrawSetTextPos( iWidth - iTextWide - flRightPadding, iHeight - flBottomPadding - iTextTall );
		surface()->DrawSetTextColor( Color(255, 0, 0, Oscillate(gpGlobals->curtime, 1)*255) );
		surface()->DrawSetTextFont( m_hHintFont );
		surface()->DrawUnicodeString( wszHintLabel, vgui::FONT_DRAW_NONADDITIVE );
	}}
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)
			);
		}
	}
}