Team Fortress 2 Source Code as on 22/4/2020
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.

69 lines
1.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "sc_hinticon.h"
  9. #include <vgui/IVGui.h>
  10. #include "inputsystem/iinputsystem.h"
  11. using namespace vgui;
  12. DECLARE_BUILD_FACTORY( CSCHintIcon );
  13. //-----------------------------------------------------------------------------
  14. CSCHintIcon::CSCHintIcon( vgui::Panel *parent, const char* panelName ) :
  15. vgui::Label( parent, panelName, L"" )
  16. , m_bIsActionMapped( false )
  17. , m_actionSetHandle( 0 )
  18. {
  19. m_szActionName[0] = '\0';
  20. }
  21. //-----------------------------------------------------------------------------
  22. // Purpose:
  23. //-----------------------------------------------------------------------------
  24. void CSCHintIcon::ApplySettings( KeyValues *inResourceData )
  25. {
  26. BaseClass::ApplySettings( inResourceData );
  27. auto szActionName = inResourceData->GetString( "actionName", "" );
  28. Q_strncpy( m_szActionName, szActionName, nMaxActionNameLength );
  29. auto szActionSet = inResourceData->GetString( "actionSet", nullptr );
  30. if ( szActionSet )
  31. {
  32. m_actionSetHandle = g_pInputSystem->GetActionSetHandle( szActionSet );
  33. }
  34. else
  35. {
  36. m_actionSetHandle = 0;
  37. }
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Purpose:
  41. //-----------------------------------------------------------------------------
  42. void CSCHintIcon::ApplySchemeSettings( IScheme *pScheme )
  43. {
  44. BaseClass::ApplySchemeSettings( pScheme );
  45. const wchar_t* iconText = L"";
  46. m_bIsActionMapped = false;
  47. if ( m_actionSetHandle )
  48. {
  49. auto origin = g_pInputSystem->GetSteamControllerActionOrigin( m_szActionName, m_actionSetHandle );
  50. if ( origin != k_EControllerActionOrigin_None )
  51. {
  52. iconText = g_pInputSystem->GetSteamControllerFontCharacterForActionOrigin( origin );
  53. if ( iconText && iconText[0] )
  54. {
  55. m_bIsActionMapped = true;
  56. }
  57. }
  58. }
  59. SetText( iconText );
  60. }