Esempio n. 1
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;
		}
	}
	
}