void CASW_Weapon_Welder::UpdateDoorWeldingEffects( void )
{
	if ( !m_bIsFiring || !GetMarine() || !GetMarine()->GetMarineResource() )
	{
		RemoveWeldingEffects();
		StopWelderSound();
		return;
	}

	C_ASW_Door* pDoor = GetMarine()->GetMarineResource()->m_hWeldingDoor.Get();
	if ( !pDoor || pDoor->IsOpen() )
	{
		RemoveWeldingEffects();
		StopWelderSound();
		return;
	}

	StartWelderSound();

	if ( !m_hWeldEffects || m_bWeldSealLast != m_bWeldSeal )
	{
		CreateWeldingEffects( pDoor );
	}

	if ( m_hWeldEffects )
	{
		m_hWeldEffects->SetControlPoint( 0, pDoor->GetWeldFacingPoint( GetMarine() ) );
		m_hWeldEffects->SetControlPointForwardVector( 0, pDoor->GetSparkNormal( GetMarine() ) );
	}

	m_bWeldSealLast = m_bWeldSeal;
}
Esempio n. 2
0
void CASWHudHealth::OnThink()
{
	if ( asw_door_healthbars.GetInt() == 0 )
		return;

	MDLCACHE_CRITICAL_SECTION();

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

	if ( asw_door_healthbars.GetInt() == 1 )
	{
		if ( !m_pDoorTooltip[0] )
		{
			C_ASW_Door* pDoor = C_ASW_Door::GetDoorNear( ASWInput()->GetCrosshairAimingPos() );
			if (pDoor)	// check for creating the window to report a door's health if we mouse over it
			{						
				m_pDoorTooltip[0] = new CASW_VGUI_Door_Tooltip( GetParent(), "DoorTooltip");
				vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFile("resource/SwarmSchemeNew.res", "SwarmSchemeNew");
				m_pDoorTooltip[0]->SetScheme(scheme);
				m_pDoorTooltip[0]->SetAlpha(0);
				m_pDoorTooltip[0]->m_bShowDoorUnderCursor = true;
			}
		}
		return;
	}

	// find all doors on-screen
	int iCurrentTooltip = 0;
	for ( int i=0; i<g_ClientDoorList.Count() && iCurrentTooltip < MAX_DOOR_HEALTH_BARS ;i++ )
	{
		C_ASW_Door *pDoor = g_ClientDoorList[i];
		int iDoorType = 0;
		if ( !pDoor || pDoor->GetHealthFraction(iDoorType) <= 0.0f|| pDoor->GetHealthFraction(iDoorType) >= 1.0f || pDoor->IsDormant() || pDoor->IsOpen() )
			continue;

		// assign a tooltip panel to show this door's health
		if ( m_pDoorTooltip[iCurrentTooltip] == NULL )
		{
			m_pDoorTooltip[iCurrentTooltip] = new CASW_VGUI_Door_Tooltip( GetParent(), "DoorTooltip");
			vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFile("resource/SwarmSchemeNew.res", "SwarmSchemeNew");
			m_pDoorTooltip[iCurrentTooltip]->SetScheme(scheme);
			m_pDoorTooltip[iCurrentTooltip]->SetAlpha(0);
		}

		if ( !m_pDoorTooltip[iCurrentTooltip] )
			continue;

		int mx, my;
		if ( m_pDoorTooltip[iCurrentTooltip]->GetDoorHealthBarPosition( pDoor, mx, my ) )
		{
			m_pDoorTooltip[iCurrentTooltip]->SetDoor( pDoor );
			iCurrentTooltip++;
		}
	}
}
Esempio n. 3
0
C_ASW_Door* C_ASW_Door::GetDoorNear(Vector vecSrc)
{
	for (int i=0;i<g_ClientDoorList.Count();i++)
	{			
		C_ASW_Door *pEnt = g_ClientDoorList[i];
		int iDoorType;
		if (!pEnt || pEnt->GetHealth() <= 0 || pEnt->GetHealthFraction(iDoorType) >= 1.0f)
			continue;

		Vector mins, maxs;
		
		// get the size of the door
		pEnt->GetRenderBoundsWorldspace(mins,maxs);

		// pull out all 8 corners of this volume
		Vector worldPos[8];
		Vector screenPos[8];
		worldPos[0] = mins;
		worldPos[1] = mins; worldPos[1].x = maxs.x;
		worldPos[2] = mins; worldPos[2].y = maxs.y;
		worldPos[3] = mins; worldPos[3].z = maxs.z;
		worldPos[4] = mins;
		worldPos[5] = maxs; worldPos[5].x = mins.x;
		worldPos[6] = maxs; worldPos[6].y = mins.y;
		worldPos[7] = maxs; worldPos[7].z = mins.z;

		// convert them to screen space
		for (int k=0;k<8;k++)
		{
			debugoverlay->ScreenPosition( worldPos[k], screenPos[k] );
		}

		// find the rectangle bounding all screen space points
		Vector topLeft = screenPos[0];
		Vector bottomRight = screenPos[0];
		for (int k=0;k<8;k++)
		{
			topLeft.x = MIN(screenPos[k].x, topLeft.x);
			topLeft.y = MIN(screenPos[k].y, topLeft.y);
			bottomRight.x = MAX(screenPos[k].x, bottomRight.x);
			bottomRight.y = MAX(screenPos[k].y, bottomRight.y);
		}
		int BracketSize = 5;	// todo: set by screen res?

		// pad it a bit
		topLeft.x -= BracketSize * 2;
		topLeft.y -= BracketSize * 2;
		bottomRight.x += BracketSize * 2;
		bottomRight.y += BracketSize * 2;

		// check if the cursor is inside this
		int x, y;
		vgui::input()->GetCursorPos( x, y );

		if (x >= topLeft.x && x <= bottomRight.x &&
			y >= topLeft.y && y <= bottomRight.y)
		{
			return pEnt;
		}	
	}

	return NULL;
}
void CASW_VGUI_Door_Tooltip::OnThink()
{
	MDLCACHE_CRITICAL_SECTION();
	
	C_ASW_Player* pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if ( pPlayer && m_bShowDoorUnderCursor )
	{
		C_ASW_Door* pDoorUnderCursor = C_ASW_Door::GetDoorNear( ASWInput()->GetCrosshairAimingPos() );
		if (pDoorUnderCursor && pDoorUnderCursor->IsOpen())	// don't show open doors
			pDoorUnderCursor = NULL;
		SetDoor(pDoorUnderCursor);		
	}
	// fade in/out as the door changes
	if (m_bQueuedDoor)
	{
		if (GetAlpha() <= 0)
		{
			m_hDoor = m_hQueuedDoor;			
			m_hQueuedDoor = NULL;
			m_bQueuedDoor = false;
			m_bDoingSlowFade = false;
			m_fNextUpdateTime = gpGlobals->curtime;
			if (GetDoor())
				vgui::GetAnimationController()->RunAnimationCommand(this, "Alpha", 200, 0, ASW_HEALTH_REPORT_FADE_TIME, vgui::AnimationController::INTERPOLATOR_LINEAR);
		}
		else if (GetAlpha() >= 200)
		{
			if (m_hQueuedDoor.Get() == NULL)
			{
				if (!m_bDoingSlowFade)
				{
					m_bDoingSlowFade = true;
					float delay = 0; // 1.5f
					vgui::GetAnimationController()->RunAnimationCommand(this, "Alpha", 0, delay, ASW_HEALTH_REPORT_FADE_TIME * 3, vgui::AnimationController::INTERPOLATOR_LINEAR);
				}
			}
			else
			{
				vgui::GetAnimationController()->RunAnimationCommand(this, "Alpha", 0, 0, ASW_HEALTH_REPORT_FADE_TIME, vgui::AnimationController::INTERPOLATOR_LINEAR);
				m_bDoingSlowFade = false;
			}
		}
		// if we're doing a slow fade out but the player has now mouse overed another door, do the fade quickly
		if (m_bDoingSlowFade && m_hQueuedDoor.Get() != NULL)
		{
			vgui::GetAnimationController()->RunAnimationCommand(this, "Alpha", 0, 0, ASW_HEALTH_REPORT_FADE_TIME, vgui::AnimationController::INTERPOLATOR_LINEAR);
			m_bDoingSlowFade = false;
		}
	}
	// check for updating health
	C_ASW_Door* pDoor = GetDoor();
	if (gpGlobals->curtime >= m_fNextUpdateTime && pDoor)
	{
		// set the health label accordingly
		int health = pDoor->GetHealth();

		if (health != m_iOldDoorHealth)
		{
			m_iOldDoorHealth = health;
			m_fDoorHealthFraction = pDoor->GetHealthFraction(m_iDoorType);
		}
		m_fNextUpdateTime = gpGlobals->curtime + 0.05f;
	}

	// reposition	
	if (pDoor)
	{	
		int mx, my, iDoorType;	
		if ( pDoor->IsAlive() && pDoor->GetHealthFraction(iDoorType) < 1.0f && !pDoor->IsOpen() && !pDoor->IsDormant() && GetDoorHealthBarPosition( pDoor, mx, my ) )
		{
			mx = clamp(mx, 0, ScreenWidth() - GetWide());
			my = clamp(my, 0, ScreenHeight() - GetTall());

			SetPos(mx, my);
		}
		else
		{
			SetDoor( NULL );
			return;
		}
	}
	
}