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.

4272 lines
143 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "backpack_panel.h"
  8. #include "item_confirm_delete_dialog.h"
  9. #include "vgui/ISurface.h"
  10. #include "gamestringpool.h"
  11. #include "iclientmode.h"
  12. #include "econ_item_inventory.h"
  13. #include "ienginevgui.h"
  14. #include <vgui/ILocalize.h>
  15. #include "vgui_controls/TextImage.h"
  16. #include "vgui_controls/CheckButton.h"
  17. #include "vgui_controls/ComboBox.h"
  18. #include "vgui_controls/ScalableImagePanel.h"
  19. #include "vgui/IInput.h"
  20. #include "econ/tool_items/tool_items.h"
  21. #include "econ_gcmessages.h"
  22. #include "item_style_select_dialog.h"
  23. #include "econ_item_system.h"
  24. #include "econ_item_tools.h"
  25. #include "econ_ui.h"
  26. #include "gc_clientsystem.h"
  27. #include "econ_store.h"
  28. #include "rtime.h"
  29. #include "econ_item_description.h"
  30. #include "dynamic_recipe_subpanel.h"
  31. #include "item_slot_panel.h"
  32. #include "crate_detail_panels.h"
  33. #include "tf_warinfopanel.h"
  34. #include "character_info_panel.h"
  35. #include "trading_start_dialog.h"
  36. #include "vgui_controls/MenuItem.h"
  37. #include "tf_duckleaderboard.h"
  38. #include "tf_item_inventory.h"
  39. #include "store/store_panel.h"
  40. #include "strange_count_transfer_panel.h"
  41. #include "collection_crafting_panel.h"
  42. #include "halloween_offering_panel.h"
  43. #include "store/v2/tf_store_preview_item2.h"
  44. #include "item_ad_panel.h"
  45. #include "client_community_market.h"
  46. // memdbgon must be the last include file in a .cpp file!!!
  47. #include <tier0/memdbgon.h>
  48. #ifdef STAGING_ONLY
  49. extern ConVar tf_use_card_tooltips;
  50. extern ConVar tf_weapon_force_allow_inspect;
  51. #endif // STAGING_ONLY
  52. ConVar tf_trade_up_use_count( "tf_trade_up_use_count", "3", FCVAR_ARCHIVE | FCVAR_HIDDEN );
  53. void UseConsumableItem( CEconItemView *pItem, vgui::Panel* pParent );
  54. const ItemSortTypeData_t g_BackpackSortTypes[] =
  55. {
  56. { "#Backpack_SortBy_Header", kGCItemSort_NoSort },
  57. { "#Backpack_SortBy_Rarity", kGCItemSort_SortByRarity },
  58. { "#Backpack_SortBy_Type", kGCItemSort_SortByType },
  59. { "#Backpack_SortBy_Class", kTFGCItemSort_SortByClass },
  60. { "#Backpack_SortBy_Slot", kTFGCItemSort_SortBySlot },
  61. { "#Backpack_SortBy_Date", kGCItemSort_SortByDate },
  62. };
  63. // Array of borders for rarities. Three borders for each rarity: Base, Mouseover, and Selected
  64. const char *g_szItemBorders[][5] =
  65. {
  66. { "BackpackItemBorder", "BackpackItemMouseOverBorder", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder", "BackpackItemGreyedOutSelectedBorder" }, // AE_NORMAL = 0
  67. { "BackpackItemBorder_1", "BackpackItemMouseOverBorder_1", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_1", "BackpackItemGreyedOutSelectedBorder_1" }, // AE_RARITY1 = 1
  68. { "BackpackItemBorder_2", "BackpackItemMouseOverBorder_2", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_2", "BackpackItemGreyedOutSelectedBorder_2" }, // AE_RARITY2 = 2
  69. { "BackpackItemBorder_Vintage", "BackpackItemMouseOverBorder_Vintage", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_Vintage", "BackpackItemGreyedOutSelectedBorder_Vintage" }, // AE_VINTAGE = 3
  70. { "BackpackItemBorder_3", "BackpackItemMouseOverBorder_3", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_3", "BackpackItemGreyedOutSelectedBorder_3" }, // AE_RARITY3
  71. { "BackpackItemBorder_4", "BackpackItemMouseOverBorder_4", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_4", "BackpackItemGreyedOutSelectedBorder_4" }, // AE_RARITY4
  72. { "BackpackItemBorder_Unique", "BackpackItemMouseOverBorder_Unique", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_Unique", "BackpackItemGreyedOutSelectedBorder_Unique" }, // AE_UNIQUE
  73. { "BackpackItemBorder_Community", "BackpackItemMouseOverBorder_Community", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_Community", "BackpackItemGreyedOutSelectedBorder_Community" }, // AE_COMMUNITY
  74. { "BackpackItemBorder_Developer", "BackpackItemMouseOverBorder_Developer", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_Developer", "BackpackItemGreyedOutSelectedBorder_Developer" }, // AE_DEVELOPER
  75. { "BackpackItemBorder_SelfMade", "BackpackItemMouseOverBorder_SelfMade", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_SelfMade", "BackpackItemGreyedOutSelectedBorder_SelfMade" }, // AE_SELFMADE
  76. { "BackpackItemBorder_Customized", "BackpackItemMouseOverBorder_Customized", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_Customized", "BackpackItemGreyedOutSelectedBorder_Customized" }, // AE_CUSTOMIZED
  77. { "BackpackItemBorder_Strange", "BackpackItemMouseOverBorder_Strange", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_Strange", "BackpackItemGreyedOutSelectedBorder_Strange" }, // AE_STRANGE
  78. { "BackpackItemBorder_Completed", "BackpackItemMouseOverBorder_Completed", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_Completed", "BackpackItemGreyedOutSelectedBorder_Completed" }, // AE_COMPLETED
  79. { "BackpackItemBorder_Haunted", "BackpackItemMouseOverBorder_Haunted", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_Haunted", "BackpackItemGreyedOutSelectedBorder_Haunted" }, // AE_HAUNTED
  80. { "BackpackItemBorder_Collectors", "BackpackItemMouseOverBorder_Collectors", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_Collectors", "BackpackItemGreyedOutSelectedBorder_Collectors" }, // AE_COLLECTORS
  81. { "BackpackItemBorder_PaintkitWeapon", "BackpackItemMouseOverBorder_PaintkitWeapon", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_PaintkitWeapon", "BackpackItemGreyedOutSelectedBorder_PaintkitWeapon" }, // AE_Paintkit
  82. { "BackpackItemBorder_RarityDefault", "BackpackItemMouseOverBorder_RarityDefault", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_RarityDefault", "BackpackItemGreyedOutSelectedBorder_RarityDefault" }, // AE_RARITY_DEFAULT,
  83. { "BackpackItemBorder_RarityCommon", "BackpackItemMouseOverBorder_RarityCommon", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_RarityCommon", "BackpackItemGreyedOutSelectedBorder_RarityCommon" }, // AE_RARITY_COMMON,
  84. { "BackpackItemBorder_RarityUncommon", "BackpackItemMouseOverBorder_RarityUncommon", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_RarityUncommon", "BackpackItemGreyedOutSelectedBorder_RarityUncommon" }, // AE_RARITY_UNCOMMON,
  85. { "BackpackItemBorder_RarityRare", "BackpackItemMouseOverBorder_RarityRare", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_RarityRare", "BackpackItemGreyedOutSelectedBorder_RarityRare" }, // AE_RARITY_RARE,
  86. { "BackpackItemBorder_RarityMythical", "BackpackItemMouseOverBorder_RarityMythical", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_RarityMythical", "BackpackItemGreyedOutSelectedBorder_RarityMythical" }, // AE_RARITY_MYTHICAL,
  87. { "BackpackItemBorder_RarityLegendary", "BackpackItemMouseOverBorder_RarityLegendary", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_RarityLegendary", "BackpackItemGreyedOutSelectedBorder_RarityLegendary" }, // AE_RARITY_LEGENDARY,
  88. { "BackpackItemBorder_RarityAncient", "BackpackItemMouseOverBorder_RarityAncient", "BackpackItemSelectedBorder", "BackpackItemGreyedOutBorder_RarityAncient", "BackpackItemGreyedOutSelectedBorder_RarityAncient" }, // AE_RARITY_ANCIENT,
  89. };
  90. COMPILE_TIME_ASSERT( ARRAYSIZE(g_szItemBorders) == AE_MAX_TYPES );
  91. enum { kNoUserData = -1 };
  92. static bool HasPaint ( const CEconItemView *pEconItemView, const char *, int )
  93. {
  94. static CSchemaAttributeDefHandle pAttrDef_PaintRGB( "set item tint RGB" );
  95. static CSchemaAttributeDefHandle pAttrDef_PaintRGB2( "set item tint RGB 2" );
  96. return pEconItemView->FindAttribute( pAttrDef_PaintRGB )
  97. || pEconItemView->FindAttribute( pAttrDef_PaintRGB2 );
  98. }
  99. static bool HasCustomAttribute ( const CEconItemView *pEconItemView, const char *szAttrName, int )
  100. {
  101. const CEconItemAttributeDefinition *pAttrDef = GetItemSchema()->GetAttributeDefinitionByName( szAttrName );
  102. return pAttrDef
  103. ? pEconItemView->FindAttribute( pAttrDef )
  104. : NULL;
  105. }
  106. static bool HasCustomUserAttribute ( const CEconItemView *pEconItemView, const char *, int iUserData )
  107. {
  108. Assert( iUserData != kNoUserData );
  109. CCountUserGeneratedAttributeIterator countIterator;
  110. pEconItemView->IterateAttributes( &countIterator );
  111. return countIterator.GetCount() > iUserData;
  112. }
  113. static bool HasRemovableCustomName ( const CEconItemView *pEconItemView, const char *, int )
  114. {
  115. if ( !pEconItemView->GetItemDefinition() )
  116. return false;
  117. if ( pEconItemView->GetQuality() == AE_UNIQUE && pEconItemView->GetItemDefinition()->GetArmoryDescString() && !V_stricmp( pEconItemView->GetItemDefinition()->GetArmoryDescString(), "stockitem" ) )
  118. return false;
  119. return pEconItemView->GetSOCData() && pEconItemView->GetSOCData()->GetCustomName();
  120. }
  121. static bool HasRemovableCustomDesc ( const CEconItemView *pEconItemView, const char *, int )
  122. {
  123. if ( !pEconItemView->GetItemDefinition() )
  124. return false;
  125. if ( pEconItemView->GetQuality() == AE_UNIQUE && pEconItemView->GetItemDefinition()->GetArmoryDescString() && !V_stricmp( pEconItemView->GetItemDefinition()->GetArmoryDescString(), "stockitem" ) )
  126. return false;
  127. return pEconItemView->GetSOCData() && pEconItemView->GetSOCData()->GetCustomDesc();
  128. }
  129. enum EItemCustomizationRemoveType
  130. {
  131. kCustomizationRemove_Paint,
  132. kCustomizationRemove_Name,
  133. kCustomizationRemove_Desc,
  134. kCustomizationRemove_CustomTexture,
  135. kCustomizationRemove_MakersMark,
  136. kCustomizationRemove_UniqueCraftIndex,
  137. kCustomizationRemove_StrangePart,
  138. kCustomizationRemove_StrangeScores,
  139. kCustomizationRemove_UpgradeCard,
  140. kCustomizationRemove_KillStreak,
  141. kCustomizationRemove_GiftedBy,
  142. kCustomizationRemove_Festivizer,
  143. };
  144. typedef bool (* HasRefurbishablePropertyFunc_t)( const CEconItemView *pEconItemView, const char *pArg, int iUserData );
  145. void GetCustomDialogToken_PaintName( const CEconItemView *pEconItemView, int iUserData, CUtlConstWideString& out_String )
  146. {
  147. extern const CEconItemDefinition *GetPaintItemDefinitionForPaintedItem( const IEconItemInterface *pEconItem );
  148. Assert( iUserData == kNoUserData );
  149. const CEconItemDefinition *pPaintItemDef = GetPaintItemDefinitionForPaintedItem( pEconItemView );
  150. if ( !pPaintItemDef )
  151. {
  152. out_String = L"";
  153. return;
  154. }
  155. out_String = GLocalizationProvider()->Find( pPaintItemDef->GetItemBaseName() );
  156. }
  157. void GetCustomDialogToken_StrangePartName( const CEconItemView *pEconItemView, int iUserData, CUtlConstWideString& out_String )
  158. {
  159. extern uint32 GetScoreTypeForKillEaterAttr( const IEconItemInterface *pEconItem, const CEconItemAttributeDefinition *pAttribDef );
  160. extern const wchar_t *GetLocalizedStringForKillEaterTypeAttr( const CLocalizationProvider *pLocalizationProvider, uint32 unKillEaterEventType ); // return type changed from locchar_t * because the backpack panel only exists on the client
  161. uint32 unKillEaterBaseType = GetScoreTypeForKillEaterAttr( pEconItemView, GetKillEaterAttr_Type( iUserData ) );
  162. out_String = GetLocalizedStringForKillEaterTypeAttr( GLocalizationProvider(), unKillEaterBaseType );
  163. }
  164. void GetCustomDialogToken_UserAttributeName( const CEconItemView *pEconItemView, int iUserData, CUtlConstWideString& out_String )
  165. {
  166. Assert( pEconItemView );
  167. const CEconItemAttributeDefinition *pAttrDef = GetCardUpgradeForIndex( pEconItemView, iUserData );
  168. if ( !pAttrDef )
  169. {
  170. out_String = L"unknown";
  171. return;
  172. }
  173. attrib_value_t attrVal;
  174. Verify( pEconItemView->FindAttribute( pAttrDef, &attrVal ) );
  175. CEconAttributeDescription attrDesc( GLocalizationProvider(), pAttrDef, attrVal );
  176. out_String = attrDesc.GetShortDescription();
  177. }
  178. typedef void (* GetCustomDialogLocalizationTokenFunc_t)( const CEconItemView *pEconItemView, int iUserData, CUtlConstWideString& out_String );
  179. struct RefurbishableProperty
  180. {
  181. HasRefurbishablePropertyFunc_t m_pFunc;
  182. GetCustomDialogLocalizationTokenFunc_t m_pGetCustomDialogLocalizationTokenFunc;
  183. const char *m_szArg;
  184. const char *m_pszSelectionUILocalizationToken;
  185. const char *m_szDialogTitle;
  186. const char *m_szDialogDesc;
  187. EItemCustomizationRemoveType m_eRemovalType;
  188. int m_iUserData;
  189. };
  190. // TODO: Add Gifted by Tag here
  191. static RefurbishableProperty g_RemoveableAttributes[] =
  192. {
  193. { &HasRemovableCustomName, NULL, NULL, "#RefurbishItem_RemoveNameCombo", "#RefurbishItem_RemoveNameTitle", "#RefurbishItem_RemoveName", kCustomizationRemove_Name, kNoUserData }, // does this item have a custom name?
  194. { &HasRemovableCustomDesc, NULL, NULL, "#RefurbishItem_RemoveDescCombo", "#RefurbishItem_RemoveDescTitle", "#RefurbishItem_RemoveDesc", kCustomizationRemove_Desc, kNoUserData }, // does this item have a custom description?
  195. { &HasPaint, &GetCustomDialogToken_PaintName, "set item tint rgb", "#RefurbishItem_RemovePaintCombo", "#RefurbishItem_RemovePaintTitle", "#RefurbishItem_RemovePaint", kCustomizationRemove_Paint, kNoUserData }, // is this item painted?
  196. { &HasCustomAttribute, NULL, "custom texture hi", "#RefurbishItem_RemoveCustomTextureCombo", "#RefurbishItem_RemoveCustomTextureTitle", "#RefurbishItem_RemoveCustomTexture", kCustomizationRemove_CustomTexture, kNoUserData }, // does this have a custom texture applied?
  197. { &HasCustomAttribute, NULL, "makers mark id", "#RefurbishItem_RemoveMakersMarkCombo", "#RefurbishItem_RemoveMakersMarkTitle", "#RefurbishItem_RemoveMakersMark", kCustomizationRemove_MakersMark, kNoUserData }, // was this item crafted by a specific dude?
  198. { &HasCustomAttribute, NULL, "killstreak tier", "#RefurbishItem_RemoveKillStreakCombo", "#RefurbishItem_RemoveKillStreakTitle", "#RefurbishItem_RemoveKillStreak", kCustomizationRemove_KillStreak, kNoUserData }, // Killstreak Effect
  199. { &HasCustomAttribute, NULL, "gifter account id", "#RefurbishItem_RemoveGifterCombo", "#RefurbishItem_RemoveGifterTitle", "#RefurbishItem_RemoveGifter", kCustomizationRemove_GiftedBy, kNoUserData }, // Gifted by
  200. { &HasCustomAttribute, NULL, "is_festivized", "#RefurbishItem_RemoveFestivizerCombo", "#RefurbishItem_RemoveFestivizerTitle", "#RefurbishItem_RemoveFestivizer", kCustomizationRemove_Festivizer, kNoUserData }, // Festivizer
  201. //"gifter account id", // who gifted us this item? (will also remove "event date")
  202. };
  203. //-----------------------------------------------------------------------------
  204. // Purpose: Look over this weapon to see if it has any strange stat counters to reset optionally.
  205. //-----------------------------------------------------------------------------
  206. static bool HasResettableScoreAttributes ( const CEconItemView *pEconItemView, const char *, int )
  207. {
  208. if ( !pEconItemView )
  209. return false;
  210. for ( int i = 0; i < GetKillEaterAttrCount(); i++ )
  211. {
  212. uint32 unScore;
  213. if ( pEconItemView->FindAttribute( GetKillEaterAttr_Score( i ), &unScore ) && unScore > 0 )
  214. return true;
  215. }
  216. return false;
  217. }
  218. //-----------------------------------------------------------------------------
  219. // Purpose:
  220. //-----------------------------------------------------------------------------
  221. int GetRemovableAttributesCount()
  222. {
  223. return ARRAYSIZE( g_RemoveableAttributes )
  224. + GetKillEaterAttrCount()
  225. + GetMaxCardUpgradesPerItem() // remove card upgrades
  226. + 1; // strange quality item score reset
  227. }
  228. RefurbishableProperty RemovableAttributes_GetAttributeDetails( int i )
  229. {
  230. Assert( i >= 0 );
  231. Assert( i < GetRemovableAttributesCount() );
  232. if ( i < ARRAYSIZE( g_RemoveableAttributes ) )
  233. return g_RemoveableAttributes[i];
  234. // Which attribute in particular are we looking for?
  235. int iStrangePartIndex = i - ARRAYSIZE( g_RemoveableAttributes );
  236. if ( iStrangePartIndex < GetKillEaterAttrCount() )
  237. {
  238. int iKillEaterAttrIndex = (GetKillEaterAttrCount() - GetKillEaterAttrCount()) + iStrangePartIndex;
  239. // if we're looking at strange attributes...
  240. if ( GetKillEaterAttr_IsUserCustomizable( iKillEaterAttrIndex ) )
  241. {
  242. // Common properties for all strange part attributes.
  243. static RefurbishableProperty sStrangePartProperty = { &HasCustomAttribute, &GetCustomDialogToken_StrangePartName, NULL, "#RefurbishItem_RemoveStrangePartCombo", "#RefurbishItem_RemoveStrangePartTitle", "#RefurbishItem_RemoveStrangePart", kCustomizationRemove_StrangePart, kNoUserData };
  244. RefurbishableProperty partReturnProp = sStrangePartProperty;
  245. partReturnProp.m_szArg = GetKillEaterAttr_Score( iKillEaterAttrIndex )->GetDefinitionName(); // ...then we check for the presence of a score attribute if this slot is a strange part...
  246. partReturnProp.m_iUserData = iKillEaterAttrIndex;
  247. return partReturnProp;
  248. }
  249. // ...or the presence of a restriction attribute if this slot is a base slot that might have a filter
  250. static RefurbishableProperty sStrangeFilterProperty = { &HasCustomAttribute, &GetCustomDialogToken_StrangePartName, NULL, "#RefurbishItem_RemoveStrangeFilterCombo", "#RefurbishItem_RemoveStrangeFilterTitle", "#RefurbishItem_RemoveStrangeFilter", kCustomizationRemove_StrangePart, kNoUserData };
  251. RefurbishableProperty filterReturnProp = sStrangeFilterProperty;
  252. filterReturnProp.m_szArg = GetKillEaterAttr_Restriction( iKillEaterAttrIndex )->GetDefinitionName();
  253. filterReturnProp.m_iUserData = iKillEaterAttrIndex;
  254. return filterReturnProp;
  255. }
  256. // Look for any properties that were user-assigned. We allow users to remove them.
  257. int iCardUpgradeIndex = iStrangePartIndex - GetKillEaterAttrCount();
  258. if ( iCardUpgradeIndex < GetMaxCardUpgradesPerItem() )
  259. {
  260. // Common properties for all card upgrade attributes.
  261. static RefurbishableProperty sCardUpgradeProperty = { &HasCustomUserAttribute, &GetCustomDialogToken_UserAttributeName, NULL, "#RefurbishItem_RemoveSpellCombo", "#RefurbishItem_RemoveSpellTitle", "#RefurbishItem_RemoveSpellUpgrade", kCustomizationRemove_UpgradeCard, kNoUserData };
  262. RefurbishableProperty returnProp = sCardUpgradeProperty;
  263. // FIX THIS FOR CARDS / SPELLS?
  264. // returnProp.m_szArg = GetCustomDialogToken_UserAttributeName ?
  265. returnProp.m_iUserData = iCardUpgradeIndex;
  266. return returnProp;
  267. }
  268. // We might also be trying to reset the strange score counters.
  269. Assert( iStrangePartIndex == GetKillEaterAttrCount() + GetMaxCardUpgradesPerItem() );
  270. Assert( i == GetRemovableAttributesCount() - 1 );
  271. static RefurbishableProperty sStrangeScoreReset = { &HasResettableScoreAttributes, NULL, NULL, "#RefurbishItem_RemoveStrangeScoresCombo", "#RefurbishItem_RemoveStrangeScoresTitle", "#RefurbishItem_RemoveStrangeScores", kCustomizationRemove_StrangeScores, kNoUserData };
  272. return sStrangeScoreReset;
  273. }
  274. bool RemovableAttributes_DoesAttributeApply( int i, const CEconItemView *pEconItemView )
  275. {
  276. static CSchemaAttributeDefHandle pAttr_CannotRestore( "cannot restore" );
  277. if ( pEconItemView->FindAttribute( pAttr_CannotRestore ) )
  278. return false;
  279. RefurbishableProperty attr = RemovableAttributes_GetAttributeDetails( i );
  280. return attr.m_pFunc( pEconItemView, attr.m_szArg, attr.m_iUserData );
  281. }
  282. bool RemovableAttributes_DoAnyAttributesApply( const CEconItemView *pEconItemView )
  283. {
  284. static CSchemaAttributeDefHandle pAttr_CannotRestore( "cannot restore" );
  285. if ( pEconItemView->FindAttribute( pAttr_CannotRestore ) )
  286. return false;
  287. for ( int i = 0; i < GetRemovableAttributesCount(); i++ )
  288. {
  289. if ( RemovableAttributes_DoesAttributeApply( i, pEconItemView ) )
  290. return true;
  291. }
  292. return false;
  293. }
  294. //-----------------------------------------------------------------------------
  295. // Purpose:
  296. //-----------------------------------------------------------------------------
  297. ConVar cl_showbackpackrarities( "cl_showbackpackrarities", "0", FCVAR_ARCHIVE, "0 = Show no backpack icon border colors. 1 = Show item rarities within the backpack. 2 = Show item rarities only for Market-listable items." );
  298. ConVar cl_show_market_data_on_items( "cl_show_market_data_on_items", "1", FCVAR_ARCHIVE, "0 = Never. 1 = Only when showing borders for Market-listable items. 2 = Always." );
  299. ConVar tf_explanations_backpackpanel( "tf_explanations_backpackpanel", "0", FCVAR_ARCHIVE, "Whether the user has seen explanations for this panel." );
  300. ConVar tf_backpack_page_button_delay( "tf_backpack_page_button_delay", "0.5", FCVAR_ARCHIVE, "Amount of time the mouse cursor needs to hover over the page button to select the page." );
  301. //-----------------------------------------------------------------------------
  302. // Purpose:
  303. //-----------------------------------------------------------------------------
  304. CBackpackPanel::CBackpackPanel( vgui::Panel *parent, const char *panelName ) : CBaseLoadoutPanel( parent, panelName )
  305. {
  306. m_nQuickOpenTxn = 0;
  307. m_pContextMenu = NULL;
  308. m_pPageButtonKVs = NULL;
  309. m_mapSeenItems.SetLessFunc( DefLessFunc( itemid_t ) );
  310. m_bInitializedSeenItems = false;
  311. m_pNameFilterTextEntry = NULL;
  312. m_flFilterItemTime = 0.f;
  313. m_mapFilteringItems.SetLessFunc( DefLessFunc(int) );
  314. m_pNextPageButton = NULL;
  315. m_pPrevPageButton = NULL;
  316. m_pShowExplanationsButton = NULL;
  317. m_pCurPageLabel = NULL;
  318. m_pSortByComboBox = NULL;
  319. m_pShowRarityComboBox = NULL;
  320. m_pShowBaseItemsCheckbox = NULL;
  321. m_pDragToNextPageButton = NULL;
  322. m_pDragToPrevPageButton = NULL;
  323. m_flPreventDragPageSwitchUntil = 0;
  324. m_flStartExplanationsAt = 0;
  325. m_flMouseDownTime = 0;
  326. m_pItemDraggedFromPanel = NULL;
  327. m_iDraggedFromPage = 0;
  328. m_bMouseDownOnItemPanel = false;
  329. m_bDragging = false;
  330. m_iMouseDownX = m_iMouseDownY = 0;
  331. m_pMouseDragItemPanel = vgui::SETUP_PANEL( new CItemModelPanel( this, "mousedragitempanel" ) );
  332. m_pCancelToolButton = NULL;
  333. m_pCraftButton = NULL;
  334. m_bShowBaseItems = false;
  335. m_pConfirmDeleteDialog = NULL;
  336. m_pToolIcon = NULL;
  337. m_eSelectionMode = StandardSelection;
  338. m_nLastToolPage = 0;
  339. m_pDynamicRecipePanel = NULL;
  340. m_pItemSlotPanel = NULL;
  341. m_pStrangeToolPanel = NULL;
  342. m_nNumActivePages = 0;
  343. m_pInspectPanel = new CTFItemInspectionPanel( this, "InspectionPanel" );
  344. m_pInspectCosmeticPanel = new CTFStorePreviewItemPanel2( this, "Resource/UI/econ/InspectionPanel_Cosmetic.res", "storepreviewitem", NULL );
  345. m_pCollectionCraftPanel = NULL;
  346. m_pHalloweenOfferingPanel = NULL;
  347. m_pMannCoTradePanel = NULL;
  348. CancelToolSelection();
  349. ListenForGameEvent( "gc_connected" );
  350. }
  351. CBackpackPanel::~CBackpackPanel()
  352. {
  353. if ( m_pPageButtonKVs )
  354. {
  355. m_pPageButtonKVs->deleteThis();
  356. m_pPageButtonKVs = NULL;
  357. }
  358. }
  359. //-----------------------------------------------------------------------------
  360. // Purpose:
  361. //-----------------------------------------------------------------------------
  362. void CBackpackPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  363. {
  364. if ( !m_pSortByComboBox && UsesRarityControls() )
  365. {
  366. m_pSortByComboBox = new vgui::ComboBox( this, "SortByComboBox", 5, false );
  367. m_pSortByComboBox->AddActionSignalTarget( this );
  368. }
  369. LoadControlSettings( GetResFile() );
  370. BaseClass::ApplySchemeSettings( pScheme );
  371. m_pNameFilterTextEntry = FindControl<vgui::TextEntry>( "NameFilterTextEntry" );
  372. if ( m_pNameFilterTextEntry )
  373. {
  374. m_pNameFilterTextEntry->AddActionSignalTarget( this );
  375. }
  376. m_pCancelToolButton = dynamic_cast<CExButton*>( FindChildByName("CancelApplyToolButton") );
  377. m_pCraftButton = dynamic_cast<CExButton*>( FindChildByName("CraftButton") );
  378. m_pToolIcon = dynamic_cast<vgui::ScalableImagePanel*>( FindChildByName("tool_icon") );
  379. m_pNextPageButton = dynamic_cast<CExButton*>( FindChildByName("NextPageButton") );
  380. m_pPrevPageButton = dynamic_cast<CExButton*>( FindChildByName("PrevPageButton") );
  381. m_pShowExplanationsButton = dynamic_cast<CExButton*>( FindChildByName("ShowExplanationsButton") );
  382. m_pDragToNextPageButton = dynamic_cast<CExButton*>( FindChildByName("DragToNextPageButton") );
  383. m_pDragToPrevPageButton = dynamic_cast<CExButton*>( FindChildByName("DragToPrevPageButton") );
  384. m_pCurPageLabel = dynamic_cast<vgui::Label*>( FindChildByName("CurPageLabel") );
  385. m_pShowRarityComboBox = dynamic_cast<vgui::ComboBox*>( FindChildByName( "ShowRarityComboBox" ) );
  386. if ( m_pShowRarityComboBox )
  387. {
  388. m_pShowRarityComboBox->AddActionSignalTarget( this );
  389. m_pShowRarityComboBox->AddItem( "#TF_Backpack_ShowNoBorders", NULL );
  390. m_pShowRarityComboBox->AddItem( "#TF_Backpack_ShowQualityBorders", NULL );
  391. m_pShowRarityComboBox->AddItem( "#TF_Backpack_ShowMarketableBorders", NULL );
  392. m_pShowRarityComboBox->ActivateItemByRow( cl_showbackpackrarities.GetInt() );
  393. }
  394. m_pShowBaseItemsCheckbox = dynamic_cast<vgui::CheckButton*>( FindChildByName( "ShowBaseItemsCheckbox" ) );
  395. if ( m_pShowBaseItemsCheckbox )
  396. {
  397. m_pShowBaseItemsCheckbox->AddActionSignalTarget( this );
  398. m_pShowBaseItemsCheckbox->SetSelected( m_bShowBaseItems );
  399. }
  400. m_pMouseDragItemPanel->SetBorder( pScheme->GetBorder("BackpackItemMouseOverBorder") );
  401. // Setup our combo box
  402. if ( m_pSortByComboBox )
  403. {
  404. m_pSortByComboBox->RemoveAll();
  405. vgui::HFont hFont = pScheme->GetFont( "HudFontSmallestBold", true );
  406. m_pSortByComboBox->SetFont( hFont );
  407. KeyValues *pKeyValues = new KeyValues( "data" );
  408. for ( int i = 0; i < ARRAYSIZE(g_BackpackSortTypes); i++ )
  409. {
  410. pKeyValues->SetInt( "sortby", i );
  411. m_pSortByComboBox->AddItem( g_BackpackSortTypes[i].szSortDesc, pKeyValues );
  412. }
  413. pKeyValues->deleteThis();
  414. m_pSortByComboBox->ActivateItemByRow( 0 );
  415. m_pSortByComboBox->GetMenu()->SetNumberOfVisibleItems( ARRAYSIZE(g_BackpackSortTypes) );
  416. }
  417. // Create page buttons
  418. const int nNumMaxPages = GetNumMaxPages();
  419. for ( int i=m_Pages.Count(); i<nNumMaxPages; ++i )
  420. {
  421. EditablePanel *pPage = vgui::SETUP_PANEL( new EditablePanel( this, CFmtStr( "page_%d", i ) ) );
  422. m_Pages.AddToTail( pPage );
  423. }
  424. if ( m_pInspectCosmeticPanel )
  425. {
  426. // Force it to load it's scheme now, because it needs to be done before we set it's visibility below
  427. m_pInspectCosmeticPanel->InvalidateLayout( false, true );
  428. m_pInspectCosmeticPanel->SetVisible( false );
  429. }
  430. }
  431. void CBackpackPanel::ApplySettings( KeyValues *inResourceData )
  432. {
  433. BaseClass::ApplySettings( inResourceData );
  434. KeyValues *pItemKV = inResourceData->FindKey( "pagebuttons_kv" );
  435. if ( pItemKV )
  436. {
  437. if ( m_pPageButtonKVs )
  438. {
  439. m_pPageButtonKVs->deleteThis();
  440. }
  441. m_pPageButtonKVs = new KeyValues("pagebuttons_kv");
  442. pItemKV->CopySubkeys( m_pPageButtonKVs );
  443. }
  444. }
  445. //-----------------------------------------------------------------------------
  446. // Purpose:
  447. //-----------------------------------------------------------------------------
  448. void CBackpackPanel::AddNewItemPanel( int iPanelIndex )
  449. {
  450. BaseClass::AddNewItemPanel( iPanelIndex );
  451. // Store a position for our new panel
  452. m_ItemModelPanelPos.AddToTail();
  453. m_ItemModelPanelPos[iPanelIndex].x = m_ItemModelPanelPos[iPanelIndex].y = 0;
  454. }
  455. //-----------------------------------------------------------------------------
  456. // Purpose:
  457. //-----------------------------------------------------------------------------
  458. CItemModelPanel *CBackpackPanel::GetItemPanelAtPos( int x, int y )
  459. {
  460. if ( !m_pItemModelPanels.Count() )
  461. return NULL;
  462. int iW = m_pItemModelPanels[0]->GetWide();
  463. int iH = m_pItemModelPanels[0]->GetTall();
  464. for ( int i = 0; i < m_ItemModelPanelPos.Count(); i++ )
  465. {
  466. if ( (x < m_ItemModelPanelPos[i].x) || (x > (m_ItemModelPanelPos[i].x + iW)) )
  467. continue;
  468. if ( (y < m_ItemModelPanelPos[i].y) || (y > (m_ItemModelPanelPos[i].y + iH)) )
  469. continue;
  470. return m_pItemModelPanels[i];
  471. }
  472. return NULL;
  473. }
  474. //-----------------------------------------------------------------------------
  475. // Purpose:
  476. //-----------------------------------------------------------------------------
  477. int CBackpackPanel::GetPageButtonIndexAtPos( int x, int y )
  478. {
  479. if ( !m_Pages.Count() )
  480. return -1;
  481. int iW = m_Pages[0]->GetWide();
  482. int iH = m_Pages[0]->GetTall();
  483. for ( int i = 0; i < m_PageButtonPos.Count(); i++ )
  484. {
  485. if ( (x < m_PageButtonPos[i].x) || (x > (m_PageButtonPos[i].x + iW)) )
  486. continue;
  487. if ( (y < m_PageButtonPos[i].y) || (y > (m_PageButtonPos[i].y + iH)) )
  488. continue;
  489. return m_Pages[i]->IsVisible() ? i : -1;
  490. }
  491. return -1;
  492. }
  493. //-----------------------------------------------------------------------------
  494. // Purpose: Change the text color on the page buttons based on the context of the
  495. // page they represent.
  496. //-----------------------------------------------------------------------------
  497. void CBackpackPanel::SetPageButtonTextColorBasedOnContents()
  498. {
  499. vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( GetScheme() );
  500. if ( m_Pages.Count() == 0 )
  501. return;
  502. if ( !pScheme )
  503. return;
  504. const Color& colorEmpty = pScheme->GetColor( "TanDarker", Color( 235, 226, 202, 255 ) );
  505. const Color& colorPartial = Color( 170, 161, 137, 255 );
  506. const Color& colorFull = pScheme->GetColor( "TanLight", Color( 235, 226, 202, 255 ) );
  507. const Color& colorSelected = pScheme->GetColor( "TFOrange", Color( 145, 73, 59, 255 ) );
  508. CUtlVector<int> vecPageCount;
  509. CUtlVector<int> vecNewPageCount;
  510. vecPageCount.EnsureCount( m_Pages.Count() );
  511. vecNewPageCount.EnsureCount( m_Pages.Count() );
  512. // Initialize to 0
  513. FOR_EACH_VEC( vecPageCount, i )
  514. {
  515. vecPageCount[i] = 0;
  516. vecNewPageCount[i] = 0;
  517. }
  518. CPlayerInventory *pInv = InventoryManager()->GetLocalInventory();
  519. Assert( pInv );
  520. // Tally up how many items are on each page
  521. if ( pInv )
  522. {
  523. for ( int i = 0 ; i < pInv->GetItemCount() ; ++i )
  524. {
  525. CEconItemView *pItem = pInv->GetItem( i );
  526. const int nSlot = InventoryManager()->GetBackpackPositionFromBackend( pItem->GetInventoryPosition() ) - 1;
  527. const int nPage = nSlot / GetNumSlotsPerPage();
  528. if ( nPage >= 0 && nPage < m_Pages.Count() )
  529. {
  530. vecPageCount[ nPage ] = vecPageCount[ nPage ] + 1;
  531. // Unackknowledged items technically are on the 1st page, so dont count them
  532. if ( m_mapSeenItems.Find( pItem->GetItemID() ) == m_mapSeenItems.InvalidIndex()
  533. && IsUnacknowledged( pItem->GetInventoryPosition() ) == false && !m_bShowBaseItems && !HasNameFilter() )
  534. {
  535. vecNewPageCount[ nPage ] = vecNewPageCount[ nPage ] + 1;
  536. }
  537. }
  538. }
  539. }
  540. // Set the color for each page button
  541. FOR_EACH_VEC( m_Pages, i )
  542. {
  543. const int nNewCount = vecNewPageCount[i];
  544. const int nCount = vecPageCount[i];
  545. CExButton* pButton = dynamic_cast<CExButton*>( m_Pages[i]->FindChildByName( "Button" ) );
  546. if ( pButton )
  547. {
  548. Color setColor = colorEmpty;
  549. const Color& bgColor = GetCurrentPage() == i ? colorSelected : pButton->GetButtonDefaultBgColor();
  550. if ( nCount == GetNumSlotsPerPage() )
  551. setColor = colorFull;
  552. else if ( nCount > 0 )
  553. setColor = colorPartial;
  554. pButton->SetSelectedColor( setColor, pButton->GetButtonSelectedBgColor() );
  555. pButton->SetDefaultColor( setColor, bgColor );
  556. pButton->SetArmedColor( setColor, pButton->GetButtonArmedBgColor() );
  557. pButton->SetDepressedColor( setColor, pButton->GetButtonDepressedBgColor() );
  558. }
  559. // Show our "NEW!" label if there's any unseen items on that page
  560. CExLabel* pNew = dynamic_cast<CExLabel*>( m_Pages[i]->FindChildByName( "New" ) );
  561. if ( pNew )
  562. {
  563. pNew->SetVisible( nNewCount > 0 );
  564. }
  565. }
  566. }
  567. //-----------------------------------------------------------------------------
  568. // Purpose:
  569. //-----------------------------------------------------------------------------
  570. void CBackpackPanel::MarkItemIDDirty( itemid_t itemID )
  571. {
  572. if ( m_vecDirtyItems.Find( itemID ) == m_vecDirtyItems.InvalidIndex() )
  573. {
  574. m_vecDirtyItems.AddToTail( itemID );
  575. }
  576. }
  577. //-----------------------------------------------------------------------------
  578. // Purpose:
  579. //-----------------------------------------------------------------------------
  580. void CBackpackPanel::PositionItemPanel( CItemModelPanel *pPanel, int iIndex )
  581. {
  582. int iCenter = GetWide() * 0.5;
  583. int iButtonX = (iIndex % GetNumColumns());
  584. int iButtonY = (iIndex / GetNumColumns());
  585. int iXPos = (iCenter + m_iItemBackpackOffcenterX) + (iButtonX * m_pItemModelPanels[iIndex]->GetWide()) + (m_iItemBackpackXDelta * iButtonX);
  586. int iYPos = m_iItemYPos + (iButtonY * m_pItemModelPanels[iIndex]->GetTall() ) + (m_iItemBackpackYDelta * iButtonY);
  587. m_pItemModelPanels[iIndex]->SetPos( iXPos, iYPos );
  588. }
  589. //-----------------------------------------------------------------------------
  590. // Purpose:
  591. //-----------------------------------------------------------------------------
  592. void CBackpackPanel::PerformLayout( void )
  593. {
  594. BaseClass::PerformLayout();
  595. for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
  596. {
  597. // Viewing the backpack. Layout all the buttons and hide the class image.
  598. m_pItemModelPanels[i]->SetVisible( true );
  599. m_pItemModelPanels[i]->SetNoItemText( "#SelectNoItemSlot" );
  600. PositionItemPanel( m_pItemModelPanels[i], i );
  601. // Cache off where we put the panel
  602. m_pItemModelPanels[i]->GetPos( m_ItemModelPanelPos[i].x, m_ItemModelPanelPos[i].y );
  603. // Take into account parent's position
  604. Panel* pParent = m_pItemModelPanels[i]->GetParent();
  605. if( pParent )
  606. {
  607. int x = 0,y = 0;
  608. pParent->GetPos( x, y );
  609. m_ItemModelPanelPos[i].x += x;
  610. m_ItemModelPanelPos[i].y += y;
  611. }
  612. }
  613. // adjust page buttons
  614. {
  615. m_nNumActivePages = GetNumPages();
  616. int iCenter = GetWide() * 0.5;
  617. int iPageBarWidth = 2 * abs( m_iItemBackpackOffcenterX );
  618. int iPageButtonWidth = ( iPageBarWidth - ( m_iPageButtonPerRow - 1 ) * m_iPageButtonXDelta ) / m_iPageButtonPerRow;
  619. int iPageButtonWidthPlusDelta = iPageButtonWidth + m_iPageButtonXDelta;
  620. int iPageButtonHeightPlusDelta = m_iPageButtonHeight + m_iPageButtonYDelta;
  621. int iStart = iCenter + m_iItemBackpackOffcenterX;
  622. m_PageButtonPos.EnsureCount( m_Pages.Count() );
  623. for ( int i=0; i<m_Pages.Count(); ++i )
  624. {
  625. EditablePanel *pPage = m_Pages[i];
  626. if ( pPage )
  627. {
  628. // Apply control settings here
  629. if ( m_pPageButtonKVs )
  630. pPage->ApplySettings( m_pPageButtonKVs );
  631. CExButton* pButton = dynamic_cast<CExButton*>( pPage->FindChildByName( "Button" ) );
  632. pPage->InvalidateLayout( true, true );
  633. // Make the button have the right command and send it's signals to us
  634. if ( pButton )
  635. {
  636. pButton->SetSelected( false );
  637. pButton->SetCommand( CFmtStr( "goto_page_%d", i ) );
  638. pButton->AddActionSignalTarget( this );
  639. }
  640. pPage->SetDialogVariable( "page", i+1 );
  641. bool bVisible = i < m_nNumActivePages;
  642. if ( bVisible )
  643. {
  644. int iRow = i /m_iPageButtonPerRow;
  645. int iColumn = i % m_iPageButtonPerRow;
  646. pPage->SetBounds( iStart + iColumn * iPageButtonWidthPlusDelta, m_iPageButtonYPos + iRow * iPageButtonHeightPlusDelta, iPageButtonWidth, m_iPageButtonHeight );
  647. pPage->GetPos( m_PageButtonPos[i].x , m_PageButtonPos[i].y );
  648. }
  649. pPage->SetVisible( bVisible );
  650. }
  651. }
  652. // Update colors and the "NEW!" labels
  653. SetPageButtonTextColorBasedOnContents();
  654. }
  655. if ( m_pNextPageButton )
  656. {
  657. m_pNextPageButton->SetVisible( true );
  658. }
  659. if ( m_pPrevPageButton )
  660. {
  661. m_pPrevPageButton->SetVisible( true );
  662. }
  663. if ( m_pCurPageLabel )
  664. {
  665. m_pCurPageLabel->SetVisible( true );
  666. }
  667. if ( m_pSortByComboBox )
  668. {
  669. m_pSortByComboBox->SetVisible( !InToolSelectionMode() );
  670. }
  671. if ( m_pShowRarityComboBox )
  672. {
  673. m_pShowRarityComboBox->SetVisible( true );
  674. }
  675. if ( m_pNextPageButton )
  676. {
  677. m_pNextPageButton->SetEnabled( GetNumPages() > 1 );
  678. }
  679. if ( m_pPrevPageButton )
  680. {
  681. m_pPrevPageButton->SetEnabled( GetNumPages() > 1 );
  682. }
  683. if ( !m_bDragging )
  684. {
  685. if ( m_pDragToNextPageButton && m_pDragToPrevPageButton )
  686. {
  687. m_pDragToNextPageButton->SetVisible( false );
  688. m_pDragToPrevPageButton->SetVisible( false );
  689. }
  690. }
  691. bool bShowActions = (!m_bItemsOnly && !InToolSelectionMode());
  692. if ( m_pCraftButton )
  693. {
  694. m_pCraftButton->SetVisible( bShowActions );
  695. }
  696. if ( m_pCancelToolButton )
  697. {
  698. m_pCancelToolButton->SetVisible( InToolSelectionMode() );
  699. }
  700. if ( m_pShowExplanationsButton )
  701. {
  702. m_pShowExplanationsButton->SetVisible( !m_bItemsOnly );
  703. }
  704. if ( m_pShowBaseItemsCheckbox )
  705. {
  706. m_pShowBaseItemsCheckbox->SetVisible( !m_bItemsOnly );
  707. }
  708. }
  709. //-----------------------------------------------------------------------------
  710. // Purpose:
  711. //-----------------------------------------------------------------------------
  712. void CBackpackPanel::FireGameEvent( IGameEvent *event )
  713. {
  714. static CSchemaItemDefHandle pItemDef_BasePaintCan( "Paint Can" );
  715. const char *type = event->GetName();
  716. if ( Q_strcmp( "gc_connected", type ) == 0 )
  717. {
  718. if ( !m_bInitializedSeenItems )
  719. {
  720. CPlayerInventory *pInventory = InventoryManager()->GetLocalInventory();
  721. if ( pInventory )
  722. {
  723. for ( int i = 0; i < pInventory->GetItemCount(); i++ )
  724. {
  725. CEconItemView *pItem = pInventory->GetItem(i);
  726. m_mapSeenItems.Insert( pItem->GetItemID() );
  727. }
  728. }
  729. m_bInitializedSeenItems = true;
  730. }
  731. m_vecPaintCans.Purge();
  732. m_vecStrangeParts.Purge();
  733. const CEconItemSchema::ToolsItemDefinitionMap_t &toolDefs = GetItemSchema()->GetToolsItemDefinitionMap();
  734. // Store all of the active paint can item defs
  735. FOR_EACH_MAP_FAST( toolDefs, i )
  736. {
  737. const CEconItemDefinition *pItemDef = toolDefs[i];
  738. const IEconTool *pEconTool = pItemDef->GetEconTool();
  739. if ( !pEconTool )
  740. continue;
  741. // Paint can list
  742. // Ignore the stock paintcan thats only for armory purposes
  743. if ( !V_strcmp( pEconTool->GetTypeName(), "paint_can" ) && pItemDef_BasePaintCan != pItemDef )
  744. {
  745. // Paint Can
  746. m_vecPaintCans.AddToTail( pItemDef->GetDefinitionIndex() );
  747. }
  748. // Strange Parts List
  749. else if ( !V_strcmp( pEconTool->GetTypeName(), "strange_part" ) )
  750. {
  751. m_vecStrangeParts.AddToTail( pItemDef->GetDefinitionIndex() );
  752. }
  753. }
  754. }
  755. BaseClass::FireGameEvent( event );
  756. }
  757. void CBackpackPanel::CheckForQuickOpenKey()
  758. {
  759. if ( !m_hQuickOpenCrate )
  760. return;
  761. // We only want to continue if it's the transaction we're listening for
  762. if ( EconUI()->GetStorePanel()->GetMostRecentSuccessfulTransactionID() != m_nQuickOpenTxn )
  763. {
  764. return;
  765. }
  766. CPlayerInventory *pInventory = InventoryManager()->GetLocalInventory();
  767. if ( pInventory )
  768. {
  769. for ( int i = 0; i < pInventory->GetItemCount(); i++ )
  770. {
  771. CEconItemView *pInvItem = pInventory->GetItem( i );
  772. uint32 iPosition = pInvItem->GetInventoryPosition();
  773. if ( IsUnacknowledged( iPosition ) == false )
  774. continue;
  775. if ( InventoryManager()->GetBackpackPositionFromBackend( iPosition ) != 0 )
  776. continue;
  777. // Now make sure we haven't got a clientside saved ack for this item.
  778. if ( InventoryManager()->HasBeenAckedByClient( pInvItem ) )
  779. continue;
  780. // If item is not a drop we want to show the notification otherwise they'll get the notification on death
  781. int iFoundMethod = GetUnacknowledgedReason( iPosition );
  782. if ( iFoundMethod != UNACK_ITEM_PURCHASED )
  783. continue;
  784. if ( !pInvItem->GetStaticData()->IsTool() )
  785. continue;
  786. if( !CEconSharedToolSupport::ToolCanApplyTo( pInvItem, m_hQuickOpenCrate ) )
  787. continue;
  788. if ( !pInvItem->GetStaticData()->GetEconTool() )
  789. continue;
  790. if ( !Q_strcmp( pInvItem->GetStaticData()->GetEconTool()->GetTypeName(), "decoder_ring" ) == 0 )
  791. continue;
  792. ApplyTool( this, pInvItem, m_hQuickOpenCrate );
  793. CloseStoreStatusDialog();
  794. m_hQuickOpenCrate = NULL;
  795. m_nQuickOpenTxn = 0;
  796. return;
  797. }
  798. }
  799. m_hQuickOpenCrate = NULL;
  800. m_nQuickOpenTxn = 0;
  801. }
  802. //-----------------------------------------------------------------------------
  803. // Purpose: When the store get's a new transaction ID, it comes here as well
  804. //-----------------------------------------------------------------------------
  805. void CBackpackPanel::SetCurrentTransactionID( uint64 nTxnID )
  806. {
  807. // If we've got a quick open crate st, and no quick open transaction ID,
  808. // then we want to capture the incoming transaction ID so that we can
  809. // compare future incoming successful transactions to see if they have
  810. // the key we're expecting
  811. if ( m_hQuickOpenCrate && m_nQuickOpenTxn == 0 )
  812. {
  813. m_nQuickOpenTxn = nTxnID;
  814. }
  815. }
  816. //-----------------------------------------------------------------------------
  817. // Purpose:
  818. //-----------------------------------------------------------------------------
  819. void CBackpackPanel::OnShowPanel( bool bVisible, bool bReturningFromArmory )
  820. {
  821. if ( bVisible )
  822. {
  823. m_pMouseDragItemPanel->SetVisible( false );
  824. if( m_pDynamicRecipePanel )
  825. {
  826. m_pDynamicRecipePanel->SetVisible( false );
  827. }
  828. if ( m_pItemSlotPanel )
  829. {
  830. m_pItemSlotPanel->SetVisible( false );
  831. }
  832. m_bShowBaseItems = false;
  833. if ( m_pShowBaseItemsCheckbox )
  834. {
  835. m_pShowBaseItemsCheckbox->SetSelected( m_bShowBaseItems );
  836. }
  837. if ( !bReturningFromArmory )
  838. {
  839. SetCurrentPage( 0 );
  840. CancelToolSelection();
  841. }
  842. m_nNumActivePages = 0;
  843. #ifdef STAGING_ONLY
  844. // Reset pinned-state of the card
  845. m_pMouseOverCardPanel->PinCard( false );
  846. #endif
  847. }
  848. else
  849. {
  850. if ( m_bDragging )
  851. {
  852. StopDrag( false );
  853. }
  854. }
  855. if ( m_pInspectPanel )
  856. {
  857. m_pInspectPanel->SetVisible( false );
  858. }
  859. if ( m_pInspectCosmeticPanel )
  860. {
  861. m_pInspectCosmeticPanel->SetVisible( false );
  862. }
  863. if ( m_pCollectionCraftPanel )
  864. {
  865. m_pCollectionCraftPanel->SetVisible( false );
  866. }
  867. if ( m_pHalloweenOfferingPanel )
  868. {
  869. m_pHalloweenOfferingPanel->SetVisible( false );
  870. }
  871. if ( m_pMannCoTradePanel )
  872. {
  873. m_pMannCoTradePanel->SetVisible( false );
  874. }
  875. if ( m_pStrangeToolPanel )
  876. {
  877. m_pStrangeToolPanel->MarkForDeletion();
  878. m_pStrangeToolPanel = NULL;
  879. }
  880. }
  881. //-----------------------------------------------------------------------------
  882. // Purpose:
  883. //-----------------------------------------------------------------------------
  884. void CBackpackPanel::PostShowPanel( bool bVisible )
  885. {
  886. if ( bVisible )
  887. {
  888. DeSelectAllBackpackItemPanels();
  889. RequestFocus();
  890. // Clear out text field
  891. ClearNameFilter( true );
  892. }
  893. // If this is the first time we've opened the loadout, start the loadout explanations
  894. ConVar *pConVar = GetExplanationConVar();
  895. if ( bVisible && pConVar && !pConVar->GetBool() && ShouldShowExplanations() )
  896. {
  897. m_flStartExplanationsAt = Plat_FloatTime() + 0.5;
  898. vgui::ivgui()->AddTickSignal( GetVPanel() );
  899. }
  900. }
  901. //-----------------------------------------------------------------------------
  902. // Purpose:
  903. //-----------------------------------------------------------------------------
  904. int CBackpackPanel::GetNumPages( void )
  905. {
  906. int iMaxItems = InventoryManager()->GetLocalInventory()->GetMaxItemCount();
  907. return (int)(ceil((float)iMaxItems / (float)BACKPACK_SLOTS_PER_PAGE));
  908. }
  909. //-----------------------------------------------------------------------------
  910. // Purpose:
  911. //-----------------------------------------------------------------------------
  912. void CBackpackPanel::AssignItemToPanel( CItemModelPanel *pPanel, int iIndex )
  913. {
  914. tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ );
  915. static int iItemBackpackPos = 0;
  916. if ( iIndex == 0 )
  917. {
  918. iItemBackpackPos = 0;
  919. }
  920. int iPanelBackpackPos = GetBackpackPosForPanelIndex(iIndex);
  921. static int iLastMapItem = -1;
  922. pPanel->SetShowQuantity( true );
  923. const wchar_t* wszFilter = GetNameFilter();
  924. bool bInToolSelection = InToolSelectionMode() && m_ToolSelectionItem.IsValid();
  925. CEconItemView *pItemData = NULL;
  926. CEconItemView tempItem;
  927. if ( m_bShowBaseItems )
  928. {
  929. const CEconItemDefinition* pItemDef = NULL;
  930. const CEconItemSchema::BaseItemDefinitionMap_t& mapItems = GetItemSchema()->GetBaseItemDefinitionMap();
  931. int iStart = iIndex == 0 ? mapItems.FirstInorder() : mapItems.NextInorder( iLastMapItem );
  932. for ( int it = iStart; it != mapItems.InvalidIndex(); it = mapItems.NextInorder( it ) )
  933. {
  934. iLastMapItem = it;
  935. if ( mapItems[it]->IsBaseItem() && !mapItems[it]->IsHidden() )
  936. {
  937. // Instead of linking to this base item definition, link to the definition of what it will become
  938. // when we customize it.
  939. CFmtStr fmtStrCustomizedDefName( "Upgradeable %s", mapItems[it]->GetDefinitionName() );
  940. pItemDef = GetItemSchema()->GetItemDefinitionByName( fmtStrCustomizedDefName.Access() );
  941. // If we don't have an upgradeable version, we assume that we can't upgrade it and link to the base
  942. // definition instead. We expect this to only happen if the item won't actually be useable for whatever
  943. // purpose (name tags, etc.). We sanity-check this on the GC.
  944. if ( !pItemDef )
  945. {
  946. pItemDef = mapItems[it];
  947. }
  948. tempItem.Init( pItemDef->GetDefinitionIndex(), AE_UNIQUE, AE_USE_SCRIPT_VALUE, true );
  949. // skip this item if the tool cannot be applied to it
  950. if ( bInToolSelection && !CEconSharedToolSupport::ToolCanApplyTo( &m_ToolSelectionItem, &tempItem ) )
  951. {
  952. pItemDef = NULL;
  953. continue;
  954. }
  955. if ( DoesItemPassSearchFilter( tempItem.GetDescription(), wszFilter ) )
  956. {
  957. break;
  958. }
  959. }
  960. pItemDef = NULL;
  961. }
  962. if ( pItemDef )
  963. {
  964. pItemData = &tempItem;
  965. ++iItemBackpackPos;
  966. }
  967. }
  968. else if ( HasNameFilter() )
  969. {
  970. int iStart = iIndex == 0 ? m_mapFilteringItems.FirstInorder() : m_mapFilteringItems.NextInorder( iLastMapItem );
  971. for ( int it = iStart; it != m_mapFilteringItems.InvalidIndex(); it = m_mapFilteringItems.NextInorder( it ) )
  972. {
  973. iLastMapItem = it;
  974. CEconItemView *pItem = m_mapFilteringItems[it];
  975. // skip this item if the tool cannot be applied to it
  976. if ( bInToolSelection && !CEconSharedToolSupport::ToolCanApplyTo( &m_ToolSelectionItem, pItem ) )
  977. {
  978. continue;
  979. }
  980. if ( !DoesItemPassSearchFilter( pItem->GetDescription(), wszFilter ) )
  981. {
  982. continue;
  983. }
  984. if ( ++iItemBackpackPos != iPanelBackpackPos )
  985. {
  986. continue;
  987. }
  988. pItemData = pItem;
  989. break;
  990. }
  991. }
  992. else if ( bInToolSelection )
  993. {
  994. CPlayerInventory *pInventory = InventoryManager()->GetLocalInventory();
  995. if ( pInventory )
  996. {
  997. // Backpack positions start from 1
  998. Assert( iPanelBackpackPos > 0 && iPanelBackpackPos <= pInventory->GetMaxItemCount() );
  999. int iStart = iIndex == 0 ? 0 : iLastMapItem + 1;
  1000. for ( int i = iStart; i < pInventory->GetItemCount(); i++ )
  1001. {
  1002. iLastMapItem = i;
  1003. CEconItemView *pItem = pInventory->GetItem(i);
  1004. if ( m_ToolSelectionItem.GetStaticData()->IsTool() )
  1005. {
  1006. if ( !CEconSharedToolSupport::ToolCanApplyTo( &m_ToolSelectionItem, pItem ) )
  1007. {
  1008. continue;
  1009. }
  1010. }
  1011. else
  1012. {
  1013. if ( !pItem->GetStaticData()->IsTool() )
  1014. {
  1015. continue;
  1016. }
  1017. if ( !CEconSharedToolSupport::ToolCanApplyTo( pItem, &m_ToolSelectionItem ) )
  1018. {
  1019. continue;
  1020. }
  1021. if ( ( m_ToolSelectionItem.GetStaticData()->GetCapabilities() & ITEM_CAP_DECODABLE ) && pItem->GetStaticData()->GetEconTool() && ( Q_strcmp( pItem->GetStaticData()->GetEconTool()->GetTypeName(), "decoder_ring" ) != 0 ) )
  1022. {
  1023. continue;
  1024. }
  1025. }
  1026. if ( ++iItemBackpackPos != iPanelBackpackPos )
  1027. {
  1028. continue;
  1029. }
  1030. pItemData = pItem;
  1031. break;
  1032. }
  1033. }
  1034. }
  1035. else
  1036. {
  1037. pItemData = InventoryManager()->GetItemByBackpackPosition( iPanelBackpackPos );
  1038. iItemBackpackPos = iPanelBackpackPos;
  1039. if ( pItemData == NULL && pPanel->GetItem() == NULL )
  1040. {
  1041. return;
  1042. }
  1043. int nDirtyIndex = pItemData ? m_vecDirtyItems.Find( pItemData->GetItemID() ) : m_vecDirtyItems.InvalidIndex();
  1044. if ( pItemData // Want to put in an item
  1045. && pPanel->GetItem() // Panel has an item
  1046. && pItemData->GetItemID() == pPanel->GetItem()->GetItemID() // That panel has the same item that we want to put in
  1047. && nDirtyIndex == m_vecDirtyItems.InvalidIndex() ) // And that item is not dirtied.
  1048. {
  1049. // We dont do anything
  1050. return;
  1051. }
  1052. if ( nDirtyIndex != m_vecDirtyItems.InvalidIndex() )
  1053. {
  1054. m_vecDirtyItems.Remove( nDirtyIndex );
  1055. }
  1056. }
  1057. if ( iItemBackpackPos != iPanelBackpackPos )
  1058. {
  1059. pItemData = NULL;
  1060. }
  1061. pPanel->SetItem( pItemData );
  1062. bool bSeen = true;
  1063. // Have we not seen this item before?
  1064. if ( !m_bShowBaseItems && pItemData && m_mapSeenItems.Find( pItemData->GetItemID() ) == m_mapSeenItems.InvalidIndex() )
  1065. {
  1066. bSeen = false;
  1067. }
  1068. // Show our "NEW!" label if this item hasnt been seen
  1069. CExLabel *pNewPanel = dynamic_cast< CExLabel* >( pPanel->FindChildByName( "New" ) );
  1070. if ( pNewPanel )
  1071. {
  1072. pNewPanel->SetVisible( !bSeen );
  1073. }
  1074. pPanel->DirtyDescription();
  1075. }
  1076. //-----------------------------------------------------------------------------
  1077. // Purpose:
  1078. //-----------------------------------------------------------------------------
  1079. void CBackpackPanel::ClearNameFilter( bool bUpdateModelPanels )
  1080. {
  1081. if ( m_wNameFilter.Count() == 0 )
  1082. return;
  1083. m_wNameFilter.RemoveAll();
  1084. if( m_pNameFilterTextEntry )
  1085. {
  1086. m_pNameFilterTextEntry->SetText( "" );
  1087. }
  1088. if ( bUpdateModelPanels )
  1089. {
  1090. m_flFilterItemTime = gpGlobals->curtime + 0.1f;
  1091. }
  1092. }
  1093. //-----------------------------------------------------------------------------
  1094. // Purpose:
  1095. //-----------------------------------------------------------------------------
  1096. void CBackpackPanel::UpdateFilteringItems()
  1097. {
  1098. m_mapFilteringItems.RemoveAll();
  1099. if ( !HasNameFilter() )
  1100. return;
  1101. CPlayerInventory *pInventory = InventoryManager()->GetLocalInventory();
  1102. if ( !pInventory )
  1103. return;
  1104. for ( int i = 0; i < pInventory->GetItemCount(); i++ )
  1105. {
  1106. CEconItemView *pItem = pInventory->GetItem(i);
  1107. if ( pItem->GetItemDefinition()->IsHidden() )
  1108. continue;
  1109. int iBackpackPosition = InventoryManager()->GetBackpackPositionFromBackend( pItem->GetInventoryPosition() );
  1110. m_mapFilteringItems.Insert( iBackpackPosition, pItem );
  1111. }
  1112. }
  1113. //-----------------------------------------------------------------------------
  1114. // Purpose:
  1115. //-----------------------------------------------------------------------------
  1116. void CBackpackPanel::UpdateModelPanels( void )
  1117. {
  1118. tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "%s", __FUNCTION__ );
  1119. UpdateFilteringItems();
  1120. // We're showing the backpack. Show all the items in our inventory
  1121. FOR_EACH_VEC( m_pItemModelPanels, i )
  1122. {
  1123. m_pItemModelPanels[i]->SetShowEquipped( true );
  1124. m_pItemModelPanels[i]->SetShowGreyedOutTooltip( true );
  1125. AssignItemToPanel( m_pItemModelPanels[i], i );
  1126. if ( !m_pItemModelPanels[i]->HasItem() && m_pItemModelPanels[i]->IsSelected() )
  1127. {
  1128. m_pItemModelPanels[i]->SetSelected( false );
  1129. }
  1130. SetBorderForItem( m_pItemModelPanels[i], false );
  1131. }
  1132. // Clean out. We just did all the heavy lifting.
  1133. m_vecDirtyItems.Purge();
  1134. if ( InToolSelectionMode() && m_ToolSelectionItem.IsValid() )
  1135. {
  1136. wchar_t wTemp[256];
  1137. g_pVGuiLocalize->ConstructString_safe( wTemp, g_pVGuiLocalize->Find( "BackpackApplyTool" ), 1, m_ToolSelectionItem.GetItemName() );
  1138. SetDialogVariable( "loadoutclass", wTemp );
  1139. }
  1140. else
  1141. {
  1142. SetDialogVariable( "loadoutclass", g_pVGuiLocalize->Find( "BackpackTitle" ) );
  1143. }
  1144. char szTmp[16];
  1145. V_sprintf_safe( szTmp, "%d/%d", GetCurrentPage()+1, GetNumPages() );
  1146. SetDialogVariable( "backpackpage", szTmp );
  1147. // Now layout again to position our item buttons
  1148. InvalidateLayout();
  1149. }
  1150. //-----------------------------------------------------------------------------
  1151. // Purpose: Mark visited item model panels as seen
  1152. //-----------------------------------------------------------------------------
  1153. void CBackpackPanel::OnItemPanelEntered( vgui::Panel *panel )
  1154. {
  1155. if ( m_pContextMenu && m_pContextMenu->IsVisible() )
  1156. return;
  1157. CItemModelPanel *pItemPanel = dynamic_cast < CItemModelPanel * > ( panel );
  1158. if ( pItemPanel )
  1159. {
  1160. // Hide the "NEW!" label
  1161. CExLabel *pNewPanel = dynamic_cast< CExLabel* >( pItemPanel->FindChildByName( "New" ) );
  1162. if ( pNewPanel )
  1163. {
  1164. pNewPanel->SetVisible( false );
  1165. }
  1166. // Mark this item as "seen"
  1167. CEconItemView *pItem = pItemPanel->GetItem();
  1168. if ( pItem )
  1169. {
  1170. if ( m_mapSeenItems.Find( pItem->GetItemID() ) == m_mapSeenItems.InvalidIndex() )
  1171. {
  1172. m_mapSeenItems.Insert( pItem->GetItemID() );
  1173. SetPageButtonTextColorBasedOnContents();
  1174. }
  1175. }
  1176. }
  1177. BaseClass::OnItemPanelEntered( panel );
  1178. }
  1179. //-----------------------------------------------------------------------------
  1180. // Purpose:
  1181. //-----------------------------------------------------------------------------
  1182. void CBackpackPanel::OnItemPanelMousePressed( vgui::Panel *panel )
  1183. {
  1184. CItemModelPanel *pItemPanel = dynamic_cast < CItemModelPanel * > ( panel );
  1185. if ( pItemPanel && IsVisible() && pItemPanel->IsGreyedOut() == false && AllowDragging( pItemPanel ) )
  1186. {
  1187. m_flMouseDownTime = gpGlobals->curtime;
  1188. m_iMouseDownX = m_iMouseDownY = 0;
  1189. m_pItemDraggedFromPanel = pItemPanel;
  1190. m_iDraggedFromPage = GetCurrentPage();
  1191. m_bDragging = false;
  1192. m_bMouseDownOnItemPanel = true;
  1193. }
  1194. }
  1195. //-----------------------------------------------------------------------------
  1196. // Purpose: Handle the escape key since it doesn't show up in OnKeyCodePressed
  1197. //-----------------------------------------------------------------------------
  1198. void CBackpackPanel::OnKeyCodeTyped(vgui::KeyCode code)
  1199. {
  1200. if ( code == KEY_ESCAPE && InToolSelectionMode() )
  1201. {
  1202. CancelToolSelection();
  1203. }
  1204. else if ( code == KEY_ENTER )
  1205. {
  1206. // Do nothing. This gets hit frequently when people type in the filter
  1207. // text entry and then hit 'Enter', expecting it to execute the filter.
  1208. // We automatically apply it, so let's just eat 'Enter', which was causing
  1209. // us to activate some button on the main menu.
  1210. }
  1211. else
  1212. {
  1213. BaseClass::OnKeyCodeTyped( code );
  1214. }
  1215. }
  1216. //-----------------------------------------------------------------------------
  1217. // Purpose: Handles key press events in the backpack
  1218. //-----------------------------------------------------------------------------
  1219. void CBackpackPanel::OnKeyCodePressed( vgui::KeyCode code )
  1220. {
  1221. // Ignore key events while the confirm delete dialog is up
  1222. if( m_pConfirmDeleteDialog )
  1223. return;
  1224. // let our parent class handle all the arrow key/dpad stuff
  1225. if( HandleItemSelectionKeyPressed( code ) )
  1226. {
  1227. return;
  1228. }
  1229. // Handle close here, CBasePanel parent doesn't support "DialogClosing" command
  1230. ButtonCode_t nButtonCode = GetBaseButtonCode( code );
  1231. if ( (nButtonCode == KEY_XBUTTON_B || nButtonCode == STEAMCONTROLLER_B) && InToolSelectionMode() )
  1232. {
  1233. CancelToolSelection();
  1234. }
  1235. else if( code == KEY_PAGEDOWN )
  1236. {
  1237. OnCommand( "nextpage" );
  1238. }
  1239. else if( code == KEY_PAGEUP )
  1240. {
  1241. OnCommand( "prevpage" );
  1242. }
  1243. else if ( ( nButtonCode == KEY_XBUTTON_A || code == KEY_ENTER || nButtonCode == STEAMCONTROLLER_A ) )
  1244. {
  1245. if( InToolSelectionMode() )
  1246. {
  1247. HandleToolItemSelection( GetFirstSelectedItem() );
  1248. }
  1249. else
  1250. {
  1251. OpenContextMenu();
  1252. }
  1253. }
  1254. else if ( nButtonCode == KEY_XBUTTON_X || nButtonCode == STEAMCONTROLLER_X )
  1255. {
  1256. if( !InToolSelectionMode() )
  1257. {
  1258. OnCommand( "deleteitem" );
  1259. }
  1260. }
  1261. else
  1262. {
  1263. BaseClass::OnKeyCodePressed( code );
  1264. }
  1265. }
  1266. //-----------------------------------------------------------------------------
  1267. // Purpose: Handles key press events in the backpack
  1268. //-----------------------------------------------------------------------------
  1269. void CBackpackPanel::OnKeyCodeReleased( vgui::KeyCode code )
  1270. {
  1271. if( ! HandleItemSelectionKeyReleased( code ) )
  1272. BaseClass::OnKeyCodeReleased( code );
  1273. }
  1274. //-----------------------------------------------------------------------------
  1275. // Purpose:
  1276. //-----------------------------------------------------------------------------
  1277. void CBackpackPanel::OnMouseCaptureLost( void )
  1278. {
  1279. if ( m_bDragging )
  1280. {
  1281. StopDrag( false );
  1282. }
  1283. }
  1284. //-----------------------------------------------------------------------------
  1285. // Purpose:
  1286. //-----------------------------------------------------------------------------
  1287. void CBackpackPanel::OnMouseReleased(vgui::MouseCode code)
  1288. {
  1289. if ( code == MOUSE_LEFT )
  1290. {
  1291. if ( m_bDragging )
  1292. {
  1293. // When we're dragging, we have mouse capture, so the item panels aren't getting mouse input.
  1294. // We need to find out what item panel we're over, and let it know.
  1295. if ( m_pPrevDragOverItemPanel )
  1296. {
  1297. OnItemPanelMouseReleased( m_pPrevDragOverItemPanel );
  1298. }
  1299. else
  1300. {
  1301. StopDrag( false );
  1302. }
  1303. }
  1304. }
  1305. BaseClass::OnMouseReleased( code );
  1306. }
  1307. //-----------------------------------------------------------------------------
  1308. // Purpose:
  1309. //-----------------------------------------------------------------------------
  1310. void CBackpackPanel::OnConfirmDelete( KeyValues *data )
  1311. {
  1312. // Delete all the selected item
  1313. if ( data )
  1314. {
  1315. int iConfirmed = data->GetInt( "confirmed", 0 );
  1316. if ( iConfirmed )
  1317. {
  1318. for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
  1319. {
  1320. if ( m_pItemModelPanels[i]->IsSelected() && m_pItemModelPanels[i]->HasItem() )
  1321. {
  1322. EconUI()->Gamestats_ItemTransaction( IE_ITEM_DELETED, m_pItemModelPanels[i]->GetItem() );
  1323. InventoryManager()->DropItem( m_pItemModelPanels[i]->GetItem()->GetItemID() );
  1324. }
  1325. }
  1326. DeSelectAllBackpackItemPanels();
  1327. }
  1328. }
  1329. m_pConfirmDeleteDialog = NULL;
  1330. // If we're embedded in the discard item panel, it needs to know we made room. Send a message to our parent that it can catch.
  1331. PostMessage( GetParent(), new KeyValues("ConfirmDlgResult", "confirmed", 2 ) );
  1332. }
  1333. //-----------------------------------------------------------------------------
  1334. // Purpose:
  1335. //-----------------------------------------------------------------------------
  1336. void CBackpackPanel::OnItemPanelMouseReleased( vgui::Panel *panel )
  1337. {
  1338. CItemModelPanel *pItemPanel = dynamic_cast < CItemModelPanel * > ( panel );
  1339. if ( pItemPanel && IsVisible() )
  1340. {
  1341. if ( InToolSelectionMode() )
  1342. {
  1343. // They're selecting the item they'd like to apply a tool to
  1344. HandleToolItemSelection( pItemPanel->GetItem() );
  1345. }
  1346. else if ( !m_bDragging )
  1347. {
  1348. // If they're not holding down ctrl, deselect all existing selections
  1349. if ( !vgui::input()->IsKeyDown(KEY_LCONTROL) && !vgui::input()->IsKeyDown(KEY_RCONTROL) )
  1350. {
  1351. DeSelectAllBackpackItemPanels();
  1352. }
  1353. // Quick clicks just select the item
  1354. ToggleSelectBackpackItemPanel( pItemPanel );
  1355. if ( pItemPanel->IsSelected() )
  1356. {
  1357. OpenContextMenu();
  1358. }
  1359. }
  1360. else
  1361. {
  1362. int iPanelIndex = GetBackpackPositionForPanel( pItemPanel );
  1363. if ( !CanDragTo(pItemPanel, iPanelIndex) )
  1364. {
  1365. StopDrag(false);
  1366. }
  1367. else
  1368. {
  1369. StopDrag( true );
  1370. if ( (pItemPanel != m_pItemDraggedFromPanel || m_iDraggedFromPage != GetCurrentPage() ) && m_pMouseDragItemPanel->HasItem() )
  1371. {
  1372. HandleDragTo( pItemPanel, iPanelIndex );
  1373. }
  1374. else if ( m_iDraggedFromPage == GetCurrentPage() )
  1375. {
  1376. m_pItemDraggedFromPanel->SetItem( m_pMouseDragItemPanel->GetItem() );
  1377. }
  1378. }
  1379. }
  1380. m_pItemDraggedFromPanel = NULL;
  1381. }
  1382. }
  1383. bool GetDecodedByItemDefIndex( const CEconItemView *pItem, uint32 *pDecodedBy = NULL )
  1384. {
  1385. static CSchemaAttributeDefHandle pAttrDef_DecodedBy( "decoded by itemdefindex" );
  1386. if ( pDecodedBy )
  1387. {
  1388. return pItem->FindAttribute( pAttrDef_DecodedBy, pDecodedBy );
  1389. }
  1390. else
  1391. {
  1392. return pItem->FindAttribute( pAttrDef_DecodedBy );
  1393. }
  1394. }
  1395. CEconItemView* GetFirstCompatibleKeyForCrate( const CEconItemView *pItem )
  1396. {
  1397. // Check if we have any decoder rings that can be applied onto this
  1398. CPlayerInventory *pInv = InventoryManager()->GetLocalInventory();
  1399. Assert( pInv );
  1400. if ( pInv )
  1401. {
  1402. for ( int i = 0; i < pInv->GetItemCount(); ++i )
  1403. {
  1404. CEconItemView *pInvItem = pInv->GetItem( i );
  1405. if ( pInvItem->GetQuality() == AE_SELFMADE )
  1406. continue;
  1407. if ( pInvItem->GetStaticData()->IsTool() && CEconSharedToolSupport::ToolCanApplyTo( pInvItem, pItem ) && pInvItem->GetStaticData()->GetEconTool() && ( Q_strcmp( pInvItem->GetStaticData()->GetEconTool()->GetTypeName(), "decoder_ring" ) == 0 ) )
  1408. {
  1409. return pInvItem;
  1410. }
  1411. }
  1412. }
  1413. return NULL;
  1414. }
  1415. bool CanInventoryItemsApplyTo( const CEconItemView *pItem )
  1416. {
  1417. // Check if we have any tools that can be applied onto this
  1418. CPlayerInventory *pInv = InventoryManager()->GetLocalInventory();
  1419. Assert( pInv );
  1420. if ( pInv )
  1421. {
  1422. for ( int i = 0 ; i < pInv->GetItemCount() ; ++i )
  1423. {
  1424. CEconItemView *pInvItem = pInv->GetItem( i );
  1425. if ( pInvItem->GetStaticData()->IsTool() && CEconSharedToolSupport::ToolCanApplyTo( pInvItem, pItem ) )
  1426. {
  1427. return true;
  1428. }
  1429. }
  1430. }
  1431. return false;
  1432. }
  1433. //-----------------------------------------------------------------------------
  1434. bool CreateMarketPriceString( item_definition_index_t iDefIndex, wchar_t *pszString, int iBufferSize )
  1435. {
  1436. // Get Market Price
  1437. steam_market_gc_identifier_t ident;
  1438. ident.m_unDefIndex = iDefIndex;
  1439. ident.m_unQuality = AE_UNIQUE; // Get this from default item def?
  1440. const client_market_data_t *pClientMarketData = GetClientMarketData( ident );
  1441. if ( !pClientMarketData )
  1442. return false;
  1443. const ECurrency eCurrency = EconUI()->GetStorePanel()->GetCurrency();
  1444. // Set that price into the button
  1445. wchar_t pszCurrencyString[kLocalizedPriceSizeInChararacters];
  1446. MakeMoneyString( pszCurrencyString, ARRAYSIZE( pszCurrencyString ), pClientMarketData->m_unLowestPrice, eCurrency );
  1447. wchar_t pszConstructed[kLocalizedPriceSizeInChararacters];
  1448. g_pVGuiLocalize->ConstructString_safe( pszConstructed, g_pVGuiLocalize->Find( "#TF_MarketPrice" ), 1, pszCurrencyString );
  1449. // copy result;
  1450. V_wcsncpy( pszString, pszConstructed, iBufferSize );
  1451. return true;
  1452. }
  1453. //-----------------------------------------------------------------------------
  1454. bool CreateStorePriceString( item_definition_index_t iDefIndex, wchar_t *pszString, int iBufferSize )
  1455. {
  1456. // Get Market Price
  1457. steam_market_gc_identifier_t ident;
  1458. ident.m_unDefIndex = iDefIndex;
  1459. ident.m_unQuality = AE_UNIQUE; // Get this from default item def?
  1460. // Get the price of the item
  1461. const econ_store_entry_t *pEntry = EconUI()->GetStorePanel()->GetPriceSheet()->GetEntry( iDefIndex );
  1462. if ( !pEntry )
  1463. return false;
  1464. const ECurrency eCurrency = EconUI()->GetStorePanel()->GetCurrency();
  1465. // Set that price into the button
  1466. wchar_t pszCurrencyString[kLocalizedPriceSizeInChararacters];
  1467. MakeMoneyString( pszCurrencyString, ARRAYSIZE( pszCurrencyString ), pEntry->GetCurrentPrice( eCurrency ), eCurrency );
  1468. wchar_t pszConstructed[kLocalizedPriceSizeInChararacters];
  1469. g_pVGuiLocalize->ConstructString_safe( pszConstructed, g_pVGuiLocalize->Find( "#TF_StorePrice" ), 1, pszCurrencyString );
  1470. // copy result;
  1471. V_wcsncpy( pszString, pszConstructed, iBufferSize );
  1472. return true;
  1473. }
  1474. //-----------------------------------------------------------------------------
  1475. void CBackpackPanel::AddCommerceSubmenus( Menu *pSubMenu, item_definition_index_t iItemDef, const char* pszActionFmt )
  1476. {
  1477. wchar_t wPriceListing[256];
  1478. // Store
  1479. if ( CreateStorePriceString( iItemDef, wPriceListing, sizeof( wPriceListing ) ) )
  1480. {
  1481. int nIndex = pSubMenu->AddMenuItem( "", new KeyValues( "Command", "command", CFmtStr( "%s%s%d", "store_", pszActionFmt, iItemDef ) ), this );
  1482. vgui::MenuItem *pMenuItem = pSubMenu->GetMenuItem( nIndex );
  1483. pMenuItem->SetText( wPriceListing );
  1484. pMenuItem->InvalidateLayout( true, false );
  1485. }
  1486. // Market
  1487. if ( CreateMarketPriceString( iItemDef, wPriceListing, sizeof( wPriceListing ) ) )
  1488. {
  1489. int nIndex = pSubMenu->AddMenuItem( "", new KeyValues( "Command", "command", CFmtStr( "%s%s%d", "market_", pszActionFmt, iItemDef ) ), this );
  1490. vgui::MenuItem *pMenuItem = pSubMenu->GetMenuItem( nIndex );
  1491. pMenuItem->SetText( wPriceListing );
  1492. pMenuItem->InvalidateLayout( true, false );
  1493. }
  1494. else
  1495. {
  1496. int nIndex = pSubMenu->AddMenuItem( "", new KeyValues( "Command", "command", CFmtStr( "%s%s%d", "market_", pszActionFmt, iItemDef ) ), this );
  1497. vgui::MenuItem *pMenuItem = pSubMenu->GetMenuItem( nIndex );
  1498. pMenuItem->SetText( g_pVGuiLocalize->Find( "#TF_MarketUnavailable" ) );
  1499. pMenuItem->InvalidateLayout( true, false );
  1500. }
  1501. }
  1502. //-----------------------------------------------------------------------------
  1503. void CBackpackPanel::AddPaintToContextMenu( Menu *pPaintSubMenu, item_definition_index_t iPaintDef, bool bAddCommerce )
  1504. {
  1505. GameItemDefinition_t * pPaintCanDef = dynamic_cast<GameItemDefinition_t*>( GEconItemSchema().GetItemDefinition( iPaintDef ) );
  1506. if ( !pPaintCanDef )
  1507. return;
  1508. wchar_t wBuff[256];
  1509. char cBuff[256];
  1510. V_swprintf_safe( wBuff, L" %ls", g_pVGuiLocalize->Find( pPaintCanDef->GetItemBaseName() ) );
  1511. char szItemName[256];
  1512. g_pVGuiLocalize->ConvertUnicodeToANSI( g_pVGuiLocalize->Find( pPaintCanDef->GetItemBaseName() ), szItemName, sizeof( szItemName ) );
  1513. V_sprintf_safe( cBuff, " %s", szItemName );
  1514. uint32 unPaintRGB0 = 0;
  1515. uint32 unPaintRGB1 = 0;
  1516. static CSchemaAttributeDefHandle pAttrDef_PaintRGB( "set item tint RGB" );
  1517. static CSchemaAttributeDefHandle pAttrDef_PaintRGB2( "set item tint RGB 2" );
  1518. float fRGB = 0.0f;
  1519. if ( FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pPaintCanDef, pAttrDef_PaintRGB, &fRGB ) && fRGB != 0.0f )
  1520. {
  1521. unPaintRGB0 = fRGB;
  1522. // We may or may not have a secondary paint color as well. If we don't, we just use the primary
  1523. // paint color to fill both slots.
  1524. if ( FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pPaintCanDef, pAttrDef_PaintRGB2, &fRGB ) )
  1525. {
  1526. unPaintRGB1 = fRGB;
  1527. }
  1528. else
  1529. {
  1530. unPaintRGB1 = unPaintRGB0;
  1531. }
  1532. }
  1533. if ( !bAddCommerce )
  1534. {
  1535. int nIndex = pPaintSubMenu->AddMenuItem( "", new KeyValues( "Command", "command", CFmtStr( "paint%d", iPaintDef ) ), this );
  1536. vgui::MenuItem *pMenuItem = pPaintSubMenu->GetMenuItem( nIndex );
  1537. pMenuItem->SetText( wBuff );
  1538. pMenuItem->InvalidateLayout( true, false );
  1539. CItemMaterialCustomizationIconPanel *pCustomPanel = new CItemMaterialCustomizationIconPanel( pMenuItem, "paint" );
  1540. pCustomPanel->SetZPos( -100 );
  1541. pCustomPanel->SetTall( 30 );
  1542. pCustomPanel->SetWide( 30 );
  1543. pCustomPanel->m_colPaintColors.AddToTail( Color( clamp( ( unPaintRGB0 & 0xFF0000 ) >> 16, 0, 255 ), clamp( ( unPaintRGB0 & 0xFF00 ) >> 8, 0, 255 ), clamp( ( unPaintRGB0 & 0xFF ), 0, 255 ), 255 ) );
  1544. pCustomPanel->m_colPaintColors.AddToTail( Color( clamp( ( unPaintRGB1 & 0xFF0000 ) >> 16, 0, 255 ), clamp( ( unPaintRGB1 & 0xFF00 ) >> 8, 0, 255 ), clamp( ( unPaintRGB1 & 0xFF ), 0, 255 ), 255 ) );
  1545. }
  1546. else
  1547. {
  1548. //
  1549. const char *pszContextMenuBorder = "NotificationDefault";
  1550. const char *pszContextMenuFont = "HudFontMediumSecondary";
  1551. Menu *pSubMenu = new Menu( this, "PaintSubMenu" );
  1552. pSubMenu->SetBorder( scheme()->GetIScheme( GetScheme() )->GetBorder( pszContextMenuBorder ) );
  1553. pSubMenu->SetFont( scheme()->GetIScheme( GetScheme() )->GetFont( pszContextMenuFont ) );
  1554. int iPos = pPaintSubMenu->AddCascadingMenuItem( cBuff, this, pSubMenu );
  1555. CItemMaterialCustomizationIconPanel *pCustomPanel = new CItemMaterialCustomizationIconPanel( pPaintSubMenu, "paint" );
  1556. pCustomPanel->SetZPos( 100 );
  1557. pCustomPanel->SetPos( 0, iPos * pPaintSubMenu->GetMenuItemHeight() );
  1558. pCustomPanel->SetTall( 30 );
  1559. pCustomPanel->SetWide( 30 );
  1560. pCustomPanel->m_colPaintColors.AddToTail( Color( clamp( ( unPaintRGB0 & 0xFF0000 ) >> 16, 0, 255 ), clamp( ( unPaintRGB0 & 0xFF00 ) >> 8, 0, 255 ), clamp( ( unPaintRGB0 & 0xFF ), 0, 255 ), 255 ) );
  1561. pCustomPanel->m_colPaintColors.AddToTail( Color( clamp( ( unPaintRGB1 & 0xFF0000 ) >> 16, 0, 255 ), clamp( ( unPaintRGB1 & 0xFF00 ) >> 8, 0, 255 ), clamp( ( unPaintRGB1 & 0xFF ), 0, 255 ), 255 ) );
  1562. AddCommerceSubmenus( pSubMenu, iPaintDef, "paint" );
  1563. }
  1564. }
  1565. //
  1566. // Add commerce context options for an item. Adds 'Store' and 'Market' options if appropriate (and Pricing) other wise just click to use
  1567. //
  1568. void CBackpackPanel::AddCommerceToContextMenu( Menu *pMenu, const char* pszActionFmt, item_definition_index_t iItemDefIndex, bool bAddMarket, bool bAddStore )
  1569. {
  1570. GameItemDefinition_t * pItemDef = dynamic_cast<GameItemDefinition_t*>( GEconItemSchema().GetItemDefinition( iItemDefIndex ) );
  1571. if ( !pItemDef )
  1572. return;
  1573. //
  1574. if ( !bAddMarket && !bAddStore )
  1575. {
  1576. int nIndex = pMenu->AddMenuItem( "", new KeyValues( "Command", "command", CFmtStr( "%s%d", pszActionFmt, iItemDefIndex ) ), this );
  1577. vgui::MenuItem *pMenuItem = pMenu->GetMenuItem( nIndex );
  1578. pMenuItem->SetText( g_pVGuiLocalize->Find( pItemDef->GetItemBaseName() ) );
  1579. pMenuItem->InvalidateLayout( true, false );
  1580. }
  1581. else
  1582. {
  1583. //
  1584. const char *pszContextMenuBorder = "NotificationDefault";
  1585. const char *pszContextMenuFont = "HudFontMediumSecondary";
  1586. Menu *pSubMenu = new Menu( this, "CommerceSubMenu" );
  1587. pSubMenu->SetBorder( scheme()->GetIScheme( GetScheme() )->GetBorder( pszContextMenuBorder ) );
  1588. pSubMenu->SetFont( scheme()->GetIScheme( GetScheme() )->GetFont( pszContextMenuFont ) );
  1589. pMenu->AddCascadingMenuItem( pItemDef->GetItemBaseName(), this, pSubMenu );
  1590. AddCommerceSubmenus( pSubMenu, iItemDefIndex, pszActionFmt );
  1591. }
  1592. }
  1593. //-----------------------------------------------------------------------------
  1594. // Purpose: Opens a context menu with actions relevant for the passed in item
  1595. //-----------------------------------------------------------------------------
  1596. void CBackpackPanel::OpenContextMenu()
  1597. {
  1598. CUtlVector<CEconItemView*> vecSelectedItems;
  1599. for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
  1600. {
  1601. if ( m_pItemModelPanels[i]->IsSelected() && m_pItemModelPanels[i]->GetItem() )
  1602. {
  1603. vecSelectedItems.AddToTail( m_pItemModelPanels[i]->GetItem() );
  1604. }
  1605. }
  1606. if ( m_pContextMenu )
  1607. delete m_pContextMenu;
  1608. m_pContextMenu = new Menu( this, "ContextMenu" );
  1609. MenuBuilder contextMenuBuilder( m_pContextMenu, this );
  1610. const char *pszContextMenuBorder = "NotificationDefault";
  1611. const char *pszContextMenuFont = "HudFontMediumSecondary";
  1612. m_pContextMenu->SetBorder( scheme()->GetIScheme( GetScheme() )->GetBorder( pszContextMenuBorder ) );
  1613. m_pContextMenu->SetFont( scheme()->GetIScheme( GetScheme() )->GetFont( pszContextMenuFont ) );
  1614. if ( vecSelectedItems.Count() == 1 )
  1615. {
  1616. const CEconItemView *pItem = vecSelectedItems.Head();
  1617. const CTFItemDefinition *pItemDef = pItem->GetStaticData();
  1618. static CSchemaItemDefHandle DuckBadgeItemDef( "Duck Badge" );
  1619. static CSchemaItemDefHandle StrangeCountTransferItemDef( "Strange Count Transfer Tool" );
  1620. // Tools of any kind can't be used if they are in escrow.
  1621. static CSchemaAttributeDefHandle pAttrib_ToolEscrowUntil( "tool escrow until date" );
  1622. uint32 unEscrowTime;
  1623. const bool bToolIsInEscrow = pItem->FindAttribute( pAttrib_ToolEscrowUntil, &unEscrowTime )
  1624. && unEscrowTime > CRTime::RTime32TimeCur();
  1625. const IEconTool *pEconTool = pItem->GetItemDefinition()->GetEconTool();
  1626. const bool bIsTool = pItem->GetStaticData()->IsTool() && (pEconTool != NULL);
  1627. const bool bIsGCConsumable = ( ( pItem->GetStaticData()->GetCapabilities() & ITEM_CAP_USABLE_GC ) != 0 );
  1628. bool bSkipAddTrade = false; // Hack: We should really ask the tool if the command supplants trade.
  1629. // Tool usage goes first. The cursor starts on this element, so double-clicks will work like how they used to.
  1630. // Strange Count Transfer
  1631. if ( StrangeCountTransferItemDef == pItem->GetItemDefinition() )
  1632. {
  1633. contextMenuBuilder.AddMenuItem( "#ApplyOnItem", new KeyValues( "Context_OpenStrangeCountTransfer" ), "primaryaction" );
  1634. }
  1635. else if ( pItem->GetStaticData()->IsTool() && pEconTool == NULL )
  1636. {
  1637. // do nothing. not a real tool (basic balloons with color that we don't want to 'remove' the paint)
  1638. }
  1639. else if ( (bIsTool || bIsGCConsumable) && !bToolIsInEscrow && pEconTool->CanBeUsedNow( pItem ) )
  1640. {
  1641. Assert( pEconTool );
  1642. const int nTokens = pEconTool->GetUseCommandCount( pItem );
  1643. for ( int i = 0; i < nTokens; ++i )
  1644. {
  1645. const char *pszToolUsageString = pEconTool->GetUseCommandLocalizationToken( pItem, i );
  1646. // If we didn't have a custom usage string, fall back to a sane default based on whether or
  1647. // not we're a consumable or not.
  1648. if ( !pszToolUsageString )
  1649. {
  1650. pszToolUsageString = bIsGCConsumable ? "#ConsumeItem" : "#ApplyOnItem";
  1651. }
  1652. const char *pszContext = pEconTool->GetUseCommand( pItem, i );
  1653. contextMenuBuilder.AddMenuItem( pszToolUsageString, new KeyValues( pszContext ), "primaryaction" );
  1654. }
  1655. // Hack: We should really ask the tool if the command supplants trade. For now, if we have two
  1656. // things, then one of them is trade, so skip it.
  1657. bSkipAddTrade = nTokens > 1;
  1658. }
  1659. else if ( pItem->GetItemDefinition()->GetCapabilities() & ITEM_CAP_DECODABLE )
  1660. {
  1661. static CSchemaAttributeDefHandle pAttrDef_CanShuffleCrateContents( "can shuffle crate contents" );
  1662. if ( pItem->FindAttribute( pAttrDef_CanShuffleCrateContents ) )
  1663. {
  1664. contextMenuBuilder.AddMenuItem( "#ShuffleContents", new KeyValues( "Context_Shuffle" ), "primaryaction" );
  1665. }
  1666. if ( GetFirstCompatibleKeyForCrate( pItem ) != NULL )
  1667. {
  1668. contextMenuBuilder.AddMenuItem( "#UseKey", new KeyValues( "Context_OpenCrateWithKey" ), "primaryaction" );
  1669. }
  1670. if ( GetDecodedByItemDefIndex( pItem ) )
  1671. {
  1672. contextMenuBuilder.AddMenuItem( "#GetKey", new KeyValues( "Context_GetItemFromStore" ), "primaryaction" );
  1673. contextMenuBuilder.AddMenuItem( "#BuyAndUseKey", new KeyValues( "Context_BuyKeyAndOpenCrate" ), "primaryaction" );
  1674. }
  1675. }
  1676. else if ( pItem->GetItemDefinition()->GetCapabilities() & ITEM_CAP_HAS_SLOTS )
  1677. {
  1678. // check if we have at least 1 slot criteria
  1679. static CSchemaAttributeDefHandle pAttrDef_Slot( "item slot criteria 1" );
  1680. if ( pItem->FindAttribute( pAttrDef_Slot ) )
  1681. {
  1682. contextMenuBuilder.AddMenuItem( "#EditSlots", new KeyValues( "Context_EditSlot" ), "primaryaction" );
  1683. }
  1684. }
  1685. else if ( DuckBadgeItemDef == pItem->GetItemDefinition() )
  1686. {
  1687. contextMenuBuilder.AddMenuItem( "#Duck_ViewLeaderboards", new KeyValues( "Context_OpenDuckLeaderboards" ), "primaryaction" );
  1688. if ( CanInventoryItemsApplyTo( pItem ) )
  1689. {
  1690. contextMenuBuilder.AddMenuItem( "#UseDuckToken", new KeyValues( "Context_ApplyByItem" ), "primaryaction" );
  1691. }
  1692. if ( GetDecodedByItemDefIndex( pItem ) )
  1693. {
  1694. contextMenuBuilder.AddMenuItem( "#GetDuckToken", new KeyValues( "Context_GetItemFromStore" ), "primaryaction" );
  1695. }
  1696. }
  1697. // 3D Inspect
  1698. float flInspect = 0;
  1699. static CSchemaAttributeDefHandle pAttrib_WeaponAllowInspect( "weapon_allow_inspect" );
  1700. static CSchemaAttributeDefHandle pAttrib_CosmeticAllowInspect( "cosmetic_allow_inspect" );
  1701. if ( pItem && pItem->IsValid() &&
  1702. ( FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pItem, pAttrib_WeaponAllowInspect, &flInspect ) || FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pItem, pAttrib_CosmeticAllowInspect, &flInspect )
  1703. #ifdef STAGING_ONLY
  1704. || tf_weapon_force_allow_inspect.GetBool()
  1705. #endif
  1706. ) )
  1707. {
  1708. if ( flInspect != 0
  1709. #ifdef STAGING_ONLY
  1710. || tf_weapon_force_allow_inspect.GetBool()
  1711. #endif
  1712. )
  1713. {
  1714. contextMenuBuilder.AddMenuItem( "#Context_InspectModel", new KeyValues( "Context_InspectModel" ), "primaryaction" );
  1715. }
  1716. }
  1717. // Add equip sub menu
  1718. {
  1719. Menu *pEquipSubMenu = NULL;
  1720. for ( int iClass = TF_FIRST_NORMAL_CLASS; iClass < TF_LAST_NORMAL_CLASS; iClass++ )
  1721. {
  1722. if ( !pItemDef->CanBeUsedByClass( iClass ) )
  1723. continue;
  1724. if ( pEquipSubMenu == NULL )
  1725. {
  1726. pEquipSubMenu = new Menu( this, "EquipMenu" );
  1727. pEquipSubMenu->SetBorder( scheme()->GetIScheme( GetScheme() )->GetBorder( pszContextMenuBorder ) );
  1728. pEquipSubMenu->SetFont( scheme()->GetIScheme( GetScheme() )->GetFont( pszContextMenuFont ) );
  1729. contextMenuBuilder.AddCascadingMenuItem( "#Context_Equip", pEquipSubMenu, "primaryaction" );
  1730. }
  1731. const char *pszClassName = NULL;
  1732. switch ( iClass )
  1733. {
  1734. case TF_CLASS_SCOUT: pszClassName = "#TF_Class_Name_Scout"; break;
  1735. case TF_CLASS_SNIPER: pszClassName = "#TF_Class_Name_Sniper"; break;
  1736. case TF_CLASS_SOLDIER: pszClassName = "#TF_Class_Name_Soldier"; break;
  1737. case TF_CLASS_DEMOMAN: pszClassName = "#TF_Class_Name_Demoman"; break;
  1738. case TF_CLASS_MEDIC: pszClassName = "#TF_Class_Name_Medic"; break;
  1739. case TF_CLASS_HEAVYWEAPONS: pszClassName = "#TF_Class_Name_HWGuy"; break;
  1740. case TF_CLASS_PYRO: pszClassName = "#TF_Class_Name_Pyro"; break;
  1741. case TF_CLASS_SPY: pszClassName = "#TF_Class_Name_Spy"; break;
  1742. case TF_CLASS_ENGINEER: pszClassName = "#TF_Class_Name_Engineer"; break;
  1743. }
  1744. pEquipSubMenu->AddMenuItem( pszClassName, new KeyValues( "Command", "command", CFmtStr( "equipclass%d", iClass ) ), this );
  1745. }
  1746. }
  1747. // For customizable items only
  1748. if ( !pItem->IsTemporaryItem() )
  1749. {
  1750. bool bCanCraftUp = GetCollectionCraftingInvalidReason(pItem, NULL) == NULL;
  1751. bool bCanStatClockTrade = GetCraftCommonStatClockInvalidReason(pItem, NULL) == NULL;
  1752. Menu *pMannCoTradeSubMenu = NULL;
  1753. if ( bCanCraftUp || bCanStatClockTrade )
  1754. {
  1755. pMannCoTradeSubMenu = new Menu(this, "MannCoTradeSubMenu");
  1756. pMannCoTradeSubMenu->SetBorder(scheme()->GetIScheme(GetScheme())->GetBorder(pszContextMenuBorder));
  1757. pMannCoTradeSubMenu->SetFont(scheme()->GetIScheme(GetScheme())->GetFont(pszContextMenuFont));
  1758. contextMenuBuilder.AddCascadingMenuItem("#Context_MannCoTrade", pMannCoTradeSubMenu, "customization");
  1759. if ( bCanCraftUp )
  1760. {
  1761. int nIndex = pMannCoTradeSubMenu->AddMenuItem("", new KeyValues("Command", "command", "Context_CraftUpCollection"), this);
  1762. vgui::MenuItem *pMenuItem = pMannCoTradeSubMenu->GetMenuItem(nIndex);
  1763. pMenuItem->SetText("#Context_TradeUp");
  1764. pMenuItem->InvalidateLayout(true, false);
  1765. }
  1766. if ( bCanStatClockTrade )
  1767. {
  1768. int nIndex = pMannCoTradeSubMenu->AddMenuItem("", new KeyValues("Command", "command", "Context_CraftCommonStatClock"), this);
  1769. vgui::MenuItem *pMenuItem = pMannCoTradeSubMenu->GetMenuItem(nIndex);
  1770. pMenuItem->SetText("#Context_CommonStatClock");
  1771. pMenuItem->InvalidateLayout(true, false);
  1772. }
  1773. }
  1774. // Campaign coin access trades
  1775. static CSchemaAttributeDefHandle pAttrDef_IsOperationPass( "is_operation_pass" );
  1776. if ( pItem->FindAttribute( pAttrDef_IsOperationPass ) )
  1777. {
  1778. Menu *pMannCoCoinTradeSubMenu = new Menu( this, "MannCoTradeSubMenu" );
  1779. pMannCoCoinTradeSubMenu->SetBorder( scheme()->GetIScheme( GetScheme() )->GetBorder( pszContextMenuBorder ) );
  1780. pMannCoCoinTradeSubMenu->SetFont( scheme()->GetIScheme( GetScheme() )->GetFont( pszContextMenuFont ) );
  1781. contextMenuBuilder.AddCascadingMenuItem( "#Context_MannCoTrade", pMannCoCoinTradeSubMenu, "customization" );
  1782. int nIndex = pMannCoCoinTradeSubMenu->AddMenuItem( "", new KeyValues( "Command", "command", "Context_CraftUpCollection" ), this );
  1783. vgui::MenuItem *pMenuItem = pMannCoCoinTradeSubMenu->GetMenuItem( nIndex );
  1784. pMenuItem->SetText( "#Context_TradeUp" );
  1785. pMenuItem->InvalidateLayout( true, false );
  1786. nIndex = pMannCoCoinTradeSubMenu->AddMenuItem("", new KeyValues("Command", "command", "Context_CraftCommonStatClock"), this);
  1787. pMenuItem = pMannCoCoinTradeSubMenu->GetMenuItem(nIndex);
  1788. pMenuItem->SetText("#Context_CommonStatClock");
  1789. pMenuItem->InvalidateLayout(true, false);
  1790. }
  1791. // Halloween trade up offering.
  1792. // Needs two attrs
  1793. static CSchemaAttributeDefHandle pAttrDef_HalloweenOffering( "allow_halloween_offering" );
  1794. static CSchemaAttributeDefHandle pAttrDef_DeactiveDate( "deactive date" );
  1795. // Check the date
  1796. uint32 unDeactiveDate = 0;
  1797. uint32 unCurrentDate = CRTime::RTime32TimeCur();
  1798. if ( pAttrDef_HalloweenOffering && pItem->FindAttribute( pAttrDef_HalloweenOffering ) && pItem->FindAttribute( pAttrDef_DeactiveDate, &unDeactiveDate ) && unDeactiveDate > unCurrentDate )
  1799. {
  1800. vgui::MenuItem *pMenuItem = contextMenuBuilder.AddMenuItem( "#Context_HalloweenOffering", new KeyValues( "Context_HalloweenOffering" ), "customization" );
  1801. ImagePanel *pNewImage = new ImagePanel( pMenuItem, "new" );
  1802. pNewImage->SetZPos( 100 );
  1803. pNewImage->SetWide( 40 );
  1804. pNewImage->SetTall( 40 );
  1805. pNewImage->SetPos( 220, -5 );
  1806. pNewImage->SetMouseInputEnabled( false );
  1807. pNewImage->SetShouldScaleImage( true );
  1808. pNewImage->SetImage( "new" );
  1809. }
  1810. // Change name
  1811. GameItemDefinition_t * pNameTagDef = dynamic_cast<GameItemDefinition_t*>( GEconItemSchema().GetItemDefinitionByName( "Name Tag" ) );
  1812. if ( CEconSharedToolSupport::ToolCanApplyToDefinition( dynamic_cast<const GameItemDefinition_t *>( pNameTagDef ), pItemDef ) )
  1813. {
  1814. contextMenuBuilder.AddMenuItem( "#Context_Rename", new KeyValues( "DoRename" ), "customization" );
  1815. }
  1816. // Change description
  1817. GameItemDefinition_t * pDescTagDef = dynamic_cast<GameItemDefinition_t*>( GEconItemSchema().GetItemDefinitionByName( "Description Tag" ) );
  1818. if ( CEconSharedToolSupport::ToolCanApplyToDefinition( dynamic_cast<const GameItemDefinition_t *>( pDescTagDef ), pItemDef ) )
  1819. {
  1820. contextMenuBuilder.AddMenuItem( "#Context_Description", new KeyValues( "DoDescription" ), "customization" );
  1821. }
  1822. // Add paint options sub menu
  1823. if ( m_vecPaintCans.Count() > 0 )
  1824. {
  1825. GameItemDefinition_t * pPaintCanDef = dynamic_cast<GameItemDefinition_t*>( GEconItemSchema().GetItemDefinition( m_vecPaintCans[0] ) );
  1826. if ( pPaintCanDef && CEconSharedToolSupport::ToolCanApplyToDefinition( dynamic_cast<const GameItemDefinition_t *>( pPaintCanDef ), pItemDef ) )
  1827. {
  1828. Menu *pPaintSubMenu = NULL;
  1829. pPaintSubMenu = new Menu( this, "PaintSubMenu" );
  1830. pPaintSubMenu->SetBorder( scheme()->GetIScheme( GetScheme() )->GetBorder( pszContextMenuBorder ) );
  1831. pPaintSubMenu->SetFont( scheme()->GetIScheme( GetScheme() )->GetFont( pszContextMenuFont ) );
  1832. contextMenuBuilder.AddCascadingMenuItem( "#Context_Paint", pPaintSubMenu, "customization" );
  1833. CUtlVector<item_definition_index_t> vecOwnedPaints;
  1834. CUtlVector<item_definition_index_t> vecStorePaints;
  1835. // Find out if the user owns this item or not and place in the proper bucket
  1836. CPlayerInventory *pLocalInv = TFInventoryManager()->GetLocalInventory();
  1837. FOR_EACH_VEC( m_vecPaintCans, i )
  1838. {
  1839. if ( pLocalInv && pLocalInv->FindFirstItembyItemDef( m_vecPaintCans[i] ) )
  1840. {
  1841. vecOwnedPaints.AddToTail( m_vecPaintCans[i] );
  1842. }
  1843. else
  1844. {
  1845. vecStorePaints.AddToTail( m_vecPaintCans[i] );
  1846. }
  1847. }
  1848. if ( vecOwnedPaints.Count() > 0 )
  1849. {
  1850. // Add Header and loop
  1851. int nIndex = pPaintSubMenu->AddMenuItem( "", new KeyValues( "Command", "command", "" ), this );
  1852. vgui::MenuItem *pMenuItem = pPaintSubMenu->GetMenuItem( nIndex );
  1853. pMenuItem->SetText( g_pVGuiLocalize->Find( "#TF_Owned" ) );
  1854. pMenuItem->InvalidateLayout( true, false );
  1855. FOR_EACH_VEC( vecOwnedPaints, i )
  1856. {
  1857. AddPaintToContextMenu( pPaintSubMenu, vecOwnedPaints[i], false );
  1858. }
  1859. }
  1860. pPaintSubMenu->AddSeparator();
  1861. if ( vecStorePaints.Count() > 0 )
  1862. {
  1863. // Add Header and loop
  1864. int nIndex = pPaintSubMenu->AddMenuItem( "", new KeyValues( "Command", "command", "" ), this );
  1865. vgui::MenuItem *pMenuItem = pPaintSubMenu->GetMenuItem( nIndex );
  1866. pMenuItem->SetText( g_pVGuiLocalize->Find( "#TF_Commerce" ) );
  1867. pMenuItem->InvalidateLayout( true, false );
  1868. FOR_EACH_VEC( vecStorePaints, i )
  1869. {
  1870. AddPaintToContextMenu( pPaintSubMenu, vecStorePaints[i], true );
  1871. }
  1872. }
  1873. }
  1874. }
  1875. // Strange Parts
  1876. if ( BIsItemStrange( pItem ) )
  1877. {
  1878. Menu *pStrangePartsSubMenu = NULL;
  1879. CUtlVector<item_definition_index_t> vecOwnedParts;
  1880. CUtlVector<item_definition_index_t> vecStoreParts;
  1881. // Find out if the user owns this item or not and place in the proper bucket
  1882. CPlayerInventory *pLocalInv = TFInventoryManager()->GetLocalInventory();
  1883. FOR_EACH_VEC( m_vecStrangeParts, i )
  1884. {
  1885. // Determine if this can be applied
  1886. //GameItemDefinition_t *pStrangePartDef = dynamic_cast<GameItemDefinition_t*>( GEconItemSchema().GetItemDefinition( m_vecStrangeParts[i] ) );
  1887. CEconItemView partItemView;
  1888. partItemView.Init( m_vecStrangeParts[i], AE_USE_SCRIPT_VALUE, 1 );
  1889. if ( CEconSharedToolSupport::ToolCanApplyTo( &partItemView, pItem ) )
  1890. {
  1891. // Create menu
  1892. if ( !pStrangePartsSubMenu )
  1893. {
  1894. pStrangePartsSubMenu = new Menu( this, "StrangePartsSubMenu" );
  1895. pStrangePartsSubMenu->SetBorder( scheme()->GetIScheme( GetScheme() )->GetBorder( pszContextMenuBorder ) );
  1896. pStrangePartsSubMenu->SetFont( scheme()->GetIScheme( GetScheme() )->GetFont( pszContextMenuFont ) );
  1897. contextMenuBuilder.AddCascadingMenuItem( "#Context_StrangeParts", pStrangePartsSubMenu, "customization" );
  1898. }
  1899. if ( pLocalInv && pLocalInv->FindFirstItembyItemDef( m_vecStrangeParts[i] ) )
  1900. {
  1901. vecOwnedParts.AddToTail( m_vecStrangeParts[i] );
  1902. }
  1903. else
  1904. {
  1905. vecStoreParts.AddToTail( m_vecStrangeParts[i] );
  1906. }
  1907. }
  1908. }
  1909. if ( pStrangePartsSubMenu )
  1910. {
  1911. if ( vecOwnedParts.Count() > 0 )
  1912. {
  1913. // Add Header and loop
  1914. int nIndex = pStrangePartsSubMenu->AddMenuItem( "", new KeyValues( "Command", "command", "" ), this );
  1915. vgui::MenuItem *pMenuItem = pStrangePartsSubMenu->GetMenuItem( nIndex );
  1916. pMenuItem->SetText( g_pVGuiLocalize->Find( "#TF_Owned" ) );
  1917. pMenuItem->InvalidateLayout( true, false );
  1918. FOR_EACH_VEC( vecOwnedParts, i )
  1919. {
  1920. AddCommerceToContextMenu( pStrangePartsSubMenu, "strangepart_", vecOwnedParts[i], false, false );
  1921. }
  1922. }
  1923. pStrangePartsSubMenu->AddSeparator();
  1924. if ( vecStoreParts.Count() > 0 )
  1925. {
  1926. // Add Header and loop
  1927. int nIndex = pStrangePartsSubMenu->AddMenuItem( "", new KeyValues( "Command", "command", "" ), this );
  1928. vgui::MenuItem *pMenuItem = pStrangePartsSubMenu->GetMenuItem( nIndex );
  1929. pMenuItem->SetText( g_pVGuiLocalize->Find( "#TF_Market" ) );
  1930. pMenuItem->InvalidateLayout( true, false );
  1931. FOR_EACH_VEC( vecStoreParts, i )
  1932. {
  1933. AddCommerceToContextMenu( pStrangePartsSubMenu, "strangepart_", vecStoreParts[i], true, false );
  1934. }
  1935. }
  1936. }
  1937. }
  1938. if ( pItem->IsMarketable() )
  1939. {
  1940. contextMenuBuilder.AddMenuItem( "#Context_MarketPlaceSell", new KeyValues( "DoSellMarketplace" ), "economy" );
  1941. }
  1942. // Trade to another player
  1943. if ( pItem->IsTradable() && !bSkipAddTrade )
  1944. {
  1945. contextMenuBuilder.AddMenuItem( "#Context_Trade", new KeyValues( "DoTradeToPlayer" ), "economy" );
  1946. }
  1947. if ( pItem->GetItemDefinition()->GetCapabilities() & ITEM_CAP_CAN_BE_RESTORED )
  1948. {
  1949. if ( RemovableAttributes_DoAnyAttributesApply( pItem ) )
  1950. {
  1951. contextMenuBuilder.AddMenuItem( "#RefurbishItem", new KeyValues( "Context_RefurbishItem" ), "destructive" );
  1952. }
  1953. }
  1954. }
  1955. }
  1956. else
  1957. {
  1958. // Check if ALL selected items can be crafted together
  1959. bool bCanCraftUp = true;
  1960. for( int i=0; i < COLLECTION_CRAFTING_ITEM_COUNT && i < vecSelectedItems.Count(); ++i )
  1961. {
  1962. CEconItemView* pPrevItem = ( i - 1 ) < 0 ? NULL : vecSelectedItems[ i - 1 ];
  1963. bCanCraftUp &= GetCollectionCraftingInvalidReason( vecSelectedItems[ i ], pPrevItem ) == NULL;
  1964. }
  1965. bool bCanStatClockTrade = true;
  1966. for (int i = 0; i < COLLECTION_CRAFTING_ITEM_COUNT && i < vecSelectedItems.Count(); ++i)
  1967. {
  1968. CEconItemView* pPrevItem = (i - 1) < 0 ? NULL : vecSelectedItems[i - 1];
  1969. bCanStatClockTrade &= GetCraftCommonStatClockInvalidReason(vecSelectedItems[i], pPrevItem) == NULL;
  1970. }
  1971. Menu *pMannCoTradeSubMenu = NULL;
  1972. if ( bCanCraftUp || bCanStatClockTrade )
  1973. {
  1974. pMannCoTradeSubMenu = new Menu(this, "MannCoTradeSubMenu");
  1975. pMannCoTradeSubMenu->SetBorder(scheme()->GetIScheme(GetScheme())->GetBorder(pszContextMenuBorder));
  1976. pMannCoTradeSubMenu->SetFont(scheme()->GetIScheme(GetScheme())->GetFont(pszContextMenuFont));
  1977. contextMenuBuilder.AddCascadingMenuItem("#Context_MannCoTrade", pMannCoTradeSubMenu, "customization");
  1978. if (bCanCraftUp)
  1979. {
  1980. int nIndex = pMannCoTradeSubMenu->AddMenuItem("", new KeyValues("Command", "command", "Context_CraftUpCollection"), this);
  1981. vgui::MenuItem *pMenuItem = pMannCoTradeSubMenu->GetMenuItem(nIndex);
  1982. pMenuItem->SetText("#Context_TradeUp");
  1983. pMenuItem->InvalidateLayout(true, false);
  1984. }
  1985. if (bCanStatClockTrade)
  1986. {
  1987. int nIndex = pMannCoTradeSubMenu->AddMenuItem("", new KeyValues("Command", "command", "Context_CraftCommonStatClock"), this);
  1988. vgui::MenuItem *pMenuItem = pMannCoTradeSubMenu->GetMenuItem(nIndex);
  1989. pMenuItem->SetText("#Context_CommonStatClock");
  1990. pMenuItem->InvalidateLayout(true, false);
  1991. }
  1992. }
  1993. }
  1994. if ( !m_bShowBaseItems )
  1995. {
  1996. bool bDeleteAvailable = true;
  1997. // Check that all of the selected items are deletable
  1998. for( int i=0; i < vecSelectedItems.Count() && bDeleteAvailable; ++i )
  1999. {
  2000. static CSchemaAttributeDefHandle pAttrDef_NoDelete( "cannot delete" );
  2001. bDeleteAvailable &= !vecSelectedItems[i]->FindAttribute( pAttrDef_NoDelete );
  2002. }
  2003. // Only show the delete button if every slected item is deletable
  2004. if ( bDeleteAvailable )
  2005. {
  2006. contextMenuBuilder.AddMenuItem( "#TF_SteamWorkshop_Delete", new KeyValues( "DoDelete" ), "destructive" );
  2007. }
  2008. }
  2009. // Position to the cursor's position
  2010. int nX, nY;
  2011. g_pVGuiInput->GetCursorPosition( nX, nY );
  2012. m_pContextMenu->SetPos( nX - 1, nY - 1 );
  2013. m_pContextMenu->SetVisible(true);
  2014. m_pContextMenu->AddActionSignalTarget(this);
  2015. }
  2016. //-----------------------------------------------------------------------------
  2017. // Purpose:
  2018. //-----------------------------------------------------------------------------
  2019. void CBackpackPanel::OnItemPanelMouseRightRelease( vgui::Panel *panel )
  2020. {
  2021. #ifdef STAGING_ONLY
  2022. if ( tf_use_card_tooltips.GetBool() )
  2023. {
  2024. m_pMouseOverCardPanel->PinCard( true );
  2025. }
  2026. else
  2027. #endif
  2028. {
  2029. CItemModelPanel *pItemPanel = dynamic_cast < CItemModelPanel * > ( panel );
  2030. if ( pItemPanel && pItemPanel->IsVisible() )
  2031. {
  2032. // If they're not holding down ctrl, deselect all existing selections
  2033. if ( !vgui::input()->IsKeyDown(KEY_LCONTROL) && !vgui::input()->IsKeyDown(KEY_RCONTROL) )
  2034. {
  2035. DeSelectAllBackpackItemPanels();
  2036. ToggleSelectBackpackItemPanel( pItemPanel );
  2037. }
  2038. else if ( AllowSelection() && !pItemPanel->IsGreyedOut() )
  2039. {
  2040. if ( !pItemPanel->IsSelected() && pItemPanel->HasItem() )
  2041. {
  2042. pItemPanel->SetSelected( true );
  2043. }
  2044. SetBorderForItem( pItemPanel, false );
  2045. }
  2046. OpenContextMenu();
  2047. }
  2048. }
  2049. }
  2050. void CBackpackPanel::OnMouseMismatchedRelease( MouseCode code, Panel* pPressedPanel )
  2051. {
  2052. if ( pPressedPanel )
  2053. {
  2054. OnMouseReleased( code );
  2055. }
  2056. }
  2057. //-----------------------------------------------------------------------------
  2058. // Purpose:
  2059. //-----------------------------------------------------------------------------
  2060. void CBackpackPanel::StartDrag( int x, int y )
  2061. {
  2062. // don't allow item drag if there's a filter
  2063. if ( HasNameFilter() )
  2064. return;
  2065. m_bDragging = true;
  2066. HideMouseOverPanel();
  2067. vgui::ivgui()->AddTickSignal( GetVPanel() );
  2068. m_pMouseDragItemPanel->SetItem( m_pItemDraggedFromPanel->GetItem() );
  2069. m_pMouseDragItemPanel->InvalidateLayout( true );
  2070. m_pItemDraggedFromPanel->Dragged( true );
  2071. // Calculate the mouse offset from the top left of the panel we're going to drag
  2072. m_iDragOffsetX = m_pMouseDragItemPanel->GetWide() * 0.5f;
  2073. m_iDragOffsetY = m_pMouseDragItemPanel->GetTall() * 0.5f;
  2074. m_flPreventDragPageSwitchUntil = 0;
  2075. m_pMouseDragItemPanel->SetVisible( true );
  2076. m_pItemDraggedFromPanel->SetItem( NULL );
  2077. SetBorderForItem( m_pItemDraggedFromPanel, false );
  2078. m_pPrevDragOverItemPanel = NULL;
  2079. vgui::input()->SetMouseCapture( GetVPanel() );
  2080. if ( m_pDragToNextPageButton && m_pDragToPrevPageButton )
  2081. {
  2082. m_pDragToNextPageButton->SetVisible( GetNumPages() > 1 );
  2083. m_pDragToPrevPageButton->SetVisible( GetNumPages() > 1 );
  2084. }
  2085. // play pickup sound
  2086. CEconItemView *item = m_pMouseDragItemPanel->GetItem();
  2087. if ( item )
  2088. {
  2089. const char *soundFilename = item->GetDefinitionString( "pickup_sound", "" );
  2090. if ( soundFilename[0] )
  2091. {
  2092. vgui::surface()->PlaySound( soundFilename );
  2093. }
  2094. }
  2095. }
  2096. //-----------------------------------------------------------------------------
  2097. // Purpose:
  2098. //-----------------------------------------------------------------------------
  2099. void CBackpackPanel::StopDrag( bool bSucceeded )
  2100. {
  2101. if ( !m_pItemDraggedFromPanel )
  2102. return;
  2103. if ( !bSucceeded )
  2104. {
  2105. if ( m_iDraggedFromPage == GetCurrentPage() )
  2106. {
  2107. m_pItemDraggedFromPanel->SetItem( m_pMouseDragItemPanel->GetItem() );
  2108. }
  2109. m_pItemDraggedFromPanel = NULL;
  2110. }
  2111. m_pMouseDragItemPanel->SetVisible( false );
  2112. m_bDragging = false;
  2113. vgui::input()->SetMouseCapture( NULL );
  2114. if ( m_pDragToNextPageButton && m_pDragToPrevPageButton )
  2115. {
  2116. m_pDragToNextPageButton->SetVisible( false );
  2117. m_pDragToPrevPageButton->SetVisible( false );
  2118. }
  2119. // play drop sound
  2120. CEconItemView *item = m_pMouseDragItemPanel->GetItem();
  2121. if ( item )
  2122. {
  2123. const char *soundFilename = item->GetDefinitionString( "drop_sound", "ui/item_default_drop.wav" );
  2124. vgui::surface()->PlaySound( soundFilename );
  2125. }
  2126. }
  2127. //-----------------------------------------------------------------------------
  2128. // Purpose:
  2129. //-----------------------------------------------------------------------------
  2130. int CBackpackPanel::GetBackpackPositionForPanel( CItemModelPanel *pItemPanel )
  2131. {
  2132. for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
  2133. {
  2134. if ( m_pItemModelPanels[i] == pItemPanel )
  2135. return i;
  2136. }
  2137. return -1;
  2138. }
  2139. //-----------------------------------------------------------------------------
  2140. // Purpose:
  2141. //-----------------------------------------------------------------------------
  2142. void CBackpackPanel::HandleDragTo( CItemModelPanel *pItemPanel, int iPanelIndex )
  2143. {
  2144. // Find the position based on the panel we're dragging to
  2145. if ( iPanelIndex != -1 )
  2146. {
  2147. // If the current panel is selected, unselect it
  2148. if ( m_pItemModelPanels[iPanelIndex]->IsSelected() )
  2149. {
  2150. ToggleSelectBackpackItemPanel( m_pItemModelPanels[iPanelIndex] );
  2151. }
  2152. if ( m_pItemDraggedFromPanel->IsSelected() )
  2153. {
  2154. ToggleSelectBackpackItemPanel( m_pItemDraggedFromPanel );
  2155. }
  2156. // We "move" the items in the backpack immediately, because when the messages come back
  2157. // from steam they'll fix the positions if the move fails for some reason.
  2158. CEconItemView *pItem = NULL;
  2159. if ( m_pItemModelPanels[iPanelIndex]->HasItem() )
  2160. {
  2161. // We need to copy it because it's about to get stomped by the other item
  2162. pItem = new CEconItemView( *m_pItemModelPanels[iPanelIndex]->GetItem() );
  2163. }
  2164. m_pItemModelPanels[iPanelIndex]->SetItem( m_pMouseDragItemPanel->GetItem() );
  2165. if ( m_iDraggedFromPage == GetCurrentPage() )
  2166. {
  2167. m_pItemDraggedFromPanel->SetItem( pItem );
  2168. }
  2169. if ( pItem )
  2170. {
  2171. delete pItem;
  2172. }
  2173. // Tell the inventory to move the item
  2174. // Translate it to the right page
  2175. int iBackpackPosition = GetBackpackPosForPanelIndex( iPanelIndex );
  2176. InventoryManager()->MoveItemToBackpackPosition( m_pMouseDragItemPanel->GetItem(), iBackpackPosition );
  2177. }
  2178. }
  2179. //-----------------------------------------------------------------------------
  2180. // Purpose:
  2181. //-----------------------------------------------------------------------------
  2182. void CBackpackPanel::OnTick( void )
  2183. {
  2184. BaseClass::OnTick();
  2185. bool bNeedsTick = false;
  2186. if ( m_flStartExplanationsAt && m_flStartExplanationsAt < Plat_FloatTime() )
  2187. {
  2188. m_flStartExplanationsAt = 0;
  2189. if ( ShouldShowExplanations() )
  2190. {
  2191. ConVar *pConVar = GetExplanationConVar();
  2192. if ( pConVar )
  2193. {
  2194. pConVar->SetValue( 1 );
  2195. }
  2196. CExplanationPopup *pPopup = dynamic_cast<CExplanationPopup*>( FindChildByName("StartExplanation") );
  2197. if ( pPopup )
  2198. {
  2199. pPopup->Popup();
  2200. }
  2201. }
  2202. }
  2203. else
  2204. {
  2205. bNeedsTick = true;
  2206. }
  2207. // To handle page movement while holding the mouse still over the page buttons,
  2208. // we need to keep calling OnCursorMoved() whenever we're dragging.
  2209. if ( m_bDragging && m_pMouseDragItemPanel && m_pItemDraggedFromPanel && IsVisible() )
  2210. {
  2211. int mx,my;
  2212. vgui::input()->GetCursorPos( mx, my );
  2213. ScreenToLocal( mx, my );
  2214. OnCursorMoved( mx,my );
  2215. bNeedsTick = true;
  2216. }
  2217. if ( !bNeedsTick && !NeedsDerivedTickSignal() )
  2218. {
  2219. vgui::ivgui()->RemoveTickSignal( GetVPanel() );
  2220. }
  2221. }
  2222. //-----------------------------------------------------------------------------
  2223. // Purpose:
  2224. //-----------------------------------------------------------------------------
  2225. void CBackpackPanel::OnThink( void )
  2226. {
  2227. BaseClass::OnThink();
  2228. if ( m_flFilterItemTime > 0 && gpGlobals->curtime >= m_flFilterItemTime )
  2229. {
  2230. SetCurrentPage( 0 );
  2231. DeSelectAllBackpackItemPanels();
  2232. UpdateModelPanels();
  2233. m_flFilterItemTime = 0.0f;
  2234. }
  2235. }
  2236. //-----------------------------------------------------------------------------
  2237. // Purpose:
  2238. //-----------------------------------------------------------------------------
  2239. void CBackpackPanel::OnCursorMoved( int x, int y )
  2240. {
  2241. if ( !m_pItemDraggedFromPanel )
  2242. return;
  2243. if ( m_bDragging && m_pMouseDragItemPanel )
  2244. {
  2245. m_pMouseDragItemPanel->SetPos( x - m_iDragOffsetX, y - m_iDragOffsetY );
  2246. // When we're dragging, we have mouse capture, so the item panels aren't getting mouse input.
  2247. // We need to find out what item panel we're over, and let it know.
  2248. if ( m_flPreventDragPageSwitchUntil < Plat_FloatTime() )
  2249. {
  2250. // First, are we over the page turning areas?
  2251. bool bDragNext = false;
  2252. if ( m_pDragToNextPageButton && m_pDragToNextPageButton->IsVisible() )
  2253. {
  2254. int iDragX, iDragY;
  2255. m_pDragToNextPageButton->GetPos( iDragX, iDragY );
  2256. bDragNext = ( x >= iDragX && x <= (iDragX + m_pDragToNextPageButton->GetWide() ) );
  2257. }
  2258. if ( !bDragNext && m_pNextPageButton && m_pNextPageButton->IsEnabled() )
  2259. {
  2260. int iDragX, iDragY;
  2261. m_pNextPageButton->GetPos( iDragX, iDragY );
  2262. bDragNext = ( x >= iDragX && x <= (iDragX + m_pNextPageButton->GetWide()) && y >= iDragY && y <= (iDragY + m_pNextPageButton->GetTall()) );
  2263. }
  2264. if ( bDragNext )
  2265. {
  2266. OnCommand( "nextpage" );
  2267. m_flPreventDragPageSwitchUntil = Plat_FloatTime() + tf_backpack_page_button_delay.GetFloat();
  2268. return;
  2269. }
  2270. bool bDragPrev = false;
  2271. if ( m_pDragToPrevPageButton && m_pDragToPrevPageButton->IsVisible() )
  2272. {
  2273. int iDragX, iDragY;
  2274. m_pDragToPrevPageButton->GetPos( iDragX, iDragY );
  2275. bDragPrev = ( x >= iDragX && x <= (iDragX + m_pDragToPrevPageButton->GetWide() ) );
  2276. }
  2277. if ( !bDragPrev && m_pPrevPageButton && m_pPrevPageButton->IsEnabled() )
  2278. {
  2279. int iDragX, iDragY;
  2280. m_pPrevPageButton->GetPos( iDragX, iDragY );
  2281. bDragPrev = ( x >= iDragX && x <= (iDragX + m_pPrevPageButton->GetWide()) && y >= iDragY && y <= (iDragY + m_pPrevPageButton->GetTall()) );
  2282. }
  2283. if ( bDragPrev )
  2284. {
  2285. OnCommand( "prevpage" );
  2286. m_flPreventDragPageSwitchUntil = Plat_FloatTime() + tf_backpack_page_button_delay.GetFloat();
  2287. return;
  2288. }
  2289. }
  2290. // check if we're hovering page button
  2291. static int iPrevHoveringPage = -1;
  2292. static float flLastPageButtonEnterTime = 0.f;
  2293. int iHoveringPage = GetPageButtonIndexAtPos( x, y );
  2294. if ( iHoveringPage != -1 )
  2295. {
  2296. if ( iHoveringPage == GetCurrentPage() )
  2297. {
  2298. iPrevHoveringPage = -1;
  2299. flLastPageButtonEnterTime = 0.f;
  2300. }
  2301. else if ( iPrevHoveringPage != iHoveringPage )
  2302. {
  2303. iPrevHoveringPage = iHoveringPage;
  2304. flLastPageButtonEnterTime = Plat_FloatTime() + tf_backpack_page_button_delay.GetFloat();
  2305. }
  2306. else if ( flLastPageButtonEnterTime > 0 && flLastPageButtonEnterTime < Plat_FloatTime() )
  2307. {
  2308. flLastPageButtonEnterTime = 0.f;
  2309. SetCurrentPage( iHoveringPage );
  2310. UpdateModelPanels();
  2311. }
  2312. return;
  2313. }
  2314. else
  2315. {
  2316. // reset hovering page buttons data
  2317. iPrevHoveringPage = -1;
  2318. flLastPageButtonEnterTime = 0.f;
  2319. }
  2320. CItemModelPanel *pOverPanel = GetItemPanelAtPos( x, y );
  2321. if ( m_pPrevDragOverItemPanel != pOverPanel )
  2322. {
  2323. if ( m_pPrevDragOverItemPanel )
  2324. {
  2325. OnItemPanelExited( m_pPrevDragOverItemPanel );
  2326. }
  2327. m_pPrevDragOverItemPanel = pOverPanel;
  2328. if ( m_pPrevDragOverItemPanel )
  2329. {
  2330. OnItemPanelEntered( m_pPrevDragOverItemPanel );
  2331. }
  2332. }
  2333. }
  2334. }
  2335. //-----------------------------------------------------------------------------
  2336. // Purpose:
  2337. //-----------------------------------------------------------------------------
  2338. void CBackpackPanel::OnItemPanelCursorMoved( int x, int y )
  2339. {
  2340. if ( !m_pItemDraggedFromPanel )
  2341. return;
  2342. if ( !m_bDragging && m_pItemDraggedFromPanel->HasItem() && !InToolSelectionMode() )
  2343. {
  2344. // Don't drag instantly, so it's easy to select
  2345. if ( (gpGlobals->curtime - m_flMouseDownTime) > 0.3 )
  2346. {
  2347. StartDrag( x,y );
  2348. }
  2349. else
  2350. {
  2351. if ( !m_iMouseDownX )
  2352. {
  2353. m_iMouseDownX = x;
  2354. m_iMouseDownY = y;
  2355. }
  2356. else if ( abs(m_iMouseDownX - x) > XRES(10) || abs(m_iMouseDownY - y) > YRES(10) )
  2357. {
  2358. StartDrag( x,y );
  2359. }
  2360. }
  2361. }
  2362. OnCursorMoved( x, y );
  2363. }
  2364. //-----------------------------------------------------------------------------
  2365. // Purpose:
  2366. //-----------------------------------------------------------------------------
  2367. void CBackpackPanel::ToggleSelectBackpackItemPanel( CItemModelPanel *pPanel )
  2368. {
  2369. if ( !AllowSelection() || pPanel->IsGreyedOut() )
  2370. return;
  2371. if ( pPanel->IsSelected() || !pPanel->HasItem() )
  2372. {
  2373. pPanel->SetSelected( false );
  2374. }
  2375. else
  2376. {
  2377. pPanel->SetSelected( true );
  2378. }
  2379. SetBorderForItem( pPanel, false );
  2380. }
  2381. //-----------------------------------------------------------------------------
  2382. // Purpose:
  2383. //-----------------------------------------------------------------------------
  2384. void CBackpackPanel::DeSelectAllBackpackItemPanels( void )
  2385. {
  2386. for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
  2387. {
  2388. if ( m_pItemModelPanels[i]->IsSelected() )
  2389. {
  2390. m_pItemModelPanels[i]->SetSelected( false );
  2391. SetBorderForItem( m_pItemModelPanels[i], false );
  2392. }
  2393. }
  2394. }
  2395. //-----------------------------------------------------------------------------
  2396. // Purpose: Called whenever the selection changes in the item loadout panel
  2397. //-----------------------------------------------------------------------------
  2398. void CBackpackPanel::OnItemContentsChanged( CEconItemView *pEconItemView )
  2399. {
  2400. Assert( pEconItemView );
  2401. for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
  2402. {
  2403. CEconItemView *pInternalItem = m_pItemModelPanels[i] && m_pItemModelPanels[i]->HasItem()
  2404. ? m_pItemModelPanels[i]->GetItem()
  2405. : NULL;
  2406. if ( *pInternalItem == *pEconItemView )
  2407. {
  2408. m_pItemModelPanels[i]->DirtyDescription();
  2409. OnItemSelectionChanged();
  2410. return;
  2411. }
  2412. }
  2413. }
  2414. //-----------------------------------------------------------------------------
  2415. // Purpose: Called when text changes in combo box
  2416. //-----------------------------------------------------------------------------
  2417. void CBackpackPanel::OnTextChanged( KeyValues *data )
  2418. {
  2419. Panel *pPanel = reinterpret_cast<vgui::Panel *>( data->GetPtr("panel") );
  2420. vgui::TextEntry *pTextEntry = dynamic_cast<vgui::TextEntry *>( pPanel );
  2421. if ( pTextEntry )
  2422. {
  2423. if ( pTextEntry == m_pNameFilterTextEntry )
  2424. {
  2425. m_wNameFilter.RemoveAll();
  2426. if ( m_pNameFilterTextEntry->GetTextLength() )
  2427. {
  2428. m_wNameFilter.EnsureCount( m_pNameFilterTextEntry->GetTextLength() + 1 );
  2429. m_pNameFilterTextEntry->GetText( m_wNameFilter.Base(), m_wNameFilter.Count() * sizeof(wchar_t) );
  2430. V_wcslower( m_wNameFilter.Base() );
  2431. }
  2432. m_flFilterItemTime = gpGlobals->curtime + 0.5f;
  2433. return;
  2434. }
  2435. }
  2436. vgui::ComboBox *pComboBox = dynamic_cast<vgui::ComboBox *>( pPanel );
  2437. if ( pComboBox )
  2438. {
  2439. if ( pComboBox == m_pSortByComboBox )
  2440. {
  2441. // the class selection combo box changed, update class details
  2442. KeyValues *pUserData = m_pSortByComboBox->GetActiveItemUserData();
  2443. if ( !pUserData )
  2444. return;
  2445. enum { kSortType_Dummy = -1 };
  2446. int iSortTypeSelectionIndex = pUserData->GetInt( "sortby", kSortType_Dummy );
  2447. if ( iSortTypeSelectionIndex != kSortType_Dummy )
  2448. {
  2449. uint32 iSortType = g_BackpackSortTypes[iSortTypeSelectionIndex].iSortType;
  2450. if ( iSortType != kGCItemSort_NoSort )
  2451. {
  2452. InventoryManager()->SortBackpackBy( iSortType );
  2453. // Now go back to the "Sort by" header, and move the focus to the close button.
  2454. m_pSortByComboBox->ActivateItemByRow( 0 );
  2455. }
  2456. }
  2457. }
  2458. else if ( pComboBox == m_pShowRarityComboBox )
  2459. {
  2460. cl_showbackpackrarities.SetValue( m_pShowRarityComboBox->GetActiveItem() );
  2461. // Refresh all item borders
  2462. for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
  2463. {
  2464. SetBorderForItem( m_pItemModelPanels[i], false );
  2465. }
  2466. }
  2467. }
  2468. }
  2469. //-----------------------------------------------------------------------------
  2470. // Purpose:
  2471. //-----------------------------------------------------------------------------
  2472. void CBackpackPanel::OnButtonChecked( KeyValues *pData )
  2473. {
  2474. Panel *pPanel = reinterpret_cast<vgui::Panel *>( pData->GetPtr("panel") );
  2475. if ( m_bShowBaseItems != m_pShowBaseItemsCheckbox->IsSelected() && m_pShowBaseItemsCheckbox == pPanel && IsVisible() )
  2476. {
  2477. SetShowBaseItems( m_pShowBaseItemsCheckbox->IsSelected() );
  2478. }
  2479. }
  2480. //-----------------------------------------------------------------------------
  2481. // Purpose:
  2482. //-----------------------------------------------------------------------------
  2483. void CBackpackPanel::OnCancelSelection( void )
  2484. {
  2485. if ( m_pConfirmDeleteDialog )
  2486. {
  2487. m_pConfirmDeleteDialog->MarkForDeletion();
  2488. m_pConfirmDeleteDialog = NULL;
  2489. }
  2490. }
  2491. //-----------------------------------------------------------------------------
  2492. // Purpose:
  2493. //-----------------------------------------------------------------------------
  2494. const char *CBackpackPanel::GetGreyOutItemPanelReason( CItemModelPanel *pItemPanel )
  2495. {
  2496. if ( InToolSelectionMode() )
  2497. {
  2498. bool bIsSelectedTool = (m_ToolSelectionItem.IsValid() && pItemPanel->HasItem()) ? (m_ToolSelectionItem == *pItemPanel->GetItem()) : false;
  2499. if ( !bIsSelectedTool )
  2500. {
  2501. if ( m_ToolSelectionItem.GetStaticData()->IsTool() )
  2502. {
  2503. if ( !CEconSharedToolSupport::ToolCanApplyTo( &m_ToolSelectionItem, pItemPanel->GetItem() ) )
  2504. {
  2505. return "#Econ_GreyOutReason_ToolCannotApply";
  2506. }
  2507. }
  2508. else if ( pItemPanel->GetItem() && pItemPanel->GetItem()->GetStaticData()->IsTool() )
  2509. {
  2510. if ( !CEconSharedToolSupport::ToolCanApplyTo( pItemPanel->GetItem(), &m_ToolSelectionItem ) )
  2511. {
  2512. return "#Econ_GreyOutReason_ToolCannotApply";
  2513. }
  2514. }
  2515. }
  2516. }
  2517. return NULL;
  2518. }
  2519. //-----------------------------------------------------------------------------
  2520. // Purpose:
  2521. //-----------------------------------------------------------------------------
  2522. void CBackpackPanel::SetBorderForItem( CItemModelPanel *pItemPanel, bool bMouseOver )
  2523. {
  2524. tmZone( TELEMETRY_LEVEL1, TMZF_NONE, "%s", __FUNCTION__ );
  2525. if ( !pItemPanel )
  2526. return;
  2527. const char *pszBorder = NULL;
  2528. bool bIsSelectedTool = (m_ToolSelectionItem.IsValid() && pItemPanel->HasItem()) ? (m_ToolSelectionItem == *pItemPanel->GetItem()) : false;
  2529. // Handle grey out
  2530. const char *pszGreyOutReason = GetGreyOutItemPanelReason( pItemPanel );
  2531. const bool bGreyOut = pszGreyOutReason != NULL;
  2532. pItemPanel->SetGreyedOut( pszGreyOutReason );
  2533. int iRarity = GetItemQualityForBorder( pItemPanel );
  2534. if ( InToolSelectionMode() && bIsSelectedTool )
  2535. {
  2536. // We're in tool application mode, and this panel is the tool being used
  2537. pszBorder = "BackpackItemBorder_SelfMade";
  2538. if ( m_pToolIcon )
  2539. {
  2540. int iX, iY;
  2541. pItemPanel->GetPos( iX, iY );
  2542. m_pToolIcon->SetPos( iX, iY );
  2543. m_pToolIcon->SetVisible( true );
  2544. }
  2545. }
  2546. else if ( bGreyOut )
  2547. {
  2548. if( pItemPanel->IsSelected() )
  2549. {
  2550. pszBorder = g_szItemBorders[iRarity][4];
  2551. }
  2552. else
  2553. {
  2554. pszBorder = g_szItemBorders[iRarity][3];
  2555. }
  2556. }
  2557. else
  2558. {
  2559. if ( pItemPanel->IsSelected() )
  2560. {
  2561. pszBorder = g_szItemBorders[iRarity][2];
  2562. }
  2563. else if ( bMouseOver )
  2564. {
  2565. pszBorder = g_szItemBorders[iRarity][1];
  2566. }
  2567. else
  2568. {
  2569. pszBorder = g_szItemBorders[iRarity][0];
  2570. }
  2571. }
  2572. vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( GetScheme() );
  2573. pItemPanel->SetBorder( pScheme->GetBorder( pszBorder ) );
  2574. }
  2575. //-----------------------------------------------------------------------------
  2576. class CTFRemoveItemCustomizationConfirmDialog : public CTFGenericConfirmDialog
  2577. {
  2578. DECLARE_CLASS_SIMPLE( CTFRemoveItemCustomizationConfirmDialog, CTFGenericConfirmDialog );
  2579. public:
  2580. CTFRemoveItemCustomizationConfirmDialog( const RefurbishableProperty& prop, CEconItemView *pItem )
  2581. : CTFGenericConfirmDialog( prop.m_szDialogTitle, // dialog title
  2582. prop.m_szDialogDesc, // dialog text
  2583. "#RefurbishItem_Yes", // confirm button text
  2584. "#RefurbishItem_No", // cancel button text
  2585. NULL, // callback
  2586. NULL ) // parent
  2587. , m_prop( prop )
  2588. , m_Item( *pItem ) // copy in case our UI changes behind us
  2589. {
  2590. GetCustomDialogLocalizationTokenFunc_t m_pDialogCustomTokenFunc = m_prop.m_pGetCustomDialogLocalizationTokenFunc;
  2591. if ( m_pDialogCustomTokenFunc )
  2592. {
  2593. CUtlConstWideString wsDialogCustomToken;
  2594. (*m_pDialogCustomTokenFunc)( &m_Item, m_prop.m_iUserData, wsDialogCustomToken );
  2595. if ( !wsDialogCustomToken.IsEmpty() )
  2596. {
  2597. AddStringToken( "confirm_dialog_token", wsDialogCustomToken.Get() );
  2598. }
  2599. }
  2600. }
  2601. virtual ~CTFRemoveItemCustomizationConfirmDialog() { }
  2602. virtual void OnCommand( const char *command );
  2603. private:
  2604. RefurbishableProperty m_prop;
  2605. CEconItemView m_Item;
  2606. };
  2607. //-----------------------------------------------------------------------------
  2608. // Purpose:
  2609. //-----------------------------------------------------------------------------
  2610. void SendGCSimpleAttributeRemovalMessage( CEconItemView *pEconItemView, const char *szDesc, EGCItemMsg eItemMsg )
  2611. {
  2612. EconUI()->Gamestats_ItemTransaction( IE_ITEM_REMOVED_ATTRIB, pEconItemView, szDesc );
  2613. GCSDK::CProtoBufMsg<CMsgGCRemoveCustomizationAttributeSimple> msg( eItemMsg );
  2614. msg.Body().set_item_id( pEconItemView->GetItemID() );
  2615. GCClientSystem()->BSendMessage( msg );
  2616. }
  2617. void CTFRemoveItemCustomizationConfirmDialog::OnCommand( const char *command )
  2618. {
  2619. BaseClass::OnCommand( command );
  2620. // Did the user say "yes, remove this particular attribute"? If so, notify the GC. We can't
  2621. // remove multiple attributes at a time because each removal will cause a new item to be created,
  2622. // invalidating the item reference we've got in this dialog.
  2623. if ( !Q_strnicmp( command, "confirm", 7 ) )
  2624. {
  2625. // remove the attribute
  2626. switch( m_prop.m_eRemovalType )
  2627. {
  2628. case kCustomizationRemove_Paint:
  2629. SendGCSimpleAttributeRemovalMessage( &m_Item, "paint", k_EMsgGCRemoveItemPaint );
  2630. break;
  2631. case kCustomizationRemove_Name:
  2632. {
  2633. EconUI()->Gamestats_ItemTransaction( IE_ITEM_REMOVED_ATTRIB, &m_Item, "name" );
  2634. GCSDK::CGCMsg< MsgGCRemoveItemName_t > msg( k_EMsgGCRemoveItemName );
  2635. msg.Body().m_unItemID = m_Item.GetItemID();
  2636. msg.Body().m_bDescription = false;
  2637. GCClientSystem()->BSendMessage( msg );
  2638. }
  2639. break;
  2640. case kCustomizationRemove_Desc:
  2641. {
  2642. EconUI()->Gamestats_ItemTransaction( IE_ITEM_REMOVED_ATTRIB, &m_Item, "description" );
  2643. GCSDK::CGCMsg< MsgGCRemoveItemName_t > msg( k_EMsgGCRemoveItemName );
  2644. msg.Body().m_unItemID = m_Item.GetItemID();
  2645. msg.Body().m_bDescription = true;
  2646. GCClientSystem()->BSendMessage( msg );
  2647. }
  2648. break;
  2649. case kCustomizationRemove_CustomTexture:
  2650. SendGCSimpleAttributeRemovalMessage( &m_Item, "custom_texture", k_EMsgGCRemoveCustomTexture );
  2651. break;
  2652. case kCustomizationRemove_MakersMark:
  2653. SendGCSimpleAttributeRemovalMessage( &m_Item, "makers_mark", k_EMsgGCRemoveMakersMark );
  2654. break;
  2655. case kCustomizationRemove_StrangePart:
  2656. {
  2657. Assert( m_prop.m_iUserData != kNoUserData );
  2658. int iKillEaterAttrIndex = m_prop.m_iUserData;
  2659. // What attribute did we select?
  2660. const CEconItemAttributeDefinition *pAttrDef = GetKillEaterAttr_Type( iKillEaterAttrIndex );
  2661. Assert( pAttrDef );
  2662. // Make sure this item has this attribute.
  2663. float fScoreType = kKillEaterEvent_PlayerKill;
  2664. Verify( FindAttribute_UnsafeBitwiseCast<attrib_value_t>( &m_Item, pAttrDef, &fScoreType ) || iKillEaterAttrIndex == 0 );
  2665. // Dispatch message.
  2666. EconUI()->Gamestats_ItemTransaction( IE_ITEM_REMOVED_ATTRIB, &m_Item, "strange_part" );
  2667. GCSDK::CProtoBufMsg<CMsgGCRemoveStrangePart> msg( k_EMsgGCRemoveStrangePart );
  2668. msg.Body().set_item_id( m_Item.GetItemID() );
  2669. msg.Body().set_strange_part_score_type( (int)fScoreType );
  2670. GCClientSystem()->BSendMessage( msg );
  2671. }
  2672. break;
  2673. case kCustomizationRemove_StrangeScores:
  2674. {
  2675. Assert( m_prop.m_iUserData == kNoUserData );
  2676. EconUI()->Gamestats_ItemTransaction( IE_ITEM_RESET_STRANGE_COUNTERS, &m_Item );
  2677. GCSDK::CProtoBufMsg<CMsgGCResetStrangeScores> msg( k_EMsgGCResetStrangeScores );
  2678. msg.Body().set_item_id( m_Item.GetItemID() );
  2679. GCClientSystem()->BSendMessage( msg );
  2680. }
  2681. break;
  2682. case kCustomizationRemove_UpgradeCard:
  2683. {
  2684. Assert( m_prop.m_iUserData != kNoUserData );
  2685. // Make sure we selected a valid attribute that this item has.
  2686. const CEconItemAttributeDefinition *pAttrDef = GetCardUpgradeForIndex( &m_Item, m_prop.m_iUserData );
  2687. Assert( pAttrDef );
  2688. Verify( m_Item.FindAttribute( pAttrDef ) );
  2689. // Dispatch message.
  2690. EconUI()->Gamestats_ItemTransaction( IE_ITEM_REMOVED_ATTRIB, &m_Item, "upgrade_card" );
  2691. GCSDK::CProtoBufMsg<CMsgGCRemoveUpgradeCard> msg( k_EMsgGCRemoveUpgradeCard );
  2692. msg.Body().set_item_id( m_Item.GetItemID() );
  2693. msg.Body().set_attribute_index( pAttrDef->GetDefinitionIndex() );
  2694. GCClientSystem()->BSendMessage( msg );
  2695. }
  2696. break;
  2697. case kCustomizationRemove_KillStreak:
  2698. SendGCSimpleAttributeRemovalMessage( &m_Item, "killstreak", k_EMsgGCRemoveKillStreak );
  2699. break;
  2700. case kCustomizationRemove_GiftedBy:
  2701. SendGCSimpleAttributeRemovalMessage( &m_Item, "giftedby", k_EMsgGCRemoveGiftedBy );
  2702. break;
  2703. case kCustomizationRemove_Festivizer:
  2704. SendGCSimpleAttributeRemovalMessage( &m_Item, "festivizer", k_EMsgGCRemoveFestivizer );
  2705. break;
  2706. default:
  2707. AssertMsg( false, "Unknown item customization removal type!" );
  2708. break;
  2709. }
  2710. }
  2711. SetVisible( false );
  2712. MarkForDeletion();
  2713. }
  2714. //-----------------------------------------------------------------------------
  2715. // Purpose:
  2716. //-----------------------------------------------------------------------------
  2717. class CRefurbishItemDialog : public CComboBoxBackpackOverlayDialogBase
  2718. {
  2719. public:
  2720. DECLARE_CLASS_SIMPLE( CRefurbishItemDialog, CComboBoxBackpackOverlayDialogBase );
  2721. public:
  2722. CRefurbishItemDialog( vgui::Panel *pParent, CEconItemView *m_pItem ) : CComboBoxBackpackOverlayDialogBase( pParent, m_pItem ) { }
  2723. private:
  2724. virtual void PopulateComboBoxOptions()
  2725. {
  2726. Assert( m_pItem );
  2727. KeyValues *pKeyValues = new KeyValues( "data" );
  2728. for ( int i = 0; i < GetRemovableAttributesCount(); i++ )
  2729. {
  2730. if ( RemovableAttributes_DoesAttributeApply( i, m_pItem ) )
  2731. {
  2732. pKeyValues->SetInt( "data", i );
  2733. RefurbishableProperty prop = RemovableAttributes_GetAttributeDetails( i );
  2734. CUtlConstWideString wsDialogCustomToken;
  2735. if ( prop.m_pGetCustomDialogLocalizationTokenFunc )
  2736. {
  2737. (*prop.m_pGetCustomDialogLocalizationTokenFunc)( m_pItem, prop.m_iUserData, wsDialogCustomToken );
  2738. }
  2739. CConstructLocalizedString localizedUI( GLocalizationProvider()->Find( prop.m_pszSelectionUILocalizationToken ), wsDialogCustomToken.IsEmpty() ? L"" : wsDialogCustomToken.Get() );
  2740. GetComboBox()->AddItem( localizedUI, pKeyValues );
  2741. }
  2742. }
  2743. pKeyValues->deleteThis();
  2744. Assert( GetComboBox()->GetItemCount() > 0 );
  2745. GetComboBox()->ActivateItemByRow( 0 );
  2746. }
  2747. virtual void OnComboBoxApplication()
  2748. {
  2749. if ( !m_pItem )
  2750. return;
  2751. KeyValues *pKVActiveUserData = GetComboBox()->GetActiveItemUserData();
  2752. int iIndex = pKVActiveUserData ? pKVActiveUserData->GetInt( "data", -1 ) : -1;
  2753. if ( iIndex < 0 )
  2754. return;
  2755. const RefurbishableProperty RefurbProp = RemovableAttributes_GetAttributeDetails( iIndex );
  2756. CTFRemoveItemCustomizationConfirmDialog *pDialog = new CTFRemoveItemCustomizationConfirmDialog( RefurbProp, m_pItem );
  2757. if ( pDialog )
  2758. {
  2759. pDialog->Show();
  2760. }
  2761. }
  2762. virtual const char *GetTitleLabelLocalizationToken() const { return "#TF_Item_RefurbishItemHeader"; }
  2763. };
  2764. //-----------------------------------------------------------------------------
  2765. // Purpose: Handles item selection while in tool selection mode
  2766. //-----------------------------------------------------------------------------
  2767. void CBackpackPanel::HandleToolItemSelection( CEconItemView *pItem )
  2768. {
  2769. if ( !InToolSelectionMode() )
  2770. {
  2771. // must be in tool selection mode
  2772. Assert( InToolSelectionMode() );
  2773. return;
  2774. }
  2775. if ( pItem )
  2776. {
  2777. // Check if we should bring up the shuffle dialog instead of directly using the tool
  2778. static CSchemaAttributeDefHandle pAttrDef_CanShuffleCrateContents( "can shuffle crate contents" );
  2779. if ( pItem->FindAttribute( pAttrDef_CanShuffleCrateContents ) )
  2780. {
  2781. CInputStringForItemBackpackOverlayDialog *pDialog = vgui::SETUP_PANEL( new CInputStringForItemBackpackOverlayDialog( this, pItem, &m_ToolSelectionItem ) );
  2782. if ( pDialog )
  2783. {
  2784. pDialog->Show();
  2785. CancelToolSelection();
  2786. }
  2787. }
  2788. else if ( m_ToolSelectionItem.FindAttribute( pAttrDef_CanShuffleCrateContents ) )
  2789. {
  2790. CInputStringForItemBackpackOverlayDialog *pDialog = vgui::SETUP_PANEL( new CInputStringForItemBackpackOverlayDialog( this, &m_ToolSelectionItem, pItem ) );
  2791. if ( pDialog )
  2792. {
  2793. pDialog->Show();
  2794. CancelToolSelection();
  2795. }
  2796. }
  2797. // is a tool being applied onto this item
  2798. else if ( m_ToolSelectionItem.GetStaticData()->IsTool() && ApplyTool( this, &m_ToolSelectionItem, pItem ) )
  2799. {
  2800. CancelToolSelection();
  2801. UpdateModelPanels();
  2802. }
  2803. // is this item a tool that can be applied on a selected item
  2804. else if ( pItem->GetStaticData()->IsTool() && ApplyTool( this, pItem, &m_ToolSelectionItem ) )
  2805. {
  2806. CancelToolSelection();
  2807. UpdateModelPanels();
  2808. }
  2809. }
  2810. }
  2811. //-----------------------------------------------------------------------------
  2812. // Purpose: Tries to use the item. This might switch the panel to a tool item
  2813. // selection mode, or launch the recipe crafting panel.
  2814. //-----------------------------------------------------------------------------
  2815. void CBackpackPanel::SetupToolSelectionItem()
  2816. {
  2817. for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
  2818. {
  2819. if ( m_pItemModelPanels[i]->IsSelected() && m_pItemModelPanels[i]->HasItem() )
  2820. {
  2821. m_ToolSelectionItem = *m_pItemModelPanels[i]->GetItem();
  2822. break;
  2823. }
  2824. }
  2825. }
  2826. //-----------------------------------------------------------------------------
  2827. // Purpose: Open up the trade dialog
  2828. //-----------------------------------------------------------------------------
  2829. void CBackpackPanel::DoTradeToPlayer()
  2830. {
  2831. OpenTradingStartDialog( this );
  2832. }
  2833. //-----------------------------------------------------------------------------
  2834. // Purpose: Use the trade dialog to send a gift to a player.
  2835. //-----------------------------------------------------------------------------
  2836. void CBackpackPanel::DoGiftToPlayer()
  2837. {
  2838. OpenTradingStartDialog( this, &m_ToolSelectionItem );
  2839. }
  2840. //-----------------------------------------------------------------------------
  2841. // Purpose: Open up the overlay to sell the selected item
  2842. //-----------------------------------------------------------------------------
  2843. void CBackpackPanel::DoSellMarketplace()
  2844. {
  2845. CUtlVector< CItemModelPanel* > m_vecSelected;
  2846. GetSelectedPanels( SELECT_FIRST, m_vecSelected );
  2847. Assert( m_vecSelected.Count() );
  2848. if( !m_vecSelected.Count() )
  2849. return;
  2850. if ( m_vecSelected.Count() && steamapicontext && steamapicontext->SteamFriends() && steamapicontext->SteamUtils() )
  2851. {
  2852. CEconItemView *pItem = m_vecSelected.Head()->GetItem();
  2853. const char *pszPrefix = "";
  2854. if ( GetUniverse() == k_EUniverseBeta )
  2855. {
  2856. pszPrefix = "beta.";
  2857. }
  2858. uint32 nAssetContext = 2; // k_EEconContextBackpack
  2859. char szURL[512];
  2860. V_snprintf( szURL, sizeof(szURL), "http://%ssteamcommunity.com/my/inventory/?sellOnLoad=1#%d_%d_%llu", pszPrefix, engine->GetAppID(), nAssetContext, pItem->GetItemID() );
  2861. steamapicontext->SteamFriends()->ActivateGameOverlayToWebPage( szURL );
  2862. }
  2863. }
  2864. //-----------------------------------------------------------------------------
  2865. // Purpose: Use a description tag, or offer to buy one
  2866. //-----------------------------------------------------------------------------
  2867. void CBackpackPanel::DoDescription()
  2868. {
  2869. static CSchemaItemDefHandle pItemDef_DescTag( "Description Tag" );
  2870. if ( !AttemptToUseItem( pItemDef_DescTag->GetDefinitionIndex() ) )
  2871. {
  2872. AttemptToShowItemInStore( pItemDef_DescTag->GetDefinitionIndex() );
  2873. }
  2874. }
  2875. //-----------------------------------------------------------------------------
  2876. // Purpose: Use a name tag, or offer to buy one
  2877. //-----------------------------------------------------------------------------
  2878. void CBackpackPanel::DoRename()
  2879. {
  2880. static CSchemaItemDefHandle pItemDef_NameTag( "Name Tag" );
  2881. if ( !AttemptToUseItem( pItemDef_NameTag->GetDefinitionIndex() ) )
  2882. {
  2883. AttemptToShowItemInStore( pItemDef_NameTag->GetDefinitionIndex() );
  2884. }
  2885. }
  2886. //-----------------------------------------------------------------------------
  2887. // Purpose: Delete the selected items
  2888. //-----------------------------------------------------------------------------
  2889. void CBackpackPanel::DoDelete()
  2890. {
  2891. // Hide the mouseover panel
  2892. HideMouseOverPanel();
  2893. int iItemsToDelete = 0;
  2894. for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
  2895. {
  2896. if ( m_pItemModelPanels[i]->IsSelected() && m_pItemModelPanels[i]->HasItem() )
  2897. {
  2898. iItemsToDelete++;
  2899. }
  2900. }
  2901. // Bring up confirm dialog
  2902. CConfirmDeleteItemDialog *pConfirm = vgui::SETUP_PANEL( new CConfirmDeleteItemDialog( this, ( iItemsToDelete > 1 ) ) );
  2903. if ( pConfirm )
  2904. {
  2905. pConfirm->Show();
  2906. m_pConfirmDeleteDialog = pConfirm;
  2907. }
  2908. }
  2909. //-----------------------------------------------------------------------------
  2910. // Purpose: Use the selected tool
  2911. //-----------------------------------------------------------------------------
  2912. void CBackpackPanel::DoApplyOnItem()
  2913. {
  2914. SetupToolSelectionItem();
  2915. if ( m_ToolSelectionItem.IsValid() )
  2916. {
  2917. const IEconTool *pEconTool = m_ToolSelectionItem.GetItemDefinition()->GetEconTool();
  2918. // Gather all quest objective attributes
  2919. CRecipeComponentMatchingIterator recipeIterator( NULL, NULL );
  2920. if ( m_ToolSelectionItem.GetSOCData() )
  2921. {
  2922. m_ToolSelectionItem.GetSOCData()->IterateAttributes( &recipeIterator );
  2923. }
  2924. if( pEconTool && recipeIterator.GetMatchingComponentInputs().Count() > 0 )
  2925. {
  2926. // Launch new crafting window if we need to
  2927. if( m_pDynamicRecipePanel == NULL )
  2928. {
  2929. m_pDynamicRecipePanel = vgui::SETUP_PANEL( new CDynamicRecipePanel( this, "dynamic_recipe_panel", &m_ToolSelectionItem ) );
  2930. }
  2931. // Set recipe item into panel
  2932. if ( m_pDynamicRecipePanel )
  2933. {
  2934. m_pDynamicRecipePanel->SetVisible( true );
  2935. m_pDynamicRecipePanel->SetNewRecipe( &m_ToolSelectionItem );
  2936. }
  2937. return;
  2938. }
  2939. // Check if we actually have any items we can use this tool on
  2940. bool bHasValidTargetItem = false;
  2941. CPlayerInventory *pInv = InventoryManager()->GetLocalInventory();
  2942. Assert( pInv );
  2943. if ( pInv )
  2944. {
  2945. for ( int i = 0 ; i < pInv->GetItemCount() ; ++i )
  2946. {
  2947. CEconItemView *pItem = pInv->GetItem( i );
  2948. if ( CEconSharedToolSupport::ToolCanApplyTo( &m_ToolSelectionItem, pItem ) )
  2949. {
  2950. bHasValidTargetItem = true;
  2951. break;
  2952. }
  2953. }
  2954. // If no applicable items, try stock items
  2955. if ( !bHasValidTargetItem )
  2956. {
  2957. // this is really inefficient, maybe have a list of baseitems somewhere
  2958. CEconItemView tempItem;
  2959. const CEconItemDefinition* pItemDef = NULL;
  2960. const CEconItemSchema::SortedItemDefinitionMap_t& mapItems = GetItemSchema()->GetSortedItemDefinitionMap();
  2961. for ( int it = mapItems.FirstInorder(); it != mapItems.InvalidIndex(); it = mapItems.NextInorder( it ) )
  2962. {
  2963. if ( mapItems[it]->IsBaseItem() && !mapItems[it]->IsHidden() )
  2964. {
  2965. CFmtStr fmtStrCustomizedDefName( "Upgradeable %s", mapItems[it]->GetDefinitionName() );
  2966. pItemDef = GetItemSchema()->GetItemDefinitionByName( fmtStrCustomizedDefName.Access() );
  2967. if ( pItemDef )
  2968. {
  2969. tempItem.Init( pItemDef->GetDefinitionIndex(), AE_UNIQUE, AE_USE_SCRIPT_VALUE, true );
  2970. if ( CEconSharedToolSupport::ToolCanApplyTo( &m_ToolSelectionItem, &tempItem ) )
  2971. {
  2972. bHasValidTargetItem = true;
  2973. break;
  2974. }
  2975. }
  2976. }
  2977. }
  2978. if ( bHasValidTargetItem )
  2979. {
  2980. // automatically switch to stock items
  2981. OnCommand( "showbaseitems" );
  2982. }
  2983. }
  2984. }
  2985. if ( !bHasValidTargetItem )
  2986. {
  2987. ShowMessageBox( NULL, "#ToolNoTargetItems", "#GameUI_OK" );
  2988. return;
  2989. }
  2990. m_eSelectionMode = ToolSelection;
  2991. m_nLastToolPage = GetCurrentPage();
  2992. if ( m_pMouseOverTooltip )
  2993. {
  2994. m_pMouseOverTooltip->HideTooltip();
  2995. }
  2996. ClearNameFilter( true );
  2997. SetCurrentPage( 0 );
  2998. UpdateModelPanels();
  2999. }
  3000. }
  3001. //-----------------------------------------------------------------------------
  3002. // Purpose: use a consumable item directly from the backpack
  3003. //-----------------------------------------------------------------------------
  3004. void CBackpackPanel::DoUseConsumableItem()
  3005. {
  3006. SetupToolSelectionItem();
  3007. #ifdef TF_CLIENT_DLL
  3008. UseConsumableItem( &m_ToolSelectionItem, this );
  3009. #endif
  3010. }
  3011. //-----------------------------------------------------------------------------
  3012. // Purpose: Use the tool to unwrap an item
  3013. //-----------------------------------------------------------------------------
  3014. void CBackpackPanel::DoUnwrapItem()
  3015. {
  3016. DoUseConsumableItem();
  3017. }
  3018. //-----------------------------------------------------------------------------
  3019. // Purpose: Use the tool to deliver an item
  3020. //-----------------------------------------------------------------------------
  3021. void CBackpackPanel::DoDeliverItem()
  3022. {
  3023. SetupToolSelectionItem();
  3024. #ifdef TF_CLIENT_DLL
  3025. const CEconTool_WrappedGift *pWrappedGiftTool = m_ToolSelectionItem.GetItemDefinition()
  3026. ? m_ToolSelectionItem.GetItemDefinition()->GetTypedEconTool<CEconTool_WrappedGift>()
  3027. : NULL;
  3028. if ( pWrappedGiftTool && pWrappedGiftTool->BIsDirectGift() )
  3029. {
  3030. DoUseConsumableItem();
  3031. return;
  3032. }
  3033. else if ( pWrappedGiftTool && pWrappedGiftTool->BIsGlobalGift() )
  3034. {
  3035. // If this is a global gift, we don't let the user pick a target so we're done as of now.
  3036. extern void UseUntargetedGiftConfirm( bool bConfirmed, void *pContext );
  3037. CTFGenericConfirmDialog *pDialog = ShowConfirmDialog( "#TF_DeliverGiftDialog_Title", "#TF_DeliverGiftDialog_Random_Text",
  3038. "#TF_DeliverGiftDialog_Confirm", "#TF_DeliverGiftDialog_Cancel",
  3039. &UseUntargetedGiftConfirm );
  3040. pDialog->SetContext( &m_ToolSelectionItem );
  3041. return;
  3042. }
  3043. DoGiftToPlayer();
  3044. #endif
  3045. }
  3046. //-----------------------------------------------------------------------------
  3047. // Purpose: Show
  3048. //-----------------------------------------------------------------------------
  3049. void CBackpackPanel::DoApplyByItem()
  3050. {
  3051. SetupToolSelectionItem();
  3052. m_eSelectionMode = ToolSelection;
  3053. m_nLastToolPage = GetCurrentPage();
  3054. if ( m_pMouseOverTooltip )
  3055. {
  3056. m_pMouseOverTooltip->HideTooltip();
  3057. }
  3058. ClearNameFilter( true );
  3059. SetCurrentPage( 0 );
  3060. UpdateModelPanels();
  3061. }
  3062. //-----------------------------------------------------------------------------
  3063. // Purpose: open shuffle items dialog
  3064. //-----------------------------------------------------------------------------
  3065. void CBackpackPanel::DoShuffle()
  3066. {
  3067. SetupToolSelectionItem();
  3068. CInputStringForItemBackpackOverlayDialog *pDialog = vgui::SETUP_PANEL( new CInputStringForItemBackpackOverlayDialog( this, &m_ToolSelectionItem ) );
  3069. if ( pDialog )
  3070. {
  3071. pDialog->Show();
  3072. }
  3073. }
  3074. void CBackpackPanel::DoEditSlot()
  3075. {
  3076. SetupToolSelectionItem();
  3077. // Launch new slot window if we need to
  3078. if( m_pItemSlotPanel == NULL )
  3079. {
  3080. m_pItemSlotPanel = vgui::SETUP_PANEL( new CItemSlotPanel( this ) );
  3081. }
  3082. // Set item into panel
  3083. if ( m_pItemSlotPanel )
  3084. {
  3085. m_pItemSlotPanel->SetVisible( true );
  3086. m_pItemSlotPanel->SetItem( m_ToolSelectionItem.GetSOCData() );
  3087. }
  3088. }
  3089. //-----------------------------------------------------------------------------
  3090. // Purpose: Refurbish item
  3091. //-----------------------------------------------------------------------------
  3092. void CBackpackPanel::DoRefurbishItem()
  3093. {
  3094. for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
  3095. {
  3096. if ( m_pItemModelPanels[i]->IsSelected() && m_pItemModelPanels[i]->HasItem() )
  3097. {
  3098. m_ComboBoxOverlaySelectionItem = *m_pItemModelPanels[i]->GetItem();
  3099. break;
  3100. }
  3101. }
  3102. CRefurbishItemDialog *pRefurbishDialog = vgui::SETUP_PANEL( new CRefurbishItemDialog( this, &m_ComboBoxOverlaySelectionItem ) );
  3103. if ( pRefurbishDialog )
  3104. {
  3105. pRefurbishDialog->Show();
  3106. }
  3107. }
  3108. //-----------------------------------------------------------------------------
  3109. // Purpose: Deode by item
  3110. //-----------------------------------------------------------------------------
  3111. void CBackpackPanel::DoGetItemFromStore()
  3112. {
  3113. SetupToolSelectionItem();
  3114. uint32 iDecoableItemDef = 0;
  3115. if ( GetDecodedByItemDefIndex( &m_ToolSelectionItem, &iDecoableItemDef ) )
  3116. {
  3117. // casting to the proper type since our econ system is dumb
  3118. const float& value_as_float = (float&)iDecoableItemDef;
  3119. CEconItemDefinition * pDefIndex = GetItemSchema()->GetItemDefinition( (int)value_as_float );
  3120. EconUI()->GetStorePanel()->AddToCartAndCheckoutImmediately( pDefIndex->GetDefinitionIndex() );
  3121. }
  3122. }
  3123. //-----------------------------------------------------------------------------
  3124. // Purpose: Open End of the Line duck leaderboards
  3125. //-----------------------------------------------------------------------------
  3126. void CBackpackPanel::DoOpenDuckLeaderboards()
  3127. {
  3128. CCharacterInfoPanel* pCharInfo = dynamic_cast< CCharacterInfoPanel* >( EconUI() );
  3129. CDucksLeaderboardManager *pDuckLeaderboards = vgui::SETUP_PANEL( new CDucksLeaderboardManager( pCharInfo, "DucksLeaderboardPanel" ) );
  3130. pDuckLeaderboards->SetVisible( true );
  3131. }
  3132. //-----------------------------------------------------------------------------
  3133. // Strange Count Transfer Dialog
  3134. //-----------------------------------------------------------------------------
  3135. void CBackpackPanel::DoStrangeCountTransfer()
  3136. {
  3137. CUtlVector< CItemModelPanel* > vecSelected;
  3138. GetSelectedPanels( SELECT_FIRST, vecSelected );
  3139. Assert( vecSelected.Count() );
  3140. if ( vecSelected.IsEmpty() )
  3141. return;
  3142. m_pStrangeToolPanel = vgui::SETUP_PANEL( new CStrangeCountTransferPanel( this, vecSelected[0]->GetItem() ) );
  3143. }
  3144. //-----------------------------------------------------------------------------
  3145. // Collection crafting
  3146. //-----------------------------------------------------------------------------
  3147. void CBackpackPanel::DoCraftUpCollection()
  3148. {
  3149. CUtlVector< CItemModelPanel* > vecSelected;
  3150. GetSelectedPanels( SELECT_ALL, vecSelected );
  3151. //Assert( vecSelected.Count() );
  3152. //if ( vecSelected.IsEmpty() )
  3153. // return;
  3154. // Get all the items that were selected
  3155. CUtlVector< const CEconItemView* > vecSelectedItems;
  3156. FOR_EACH_VEC( vecSelected, i )
  3157. {
  3158. if ( vecSelected[ i ]->GetItem() && GetCollectionCraftingInvalidReason( vecSelected[ i ]->GetItem(), NULL ) == NULL )
  3159. {
  3160. vecSelectedItems.AddToTail( vecSelected[ i ]->GetItem() );
  3161. }
  3162. }
  3163. // For tracking how many times they've opened this menu
  3164. tf_trade_up_use_count.SetValue( tf_trade_up_use_count.GetInt() - 1 );
  3165. // Open it up!
  3166. GetCollectionCraftPanel()->Show( vecSelectedItems );
  3167. }
  3168. //-----------------------------------------------------------------------------
  3169. // Collection crafting
  3170. //-----------------------------------------------------------------------------
  3171. void CBackpackPanel::DoHalloweenOffering()
  3172. {
  3173. // Open it up!
  3174. if ( !m_pHalloweenOfferingPanel )
  3175. {
  3176. m_pHalloweenOfferingPanel = vgui::SETUP_PANEL( new CHalloweenOfferingPanel( this, m_pMouseOverTooltip ) );
  3177. m_pHalloweenOfferingPanel->InvalidateLayout( true, true );
  3178. }
  3179. // empty
  3180. CUtlVector< const CEconItemView* > vecSelectedItems;
  3181. m_pHalloweenOfferingPanel->Show( vecSelectedItems );
  3182. }
  3183. //-----------------------------------------------------------------------------
  3184. // Craft Common StatClock
  3185. //-----------------------------------------------------------------------------
  3186. void CBackpackPanel::DoCraftCommonStatClock()
  3187. {
  3188. // Open it up!
  3189. if ( !m_pMannCoTradePanel )
  3190. {
  3191. m_pMannCoTradePanel = vgui::SETUP_PANEL( new CCraftCommonStatClockPanel( this, m_pMouseOverTooltip ) ); // make this more generic
  3192. m_pMannCoTradePanel->InvalidateLayout( true, true );
  3193. }
  3194. CUtlVector< CItemModelPanel* > vecSelected;
  3195. GetSelectedPanels(SELECT_ALL, vecSelected);
  3196. CUtlVector< const CEconItemView* > vecSelectedItems;
  3197. FOR_EACH_VEC(vecSelected, i)
  3198. {
  3199. if (vecSelected[i]->GetItem() && GetCraftCommonStatClockInvalidReason(vecSelected[i]->GetItem(), NULL) == NULL)
  3200. {
  3201. vecSelectedItems.AddToTail(vecSelected[i]->GetItem());
  3202. }
  3203. }
  3204. m_pMannCoTradePanel->Show( vecSelectedItems );
  3205. }
  3206. //-----------------------------------------------------------------------------
  3207. // Purpose: Bring up the 3D inspect panel for the selected item
  3208. //-----------------------------------------------------------------------------
  3209. void CBackpackPanel::DoInspectModel()
  3210. {
  3211. CUtlVector< CItemModelPanel* > vecSelected;
  3212. GetSelectedPanels( SELECT_FIRST, vecSelected );
  3213. if ( vecSelected.IsEmpty() )
  3214. return;
  3215. CEconItemView *pItem = vecSelected[0]->GetItem();
  3216. if ( pItem )
  3217. {
  3218. float flInspect = 0;
  3219. static CSchemaAttributeDefHandle pAttrib_WeaponAllowInspect( "weapon_allow_inspect" );
  3220. if ( ( FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pItem, pAttrib_WeaponAllowInspect, &flInspect ) && flInspect != 0.f )
  3221. #ifdef STAGING_ONLY
  3222. || tf_weapon_force_allow_inspect.GetBool()
  3223. #endif
  3224. )
  3225. {
  3226. m_pInspectPanel->SetVisible( true );
  3227. m_pInspectPanel->SetItemCopy( vecSelected[0]->GetItem() );
  3228. }
  3229. else
  3230. {
  3231. for ( int iClass = TF_FIRST_NORMAL_CLASS; iClass < TF_LAST_NORMAL_CLASS; ++iClass )
  3232. {
  3233. if ( pItem->GetStaticData()->CanBeUsedByClass( iClass ) )
  3234. {
  3235. m_pInspectCosmeticPanel->PreviewItem( iClass, pItem );
  3236. break;
  3237. }
  3238. }
  3239. m_pInspectCosmeticPanel->SetVisible( true );
  3240. }
  3241. }
  3242. }
  3243. //-----------------------------------------------------------------------------
  3244. void CBackpackPanel::OpenInspectModelPanelAndCopyItem( CEconItemView *pItemView )
  3245. {
  3246. if ( !pItemView )
  3247. return;
  3248. EconUI()->OpenEconUI( ECONUI_BACKPACK );
  3249. // Figure out which preview to show
  3250. float flInspect = 0;
  3251. static CSchemaAttributeDefHandle pAttrib_WeaponAllowInspect( "weapon_allow_inspect" );
  3252. if ( FindAttribute_UnsafeBitwiseCast<attrib_value_t>( pItemView, pAttrib_WeaponAllowInspect, &flInspect ) && flInspect != 0.f )
  3253. {
  3254. m_pInspectPanel->SetVisible( true );
  3255. m_pInspectPanel->SetItemCopy( pItemView );
  3256. }
  3257. else
  3258. {
  3259. for ( int iClass = TF_FIRST_NORMAL_CLASS; iClass < TF_LAST_NORMAL_CLASS; ++iClass )
  3260. {
  3261. if ( pItemView->GetStaticData()->CanBeUsedByClass( iClass ) )
  3262. {
  3263. m_pInspectCosmeticPanel->PreviewItemCopy( iClass, pItemView );
  3264. m_pInspectCosmeticPanel->SetVisible( true );
  3265. break;
  3266. }
  3267. }
  3268. }
  3269. }
  3270. CCollectionCraftingPanel* CBackpackPanel::GetCollectionCraftPanel()
  3271. {
  3272. if ( !m_pCollectionCraftPanel )
  3273. {
  3274. m_pCollectionCraftPanel = vgui::SETUP_PANEL( new CCollectionCraftingPanel( this, m_pMouseOverTooltip ) );
  3275. m_pCollectionCraftPanel->InvalidateLayout( true, true );
  3276. }
  3277. return m_pCollectionCraftPanel;
  3278. }
  3279. //-----------------------------------------------------------------------------
  3280. // Purpose: Buy a key, and then immediately use it on the selected crate once
  3281. // tbe store transaction completes
  3282. //-----------------------------------------------------------------------------
  3283. void CBackpackPanel::DoBuyKeyAndOpenCrate()
  3284. {
  3285. CUtlVector< CItemModelPanel* > vecSelected;
  3286. GetSelectedPanels( SELECT_FIRST, vecSelected );
  3287. if ( vecSelected.IsEmpty() )
  3288. return;
  3289. m_hQuickOpenCrate.SetItem( vecSelected.Head()->GetItem() );
  3290. uint32 iDecoableItemDef = 0;
  3291. if ( GetDecodedByItemDefIndex( m_hQuickOpenCrate, &iDecoableItemDef ) )
  3292. {
  3293. // casting to the proper type since our econ system is dumb
  3294. const float& value_as_float = (float&)iDecoableItemDef;
  3295. CEconItemDefinition * pDefIndex = GetItemSchema()->GetItemDefinition( (int)value_as_float );
  3296. EconUI()->GetStorePanel()->AddToCartAndCheckoutImmediately( pDefIndex->GetDefinitionIndex() );
  3297. }
  3298. }
  3299. //-----------------------------------------------------------------------------
  3300. // Purpose: Find the first compatible key in our inventory, and use it on the
  3301. // selected crate
  3302. //-----------------------------------------------------------------------------
  3303. void CBackpackPanel::DoOpenCrateWithKey()
  3304. {
  3305. CUtlVector< CItemModelPanel* > vecSelected;
  3306. GetSelectedPanels( SELECT_FIRST, vecSelected );
  3307. if ( vecSelected.IsEmpty() )
  3308. return;
  3309. CEconItemView *pCrate = vecSelected.Head()->GetItem();
  3310. CEconItemView *pKey = GetFirstCompatibleKeyForCrate( pCrate );
  3311. if ( !pKey )
  3312. return;
  3313. ApplyTool( this, pKey, pCrate );
  3314. }
  3315. //-----------------------------------------------------------------------------
  3316. // Purpose: Open up the loadout for a class
  3317. //-----------------------------------------------------------------------------
  3318. void CBackpackPanel::DoEquipForClass( int nClass )
  3319. {
  3320. // Negative because reasons
  3321. EconUI()->OpenEconUI( -nClass );
  3322. }
  3323. //-----------------------------------------------------------------------------
  3324. // Purpose: Given a paint can index, offer to use one or buy one
  3325. //-----------------------------------------------------------------------------
  3326. void CBackpackPanel::DoPaint( int nPaintItemIndex, bool bUseStore, bool bUseMarket )
  3327. {
  3328. if ( !bUseStore && !bUseMarket )
  3329. {
  3330. AttemptToUseItem( nPaintItemIndex );
  3331. }
  3332. if ( bUseStore )
  3333. {
  3334. AttemptToShowItemInStore( nPaintItemIndex );
  3335. }
  3336. else if ( bUseMarket )
  3337. {
  3338. AttemptToShowItemInMarket( nPaintItemIndex );
  3339. }
  3340. }
  3341. //-----------------------------------------------------------------------------
  3342. // Purpose: Given a strange part index, offer to use one or buy one (Market)
  3343. //-----------------------------------------------------------------------------
  3344. void CBackpackPanel::DoStrangePart( int nStrangePartIndex, bool bUseMarket )
  3345. {
  3346. if ( !bUseMarket )
  3347. {
  3348. AttemptToUseItem( nStrangePartIndex );
  3349. }
  3350. if ( bUseMarket )
  3351. {
  3352. AttemptToShowItemInMarket( nStrangePartIndex );
  3353. }
  3354. }
  3355. //-----------------------------------------------------------------------------
  3356. // Purpose: Try to find the first item with the passed-in item name in our inventory
  3357. // and try to use it on the selected panel's item. If we dont have an item
  3358. // matching the name passed in, go to the store and prompt the user to buy one.
  3359. //-----------------------------------------------------------------------------
  3360. bool CBackpackPanel::AttemptToUseItem( item_definition_index_t iItemDefIndex )
  3361. {
  3362. CUtlVector< CItemModelPanel* > m_vecSelected;
  3363. GetSelectedPanels( SELECT_FIRST, m_vecSelected );
  3364. Assert( m_vecSelected.Count() );
  3365. if ( !m_vecSelected.Count() )
  3366. return false;
  3367. CEconItemView *pSelectedItem = m_vecSelected.Head()->GetItem();
  3368. Assert( pSelectedItem );
  3369. if ( !pSelectedItem )
  3370. return false;
  3371. CEconItemView *pNameTag = CTFPlayerInventory::GetFirstItemOfItemDef( iItemDefIndex );
  3372. if ( pNameTag )
  3373. {
  3374. if ( ApplyTool( this, pNameTag, pSelectedItem ) )
  3375. {
  3376. CancelToolSelection();
  3377. UpdateModelPanels();
  3378. }
  3379. return true;
  3380. }
  3381. return false;
  3382. }
  3383. //-----------------------------------------------------------------------------
  3384. void CBackpackPanel::AttemptToShowItemInStore( item_definition_index_t iItemDefIndex )
  3385. {
  3386. CUtlVector< CItemModelPanel* > m_vecSelected;
  3387. GetSelectedPanels( SELECT_FIRST, m_vecSelected );
  3388. Assert( m_vecSelected.Count() );
  3389. if( !m_vecSelected.Count() )
  3390. return;
  3391. CEconItemView *pSelectedItem = m_vecSelected.Head()->GetItem();
  3392. Assert( pSelectedItem );
  3393. if ( !pSelectedItem )
  3394. return;
  3395. EconUI()->OpenStorePanel( iItemDefIndex, false );
  3396. }
  3397. //-----------------------------------------------------------------------------
  3398. void CBackpackPanel::AttemptToShowItemInMarket( item_definition_index_t iItemDefIndex )
  3399. {
  3400. CUtlVector< CItemModelPanel* > m_vecSelected;
  3401. GetSelectedPanels( SELECT_FIRST, m_vecSelected );
  3402. Assert( m_vecSelected.Count() );
  3403. if ( !m_vecSelected.Count() )
  3404. return;
  3405. CEconItemView *pSelectedItem = m_vecSelected.Head()->GetItem();
  3406. Assert( pSelectedItem );
  3407. if ( !pSelectedItem )
  3408. return;
  3409. CEconItemDefinition *pItemDef = GetItemSchema()->GetItemDefinition( iItemDefIndex );
  3410. Assert( pItemDef );
  3411. if ( !pItemDef )
  3412. return;
  3413. if ( !CBaseAdPanel::CheckForRequiredSteamComponents( "#StoreUpdate_SteamRequired", "#MMenu_OverlayRequired" ) )
  3414. return;
  3415. if ( pItemDef && steamapicontext && steamapicontext->SteamFriends() )
  3416. {
  3417. const char *pszPrefix = "";
  3418. if ( GetUniverse() == k_EUniverseBeta )
  3419. {
  3420. pszPrefix = "beta.";
  3421. }
  3422. static char pszItemName[256];
  3423. g_pVGuiLocalize->ConvertUnicodeToANSI( g_pVGuiLocalize->Find( pItemDef->GetItemBaseName() ), pszItemName, sizeof( pszItemName ) );
  3424. char szURL[512];
  3425. V_snprintf( szURL, sizeof( szURL ), "http://%ssteamcommunity.com/market/listings/%d/%s", pszPrefix, engine->GetAppID(), pszItemName );
  3426. steamapicontext->SteamFriends()->ActivateGameOverlayToWebPage( szURL );
  3427. }
  3428. }
  3429. //-----------------------------------------------------------------------------
  3430. // Purpose: Get the first, or all selected item model panels
  3431. //-----------------------------------------------------------------------------
  3432. void CBackpackPanel::GetSelectedPanels( ESelection eSelection, CUtlVector< CItemModelPanel* >& m_vecSelected ) const
  3433. {
  3434. for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
  3435. {
  3436. if ( m_pItemModelPanels[i]->IsSelected() && m_pItemModelPanels[i]->HasItem() )
  3437. {
  3438. m_vecSelected.AddToTail( m_pItemModelPanels[i] );
  3439. if ( eSelection == SELECT_FIRST )
  3440. {
  3441. return;
  3442. }
  3443. }
  3444. }
  3445. }
  3446. //-----------------------------------------------------------------------------
  3447. // Purpose:
  3448. //-----------------------------------------------------------------------------
  3449. void CBackpackPanel::OnCommand( const char *command )
  3450. {
  3451. if ( V_strncasecmp( command, "goto_page_", V_strlen( "goto_page_" ) ) == 0 )
  3452. {
  3453. int iPage = V_atoi( &command[ V_strlen( "goto_page_" ) ] );
  3454. SetCurrentPage( iPage );
  3455. UpdateModelPanels();
  3456. return;
  3457. }
  3458. else if ( !Q_strnicmp( command, "nextpage", 8 ) )
  3459. {
  3460. if ( !m_bDragging )
  3461. {
  3462. DeSelectAllBackpackItemPanels();
  3463. }
  3464. SetCurrentPage( GetCurrentPage() + 1 );
  3465. UpdateModelPanels();
  3466. return;
  3467. }
  3468. else if ( !Q_strnicmp( command, "prevpage", 8 ) )
  3469. {
  3470. if ( !m_bDragging )
  3471. {
  3472. DeSelectAllBackpackItemPanels();
  3473. }
  3474. SetCurrentPage( GetCurrentPage() - 1 );
  3475. UpdateModelPanels();
  3476. return;
  3477. }
  3478. else if ( !Q_strnicmp( command, "useitem", 7 ) )
  3479. {
  3480. AssertMsg( 0, "Everything should be going through the context menu. Fix the calling code." );
  3481. return;
  3482. }
  3483. else if ( !Q_strnicmp( command, "showbackpackitems", 17 ) )
  3484. {
  3485. SetShowBaseItems( false );
  3486. if ( m_pShowBaseItemsCheckbox )
  3487. {
  3488. m_pShowBaseItemsCheckbox->SetSelected( false );
  3489. }
  3490. return;
  3491. }
  3492. else if ( !Q_strnicmp( command, "showbaseitems", 13 ) )
  3493. {
  3494. SetShowBaseItems( true );
  3495. if ( m_pShowBaseItemsCheckbox )
  3496. {
  3497. m_pShowBaseItemsCheckbox->SetSelected( true );
  3498. }
  3499. return;
  3500. }
  3501. else if ( !Q_strnicmp( command, "canceltool", 10 ) )
  3502. {
  3503. CancelToolSelection();
  3504. UpdateModelPanels();
  3505. return;
  3506. }
  3507. else if ( !Q_stricmp( command, "show_explanations" ) )
  3508. {
  3509. if ( !m_flStartExplanationsAt )
  3510. {
  3511. m_flStartExplanationsAt = Plat_FloatTime();
  3512. vgui::ivgui()->AddTickSignal( GetVPanel() );
  3513. }
  3514. RequestFocus();
  3515. }
  3516. else if ( !Q_stricmp( command, "showdetails" ) )
  3517. {
  3518. for ( int i = 0; i < m_pItemModelPanels.Count(); i++ )
  3519. {
  3520. if ( m_pItemModelPanels[i]->IsSelected() && m_pItemModelPanels[i]->HasItem() )
  3521. {
  3522. OpenArmory( m_pItemModelPanels[i]->GetItem() );
  3523. break;
  3524. }
  3525. }
  3526. UpdateModelPanels();
  3527. return;
  3528. }
  3529. else if ( !V_strnicmp( command, "equipclass", 10 ) )
  3530. {
  3531. int nClass = atoi( command + 10 );
  3532. DoEquipForClass( nClass );
  3533. }
  3534. else if ( !V_strnicmp( command, "paint", 5 ) )
  3535. {
  3536. int nIndex = atoi( command + 5 );
  3537. DoPaint( nIndex, false, false );
  3538. }
  3539. else if ( !V_strnicmp( command, "market_paint", 12 ) )
  3540. {
  3541. int nIndex = atoi( command + 12 );
  3542. DoPaint( nIndex, false, true );
  3543. }
  3544. else if ( !V_strnicmp( command, "store_paint", 11 ) )
  3545. {
  3546. int nIndex = atoi( command + 11 );
  3547. DoPaint( nIndex, true, false );
  3548. }
  3549. else if ( !V_strnicmp( command, "strangepart_", 12 ) )
  3550. {
  3551. int nIndex = atoi( command + 12 );
  3552. DoStrangePart( nIndex, false );
  3553. }
  3554. else if ( !V_strnicmp( command, "market_strangepart_", 19 ) )
  3555. {
  3556. int nIndex = atoi( command + 19 );
  3557. DoStrangePart( nIndex, true );
  3558. }
  3559. else if ( !V_strnicmp( command, "Context_CraftUpCollection", 25 ) )
  3560. {
  3561. DoCraftUpCollection();
  3562. }
  3563. else if ( !V_strnicmp( command, "Context_CraftCommonStatClock", 25 ) )
  3564. {
  3565. DoCraftCommonStatClock();
  3566. }
  3567. #ifdef STAGING_ONLY
  3568. else if ( !V_strnicmp( command, "unpin", 5 ) )
  3569. {
  3570. m_pMouseOverCardPanel->PinCard( false );
  3571. }
  3572. #endif
  3573. BaseClass::OnCommand( command );
  3574. }
  3575. //-----------------------------------------------------------------------------
  3576. // Purpose:
  3577. //-----------------------------------------------------------------------------
  3578. void CBackpackPanel::OpenArmory( CEconItemView* item )
  3579. {
  3580. PostMessage( GetParent()->GetParent()->GetParent(), new KeyValues("OpenArmoryDirect", "itemdef", item->GetItemDefIndex() ) );
  3581. }
  3582. //-----------------------------------------------------------------------------
  3583. // Purpose:
  3584. //-----------------------------------------------------------------------------
  3585. void CBackpackPanel::CancelToolSelection( void )
  3586. {
  3587. if ( m_eSelectionMode == StandardSelection )
  3588. return;
  3589. m_eSelectionMode = StandardSelection;
  3590. ClearNameFilter( false );
  3591. OnCommand( "showbackpackitems" );
  3592. SetCurrentPage( m_nLastToolPage );
  3593. m_nLastToolPage = 0;
  3594. m_ToolSelectionItem.Invalidate();
  3595. if ( m_pToolIcon )
  3596. {
  3597. m_pToolIcon->SetVisible( false );
  3598. }
  3599. DeSelectAllBackpackItemPanels();
  3600. }
  3601. //-----------------------------------------------------------------------------
  3602. // Purpose:
  3603. //-----------------------------------------------------------------------------
  3604. void CBackpackPanel::SetShowBaseItems( bool bShow )
  3605. {
  3606. bool bGoToFirstPage = m_bShowBaseItems != bShow;
  3607. m_bShowBaseItems = bShow;
  3608. if( bGoToFirstPage )
  3609. {
  3610. SetCurrentPage( 0 );
  3611. }
  3612. DeSelectAllBackpackItemPanels();
  3613. if ( m_pToolIcon )
  3614. {
  3615. m_pToolIcon->SetVisible( false );
  3616. }
  3617. UpdateModelPanels();
  3618. }
  3619. //-----------------------------------------------------------------------------
  3620. // Purpose:
  3621. //-----------------------------------------------------------------------------
  3622. ConVar *CBackpackPanel::GetExplanationConVar( void )
  3623. {
  3624. return &tf_explanations_backpackpanel;
  3625. }
  3626. //-----------------------------------------------------------------------------
  3627. // Purpose:
  3628. //-----------------------------------------------------------------------------
  3629. void CBackpackPanel::SetCurrentPage( int nNewPage )
  3630. {
  3631. if( m_pToolIcon )
  3632. {
  3633. m_pToolIcon->SetVisible( false );
  3634. }
  3635. if ( nNewPage < 0 )
  3636. {
  3637. nNewPage = GetNumPages() - 1;
  3638. }
  3639. else if ( nNewPage >= GetNumPages() )
  3640. {
  3641. nNewPage = 0;
  3642. }
  3643. // deselect old page button
  3644. if ( m_Pages.Count() > GetCurrentPage() && m_Pages[GetCurrentPage()] )
  3645. {
  3646. CExButton* pButton = dynamic_cast<CExButton*>( m_Pages[GetCurrentPage()]->FindChildByName( "Button" ) );
  3647. if ( pButton )
  3648. {
  3649. pButton->SetSelected( false );
  3650. }
  3651. }
  3652. BaseClass::SetCurrentPage( nNewPage );
  3653. // mark new page button as selected
  3654. if ( m_Pages.Count() > GetCurrentPage() && m_Pages[GetCurrentPage()] )
  3655. {
  3656. CExButton* pButton = dynamic_cast<CExButton*>( m_Pages[GetCurrentPage()]->FindChildByName( "Button" ) );
  3657. if ( pButton )
  3658. {
  3659. pButton->SetSelected( true );
  3660. }
  3661. }
  3662. }
  3663. int CBackpackPanel::GetItemQualityForBorder( CItemModelPanel* pItemPanel ) const
  3664. {
  3665. if ( pItemPanel->HasItem() && ( cl_showbackpackrarities.GetInt() > 0 || m_bForceShowBackpackRarities )
  3666. && ( cl_showbackpackrarities.GetInt() < 2 || pItemPanel->GetItem()->IsMarketable() ) )
  3667. {
  3668. uint8 nRarity = pItemPanel->GetItem()->GetItemDefinition()->GetRarity();
  3669. if ( ( nRarity != k_unItemRarity_Any ) && ( pItemPanel->GetItem()->GetItemQuality() != AE_SELFMADE ) )
  3670. {
  3671. // translate this quality to rarity
  3672. return nRarity + AE_RARITY_DEFAULT;
  3673. }
  3674. return pItemPanel->GetItem()->GetItemQuality();
  3675. }
  3676. return 0;
  3677. }