Counter Strike : Global Offensive Source Code
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.

279 lines
7.3 KiB

  1. //========= Copyright � 1996-2001, Valve LLC, All rights reserved. ============
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "pch_serverbrowser.h"
  8. using namespace vgui;
  9. //-----------------------------------------------------------------------------
  10. // Purpose: Invisible panel that forwards up mouse movement
  11. //-----------------------------------------------------------------------------
  12. class CMouseMessageForwardingPanel : public vgui::Panel
  13. {
  14. DECLARE_CLASS_SIMPLE( CMouseMessageForwardingPanel, vgui::Panel );
  15. public:
  16. CMouseMessageForwardingPanel( Panel *parent, const char *name );
  17. virtual void PerformLayout( void );
  18. virtual void OnMousePressed( vgui::MouseCode code );
  19. virtual void OnMouseDoublePressed( vgui::MouseCode code );
  20. virtual void OnMouseWheeled(int delta);
  21. };
  22. CMouseMessageForwardingPanel::CMouseMessageForwardingPanel( Panel *parent, const char *name ) : BaseClass( parent, name )
  23. {
  24. // don't draw an
  25. SetPaintEnabled(false);
  26. SetPaintBackgroundEnabled(false);
  27. SetPaintBorderEnabled(false);
  28. }
  29. void CMouseMessageForwardingPanel::PerformLayout()
  30. {
  31. // fill out the whole area
  32. int w, t;
  33. GetParent()->GetSize(w, t);
  34. SetBounds(0, 0, w, t);
  35. }
  36. void CMouseMessageForwardingPanel::OnMousePressed( vgui::MouseCode code )
  37. {
  38. if ( GetParent() )
  39. {
  40. GetParent()->OnMousePressed( code );
  41. }
  42. }
  43. void CMouseMessageForwardingPanel::OnMouseDoublePressed( vgui::MouseCode code )
  44. {
  45. if ( GetParent() )
  46. {
  47. GetParent()->OnMouseDoublePressed( code );
  48. }
  49. }
  50. void CMouseMessageForwardingPanel::OnMouseWheeled(int delta)
  51. {
  52. if ( GetParent() )
  53. {
  54. GetParent()->OnMouseWheeled( delta );
  55. }
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose:
  59. //-----------------------------------------------------------------------------
  60. CQuickListPanel::CQuickListPanel( vgui::Panel* pParent, const char *pElementName ) : BaseClass( pParent, pElementName )
  61. {
  62. SetParent( pParent );
  63. m_pListPanelParent = pParent;
  64. CMouseMessageForwardingPanel *panel = new CMouseMessageForwardingPanel(this, NULL);
  65. panel->SetZPos(3);
  66. m_pLatencyImage = new ImagePanel( this, "latencyimage" );
  67. m_pPlayerCountLabel = new Label( this, "playercount", "" );
  68. m_pServerNameLabel = new Label( this, "servername", "" );
  69. m_pBGroundPanel = new Panel( this, "background" );
  70. m_pMapImage = new ImagePanel( this, "mapimage" );
  71. m_pGameTypeLabel = new Label( this, "gametype", "" );
  72. m_pMapNameLabel = new Label( this, "mapname", "" );
  73. m_pLatencyLabel = new Label( this, "latencytext", "" );
  74. const char *pPathID = "PLATFORM";
  75. if ( g_pFullFileSystem->FileExists( "servers/QuickListPanel.res", "MOD" ) )
  76. {
  77. pPathID = "MOD";
  78. }
  79. LoadControlSettings( "servers/QuickListPanel.res", pPathID );
  80. }
  81. //-----------------------------------------------------------------------------
  82. // Purpose:
  83. //-----------------------------------------------------------------------------
  84. void CQuickListPanel::ApplySchemeSettings(IScheme *pScheme)
  85. {
  86. BaseClass::ApplySchemeSettings(pScheme);
  87. if ( pScheme && m_pBGroundPanel )
  88. {
  89. m_pBGroundPanel->SetBgColor( pScheme->GetColor("QuickListBGDeselected", Color(255, 255, 255, 0 ) ) );
  90. }
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose:
  94. //-----------------------------------------------------------------------------
  95. void CQuickListPanel::SetRefreshing( void )
  96. {
  97. if ( m_pServerNameLabel )
  98. {
  99. m_pServerNameLabel->SetText( g_pVGuiLocalize->Find("#ServerBrowser_QuickListRefreshing") );
  100. }
  101. if ( m_pPlayerCountLabel )
  102. {
  103. m_pPlayerCountLabel->SetVisible( false );
  104. }
  105. if ( m_pLatencyImage )
  106. {
  107. m_pLatencyImage->SetVisible( false );
  108. }
  109. if ( m_pLatencyLabel )
  110. {
  111. m_pLatencyLabel->SetVisible( false );
  112. }
  113. }
  114. //-----------------------------------------------------------------------------
  115. // Purpose:
  116. //-----------------------------------------------------------------------------
  117. void CQuickListPanel::SetMapName( const char *pMapName )
  118. {
  119. Q_strncpy( m_szMapName, pMapName, sizeof( m_szMapName ) );
  120. if ( m_pMapNameLabel )
  121. {
  122. m_pMapNameLabel->SetText( pMapName );
  123. m_pMapNameLabel->SizeToContents();
  124. }
  125. }
  126. //-----------------------------------------------------------------------------
  127. // Purpose:
  128. //-----------------------------------------------------------------------------
  129. void CQuickListPanel::SetGameType( const char *pGameType )
  130. {
  131. if ( strlen ( pGameType ) == 0 )
  132. {
  133. m_pGameTypeLabel->SetVisible( false );
  134. return;
  135. }
  136. char gametype[ 512 ];
  137. Q_snprintf( gametype, sizeof( gametype ), "(%s)", pGameType );
  138. m_pGameTypeLabel->SetText( gametype );
  139. }
  140. //-----------------------------------------------------------------------------
  141. // Purpose:
  142. //-----------------------------------------------------------------------------
  143. void CQuickListPanel::SetServerInfo ( KeyValues *pKV, int iListID )
  144. {
  145. if ( pKV == NULL )
  146. return;
  147. m_iListID = iListID;
  148. m_pServerNameLabel->SetText( pKV->GetString( "name", " " ) );
  149. int iPing = pKV->GetInt( "ping", 0 );
  150. if ( iPing <= 100 )
  151. {
  152. m_pLatencyImage->SetImage( "../vgui/icon_con_high.vmt" );
  153. }
  154. else if ( iPing <= 150 )
  155. {
  156. m_pLatencyImage->SetImage( "../vgui/icon_con_medium.vmt" );
  157. }
  158. else
  159. {
  160. m_pLatencyImage->SetImage( "../vgui/icon_con_low.vmt" );
  161. }
  162. m_pLatencyImage->SetVisible( false );
  163. char ping[ 512 ];
  164. Q_snprintf( ping, sizeof( ping ), "%d ms", iPing );
  165. m_pLatencyLabel->SetText( ping );
  166. m_pLatencyLabel->SetVisible( true );
  167. wchar_t players[ 512 ];
  168. wchar_t playercount[16];
  169. wchar_t *pwszPlayers = g_pVGuiLocalize->Find("#ServerBrowser_Players");
  170. g_pVGuiLocalize->ConvertANSIToUnicode( pKV->GetString( "players", " " ), playercount, sizeof( playercount ) );
  171. _snwprintf( players, ARRAYSIZE( players ), L"%ls %ls", playercount, pwszPlayers );
  172. m_pPlayerCountLabel->SetText( players );
  173. m_pPlayerCountLabel->SetVisible( true );
  174. }
  175. //-----------------------------------------------------------------------------
  176. // Purpose:
  177. //-----------------------------------------------------------------------------
  178. void CQuickListPanel::SetImage( const char *pMapName )
  179. {
  180. char path[ 512 ];
  181. Q_snprintf( path, sizeof( path ), "materials/vgui/maps/menu_thumb_%s.vmt", pMapName );
  182. char map[ 512 ];
  183. Q_snprintf( map, sizeof( map ), "maps/%s.bsp", pMapName );
  184. if ( g_pFullFileSystem->FileExists( map, "MOD" ) == false )
  185. {
  186. pMapName = "default_download";
  187. }
  188. else
  189. {
  190. if ( g_pFullFileSystem->FileExists( path, "MOD" ) == false )
  191. {
  192. pMapName = "default";
  193. }
  194. }
  195. if ( m_pMapImage )
  196. {
  197. char imagename[ 512 ];
  198. Q_snprintf( imagename, sizeof( imagename ), "..\\vgui\\maps\\menu_thumb_%s", pMapName );
  199. m_pMapImage->SetImage ( imagename );
  200. m_pMapImage->SetMouseInputEnabled( false );
  201. }
  202. }
  203. void CQuickListPanel::OnMousePressed( vgui::MouseCode code )
  204. {
  205. if ( m_pListPanelParent )
  206. {
  207. vgui::PanelListPanel *pParent = dynamic_cast < vgui::PanelListPanel *> ( m_pListPanelParent );
  208. if ( pParent )
  209. {
  210. pParent->SetSelectedPanel( this );
  211. m_pListPanelParent->CallParentFunction( new KeyValues("ItemSelected", "itemID", -1 ) );
  212. }
  213. if ( code == MOUSE_RIGHT )
  214. {
  215. m_pListPanelParent->CallParentFunction( new KeyValues("OpenContextMenu", "itemID", -1 ) );
  216. }
  217. }
  218. }
  219. void CQuickListPanel::OnMouseDoublePressed( vgui::MouseCode code )
  220. {
  221. if ( code == MOUSE_RIGHT )
  222. return;
  223. // call the panel
  224. OnMousePressed( code );
  225. m_pListPanelParent->CallParentFunction( new KeyValues("ConnectToServer", "code", code) );
  226. }