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.

184 lines
5.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "vgui/IInput.h"
  8. #include <vgui/IVGui.h>
  9. #include <vgui/IScheme.h>
  10. #include "blueprint_panel.h"
  11. #include "vgui_controls/TextImage.h"
  12. #include "vgui_controls/Label.h"
  13. #include "vgui_controls/Button.h"
  14. #include "ienginevgui.h"
  15. #include "VGuiMatSurface/IMatSystemSurface.h"
  16. #include "renderparm.h"
  17. DECLARE_BUILD_FACTORY( CBlueprintPanel );
  18. //-----------------------------------------------------------------------------
  19. // Purpose:
  20. //-----------------------------------------------------------------------------
  21. CBlueprintPanel::CBlueprintPanel( vgui::Panel *parent, const char *name ) : vgui::EditablePanel( parent, name )
  22. {
  23. m_bClickable = false;
  24. m_bMouseOver = false;
  25. m_bInStack = false;
  26. SetActAsButton( false, false );
  27. }
  28. //-----------------------------------------------------------------------------
  29. // Purpose:
  30. //-----------------------------------------------------------------------------
  31. void CBlueprintPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  32. {
  33. BaseClass::ApplySchemeSettings( pScheme );
  34. LoadControlSettings( "Resource/UI/build_menu/base_selectable.res" );
  35. m_pItemNameLabel = dynamic_cast<vgui::Label*>( FindChildByName("ItemNameLabel") );
  36. m_pItemCostLabel = dynamic_cast<vgui::Label*>( FindChildByName("CostLabel") );
  37. m_pIcon = dynamic_cast<CIconPanel*>( FindChildByName("BuildingIcon") );
  38. m_pMetalIcon = dynamic_cast<CIconPanel*>( FindChildByName("MetalIcon") );
  39. m_pBackground = dynamic_cast<CIconPanel*>( FindChildByName("ItemBackground") );
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Purpose:
  43. //-----------------------------------------------------------------------------
  44. void CBlueprintPanel::SetObjectInfo( const CObjectInfo* pNewInfo )
  45. {
  46. m_pObjectInfo = pNewInfo;
  47. bool bVisible = pNewInfo != NULL;
  48. if ( m_pItemNameLabel )
  49. {
  50. if ( m_pObjectInfo )
  51. {
  52. m_pItemNameLabel->SetText( m_pObjectInfo->m_pBuilderWeaponName );
  53. }
  54. m_pItemNameLabel->SetVisible( bVisible );
  55. }
  56. if ( m_pItemCostLabel )
  57. {
  58. if ( m_pObjectInfo )
  59. {
  60. V_snprintf( m_pszCost, sizeof( m_pszCost ), "%i", m_pObjectInfo->m_Cost );
  61. m_pItemCostLabel->SetText( m_pszCost );
  62. }
  63. m_pItemCostLabel->SetVisible( bVisible );
  64. }
  65. if ( m_pIcon )
  66. {
  67. if ( m_pObjectInfo )
  68. {
  69. m_pIcon->SetIcon( m_pObjectInfo->m_pIconMenu );
  70. }
  71. m_pIcon->SetVisible( bVisible );
  72. }
  73. if ( m_pMetalIcon )
  74. {
  75. m_pMetalIcon->SetVisible( bVisible );
  76. }
  77. if ( m_pBackground )
  78. {
  79. m_pBackground->SetVisible( bVisible );
  80. }
  81. SetVisible( bVisible );
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Purpose:
  85. //-----------------------------------------------------------------------------
  86. void CBlueprintPanel::SetActAsButton( bool bClickable, bool bMouseOver )
  87. {
  88. m_bClickable = bClickable;
  89. m_bMouseOver = bMouseOver;
  90. SetMouseInputEnabled( m_bClickable || m_bMouseOver );
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose:
  94. //-----------------------------------------------------------------------------
  95. void CBlueprintPanel::OnCursorEntered( void )
  96. {
  97. if ( !m_bMouseOver )
  98. return;
  99. PostActionSignal( new KeyValues("BlueprintPanelEntered") );
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Purpose:
  103. //-----------------------------------------------------------------------------
  104. void CBlueprintPanel::OnCursorExited( void )
  105. {
  106. if ( !m_bMouseOver )
  107. return;
  108. PostActionSignal( new KeyValues("BlueprintPanelExited") );
  109. }
  110. //-----------------------------------------------------------------------------
  111. // Purpose:
  112. //-----------------------------------------------------------------------------
  113. void CBlueprintPanel::OnMousePressed(vgui::MouseCode code)
  114. {
  115. if ( !m_bClickable || code != MOUSE_LEFT )
  116. return;
  117. PostActionSignal( new KeyValues("BlueprintPanelMousePressed") );
  118. vgui::surface()->PlaySound( "UI/buttonclick.wav" );
  119. }
  120. //-----------------------------------------------------------------------------
  121. // Purpose:
  122. //-----------------------------------------------------------------------------
  123. void CBlueprintPanel::OnMouseReleased(vgui::MouseCode code)
  124. {
  125. if ( !m_bClickable || code != MOUSE_LEFT )
  126. return;
  127. PostActionSignal( new KeyValues("BlueprintPanelMouseReleased") );
  128. vgui::surface()->PlaySound( "UI/buttonclickrelease.wav" );
  129. }
  130. //-----------------------------------------------------------------------------
  131. // Purpose:
  132. //-----------------------------------------------------------------------------
  133. void CBlueprintPanel::OnMouseDoublePressed(vgui::MouseCode code)
  134. {
  135. if ( !m_bClickable || code != MOUSE_LEFT )
  136. return;
  137. PostActionSignal( new KeyValues("BlueprintPanelMouseDoublePressed") );
  138. vgui::surface()->PlaySound( "UI/buttonclickrelease.wav" );
  139. }
  140. //-----------------------------------------------------------------------------
  141. // Purpose:
  142. //-----------------------------------------------------------------------------
  143. void CBlueprintPanel::OnCursorMoved( int x, int y )
  144. {
  145. if ( !m_bClickable )
  146. return;
  147. // Add our own xpos/ypos offset
  148. int iXPos;
  149. int iYPos;
  150. GetPos( iXPos, iYPos );
  151. PostActionSignal( new KeyValues("BlueprintPanelCursorMoved", "x", x + iXPos, "y", y + iYPos) );
  152. }