summaryrefslogtreecommitdiff
path: root/game/shared/tf/tf_quest_editor_panel.h
blob: 3d3d0a801fd2e0dfe1ce7899d1b73ae8b5cbc956 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#ifndef TF_QUEST_EDITOR_PANEL_H
#define TF_QUEST_EDITOR_PANEL_H

#include "cbase.h"
#include "vgui_controls/EditablePanel.h"
#include "vgui_controls/Frame.h"
#include "vgui_controls/ComboBox.h"
#include "tf_quest_restriction.h"
#include "clientmode_tf.h"
#include "vgui_controls/ScrollableEditablePanel.h"
#include "tf_controls.h"


#ifdef STAGING_ONLY

using namespace vgui;

#define MAX_QUEST_NAME_LENGTH 256
#define MAX_QUEST_DESC_LENGTH 4096

class CEditorQuest;
class IEditorObjectParameter;
class IEditableDataType;

struct EditorObjectInitStruct
{
	Panel *pParent;
	const char* m_pszKeyName;
	int nFlags;
};


//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class IEditorObject : public EditablePanel
{
public:

	DECLARE_CLASS_SIMPLE( IEditorObject, EditablePanel );
	IEditorObject( EditorObjectInitStruct init );

	virtual int GetContentTall() const = 0;
	virtual void PerformLayout() OVERRIDE;
	virtual void OnSizeChanged( int newWide, int newTall ) OVERRIDE;

	virtual void OnThink() OVERRIDE;

	void SetOwningEditable( const IEditableDataType* pEditable ) { m_pOwningEditable = pEditable; }
	void SetFlag( int nFlag, bool bValue ) { bValue ? m_Flags |= nFlag : m_Flags &= (~nFlag); }
	bool IsFlagSet( int nFlag, bool bCheckUpTree = false ) const;

	enum ESerializeAction
	{
		WRITE_THIS_AND_CONTINUE,
		SKIP_THIS_AND_CONTINUE,
		SKIP_THIS_AND_CHILDREN
	};

	virtual void SerializeToKVs( KeyValues* pKV, const IEditableDataType* pCallingEditable ) const = 0;
	ESerializeAction ShouldWrite( const IEditableDataType* pCallingEditable ) const;

	const char* GetKeyName() const { return m_szKeyName; }
	virtual void ClearPendingChangesFlag();

	virtual bool HasChanges( bool bCheckChildren ) const { return m_bHasChanges; }

protected:
	
	const IEditableDataType* GetOwningEditable() const;
	void InvalidateChain();

	mutable bool m_bHasChanges;
	uint32 m_Flags;

	char m_szKeyName[MAX_QUEST_DESC_LENGTH];

private:
	const IEditableDataType* m_pOwningEditable;
};

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class IEditableDataType
{
public:

	enum EType
	{
		TYPE_QUEST = 0,
		TYPE_OBJECTIVE_CONDITIONS,
		NUM_TYPES
	};

	IEditableDataType( KeyValues* pKVData );
	virtual ~IEditableDataType();
	void CreatePanels( Panel* pParent );
	void DestroyPanels();
	bool MatchesCriteria( EType type, const char* pszName ) const;
	void SaveChangesToDisk();	// Writes all changes to disk
	void SaveEdits();			// Saves any changes that have been made with the controls.  Does NOT write to disk.
	void DeleteEntry();
	void RevertChanges();
	void SetButton( Button* pButton ) { m_hButton = pButton; }
	Panel* GetButton() const { return m_hButton.Get(); }
	void CheckForChanges();

	KeyValues* GetLiveData() const { return m_pKVLiveData; }
	virtual EType GetType() const = 0;

protected:
	virtual void WriteDataToDisk( bool bDelete ) = 0;
	void WriteObjectToKeyValues( bool bDelete, KeyValues* pKVExistingFileData );
	virtual IEditorObject* CreateEditableObject_Internal( Panel* pParent ) const = 0;
	void UpdateButton();

	IEditorObject* m_pCurrentObject;
	KeyValues* m_pKVLiveData;
	KeyValues* m_pKVSavedData;
	bool m_bHasUnsavedChanges;
	mutable PHandle m_hButton;
};

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CEditableQuestDataType : public IEditableDataType
{
public:
	CEditableQuestDataType( KeyValues *pKV ) : IEditableDataType( pKV ) {}
private:
	virtual void WriteDataToDisk( bool bDelete ) OVERRIDE;
	virtual EType GetType() const { return IEditableDataType::TYPE_QUEST; }
	virtual IEditorObject* CreateEditableObject_Internal( Panel* pParent ) const OVERRIDE;
};

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CEditableObjectiveConditionDataType : public IEditableDataType
{
public:
	CEditableObjectiveConditionDataType( KeyValues *pKV ) : IEditableDataType( pKV ) {}
private:
	virtual void WriteDataToDisk( bool bDelete ) OVERRIDE;
	virtual EType GetType() const { return IEditableDataType::TYPE_OBJECTIVE_CONDITIONS; }
	virtual IEditorObject* CreateEditableObject_Internal( Panel* pParent ) const OVERRIDE;
};

//-----------------------------------------------------------------------------
// Purpose: Contains children
//-----------------------------------------------------------------------------
class CEditorObjectNode : public IEditorObject
{
public:
	DECLARE_CLASS_SIMPLE( CEditorObjectNode, IEditorObject );
	CEditorObjectNode( EditorObjectInitStruct init );
	virtual ~CEditorObjectNode();

	virtual void PerformLayout() OVERRIDE;
	virtual void OnCommand( const char *command ) OVERRIDE;
	virtual void MarkForDeletion() OVERRIDE;

	virtual int GetContentTall() const OVERRIDE;
	virtual void SerializeToKVs( KeyValues* pKV, const IEditableDataType* pCallingEditable ) const OVERRIDE;

	void AddChild( IEditorObject* pChild );
	void RemoveChild( IEditorObject* pChild );

	const CUtlVector< IEditorObject* >& GetChildren() const { return m_vecChildren; }
	int GetNextAvailableKeyNumber() const;

	virtual bool HasChanges( bool bCheckChildren ) const OVERRIDE;

protected:

	virtual void RemoveNode();
	virtual void ClearPendingChangesFlag() OVERRIDE;

	CUtlVector< IEditorObject* > m_vecChildren;

private:

	Button *m_pDeleteButton;
	Button *m_pToggleCollapseButton;
};

//-----------------------------------------------------------------------------
// Purpose: Contains a single parameter that can be edited
//-----------------------------------------------------------------------------
class IEditorObjectParameter : public IEditorObject
{
public:
	DECLARE_CLASS_SIMPLE( IEditorObjectParameter, IEditorObject );
	IEditorObjectParameter( EditorObjectInitStruct init, const char *pszLabelText );
	~IEditorObjectParameter();

	virtual void PerformLayout();

	virtual int GetContentTall() const = 0;
	virtual const char *GetValue() const = 0;
	virtual void SerializeToKVs( KeyValues* pKV, const IEditableDataType* pCallingEditable ) const OVERRIDE;
	void UpdateSavedValue( const char* pszNewValue ) const;

	MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", data );
protected:

	mutable char m_szSavedValueBuff[MAX_QUEST_DESC_LENGTH]; // This is the value that's saved to disk

private:
	virtual bool CheckForChanges() const;

	Label		*m_pLabel;
};

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CTextEntryEditorParam : public IEditorObjectParameter
{
public:

	DECLARE_CLASS_SIMPLE( CTextEntryEditorParam, IEditorObjectParameter );
	CTextEntryEditorParam( EditorObjectInitStruct init, const char *pszLabelText, const char *pszValue );

	virtual void PerformLayout() OVERRIDE;

	virtual int GetContentTall() const OVERRIDE;
	TextEntry*  GetTextEntry() const { return m_pTextEntry; }
	void SetTextEntryValue( const char* pszValue );
	const char *GetValue() const OVERRIDE;

private:

	TextEntry *m_pTextEntry;
	mutable char m_szValueBuff[MAX_QUEST_DESC_LENGTH];
};


//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
DECLARE_AUTO_LIST( ILocalizationEditorParamAutoList );
class CLocalizationEditorParam : public CTextEntryEditorParam, public ILocalizationEditorParamAutoList
{
public:
	DECLARE_CLASS_SIMPLE( CLocalizationEditorParam, CTextEntryEditorParam );
	CLocalizationEditorParam( EditorObjectInitStruct init, const char *pszLabelText, const char *pszLocalizationToken );

	const char *GetValue() const OVERRIDE;
	const char *GetLocalizationValue() const;

private:
	virtual bool CheckForChanges() const OVERRIDE;

	char m_szLocalizationToken[MAX_QUEST_NAME_LENGTH];
};


//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CComboBoxEditorParam : public IEditorObjectParameter
{
public:
	DECLARE_CLASS_SIMPLE( CComboBoxEditorParam, IEditorObjectParameter );
	CComboBoxEditorParam( EditorObjectInitStruct init, const char *pszLabelText );

	virtual void PerformLayout() OVERRIDE;
	const char *GetValue() const OVERRIDE;

	virtual int GetContentTall() const OVERRIDE;
	void ClearComboBoxEntries() { m_pComboBox->RemoveAll(); }
	void AddComboBoxEntry( const char* pszText, bool bSelected, const char* pszWriteValue, const char* pszCommand );
	ComboBox* GetComboBox() const { return m_pComboBox; }

	MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", data );

protected:

	ComboBox *m_pComboBox;
	mutable char m_szValueBuff[MAX_QUEST_DESC_LENGTH];
};

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CNewQuestObjectiveParam : public CComboBoxEditorParam
{
public:
	DECLARE_CLASS_SIMPLE( CNewQuestObjectiveParam, CComboBoxEditorParam );
	CNewQuestObjectiveParam( EditorObjectInitStruct init, const char *pszLabelText );

	virtual void PerformLayout() OVERRIDE;
	virtual void OnCommand( const char *command ) OVERRIDE;

private:
	Button *m_pAddButton;
};

class CQuestObjectiveNode : public CEditorObjectNode
{
public:
	DECLARE_CLASS_SIMPLE( CQuestObjectiveNode, CEditorObjectNode );
	CQuestObjectiveNode( CEditorObjectNode* pParentNode, KeyValues* pKVObjective );

	virtual void OnCommand( const char *command ) OVERRIDE;
	virtual void PerformLayout() OVERRIDE;

	MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", data );
	MESSAGE_FUNC_PARAMS( OnObjectiveSelected, "ObjectiveSelected", data );
private:
	void PopulateAndSelectConditionsCombobox( int nSelectedDefIndex );

	CComboBoxEditorParam* m_pDefIndexComboBox;
	Button* m_pSelectObjectiveButton;
};

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class IOptionalExpandableBlock : public CEditorObjectNode
{
public:
	DECLARE_CLASS_SIMPLE( IOptionalExpandableBlock, CEditorObjectNode );
	IOptionalExpandableBlock( EditorObjectInitStruct init, const char* pszButtonText );

	virtual void InitControls( KeyValues* pKVBlock );

	virtual void PerformLayout() OVERRIDE;
	virtual void OnCommand( const char *command ) OVERRIDE;

protected:
	virtual void CreateNewControl( KeyValues* pKV );

private:
	virtual void CreateNewDefaultControl() = 0;
	virtual int GetMinCount() const = 0;

	Button *m_pAddButton;
	int m_nMinCount;
};


class CQuestDescriptionNode : public IOptionalExpandableBlock
{
public:
	DECLARE_CLASS_SIMPLE( CQuestDescriptionNode, IOptionalExpandableBlock );
	CQuestDescriptionNode( EditorObjectInitStruct init ) : IOptionalExpandableBlock( init, "Add new Description" ) {}

private:
	virtual void CreateNewControl( KeyValues* pKV ) OVERRIDE;
	virtual void CreateNewDefaultControl() OVERRIDE;
	virtual int GetMinCount() const OVERRIDE { return 1; }
};

class CQuestNameNode : public IOptionalExpandableBlock
{
public:
	DECLARE_CLASS_SIMPLE( CQuestNameNode, IOptionalExpandableBlock );
	CQuestNameNode( EditorObjectInitStruct init ) : IOptionalExpandableBlock( init, "Add new Name" ) {}

private:
	virtual void CreateNewControl( KeyValues* pKV ) OVERRIDE;
	virtual void CreateNewDefaultControl() OVERRIDE;
	virtual int GetMinCount() const OVERRIDE { return 1; }
};

class CRequiredItemsParam : public IOptionalExpandableBlock
{
public:
	DECLARE_CLASS_SIMPLE( CRequiredItemsParam, IOptionalExpandableBlock );
	CRequiredItemsParam( EditorObjectInitStruct init ) : IOptionalExpandableBlock( init, "Add new Loaner Item Set" ) {}

private:
	virtual void CreateNewControl( KeyValues* pKV ) OVERRIDE;
	virtual void CreateNewDefaultControl() OVERRIDE;
	virtual int GetMinCount() const OVERRIDE { return 0; }
};

class CQualifyingItemsParam : public IOptionalExpandableBlock
{
public:
	DECLARE_CLASS_SIMPLE( CQualifyingItemsParam, IOptionalExpandableBlock );
	CQualifyingItemsParam( EditorObjectInitStruct init ) : IOptionalExpandableBlock( init, "Add new Qualifying Item" ) {}

private:
	virtual void CreateNewControl( KeyValues* pKV ) OVERRIDE;
	virtual void CreateNewDefaultControl() OVERRIDE;
	virtual int GetMinCount() const OVERRIDE { return 0; }
};

class CObjectiveExpandable : public IOptionalExpandableBlock
{
public:
	DECLARE_CLASS_SIMPLE( CObjectiveExpandable, IOptionalExpandableBlock );
	CObjectiveExpandable( EditorObjectInitStruct init ) : IOptionalExpandableBlock( init, "Add new Objective" ) {}

private:
	virtual void CreateNewControl( KeyValues* pKV ) OVERRIDE;
	virtual void CreateNewDefaultControl() OVERRIDE;
	virtual int GetMinCount() const OVERRIDE { return 1; }
};

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CQuestObjectiveRestrictionNode : public CEditorObjectNode
{
public:
	DECLARE_CLASS_SIMPLE( CQuestObjectiveRestrictionNode, CEditorObjectNode );
	CQuestObjectiveRestrictionNode( EditorObjectInitStruct init, CTFQuestCondition *pCondition );

	virtual void PerformLayout() OVERRIDE;

	CTFQuestCondition *GetCondition() { return m_pCondition; }

	void SetNewType( const char *pszType );
	void SetNewEvent( const char *pszEvent );

private:

	virtual void RemoveNode() OVERRIDE;
	void CreateControlsForCondition();
	void CreateAddOpportunityParam();

	char m_szEventName[MAX_QUEST_NAME_LENGTH];

	CTFQuestCondition *m_pCondition;
	CNewQuestObjectiveParam *m_pNewCondition;
};

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CEditorQuest : public CEditorObjectNode
{
public:
	CEditorQuest( KeyValues *pKV, Panel* pParent, const IEditableDataType* pEditable );
	~CEditorQuest();

private:
};

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CQuestEditorPanel : public Frame
{
public:
	DECLARE_CLASS_SIMPLE( CQuestEditorPanel, Frame );

	CQuestEditorPanel( Panel *pParent, const char *pszName );
	~CQuestEditorPanel() {}

	virtual void ApplySchemeSettings( IScheme *pScheme ) OVERRIDE;
	virtual void ApplySettings( KeyValues *inResourceData );
	virtual void PerformLayout() OVERRIDE;
	virtual void OnCommand( const char *command ) OVERRIDE;

	virtual void OnThink() OVERRIDE;

	void Deploy();

	IEditableDataType* OpenForEdit( IEditableDataType::EType type, const char* pszName, Panel* pParent );
	void CloseEdit( IEditableDataType* pEditable );
	bool IsOpenForEdit( const IEditableDataType* pEditable ) const;

	const CUtlVector< IEditableDataType* >& GetEditableData() const { return m_vecEditableData; }

	IEditableDataType* CreateNewQuest();
	IEditableDataType* CreateNewObjectiveCondition();

	Button* GetButtonForEditable( const IEditableDataType* pEditable ) const;

	void CheckForChanges();

	MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", data );
	MESSAGE_FUNC_PARAMS( OnSelectQuestObjective, "SelectQuestObjective", data );
private:

	void UpdateButtons( IEditableDataType::EType type );
	void ResetQuestSelectionState() { m_eCurrentSelectionMode = SELECTION_MODE_NONE; }

	template< typename T >
	IEditableDataType* AddNewEditableKVData( KeyValues* pKVConditionsData, const char* pszName );

	void PopulateExistingQuests();
	void OpenEditContextMenu();

	CExScrollingEditablePanel* m_pButtonsContainers[ IEditableDataType::NUM_TYPES ];
	CUtlVector< Button* > m_vecEditableButtons[ IEditableDataType::NUM_TYPES ];
	TextEntry* m_pButtonsFilterTextEntry[ IEditableDataType::NUM_TYPES ];

	CExScrollingEditablePanel *m_pEditingPanel;

	IEditableDataType* m_pCurrentOpenEdit;
	CUtlVector< IEditableDataType* > m_vecEditableData;
	CUtlVector< IEditableDataType* > m_vecOpenEdits;

	enum ESelectionMode_t
	{
		SELECTION_MODE_NONE = 0,
		SELECTION_MODE_QUEST_OBJECTIVE,
	};

	ESelectionMode_t m_eCurrentSelectionMode;
	PHandle m_hSelectionPanel;
};

#endif // STAGING_ONLY
#endif // TF_QUEST_EDITOR_PANEL_H