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.

202 lines
4.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: [jpaquin] The "Player Two press start" widget
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "basepanel.h"
  8. #include "scaleformui/scaleformui.h"
  9. #include "iclientmode.h"
  10. #include "clientmode_csnormal.h"
  11. #include "sfhudflashinterface.h"
  12. #include "vgui/ILocalize.h"
  13. #include "VGuiMatSurface/IMatSystemSurface.h"
  14. #if defined( _X360 )
  15. #include "xbox/xbox_launch.h"
  16. #endif
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. static const float UPDATE_INTERVAL = 60.0f;
  20. class SFHudTrialTimer : public SFHudFlashInterface
  21. {
  22. public:
  23. explicit SFHudTrialTimer( const char *value ) : SFHudFlashInterface( value ),
  24. m_fNextUpdate( 0.0f ),
  25. m_bVisible( false )
  26. {
  27. SetHiddenBits( /* HIDEHUD_MISCSTATUS */ 0 );
  28. }
  29. virtual ~SFHudTrialTimer()
  30. {
  31. }
  32. void ProcessInput( void )
  33. {
  34. if ( FlashAPIIsValid() )
  35. {
  36. if ( m_fNextUpdate < gpGlobals->curtime )
  37. {
  38. m_fNextUpdate = gpGlobals->curtime + UPDATE_INTERVAL;
  39. bool bUnlocked = false;
  40. float timeLeft = 0;
  41. #if defined( _X360 )
  42. if ( xboxsystem )
  43. {
  44. bUnlocked = xboxsystem->IsArcadeTitleUnlocked();
  45. if ( !bUnlocked )
  46. {
  47. timeLeft = xboxsystem->GetArcadeRemainingTrialTime( m_iFlashSlot - SF_FIRST_SS_SLOT );
  48. }
  49. }
  50. #else
  51. ConVarRef xbox_arcade_title_unlocked( "xbox_arcade_title_unlocked" );
  52. ConVarRef xbox_arcade_remaining_trial_time( "xbox_arcade_remaining_trial_time" );
  53. bUnlocked = xbox_arcade_title_unlocked.GetBool();
  54. timeLeft = xbox_arcade_remaining_trial_time.GetFloat();
  55. #endif
  56. if ( !bUnlocked )
  57. {
  58. int minutesLeft = floorf( timeLeft / 60.0f );
  59. minutesLeft = MAX( minutesLeft, 0 );
  60. if ( minutesLeft == 1 )
  61. {
  62. WITH_SLOT_LOCKED
  63. {
  64. m_pTimerMessage->SetTextHTML( "#SFUI_TrialHudTextMinute" );
  65. }
  66. }
  67. else
  68. {
  69. char strTrialTime[16];
  70. Q_snprintf( strTrialTime, sizeof( strTrialTime ), "%d", minutesLeft );
  71. wchar_t buffer[128];
  72. wchar_t wTrialTime[16];
  73. g_pVGuiLocalize->ConvertANSIToUnicode( strTrialTime, wTrialTime, sizeof( wTrialTime ) );
  74. g_pVGuiLocalize->ConstructString( buffer, sizeof( buffer ), g_pVGuiLocalize->Find( "#SFUI_TrialHudTextMinutes" ), 1, wTrialTime );
  75. WITH_SLOT_LOCKED
  76. {
  77. m_pTimerMessage->SetTextHTML( buffer );
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84. void LevelInit( void )
  85. {
  86. if ( !FlashAPIIsValid() )
  87. {
  88. SFUI_REQUEST_ELEMENT( SF_SS_SLOT( GET_ACTIVE_SPLITSCREEN_SLOT() ), g_pScaleformUI, SFHudTrialTimer, this, TrialTimer );
  89. }
  90. }
  91. virtual void LevelShutdown( void )
  92. {
  93. if ( FlashAPIIsValid() )
  94. {
  95. RemoveFlashElement();
  96. }
  97. }
  98. virtual void SetActive( bool bActive )
  99. {
  100. ShowPanel( bActive, false );
  101. CHudElement::SetActive( bActive );
  102. }
  103. virtual bool ShouldDraw( void )
  104. {
  105. bool result = cl_drawhud.GetBool();
  106. #if defined( _X360 )
  107. if ( result && xboxsystem )
  108. {
  109. result = !( xboxsystem->IsArcadeTitleUnlocked() );
  110. }
  111. #else
  112. ConVarRef xbox_arcade_title_unlocked( "xbox_arcade_title_unlocked" );
  113. result = result && !xbox_arcade_title_unlocked.GetBool();
  114. #endif
  115. return result && CHudElement::ShouldDraw();
  116. }
  117. // these overload the ScaleformFlashInterfaceMixin class
  118. virtual void FlashReady( void )
  119. {
  120. SFVALUE panel = m_pScaleformUI->Value_GetMember( m_FlashAPI, "Panel" );
  121. if ( panel != NULL )
  122. {
  123. m_pTimerMessage = m_pScaleformUI->TextObject_MakeTextObjectFromMember( panel, "AnimatedText" );
  124. m_pScaleformUI->ReleaseValue( panel );
  125. }
  126. ShowPanel( m_bVisible, true );
  127. }
  128. virtual bool PreUnloadFlash( void )
  129. {
  130. SafeReleaseSFTextObject( m_pTimerMessage );
  131. return SFHudFlashInterface::PreUnloadFlash();
  132. }
  133. protected:
  134. void ShowPanel( bool bShow, bool force )
  135. {
  136. if ( ( bShow != m_bVisible ) || force )
  137. {
  138. m_bVisible = bShow;
  139. if ( m_FlashAPI )
  140. {
  141. if ( m_bVisible )
  142. {
  143. m_fNextUpdate = 0.0f;
  144. ProcessInput();
  145. WITH_SLOT_LOCKED
  146. m_pScaleformUI->Value_InvokeWithoutReturn( m_FlashAPI, "ShowPanel", NULL, 0 );
  147. }
  148. else
  149. {
  150. WITH_SLOT_LOCKED
  151. m_pScaleformUI->Value_InvokeWithoutReturn( m_FlashAPI, "HidePanel", NULL, 0 );
  152. }
  153. }
  154. }
  155. }
  156. protected:
  157. ISFTextObject* m_pTimerMessage;
  158. float m_fNextUpdate;
  159. bool m_bVisible;
  160. };
  161. DECLARE_HUDELEMENT( SFHudTrialTimer );
  162. SFUI_BEGIN_GAME_API_DEF
  163. SFUI_END_GAME_API_DEF( SFHudTrialTimer, TrialTimer );