Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions sp/src/game/client/c_baseplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,9 @@ void C_BasePlayer::DetermineVguiInputMode( CUserCmd *pCmd )

// Kill all attack inputs if we're in vgui screen mode
pCmd->buttons &= ~(IN_ATTACK | IN_ATTACK2 | IN_VALIDVGUIINPUT);
#ifdef MAPBASE
pCmd->buttons |= IN_VGUIMODE;
#endif // MAPBASE
return;
}
#else
Expand All @@ -1142,6 +1145,10 @@ void C_BasePlayer::DetermineVguiInputMode( CUserCmd *pCmd )

// Kill all attack inputs if we're in vgui screen mode
pCmd->buttons &= ~(IN_ATTACK | IN_ATTACK2);
#ifdef MAPBASE
pCmd->buttons &= ~(IN_USE | IN_ATTACK3);
pCmd->buttons |= IN_VGUIMODE;
#endif // MAPBASE
return;
}
#endif
Expand Down Expand Up @@ -1206,6 +1213,10 @@ void C_BasePlayer::DetermineVguiInputMode( CUserCmd *pCmd )

// Kill all attack inputs if we're in vgui screen mode
pCmd->buttons &= ~(IN_ATTACK | IN_ATTACK2);
#ifdef MAPBASE
pCmd->buttons &= ~(IN_USE | IN_ATTACK3);
pCmd->buttons |= IN_VGUIMODE;
#endif // MAPBASE
}
}

Expand Down
129 changes: 100 additions & 29 deletions sp/src/game/client/c_vguiscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ extern vgui::IInputInternal *g_InputInternal;
#define VGUI_SCREEN_MODE_RADIUS 80

//Precache the materials
CLIENTEFFECT_REGISTER_BEGIN( PrecacheEffectVGuiScreen )
CLIENTEFFECT_MATERIAL( "engine/writez" )
CLIENTEFFECT_REGISTER_BEGIN(PrecacheEffectVGuiScreen)
CLIENTEFFECT_MATERIAL("engine/writez")
CLIENTEFFECT_REGISTER_END()

#ifdef MAPBASE
C_EntityClassList<C_VGuiScreen> g_VGUIScreenList;
template <> C_VGuiScreen* C_EntityClassList<C_VGuiScreen>::m_pClassList = NULL;
#endif // MAPBASE

// ----------------------------------------------------------------------------- //
// This is a cache of preloaded keyvalues.
Expand Down Expand Up @@ -102,11 +106,19 @@ C_VGuiScreen::C_VGuiScreen()

m_WriteZMaterial.Init( "engine/writez", TEXTURE_GROUP_VGUI );
m_OverlayMaterial.Init( m_WriteZMaterial );

#ifdef MAPBASE
g_VGUIScreenList.Insert(this);
#endif // MAPBASE
}

C_VGuiScreen::~C_VGuiScreen()
{
DestroyVguiScreen();

#ifdef MAPBASE
g_VGUIScreenList.Remove(this);
#endif // MAPBASE
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -416,35 +428,70 @@ void C_VGuiScreen::ClientThink( void )
int px = (int)(u * m_nPixelWidth + 0.5f);
int py = (int)(v * m_nPixelHeight + 0.5f);

#ifndef MAPBASE
// Generate mouse input commands
if ((px != m_nOldPx) || (py != m_nOldPy))
{
g_InputInternal->InternalCursorMoved( px, py );
g_InputInternal->InternalCursorMoved(px, py);

m_nOldPx = px;
m_nOldPy = py;
}

if (m_nButtonPressed & IN_ATTACK)
{
g_InputInternal->SetMouseCodeState( MOUSE_LEFT, vgui::BUTTON_PRESSED );
g_InputInternal->SetMouseCodeState(MOUSE_LEFT, vgui::BUTTON_PRESSED);
g_InputInternal->InternalMousePressed(MOUSE_LEFT);
}
if (m_nButtonPressed & IN_ATTACK2)
{
g_InputInternal->SetMouseCodeState( MOUSE_RIGHT, vgui::BUTTON_PRESSED );
g_InputInternal->InternalMousePressed( MOUSE_RIGHT );
g_InputInternal->SetMouseCodeState(MOUSE_RIGHT, vgui::BUTTON_PRESSED);
g_InputInternal->InternalMousePressed(MOUSE_RIGHT);
}
if ( (m_nButtonReleased & IN_ATTACK) || m_bLoseThinkNextFrame) // for a button release on loosing focus
if ((m_nButtonReleased & IN_ATTACK) || m_bLoseThinkNextFrame) // for a button release on loosing focus
{
g_InputInternal->SetMouseCodeState( MOUSE_LEFT, vgui::BUTTON_RELEASED );
g_InputInternal->InternalMouseReleased( MOUSE_LEFT );
g_InputInternal->SetMouseCodeState(MOUSE_LEFT, vgui::BUTTON_RELEASED);
g_InputInternal->InternalMouseReleased(MOUSE_LEFT);
}
if (m_nButtonReleased & IN_ATTACK2)
{
g_InputInternal->SetMouseCodeState( MOUSE_RIGHT, vgui::BUTTON_RELEASED );
g_InputInternal->InternalMouseReleased( MOUSE_RIGHT );
g_InputInternal->SetMouseCodeState(MOUSE_RIGHT, vgui::BUTTON_RELEASED);
g_InputInternal->InternalMouseReleased(MOUSE_RIGHT);
}
#else
vgui::VPANEL focus = g_InputInternal->GetMouseOver();
// Generate mouse input commands
if ((px != m_nOldPx) || (py != m_nOldPy))
{
g_InputInternal->UpdateCursorPosInternal(px, py);

m_nOldPx = px;
m_nOldPy = py;

focus = pPanel->IsWithinTraverse(px, py, true);
g_InputInternal->SetMouseFocus(focus);
vgui::ivgui()->PostMessage(focus, new KeyValues("CursorMoved", "xpos", px, "ypos", py), NULL);
}

for (int i = 0; i < 2; i++)
{
const int nBit = i ? IN_ATTACK2 : (IN_ATTACK | IN_USE);
const vgui::MouseCode nButton = i ? MOUSE_RIGHT : MOUSE_LEFT;

if ((m_nButtonReleased & nBit) || ((m_nButtonState & nBit) && m_bLoseThinkNextFrame)) // for a button release on loosing focus
{
g_InputInternal->SetMouseCodeState(nButton, vgui::BUTTON_RELEASED);
vgui::ivgui()->PostMessage(focus, new KeyValues("MouseReleased", "code", nButton), NULL);
}
else if (m_nButtonPressed & nBit)
{
g_InputInternal->SetMouseCodeState(nButton, vgui::BUTTON_PRESSED);
vgui::ivgui()->PostMessage(focus, new KeyValues("MousePressed", "code", nButton), NULL);
}
}
#endif // !MAPBASE


if ( m_bLoseThinkNextFrame == true )
{
m_bLoseThinkNextFrame = false;
Expand Down Expand Up @@ -627,36 +674,37 @@ bool C_VGuiScreen::IsInputOnlyToOwner( void )
return (m_fScreenFlags & VGUI_SCREEN_ONLY_USABLE_BY_OWNER) != 0;
}

#ifndef MAPBASE
//-----------------------------------------------------------------------------
//
// Enumator class for finding vgui screens close to the local player
//
//-----------------------------------------------------------------------------
class CVGuiScreenEnumerator : public IPartitionEnumerator
{
DECLARE_CLASS_GAMEROOT( CVGuiScreenEnumerator, IPartitionEnumerator );
DECLARE_CLASS_GAMEROOT(CVGuiScreenEnumerator, IPartitionEnumerator);
public:
virtual IterationRetval_t EnumElement( IHandleEntity *pHandleEntity );
virtual IterationRetval_t EnumElement(IHandleEntity* pHandleEntity);

int GetScreenCount();
C_VGuiScreen *GetVGuiScreen( int index );
C_VGuiScreen* GetVGuiScreen(int index);

private:
CUtlVector< CHandle< C_VGuiScreen > > m_VguiScreens;
};

IterationRetval_t CVGuiScreenEnumerator::EnumElement( IHandleEntity *pHandleEntity )
IterationRetval_t CVGuiScreenEnumerator::EnumElement(IHandleEntity* pHandleEntity)
{
C_BaseEntity *pEnt = ClientEntityList().GetBaseEntityFromHandle( pHandleEntity->GetRefEHandle() );
if ( pEnt == NULL )
C_BaseEntity* pEnt = ClientEntityList().GetBaseEntityFromHandle(pHandleEntity->GetRefEHandle());
if (pEnt == NULL)
return ITERATION_CONTINUE;

// FIXME.. pretty expensive...
C_VGuiScreen *pScreen = dynamic_cast<C_VGuiScreen*>(pEnt);
if ( pScreen )
C_VGuiScreen* pScreen = dynamic_cast<C_VGuiScreen*>(pEnt);
if (pScreen)
{
int i = m_VguiScreens.AddToTail( );
m_VguiScreens[i].Set( pScreen );
int i = m_VguiScreens.AddToTail();
m_VguiScreens[i].Set(pScreen);
}

return ITERATION_CONTINUE;
Expand All @@ -667,10 +715,12 @@ int CVGuiScreenEnumerator::GetScreenCount()
return m_VguiScreens.Count();
}

C_VGuiScreen *CVGuiScreenEnumerator::GetVGuiScreen( int index )
C_VGuiScreen* CVGuiScreenEnumerator::GetVGuiScreen(int index)
{
return m_VguiScreens[index].Get();
}
}
#endif // !MAPBASE



//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -704,18 +754,29 @@ C_BaseEntity *FindNearbyVguiScreen( const Vector &viewPosition, const QAngle &vi
Ray_t lookRay;
lookRay.Init( viewPosition, lookEnd );

#ifndef MAPBASE
// Look for vgui screens that are close to the player
CVGuiScreenEnumerator localScreens;
partition->EnumerateElementsInSphere( PARTITION_CLIENT_NON_STATIC_EDICTS, viewPosition, VGUI_SCREEN_MODE_RADIUS, false, &localScreens );
partition->EnumerateElementsInSphere(PARTITION_CLIENT_NON_STATIC_EDICTS, viewPosition, VGUI_SCREEN_MODE_RADIUS, false, &localScreens);
#endif // !MAPBASE

Vector vecOut, vecViewDelta;

float flBestDist = 2.0f;
C_VGuiScreen *pBestScreen = NULL;
#ifndef MAPBASE
for (int i = localScreens.GetScreenCount(); --i >= 0; )
#else
for (C_VGuiScreen* pScreen = g_VGUIScreenList.m_pClassList; pScreen != NULL; pScreen = pScreen->m_pNext)
#endif // !MAPBASE
{
C_VGuiScreen *pScreen = localScreens.GetVGuiScreen(i);

#ifndef MAPBASE
C_VGuiScreen* pScreen = localScreens.GetVGuiScreen(i);
#else
// Skip if out of PVS
if (pScreen->IsDormant())
continue;
#endif
if ( pScreen->IsAttachedToViewModel() )
continue;

Expand Down Expand Up @@ -865,11 +926,21 @@ vgui::Panel *CVGuiScreenPanel::CreateControlByName(const char *controlName)
//-----------------------------------------------------------------------------
// Purpose: Called when the user presses a button
//-----------------------------------------------------------------------------
void CVGuiScreenPanel::OnCommand( const char *command)
void CVGuiScreenPanel::OnCommand(const char* command)
{
if ( Q_stricmp( command, "vguicancel" ) )
if (Q_stricmp(command, "vguicancel"))
{
engine->ClientCmd( const_cast<char *>( command ) );
#ifdef MAPBASE
if (m_hEntity && m_hEntity->IsServerEntity())
{
KeyValues* pCommand = new KeyValues("EntityCommand");
pCommand->SetInt("entindex", m_hEntity->index);
pCommand->SetString("command_data", command);
engine->ServerCmdKeyValues(pCommand);
}
else
#endif
engine->ClientCmd(const_cast<char*>(command));
}

BaseClass::OnCommand(command);
Expand Down
4 changes: 4 additions & 0 deletions sp/src/game/client/c_vguiscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class C_VGuiScreen : public C_BaseEntity
public:
DECLARE_CLIENTCLASS();

#ifdef MAPBASE
C_VGuiScreen* m_pNext;
#endif // MAPBASE

C_VGuiScreen();
~C_VGuiScreen();

Expand Down
10 changes: 10 additions & 0 deletions sp/src/game/server/baseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,9 @@ class CBaseEntity : public IServerEntity

void ValidateEntityConnections();
void FireNamedOutput( const char *pszOutput, variant_t variant, CBaseEntity *pActivator, CBaseEntity *pCaller, float flDelay = 0.0f );
#ifdef MAPBASE
virtual
#endif
CBaseEntityOutput *FindNamedOutput( const char *pszOutput );
#ifdef MAPBASE_VSCRIPT
void ScriptFireOutput( const char *pszOutput, HSCRIPT hActivator, HSCRIPT hCaller, const char *szValue, float flDelay );
Expand Down Expand Up @@ -864,6 +867,13 @@ class CBaseEntity : public IServerEntity

void SetAIWalkable( bool bBlocksLOS );
bool IsAIWalkable( void );

#ifdef MAPBASE
// Handle a potentially complex command from a client.
// Returns true if the command was handled successfully.
virtual bool HandleEntityCommand(CBasePlayer* pClient, KeyValues* pKeyValues) { return false; }
#endif // MAPBASE

private:
int SaveDataDescBlock( ISave &save, datamap_t *dmap );
int RestoreDataDescBlock( IRestore &restore, datamap_t *dmap );
Expand Down
14 changes: 14 additions & 0 deletions sp/src/game/server/hl2/hl2_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3617,6 +3617,20 @@ void CHL2_Player::UpdateWeaponPosture( void )
{
m_LowerWeaponTimer.Set( .3 );
VPROF( "CHL2_Player::UpdateWeaponPosture-CheckLower" );

#ifdef MAPBASE
if (m_nButtons & IN_VGUIMODE)
{
//We're over a friendly, drop our weapon
if (Weapon_Lower() == false)
{
//FIXME: We couldn't lower our weapon!
}

return;
}
#endif // MAPBASE

Vector vecAim = BaseClass::GetAutoaimVector( AUTOAIM_SCALE_DIRECT_ONLY );

const float CHECK_FRIENDLY_RANGE = 50 * 12;
Expand Down
Loading