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.

183 lines
5.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "ObjectControlPanel.h"
  9. #include <vgui_controls/Controls.h>
  10. #include <vgui_controls/Label.h>
  11. #include "vgui_bitmapbutton.h"
  12. #include <vgui/ISurface.h>
  13. #include <vgui/IVGui.h>
  14. #include "c_tf_player.h"
  15. #include "clientmode_tf.h"
  16. #include <vgui/IScheme.h>
  17. #include <vgui_controls/Slider.h>
  18. #include "vgui_rotation_slider.h"
  19. // memdbgon must be the last include file in a .cpp file!!!
  20. #include "tier0/memdbgon.h"
  21. #define DISMANTLE_WAIT_TIME 5.0
  22. //-----------------------------------------------------------------------------
  23. // Standard VGUI panel for objects
  24. //-----------------------------------------------------------------------------
  25. DECLARE_VGUI_SCREEN_FACTORY( CObjectControlPanel, "object_control_panel" );
  26. //-----------------------------------------------------------------------------
  27. // Constructor:
  28. //-----------------------------------------------------------------------------
  29. CObjectControlPanel::CObjectControlPanel( vgui::Panel *parent, const char *panelName )
  30. : BaseClass( parent, panelName, NULL )
  31. {
  32. // Make some high-level panels to group stuff we want to activate/deactivate
  33. m_pActivePanel = new CCommandChainingPanel( this, "ActivePanel" );
  34. SetCursor( vgui::dc_none ); // don't draw a VGUI cursor for this panel, and for its children
  35. // Make sure these are behind everything
  36. m_pActivePanel->SetZPos( -1 );
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Initialization
  40. //-----------------------------------------------------------------------------
  41. bool CObjectControlPanel::Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData )
  42. {
  43. // Make sure we get ticked...
  44. vgui::ivgui()->AddTickSignal( GetVPanel() );
  45. if (!BaseClass::Init(pKeyValues, pInitData))
  46. return false;
  47. SetCursor( vgui::dc_none ); // don't draw a VGUI cursor for this panel, and for its children
  48. // Make the bounds of the sub-panels match
  49. int x, y, w, h;
  50. GetBounds( x, y, w, h );
  51. m_pActivePanel->SetBounds( x, y, w, h );
  52. // Make em all invisible
  53. m_pActivePanel->SetVisible( false );
  54. m_pCurrentPanel = m_pActivePanel;
  55. return true;
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Returns the object it's attached to
  59. //-----------------------------------------------------------------------------
  60. C_BaseObject *CObjectControlPanel::GetOwningObject() const
  61. {
  62. C_BaseEntity *pScreenEnt = GetEntity();
  63. if (!pScreenEnt)
  64. return NULL;
  65. C_BaseEntity *pObj = pScreenEnt->GetOwnerEntity();
  66. if (!pObj)
  67. return NULL;
  68. Assert( dynamic_cast<C_BaseObject*>(pObj) );
  69. return static_cast<C_BaseObject*>(pObj);
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Ticks the panel when its in its various states
  73. //-----------------------------------------------------------------------------
  74. void CObjectControlPanel::OnTickActive( C_BaseObject *pObj, C_TFPlayer *pLocalPlayer )
  75. {
  76. //ShowDismantleButton( !(pObj->GetFlags() & OF_CANNOT_BE_DISMANTLED) && pObj->GetOwner() == pLocalPlayer );
  77. }
  78. vgui::Panel* CObjectControlPanel::TickCurrentPanel()
  79. {
  80. C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
  81. C_BaseObject *pObj = GetOwningObject();
  82. m_pCurrentPanel = GetActivePanel();
  83. OnTickActive(pObj, pLocalPlayer);
  84. return m_pCurrentPanel;
  85. }
  86. void CObjectControlPanel::SendToServerObject( const char *pMsg )
  87. {
  88. C_BaseObject *pObj = GetOwningObject();
  89. if (pObj)
  90. {
  91. pObj->SendClientCommand( pMsg );
  92. }
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Frame-based update
  96. //-----------------------------------------------------------------------------
  97. void CObjectControlPanel::OnTick()
  98. {
  99. BaseClass::OnTick();
  100. C_BaseObject *pObj = GetOwningObject();
  101. if (!pObj)
  102. return;
  103. if ( IsVisible() )
  104. {
  105. // Update the current subpanel
  106. m_pCurrentPanel->SetVisible( false );
  107. m_pCurrentPanel = TickCurrentPanel();
  108. m_pCurrentPanel->SetVisible( true );
  109. }
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Button click handlers
  113. //-----------------------------------------------------------------------------
  114. void CObjectControlPanel::OnCommand( const char *command )
  115. {
  116. BaseClass::OnCommand(command);
  117. }
  118. DECLARE_VGUI_SCREEN_FACTORY( CRotatingObjectControlPanel, "rotating_object_control_panel" );
  119. //-----------------------------------------------------------------------------
  120. // This is a panel for an object that has rotational controls
  121. //-----------------------------------------------------------------------------
  122. CRotatingObjectControlPanel::CRotatingObjectControlPanel( vgui::Panel *parent, const char *panelName )
  123. : BaseClass( parent, panelName )
  124. {
  125. }
  126. bool CRotatingObjectControlPanel::Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData )
  127. {
  128. // Grab ahold of certain well-known controls
  129. m_pRotationSlider = new CRotationSlider( GetActivePanel(), "RotationSlider" );
  130. m_pRotationLabel = new vgui::Label( GetActivePanel(), "RotationLabel", "Rotation Control" );
  131. if (!BaseClass::Init(pKeyValues, pInitData))
  132. return false;
  133. m_pRotationSlider->SetControlledObject( GetOwningObject() );
  134. return true;
  135. }
  136. void CRotatingObjectControlPanel::OnTickActive( C_BaseObject *pObj, C_TFPlayer *pLocalPlayer )
  137. {
  138. BaseClass::OnTickActive( pObj, pLocalPlayer );
  139. bool bEnable = (pObj->GetOwner() == pLocalPlayer);
  140. m_pRotationSlider->SetVisible( bEnable );
  141. m_pRotationLabel->SetVisible( bEnable );
  142. }