const char* C_ASW_Button_Area::GetHackIconText(C_ASW_Marine *pUser)
{
	if (m_bIsInUse)
	{
		C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
		if (pPlayer && pPlayer->GetViewMarine() && pPlayer->GetViewMarine()->m_hUsingEntity.Get() == this)
		{
			return "#asw_exit_panel";
		}
	}
	return "#asw_hack_panel";
}
bool CASWHudUseArea::AddUseIconsFor(C_BaseEntity* pEnt)
{
	C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if (!pPlayer)
		return false;
	C_ASW_Marine *pMarine = pPlayer->GetViewMarine();
	if (!pMarine)
		return false;

	if (g_asw_iGUIWindowsOpen > 0)	// don't show use icons while an info message is up
		return false;

	IASW_Client_Usable_Entity* pUsable = dynamic_cast<IASW_Client_Usable_Entity*>(pEnt);
	if (pUsable)
	{
		ASWUseAction action;
		if (!pUsable->GetUseAction(action, pMarine))
			return false;

		if (m_pUseIcon)
			m_pUseIcon->SetUseAction(action);

		pPlayer->UseIconTarget[0] = action.UseTarget;

		if (m_pUseIcon && m_pUseIcon->m_pUseText && m_pUseIcon->m_CurrentAction == action)
		{
			if (m_pCustomPaintPanel)
				m_pCustomPaintPanel->m_hUsable = pUsable->GetEntity();
		}
		return true;
	}	
	return false;
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
// Purpose: Hide all the ASW hud in certain cases
//-----------------------------------------------------------------------------
bool CASW_HudElement::ShouldDraw( void )
{
	if (!CHudElement::ShouldDraw())
		return false;

	if (engine->IsLevelMainMenuBackground())
		return false;

	if (ASWGameRules())
	{
		if (ASWGameRules()->IsIntroMap() || ASWGameRules()->IsOutroMap())
			return false;
	}

	C_ASW_Player *pASWPlayer = C_ASW_Player::GetLocalASWPlayer();
	C_ASW_Marine *pMarine = pASWPlayer ? pASWPlayer->GetViewMarine() : NULL;
	// hide things due to turret control
	if ( ( m_iHiddenBits & HIDEHUD_REMOTE_TURRET ) && pMarine && pMarine->IsControllingTurret() )
		return false;
	if ( ( m_iHiddenBits & HIDEHUD_PLAYERDEAD ) && ( !pMarine || pMarine->GetHealth() <= 0 ) )
		return false;

	if ( !asw_draw_hud.GetBool() )
		return false;

	return true;
}
void CASW_Hud_Powerups::OnThink()
{
	//SetAlpha( 0 );

	C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if (!pPlayer)
		return;

	C_ASW_Marine *pMarine = pPlayer->GetViewMarine();
	if ( !pMarine )
		return;

	UpdatePowerupIcon( pMarine );	
}
void C_Prop_ASW_Fade::ClientThink()
{
	BaseClass::ClientThink();

	C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if (!pPlayer)
	{
		return;
	}

	C_ASW_Marine *pMarine = pPlayer->GetViewMarine();

	bool bFade = pPlayer->GetASWControls() == 1 && pMarine && pMarine->GetAbsOrigin().z <= m_vecFadeOrigin.z;
	byte target = bFade ? m_nFadeOpacity : m_nNormalOpacity;
	byte prev = bFade ? m_nNormalOpacity : m_nFadeOpacity;
	if (bFade != m_bFaded)
	{
		m_bFaded = bFade;
		m_flInterpStart = gpGlobals->curtime - fabs((m_nFadeOpacity != m_nNormalOpacity) ? asw_fade_duration.GetFloat() * (GetRenderAlpha() - prev) / (m_nFadeOpacity - m_nNormalOpacity) : asw_fade_duration.GetFloat());
		m_flInterpStart = MAX(0, m_flInterpStart);
	}

	if ( pPlayer->GetASWControls() != m_iLastControls || pMarine != m_hLastMarine.Get() )
	{
		m_iLastControls = pPlayer->GetASWControls();
		m_hLastMarine = pMarine;
		m_flInterpStart = 0;
		SetRenderAlpha(target);
		return;
	}

	if (m_flInterpStart + asw_fade_duration.GetFloat() <= gpGlobals->curtime)
	{
		SetRenderAlpha(target);
	}
	else if (m_flInterpStart > 0)
	{
		SetRenderAlpha(Lerp((gpGlobals->curtime - m_flInterpStart) / asw_fade_duration.GetFloat(), prev, target));
	}
}
void CASWHudCrosshair::GetCurrentPos( int &x, int &y )
{
	C_ASW_Player* pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if ( !pPlayer )
		return;

	C_ASW_Marine *pMarine = pPlayer->GetViewMarine();
	bool bControllingTurret = (pMarine && pMarine->IsControllingTurret());

	m_pTurretTextTopLeft->SetVisible( bControllingTurret );
	m_pTurretTextTopRight->SetVisible( bControllingTurret );
	m_pTurretTextTopLeftGlow->SetVisible( bControllingTurret );
	m_pTurretTextTopRightGlow->SetVisible( bControllingTurret );

	if ( !bControllingTurret )
	{
		ASWInput()->GetSimulatedFullscreenMousePos( &x, &y );
	}
	else
	{
		x = ScreenWidth() / 2;
		y = ScreenHeight() / 2;
	}
}
void CASWHudUseArea::Paint()
{
	VPROF_BUDGET( "CASWHudUseArea::Paint", VPROF_BUDGETGROUP_ASW_CLIENT );
	GetSize(m_iFrameWidth,m_iFrameHeight);
	m_iFrameWidth = ScreenWidth();
	BaseClass::Paint();

	C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if (!pPlayer)
		return;

	C_ASW_Marine *pMarine = pPlayer->GetViewMarine();
	if (!pMarine)
		return;
	int r, g, b;
	r = g = b = 255;
	if (asw_debug_hud.GetBool())
	{
		char cbuffer[20];
		Q_snprintf(cbuffer, sizeof(cbuffer), "Usable = %d", pPlayer->m_iUseEntities);		
		g_pMatSystemSurface->DrawColoredText(m_hUseAreaFont, 0, 0, r, g, 
				b, 200, &cbuffer[0]);
	}
	
	for (int k=0; k<3; k++)
	{
		pPlayer->UseIconTarget[k] = NULL;
	}

	m_iNumUseIcons = 0;
	pPlayer->FindUseEntities();

	// don't add any icons if our marine is dead
	if (!pPlayer->GetViewMarine() || !pPlayer->GetViewMarine()->IsAlive())
	{
		pPlayer->UseIconTarget[0] = NULL;
		if (m_pUseIcon)
			m_pUseIcon->ClearUseAction();
		return;
	}

	int iNumToDraw = MIN(1, pPlayer->m_iUseEntities);
	int iDrew = 0;
	for (int i=0; i<iNumToDraw; i++)
	{	
		if (AddUseIconsFor(pPlayer->GetUseEntity(i)))
			iDrew++;
		
		if (asw_debug_hud.GetBool())
		{
			char buffer[20];
			C_BaseEntity *pEnt = pPlayer->GetUseEntity(i);
			Q_snprintf(buffer, sizeof(buffer), "Use:%d", pEnt->entindex());
			//int wide = g_pMatSystemSurface->DrawTextLen(m_hUseAreaFont, &buffer[0]);
			int tall = vgui::surface()->GetFontTall( m_hUseAreaFont );
			float xPos		= 0;
			float yPos		= (i+1) * tall;
			
			// actual text
			g_pMatSystemSurface->DrawColoredText(m_hUseAreaFont, xPos, yPos, r, g, 
				b, 200, &buffer[0]);
		}
	}
	if (iDrew < 1)
	{
		if (m_pUseIcon)
			m_pUseIcon->ClearUseAction();
	}
}
void CASWHudCrosshair::OnThink()
{
	C_ASW_Player* pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if ( !pPlayer )
		return;

	PaintReloadProgressBar();

	C_ASW_Marine *pMarine = pPlayer->GetViewMarine();
	bool bControllingTurret = (pMarine && pMarine->IsControllingTurret());
	if (!bControllingTurret)
		return;

	C_ASW_Remote_Turret *pTurret = pMarine->GetRemoteTurret();
	if (!pTurret)
		return;

	Vector vecWeaponPos = pTurret->GetAbsOrigin();
	QAngle angWeapon = pTurret->EyeAngles();
	Vector vecWeaponDir;
	AngleVectors(angWeapon, &vecWeaponDir);

	// increase lock time of all targets and discard out of range/facing ones
	for (int k=0;k<ASW_MAX_TURRET_TARGETS;k++)
	{
		C_BaseEntity *pEnt = m_TurretTarget[k].Get();
		if (pEnt)
		{
			// validate the target
			bool bValid = true;
			Vector diff = pEnt->GetAbsOrigin() - vecWeaponPos;
			if (diff.Length() > ASW_TURRET_TARGET_RANGE || !pEnt->ShouldDraw())				
			{
				bValid = false;
			}
			else
			{
				diff.NormalizeInPlace();
				float flDot = diff.Dot(vecWeaponDir);
				if (flDot < asw_turret_dot.GetFloat())
					bValid = false;
					
			}
			// fade it in or out appropriately
			if (bValid)
			{
				if (m_fTurretTargetLock[k] < 1.0f)
				{
					m_fTurretTargetLock[k] += gpGlobals->frametime * 2;
					if (m_fTurretTargetLock[k] > 1.0f)
						m_fTurretTargetLock[k] = 1.0f;
				}
			}
			else
			{
				if (m_fTurretTargetLock[k] <= 0)
				{
					m_TurretTarget[k] = NULL;
				}
				else
				{
					m_fTurretTargetLock[k] -= gpGlobals->frametime * 2;
					if (m_fTurretTargetLock[k] < 0.0f)
						m_fTurretTargetLock[k] = 0.0f;
				}
			}
		}
	}

	// check for adding new targets to the array
	for ( int i = 0; i < IASW_Client_Aim_Target::AutoList().Count(); i++ )
	{
		IASW_Client_Aim_Target *pAimTarget = static_cast< IASW_Client_Aim_Target* >( IASW_Client_Aim_Target::AutoList()[ i ] );
		C_BaseEntity *pEnt = pAimTarget->GetEntity();
		if (!pEnt || !pAimTarget->IsAimTarget() || !pEnt->ShouldDraw())
			continue;
		
		// check he's in range
		Vector vecAlienPos = pEnt->WorldSpaceCenter();
		float flAlienDist = vecAlienPos.DistTo(vecWeaponPos);		
		if (flAlienDist > ASW_TURRET_TARGET_RANGE)
			continue;

		// check it's in front of us
		Vector dir = vecAlienPos - vecWeaponPos;
		dir.NormalizeInPlace();
		if (dir.Dot(vecWeaponDir) <= asw_turret_dot.GetFloat())
			continue;

		// we've got a possible target, add him to the list if he's not in there already
		bool bAlreadyInArray = false;
		int iSpace = -1;
		for (int k=0;k<ASW_MAX_TURRET_TARGETS;k++)
		{
			if (m_TurretTarget[k].Get() == pEnt)
			{
				bAlreadyInArray = true;
				break;
			}
			if (iSpace == -1 && m_TurretTarget[k].Get() == NULL)
				iSpace = k;
		}

		if (bAlreadyInArray)
			continue;

		if (iSpace != -1)
		{
			m_TurretTarget[iSpace] = pEnt;
			m_fTurretTargetLock[iSpace] = 0;
		}
	}
}
void CASWHudCrosshair::PaintTurretTextures()
{
	// draw border in centre of screen
	//int h = ScreenHeight();
	//int w = h * 1.333333f;
	//int x = (ScreenWidth() * 0.5f) - (w * 0.5f);
	//int y = 0;

	surface()->DrawSetColor(Color(255,255,255,255));

	/*
	int tx = YRES( 5 );
	int ty = YRES( 5 );
	vgui::surface()->DrawSetTextFont( m_hTurretFont );
	vgui::surface()->DrawSetTextColor( 255, 255, 255, 200 );
	vgui::surface()->DrawSetTextPos( tx, ty );

	int nFontTall = vgui::surface()->GetFontTall( m_hTurretFont );

	wchar_t szconverted[ 1024 ];
	g_pVGuiLocalize->ConvertANSIToUnicode( "#asw_turret_text_top_left", szconverted, sizeof( szconverted )  );
	vgui::surface()->DrawPrintText( szconverted, wcslen( szconverted ) );

	ty = ScreenHeight() - nFontTall * 8 - YRES( 100 );
	vgui::surface()->DrawSetTextPos( tx, ty );
	g_pVGuiLocalize->ConvertANSIToUnicode( "#asw_turret_text_lower_left", szconverted, sizeof( szconverted )  );
	vgui::surface()->DrawPrintText( szconverted, wcslen( szconverted ) );
	*/

	// draw black boxes either side
	//if (m_nBlackBarTexture != -1)
	//{
		//surface()->DrawSetTexture(m_nBlackBarTexture);
		//surface()->DrawTexturedRect(0, y, x, y + h);
		//surface()->DrawTexturedRect(x + w, y, x, y + h);
	//}

	// draw fancy brackets over all turret targets
	float fScale = (ScreenHeight() / 768.0f);
	int iBSize = fScale * 32.0f;
	for (int i=0;i<ASW_MAX_TURRET_TARGETS;i++)
	{
		C_BaseEntity *pEnt = m_TurretTarget[i];
		if (!pEnt)
			continue;

		// distance of each bracket part from the ent
		float fDist = fScale * 200.0f * (1.0f - m_fTurretTargetLock[i]);
		
		Vector pos = (pEnt->WorldSpaceCenter() - pEnt->GetAbsOrigin()) + pEnt->GetRenderOrigin();
		Vector screenPos;
		debugoverlay->ScreenPosition( pos, screenPos );
		surface()->DrawSetColor(Color(255,255,255,255.0f * m_fTurretTargetLock[i] ));

		surface()->DrawSetTexture(m_nLeftBracketTexture);
		int bx = screenPos[0] - fDist;
		int by = screenPos[1] - fDist;
		surface()->DrawTexturedRect(bx - iBSize, by - iBSize, bx + iBSize, by + iBSize);

		surface()->DrawSetTexture(m_nRightBracketTexture);
		bx = screenPos[0] + fDist;
		by = screenPos[1] - fDist;
		surface()->DrawTexturedRect(bx - iBSize, by - iBSize, bx + iBSize, by + iBSize);

		surface()->DrawSetTexture(m_nLowerBracketTexture);
		bx = screenPos[0];
		by = screenPos[1] + fDist;
		surface()->DrawTexturedRect(bx - iBSize, by - iBSize, bx + iBSize, by + iBSize);
	}

	// draw crosshair
	C_ASW_Player* pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if ( pPlayer )
	{
		C_ASW_Marine *pMarine = pPlayer->GetViewMarine();
		bool bControllingTurret = (pMarine && pMarine->IsControllingTurret());
		if (bControllingTurret)
		{
			C_ASW_Remote_Turret *pTurret = pMarine->GetRemoteTurret();
			if (pTurret)
			{
				Vector vecWeaponSrc = pTurret->GetTurretMuzzlePosition();
				QAngle angFacing = pTurret->EyeAngles();
				Vector vecWeaponDir;
				AngleVectors(angFacing, &vecWeaponDir);

				// trace along until we hit something
				trace_t tr;
				UTIL_TraceLine(vecWeaponSrc, vecWeaponSrc + vecWeaponDir * 1200,	// fog range of the turret
					MASK_SHOT, pTurret, COLLISION_GROUP_NONE, &tr);
				//Msg("Tracing from %s ", VecToString(vecWeaponSrc));
				//Msg("at angle %s\n", VecToString(angFacing));
				
				Vector pos = tr.DidHit() ? tr.endpos : vecWeaponSrc + vecWeaponDir * 1200;
				Vector screenPos;
				debugoverlay->ScreenPosition( pos, screenPos );

				// paint a crosshair at that spot
				surface()->DrawSetColor(Color(255,255,255,255));
				surface()->DrawSetTexture(m_nTurretCrosshair);
				surface()->DrawTexturedRect(screenPos[0] - iBSize, screenPos[1] - iBSize,	// shift it up a bit to match where the gun actually fires (not sure why it's not matched already!)
											screenPos[0] + iBSize, screenPos[1] + iBSize);
			}
		}
	}

	// draw interlace/noise overlay
	if (m_nTurretTexture!=-1)
	{
		surface()->DrawSetColor(Color(255,255,255,255));
		surface()->DrawSetTexture(m_nTurretTexture);
		surface()->DrawTexturedRect(0, 0, ScreenWidth(), ScreenHeight());
	}
}
void CASWHudCrosshair::Paint( void )
{
	VPROF_BUDGET( "CASWHudCrosshair::Paint", VPROF_BUDGETGROUP_ASW_CLIENT );
	if ( !crosshair.GetBool() )
		return;

	if ( engine->IsDrawingLoadingImage() || engine->IsPaused() || !engine->IsActiveApp() )
		return;
	
	C_ASW_Player* pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if ( !pPlayer )
		return;

	if ( pPlayer->GetFlags() & FL_FROZEN )
		return;

	if ( pPlayer->entindex() != render->GetViewEntity() )
		return;

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

	C_ASW_Marine *pMarine = pPlayer->GetViewMarine();
	bool bControllingTurret = (pMarine && pMarine->IsControllingTurret());
	if ( bControllingTurret )
	{
		PaintTurretTextures();
		return;	// don't draw the normal cross hair in addition
	}

	int x, y;
	GetCurrentPos( x, y );

	int nCrosshair = GetCurrentCrosshair( x, y );

	if ( nCrosshair == m_nCrosshairTexture )
	{
		if ( pPlayer->IsSniperScopeActive() )
		{
			DrawSniperScope( x, y );
		}
		else
		{
			if ( pPlayer->GetASWControls() != 1 )
				return;
			DrawDirectionalCrosshair( x, y, YRES( asw_crosshair_progress_size.GetInt() ) );
		}
	}
	else if ( nCrosshair != -1 )
	{
		const float fCrosshairScale = 1.0f;
		int w = YRES( 20 ) * fCrosshairScale;
		int h = YRES( 20 ) * fCrosshairScale;
		surface()->DrawSetColor( m_clrCrosshair );
		surface()->DrawSetTexture( nCrosshair );
		surface()->DrawTexturedRect( x - w, y - h, x + w, y + h );
	}

	// icons attached to the cursor
	x += 32; y += 16;	// move them down and to the right a bit
	if ( m_bShowGiveAmmo )
	{
		// todo: this text should in the ammo report tooltip?
		const wchar_t *ammoName = g_pVGuiLocalize->Find(GetAmmoName(m_iShowGiveAmmoType));
		DrawAttachedIcon(m_nGiveAmmoTexture, x, y, ammoName);
	}
	else if (m_bShowGiveHealth)
	{
		DrawAttachedIcon(m_nGiveHealthTexture, x, y);
	}
}