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.

225 lines
7.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Singleton dialog that generates and presents the entity report.
  4. //
  5. //===========================================================================//
  6. #include "InfoTargetPropertiesPanel.h"
  7. #include "tier1/KeyValues.h"
  8. #include "tier1/utlbuffer.h"
  9. #include "iregistry.h"
  10. #include "vgui/ivgui.h"
  11. #include "vgui_controls/listpanel.h"
  12. #include "vgui_controls/textentry.h"
  13. #include "vgui_controls/checkbutton.h"
  14. #include "vgui_controls/combobox.h"
  15. #include "vgui_controls/radiobutton.h"
  16. #include "vgui_controls/messagebox.h"
  17. #include "vgui_controls/scrollbar.h"
  18. #include "vcdblockdoc.h"
  19. #include "vcdblocktool.h"
  20. #include "datamodel/dmelement.h"
  21. #include "dmevmfentity.h"
  22. #include "dme_controls/soundpicker.h"
  23. #include "dme_controls/soundrecordpanel.h"
  24. #include "matsys_controls/picker.h"
  25. #include "vgui_controls/fileopendialog.h"
  26. #include "filesystem.h"
  27. // memdbgon must be the last include file in a .cpp file!!!
  28. #include <tier0/memdbgon.h>
  29. using namespace vgui;
  30. class CScrollableEditablePanel : public vgui::EditablePanel
  31. {
  32. DECLARE_CLASS_SIMPLE( CScrollableEditablePanel, vgui::EditablePanel );
  33. public:
  34. CScrollableEditablePanel( vgui::Panel *pParent, vgui::EditablePanel *pChild, const char *pName );
  35. virtual ~CScrollableEditablePanel() {}
  36. virtual void PerformLayout();
  37. MESSAGE_FUNC( OnScrollBarSliderMoved, "ScrollBarSliderMoved" );
  38. private:
  39. vgui::ScrollBar *m_pScrollBar;
  40. vgui::EditablePanel *m_pChild;
  41. };
  42. CScrollableEditablePanel::CScrollableEditablePanel( vgui::Panel *pParent, vgui::EditablePanel *pChild, const char *pName ) :
  43. BaseClass( pParent, pName )
  44. {
  45. m_pChild = pChild;
  46. m_pChild->SetParent( this );
  47. m_pScrollBar = new vgui::ScrollBar( this, "VerticalScrollBar", true );
  48. m_pScrollBar->SetWide( 16 );
  49. m_pScrollBar->SetAutoResize( PIN_TOPRIGHT, AUTORESIZE_DOWN, 0, 0, -16, 0 );
  50. m_pScrollBar->AddActionSignalTarget( this );
  51. }
  52. void CScrollableEditablePanel::PerformLayout()
  53. {
  54. BaseClass::PerformLayout();
  55. m_pChild->SetWide( GetWide() - 16 );
  56. m_pScrollBar->SetRange( 0, m_pChild->GetTall() );
  57. m_pScrollBar->SetRangeWindow( GetTall() );
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Called when the scroll bar moves
  61. //-----------------------------------------------------------------------------
  62. void CScrollableEditablePanel::OnScrollBarSliderMoved()
  63. {
  64. InvalidateLayout();
  65. int nScrollAmount = m_pScrollBar->GetValue();
  66. m_pChild->SetPos( 0, -nScrollAmount );
  67. }
  68. //-----------------------------------------------------------------------------
  69. // Constructor
  70. //-----------------------------------------------------------------------------
  71. CInfoTargetPropertiesPanel::CInfoTargetPropertiesPanel( CVcdBlockDoc *pDoc, vgui::Panel* pParent )
  72. : BaseClass( pParent, "InfoTargetPropertiesPanel" ), m_pDoc( pDoc )
  73. {
  74. SetPaintBackgroundEnabled( true );
  75. SetKeyBoardInputEnabled( true );
  76. m_pInfoTarget = new vgui::EditablePanel( (vgui::Panel*)NULL, "InfoTarget" );
  77. m_pTargetName = new vgui::TextEntry( m_pInfoTarget, "TargetName" );
  78. m_pTargetName->AddActionSignalTarget( this );
  79. m_pTargetPosition[0] = new vgui::TextEntry( m_pInfoTarget, "PositionX" );
  80. m_pTargetPosition[0]->AddActionSignalTarget( this );
  81. m_pTargetPosition[1] = new vgui::TextEntry( m_pInfoTarget, "PositionY" );
  82. m_pTargetPosition[1]->AddActionSignalTarget( this );
  83. m_pTargetPosition[2] = new vgui::TextEntry( m_pInfoTarget, "PositionZ" );
  84. m_pTargetPosition[2]->AddActionSignalTarget( this );
  85. m_pTargetOrientation[0] = new vgui::TextEntry( m_pInfoTarget, "Pitch" );
  86. m_pTargetOrientation[0]->AddActionSignalTarget( this );
  87. m_pTargetOrientation[1] = new vgui::TextEntry( m_pInfoTarget, "Yaw" );
  88. m_pTargetOrientation[1]->AddActionSignalTarget( this );
  89. m_pTargetOrientation[2] = new vgui::TextEntry( m_pInfoTarget, "Roll" );
  90. m_pTargetOrientation[2]->AddActionSignalTarget( this );
  91. m_pInfoTarget->LoadControlSettings( "resource/infotargetpropertiessubpanel_target.res" );
  92. m_pInfoTargetScroll = new CScrollableEditablePanel( this, m_pInfoTarget, "InfoTargetScroll" );
  93. LoadControlSettings( "resource/infotargetpropertiespanel.res" );
  94. m_pInfoTargetScroll->SetVisible( false );
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Text to attribute...
  98. //-----------------------------------------------------------------------------
  99. void CInfoTargetPropertiesPanel::TextEntryToAttribute( vgui::TextEntry *pEntry, const char *pAttributeName )
  100. {
  101. int nLen = pEntry->GetTextLength();
  102. char *pBuf = (char*)_alloca( nLen+1 );
  103. pEntry->GetText( pBuf, nLen+1 );
  104. m_hEntity->SetValue( pAttributeName, pBuf );
  105. }
  106. void CInfoTargetPropertiesPanel::TextEntriesToVector( vgui::TextEntry *pEntry[3], const char *pAttributeName )
  107. {
  108. Vector vec;
  109. for ( int i = 0; i < 3; ++i )
  110. {
  111. int nLen = pEntry[i]->GetTextLength();
  112. char *pBuf = (char*)_alloca( nLen+1 );
  113. pEntry[i]->GetText( pBuf, nLen+1 );
  114. vec[i] = atof( pBuf );
  115. }
  116. m_hEntity->SetValue( pAttributeName, vec );
  117. clienttools->MarkClientRenderableDirty( m_hEntity );
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Updates entity state when text fields change
  121. //-----------------------------------------------------------------------------
  122. void CInfoTargetPropertiesPanel::UpdateInfoTarget()
  123. {
  124. if ( !m_hEntity.Get() )
  125. return;
  126. CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Info Target Change", "Info Target Change" );
  127. TextEntryToAttribute( m_pTargetName, "targetname" );
  128. TextEntriesToVector( m_pTargetPosition, "origin" );
  129. TextEntriesToVector( m_pTargetOrientation, "angles" );
  130. m_hEntity->MarkDirty();
  131. }
  132. //-----------------------------------------------------------------------------
  133. // Populates the info_target fields
  134. //-----------------------------------------------------------------------------
  135. void CInfoTargetPropertiesPanel::PopulateInfoTargetFields()
  136. {
  137. if ( !m_hEntity.Get() )
  138. return;
  139. m_pTargetName->SetText( m_hEntity->GetTargetName() );
  140. Vector vecPosition = m_hEntity->GetRenderOrigin();
  141. QAngle vecAngles = m_hEntity->GetRenderAngles();
  142. for ( int i = 0; i < 3; ++i )
  143. {
  144. char pTemp[512];
  145. Q_snprintf( pTemp, sizeof(pTemp), "%.2f", vecPosition[i] );
  146. m_pTargetPosition[i]->SetText( pTemp );
  147. Q_snprintf( pTemp, sizeof(pTemp), "%.2f", vecAngles[i] );
  148. m_pTargetOrientation[i]->SetText( pTemp );
  149. }
  150. }
  151. //-----------------------------------------------------------------------------
  152. // Sets the object to look at
  153. //-----------------------------------------------------------------------------
  154. void CInfoTargetPropertiesPanel::SetObject( CDmeVMFEntity *pEntity )
  155. {
  156. m_hEntity = pEntity;
  157. m_pInfoTargetScroll->SetVisible( false );
  158. if ( pEntity )
  159. {
  160. if ( !Q_stricmp( pEntity->GetClassName(), "info_target" ) )
  161. {
  162. PopulateInfoTargetFields();
  163. m_pInfoTargetScroll->SetVisible( true );
  164. m_pTargetName->RequestFocus();
  165. return;
  166. }
  167. }
  168. }
  169. //-----------------------------------------------------------------------------
  170. // Called when text is changed
  171. //-----------------------------------------------------------------------------
  172. void CInfoTargetPropertiesPanel::OnTextChanged( KeyValues *pParams )
  173. {
  174. vgui::Panel *pPanel = (vgui::Panel*)pParams->GetPtr( "panel" );
  175. if ( pPanel->GetParent() == m_pInfoTarget )
  176. {
  177. UpdateInfoTarget();
  178. return;
  179. }
  180. }