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.

138 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef KEYBOARDEDITORDIALOG_H
  7. #define KEYBOARDEDITORDIALOG_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "vgui_controls/Frame.h"
  12. #include "vgui_controls/PropertySheet.h"
  13. #include "vgui_controls/PropertyPage.h"
  14. class VControlsListPanel;
  15. namespace vgui
  16. {
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Dialog for use in editing keybindings
  19. //-----------------------------------------------------------------------------
  20. class CKeyBoardEditorPage : public EditablePanel
  21. {
  22. DECLARE_CLASS_SIMPLE( CKeyBoardEditorPage, EditablePanel );
  23. public:
  24. CKeyBoardEditorPage( Panel *parent, Panel *panelToEdit, KeyBindingContextHandle_t handle );
  25. ~CKeyBoardEditorPage();
  26. void SetKeybindingsSaveFile( char const *filename, char const *pathID = 0 );
  27. virtual void OnKeyCodeTyped(vgui::KeyCode code);
  28. virtual void ApplySchemeSettings( IScheme *scheme );
  29. void OnSaveChanges();
  30. void OnRevert();
  31. void OnUseDefaults();
  32. protected:
  33. virtual void OnPageHide();
  34. virtual void OnCommand( char const *cmd );
  35. void PopulateList();
  36. void GetMappingList( Panel *panel, CUtlVector< PanelKeyBindingMap * >& maps );
  37. int GetMappingCount( Panel *panel );
  38. void BindKey( vgui::KeyCode code );
  39. // Trap row selection message
  40. MESSAGE_FUNC( ItemSelected, "ItemSelected" );
  41. MESSAGE_FUNC_INT( OnClearBinding, "ClearBinding", item );
  42. void SaveMappings();
  43. void UpdateCurrentMappings();
  44. void RestoreMappings();
  45. void ApplyMappings();
  46. protected:
  47. void AnsiText( char const *token, char *out, size_t buflen );
  48. Panel *m_pPanel;
  49. KeyBindingContextHandle_t m_Handle;
  50. VControlsListPanel *m_pList;
  51. struct SaveMapping_t
  52. {
  53. SaveMapping_t();
  54. SaveMapping_t( const SaveMapping_t& src );
  55. PanelKeyBindingMap *map;
  56. CUtlVector< BoundKey_t > current;
  57. CUtlVector< BoundKey_t > original;
  58. };
  59. CUtlVector< SaveMapping_t * > m_Save;
  60. };
  61. //-----------------------------------------------------------------------------
  62. // Purpose: Dialog for use in editing keybindings
  63. //-----------------------------------------------------------------------------
  64. class CKeyBoardEditorSheet : public PropertySheet
  65. {
  66. DECLARE_CLASS_SIMPLE( CKeyBoardEditorSheet, PropertySheet );
  67. public:
  68. CKeyBoardEditorSheet( Panel *parent, Panel *panelToEdit, KeyBindingContextHandle_t handle );
  69. void SetKeybindingsSaveFile( char const *filename, char const *pathID = 0 );
  70. void OnSaveChanges();
  71. void OnRevert();
  72. void OnUseDefaults();
  73. protected:
  74. vgui::PHandle m_hPanel;
  75. KeyBindingContextHandle_t m_Handle;
  76. bool m_bSaveToExternalFile;
  77. CUtlSymbol m_SaveFileName;
  78. CUtlSymbol m_SaveFilePathID;
  79. Color m_clrAlteredItem;
  80. };
  81. //-----------------------------------------------------------------------------
  82. // Purpose: Dialog for use in editing keybindings
  83. //-----------------------------------------------------------------------------
  84. class CKeyBoardEditorDialog : public Frame
  85. {
  86. DECLARE_CLASS_SIMPLE( CKeyBoardEditorDialog, Frame );
  87. public:
  88. CKeyBoardEditorDialog( Panel *parent, Panel *panelToEdit, KeyBindingContextHandle_t handle );
  89. void SetKeybindingsSaveFile( char const *filename, char const *pathID = 0 );
  90. virtual void OnCommand( char const *cmd );
  91. private:
  92. CKeyBoardEditorSheet *m_pKBEditor;
  93. Button *m_pSave;
  94. Button *m_pCancel;
  95. Button *m_pRevert;
  96. Button *m_pUseDefaults;
  97. };
  98. }
  99. #endif // KEYBOARDEDITORDIALOG_H