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.

295 lines
8.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: All matchmaking dialogs inherit from this
  4. //
  5. //=============================================================================//
  6. #include "vgui_controls/Label.h"
  7. #include "GameUI_Interface.h"
  8. #include "KeyValues.h"
  9. #include "basedialog.h"
  10. #include "BasePanel.h"
  11. #include "matchmakingbasepanel.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. //---------------------------------------------------------
  15. // CBaseDialog
  16. //---------------------------------------------------------
  17. CBaseDialog::CBaseDialog( vgui::Panel *pParent, const char *pName ) : BaseClass( pParent, pName )
  18. {
  19. SetTitleBarVisible( false );
  20. SetCloseButtonVisible( false );
  21. SetSizeable( false );
  22. m_pParent = pParent;
  23. m_Menu.SetParent( this );
  24. m_pTitle = new vgui::Label( this, "DialogTitle", "" );
  25. m_pFooterInfo = NULL;
  26. m_nBorderWidth = 0;
  27. m_nButtonGap = -1;
  28. }
  29. CBaseDialog::~CBaseDialog()
  30. {
  31. delete m_pTitle;
  32. if ( m_pFooterInfo )
  33. {
  34. m_pFooterInfo->deleteThis();
  35. }
  36. }
  37. //---------------------------------------------------------
  38. // Purpose: Activate the dialog
  39. //---------------------------------------------------------
  40. void CBaseDialog::Activate( void )
  41. {
  42. BaseClass::Activate();
  43. InvalidateLayout( false, false );
  44. }
  45. //---------------------------------------------------------
  46. // Purpose: Set the title and menu positions
  47. //---------------------------------------------------------
  48. void CBaseDialog::PerformLayout( void )
  49. {
  50. BaseClass::PerformLayout();
  51. m_pTitle->SizeToContents();
  52. int menux, menuy;
  53. m_Menu.GetPos( menux, menuy );
  54. int autoWide = m_Menu.GetWide() + m_nBorderWidth * 2;
  55. int autoTall = menuy + m_Menu.GetTall() + m_nBorderWidth;
  56. autoWide = max( autoWide, GetWide() );
  57. autoTall = max( autoTall, GetTall() );
  58. SetSize( autoWide, autoTall );
  59. if ( m_pFooterInfo && m_pParent )
  60. {
  61. CMatchmakingBasePanel *pBasePanel = dynamic_cast< CMatchmakingBasePanel* >( m_pParent );
  62. if ( pBasePanel )
  63. {
  64. // the base panel is our parent
  65. pBasePanel->SetFooterButtons( this, m_pFooterInfo, m_nButtonGap );
  66. }
  67. }
  68. if ( m_Menu.GetActiveItemIndex() == -1 )
  69. {
  70. m_Menu.SetFocus( 0 );
  71. }
  72. }
  73. //---------------------------------------------------------
  74. // Purpose: Setup sizes and positions
  75. //---------------------------------------------------------
  76. void CBaseDialog::ApplySettings( KeyValues *inResourceData )
  77. {
  78. BaseClass::ApplySettings( inResourceData );
  79. m_nBorderWidth = inResourceData->GetInt( "borderwidth", 0 );
  80. KeyValues *pFooter = inResourceData->FindKey( "Footer" );
  81. if ( pFooter )
  82. {
  83. m_pFooterInfo = pFooter->MakeCopy();
  84. }
  85. m_nButtonGap = inResourceData->GetInt( "footer_buttongap", -1 );
  86. }
  87. //---------------------------------------------------------
  88. // Purpose: Setup colors and fonts
  89. //---------------------------------------------------------
  90. void CBaseDialog::ApplySchemeSettings( vgui::IScheme *pScheme )
  91. {
  92. BaseClass::ApplySchemeSettings( pScheme );
  93. SetPaintBackgroundType( 2 );
  94. m_pTitle->SetFgColor( pScheme->GetColor( "MatchmakingDialogTitleColor", Color( 200, 184, 151, 255 ) ) );
  95. char szResourceName[MAX_PATH];
  96. Q_snprintf( szResourceName, sizeof( szResourceName ), "%s.res", GetName() );
  97. KeyValues *pKeys = BasePanel()->GetConsoleControlSettings()->FindKey( szResourceName );
  98. LoadControlSettings( "NULL", NULL, pKeys );
  99. }
  100. //-----------------------------------------------------------------
  101. // Purpose: Set the resource file to load this dialog's settings
  102. //-----------------------------------------------------------------
  103. void CBaseDialog::OnClose()
  104. {
  105. // Hide the rather ugly fade out
  106. SetAlpha( 0 );
  107. BaseClass::OnClose();
  108. }
  109. //-----------------------------------------------------------------
  110. // Purpose: Change properties of a menu item
  111. //-----------------------------------------------------------------
  112. void CBaseDialog::OverrideMenuItem( KeyValues *pKeys )
  113. {
  114. // Do nothing
  115. }
  116. //-----------------------------------------------------------------
  117. // Purpose: Swap the order of two menu items
  118. //-----------------------------------------------------------------
  119. void CBaseDialog::SwapMenuItems( int iOne, int iTwo )
  120. {
  121. // Do nothing
  122. }
  123. //-----------------------------------------------------------------
  124. // Purpose: Send key presses to the dialog's menu
  125. //-----------------------------------------------------------------
  126. void CBaseDialog::OnKeyCodePressed( vgui::KeyCode code )
  127. {
  128. if ( code == KEY_XBUTTON_START )
  129. {
  130. m_KeyRepeat.Reset();
  131. if ( GameUI().IsInLevel() )
  132. {
  133. m_pParent->OnCommand( "ResumeGame" );
  134. }
  135. return;
  136. }
  137. m_KeyRepeat.KeyDown( code );
  138. // Send down to the menu
  139. if ( !m_Menu.HandleKeyCode( code ) )
  140. {
  141. if ( code == KEY_XBUTTON_B )
  142. {
  143. OnCommand( "DialogClosing" );
  144. SetDeleteSelfOnClose( true );
  145. }
  146. else
  147. {
  148. BaseClass::OnKeyCodePressed( code );
  149. }
  150. }
  151. }
  152. //-----------------------------------------------------------------------------
  153. // Purpose:
  154. //-----------------------------------------------------------------------------
  155. void CBaseDialog::OnKeyCodeReleased( vgui::KeyCode code )
  156. {
  157. m_KeyRepeat.KeyUp( code );
  158. BaseClass::OnKeyCodeReleased( code );
  159. }
  160. //-----------------------------------------------------------------------------
  161. // Purpose:
  162. //-----------------------------------------------------------------------------
  163. void CBaseDialog::HandleKeyRepeated( vgui::KeyCode code )
  164. {
  165. m_Menu.HandleKeyCode( code );
  166. }
  167. //-----------------------------------------------------------------------------
  168. // Purpose:
  169. //-----------------------------------------------------------------------------
  170. void CBaseDialog::OnThink()
  171. {
  172. vgui::KeyCode code = m_KeyRepeat.KeyRepeated();
  173. if ( code )
  174. {
  175. if ( HasFocus() )
  176. {
  177. HandleKeyRepeated( code );
  178. }
  179. else
  180. {
  181. // This can happen because of the slight delay after selecting a
  182. // menu option and the resulting action. The selection caused the
  183. // key repeater to be reset, but the player can press a movement
  184. // key before the action occurs, leaving us with a key repeating
  185. // on this dialog even though it no longer has focus.
  186. m_KeyRepeat.Reset();
  187. }
  188. }
  189. BaseClass::OnThink();
  190. }
  191. //-----------------------------------------------------------------
  192. // Purpose: Forward commands to the matchmaking base panel
  193. //-----------------------------------------------------------------
  194. void CBaseDialog::OnCommand( const char *pCommand )
  195. {
  196. m_KeyRepeat.Reset();
  197. m_pParent->OnCommand( pCommand );
  198. }
  199. //---------------------------------------------------------------------
  200. // Helper object to display the map picture and descriptive text
  201. //---------------------------------------------------------------------
  202. CScenarioInfoPanel::CScenarioInfoPanel( vgui::Panel *parent, const char *pName ) : BaseClass( parent, pName )
  203. {
  204. m_pMapImage = new vgui::ImagePanel( this, "MapImage" );
  205. m_pTitle = new CPropertyLabel( this, "Title", "" );
  206. m_pSubtitle = new CPropertyLabel( this, "Subtitle", "" );
  207. m_pDescOne = new CPropertyLabel( this, "DescOne", "" );
  208. m_pDescTwo = new CPropertyLabel( this, "DescTwo", "" );
  209. m_pDescThree = new CPropertyLabel( this, "DescThree", "" );
  210. m_pValueTwo = new CPropertyLabel( this, "ValueTwo", "" );
  211. m_pValueThree = new CPropertyLabel( this, "ValueThree", "" );
  212. }
  213. CScenarioInfoPanel::~CScenarioInfoPanel()
  214. {
  215. delete m_pMapImage;
  216. delete m_pTitle;
  217. delete m_pSubtitle;
  218. delete m_pDescOne;
  219. delete m_pDescTwo;
  220. delete m_pDescThree;
  221. delete m_pValueTwo;
  222. delete m_pValueThree;
  223. }
  224. void CScenarioInfoPanel::PerformLayout( void )
  225. {
  226. BaseClass::PerformLayout();
  227. }
  228. void CScenarioInfoPanel::ApplySettings( KeyValues *pResourceData )
  229. {
  230. BaseClass::ApplySettings( pResourceData );
  231. }
  232. void CScenarioInfoPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
  233. {
  234. BaseClass::ApplySchemeSettings( pScheme );
  235. Color fontColor = pScheme->GetColor( "MatchmakingDialogTitleColor", Color( 0, 0, 0, 255 ) );
  236. m_pTitle->SetFgColor( fontColor );
  237. m_pSubtitle->SetFgColor( fontColor );
  238. m_pDescOne->SetFgColor( fontColor );
  239. m_pDescTwo->SetFgColor( fontColor );
  240. m_pDescThree->SetFgColor( fontColor );
  241. m_pValueTwo->SetFgColor( fontColor );
  242. m_pValueThree->SetFgColor( fontColor );
  243. SetPaintBackgroundType( 2 );
  244. KeyValues *pKeys = BasePanel()->GetConsoleControlSettings()->FindKey( "ScenarioInfoPanel.res" );
  245. ApplySettings( pKeys );
  246. }
  247. DECLARE_BUILD_FACTORY( CScenarioInfoPanel );