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.

458 lines
12 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "econ_sample_rootui.h"
  8. #include "vgui/IInput.h"
  9. #include <vgui/ILocalize.h>
  10. #include "ienginevgui.h"
  11. #include "econ_item_inventory.h"
  12. #include "backpack_panel.h"
  13. #include "item_pickup_panel.h"
  14. #include "store/store_panel.h"
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include <tier0/memdbgon.h>
  17. static vgui::DHANDLE<CEconSampleRootUI> g_EconSampleRootUIPanel;
  18. #if !defined (TF_CLIENT_DLL)
  19. IEconRootUI *EconUI( void )
  20. {
  21. if (!g_EconSampleRootUIPanel.Get())
  22. {
  23. g_EconSampleRootUIPanel = vgui::SETUP_PANEL( new CEconSampleRootUI( NULL ) );
  24. g_EconSampleRootUIPanel->InvalidateLayout( false, true );
  25. }
  26. return g_EconSampleRootUIPanel;
  27. }
  28. #endif
  29. //-----------------------------------------------------------------------------
  30. // Purpose: Basic help dialog
  31. //-----------------------------------------------------------------------------
  32. CEconSampleRootUI::CEconSampleRootUI( vgui::Panel *parent ) : vgui::Frame(parent, "econ_sample_rootui")
  33. {
  34. // Econ UI is parented to the game UI panel (not the client DLL panel).
  35. vgui::VPANEL gameuiPanel = enginevgui->GetPanel( PANEL_GAMEUIDLL );
  36. SetParent( gameuiPanel );
  37. // We don't want the gameui to delete us, or things get messy
  38. SetAutoDelete( false );
  39. SetMoveable( false );
  40. SetSizeable( false );
  41. SetCloseButtonVisible( false );
  42. vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/ClientScheme.res", "ClientScheme");
  43. SetScheme(scheme);
  44. SetProportional( true );
  45. ListenForGameEvent( "gameui_hidden" );
  46. // Create our subpanels
  47. m_pBackpackPanel = new CBackpackPanel( this, "backpack_panel" );
  48. // Start with just the base UI visible
  49. m_nVisiblePanel = ECONUI_BASEUI;
  50. UpdateSubPanelVisibility();
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose:
  54. //-----------------------------------------------------------------------------
  55. CEconSampleRootUI::~CEconSampleRootUI()
  56. {
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose:
  60. //-----------------------------------------------------------------------------
  61. void CEconSampleRootUI::ApplySchemeSettings( vgui::IScheme *pScheme )
  62. {
  63. BaseClass::ApplySchemeSettings( pScheme );
  64. LoadControlSettings( "Resource/UI/Econ/RootUI.res" );
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. //-----------------------------------------------------------------------------
  69. void CEconSampleRootUI::PerformLayout( void )
  70. {
  71. if ( GetVParent() )
  72. {
  73. int w,h;
  74. vgui::ipanel()->GetSize( GetVParent(), w, h );
  75. SetBounds(0,0,w,h);
  76. }
  77. BaseClass::PerformLayout();
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Purpose:
  81. //-----------------------------------------------------------------------------
  82. void CEconSampleRootUI::ShowPanel(bool bShow)
  83. {
  84. m_bPreventClosure = false;
  85. SetVisible( bShow );
  86. if ( bShow )
  87. {
  88. MoveToFront();
  89. m_nVisiblePanel = ECONUI_BASEUI;
  90. UpdateSubPanelVisibility();
  91. InventoryManager()->ShowItemsPickedUp( true, false );
  92. }
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Purpose:
  96. //-----------------------------------------------------------------------------
  97. void CEconSampleRootUI::FireGameEvent( IGameEvent *event )
  98. {
  99. const char * type = event->GetName();
  100. if ( Q_strcmp(type, "gameui_hidden") == 0 )
  101. {
  102. if ( m_bPreventClosure )
  103. {
  104. engine->ClientCmd_Unrestricted( "gameui_activate" );
  105. }
  106. else
  107. {
  108. ShowPanel( false );
  109. }
  110. }
  111. }
  112. //-----------------------------------------------------------------------------
  113. // Purpose:
  114. //-----------------------------------------------------------------------------
  115. void CEconSampleRootUI::OnCommand( const char *command )
  116. {
  117. if ( !Q_stricmp( command, "close" ) )
  118. {
  119. ShowPanel( false );
  120. // If we're connected to a game server, we also close the game UI.
  121. if ( engine->IsInGame() )
  122. {
  123. bool bClose = true;
  124. if ( m_bCheckForRoomOnExit )
  125. {
  126. // Check to make sure the player has room for all his items. If not, bring up the discard panel. Otherwise, go away.
  127. // We need to do this to catch players who used the "Change Loadout" button in the pickup panel, and may be out of room.
  128. bClose = !InventoryManager()->CheckForRoomAndForceDiscard();
  129. }
  130. if ( bClose )
  131. {
  132. engine->ClientCmd_Unrestricted( "gameui_hide" );
  133. }
  134. }
  135. }
  136. else if ( !Q_stricmp( command, "back" ) )
  137. {
  138. ShowPanel( true );
  139. }
  140. else if ( !Q_stricmp( command, "loadout" ) )
  141. {
  142. // Ignore selection while we don't have a steam connection
  143. if ( !InventoryManager()->GetLocalInventory()->RetrievedInventoryFromSteam() )
  144. return;
  145. OpenSubPanel( ECONUI_LOADOUT );
  146. }
  147. else if ( !Q_strnicmp( command, "backpack", 8 ) )
  148. {
  149. OpenSubPanel( ECONUI_BACKPACK );
  150. }
  151. else if ( !Q_strnicmp( command, "crafting", 8 ) )
  152. {
  153. OpenSubPanel( ECONUI_CRAFTING );
  154. }
  155. else if ( !Q_strnicmp( command, "armory", 6 ) )
  156. {
  157. OpenSubPanel( ECONUI_ARMORY );
  158. }
  159. else if ( !Q_strnicmp( command, "store", 5 ) )
  160. {
  161. EconUI()->OpenStorePanel( 0, false );
  162. }
  163. else if ( !Q_strnicmp( command, "trading", 7 ) )
  164. {
  165. // if ( IsFreeTrialAccount() )
  166. // {
  167. // ShowMessageBox( "#TF_Trial_CannotTrade_Title", "#TF_Trial_CannotTrade_Text", "#GameUI_OK" );
  168. // return;
  169. // }
  170. OpenTradingStartDialog();
  171. }
  172. else
  173. {
  174. engine->ClientCmd( const_cast<char *>( command ) );
  175. }
  176. BaseClass::OnCommand( command );
  177. }
  178. //-----------------------------------------------------------------------------
  179. // Purpose:
  180. //-----------------------------------------------------------------------------
  181. void CEconSampleRootUI::OnKeyCodeTyped(vgui::KeyCode code)
  182. {
  183. if ( code == KEY_ESCAPE )
  184. {
  185. if ( !m_bPreventClosure )
  186. {
  187. ShowPanel( false );
  188. }
  189. }
  190. else
  191. {
  192. BaseClass::OnKeyCodeTyped( code );
  193. }
  194. }
  195. //-----------------------------------------------------------------------------
  196. // Purpose:
  197. //-----------------------------------------------------------------------------
  198. IEconRootUI *CEconSampleRootUI::OpenEconUI( int iDirectToPage, bool bCheckForInventorySpaceOnExit )
  199. {
  200. engine->ClientCmd_Unrestricted( "gameui_activate" );
  201. ShowPanel( true );
  202. if ( iDirectToPage == ECONUI_BACKPACK )
  203. {
  204. }
  205. else if ( iDirectToPage == ECONUI_CRAFTING )
  206. {
  207. }
  208. else if ( iDirectToPage == ECONUI_ARMORY )
  209. {
  210. }
  211. SetCheckForRoomOnExit( bCheckForInventorySpaceOnExit );
  212. return this;
  213. }
  214. //-----------------------------------------------------------------------------
  215. // Purpose:
  216. //-----------------------------------------------------------------------------
  217. void CEconSampleRootUI::CloseEconUI( void )
  218. {
  219. if ( IsVisible() )
  220. {
  221. ShowPanel( false );
  222. }
  223. }
  224. //-----------------------------------------------------------------------------
  225. // Purpose:
  226. //-----------------------------------------------------------------------------
  227. bool CEconSampleRootUI::IsUIPanelVisible( EconBaseUIPanels_t iPanel )
  228. {
  229. if ( !IsVisible() )
  230. return false;
  231. switch ( iPanel )
  232. {
  233. case ECONUI_BASEUI:
  234. return true;
  235. case ECONUI_BACKPACK:
  236. return (GetBackpackPanel() && GetBackpackPanel()->IsVisible());
  237. case ECONUI_CRAFTING:
  238. //return (GetCraftingPanel() && GetCraftingPanel()->IsVisible());
  239. break;
  240. case ECONUI_ARMORY:
  241. break;
  242. case ECONUI_TRADING:
  243. break;
  244. case ECONUI_LOADOUT:
  245. break;
  246. default:
  247. Assert(0);
  248. break;
  249. }
  250. return false;
  251. }
  252. //-----------------------------------------------------------------------------
  253. // Purpose:
  254. //-----------------------------------------------------------------------------
  255. void CEconSampleRootUI::OpenSubPanel( EconBaseUIPanels_t nPanel )
  256. {
  257. m_nVisiblePanel = nPanel;
  258. UpdateSubPanelVisibility();
  259. }
  260. //-----------------------------------------------------------------------------
  261. // Purpose:
  262. //-----------------------------------------------------------------------------
  263. void CEconSampleRootUI::OpenTradingStartDialog( void )
  264. {
  265. }
  266. //-----------------------------------------------------------------------------
  267. // Purpose:
  268. //-----------------------------------------------------------------------------
  269. void CEconSampleRootUI::UpdateSubPanelVisibility( void )
  270. {
  271. bool bBackpackVisible = (m_nVisiblePanel == ECONUI_BACKPACK);
  272. if ( m_pBackpackPanel->IsVisible() != bBackpackVisible )
  273. {
  274. m_pBackpackPanel->ShowPanel( false, bBackpackVisible );
  275. }
  276. //m_pClassLoadoutPanel->SetVisible( false );
  277. //m_pArmoryPanel->SetVisible( false );
  278. //m_pCraftingPanel->ShowPanel( m_iCurrentClassIndex, true, (m_iPrevShowingPanel == CHAP_ARMORY) );
  279. }
  280. static vgui::DHANDLE<CItemPickupPanel> g_ItemPickupPanel;
  281. static vgui::DHANDLE<CItemDiscardPanel> g_ItemDiscardPanel;
  282. //-----------------------------------------------------------------------------
  283. // Purpose:
  284. //-----------------------------------------------------------------------------
  285. CItemPickupPanel *CEconSampleRootUI::OpenItemPickupPanel( void )
  286. {
  287. if (!g_ItemPickupPanel.Get())
  288. {
  289. g_ItemPickupPanel = vgui::SETUP_PANEL( new CItemPickupPanel( NULL ) );
  290. g_ItemPickupPanel->InvalidateLayout( false, true );
  291. }
  292. engine->ClientCmd_Unrestricted( "gameui_activate" );
  293. g_ItemPickupPanel->ShowPanel( true );
  294. return g_ItemPickupPanel;
  295. }
  296. //-----------------------------------------------------------------------------
  297. // Purpose:
  298. //-----------------------------------------------------------------------------
  299. CItemDiscardPanel *CEconSampleRootUI::OpenItemDiscardPanel( void )
  300. {
  301. if (!g_ItemDiscardPanel.Get())
  302. {
  303. g_ItemDiscardPanel = vgui::SETUP_PANEL( new CItemDiscardPanel( NULL ) );
  304. g_ItemDiscardPanel->InvalidateLayout( false, true );
  305. }
  306. engine->ClientCmd_Unrestricted( "gameui_activate" );
  307. g_ItemDiscardPanel->ShowPanel( true );
  308. return g_ItemDiscardPanel;
  309. }
  310. static vgui::DHANDLE<CStorePanel> g_StorePanel;
  311. //-----------------------------------------------------------------------------
  312. // Purpose:
  313. //-----------------------------------------------------------------------------
  314. void CEconSampleRootUI::CreateStorePanel( void )
  315. {
  316. // Clean up previous store panel?
  317. if ( g_StorePanel.Get() != NULL )
  318. {
  319. g_StorePanel->MarkForDeletion();
  320. }
  321. // Create the store panel
  322. g_StorePanel = vgui::SETUP_PANEL( new CStorePanel( NULL ) );
  323. }
  324. //-----------------------------------------------------------------------------
  325. // Purpose:
  326. //-----------------------------------------------------------------------------
  327. CStorePanel *CEconSampleRootUI::OpenStorePanel( int iItemDef, bool bAddToCart )
  328. {
  329. // Make sure we've got the appropriate connections to Steam
  330. if ( !steamapicontext || !steamapicontext->SteamUtils() )
  331. {
  332. OpenStoreStatusDialog( NULL, "#StoreUpdate_SteamRequired", true, false );
  333. return NULL;
  334. }
  335. if ( !steamapicontext->SteamUtils()->IsOverlayEnabled() )
  336. {
  337. OpenStoreStatusDialog( NULL, "#StoreUpdate_OverlayRequired", true, false );
  338. return NULL;
  339. }
  340. if ( !CStorePanel::IsPricesheetLoaded() )
  341. {
  342. OpenStoreStatusDialog( NULL, "#StoreUpdate_Loading", false, false );
  343. CStorePanel::SetShouldShowWarnings( true );
  344. CStorePanel::RequestPricesheet();
  345. return NULL;
  346. }
  347. if ( !g_StorePanel )
  348. return NULL;
  349. engine->ClientCmd_Unrestricted( "gameui_activate" );
  350. if ( iItemDef )
  351. {
  352. g_StorePanel->StartAtItemDef( iItemDef, bAddToCart );
  353. }
  354. g_StorePanel->ShowPanel( true );
  355. return g_StorePanel;
  356. }
  357. //-----------------------------------------------------------------------------
  358. // Purpose:
  359. //-----------------------------------------------------------------------------
  360. CStorePanel *CEconSampleRootUI::GetStorePanel( void )
  361. {
  362. return g_StorePanel;
  363. }
  364. #ifdef _DEBUG
  365. //-----------------------------------------------------------------------------
  366. // Purpose:
  367. //-----------------------------------------------------------------------------
  368. void Open_EconUI( const CCommand &args )
  369. {
  370. EconUI()->OpenEconUI();
  371. }
  372. ConCommand open_econui( "open_econui", Open_EconUI );
  373. //-----------------------------------------------------------------------------
  374. // Purpose:
  375. //-----------------------------------------------------------------------------
  376. void Open_EconUIBackpack( const CCommand &args )
  377. {
  378. EconUI()->OpenEconUI( ECONUI_BACKPACK );
  379. }
  380. ConCommand open_econui_backpack( "open_econui_backpack", Open_EconUIBackpack, "Open the backpack.", FCVAR_NONE );
  381. //-----------------------------------------------------------------------------
  382. // Purpose:
  383. //-----------------------------------------------------------------------------
  384. void Open_EconUICrafting( const CCommand &args )
  385. {
  386. EconUI()->OpenEconUI( ECONUI_CRAFTING );
  387. }
  388. ConCommand open_econui_crafting( "open_econui_crafting", Open_EconUICrafting, "Open the crafting screen.", FCVAR_NONE );
  389. #endif // _DEBUG