/
PrefabSelector.h
122 lines (90 loc) · 2.87 KB
/
PrefabSelector.h
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
#pragma once
#include "iuimanager.h"
#include "imapresource.h"
#include "wxutil/dialog/DialogBase.h"
#include "wxutil/preview/ModelPreview.h"
#include "wxutil/WindowPosition.h"
#include "wxutil/PanedPosition.h"
#include "wxutil/fsview/FileSystemView.h"
#include "wxutil/PathEntry.h"
#include "ui/common/MapPreview.h"
#include <memory>
#include <string>
#include <wx/combobox.h>
class wxCheckBox;
class wxSizer;
class wxRadioButton;
namespace ui
{
class PrefabSelector;
typedef std::shared_ptr<PrefabSelector> PrefabSelectorPtr;
class PrefabPopulator;
/// Dialog for browsing and selecting a prefab
class PrefabSelector :
public wxutil::DialogBase
{
public:
struct Result
{
std::string prefabPath; // VFS path of the prefab
bool insertAsGroup; // whether to insert the prefab as group
};
private:
wxPanel* _dialogPanel;
// Model preview widget
std::unique_ptr<ui::MapPreview> _preview;
// Main tree view with the folder hierarchy
wxutil::FileSystemView* _treeView;
// The window position tracker
wxutil::WindowPosition _position;
wxutil::PanedPosition _panedPosition;
// Last selected prefab,
std::string _lastPrefab;
IMapResourcePtr _mapResource;
wxTextCtrl* _description;
wxRadioButton* _useModPath;
wxRadioButton* _useCustomPath;
wxRadioButton* _useRecentPath;
wxComboBox* _recentPathSelector;
wxutil::PathEntry* _customPath;
wxCheckBox* _insertAsGroupBox;
std::list<std::string> _recentPaths;
bool _handlingSelectionChange;
private:
// Private constructor, creates widgets
PrefabSelector();
// Home of the static instance
static PrefabSelector& Instance();
// This is where the static shared_ptr of the singleton instance is held.
static PrefabSelectorPtr& InstancePtr();
// Helper functions to configure GUI components
void setupTreeView(wxWindow* parent);
void setupPathSelector(wxSizer* parentSizer);
// Populate the tree view with prefabs
void populatePrefabs();
// Get the path that should be used for prefab population
// This reflects the settings made by the user on the top of the selector window
std::string getPrefabFolder();
void clearPreview();
// Return the selected prefab path
std::string getSelectedPath();
bool getInsertAsGroup();
void updateUsageInfo();
void addCustomPathToRecentList();
void onSelectionChanged(wxutil::FileSystemView::SelectionChangedEvent& ev);
void onPrefabPathSelectionChanged();
void onRescanPrefabs(wxCommandEvent& ev);
void onMainFrameShuttingDown();
public:
int ShowModal() override;
/**
* Display the Selector instance, constructing it on first use, and
* return the VFS path of the prefab selected by the user.
*
* @curPrefab: the name of the currently selected prefab the tree will browse to
* Leave this empty to leave the treeview focus where it was when
* the dialog was closed.
*/
static Result ChoosePrefab(const std::string& curPrefab = "");
};
}