summaryrefslogtreecommitdiff
path: root/common/GameUI/scriptobject.h
blob: 78bf3e34cd15a2e5ab3285bc98adca39a805bd7f (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

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

#include <vgui_controls/Panel.h>

class CPanelListPanel;

#define SCRIPT_VERSION 1.0f

typedef void * FileHandle_t;

enum objtype_t
{
	O_BADTYPE,
	O_BOOL,
	O_NUMBER,
	O_LIST,
	O_STRING,
	O_OBSOLETE,
	O_SLIDER,
	O_CATEGORY,
};

typedef struct
{
	objtype_t type;
	char szDescription[32];
} objtypedesc_t;

class CScriptListItem
{
public:
	CScriptListItem();
	CScriptListItem( char const *strItem, char const *strValue );

	char szItemText[128];
	char szValue[256];

	CScriptListItem *pNext;
};

class CScriptObject : public vgui::Panel
{
public:
	void AddItem( CScriptListItem *pItem );
	void RemoveAndDeleteAllItems( void );
	CScriptObject( void );
	~CScriptObject();

	bool ReadFromBuffer( const char **pBuffer, bool isNewObject );
	void WriteToConfig();
	void WriteToFile( FileHandle_t fp );
	void WriteToScriptFile( FileHandle_t fp );
	void SetCurValue( char const *strValue );

	objtype_t GetType( char *pszType );

	objtype_t type;

	char cvarname[64 ];
	char prompt[ 256 ];
	char tooltip[ 256 ];

	CScriptListItem *pListItems;

	float fMin, fMax;

	char	defValue[ 128 ];  // Default value string
	float   fdefValue; // Float version of default value.

	char	curValue[ 128 ];
	float   fcurValue;

	bool bSetInfo;  // Prepend "Setinfo" to keyvalue pair in config?
	// Linked list of default list box items.

	CScriptObject *pNext;
};

abstract_class CDescription
{
public:
	CDescription( void );
	virtual ~CDescription();

	bool ReadFromBuffer( const char **pBuffer, bool bAllowNewObject );
	bool InitFromFile( const char *pszFileName, bool bAllowNewObject = true );
	void TransferCurrentValues( const char *pszConfigFile );

	void AddObject( CScriptObject *pItem );
	void WriteToConfig();
	void WriteToFile( FileHandle_t fp );
	void WriteToScriptFile( FileHandle_t fp );

	virtual void WriteScriptHeader( FileHandle_t fp ) = 0; // Clients must implement this.
	virtual void WriteFileHeader( FileHandle_t fp ) = 0; // Clients must implement this.

	void setDescription( const char *pszDesc );
	void setHint( const char *pszHint );

	const char *GetDescription( void ) { return m_pszDescriptionType; };
	const char *getHint( void ) { return m_pszHintText; } ;
public:
	CScriptObject *pObjList;
	CScriptObject *FindObject( const char *pszObjectName );

private:

	char *m_pszHintText;
	char *m_pszDescriptionType;
};

namespace vgui
{
	class Label;
	class Panel;
}

class mpcontrol_t : public vgui::Panel
{
public:
	mpcontrol_t( vgui::Panel *parent, char const *panelName );

	virtual	void	OnSizeChanged( int wide, int tall ) OVERRIDE;

	objtype_t		type;
	vgui::Panel		*pControl;
	vgui::Label		*pPrompt;
	CScriptObject	*pScrObj;

	mpcontrol_t		*next;
};

class CInfoDescription : public CDescription
{
public:
	CInfoDescription( void );

	virtual void WriteScriptHeader( FileHandle_t fp ) OVERRIDE;
	virtual void WriteFileHeader( FileHandle_t fp ) OVERRIDE; 
};

void UTIL_StripInvalidCharacters( char *pszInput, int maxlen );

#endif // SCRIPTOBJECT_H