Exemplo n.º 1
0
void ClientModeSDKNormal::OverrideMouseInput( float *x, float *y )
{
	C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer();
	if (!pPlayer)
		return;

	float flSlowMultiplier = RemapValClamped(pPlayer->GetSlowMoMultiplier(), 0.4f, 1, m_slowmodamping.GetFloat(), 1);

	*x *= flSlowMultiplier;
	*y *= flSlowMultiplier;

	*y *= m_verticaldamping.GetFloat();

	C_WeaponSDKBase* pWeapon = pPlayer->GetActiveSDKWeapon();

	if (pWeapon)
	{
		float flAimInMultiplier;
		if (pWeapon->HasAimInSpeedPenalty())
			flAimInMultiplier = RemapValClamped(pPlayer->m_Shared.GetAimIn(), 0, 1, 1, m_aimindamping.GetFloat());
		else
			flAimInMultiplier = RemapValClamped(pPlayer->m_Shared.GetAimIn(), 0, 1, 1, m_partialaimindamping.GetFloat());

		*x *= flAimInMultiplier;
		*y *= flAimInMultiplier;
	}

	BaseClass::OverrideMouseInput(x, y);
}
Exemplo n.º 2
0
Vector2D CHudAmmo::GetRoundPosition(int i)
{
	int iWidth, iHeight;
	GetSize(iWidth, iHeight);

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

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

	CHudTexture* pTexture = GetTexture();
	if ( !pTexture )
		return Vector2D(iWidth - flRightPadding*flScale, iHeight - flBottomPadding*flScale);

	C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer();

	float flSpacing = scheme()->GetProportionalScaledValueEx(GetScheme(), 10*flScale);

	int iMaxClip = pPlayer->GetActiveSDKWeapon()->GetMaxClip1();

	float flTotalWidth = (GetTextureDrawWidth(pTexture, flScale) + flSpacing) * iMaxClip;
	float flTotalSpace = scheme()->GetProportionalScaledValueEx(GetScheme(), 420*flScale);
	if (flTotalWidth > flTotalSpace)
		flSpacing = -scheme()->GetProportionalScaledValueEx(GetScheme(), 5)*flScale;

	if (flSpacing < 0)
	{
		if (i%2 == 0)
			return Vector2D(iWidth - (i+1)*GetTextureDrawWidth(pTexture, flScale) - i*flSpacing - flRightPadding*flScale, iHeight - GetTextureDrawHeight(pTexture, flScale) - (flBottomPadding+10)*flScale);
		else
			return Vector2D(iWidth - (i+1)*GetTextureDrawWidth(pTexture, flScale) - i*flSpacing - flRightPadding*flScale, iHeight - GetTextureDrawHeight(pTexture, flScale) - flBottomPadding*flScale);
	}
	else
		return Vector2D(iWidth - (i+1)*GetTextureDrawWidth(pTexture, flScale) - i*flSpacing - flRightPadding*flScale, iHeight - GetTextureDrawHeight(pTexture, flScale) - flBottomPadding*flScale);
}
//-----------------------------------------------------------------------------
// Purpose: For each panel effect, check if it wants to draw and draw it on
//  this panel/surface if so
//-----------------------------------------------------------------------------
void C_SDKRootPanel::RenderLetterboxing( void )
{
	C_SDKPlayer* pPlayer = C_SDKPlayer::GetLocalOrSpectatedPlayer();
	C_WeaponSDKBase* pWeapon = pPlayer->GetActiveSDKWeapon();

	ConVarRef spec_freeze_time("spec_freeze_time");
	if (pPlayer && !pPlayer->IsAlive() && pPlayer->GetDeathTime() && gpGlobals->curtime < pPlayer->GetDeathTime() + spec_freeze_time.GetFloat())
		RenderDeathFrame();
	else
		m_flKilledByStartTime = 0;

	float flLetterbox = 0.0;
	if (pPlayer)
	{
		if (pPlayer->m_Shared.GetAimIn() > 0 && pWeapon && (pWeapon->FullAimIn() || pWeapon->HasAimInFireRateBonus() || pWeapon->HasAimInRecoilBonus()))
		{
			flLetterbox = pPlayer->m_Shared.GetAimIn()*2;
			if (flLetterbox > 1)
				flLetterbox = 1;
		}

		if (pPlayer->GetSlowMoMultiplier() < 1)
			flLetterbox = std::max(flLetterbox, RemapValClamped(pPlayer->GetSlowMoMultiplier(), 1, 0.8f, 0, 1));
	}

	if (flLetterbox > 0)
	{
		int iWidth = ScreenWidth();
		int iHeight = ScreenHeight();

		int i169Height = iWidth*9/16;
		if (i169Height >= iHeight - 50)
			i169Height = iHeight - 50;
		int iBarHeight = ((iHeight - i169Height)/2)*flLetterbox;

		surface()->DrawSetColor(Color(0, 0, 0, 255*flLetterbox));
		surface()->DrawFilledRect( 0, 0, ScreenWidth(), iBarHeight );
		surface()->DrawFilledRect( 0, ScreenHeight()-iBarHeight, ScreenWidth(), ScreenHeight() );
	}

	float flSlow = 1;
	if (pPlayer)
		flSlow *= pPlayer->GetSlowMoMultiplier();

	if (flSlow < 1)
	{
		surface()->DrawSetColor(Color(0, 0, 255, (int)RemapValClamped(flSlow, 1, 0, 0, 10)));
		surface()->DrawFilledRect( 0, 0, ScreenWidth(), ScreenHeight() );
	}
}
Exemplo n.º 4
0
CHudTexture* CHudAmmo::GetTexture()
{
	C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer();
	if ( !pPlayer )
		return NULL;

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

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

	if (FStrEq(pPlayer->GetActiveSDKWeapon()->GetSDKWpnData().szAmmo1, "9x19mm"))
		return m_p9mmRound;
	else if (FStrEq(pPlayer->GetActiveSDKWeapon()->GetSDKWpnData().szAmmo1, "762x51mm"))
		return m_p762Round;
	else if (FStrEq(pPlayer->GetActiveSDKWeapon()->GetSDKWpnData().szAmmo1, "45acp"))
		return m_p45acpRound;
	else if (FStrEq(pPlayer->GetActiveSDKWeapon()->GetSDKWpnData().szAmmo1, "buckshot"))
		return m_pBuckshotRound;

	return NULL;
}
void CDAHudCrosshair::CalculateCrosshair( void )
{
	C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer();
	if ( !pPlayer )
		return;

	CWeaponSDKBase *pWeapon = pPlayer->GetActiveSDKWeapon();

	if (!pWeapon)
	{
		ResetCrosshair();
		return;
	}

	if ( !pWeapon->ShouldDrawCrosshair() )
	{
		ResetCrosshair();
		return;
	}

	Color clrHUD = Color( 200, 200, 200, 255 );
	clrHUD[3] = 255;
	Color white( 255, 255, 255, 255 );

	if ( pPlayer->m_Shared.GetAimIn() <= 0.5f || !pWeapon->HasAimInRecoilBonus() )
	{ 
		if ( pWeapon->GetWpnData().iconCrosshair )
			SetCrosshair( pWeapon->GetWpnData().iconCrosshair, clrHUD );
		else
			ResetCrosshair();
	}
	else
	{ 
		// zoomed crosshairs
		if ( pWeapon->GetWpnData().iconZoomedCrosshair )
			SetCrosshair( pWeapon->GetWpnData().iconZoomedCrosshair, white );
		else if ( pWeapon->GetWpnData().iconCrosshair )
			SetCrosshair( pWeapon->GetWpnData().iconCrosshair, clrHUD );
		else
			ResetCrosshair();
	}
}
void C_SDKRootPanel::RenderDeathFrame( void )
{
	int iWidth = ScreenWidth();
	int iHeight = ScreenHeight();

	int iTopBarHeight = 150;
	int iBottomBarHeight = 75;

	surface()->DrawSetColor(Color(0, 0, 0, 255));
	surface()->DrawFilledRect( 0, 0, iWidth, iTopBarHeight );
	surface()->DrawFilledRect( 0, iHeight-iBottomBarHeight, iWidth, iHeight );

	if (m_hDeathFrameLarge == vgui::INVALID_FONT)
	{
		vgui::HScheme scheme = vgui::scheme()->GetScheme( "ClientScheme" );
		vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( scheme );
		m_hDeathFrameLarge = pScheme->GetFont("DeathFrameLarge", false);
		m_hDeathFrameMedium = pScheme->GetFont("DeathFrameMedium", false);
		m_hDeathFrameSmall = pScheme->GetFont("DeathFrameSmall", false);
	}

	std::wstring sKilledBy;

	C_SDKPlayer* pPlayer = C_SDKPlayer::GetLocalOrSpectatedPlayer();
	C_SDKPlayer* pKiller = pPlayer->GetKiller();

	if (!m_flKilledByStartTime)
		m_flKilledByStartTime = gpGlobals->curtime;

	float flLerpTime = da_deathframe_lerp_time.GetFloat();

	wchar_t* pszScreenshot = g_pVGuiLocalize->Find("#DA_DeathFrame_Screenshot");

	if (pszScreenshot)
	{
		wchar_t szScreenshot[512];
		UTIL_ReplaceKeyBindings( pszScreenshot, wcslen(pszScreenshot)*sizeof(wchar_t), szScreenshot, sizeof( szScreenshot ) );

		float flXOffset = RemapValClamped(Bias(RemapValClamped(gpGlobals->curtime, m_flKilledByStartTime + 0.5f, m_flKilledByStartTime + 0.5f + flLerpTime, 0, 1), 0.8f), 0, 1, -iWidth*2/3, 0);

		int iWide, iTall;
		surface()->GetTextSize(m_hDeathFrameSmall, pszScreenshot, iWide, iTall);
		surface()->DrawSetTextFont(m_hDeathFrameSmall);
		surface()->DrawSetTextPos(10 + flXOffset, 10);
		surface()->DrawSetTextColor(Color(255, 255, 255, 255));
		surface()->DrawPrintText(szScreenshot, wcslen(szScreenshot));
	}

	if (pKiller != pPlayer)
	{
		wchar_t* pszKilledBy = g_pVGuiLocalize->Find("#DA_DeathFrame_KilledBy");

		float flKilledByXOffset = RemapValClamped(Bias(RemapValClamped(gpGlobals->curtime, m_flKilledByStartTime, m_flKilledByStartTime + flLerpTime, 0, 1), 0.8f), 0, 1, -iWidth*2/3, 0);

		if (pszKilledBy)
		{
			int iWide, iTall;
			surface()->GetTextSize(m_hDeathFrameLarge, pszKilledBy, iWide, iTall);
			surface()->DrawSetTextFont(m_hDeathFrameLarge);
			surface()->DrawSetTextPos(flKilledByXOffset + iWidth/2 - iWide/2, 10);
			surface()->DrawSetTextColor(Color(255, 255, 255, 255));
			surface()->DrawPrintText(pszKilledBy, wcslen(pszKilledBy));
		}

		wchar_t wszPlayerName[MAX_PLAYER_NAME_LENGTH];
		if (pKiller)
			g_pVGuiLocalize->ConvertANSIToUnicode( pKiller->GetPlayerName(), wszPlayerName, sizeof(wszPlayerName) );
		else
		{
			wchar_t* pszTheGround;
			switch (((int)m_flKilledByStartTime)%3) // Effectively a random number.
			{
			case 0:
			default:
				pszTheGround = g_pVGuiLocalize->Find("#DA_DeathFrame_TheGround");
				break;

			case 1:
				pszTheGround = g_pVGuiLocalize->Find("#DA_DeathFrame_SuddenStop");
				break;

			case 2:
				pszTheGround = g_pVGuiLocalize->Find("#DA_DeathFrame_Gravity");
				break;
			}

			if (pszTheGround)
				wcscpy(wszPlayerName, pszTheGround);
			else
				wcscpy(wszPlayerName, L"The Ground");
		}

		int iWide, iTall;
		surface()->GetTextSize(m_hDeathFrameLarge, wszPlayerName, iWide, iTall);
		surface()->DrawSetTextFont(m_hDeathFrameLarge);
		surface()->DrawSetTextPos(flKilledByXOffset + iWidth/2 - iWide/2, 20 + surface()->GetFontTall(m_hDeathFrameLarge));
		surface()->DrawSetTextColor(Color(255, 255, 255, 255));
		surface()->DrawPrintText(wszPlayerName, wcslen(wszPlayerName));
	}

	float flWeaponXOffset = RemapValClamped(Bias(RemapValClamped(gpGlobals->curtime, m_flKilledByStartTime + 0.2f, m_flKilledByStartTime + 0.2f + flLerpTime, 0, 1), 0.8f), 0, 1, iWidth*2/3, 0);

	wchar_t* pszWeaponOfChoice = g_pVGuiLocalize->Find("#DA_DeathFrame_WeaponOfChoice");

	if (pKiller && pszWeaponOfChoice && pKiller->GetActiveSDKWeapon())
	{
		wchar_t* pszWeaponName = g_pVGuiLocalize->Find(pKiller->GetActiveSDKWeapon()->GetPrintName());
		if (pszWeaponName)
		{
			std::wstring sMessage = std::wstring(pszWeaponOfChoice) + pszWeaponName;

			int iWide, iTall;
			surface()->GetTextSize(m_hDeathFrameMedium, sMessage.c_str(), iWide, iTall);
			surface()->DrawSetTextFont(m_hDeathFrameMedium);
			surface()->DrawSetTextPos(flWeaponXOffset + iWidth/2 - iWide/2, iHeight - iTall - 20);
			surface()->DrawSetTextColor(Color(255, 255, 255, 255));
			surface()->DrawPrintText(sMessage.c_str(), sMessage.length());
		}
	}
}
Exemplo n.º 7
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 CDAHudCrosshair::Paint( void )
{
	if ( !m_pCrosshair )
		return;

	if ( !IsCurrentViewAccessAllowed() )
		return;

	m_curViewAngles = CurrentViewAngles();
	m_curViewOrigin = CurrentViewOrigin();

	float x, y;
	x = ScreenWidth()/2;
	y = ScreenHeight()/2;

	bool bObstruction = false;

	C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer();

	if (!UseVR() && pPlayer && pPlayer->IsInThirdPerson() && m_pObstructionCrosshair)
	{
		Vector vecCamera = pPlayer->GetThirdPersonCameraPosition();

		Vector vecShootPosition = pPlayer->Weapon_ShootPosition();
		if (pPlayer->GetActiveSDKWeapon())
			vecShootPosition = pPlayer->GetActiveSDKWeapon()->GetShootPosition(pPlayer);

		Vector vecForward = pPlayer->GetThirdPersonCameraTarget() - vecShootPosition;

		// Now trace to see where the player will hit
		trace_t tr2;
		UTIL_TraceLine( vecShootPosition, vecShootPosition + vecForward * 1000, MASK_SOLID|CONTENTS_DEBRIS|CONTENTS_HITBOX, pPlayer, COLLISION_GROUP_NONE, &tr2 );

		//DebugDrawLine(vecCamera, tr.endpos, 255, 0, 0, true, 0.1f);
		//DebugDrawLine(vecShootPosition, tr2.endpos, 0, 0, 255, true, 0.1f);

		if ((tr2.endpos - pPlayer->GetThirdPersonCameraTarget()).LengthSqr() > 1)
		{
			bObstruction = true;

			Vector vecScreen;

			ScreenTransform( tr2.endpos, vecScreen );

			float x2, y2;

			x2 = ScreenWidth()/2 + 0.5 * vecScreen.x * ScreenWidth() + 0.5;
			y2 = ScreenHeight()/2 - 0.5 * vecScreen.y * ScreenHeight() + 0.5;

			m_pObstructionCrosshair->DrawSelf( 
					x2 - 0.5f * m_pObstructionCrosshair->Width(), 
					y2 - 0.5f * m_pObstructionCrosshair->Height(),
					m_clrCrosshair );
		}
	}

	if (!UseVR())
	{
		m_pCrosshair->DrawSelf( 
				x - 0.5f * m_pCrosshair->Width(), 
				y - 0.5f * m_pCrosshair->Height(),
				bObstruction?Color(128, 128, 128, m_clrCrosshair.a()/2):m_clrCrosshair );
	}

	float flWatchAlphaGoal = (pPlayer->GetSlowMoTime() > 0)?1:0;
	m_flWatchAlpha = Approach(flWatchAlphaGoal, m_flWatchAlpha, gpGlobals->frametime * 3);

	if (m_flWatchAlpha > 0)
	{
		float flValue = (pPlayer->GetSlowMoTime() - gpGlobals->curtime)*60;
		if (flValue < 0)
			flValue = 0;

		int iMinutes = flValue / 60;
		int iSeconds = flValue - iMinutes * 60;

		wchar_t wcsUnicode[6];

		if ( iSeconds < 10 )
			V_snwprintf( wcsUnicode, ARRAYSIZE(wcsUnicode), L"%d:0%d", iMinutes, iSeconds );
		else
			V_snwprintf( wcsUnicode, ARRAYSIZE(wcsUnicode), L"%d:%d", iMinutes, iSeconds );

		surface()->DrawSetTextPos( x  + m_pCrosshair->Width(), y - surface()->GetFontTall(m_hWatchFont)/2 );
		surface()->DrawSetTextColor( Color(m_clrCrosshair.r(), m_clrCrosshair.g(), m_clrCrosshair.b(), m_clrCrosshair.a()*m_flWatchAlpha*0.3) );
		surface()->DrawSetTextFont( m_hWatchFont );
		surface()->DrawUnicodeString( wcsUnicode, vgui::FONT_DRAW_NONADDITIVE );
	}
}