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.

1583 lines
36 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #include "tier1/keyvalues.h"
  9. #include "vgui/ILocalize.h"
  10. #include "vgui/ISurface.h"
  11. #include "vgui_controls/Controls.h"
  12. #include "convar.h"
  13. #include "../game/shared/cstrike15/dlchelper.h"
  14. #include <vstdlib/vstrtools.h>
  15. #include "vgui/ISystem.h"
  16. // NOTE: This has to be the last file included!
  17. #include "tier0/memdbgon.h"
  18. #define FLASH_ARRAY_ID "_array_"
  19. #define FLASH_ARRAY_NAME_ID "_name_"
  20. #define FLASH_ARRAY_ELEMENT_ID "_"
  21. static const float CHANGE_CONTROLLER_TIMEOUT = 0.5f;
  22. using namespace SF::GFx;
  23. /*******************************
  24. * visitors to allow flash objects to be serialized
  25. */
  26. class FlashArrayVisitor: public Value::ArrayVisitor
  27. {
  28. public:
  29. KeyValues* m_pKV;
  30. const Value* m_pOriginalValue;
  31. void AddObject( const Value& val );
  32. void AddArray( const Value& val )
  33. {
  34. KeyValues* pnew = m_pKV->CreateNewKey();
  35. pnew->SetName( FLASH_ARRAY_ID );
  36. FlashArrayVisitor visitor;
  37. visitor.m_pKV = pnew;
  38. visitor.m_pOriginalValue = &val;
  39. val.VisitElements( &visitor );
  40. if ( pnew->IsEmpty() )
  41. {
  42. m_pKV->RemoveSubKey( pnew );
  43. }
  44. }
  45. void Visit( unsigned int idx, const Value& val )
  46. {
  47. if ( *m_pOriginalValue == val )
  48. {
  49. return;
  50. }
  51. SF::Double number;
  52. int inumber;
  53. KeyValues* pnew = NULL;
  54. switch ( val.GetType() )
  55. {
  56. case Value::VT_Boolean:
  57. pnew = m_pKV->CreateNewKey();
  58. pnew->SetBool( NULL, val.GetBool() );
  59. break;
  60. case Value::VT_Number:
  61. number = val.GetNumber();
  62. inumber = ( int ) number;
  63. pnew = NULL;
  64. if ( ( SF::Double ) inumber == number )
  65. {
  66. pnew = m_pKV->CreateNewKey();
  67. pnew->SetInt( NULL, inumber );
  68. }
  69. else
  70. {
  71. pnew = m_pKV->CreateNewKey();
  72. pnew->SetFloat( NULL, ( float ) number );
  73. }
  74. break;
  75. case Value::VT_String:
  76. pnew = m_pKV->CreateNewKey();
  77. pnew->SetString( NULL, val.GetString() );
  78. break;
  79. case Value::VT_Object:
  80. AddObject( val );
  81. break;
  82. case Value::VT_Array:
  83. AddArray( val );
  84. break;
  85. default:
  86. break;
  87. }
  88. if ( pnew )
  89. pnew->SetName( FLASH_ARRAY_ELEMENT_ID );
  90. }
  91. };
  92. class FlashObjectVisitor: public Value::ObjectVisitor
  93. {
  94. public:
  95. KeyValues* m_pKV;
  96. const Value* m_pOriginalValue;
  97. void AddObject( const char* name, const Value& val )
  98. {
  99. KeyValues* pnew = m_pKV->CreateNewKey();
  100. pnew->SetName( name );
  101. FlashObjectVisitor visitor;
  102. visitor.m_pKV = pnew;
  103. visitor.m_pOriginalValue = &val;
  104. val.VisitMembers( &visitor );
  105. if ( pnew->IsEmpty() )
  106. {
  107. m_pKV->RemoveSubKey( pnew );
  108. }
  109. }
  110. void AddArray( const char* name, const Value& val )
  111. {
  112. KeyValues* pnew = m_pKV->CreateNewKey();
  113. pnew->SetName( FLASH_ARRAY_ID );
  114. pnew->SetString( FLASH_ARRAY_NAME_ID, name );
  115. FlashArrayVisitor visitor;
  116. visitor.m_pKV = pnew;
  117. visitor.m_pOriginalValue = &val;
  118. val.VisitElements( &visitor );
  119. if ( pnew->IsEmpty() )
  120. {
  121. m_pKV->RemoveSubKey( pnew );
  122. }
  123. }
  124. void Visit( const char* name, const Value& val )
  125. {
  126. if ( *m_pOriginalValue == val )
  127. {
  128. return;
  129. }
  130. SF::Double number;
  131. int inumber;
  132. switch ( val.GetType() )
  133. {
  134. case Value::VT_Boolean:
  135. m_pKV->SetBool( name, val.GetBool() );
  136. break;
  137. case Value::VT_Number:
  138. number = val.GetNumber();
  139. inumber = ( int ) number;
  140. if ( ( SF::Double ) inumber == number )
  141. {
  142. m_pKV->SetInt( name, inumber );
  143. }
  144. else
  145. {
  146. m_pKV->SetFloat( name, ( float ) number );
  147. }
  148. break;
  149. case Value::VT_String:
  150. m_pKV->SetString( name, val.GetString() );
  151. break;
  152. case Value::VT_Object:
  153. AddObject( name, val );
  154. break;
  155. case Value::VT_Array:
  156. AddArray( name, val );
  157. break;
  158. default:
  159. break;
  160. }
  161. }
  162. };
  163. void FlashArrayVisitor::AddObject( const Value& val )
  164. {
  165. KeyValues* pnew = m_pKV->CreateNewKey();
  166. pnew->SetName( FLASH_ARRAY_ELEMENT_ID );
  167. FlashObjectVisitor visitor;
  168. visitor.m_pKV = pnew;
  169. visitor.m_pOriginalValue = &val;
  170. val.VisitMembers( &visitor );
  171. if ( pnew->IsEmpty() )
  172. {
  173. m_pKV->RemoveSubKey( pnew );
  174. }
  175. }
  176. BaseSlot::BaseSlot()
  177. {
  178. m_pMovieDef = NULL;
  179. m_pMovieView = NULL;
  180. m_iRefCount = 1;
  181. m_iSlot = -1;
  182. m_fChangeControllerTimeout = 0;
  183. m_advanceCount = 0;
  184. }
  185. bool BaseSlot::ConvertValue( Value *value, KeyValues* kv )
  186. {
  187. bool result = true;
  188. switch ( kv->GetDataType() )
  189. {
  190. case KeyValues::TYPE_STRING:
  191. m_pMovieView->CreateString( value, kv->GetString() );
  192. break;
  193. case KeyValues::TYPE_INT:
  194. value->SetNumber( ( SF::Double ) kv->GetInt() );
  195. break;
  196. case KeyValues::TYPE_FLOAT:
  197. value->SetNumber( ( SF::Double ) kv->GetFloat() );
  198. break;
  199. case KeyValues::TYPE_WSTRING:
  200. m_pMovieView->CreateStringW( value, kv->GetWString() );
  201. break;
  202. case KeyValues::TYPE_UINT64:
  203. value->SetNumber( ( SF::Double ) kv->GetUint64() );
  204. break;
  205. default:
  206. result = false;
  207. break;
  208. }
  209. return result;
  210. }
  211. const char* BaseSlot::PopulateArray( Value* value, KeyValues* kv )
  212. {
  213. m_pMovieView->CreateArray( value );
  214. Value workValue;
  215. // count the number of array slots needed
  216. int numElements = 0;
  217. for ( KeyValues* piter = kv->GetFirstSubKey(); piter; piter = piter->GetNextKey() )
  218. {
  219. if ( Q_strcasecmp( FLASH_ARRAY_NAME_ID, piter->GetName() ) )
  220. numElements++;
  221. }
  222. value->SetArraySize( numElements );
  223. int currentElement = 0;
  224. for ( KeyValues* piter = kv->GetFirstSubKey(); piter; piter = piter->GetNextKey() )
  225. {
  226. // skip the element that defines the array object name
  227. if ( Q_strcasecmp( FLASH_ARRAY_NAME_ID, piter->GetName() ) )
  228. {
  229. if ( !Q_strcasecmp( FLASH_ARRAY_ID, piter->GetName() ) )
  230. {
  231. PopulateArray( &workValue, piter );
  232. }
  233. else if ( !ConvertValue( &workValue, piter ) )
  234. {
  235. PopulateObject( &workValue, piter );
  236. }
  237. value->SetElement( currentElement, workValue );
  238. workValue.SetNull();
  239. currentElement++;
  240. }
  241. }
  242. return kv->GetString( FLASH_ARRAY_NAME_ID, NULL );
  243. }
  244. void BaseSlot::PopulateObject( Value* value, KeyValues* kv )
  245. {
  246. m_pMovieView->CreateObject( value );
  247. Value workValue;
  248. // first iterate through the values at this level and assign them to the m_pObject
  249. for ( KeyValues* piter = kv->GetFirstValue(); piter; piter = piter->GetNextValue() )
  250. {
  251. if ( ConvertValue( &workValue, piter ) )
  252. {
  253. value->SetMember( piter->GetName(), workValue );
  254. workValue.SetNull();
  255. }
  256. }
  257. // now make the sub objects
  258. for ( KeyValues* piter = kv->GetFirstTrueSubKey(); piter; piter = piter->GetNextTrueSubKey() )
  259. {
  260. if ( !Q_strcasecmp( FLASH_ARRAY_ID, piter->GetName() ) )
  261. {
  262. const char* name = PopulateArray( &workValue, piter );
  263. value->SetMember( name, workValue );
  264. }
  265. else
  266. {
  267. m_pMovieView->CreateObject( &workValue );
  268. PopulateObject( &workValue, piter );
  269. value->SetMember( piter->GetName(), workValue );
  270. }
  271. workValue.SetNull();
  272. }
  273. }
  274. void BaseSlot::LoadKVFile( SCALEFORM_CALLBACK_ARGS_DECL )
  275. {
  276. FunctionHandler::Params* params = FromSFPARAMS( obj );
  277. const char* filename = params->pArgs[0].GetString();
  278. const char* section = filename;
  279. if ( params->ArgCount > 1 )
  280. {
  281. section = params->pArgs[1].GetString();
  282. }
  283. const char* startDir = "GAME";
  284. if ( params->ArgCount > 2 )
  285. {
  286. startDir = params->pArgs[2].GetString();
  287. }
  288. // See if we don't want to load any dlc keys
  289. bool checkForDlcFiles = true;
  290. if ( params->ArgCount > 3 )
  291. {
  292. checkForDlcFiles = params->pArgs[3].GetBool();
  293. }
  294. KeyValues* pkeyValueData = new KeyValues( section );
  295. // Load the config data
  296. if ( pkeyValueData )
  297. {
  298. Value rootValue;
  299. pkeyValueData->LoadFromFile( g_pFullFileSystem, filename, startDir );
  300. // Add/update any key value changes from DLC files
  301. if ( checkForDlcFiles )
  302. {
  303. DLCHelper::AppendDLCKeyValues( pkeyValueData, filename, startDir );
  304. }
  305. PopulateObject( params->pRetVal, pkeyValueData );
  306. pkeyValueData->deleteThis();
  307. }
  308. }
  309. void BaseSlot::SaveKVFile( SCALEFORM_CALLBACK_ARGS_DECL )
  310. {
  311. FunctionHandler::Params* params = FromSFPARAMS( obj );
  312. Value* pvalue = &params->pArgs[0];
  313. const char* filename = params->pArgs[1].GetString();
  314. const char* section = filename;
  315. if ( params->ArgCount > 2 )
  316. {
  317. section = params->pArgs[2].GetString();
  318. }
  319. const char* where = "GAME";
  320. if ( params->ArgCount > 3 )
  321. {
  322. where = params->pArgs[3].GetString();
  323. }
  324. KeyValues* pKV = new KeyValues( section );
  325. FlashObjectVisitor visitor;
  326. visitor.m_pKV = pKV;
  327. visitor.m_pOriginalValue = pvalue;
  328. pvalue->VisitMembers( &visitor );
  329. pKV->SaveToFile( g_pFullFileSystem, filename, where );
  330. pKV->deleteThis();
  331. }
  332. void BaseSlot::GetConvar( FunctionHandler::Params* params, CVAR_TYPE_WANTED typeWanted )
  333. {
  334. bool resultValid = false;
  335. if ( params->ArgCount != 1 )
  336. {
  337. SFINST.LogPrintf( "scaleform: script called GetConvar* with %d args\n", params->ArgCount );
  338. }
  339. else
  340. {
  341. const char* convarname = params->pArgs[0].GetString();
  342. if ( !convarname || !*convarname )
  343. {
  344. SFINST.LogPrintf( "scaleform: script called GetConvar* with bad first argument\n" );
  345. }
  346. else
  347. {
  348. ConVarRef convar( convarname );
  349. if ( convar.IsValid() )
  350. {
  351. switch ( typeWanted )
  352. {
  353. case CVAR_WANT_NUMBER:
  354. params->pRetVal->SetNumber( convar.GetFloat() );
  355. resultValid = true;
  356. break;
  357. case CVAR_WANT_NUMBER_MIN:
  358. params->pRetVal->SetNumber( convar.GetMin() );
  359. resultValid = true;
  360. break;
  361. case CVAR_WANT_NUMBER_MAX:
  362. params->pRetVal->SetNumber( convar.GetMax() );
  363. resultValid = true;
  364. break;
  365. case CVAR_WANT_BOOL:
  366. params->pRetVal->SetBoolean( convar.GetBool() );
  367. resultValid = true;
  368. break;
  369. case CVAR_WANT_STRING:
  370. if ( !convar.IsFlagSet( FCVAR_NEVER_AS_STRING ) )
  371. {
  372. const char* str = convar.GetString();
  373. if ( str )
  374. {
  375. m_pMovieView->CreateString( params->pRetVal, str );
  376. resultValid = true;
  377. }
  378. }
  379. break;
  380. default:
  381. break;
  382. }
  383. }
  384. }
  385. }
  386. if ( !resultValid )
  387. {
  388. params->pRetVal->SetNull();
  389. }
  390. }
  391. void BaseSlot::GetConvarNumber( SCALEFORM_CALLBACK_ARGS_DECL )
  392. {
  393. GetConvar( FromSFPARAMS( obj ), CVAR_WANT_NUMBER );
  394. }
  395. void BaseSlot::GetConvarNumberMin( SCALEFORM_CALLBACK_ARGS_DECL )
  396. {
  397. GetConvar( FromSFPARAMS( obj ), CVAR_WANT_NUMBER_MIN );
  398. }
  399. void BaseSlot::GetConvarNumberMax( SCALEFORM_CALLBACK_ARGS_DECL )
  400. {
  401. GetConvar( FromSFPARAMS( obj ), CVAR_WANT_NUMBER_MAX );
  402. }
  403. void BaseSlot::GetConvarString( SCALEFORM_CALLBACK_ARGS_DECL )
  404. {
  405. GetConvar( FromSFPARAMS( obj ), CVAR_WANT_STRING );
  406. }
  407. void BaseSlot::GetConvarBoolean( SCALEFORM_CALLBACK_ARGS_DECL )
  408. {
  409. GetConvar( FromSFPARAMS( obj ), CVAR_WANT_BOOL );
  410. }
  411. void BaseSlot::GetPlayerColorObject( SCALEFORM_CALLBACK_ARGS_DECL )
  412. {
  413. FunctionHandler::Params* params = FromSFPARAMS( obj );
  414. int nSlot = 0;
  415. int nPos = 0;
  416. if ( !params->pArgs[0].IsUndefined() )
  417. {
  418. nSlot = params->pArgs[0].GetNumber();
  419. nPos = params->pArgs[1].GetNumber( );
  420. }
  421. else
  422. {
  423. Warning( "Actionscript passed an undefined param to BaseSlot::GetPlayerColorObject!\n" );
  424. }
  425. if ( nSlot < 0 || nSlot > 4 )
  426. return;
  427. int r = 0;
  428. int g = 0;
  429. int b = 0;
  430. switch ( nSlot )
  431. {
  432. case 0:
  433. {
  434. static ConVarRef cl_teammate_color_1( "cl_teammate_color_1" );
  435. sscanf( cl_teammate_color_1.GetString(), "%i %i %i", &r, &g, &b );
  436. break;
  437. }
  438. case 1:
  439. {
  440. static ConVarRef cl_teammate_color_2( "cl_teammate_color_2" );
  441. sscanf( cl_teammate_color_2.GetString(), "%i %i %i", &r, &g, &b );
  442. break;
  443. }
  444. case 2:
  445. {
  446. static ConVarRef cl_teammate_color_3( "cl_teammate_color_3" );
  447. sscanf( cl_teammate_color_3.GetString(), "%i %i %i", &r, &g, &b );
  448. break;
  449. }
  450. case 3:
  451. {
  452. static ConVarRef cl_teammate_color_4( "cl_teammate_color_4" );
  453. sscanf( cl_teammate_color_4.GetString(), "%i %i %i", &r, &g, &b );
  454. break;
  455. }
  456. case 4:
  457. {
  458. static ConVarRef cl_teammate_color_5( "cl_teammate_color_5" );
  459. sscanf( cl_teammate_color_5.GetString(), "%i %i %i", &r, &g, &b );
  460. break;
  461. }
  462. }
  463. if ( nPos == 0 )
  464. {
  465. params->pRetVal->SetNumber( r );
  466. }
  467. else if ( nPos == 1 )
  468. {
  469. params->pRetVal->SetNumber( g );
  470. }
  471. else if ( nPos == 2 )
  472. {
  473. params->pRetVal->SetNumber( b );
  474. }
  475. }
  476. void BaseSlot::GetPAXAvatarFromName( SCALEFORM_CALLBACK_ARGS_DECL )
  477. {
  478. FunctionHandler::Params* params = FromSFPARAMS( obj );
  479. if ( params->ArgCount != 1 )
  480. {
  481. SFINST.LogPrintf( "scaleform: script called GetPAXAvatarFromName with %d args\n", params->ArgCount );
  482. }
  483. else
  484. {
  485. const char* playerName = params->pArgs[0].GetString();
  486. if ( !playerName || !*playerName )
  487. {
  488. SFINST.LogPrintf( "scaleform: script called GetPAXAvatarFromName with bad first argument\n" );
  489. }
  490. else
  491. {
  492. int nAvatarIndex = V_atoi( playerName + ( V_strlen( playerName ) - 1 ) );
  493. char szAvatar[256];
  494. V_snprintf( szAvatar, ARRAYSIZE( szAvatar ), "demo_avatars/CSGO_AVATAR_%d.dds", nAvatarIndex );
  495. m_pMovieView->CreateString( params->pRetVal, szAvatar );
  496. }
  497. }
  498. }
  499. void BaseSlot::SetConvar( SCALEFORM_CALLBACK_ARGS_DECL )
  500. {
  501. FunctionHandler::Params* params = FromSFPARAMS( obj );
  502. if ( params->ArgCount != 2 )
  503. {
  504. SFINST.LogPrintf( "scaleform: script called setconver with %d args\n", params->ArgCount );
  505. }
  506. else
  507. {
  508. const char* convarname = params->pArgs[0].GetString();
  509. if ( !convarname || !*convarname )
  510. {
  511. SFINST.LogPrintf( "scaleform: script called setconver with bad first argument\n" );
  512. }
  513. else
  514. {
  515. ConVarRef varref( convarname );
  516. switch ( params->pArgs[1].GetType() )
  517. {
  518. case Value::VT_Boolean:
  519. varref.SetValue( params->pArgs[1].GetBool() );
  520. break;
  521. case Value::VT_Number:
  522. varref.SetValue( ( float ) params->pArgs[1].GetNumber() );
  523. break;
  524. case Value::VT_String:
  525. varref.SetValue( params->pArgs[1].GetString() );
  526. break;
  527. default:
  528. SFINST.LogPrintf( "scaleform: illegal attempt to set %s to type number# 0x%x\n", convarname, params->pArgs[1].GetType() );
  529. break;
  530. }
  531. #if defined( DEBUG )
  532. if ( varref.IsValid() )
  533. {
  534. SFINST.LogPrintf( "scaleform: set convar %s to %s\n", convarname, varref.GetString() );
  535. }
  536. else
  537. {
  538. SFINST.LogPrintf( "scaleform: convar %s is not valid\n", convarname );
  539. }
  540. #endif
  541. }
  542. }
  543. }
  544. void BaseSlot::Translate( SCALEFORM_CALLBACK_ARGS_DECL )
  545. {
  546. FunctionHandler::Params* params = FromSFPARAMS( obj );
  547. const char* value = NULL;
  548. if ( !params->pArgs[0].IsUndefined() )
  549. {
  550. value = params->pArgs[0].GetString();
  551. }
  552. else
  553. {
  554. Warning( "Actionscript passed an undefined param to BaseSlot::Translate!\n" );
  555. }
  556. if ( value && *value == '#' )
  557. {
  558. m_pMovieView->CreateStringW( params->pRetVal, SFINST.Translate( value, NULL ) );
  559. }
  560. else
  561. {
  562. *( params->pRetVal ) = params->pArgs[0];
  563. }
  564. }
  565. void BaseSlot::ReplaceGlyphs( SCALEFORM_CALLBACK_ARGS_DECL )
  566. {
  567. FunctionHandler::Params* params = FromSFPARAMS( obj );
  568. const char* text = NULL;
  569. const wchar_t* wtext = NULL;
  570. int fontSize = 0;
  571. if ( params->pArgs[0].IsStringW() )
  572. {
  573. wtext = params->pArgs[0].GetStringW();
  574. }
  575. else
  576. {
  577. text = params->pArgs[0].GetString();
  578. }
  579. if ( params->ArgCount == 2 )
  580. {
  581. fontSize = ( int )params->pArgs[1].GetNumber();
  582. }
  583. const wchar_t* result;
  584. if ( text )
  585. {
  586. result = SFINST.ReplaceGlyphKeywordsWithHTML( text, fontSize );
  587. }
  588. else
  589. {
  590. result = SFINST.ReplaceGlyphKeywordsWithHTML( wtext, fontSize );
  591. }
  592. m_pMovieView->CreateStringW( params->pRetVal, result );
  593. }
  594. void BaseSlot::GetClipboardText( SCALEFORM_CALLBACK_ARGS_DECL )
  595. {
  596. int size = g_pVGuiSystem->GetClipboardTextCount();
  597. if ( size )
  598. {
  599. wchar_t* buffer = new wchar_t[size];
  600. g_pVGuiSystem->GetClipboardText( 0, buffer, size * sizeof( wchar_t ) );
  601. m_pMovieView->CreateStringW( FromSFPARAMS( obj )->pRetVal, buffer );
  602. delete[] buffer;
  603. }
  604. else
  605. {
  606. FromSFPARAMS( obj )->pRetVal->SetNull();
  607. }
  608. }
  609. void BaseSlot::SetClipboardText( SCALEFORM_CALLBACK_ARGS_DECL )
  610. {
  611. FunctionHandler::Params* params = FromSFPARAMS( obj );
  612. if ( params->ArgCount > 0 )
  613. {
  614. if ( params->pArgs[0].IsStringW() )
  615. {
  616. const wchar_t* pString = params->pArgs[0].GetStringW();
  617. if ( pString )
  618. {
  619. int len = V_wcslen( pString );
  620. g_pVGuiSystem->SetClipboardText( pString, len+1 );
  621. }
  622. }
  623. else if ( params->pArgs[0].IsString() )
  624. {
  625. const char* pString = params->pArgs[0].GetString();
  626. if ( pString )
  627. {
  628. int len = strlen( pString );
  629. g_pVGuiSystem->SetClipboardText( pString, len+1 );
  630. }
  631. }
  632. }
  633. }
  634. void BaseSlot::MakeStringSafe( SCALEFORM_CALLBACK_ARGS_DECL )
  635. {
  636. FunctionHandler::Params* params = FromSFPARAMS( obj );
  637. const char* intext = NULL;
  638. if ( params && params->ArgCount > 0 )
  639. intext = params->pArgs[0].GetString();
  640. if ( !intext )
  641. {
  642. m_pMovieView->CreateStringW( params->pRetVal, L"" );
  643. return;
  644. }
  645. int originalStringLength = V_strlen( intext )+1;
  646. wchar_t* pFirstBuffer = new wchar_t[originalStringLength];
  647. V_UTF8ToUnicode( intext, pFirstBuffer, originalStringLength*sizeof( wchar_t ) );
  648. wchar_t* pSecondBuffer = new wchar_t[originalStringLength*15];
  649. SFINST.MakeStringSafe( pFirstBuffer, pSecondBuffer, originalStringLength * sizeof( wchar_t )*15 );
  650. m_pMovieView->CreateStringW( params->pRetVal, pSecondBuffer );
  651. delete[] pFirstBuffer;
  652. delete[] pSecondBuffer;
  653. }
  654. void BaseSlot::ConsoleCommand( SCALEFORM_CALLBACK_ARGS_DECL )
  655. {
  656. FunctionHandler::Params* params = FromSFPARAMS( obj );
  657. const char *command = params->pArgs[0].GetString();
  658. SFINST.GetEnginePtr()->ClientCmd( command );
  659. }
  660. void BaseSlot::ConsoleCommandExecute( SCALEFORM_CALLBACK_ARGS_DECL )
  661. {
  662. FunctionHandler::Params* params = FromSFPARAMS( obj );
  663. const char *command = params->pArgs[0].GetString();
  664. SFINST.GetEnginePtr()->ExecuteClientCmd( command );
  665. }
  666. void BaseSlot::SendUIEvent( SCALEFORM_CALLBACK_ARGS_DECL )
  667. {
  668. FunctionHandler::Params* params = FromSFPARAMS( obj );
  669. SFINST.SendUIEvent( params->pArgs[0].GetString(), params->pArgs[1].GetString(), m_iSlot);
  670. }
  671. void BaseSlot::UpdateSafeZone( void )
  672. {
  673. m_GlobalValue.Invoke( "UpdateSafeZone", 0 );
  674. }
  675. bool BaseSlot::SetToControllerUI( bool value, bool isKeyOrButtonPress )
  676. {
  677. if ( value && g_pInputSystem->GetCurrentInputDevice() == INPUT_DEVICE_STEAM_CONTROLLER )
  678. {
  679. // When we are using a steam controller we never want to use
  680. // controller UI.
  681. value = false;
  682. }
  683. #if defined WIN32
  684. if ( g_pInputSystem->IsSamplingForCurrentDevice( ) && isKeyOrButtonPress )
  685. {
  686. if( value )
  687. {
  688. g_pInputSystem->SetCurrentInputDevice( INPUT_DEVICE_GAMEPAD );
  689. ConVarRef var( "joystick" );
  690. if( var.IsValid( ) )
  691. var.SetValue( 1 );
  692. }
  693. else
  694. {
  695. g_pInputSystem->SetCurrentInputDevice( INPUT_DEVICE_KEYBOARD_MOUSE );
  696. ConVarRef var( "joystick" );
  697. if( var.IsValid( ) )
  698. var.SetValue( 0 );
  699. }
  700. g_pInputSystem->SampleInputToFindCurrentDevice( false );
  701. }
  702. #endif
  703. if ( value != m_bControllerUI )
  704. {
  705. if ( m_fChangeControllerTimeout <= 0 )
  706. {
  707. Value showem( value );
  708. m_bControllerUI = value;
  709. m_GlobalValue.Invoke( "SetToControllerUI", NULL, &showem, 1 );
  710. m_fChangeControllerTimeout = CHANGE_CONTROLLER_TIMEOUT;
  711. return true;
  712. }
  713. }
  714. return false;
  715. }
  716. bool BaseSlot::IsSetToControllerUI( void )
  717. {
  718. return m_bControllerUI;
  719. }
  720. void BaseSlot::UpdateTint( void )
  721. {
  722. m_GlobalValue.Invoke( "UpdateTint", 0 );
  723. }
  724. bool BaseSlot::HandleKeyEvent( bool keyDown, ButtonCode_t code, ButtonCode_t vkey, const char* binding, int slot )
  725. {
  726. Value args[4];
  727. Value flashResult;
  728. flashResult.SetNull();
  729. args[0].SetNumber( ( SF::Double ) code );
  730. args[1].SetNumber( ( SF::Double ) vkey );
  731. args[2].SetNumber( ( SF::Double ) slot );
  732. if ( binding && *binding == '+' )
  733. binding++;
  734. args[3].SetString( binding );
  735. m_GlobalValue.Invoke( keyDown ? "KeyDownEvent" : "KeyUpEvent", &flashResult, args, 4 );
  736. if (flashResult.IsBool())
  737. return flashResult.GetBool();
  738. else
  739. return false;
  740. }
  741. bool BaseSlot::HandleCharTyped( const wchar_t* typed, int slot )
  742. {
  743. Value args[2];
  744. Value result;
  745. result.SetNull();
  746. args[0].SetStringW( typed );
  747. args[1].SetNumber( ( SF::Double ) slot );
  748. #if defined( _OSX )
  749. // [will] - HACK: Change Mac's backspace 127 (del) character into '\b' for chat window.
  750. if( *typed == 127 )
  751. {
  752. args[0].SetString( "\b" );
  753. }
  754. #endif
  755. m_GlobalValue.Invoke( "CharTyped", &result, args, 2 );
  756. return !result.IsNull() && result.GetBool();
  757. }
  758. void BaseSlot::LockInputToSlot( int slot )
  759. {
  760. Value args[1];
  761. args[0].SetNumber( ( SF::Double ) slot );
  762. m_GlobalValue.Invoke( "LockInputToSlot", NULL, args, 1 );
  763. }
  764. void BaseSlot::UnlockInput( void )
  765. {
  766. m_GlobalValue.Invoke( "UnlockInput", NULL );
  767. }
  768. void BaseSlot::ForceCollectGarbage( void )
  769. {
  770. if ( m_pMovieView )
  771. m_pMovieView->ForceCollectGarbage( );
  772. }
  773. void BaseSlot::CreateKeyTable()
  774. {
  775. Value keyTable;
  776. m_pMovieView->CreateObject( &keyTable );
  777. m_GlobalValue.SetMember( "ValveKeyTable", keyTable );
  778. #define KEYENTRY( value) \
  779. { \
  780. Value gfxv; \
  781. char numberAsString[10]; \
  782. \
  783. gfxv.SetNumber((SF::Double)(value)); \
  784. keyTable.SetMember(#value, gfxv); \
  785. \
  786. V_snprintf(numberAsString, sizeof(numberAsString), "%d", value); \
  787. gfxv.SetString(#value); \
  788. keyTable.SetMember(numberAsString, gfxv); \
  789. }
  790. KEYENTRY( KEY_NONE );
  791. KEYENTRY( KEY_0 );
  792. KEYENTRY( KEY_1 );
  793. KEYENTRY( KEY_2 );
  794. KEYENTRY( KEY_3 );
  795. KEYENTRY( KEY_4 );
  796. KEYENTRY( KEY_5 );
  797. KEYENTRY( KEY_6 );
  798. KEYENTRY( KEY_7 );
  799. KEYENTRY( KEY_8 );
  800. KEYENTRY( KEY_9 );
  801. KEYENTRY( KEY_A );
  802. KEYENTRY( KEY_B );
  803. KEYENTRY( KEY_C );
  804. KEYENTRY( KEY_D );
  805. KEYENTRY( KEY_E );
  806. KEYENTRY( KEY_F );
  807. KEYENTRY( KEY_G );
  808. KEYENTRY( KEY_H );
  809. KEYENTRY( KEY_I );
  810. KEYENTRY( KEY_J );
  811. KEYENTRY( KEY_K );
  812. KEYENTRY( KEY_L );
  813. KEYENTRY( KEY_M );
  814. KEYENTRY( KEY_N );
  815. KEYENTRY( KEY_O );
  816. KEYENTRY( KEY_P );
  817. KEYENTRY( KEY_Q );
  818. KEYENTRY( KEY_R );
  819. KEYENTRY( KEY_S );
  820. KEYENTRY( KEY_T );
  821. KEYENTRY( KEY_U );
  822. KEYENTRY( KEY_V );
  823. KEYENTRY( KEY_W );
  824. KEYENTRY( KEY_X );
  825. KEYENTRY( KEY_Y );
  826. KEYENTRY( KEY_Z );
  827. KEYENTRY( KEY_PAD_0 );
  828. KEYENTRY( KEY_PAD_1 );
  829. KEYENTRY( KEY_PAD_2 );
  830. KEYENTRY( KEY_PAD_3 );
  831. KEYENTRY( KEY_PAD_4 );
  832. KEYENTRY( KEY_PAD_5 );
  833. KEYENTRY( KEY_PAD_6 );
  834. KEYENTRY( KEY_PAD_7 );
  835. KEYENTRY( KEY_PAD_8 );
  836. KEYENTRY( KEY_PAD_9 );
  837. KEYENTRY( KEY_PAD_DIVIDE );
  838. KEYENTRY( KEY_PAD_MULTIPLY );
  839. KEYENTRY( KEY_PAD_MINUS );
  840. KEYENTRY( KEY_PAD_PLUS );
  841. KEYENTRY( KEY_PAD_ENTER );
  842. KEYENTRY( KEY_PAD_DECIMAL );
  843. KEYENTRY( KEY_LBRACKET );
  844. KEYENTRY( KEY_RBRACKET );
  845. KEYENTRY( KEY_SEMICOLON );
  846. KEYENTRY( KEY_APOSTROPHE );
  847. KEYENTRY( KEY_BACKQUOTE );
  848. KEYENTRY( KEY_COMMA );
  849. KEYENTRY( KEY_PERIOD );
  850. KEYENTRY( KEY_SLASH );
  851. KEYENTRY( KEY_BACKSLASH );
  852. KEYENTRY( KEY_MINUS );
  853. KEYENTRY( KEY_EQUAL );
  854. KEYENTRY( KEY_ENTER );
  855. KEYENTRY( KEY_SPACE );
  856. KEYENTRY( KEY_BACKSPACE );
  857. KEYENTRY( KEY_TAB );
  858. KEYENTRY( KEY_CAPSLOCK );
  859. KEYENTRY( KEY_NUMLOCK );
  860. KEYENTRY( KEY_ESCAPE );
  861. KEYENTRY( KEY_SCROLLLOCK );
  862. KEYENTRY( KEY_INSERT );
  863. KEYENTRY( KEY_DELETE );
  864. KEYENTRY( KEY_HOME );
  865. KEYENTRY( KEY_END );
  866. KEYENTRY( KEY_PAGEUP );
  867. KEYENTRY( KEY_PAGEDOWN );
  868. KEYENTRY( KEY_BREAK );
  869. KEYENTRY( KEY_LSHIFT );
  870. KEYENTRY( KEY_RSHIFT );
  871. KEYENTRY( KEY_LALT );
  872. KEYENTRY( KEY_RALT );
  873. KEYENTRY( KEY_LCONTROL );
  874. KEYENTRY( KEY_RCONTROL );
  875. KEYENTRY( KEY_LWIN );
  876. KEYENTRY( KEY_RWIN );
  877. KEYENTRY( KEY_APP );
  878. KEYENTRY( KEY_UP );
  879. KEYENTRY( KEY_LEFT );
  880. KEYENTRY( KEY_DOWN );
  881. KEYENTRY( KEY_RIGHT );
  882. KEYENTRY( KEY_F1 );
  883. KEYENTRY( KEY_F2 );
  884. KEYENTRY( KEY_F3 );
  885. KEYENTRY( KEY_F4 );
  886. KEYENTRY( KEY_F5 );
  887. KEYENTRY( KEY_F6 );
  888. KEYENTRY( KEY_F7 );
  889. KEYENTRY( KEY_F8 );
  890. KEYENTRY( KEY_F9 );
  891. KEYENTRY( KEY_F10 );
  892. KEYENTRY( KEY_F11 );
  893. KEYENTRY( KEY_F12 );
  894. KEYENTRY( KEY_CAPSLOCKTOGGLE );
  895. KEYENTRY( KEY_NUMLOCKTOGGLE );
  896. KEYENTRY( KEY_SCROLLLOCKTOGGLE );
  897. KEYENTRY( MOUSE_LEFT );
  898. KEYENTRY( MOUSE_RIGHT );
  899. KEYENTRY( MOUSE_MIDDLE );
  900. KEYENTRY( MOUSE_4 );
  901. KEYENTRY( MOUSE_5 );
  902. KEYENTRY( MOUSE_WHEEL_UP );
  903. KEYENTRY( MOUSE_WHEEL_DOWN );
  904. KEYENTRY( KEY_XBUTTON_UP );
  905. KEYENTRY( KEY_XBUTTON_RIGHT );
  906. KEYENTRY( KEY_XBUTTON_DOWN );
  907. KEYENTRY( KEY_XBUTTON_LEFT );
  908. KEYENTRY( KEY_XBUTTON_A );
  909. KEYENTRY( KEY_XBUTTON_B );
  910. KEYENTRY( KEY_XBUTTON_X );
  911. KEYENTRY( KEY_XBUTTON_Y );
  912. KEYENTRY( KEY_XBUTTON_LEFT_SHOULDER );
  913. KEYENTRY( KEY_XBUTTON_RIGHT_SHOULDER );
  914. KEYENTRY( KEY_XBUTTON_BACK );
  915. KEYENTRY( KEY_XBUTTON_START );
  916. KEYENTRY( KEY_XBUTTON_STICK1 );
  917. KEYENTRY( KEY_XBUTTON_STICK2 );
  918. KEYENTRY( KEY_XBUTTON_INACTIVE_START );
  919. KEYENTRY( KEY_XSTICK1_RIGHT );
  920. KEYENTRY( KEY_XSTICK1_LEFT );
  921. KEYENTRY( KEY_XSTICK1_DOWN );
  922. KEYENTRY( KEY_XSTICK1_UP );
  923. KEYENTRY( KEY_XBUTTON_LTRIGGER );
  924. KEYENTRY( KEY_XBUTTON_RTRIGGER );
  925. KEYENTRY( KEY_XSTICK2_RIGHT );
  926. KEYENTRY( KEY_XSTICK2_LEFT );
  927. KEYENTRY( KEY_XSTICK2_DOWN );
  928. KEYENTRY( KEY_XSTICK2_UP );
  929. KEYENTRY( KEY_XBUTTON_FIREMODE_SELECTOR_1 );
  930. KEYENTRY( KEY_XBUTTON_FIREMODE_SELECTOR_2 );
  931. KEYENTRY( KEY_XBUTTON_FIREMODE_SELECTOR_3 );
  932. KEYENTRY( KEY_XBUTTON_RELOAD );
  933. KEYENTRY( KEY_XBUTTON_TRIGGER );
  934. KEYENTRY( KEY_XBUTTON_PUMP_ACTION );
  935. KEYENTRY( KEY_XBUTTON_ROLL_RIGHT );
  936. KEYENTRY( KEY_XBUTTON_ROLL_LEFT );
  937. }
  938. void BaseSlot::Init( const char* movieName, int slot )
  939. {
  940. SFDevMsg("BaseSlot::Init(%s,%d)\n", movieName, slot);
  941. m_iSlot = slot;
  942. m_pMovieDef = FromSFMOVIEDEF( SFINST.CreateMovieDef( movieName ) );
  943. if ( m_pMovieDef )
  944. {
  945. m_pMovieView = FromSFMOVIE( SFINST.MovieDef_CreateInstance( ToSFMOVIEDEF( m_pMovieDef ), true ) );
  946. m_pMovieView->SetViewScaleMode( Movie::SM_NoScale );
  947. m_pMovieView->SetViewAlignment( Movie::Align_TopLeft );
  948. m_pMovieView->GetVariable( &m_GlobalValue, "_global" );
  949. if ( slot == SF_FULL_SCREEN_SLOT ) // main menu slot receives IME focus on startup
  950. {
  951. m_pMovieView->HandleEvent( Event::SetFocus );
  952. }
  953. Value platformCode;
  954. m_bControllerUI = true;
  955. if ( IsX360() )
  956. {
  957. platformCode.SetNumber( 1 );
  958. }
  959. else if ( IsPS3() || SFINST.GetForcePS3() )
  960. {
  961. platformCode.SetNumber( 2 );
  962. }
  963. else if ( IsOSX() )
  964. {
  965. platformCode.SetNumber( 3 );
  966. m_bControllerUI = false;
  967. }
  968. else
  969. {
  970. platformCode.SetNumber( 0 );
  971. m_bControllerUI = false;
  972. }
  973. if ( !m_bControllerUI )
  974. m_bControllerUI = ( m_iSlot != SF_FULL_SCREEN_SLOT ) && ( ( m_iSlot - SF_FIRST_SS_SLOT ) != 0 );
  975. m_GlobalValue.SetMember( "PlatformCode", platformCode );
  976. // we will have to revisit this when the keyboard can be assigned to player 2
  977. m_GlobalValue.SetMember( "wantControllerShown", m_bControllerUI );
  978. Value number;
  979. number.SetNumber( slot );
  980. m_GlobalValue.SetMember( "UISlot", number );
  981. const ScaleformUIFunctionHandlerDefinition* table = GetSlotAPITable();
  982. if ( table )
  983. {
  984. m_pMovieView->CreateObject( &m_GameAPI );
  985. while ( table->m_pName != NULL )
  986. {
  987. SFINST.AddAPIFunctionToObject( ToSFVALUE( &m_GameAPI ), ToSFMOVIE( m_pMovieView ), reinterpret_cast<ScaleformUIFunctionHandlerObject*> ( this ), table );
  988. table++;
  989. }
  990. m_GlobalValue.SetMember( "GameInterface", m_GameAPI );
  991. UpdateTint();
  992. }
  993. CreateKeyTable();
  994. m_pMovieView->SetBackgroundAlpha( 0 );
  995. Advance( 0 );
  996. Value initFunc;
  997. initFunc.SetNull();
  998. if (m_GlobalValue.GetMember( "InitSlot", &initFunc ) )
  999. {
  1000. m_GlobalValue.Invoke( "InitSlot" );
  1001. }
  1002. initFunc.SetNull();
  1003. m_pMovieView->SetViewport( SFINST.GetScreenWidth(), SFINST.GetScreenHeight(), 0, 0, SFINST.GetScreenWidth(), SFINST.GetScreenHeight() );
  1004. m_GlobalValue.Invoke( "ForceResize" );
  1005. }
  1006. else
  1007. {
  1008. // Movie is corrupt or signature mismatch (pcbeta rel)
  1009. Error( "Error loading %s!\n", movieName );
  1010. }
  1011. }
  1012. void BaseSlot::Unload( void )
  1013. {
  1014. SFDevMsg("BaseSlot::Unload slot=%d\n", m_iSlot);
  1015. if ( m_pMovieView )
  1016. {
  1017. // Last-chance function before the slot is unloaded
  1018. // if we're not rendering scaleform, ShutdownSlot may not have a value.
  1019. if ( m_GlobalValue.HasMember( "ShutdownSlot") )
  1020. m_GlobalValue.Invoke( "ShutdownSlot" );
  1021. // Unload all global objects
  1022. for ( UtlSymId_t sym = m_mapGlobalObjects.Head(); sym != m_mapGlobalObjects.InvalidIndex(); sym = m_mapGlobalObjects.Next( sym ) )
  1023. {
  1024. if ( m_mapGlobalObjects[ sym ] )
  1025. {
  1026. Value value;
  1027. value.SetNull();
  1028. m_GlobalValue.SetMember( m_mapGlobalObjects.String( sym ), value );
  1029. m_mapGlobalObjects[sym]->SetNull();
  1030. delete m_mapGlobalObjects[sym];
  1031. m_mapGlobalObjects[sym] = NULL;
  1032. }
  1033. }
  1034. m_mapGlobalObjects.Purge();
  1035. // Unset gameinterface
  1036. Value value;
  1037. value.SetNull();
  1038. m_GlobalValue.SetMember( "GameInterface", value );
  1039. m_GameAPI.SetNull();
  1040. m_GlobalValue.SetNull();
  1041. SFINST.ReleaseMovieView( ToSFMOVIE( m_pMovieView ) );
  1042. SFINST.ReleaseMovieDef( ToSFMOVIEDEF( m_pMovieDef ) );
  1043. m_pMovieView = NULL;
  1044. m_pMovieDef = NULL;
  1045. }
  1046. m_iSlot = -1;
  1047. }
  1048. void BaseSlot::AddRef( void )
  1049. {
  1050. ThreadInterlockedIncrement( &m_iRefCount );
  1051. }
  1052. bool BaseSlot::Release( void )
  1053. {
  1054. ThreadInterlockedDecrement( &m_iRefCount );
  1055. bool result = ( m_iRefCount == 0 );
  1056. if ( result )
  1057. {
  1058. Unload();
  1059. delete this;
  1060. }
  1061. return result;
  1062. }
  1063. void BaseSlot::Advance( float time )
  1064. {
  1065. const int kNumCatchupFrames = 0;
  1066. m_pMovieView->Advance( time, kNumCatchupFrames );
  1067. m_fChangeControllerTimeout -= time;
  1068. }
  1069. void BaseSlot::LockMostRecentInputDevice( void )
  1070. {
  1071. if( m_bControllerUI )
  1072. {
  1073. g_pInputSystem->SetCurrentInputDevice( INPUT_DEVICE_GAMEPAD );
  1074. ConVarRef var( "joystick" );
  1075. if( var.IsValid( ) )
  1076. var.SetValue( 1 );
  1077. }
  1078. else
  1079. {
  1080. g_pInputSystem->SetCurrentInputDevice( INPUT_DEVICE_KEYBOARD_MOUSE );
  1081. ConVarRef var( "joystick" );
  1082. if( var.IsValid( ) )
  1083. var.SetValue( 0 );
  1084. }
  1085. }
  1086. /***********************************************************************************************************/
  1087. static const ScaleformUIFunctionHandlerDefinition rootGameAPITable[] = {
  1088. { "AddInputConsumer", ToScaleformUIFunctionHandler ( &MovieSlot::AddInputConsumer ) },
  1089. { "RemoveInputConsumer", ToScaleformUIFunctionHandler ( &MovieSlot::RemoveInputConsumer ) },
  1090. { "SetCursorShape", ToScaleformUIFunctionHandler ( &MovieSlot::SetCursorShape ) },
  1091. { "ShowCursor", ToScaleformUIFunctionHandler ( &MovieSlot::ShowCursor ) },
  1092. { "HideCursor", ToScaleformUIFunctionHandler ( &MovieSlot::HideCursor ) },
  1093. { "LoadKVFile", ToScaleformUIFunctionHandler ( &MovieSlot::LoadKVFile ) },
  1094. { "SaveKVFile", ToScaleformUIFunctionHandler ( &MovieSlot::SaveKVFile ) },
  1095. { "SetConvar", ToScaleformUIFunctionHandler ( &MovieSlot::SetConvar ) },
  1096. { "GetConvarNumber", ToScaleformUIFunctionHandler ( &MovieSlot::GetConvarNumber ) },
  1097. { "GetConvarNumberMin", ToScaleformUIFunctionHandler ( &MovieSlot::GetConvarNumberMin ) },
  1098. { "GetConvarNumberMax", ToScaleformUIFunctionHandler ( &MovieSlot::GetConvarNumberMax ) },
  1099. { "GetConvarString", ToScaleformUIFunctionHandler ( &MovieSlot::GetConvarString ) },
  1100. { "GetConvarBoolean", ToScaleformUIFunctionHandler ( &MovieSlot::GetConvarBoolean ) },
  1101. { "GetPAXAvatarFromName", ToScaleformUIFunctionHandler ( &MovieSlot::GetPAXAvatarFromName ) },
  1102. { "GetPlayerColorObject", ToScaleformUIFunctionHandler ( &MovieSlot::GetPlayerColorObject ) },
  1103. { "Translate", ToScaleformUIFunctionHandler ( &MovieSlot::Translate ) },
  1104. { "ReplaceGlyphs", ToScaleformUIFunctionHandler ( &MovieSlot::ReplaceGlyphs ) },
  1105. { "PlaySound", ToScaleformUIFunctionHandler ( &MovieSlot::PlaySoundScaleform ) },
  1106. { "ConsoleCommand", ToScaleformUIFunctionHandler ( &MovieSlot::ConsoleCommand ) },
  1107. { "ConsoleCommandExecute", ToScaleformUIFunctionHandler ( &MovieSlot::ConsoleCommandExecute ) },
  1108. { "DisableAnalogStickNavigation", ToScaleformUIFunctionHandler ( &MovieSlot::DisableAnalogStickNavigation ) },
  1109. { "DenyInputToGame", ToScaleformUIFunctionHandler ( &MovieSlot::DenyInputToGameFromFlash ) },
  1110. { "SendUIEvent", ToScaleformUIFunctionHandler ( &MovieSlot::SendUIEvent ) },
  1111. { "MakeStringSafe", ToScaleformUIFunctionHandler ( &MovieSlot::MakeStringSafe ) },
  1112. { "GetClipboardText", ToScaleformUIFunctionHandler ( &MovieSlot::GetClipboardText ) },
  1113. { "SetClipboardText", ToScaleformUIFunctionHandler ( &MovieSlot::SetClipboardText ) },
  1114. { NULL, NULL } };
  1115. const ScaleformUIFunctionHandlerDefinition* MovieSlot::GetSlotAPITable( void )
  1116. {
  1117. return rootGameAPITable;
  1118. }
  1119. MovieSlot::MovieSlot() :
  1120. BaseSlot()
  1121. {
  1122. m_iNumInputConsumers = 0;
  1123. m_bDisableAnalogNavigation = false;
  1124. }
  1125. void MovieSlot::AddInputConsumer( SCALEFORM_CALLBACK_ARGS_DECL )
  1126. {
  1127. m_iNumInputConsumers++;
  1128. }
  1129. void MovieSlot::RemoveInputConsumer( SCALEFORM_CALLBACK_ARGS_DECL )
  1130. {
  1131. if ( m_iNumInputConsumers <= 0 )
  1132. DebuggerBreakIfDebugging();
  1133. m_iNumInputConsumers = ( m_iNumInputConsumers <= 1 ) ? 0 : m_iNumInputConsumers--;
  1134. }
  1135. void MovieSlot::SetCursorShape( SCALEFORM_CALLBACK_ARGS_DECL )
  1136. {
  1137. // get the cursor shape index
  1138. int i = ( int ) pui->Params_GetArgAsNumber( obj, 0 );
  1139. SFINST.SetCursorShape( i );
  1140. }
  1141. void MovieSlot::ShowCursor( SCALEFORM_CALLBACK_ARGS_DECL )
  1142. {
  1143. if ( SFINST.IsSlotKeyboardAccessible( m_iSlot ) )
  1144. SFINST.ShowCursor();
  1145. }
  1146. void MovieSlot::HideCursor( SCALEFORM_CALLBACK_ARGS_DECL )
  1147. {
  1148. if ( SFINST.IsSlotKeyboardAccessible( m_iSlot ) )
  1149. SFINST.HideCursor();
  1150. }
  1151. #if defined( _PS3 )
  1152. void MovieSlot::PS3UseMoveCursor( SCALEFORM_CALLBACK_ARGS_DECL )
  1153. {
  1154. if ( SFINST.IsSlotKeyboardAccessible( m_iSlot ) )
  1155. SFINST.PS3UseMoveCursor();
  1156. }
  1157. void MovieSlot::PS3UseStandardCursor( SCALEFORM_CALLBACK_ARGS_DECL )
  1158. {
  1159. if ( SFINST.IsSlotKeyboardAccessible( m_iSlot ) )
  1160. SFINST.PS3UseStandardCursor();
  1161. }
  1162. void MovieSlot::PS3ForceCursorStart( SCALEFORM_CALLBACK_ARGS_DECL )
  1163. {
  1164. if ( SFINST.IsSlotKeyboardAccessible( m_iSlot ) )
  1165. SFINST.PS3ForceCursorStart();
  1166. }
  1167. void MovieSlot::PS3ForceCursorEnd( SCALEFORM_CALLBACK_ARGS_DECL )
  1168. {
  1169. if ( SFINST.IsSlotKeyboardAccessible( m_iSlot ) )
  1170. SFINST.PS3ForceCursorEnd();
  1171. }
  1172. #endif
  1173. void MovieSlot::PlaySoundScaleform( SCALEFORM_CALLBACK_ARGS_DECL )
  1174. {
  1175. const char* soundname = pui->Params_GetArgAsString( obj, 0 );
  1176. vgui::surface()->PlaySound( soundname );
  1177. }
  1178. void MovieSlot::DenyInputToGameFromFlash( SCALEFORM_CALLBACK_ARGS_DECL )
  1179. {
  1180. bool bDenyInput = pui->Params_GetArgAsBool( obj, 0 );
  1181. SFINST.DenyInputToGameFromFlash( m_iSlot, bDenyInput );
  1182. }
  1183. void MovieSlot::DisableAnalogStickNavigation( SCALEFORM_CALLBACK_ARGS_DECL )
  1184. {
  1185. bool bDisable = true;
  1186. if ( pui->Params_GetNumArgs( obj ) > 0 )
  1187. {
  1188. bDisable = pui->Params_GetArgAsBool( obj, 0 );
  1189. }
  1190. m_bDisableAnalogNavigation = bDisable;
  1191. }
  1192. bool MovieSlot::AnalogStickNavigationDisabled( void )
  1193. {
  1194. return m_bDisableAnalogNavigation;
  1195. }
  1196. void MovieSlot::RequestElement( const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject )
  1197. {
  1198. if ( m_pMovieView )
  1199. {
  1200. Value args[2];
  1201. m_pMovieView->CreateString( &args[0], elementName );
  1202. m_pMovieView->CreateObject( &args[1] );
  1203. const ScaleformUIFunctionHandlerDefinition* table = tableObject->GetTable();
  1204. while ( table->m_pName != NULL )
  1205. {
  1206. SFINST.AddAPIFunctionToObject( ToSFVALUE( &args[1] ), ToSFMOVIE( m_pMovieView ), object, table );
  1207. table++;
  1208. }
  1209. // now that we've got the api, call flash's load element
  1210. m_GlobalValue.Invoke( "RequestElement", NULL, args, 2 );
  1211. }
  1212. }
  1213. void MovieSlot::RemoveElement( Value* element )
  1214. {
  1215. if ( m_pMovieView )
  1216. {
  1217. m_GlobalValue.Invoke( "RemoveElement", NULL, element, 1 );
  1218. }
  1219. }
  1220. void MovieSlot::InstallGlobalObject( const char* elementName, ScaleformUIFunctionHandlerObject* object, const IScaleformUIFunctionHandlerDefinitionTable* tableObject, SF::GFx::Value* *pInstalledGlobalObjectResult )
  1221. {
  1222. if ( m_mapGlobalObjects.Defined( elementName ) && m_mapGlobalObjects[elementName] )
  1223. {
  1224. Error( "SF Global Object %s is already installed!\n", elementName );
  1225. return;
  1226. }
  1227. const ScaleformUIFunctionHandlerDefinition* table = tableObject->GetTable();
  1228. if ( !table || !object )
  1229. {
  1230. Error( "SF Global Object %s has NULL table!\n", elementName );
  1231. return;
  1232. }
  1233. Value *pValue = new Value;
  1234. m_pMovieView->CreateObject( pValue );
  1235. while ( table->m_pName != NULL )
  1236. {
  1237. SFINST.AddAPIFunctionToObject( ToSFVALUE( pValue ), ToSFMOVIE( m_pMovieView ), object, table );
  1238. table++;
  1239. }
  1240. m_GlobalValue.SetMember( elementName, *pValue );
  1241. m_mapGlobalObjects[ elementName ] = pValue;
  1242. *pInstalledGlobalObjectResult = pValue;
  1243. }
  1244. void MovieSlot::RemoveGlobalObject( SF::GFx::Value* element )
  1245. {
  1246. for ( UtlSymId_t sym = m_mapGlobalObjects.Head(); sym != m_mapGlobalObjects.InvalidIndex(); sym = m_mapGlobalObjects.Next( sym ) )
  1247. {
  1248. if ( m_mapGlobalObjects[ sym ] == element )
  1249. {
  1250. Value value;
  1251. value.SetNull();
  1252. m_GlobalValue.SetMember( m_mapGlobalObjects.String( sym ), value );
  1253. m_mapGlobalObjects[sym]->SetNull();
  1254. delete m_mapGlobalObjects[sym];
  1255. m_mapGlobalObjects[sym] = NULL;
  1256. return;
  1257. }
  1258. }
  1259. Error( "Attempted to remove SF Global Object which is not installed!\n" );
  1260. }
  1261. /***************************************************************************************************/
  1262. void CursorSlot::SetCursorShape( int shape )
  1263. {
  1264. Value newShape;
  1265. newShape.SetNumber( shape );
  1266. m_GlobalValue.Invoke( "SetCursorShape", NULL, &newShape, 1 );
  1267. }
  1268. void CursorSlot::Hide( void )
  1269. {
  1270. if ( !m_bUIHidden )
  1271. {
  1272. m_bUIHidden = true;
  1273. m_GlobalValue.Invoke( "Hide", NULL );
  1274. }
  1275. }
  1276. void CursorSlot::Show( void )
  1277. {
  1278. if ( m_bUIHidden )
  1279. {
  1280. m_bUIHidden = false;
  1281. m_GlobalValue.Invoke( "Show", NULL );
  1282. }
  1283. }