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.

282 lines
8.5 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifdef DEBUG
  7. #include "cbase.h"
  8. #include "ienginevgui.h"
  9. #include "gameui_interface.h"
  10. #include "basepanel.h"
  11. #include "vgui/ILocalize.h"
  12. #include "vgui/ISurface.h"
  13. #include "vgui/ISystem.h"
  14. #include "vgui/IVGui.h"
  15. #include "vgui_controls/PanelListPanel.h"
  16. #include "vgui_controls/TextEntry.h"
  17. #include "vgui_controls/ListPanel.h"
  18. #include "vgui_controls/FileOpenDialog.h"
  19. #include "vgui_controls/ComboBox.h"
  20. #include "vgui_controls/CheckButton.h"
  21. #include "vgui_controls/RadioButton.h"
  22. #include "vgui_controls/Slider.h"
  23. #include "vgui_controls/MessageBox.h"
  24. #include "matsys_controls/colorpickerpanel.h"
  25. #include "matsys_controls/vtfpreviewpanel.h"
  26. #include "filesystem.h"
  27. #include "keyvalues.h"
  28. #include "engineinterface.h"
  29. #include "gameui_interface.h"
  30. #include "vstdlib/random.h"
  31. #include "ironsight_editor.h"
  32. #ifdef IRONSIGHT
  33. CIronSightDialog *g_pIronSightDialog = NULL;
  34. using namespace vgui;
  35. // memdbgon must be the last include file in a .cpp file!!!
  36. #include "tier0/memdbgon.h"
  37. extern ConVar ironsight_position;
  38. extern ConVar ironsight_angle;
  39. extern ConVar ironsight_fov;
  40. extern ConVar ironsight_override;
  41. extern ConVar ironsight_pivot_forward;
  42. extern ConVar ironsight_looseness;
  43. //-----------------------------------------------------------------------------
  44. // Purpose:
  45. //-----------------------------------------------------------------------------
  46. CIronSightDialog::CIronSightDialog(vgui::Panel *parent) : BaseClass(parent, "IronSightDialog")
  47. {
  48. SetDeleteSelfOnClose(true);
  49. SetSizeable( false );
  50. MoveToCenterOfScreen();
  51. m_pSliderPosX = new vgui::Slider( this, "SliderPosX" );
  52. m_pSliderPosX->AddActionSignalTarget( this );
  53. m_pSliderPosX->SetRange( -100, 100 );
  54. m_pSliderPosX->SetDragOnRepositionNob( true );
  55. m_pSliderPosY = new vgui::Slider( this, "SliderPosY" );
  56. m_pSliderPosY->AddActionSignalTarget( this );
  57. m_pSliderPosY->SetRange( -100, 100 );
  58. m_pSliderPosY->SetDragOnRepositionNob( true );
  59. m_pSliderPosZ = new vgui::Slider( this, "SliderPosZ" );
  60. m_pSliderPosZ->AddActionSignalTarget( this );
  61. m_pSliderPosZ->SetRange( -100, 100 );
  62. m_pSliderPosZ->SetDragOnRepositionNob( true );
  63. m_pSliderRotX = new vgui::Slider( this, "SliderRotX" );
  64. m_pSliderRotX->AddActionSignalTarget( this );
  65. m_pSliderRotX->SetRange( -100, 100 );
  66. m_pSliderRotX->SetDragOnRepositionNob( true );
  67. m_pSliderRotY = new vgui::Slider( this, "SliderRotY" );
  68. m_pSliderRotY->AddActionSignalTarget( this );
  69. m_pSliderRotY->SetRange( -100, 100 );
  70. m_pSliderRotY->SetDragOnRepositionNob( true );
  71. m_pSliderRotZ = new vgui::Slider( this, "SliderRotZ" );
  72. m_pSliderRotZ->AddActionSignalTarget( this );
  73. m_pSliderRotZ->SetRange( -100, 100 );
  74. m_pSliderRotZ->SetDragOnRepositionNob( true );
  75. m_pSliderFOV = new vgui::Slider( this, "SliderFOV" );
  76. m_pSliderFOV->AddActionSignalTarget( this );
  77. m_pSliderFOV->SetRange( 10, 90 );
  78. m_pSliderFOV->SetDragOnRepositionNob( true );
  79. m_pSliderFOV->SetValue(90);
  80. m_pSliderPivotForward = new vgui::Slider( this, "SliderPivotForward" );
  81. m_pSliderPivotForward->AddActionSignalTarget( this );
  82. m_pSliderPivotForward->SetRange( -20, 20 );
  83. m_pSliderPivotForward->SetDragOnRepositionNob( true );
  84. m_pSliderPivotForward->SetValue(0);
  85. m_pSliderLooseness = new vgui::Slider( this, "SliderLooseness" );
  86. m_pSliderLooseness->AddActionSignalTarget( this );
  87. m_pSliderLooseness->SetRange( 0, 100 );
  88. m_pSliderLooseness->SetDragOnRepositionNob( true );
  89. m_pSliderLooseness->SetValue(100);
  90. m_pSchemaText = new vgui::TextEntry( this, "SchemaText" );
  91. m_pSchemaText->AddActionSignalTarget( this );
  92. m_pSchemaText->SetMultiline( true );
  93. LoadControlSettings("Resource/ironsight_dialog.res");
  94. m_vecPosBackup = Vector(0,0,0);
  95. m_vecRotBackup = Vector(0,0,0);
  96. sscanf( ironsight_position.GetString(), "%f %f %f", &m_vecPosBackup.x, &m_vecPosBackup.y, &m_vecPosBackup.z );
  97. m_pSliderPosX->SetValue(0);
  98. m_pSliderPosY->SetValue(0);
  99. m_pSliderPosZ->SetValue(0);
  100. sscanf( ironsight_angle.GetString(), "%f %f %f", &m_vecRotBackup.x, &m_vecRotBackup.y, &m_vecRotBackup.z );
  101. m_pSliderRotX->SetValue(0);
  102. m_pSliderRotY->SetValue(0);
  103. m_pSliderRotZ->SetValue(0);
  104. m_pSliderFOV->SetValue( ironsight_fov.GetFloat() );
  105. m_pSliderPivotForward->SetValue( ironsight_pivot_forward.GetFloat() );
  106. m_pSliderLooseness->SetValue( ironsight_looseness.GetFloat() * 100.0f );
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. //-----------------------------------------------------------------------------
  111. CIronSightDialog::~CIronSightDialog()
  112. {
  113. delete m_pSliderPosX;
  114. delete m_pSliderPosY;
  115. delete m_pSliderPosZ;
  116. delete m_pSliderRotX;
  117. delete m_pSliderRotY;
  118. delete m_pSliderRotZ;
  119. delete m_pSliderFOV;
  120. delete m_pSliderPivotForward;
  121. delete m_pSchemaText;
  122. }
  123. //-----------------------------------------------------------------------------
  124. // Purpose:
  125. //-----------------------------------------------------------------------------
  126. void CIronSightDialog::OnClose( void )
  127. {
  128. BaseClass::OnClose();
  129. }
  130. //-----------------------------------------------------------------------------
  131. // Purpose:
  132. // Input : *command -
  133. //-----------------------------------------------------------------------------
  134. void CIronSightDialog::OnMessage( const KeyValues *pParams, vgui::VPANEL fromPanel )
  135. {
  136. if ( !Q_strcmp( "SliderMoved", pParams->GetName() ) )
  137. {
  138. char szTemp[128];
  139. V_snprintf( szTemp, 128, "%f %f %f",
  140. float( m_vecPosBackup.x + m_pSliderPosX->GetValue() * 0.01f ),
  141. float( m_vecPosBackup.y + m_pSliderPosY->GetValue() * 0.01f ),
  142. float( m_vecPosBackup.z + m_pSliderPosZ->GetValue() * 0.01f ) );
  143. //Msg( "ironsight_position: %s\n", szTemp );
  144. ironsight_position.SetValue( szTemp );
  145. V_snprintf( szTemp, 128, "%f %f %f",
  146. float( m_vecRotBackup.x + m_pSliderRotX->GetValue() * 0.01f ),
  147. float( m_vecRotBackup.y + m_pSliderRotY->GetValue() * 0.01f ),
  148. float( m_vecRotBackup.z + m_pSliderRotZ->GetValue() * 0.01f ) );
  149. //Msg( "ironsight_angle: %s\n", szTemp );
  150. ironsight_angle.SetValue( szTemp );
  151. ironsight_fov.SetValue( m_pSliderFOV->GetValue() );
  152. ironsight_pivot_forward.SetValue( m_pSliderPivotForward->GetValue() );
  153. ironsight_looseness.SetValue( m_pSliderLooseness->GetValue() * 0.01f );
  154. char szSchemaText[512];
  155. V_snprintf(szSchemaText, 512, "\"ironsight eye pos\" \"%s\"\n\"ironsight pivot angle\" \"%s\"\n\"ironsight fov\" \"%s\"\n\"ironsight pivot forward\" \"%s\"\n\"ironsight looseness\" \"%f\"",
  156. ironsight_position.GetString(),
  157. ironsight_angle.GetString(),
  158. ironsight_fov.GetString(),
  159. ironsight_pivot_forward.GetString(),
  160. ironsight_looseness.GetFloat()
  161. );
  162. m_pSchemaText->SetText( szSchemaText );
  163. }
  164. else if ( !Q_strcmp( "SliderDragEnd", pParams->GetName() ) )
  165. {
  166. sscanf( ironsight_position.GetString(), "%f %f %f", &m_vecPosBackup.x, &m_vecPosBackup.y, &m_vecPosBackup.z );
  167. m_pSliderPosX->SetValue(0);
  168. m_pSliderPosY->SetValue(0);
  169. m_pSliderPosZ->SetValue(0);
  170. sscanf( ironsight_angle.GetString(), "%f %f %f", &m_vecRotBackup.x, &m_vecRotBackup.y, &m_vecRotBackup.z );
  171. m_pSliderRotX->SetValue(0);
  172. m_pSliderRotY->SetValue(0);
  173. m_pSliderRotZ->SetValue(0);
  174. }
  175. else if ( !Q_strcmp( "CloseFrameButtonPressed", pParams->GetName() ) )
  176. {
  177. Close();
  178. }
  179. else if ( !Q_strcmp( "CheckButtonChecked", pParams->GetName() ) )
  180. {
  181. ironsight_override.SetValue( pParams->MakeCopy()->GetInt("state") );
  182. }
  183. else
  184. {
  185. BaseClass::OnMessage( pParams, fromPanel );
  186. }
  187. /*
  188. //don't spew these
  189. if ( Q_strcmp( "OnMouseFocusTicked", pParams->GetName() ) &&
  190. Q_strcmp( "KeyFocusTicked", pParams->GetName() ) &&
  191. Q_strcmp( "MouseFocusTicked", pParams->GetName() ) &&
  192. Q_strcmp( "CursorMoved", pParams->GetName() ) &&
  193. Q_strcmp( "CursorExited", pParams->GetName() ) &&
  194. Q_strcmp( "CursorEntered", pParams->GetName() ) &&
  195. Q_strcmp( "OnNavigateTo", pParams->GetName() ) &&
  196. Q_strcmp( "OnNavigateFrom", pParams->GetName() ) )
  197. {
  198. Msg( "=========================" );
  199. KeyValuesDumpAsDevMsg( pParams->MakeCopy() );
  200. }
  201. */
  202. }
  203. //void CIronSightDialog::OnCommand( const char *command )
  204. //{
  205. // if ( !Q_strcmp( command, "refresh_scheme" ) )
  206. // {
  207. // LoadControlSettings("Resource/ironsight_dialog.res");
  208. // }
  209. //}
  210. CON_COMMAND_F( ironsight_editor, "Edit ironsights.", FCVAR_DONTRECORD | FCVAR_DEVELOPMENTONLY )
  211. {
  212. g_pIronSightDialog = new CIronSightDialog(NULL);
  213. vgui::VPANEL parentPanel = enginevgui->GetPanel( PANEL_INGAMESCREENS );
  214. g_pIronSightDialog->SetParent( parentPanel );
  215. g_pIronSightDialog->SetVisible( true );
  216. g_pIronSightDialog->Repaint();
  217. g_pIronSightDialog->MoveToFront();
  218. }
  219. #endif
  220. #endif