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.

227 lines
8.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "CreateMultiplayerGameBotPage.h"
  9. using namespace vgui;
  10. #include <KeyValues.h>
  11. #include <vgui_controls/ComboBox.h>
  12. #include <vgui_controls/CheckButton.h>
  13. #include <vgui_controls/Label.h>
  14. #include <vgui_controls/TextEntry.h>
  15. #include "FileSystem.h"
  16. #include "PanelListPanel.h"
  17. #include "ScriptObject.h"
  18. #include "tier1/convar.h"
  19. #include "EngineInterface.h"
  20. #include "CvarToggleCheckButton.h"
  21. // memdbgon must be the last include file in a .cpp file!!!
  22. #include <tier0/memdbgon.h>
  23. // for join team combo box
  24. enum BotGUITeamType
  25. {
  26. BOT_GUI_TEAM_RANDOM = 0,
  27. BOT_GUI_TEAM_CT = 1,
  28. BOT_GUI_TEAM_T = 2
  29. };
  30. // these must correlate with above enum
  31. static const char *joinTeamArg[] = { "any", "ct", "t", NULL };
  32. // for bot chatter combo box
  33. enum BotGUIChatterType
  34. {
  35. BOT_GUI_CHATTER_NORMAL = 0,
  36. BOT_GUI_CHATTER_MINIMAL = 1,
  37. BOT_GUI_CHATTER_RADIO = 2,
  38. BOT_GUI_CHATTER_OFF = 3
  39. };
  40. // these must correlate with above enum
  41. static const char *chatterArg[] = { "normal", "minimal", "radio", "off", NULL };
  42. extern void UTIL_StripInvalidCharacters( char *pszInput );
  43. //-----------------------------------------------------------------------------
  44. void CCreateMultiplayerGameBotPage::SetJoinTeamCombo( const char *team )
  45. {
  46. if (team)
  47. {
  48. for( int i=0; joinTeamArg[i]; ++i )
  49. if (!stricmp( team, joinTeamArg[i] ))
  50. {
  51. m_joinTeamCombo->ActivateItemByRow( i );
  52. return;
  53. }
  54. }
  55. else
  56. {
  57. m_joinTeamCombo->ActivateItemByRow( BOT_GUI_TEAM_RANDOM );
  58. }
  59. }
  60. //-----------------------------------------------------------------------------
  61. void CCreateMultiplayerGameBotPage::SetChatterCombo( const char *chatter )
  62. {
  63. if (chatter)
  64. {
  65. for( int i=0; chatterArg[i]; ++i )
  66. if (!stricmp( chatter, chatterArg[i] ))
  67. {
  68. m_chatterCombo->ActivateItemByRow( i );
  69. return;
  70. }
  71. }
  72. else
  73. {
  74. m_joinTeamCombo->ActivateItemByRow( BOT_GUI_CHATTER_NORMAL );
  75. }
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Constructor
  79. //-----------------------------------------------------------------------------
  80. CCreateMultiplayerGameBotPage::CCreateMultiplayerGameBotPage( vgui::Panel *parent, const char *name, KeyValues *botKeys ) : PropertyPage( parent, name )
  81. {
  82. m_pSavedData = botKeys;
  83. m_allowRogues = new CCvarToggleCheckButton( this, "BotAllowRogueCheck", "", "bot_allow_rogues" );
  84. m_allowPistols = new CCvarToggleCheckButton( this, "BotAllowPistolsCheck", "", "bot_allow_pistols" );
  85. m_allowShotguns = new CCvarToggleCheckButton( this, "BotAllowShotgunsCheck", "", "bot_allow_shotguns" );
  86. m_allowSubmachineGuns = new CCvarToggleCheckButton( this, "BotAllowSubmachineGunsCheck", "", "bot_allow_sub_machine_guns" );
  87. m_allowRifles = new CCvarToggleCheckButton( this, "BotAllowRiflesCheck", "", "bot_allow_rifles" );
  88. m_allowMachineGuns = new CCvarToggleCheckButton( this, "BotAllowMachineGunsCheck", "", "bot_allow_machine_guns" );
  89. m_allowGrenades = new CCvarToggleCheckButton( this, "BotAllowGrenadesCheck", "", "bot_allow_grenades" );
  90. m_allowSnipers = new CCvarToggleCheckButton( this, "BotAllowSnipersCheck", "", "bot_allow_snipers" );
  91. #ifdef CS_SHIELD_ENABLED
  92. m_allowShields = new CCvarToggleCheckButton( this, "BotAllowShieldCheck", "", "bot_allow_shield" );
  93. #endif // CS_SHIELD_ENABLED
  94. m_joinAfterPlayer = new CCvarToggleCheckButton( this, "BotJoinAfterPlayerCheck", "", "bot_join_after_player" );
  95. m_deferToHuman = new CCvarToggleCheckButton( this, "BotDeferToHumanCheck", "", "bot_defer_to_human" );
  96. // set up team join combo box
  97. // NOTE: If order of AddItem is changed, update the associated enum
  98. m_joinTeamCombo = new ComboBox( this, "BotJoinTeamCombo", 3, false );
  99. m_joinTeamCombo->AddItem( "#Cstrike_Random", NULL );
  100. m_joinTeamCombo->AddItem( "#Cstrike_ScoreBoard_CT", NULL );
  101. m_joinTeamCombo->AddItem( "#Cstrike_ScoreBoard_Ter", NULL );
  102. // set up chatter combo box
  103. // NOTE: If order of AddItem is changed, update the associated enum
  104. m_chatterCombo = new ComboBox( this, "BotChatterCombo", 4, false );
  105. m_chatterCombo->AddItem( "#Cstrike_Bot_Chatter_Normal", NULL );
  106. m_chatterCombo->AddItem( "#Cstrike_Bot_Chatter_Minimal", NULL );
  107. m_chatterCombo->AddItem( "#Cstrike_Bot_Chatter_Radio", NULL );
  108. m_chatterCombo->AddItem( "#Cstrike_Bot_Chatter_Off", NULL );
  109. // create text entry fields for quota and prefix
  110. m_prefixEntry = new TextEntry( this, "BotPrefixEntry" );
  111. // set positions and sizes from resources file
  112. LoadControlSettings( "Resource/CreateMultiplayerGameBotPage.res" );
  113. // get initial values from bot keys
  114. m_joinAfterPlayer->SetSelected( botKeys->GetBool( "bot_join_after_player", true ) );
  115. m_allowRogues->SetSelected( botKeys->GetBool( "bot_allow_rogues", true ) );
  116. m_allowPistols->SetSelected( botKeys->GetBool( "bot_allow_pistols", true ) );
  117. m_allowShotguns->SetSelected( botKeys->GetBool( "bot_allow_shotguns", true ) );
  118. m_allowSubmachineGuns->SetSelected( botKeys->GetBool( "bot_allow_sub_machine_guns", true ) );
  119. m_allowMachineGuns->SetSelected( botKeys->GetBool( "bot_allow_machine_guns", true ) );
  120. m_allowRifles->SetSelected( botKeys->GetBool( "bot_allow_rifles", true ) );
  121. m_allowSnipers->SetSelected( botKeys->GetBool( "bot_allow_snipers", true ) );
  122. m_allowGrenades->SetSelected( botKeys->GetBool( "bot_allow_grenades", true ) );
  123. #ifdef CS_SHIELD_ENABLED
  124. m_allowShields->SetSelected( botKeys->GetBool( "bot_allow_shield", true ) );
  125. #endif // CS_SHIELD_ENABLED
  126. m_deferToHuman->SetSelected( botKeys->GetBool( "bot_defer_to_human", true ) );
  127. SetJoinTeamCombo( botKeys->GetString( "bot_join_team", "any" ) );
  128. SetChatterCombo( botKeys->GetString( "bot_chatter", "normal" ) );
  129. // set bot_prefix
  130. const char *prefix = botKeys->GetString( "bot_prefix" );
  131. if (prefix)
  132. SetControlString( "BotPrefixEntry", prefix );
  133. }
  134. //-----------------------------------------------------------------------------
  135. // Destructor
  136. //-----------------------------------------------------------------------------
  137. CCreateMultiplayerGameBotPage::~CCreateMultiplayerGameBotPage()
  138. {
  139. // vgui handles deletion of children automatically through the hierarchy
  140. }
  141. //-----------------------------------------------------------------------------
  142. // Reset values
  143. //-----------------------------------------------------------------------------
  144. void CCreateMultiplayerGameBotPage::OnResetChanges()
  145. {
  146. }
  147. //-----------------------------------------------------------------------------
  148. //-----------------------------------------------------------------------------
  149. void UpdateValue( KeyValues *data, const char *cvarName, int value )
  150. {
  151. data->SetInt( cvarName, value );
  152. ConVarRef var( cvarName );
  153. var.SetValue( value );
  154. }
  155. //-----------------------------------------------------------------------------
  156. //-----------------------------------------------------------------------------
  157. void UpdateValue( KeyValues *data, const char *cvarName, const char *value )
  158. {
  159. data->SetString( cvarName, value );
  160. ConVarRef var( cvarName );
  161. var.SetValue( value );
  162. }
  163. //-----------------------------------------------------------------------------
  164. // Called to get data from the page
  165. //-----------------------------------------------------------------------------
  166. void CCreateMultiplayerGameBotPage::OnApplyChanges()
  167. {
  168. UpdateValue( m_pSavedData, "bot_join_after_player", m_joinAfterPlayer->IsSelected() );
  169. UpdateValue( m_pSavedData, "bot_allow_rogues", m_allowRogues->IsSelected() );
  170. UpdateValue( m_pSavedData, "bot_allow_pistols", m_allowPistols->IsSelected() );
  171. UpdateValue( m_pSavedData, "bot_allow_shotguns", m_allowShotguns->IsSelected() );
  172. UpdateValue( m_pSavedData, "bot_allow_sub_machine_guns", m_allowSubmachineGuns->IsSelected() );
  173. UpdateValue( m_pSavedData, "bot_allow_machine_guns", m_allowMachineGuns->IsSelected() );
  174. UpdateValue( m_pSavedData, "bot_allow_rifles", m_allowRifles->IsSelected() );
  175. UpdateValue( m_pSavedData, "bot_allow_snipers", m_allowSnipers->IsSelected() );
  176. UpdateValue( m_pSavedData, "bot_allow_grenades", m_allowGrenades->IsSelected() );
  177. #ifdef CS_SHIELD_ENABLED
  178. UpdateValue( m_pSavedData, "bot_allow_shield", m_allowShields->IsSelected() );
  179. #endif // CS_SHIELD_ENABLED
  180. UpdateValue( m_pSavedData, "bot_defer_to_human", m_deferToHuman->IsSelected() );
  181. // set bot_join_team
  182. UpdateValue( m_pSavedData, "bot_join_team", joinTeamArg[ m_joinTeamCombo->GetActiveItem() ] );
  183. // set bot_chatter
  184. UpdateValue( m_pSavedData, "bot_chatter", chatterArg[ m_chatterCombo->GetActiveItem() ] );
  185. // set bot_prefix
  186. #define BUF_LENGTH 256
  187. char entryBuffer[ BUF_LENGTH ];
  188. m_prefixEntry->GetText( entryBuffer, BUF_LENGTH );
  189. UpdateValue( m_pSavedData, "bot_prefix", entryBuffer );
  190. }