aboutsummaryrefslogtreecommitdiff
path: root/mp/src/public/vgui_controls/KeyBoardEditorDialog.h
blob: 209c86f76ec2184ea5ee97468cbb4f3fbbcdc3f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================

#ifndef KEYBOARDEDITORDIALOG_H
#define KEYBOARDEDITORDIALOG_H
#ifdef _WIN32
#pragma once
#endif

#include "vgui_controls/Frame.h"
#include "vgui_controls/PropertySheet.h"
#include "vgui_controls/PropertyPage.h"

class VControlsListPanel;

namespace vgui
{

//-----------------------------------------------------------------------------
// Purpose: Dialog for use in editing keybindings
//-----------------------------------------------------------------------------
class CKeyBoardEditorPage : public EditablePanel
{
	DECLARE_CLASS_SIMPLE( CKeyBoardEditorPage, EditablePanel );

public:
	CKeyBoardEditorPage( Panel *parent, Panel *panelToEdit, KeyBindingContextHandle_t handle );
	~CKeyBoardEditorPage();

	void	SetKeybindingsSaveFile( char const *filename, char const *pathID = 0 );

	virtual void	OnKeyCodeTyped(vgui::KeyCode code);

	virtual void	ApplySchemeSettings( IScheme *scheme );

	void			OnSaveChanges();
	void			OnRevert();
	void			OnUseDefaults();

protected:

	virtual void	OnPageHide();

	virtual void	OnCommand( char const *cmd );

	void			PopulateList();

	void			GetMappingList( Panel *panel, CUtlVector< PanelKeyBindingMap * >& maps );
	int				GetMappingCount( Panel *panel );

	void			BindKey( vgui::KeyCode code );

		// Trap row selection message
	MESSAGE_FUNC( ItemSelected, "ItemSelected" );
	MESSAGE_FUNC_INT( OnClearBinding, "ClearBinding", item );

	void			SaveMappings();
	void			UpdateCurrentMappings();
	void			RestoreMappings();
	void			ApplyMappings();

protected:
	void					AnsiText( char const *token, char *out, size_t buflen );

	Panel			*m_pPanel;
	KeyBindingContextHandle_t m_Handle;

	VControlsListPanel	*m_pList;

	struct SaveMapping_t
	{
		SaveMapping_t();
		SaveMapping_t( const SaveMapping_t& src );

		PanelKeyBindingMap		*map;
		CUtlVector< BoundKey_t > current;
		CUtlVector< BoundKey_t > original;
	};

	CUtlVector< SaveMapping_t * > m_Save;
};


//-----------------------------------------------------------------------------
// Purpose: Dialog for use in editing keybindings
//-----------------------------------------------------------------------------
class CKeyBoardEditorSheet : public PropertySheet
{
	DECLARE_CLASS_SIMPLE( CKeyBoardEditorSheet, PropertySheet );

public:
	CKeyBoardEditorSheet( Panel *parent, Panel *panelToEdit, KeyBindingContextHandle_t handle );

	void	SetKeybindingsSaveFile( char const *filename, char const *pathID = 0 );

	void			OnSaveChanges();
	void			OnRevert();
	void			OnUseDefaults();

protected:

	vgui::PHandle			m_hPanel;
	KeyBindingContextHandle_t m_Handle;
	bool					m_bSaveToExternalFile;
	CUtlSymbol				m_SaveFileName;
	CUtlSymbol				m_SaveFilePathID;
	Color					m_clrAlteredItem;
};

//-----------------------------------------------------------------------------
// Purpose: Dialog for use in editing keybindings
//-----------------------------------------------------------------------------
class CKeyBoardEditorDialog : public Frame
{
	DECLARE_CLASS_SIMPLE( CKeyBoardEditorDialog, Frame );

public:
	CKeyBoardEditorDialog( Panel *parent, Panel *panelToEdit, KeyBindingContextHandle_t handle );

	void			SetKeybindingsSaveFile( char const *filename, char const *pathID = 0 );

	virtual void	OnCommand( char const *cmd );

private:
	CKeyBoardEditorSheet		*m_pKBEditor;

	Button						*m_pSave;
	Button						*m_pCancel;
	Button						*m_pRevert;
	Button						*m_pUseDefaults;
};

}

#endif // KEYBOARDEDITORDIALOG_H