Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.7 KiB

  1. //=========== (C) Copyright Valve, L.L.C. All rights reserved. ===========
  2. #include "cbase.h"
  3. #include "ui_nugget.h"
  4. #include "matchmaking/imatchframework.h"
  5. class CUiNuggetMatchEvents : public CUiNuggetBase, IMatchEventsSink
  6. {
  7. DECLARE_NUGGET_FN_MAP( CUiNuggetMatchEvents, CUiNuggetBase );
  8. virtual void OnEvent( KeyValues *pEvent )
  9. {
  10. BroadcastEventToScreens( pEvent );
  11. return;
  12. #if SCRIPTS_NEED_EVENT_NAMES_WITH_BASIC_CHARSET
  13. // In case scripts cannot define function names
  14. // associations with any characters, then we'll
  15. // need to do some work to make event names conform
  16. // with those scripts.
  17. //
  18. // In lua we can easily do any member function names:
  19. /*
  20. mainmenu["Command::Game::SampleCmd"] = function(self, params)
  21. print( "Command::Game::SampleCmd" )
  22. print( self.extraPieceOfData )
  23. end
  24. */
  25. //
  26. // Fix the event name for scripting:
  27. char chEventName[256] = {0}, *pch = chEventName;
  28. Q_snprintf( chEventName, ARRAYSIZE( chEventName ), "%s", pEvent->GetName() );
  29. for ( ; *pch; ++ pch )
  30. {
  31. bool bValidChar = (
  32. ( *pch >= 'a' && *pch <= 'z' ) ||
  33. ( *pch >= 'A' && *pch <= 'Z' ) ||
  34. ( *pch >= '0' && *pch <= '9' )
  35. );
  36. if ( !bValidChar )
  37. *pch = '_';
  38. }
  39. // New event for scripting
  40. KeyValues *pEventCopy = pEvent->MakeCopy();
  41. KeyValues::AutoDelete autodelete_pEventCopy( pEventCopy );
  42. pEventCopy->SetName( chEventName );
  43. BroadcastEventToScreens( pEventCopy );
  44. #endif
  45. }
  46. public:
  47. CUiNuggetMatchEvents()
  48. {
  49. g_pMatchFramework->GetEventsSubscription()->Subscribe( this );
  50. }
  51. ~CUiNuggetMatchEvents()
  52. {
  53. g_pMatchFramework->GetEventsSubscription()->Unsubscribe( this );
  54. }
  55. };
  56. UI_NUGGET_FACTORY_SINGLETON( CUiNuggetMatchEvents, "matchevents" );