initial
This commit is contained in:
72
game/client/gameui/nuggets/ui_application.cpp
Normal file
72
game/client/gameui/nuggets/ui_application.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
//=========== (C) Copyright Valve, L.L.C. All rights reserved. ===========
|
||||
|
||||
#include "cbase.h"
|
||||
#include "ui_nugget.h"
|
||||
|
||||
#include "vstdlib/iprocessutils.h"
|
||||
#include "../uigamedata.h"
|
||||
|
||||
class CUiNuggetApplication : public CUiNuggetBase
|
||||
{
|
||||
DECLARE_NUGGET_FN_MAP( CUiNuggetApplication, CUiNuggetBase );
|
||||
|
||||
NUGGET_FN( Quit )
|
||||
{
|
||||
// We need to quit the app
|
||||
if ( IsPC() )
|
||||
{
|
||||
engine->ClientCmd( "quit" );
|
||||
}
|
||||
|
||||
// X360 can quit in demo mode
|
||||
if ( IsGameConsole() )
|
||||
{
|
||||
engine->ExecuteClientCmd( "demo_exit" );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NUGGET_FN( ResumeGame )
|
||||
{
|
||||
engine->ClientCmd("gameui_hide");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NUGGET_FN( ExitToMainMenu )
|
||||
{
|
||||
engine->ExecuteClientCmd( "gameui_hide" );
|
||||
|
||||
if ( IMatchSession *pMatchSession = g_pMatchFramework->GetMatchSession() )
|
||||
{
|
||||
// Closing an active session results in disconnecting from the game.
|
||||
g_pMatchFramework->CloseSession();
|
||||
}
|
||||
else
|
||||
{
|
||||
// On PC people can be playing via console bypassing matchmaking
|
||||
// and required session settings, so to leave game duplicate
|
||||
// session closure with an extra "disconnect" command.
|
||||
engine->ExecuteClientCmd( "disconnect" );
|
||||
}
|
||||
|
||||
engine->ExecuteClientCmd( "gameui_activate" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NUGGET_FN( SteamOverlayCommand )
|
||||
{
|
||||
#ifndef _GAMECONSOLE
|
||||
BaseModUI::CUIGameData::Get()->ExecuteOverlayCommand( args->GetString( "command" ) );
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NUGGET_FN( LaunchExternalApp )
|
||||
{
|
||||
int nExitCode = g_pProcessUtils ? g_pProcessUtils->SimpleRunProcess( args->GetString( "command" ) ) : -1;
|
||||
return new KeyValues( "", "code", nExitCode );
|
||||
}
|
||||
};
|
||||
|
||||
UI_NUGGET_FACTORY_SINGLETON( CUiNuggetApplication, "app" );
|
31
game/client/gameui/nuggets/ui_loadingprogress.cpp
Normal file
31
game/client/gameui/nuggets/ui_loadingprogress.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
//=========== (C) Copyright Valve, L.L.C. All rights reserved. ===========
|
||||
|
||||
#include "cbase.h"
|
||||
#include "ui_nugget.h"
|
||||
|
||||
class CUiNuggetLoadingProgress : public CUiNuggetBase
|
||||
{
|
||||
public:
|
||||
CUiNuggetLoadingProgress()
|
||||
{
|
||||
m_pUiNuggetData->SetString( "map", "" );
|
||||
m_pUiNuggetData->SetFloat( "progress", 0.0f );
|
||||
}
|
||||
|
||||
DECLARE_NUGGET_FN_MAP( CUiNuggetLoadingProgress, CUiNuggetBase );
|
||||
|
||||
NUGGET_BROADCAST_FN( OnLevelLoadingProgress )
|
||||
{
|
||||
m_pUiNuggetData->MergeFrom( args, KeyValues::MERGE_KV_BORROW );
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool ShouldDeleteOnLastScreenDisconnect()
|
||||
{
|
||||
// bad to try to delete a static.
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
static CUiNuggetLoadingProgress g_nugget_loadingprogress;
|
||||
UI_NUGGET_FACTORY_GLOBAL_INSTANCE( CUiNuggetLoadingProgress, &g_nugget_loadingprogress, "loadingprogress" );
|
63
game/client/gameui/nuggets/ui_matchevents.cpp
Normal file
63
game/client/gameui/nuggets/ui_matchevents.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
//=========== (C) Copyright Valve, L.L.C. All rights reserved. ===========
|
||||
|
||||
#include "cbase.h"
|
||||
#include "ui_nugget.h"
|
||||
#include "matchmaking/imatchframework.h"
|
||||
|
||||
class CUiNuggetMatchEvents : public CUiNuggetBase, IMatchEventsSink
|
||||
{
|
||||
DECLARE_NUGGET_FN_MAP( CUiNuggetMatchEvents, CUiNuggetBase );
|
||||
|
||||
virtual void OnEvent( KeyValues *pEvent )
|
||||
{
|
||||
BroadcastEventToScreens( pEvent );
|
||||
return;
|
||||
|
||||
#if SCRIPTS_NEED_EVENT_NAMES_WITH_BASIC_CHARSET
|
||||
// In case scripts cannot define function names
|
||||
// associations with any characters, then we'll
|
||||
// need to do some work to make event names conform
|
||||
// with those scripts.
|
||||
//
|
||||
// In lua we can easily do any member function names:
|
||||
/*
|
||||
mainmenu["Command::Game::SampleCmd"] = function(self, params)
|
||||
print( "Command::Game::SampleCmd" )
|
||||
print( self.extraPieceOfData )
|
||||
end
|
||||
*/
|
||||
//
|
||||
// Fix the event name for scripting:
|
||||
char chEventName[256] = {0}, *pch = chEventName;
|
||||
Q_snprintf( chEventName, ARRAYSIZE( chEventName ), "%s", pEvent->GetName() );
|
||||
for ( ; *pch; ++ pch )
|
||||
{
|
||||
bool bValidChar = (
|
||||
( *pch >= 'a' && *pch <= 'z' ) ||
|
||||
( *pch >= 'A' && *pch <= 'Z' ) ||
|
||||
( *pch >= '0' && *pch <= '9' )
|
||||
);
|
||||
if ( !bValidChar )
|
||||
*pch = '_';
|
||||
}
|
||||
|
||||
// New event for scripting
|
||||
KeyValues *pEventCopy = pEvent->MakeCopy();
|
||||
KeyValues::AutoDelete autodelete_pEventCopy( pEventCopy );
|
||||
pEventCopy->SetName( chEventName );
|
||||
BroadcastEventToScreens( pEventCopy );
|
||||
#endif
|
||||
}
|
||||
|
||||
public:
|
||||
CUiNuggetMatchEvents()
|
||||
{
|
||||
g_pMatchFramework->GetEventsSubscription()->Subscribe( this );
|
||||
}
|
||||
~CUiNuggetMatchEvents()
|
||||
{
|
||||
g_pMatchFramework->GetEventsSubscription()->Unsubscribe( this );
|
||||
}
|
||||
};
|
||||
|
||||
UI_NUGGET_FACTORY_SINGLETON( CUiNuggetMatchEvents, "matchevents" );
|
275
game/client/gameui/nuggets/ui_nugget.cpp
Normal file
275
game/client/gameui/nuggets/ui_nugget.cpp
Normal file
@ -0,0 +1,275 @@
|
||||
//=========== (C) Copyright Valve, L.L.C. All rights reserved. ===========
|
||||
|
||||
#include "cbase.h"
|
||||
#include "ui_nugget.h"
|
||||
#include "vstdlib/ikeyvaluessystem.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// CUiNuggetReference implementation
|
||||
//
|
||||
|
||||
class CUiNuggetReference
|
||||
{
|
||||
public:
|
||||
virtual void OnNuggetReleased( CUiNuggetBase *pNugget ) = 0;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// CUiNuggetBase implementation
|
||||
//
|
||||
|
||||
CUiNuggetBase::CUiNuggetBase() :
|
||||
m_pUiNuggetData( new KeyValues( "" ) ),
|
||||
m_autodelete_m_pUiNuggetData( m_pUiNuggetData )
|
||||
{
|
||||
}
|
||||
|
||||
CUiNuggetBase::~CUiNuggetBase()
|
||||
{
|
||||
while ( m_arrReferences.Count() )
|
||||
{
|
||||
CUiNuggetReference *pSink = m_arrReferences.Head();
|
||||
m_arrReferences.RemoveMultipleFromHead( 1 );
|
||||
pSink->OnNuggetReleased( this );
|
||||
}
|
||||
}
|
||||
|
||||
int CUiNuggetBase::OnScreenConnected( IGameUISystem *pScreenView )
|
||||
{
|
||||
ConnectionInfo_t ci( pScreenView );
|
||||
int idx = m_arrConnectedScreens.Find( ci );
|
||||
if ( idx != m_arrConnectedScreens.InvalidIndex() )
|
||||
{
|
||||
++ m_arrConnectedScreens[idx].m_nRefCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
ci.m_nRefCount = 1;
|
||||
m_arrConnectedScreens.AddToTail( ci );
|
||||
}
|
||||
return m_arrConnectedScreens.Count();
|
||||
}
|
||||
|
||||
int CUiNuggetBase::OnScreenDisconnected( IGameUISystem *pScreenView )
|
||||
{
|
||||
ConnectionInfo_t ci( pScreenView );
|
||||
int idx = m_arrConnectedScreens.Find( ci );
|
||||
if ( idx != m_arrConnectedScreens.InvalidIndex() )
|
||||
{
|
||||
if ( -- m_arrConnectedScreens[idx].m_nRefCount )
|
||||
return m_arrConnectedScreens.Count();
|
||||
|
||||
// Otherwise this screen must be released
|
||||
m_arrConnectedScreens.Remove( idx );
|
||||
|
||||
// Assert that screen is not disconnecting in the middle of
|
||||
// event broadcast (otherwise need to implement index adjustment
|
||||
// so that broadcast could succeed)
|
||||
Assert( !m_arrBroadcastEventIdxArray.Count() );
|
||||
|
||||
// Check if we need to delete us
|
||||
int numRemaining = m_arrConnectedScreens.Count();
|
||||
if ( !numRemaining && ShouldDeleteOnLastScreenDisconnect() )
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
return numRemaining;
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning( "CUiNuggetBase::OnScreenDisconnected %p for not connected screen!\n", pScreenView );
|
||||
Assert( !"OnScreenDisconnected" );
|
||||
return m_arrConnectedScreens.Count();
|
||||
}
|
||||
}
|
||||
|
||||
KeyValues * CUiNuggetBase::OnScreenEvent( IGameUISystem *pScreenView, KeyValues *kvEvent )
|
||||
{
|
||||
int nEvent = kvEvent->GetNameSymbol();
|
||||
|
||||
static int const s_nGetData = KeyValuesSystem()->GetSymbolForString( "GetData" );
|
||||
if ( nEvent == s_nGetData )
|
||||
{
|
||||
return m_pUiNuggetData->MakeCopy();
|
||||
}
|
||||
|
||||
static int const s_nEnableEvents = KeyValuesSystem()->GetSymbolForString( "EnableEvents" );
|
||||
if ( nEvent == s_nEnableEvents )
|
||||
{
|
||||
int nScriptHandle = kvEvent->GetInt( "scripthandle" );
|
||||
bool bEnabled = kvEvent->GetBool( "enable", true );
|
||||
m_arrEventsDisabledScreenHandles.FindAndFastRemove( nScriptHandle );
|
||||
if ( !bEnabled )
|
||||
m_arrEventsDisabledScreenHandles.AddToTail( nScriptHandle );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DevWarning( "CUiNuggetBase(%p)::OnScreenEvent for unknown command %s!\n", this, kvEvent->GetName() );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CUiNuggetBase::BroadcastEventToScreens( KeyValues *kvEvent )
|
||||
{
|
||||
int idx = 0;
|
||||
m_arrBroadcastEventIdxArray.AddToTail( &idx );
|
||||
|
||||
for ( ; idx < m_arrConnectedScreens.Count(); ++ idx )
|
||||
{
|
||||
IGameUISystem *pUI = m_arrConnectedScreens[idx].m_pScreen;
|
||||
int iScriptHandle = pUI->GetScriptHandle();
|
||||
if ( m_arrEventsDisabledScreenHandles.Find( iScriptHandle ) != m_arrEventsDisabledScreenHandles.InvalidIndex() )
|
||||
continue;
|
||||
pUI->ExecuteScript( kvEvent );
|
||||
}
|
||||
|
||||
m_arrBroadcastEventIdxArray.RemoveMultipleFromTail( 1 );
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// CUiNuggetFactoryRegistrarBase implementation
|
||||
//
|
||||
|
||||
static CUiNuggetFactoryRegistrarBase *g_pUiNuggetFactoriesCircularList = NULL;
|
||||
|
||||
CUiNuggetFactoryRegistrarBase::CUiNuggetFactoryRegistrarBase()
|
||||
{
|
||||
// Add us to list
|
||||
CUiNuggetFactoryRegistrarBase *pLeft = this;
|
||||
CUiNuggetFactoryRegistrarBase *pRight = this;
|
||||
|
||||
if ( g_pUiNuggetFactoriesCircularList )
|
||||
{
|
||||
pLeft = g_pUiNuggetFactoriesCircularList;
|
||||
pRight = g_pUiNuggetFactoriesCircularList->m_pNext;
|
||||
|
||||
pLeft->m_pNext = this;
|
||||
pRight->m_pPrev = this;
|
||||
}
|
||||
|
||||
g_pUiNuggetFactoriesCircularList = this;
|
||||
m_pNext = pRight;
|
||||
m_pPrev = pLeft;
|
||||
}
|
||||
|
||||
CUiNuggetFactoryRegistrarBase::~CUiNuggetFactoryRegistrarBase()
|
||||
{
|
||||
// Remove us from list
|
||||
if ( m_pPrev == this || m_pNext == this )
|
||||
{
|
||||
Assert( m_pPrev == this && m_pNext == this && g_pUiNuggetFactoriesCircularList == this );
|
||||
g_pUiNuggetFactoriesCircularList = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pPrev->m_pNext = m_pNext;
|
||||
m_pNext->m_pPrev = m_pPrev;
|
||||
if ( g_pUiNuggetFactoriesCircularList == this )
|
||||
g_pUiNuggetFactoriesCircularList = m_pPrev;
|
||||
}
|
||||
}
|
||||
|
||||
void CUiNuggetFactoryRegistrarBase::Register()
|
||||
{
|
||||
Assert( g_pGameUISystemMgr );
|
||||
g_pGameUISystemMgr->RegisterScreenControllerFactory( GetName(), this );
|
||||
}
|
||||
|
||||
void CUiNuggetFactoryRegistrarBase::RegisterAll()
|
||||
{
|
||||
CUiNuggetFactoryRegistrarBase *p = g_pUiNuggetFactoriesCircularList;
|
||||
if ( !p )
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
p->Register();
|
||||
p = p->m_pNext;
|
||||
}
|
||||
while ( p != g_pUiNuggetFactoriesCircularList );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// factories implementation
|
||||
//
|
||||
|
||||
CUiNuggetFactoryRegistrarBaseSingleton::CUiNuggetFactoryRegistrarBaseSingleton() :
|
||||
m_pSingleton( NULL )
|
||||
{
|
||||
}
|
||||
|
||||
class CUiNuggetFactoryRegistrarBaseSingletonReferenceTracker : public CUiNuggetReference
|
||||
{
|
||||
public:
|
||||
CUiNuggetFactoryRegistrarBaseSingletonReferenceTracker( CUiNuggetBase *pNugget, CUiNuggetFactoryRegistrarBaseSingleton *pFactory )
|
||||
{
|
||||
m_pFactory = pFactory;
|
||||
m_pFactory->m_pSingleton = pNugget;
|
||||
pNugget->AddReferenceSink( this );
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void OnNuggetReleased( CUiNuggetBase *pNugget )
|
||||
{
|
||||
m_pFactory->m_pSingleton = NULL;
|
||||
delete this;
|
||||
}
|
||||
|
||||
private:
|
||||
CUiNuggetFactoryRegistrarBaseSingleton *m_pFactory;
|
||||
};
|
||||
|
||||
IGameUIScreenController * CUiNuggetFactoryRegistrarBaseSingleton::GetController( KeyValues *kvRequest )
|
||||
{
|
||||
if ( Q_stricmp( GetName(), kvRequest->GetName() ) )
|
||||
return NULL;
|
||||
|
||||
if ( !m_pSingleton )
|
||||
{
|
||||
m_pSingleton = CreateNewController();
|
||||
new CUiNuggetFactoryRegistrarBaseSingletonReferenceTracker( m_pSingleton, this );
|
||||
}
|
||||
|
||||
return m_pSingleton;
|
||||
}
|
||||
|
||||
class CUiNuggetFactoryRegistrarBaseInstancesReferenceTracker : public CUiNuggetReference
|
||||
{
|
||||
public:
|
||||
CUiNuggetFactoryRegistrarBaseInstancesReferenceTracker( CUiNuggetBase *pNugget, CUiNuggetFactoryRegistrarBaseInstances *pFactory )
|
||||
{
|
||||
m_pFactory = pFactory;
|
||||
m_pFactory->m_arrInstances.AddToTail( pNugget );
|
||||
pNugget->AddReferenceSink( this );
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void OnNuggetReleased( CUiNuggetBase *pNugget )
|
||||
{
|
||||
m_pFactory->m_arrInstances.FindAndRemove( pNugget );
|
||||
delete this;
|
||||
}
|
||||
|
||||
private:
|
||||
CUiNuggetFactoryRegistrarBaseInstances *m_pFactory;
|
||||
};
|
||||
|
||||
IGameUIScreenController * CUiNuggetFactoryRegistrarBaseInstances::GetController( KeyValues *kvRequest )
|
||||
{
|
||||
if ( Q_stricmp( GetName(), kvRequest->GetName() ) )
|
||||
return NULL;
|
||||
|
||||
CUiNuggetBase *pInstance = CreateNewController();
|
||||
if ( !pInstance )
|
||||
return NULL;
|
||||
|
||||
new CUiNuggetFactoryRegistrarBaseInstancesReferenceTracker( pInstance, this );
|
||||
return pInstance;
|
||||
}
|
||||
|
252
game/client/gameui/nuggets/ui_nugget.h
Normal file
252
game/client/gameui/nuggets/ui_nugget.h
Normal file
@ -0,0 +1,252 @@
|
||||
//=========== (C) Copyright Valve, L.L.C. All rights reserved. ===========
|
||||
|
||||
#ifndef UI_NUGGET_H
|
||||
#define UI_NUGGET_H
|
||||
|
||||
#include "game_controls/igameuisystemmgr.h"
|
||||
#include "matchmaking/imatchframework.h"
|
||||
#include "fmtstr.h"
|
||||
#include "utlstringmap.h"
|
||||
|
||||
class CUiNuggetBase;
|
||||
class CUiNuggetReference;
|
||||
class CUiNuggetFactoryRegistrarBase;
|
||||
class CUiNuggetFactoryRegistrarBaseInstances;
|
||||
class CUiNuggetFactoryRegistrarBaseSingleton;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Base class for implementing UI nuggets
|
||||
//
|
||||
|
||||
class CUiNuggetBase : public IGameUIScreenController
|
||||
{
|
||||
public:
|
||||
CUiNuggetBase();
|
||||
virtual ~CUiNuggetBase();
|
||||
|
||||
// IGameUIScreenController
|
||||
public:
|
||||
// Connects a screen to the controller, returns number of
|
||||
// remaining connected screens (or 1 for the first connection)
|
||||
virtual int OnScreenConnected( IGameUISystem *pScreenView );
|
||||
|
||||
// Releases the screen from controller, returns number of
|
||||
// remaining connected screens (returns 0 if no screens are
|
||||
// connected - new object must be reacquired from factory
|
||||
// in this case)
|
||||
virtual int OnScreenDisconnected( IGameUISystem *pScreenView );
|
||||
|
||||
// Callback for screen events handling
|
||||
virtual KeyValues * OnScreenEvent( IGameUISystem *pScreenView, KeyValues *kvEvent );
|
||||
|
||||
// Broadcast an event to all connected screens (caller retains ownership of keyvalues)
|
||||
virtual void BroadcastEventToScreens( KeyValues *kvEvent );
|
||||
|
||||
public:
|
||||
// Add a reference to the nugget to be notified upon release
|
||||
virtual void AddReferenceSink( CUiNuggetReference *pSink ) { m_arrReferences.AddToTail( pSink ); }
|
||||
|
||||
protected:
|
||||
// Policy for whether the object should be deleted when no screen references remain
|
||||
virtual bool ShouldDeleteOnLastScreenDisconnect() { return true; }
|
||||
|
||||
protected:
|
||||
struct ConnectionInfo_t
|
||||
{
|
||||
IGameUISystem *m_pScreen;
|
||||
int m_nRefCount;
|
||||
|
||||
explicit ConnectionInfo_t( IGameUISystem *pScreen = NULL ) : m_pScreen( pScreen ), m_nRefCount( 0 ) {}
|
||||
bool operator == ( ConnectionInfo_t const &other ) const { return m_pScreen == other.m_pScreen; }
|
||||
};
|
||||
typedef CUtlVector< ConnectionInfo_t > ConnectedScreens;
|
||||
ConnectedScreens m_arrConnectedScreens;
|
||||
CUtlVector< int > m_arrEventsDisabledScreenHandles;
|
||||
|
||||
KeyValues *m_pUiNuggetData;
|
||||
KeyValues::AutoDelete m_autodelete_m_pUiNuggetData;
|
||||
|
||||
private:
|
||||
CUtlVector< int * > m_arrBroadcastEventIdxArray;
|
||||
CUtlVector< CUiNuggetReference * > m_arrReferences;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Declaration of UI nuggets factories
|
||||
//
|
||||
|
||||
class CUiNuggetFactoryRegistrarBase : public IGameUIScreenControllerFactory
|
||||
{
|
||||
public:
|
||||
CUiNuggetFactoryRegistrarBase();
|
||||
~CUiNuggetFactoryRegistrarBase();
|
||||
|
||||
virtual void Register();
|
||||
|
||||
virtual char const *GetName() = 0;
|
||||
|
||||
public:
|
||||
static void RegisterAll();
|
||||
|
||||
private:
|
||||
CUiNuggetFactoryRegistrarBase *m_pPrev, *m_pNext;
|
||||
};
|
||||
|
||||
class CUiNuggetFactoryRegistrarBaseGlobalInstance : public CUiNuggetFactoryRegistrarBase
|
||||
{
|
||||
public:
|
||||
// Returns an instance of a controller interface
|
||||
virtual IGameUIScreenController * GetController( KeyValues *kvRequest ) = 0;
|
||||
|
||||
// Access controller instances
|
||||
virtual int GetControllerInstancesCount() { return 1; }
|
||||
virtual IGameUIScreenController * GetControllerInstance( int iIndex ) = 0;
|
||||
};
|
||||
|
||||
class CUiNuggetFactoryRegistrarBaseSingleton : public CUiNuggetFactoryRegistrarBase
|
||||
{
|
||||
friend class CUiNuggetFactoryRegistrarBaseSingletonReferenceTracker;
|
||||
public:
|
||||
CUiNuggetFactoryRegistrarBaseSingleton();
|
||||
|
||||
public:
|
||||
// Returns an instance of a controller interface
|
||||
virtual IGameUIScreenController * GetController( KeyValues *kvRequest );
|
||||
|
||||
// Access controller instances
|
||||
virtual int GetControllerInstancesCount() { return !!m_pSingleton; }
|
||||
virtual IGameUIScreenController * GetControllerInstance( int iIndex ) { return m_pSingleton; }
|
||||
|
||||
public:
|
||||
// Creates an instance of a controller interface
|
||||
virtual CUiNuggetBase * CreateNewController() = 0;
|
||||
|
||||
protected:
|
||||
CUiNuggetBase *m_pSingleton;
|
||||
};
|
||||
|
||||
class CUiNuggetFactoryRegistrarBaseInstances : public CUiNuggetFactoryRegistrarBase
|
||||
{
|
||||
friend class CUiNuggetFactoryRegistrarBaseInstancesReferenceTracker;
|
||||
public:
|
||||
// Returns an instance of a controller interface
|
||||
virtual IGameUIScreenController * GetController( KeyValues *kvRequest );
|
||||
|
||||
// Access controller instances
|
||||
virtual int GetControllerInstancesCount() { return m_arrInstances.Count(); }
|
||||
virtual IGameUIScreenController * GetControllerInstance( int iIndex ) { return m_arrInstances.IsValidIndex( iIndex ) ? m_arrInstances[iIndex] : NULL; }
|
||||
|
||||
public:
|
||||
// Creates an instance of a controller interface
|
||||
virtual CUiNuggetBase * CreateNewController() = 0;
|
||||
|
||||
protected:
|
||||
// Nugget instances
|
||||
CUtlVector< CUiNuggetBase * > m_arrInstances;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Macros to be used to declare UI nuggets factories
|
||||
//
|
||||
|
||||
// Global instance factory - a nugget instance always exists in a global variable
|
||||
// and is always shared with all screens.
|
||||
#define UI_NUGGET_FACTORY_GLOBAL_INSTANCE( nuggetclassname, instanceptr, scriptname ) \
|
||||
namespace { \
|
||||
class Factory_##nuggetclassname##_Class : public CUiNuggetFactoryRegistrarBaseGlobalInstance \
|
||||
{ \
|
||||
virtual IGameUIScreenController * GetController( KeyValues *kvRequest ) { return static_cast< nuggetclassname * >( instanceptr ); } \
|
||||
virtual IGameUIScreenController * GetControllerInstance( int iIndex ) { return static_cast< nuggetclassname * >( instanceptr ); } \
|
||||
virtual char const * GetName() { return scriptname; } \
|
||||
} \
|
||||
g_factory_##nuggetclassname##_globalinstance; \
|
||||
};
|
||||
|
||||
// Singleton factory - create a new nugget instance and share it with all screens
|
||||
// until all references to the nugget are released and nugget is destroyed.
|
||||
// If nugget policy is not deleting the nugget upon last release, then a single nugget
|
||||
// instance will be created once and shared with all screens.
|
||||
#define UI_NUGGET_FACTORY_SINGLETON( nuggetclassname, scriptname ) \
|
||||
namespace { \
|
||||
class Factory_##nuggetclassname##_Class : public CUiNuggetFactoryRegistrarBaseSingleton \
|
||||
{ \
|
||||
virtual CUiNuggetBase * CreateNewController() { return new nuggetclassname; } \
|
||||
virtual char const * GetName() { return scriptname; } \
|
||||
} \
|
||||
g_factory_##nuggetclassname##_singleton; \
|
||||
};
|
||||
|
||||
// Instances factory - create a new nugget instance per each request.
|
||||
// Screens need to implement own methods of sharing data from a single nugget
|
||||
// instance. Nugget instance must be marked for delete upon last release.
|
||||
#define UI_NUGGET_FACTORY_INSTANCES( nuggetclassname, scriptname ) \
|
||||
namespace { \
|
||||
class Factory_##nuggetclassname##_Class : public CUiNuggetFactoryRegistrarBaseInstances \
|
||||
{ \
|
||||
virtual CUiNuggetBase * CreateNewController() { return new nuggetclassname; } \
|
||||
virtual char const * GetName() { return scriptname; } \
|
||||
} \
|
||||
g_factory_##nuggetclassname##_instances; \
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Macros to be used to declare nuggets functions
|
||||
//
|
||||
|
||||
#define DECLARE_NUGGET_FN_MAP( classname, baseclass ) \
|
||||
typedef classname NuggetEventMapClass; \
|
||||
typedef baseclass NuggetEventMapBaseClass; \
|
||||
class NuggetEventMap : \
|
||||
public CUtlStringMap< KeyValues * (classname::*)( IGameUISystem *pScreenView, KeyValues *args ) > \
|
||||
{} \
|
||||
m_NuggetEventMap; \
|
||||
class NuggetPreBroadcastMap : \
|
||||
public CUtlStringMap< bool (classname::*)( KeyValues *args ) > \
|
||||
{} \
|
||||
m_NuggetPreBroadcastMap; \
|
||||
virtual KeyValues * OnScreenEvent( IGameUISystem *pScreenView, KeyValues *args ) { \
|
||||
char const *szEvent = args->GetName(); \
|
||||
UtlSymId_t sym = m_NuggetEventMap.Find( szEvent ); \
|
||||
if ( sym != m_NuggetEventMap.InvalidIndex() ) { \
|
||||
return (this->* (m_NuggetEventMap[sym]) )( pScreenView, args ); \
|
||||
} \
|
||||
return NuggetEventMapBaseClass::OnScreenEvent( pScreenView, args ); \
|
||||
} \
|
||||
virtual void BroadcastEventToScreens( KeyValues *args ) { \
|
||||
char const *szEvent = args->GetName(); \
|
||||
UtlSymId_t sym = m_NuggetPreBroadcastMap.Find( szEvent ); \
|
||||
if ( sym != m_NuggetPreBroadcastMap.InvalidIndex() ) { \
|
||||
if ( ! (this->* (m_NuggetPreBroadcastMap[sym]) )( args ) ) return; \
|
||||
} \
|
||||
return NuggetEventMapBaseClass::BroadcastEventToScreens( args ); \
|
||||
}
|
||||
|
||||
#define NUGGET_FN( eventname ) \
|
||||
class eventname##_EventRegistrar { \
|
||||
public: typedef eventname##_EventRegistrar ThisClass; \
|
||||
eventname##_EventRegistrar() { \
|
||||
NuggetEventMapClass *pNugget = reinterpret_cast< NuggetEventMapClass * >( reinterpret_cast< size_t >( this ) - offsetof( NuggetEventMapClass, m_##eventname##_EventRegistrar ) ); \
|
||||
pNugget->m_NuggetEventMap[ #eventname ] = &NuggetEventMapClass::Event_##eventname; \
|
||||
COMPILE_TIME_ASSERT( offsetof( NuggetEventMapClass, m_##eventname##_EventRegistrar ) > offsetof( NuggetEventMapClass, m_NuggetEventMap ) ); \
|
||||
} } m_##eventname##_EventRegistrar; \
|
||||
KeyValues * Event_##eventname( IGameUISystem *pScreenView, KeyValues *args )
|
||||
|
||||
|
||||
#define NUGGET_BROADCAST_FN( eventname ) \
|
||||
class eventname##_BroadcastRegistrar { \
|
||||
public: typedef eventname##_BroadcastRegistrar ThisClass; \
|
||||
eventname##_BroadcastRegistrar() { \
|
||||
NuggetEventMapClass *pNugget = reinterpret_cast< NuggetEventMapClass * >( reinterpret_cast< size_t >( this ) - offsetof( NuggetEventMapClass, m_##eventname##_BroadcastRegistrar ) ); \
|
||||
pNugget->m_NuggetPreBroadcastMap[ #eventname ] = &NuggetEventMapClass::Broadcast_##eventname; \
|
||||
COMPILE_TIME_ASSERT( offsetof( NuggetEventMapClass, m_##eventname##_BroadcastRegistrar ) > offsetof( NuggetEventMapClass, m_NuggetPreBroadcastMap ) ); \
|
||||
} } m_##eventname##_BroadcastRegistrar; \
|
||||
bool Broadcast_##eventname( KeyValues *args )
|
||||
|
||||
|
||||
#endif // UI_NUGGET_H
|
44
game/client/gameui/nuggets/ui_playermanager.cpp
Normal file
44
game/client/gameui/nuggets/ui_playermanager.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
//=========== (C) Copyright Valve, L.L.C. All rights reserved. ===========
|
||||
|
||||
#include "cbase.h"
|
||||
#include "ui_nugget.h"
|
||||
|
||||
class CUiNuggetPlayerManager : public CUiNuggetBase
|
||||
{
|
||||
DECLARE_NUGGET_FN_MAP( CUiNuggetPlayerManager, CUiNuggetBase );
|
||||
|
||||
NUGGET_FN( GetLocalPlayer )
|
||||
{
|
||||
// Request for local player info
|
||||
int iController = args->GetInt( "index" );
|
||||
IPlayerLocal *pLocalPlayer = g_pMatchFramework->GetMatchSystem()->GetPlayerManager()->GetLocalPlayer( iController );
|
||||
if ( !pLocalPlayer )
|
||||
return NULL;
|
||||
|
||||
return PlayerAsKeyValues( pLocalPlayer, CFmtStr( "localplayer%d", iController ) );
|
||||
}
|
||||
|
||||
NUGGET_FN( JoinFriend )
|
||||
{
|
||||
// Request to join a friend
|
||||
XUID xuid = args->GetUint64( "xuid" );
|
||||
IPlayerFriend *pFriend = g_pMatchFramework->GetMatchSystem()->GetPlayerManager()->GetFriendByXUID( xuid );
|
||||
if ( !pFriend )
|
||||
return NULL;
|
||||
|
||||
pFriend->Join();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
KeyValues * PlayerAsKeyValues( IPlayer *pPlayer, char const *szResultTitle = "" )
|
||||
{
|
||||
KeyValues *kv = new KeyValues( szResultTitle );
|
||||
kv->SetString( "name", pPlayer->GetName() );
|
||||
kv->SetString( "xuid", CFmtStr( "%llu", pPlayer->GetXUID() ) );
|
||||
kv->SetInt( "index", pPlayer->GetPlayerIndex() );
|
||||
kv->SetInt( "state", pPlayer->GetOnlineState() );
|
||||
return kv;
|
||||
}
|
||||
};
|
||||
|
||||
UI_NUGGET_FACTORY_SINGLETON( CUiNuggetPlayerManager, "playermanager" );
|
51
game/client/gameui/nuggets/ui_semaphore.cpp
Normal file
51
game/client/gameui/nuggets/ui_semaphore.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
//=========== (C) Copyright Valve, L.L.C. All rights reserved. ===========
|
||||
|
||||
#include "cbase.h"
|
||||
#include "ui_nugget.h"
|
||||
|
||||
class CUiNuggetSemaphore : public CUiNuggetBase
|
||||
{
|
||||
DECLARE_NUGGET_FN_MAP( CUiNuggetSemaphore, CUiNuggetBase );
|
||||
|
||||
NUGGET_FN( Configure )
|
||||
{
|
||||
m_pUiNuggetData->MergeFrom( args, KeyValues::MERGE_KV_UPDATE );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NUGGET_FN( Signal )
|
||||
{
|
||||
char const *szSemaphoreSignal = m_pUiNuggetData->GetString( "signal" );
|
||||
if ( !*szSemaphoreSignal )
|
||||
return NULL;
|
||||
|
||||
KeyValues *pEvent = m_pUiNuggetData->MakeCopy();
|
||||
pEvent->SetName( szSemaphoreSignal );
|
||||
KeyValues::AutoDelete autodelete_pEvent( pEvent );
|
||||
|
||||
char const *szEventData = m_pUiNuggetData->GetString( "eventdata" );
|
||||
if ( *szEventData )
|
||||
{
|
||||
if ( KeyValues *pSub = pEvent->FindKey( szEventData ) )
|
||||
{
|
||||
pEvent->RemoveSubKey( pSub );
|
||||
pSub->deleteThis();
|
||||
}
|
||||
KeyValues *pParams = args->MakeCopy();
|
||||
pParams->SetName( szEventData );
|
||||
pEvent->AddSubKey( pParams );
|
||||
}
|
||||
|
||||
BroadcastEventToScreens( pEvent );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public:
|
||||
CUiNuggetSemaphore()
|
||||
{
|
||||
m_pUiNuggetData->SetString( "signal", "OnSemaphore" );
|
||||
m_pUiNuggetData->SetString( "eventdata", "eventdata" );
|
||||
}
|
||||
};
|
||||
|
||||
UI_NUGGET_FACTORY_INSTANCES( CUiNuggetSemaphore, "semaphore" );
|
70
game/client/gameui/nuggets/ui_sessions.cpp
Normal file
70
game/client/gameui/nuggets/ui_sessions.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
//=========== (C) Copyright Valve, L.L.C. All rights reserved. ===========
|
||||
|
||||
#include "cbase.h"
|
||||
#include "ui_nugget.h"
|
||||
|
||||
class CUiNuggetSessions : public CUiNuggetBase
|
||||
{
|
||||
DECLARE_NUGGET_FN_MAP( CUiNuggetSessions, CUiNuggetBase );
|
||||
|
||||
NUGGET_FN( CloseSession )
|
||||
{
|
||||
g_pMatchFramework->CloseSession();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NUGGET_FN( CreateSession )
|
||||
{
|
||||
args->SetName( "settings" );
|
||||
g_pMatchFramework->CreateSession( args );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NUGGET_FN( MatchSession )
|
||||
{
|
||||
args->SetName( "settings" );
|
||||
g_pMatchFramework->MatchSession( args );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NUGGET_FN( SessionSystemData )
|
||||
{
|
||||
if ( IMatchSession *p = g_pMatchFramework->GetMatchSession() )
|
||||
{
|
||||
KeyValues *kv = p->GetSessionSystemData();
|
||||
return kv ? kv->MakeCopy() : NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NUGGET_FN( SessionSettings )
|
||||
{
|
||||
if ( IMatchSession *p = g_pMatchFramework->GetMatchSession() )
|
||||
{
|
||||
KeyValues *kv = p->GetSessionSettings();
|
||||
return kv ? kv->MakeCopy() : NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NUGGET_FN( SessionUpdateSettings )
|
||||
{
|
||||
if ( IMatchSession *p = g_pMatchFramework->GetMatchSession() )
|
||||
{
|
||||
args->SetName( "settings" );
|
||||
p->UpdateSessionSettings( args );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NUGGET_FN( SessionCommand )
|
||||
{
|
||||
if ( IMatchSession *p = g_pMatchFramework->GetMatchSession() )
|
||||
{
|
||||
p->Command( args->GetFirstSubKey() );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
UI_NUGGET_FACTORY_SINGLETON( CUiNuggetSessions, "sessions" );
|
Reference in New Issue
Block a user