/
ModelSelector.h
178 lines (134 loc) · 4.87 KB
/
ModelSelector.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
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
#pragma once
#include "MaterialsList.h"
#include "ModelTreeView.h"
#include <sigc++/connection.h>
#include "modelskin.h"
#include "iradiant.h"
#include "wxutil/dialog/DialogBase.h"
#include "wxutil/preview/ModelPreview.h"
#include "wxutil/WindowPosition.h"
#include "wxutil/PanedPosition.h"
#include "wxutil/dataview/ResourceTreeView.h"
#include "wxutil/dataview/TreeModelFilter.h"
#include "wxutil/XmlResourceBasedWidget.h"
#include "wxutil/dataview/KeyValueTable.h"
#include <string>
#include <wx/tglbtn.h>
namespace ui
{
class ModelPopulator;
class ModelSelector;
typedef std::shared_ptr<ModelSelector> ModelSelectorPtr;
/// Dialog for browsing and selecting a model and/or skin
class ModelSelector: public wxutil::DialogBase, private wxutil::XmlResourceBasedWidget
{
public:
/**
* Data structure containing the kind (model/eclass),
* the name of the object and a possible skin name.
* Als contains the options (whether to create Monsterclip).
*/
struct Result
{
enum class ObjectKind
{
Model,
EntityClass,
};
// The object to create
ObjectKind objectKind;
// Eclass/Model name
std::string name;
// The skin of the model (if not empty)
std::string skin;
// Model creation options
bool createClip = false;
};
private:
wxPanel* _dialogPanel;
// Model preview widget
wxutil::ModelPreviewPtr _modelPreview;
// Main tree view with model hierarchy
ModelTreeView* _treeView;
wxToggleButton* _showSkinsBtn = nullptr;
// The model name which the info panels are currently displaying info for
std::string _infoModel;
std::string _infoSkin;
// Key/value table for model information
wxutil::KeyValueTable* _infoTable;
// Materials list table
MaterialsList* _materialsList;
struct RelatedEntityColumns :
public wxutil::TreeModel::ColumnRecord
{
RelatedEntityColumns() :
eclassName(add(wxutil::TreeModel::Column::String)),
skin(add(wxutil::TreeModel::Column::String))
{}
wxutil::TreeModel::Column eclassName;
wxutil::TreeModel::Column skin;
};
RelatedEntityColumns _relatedEntityColumns;
wxutil::TreeModel::Ptr _relatedEntityStore;
wxutil::TreeView* _relatedEntityView;
// The window position tracker
wxutil::WindowPosition _position;
wxutil::PanedPosition _panedPosition;
// Whether to show advanced options panel
bool _showOptions;
sigc::connection _modelsReloadedConn;
sigc::connection _skinsReloadedConn;
Result _result;
private:
// Private constructor, creates widgets
ModelSelector();
// Home of the static instance
static ModelSelector& Instance();
// This is where the static shared_ptr of the singleton instance is held.
static ModelSelectorPtr& InstancePtr();
// Show the dialog, called internally by chooseModel(). Return the selected model path
Result showAndBlock(const std::string& curModel, bool showOptions, bool showSkins);
// Helper functions to configure GUI components
void setupAdvancedPanel(wxWindow* parent);
void setupTreeView(wxWindow* parent);
wxWindow* setupTreeViewToolbar(wxWindow* parent);
// Populate the tree view with models
void populateModels();
void handleSelectionChange();
void cancelDialog();
// wx callbacks
void onOK(wxCommandEvent& ev);
void onCancel(wxCommandEvent& ev);
void onReloadModels(wxCommandEvent& ev);
void onReloadSkins(wxCommandEvent& ev);
void onRescanFolders(wxCommandEvent& ev);
void onTreeViewPopulationFinished(wxutil::ResourceTreeView::PopulationFinishedEvent& ev);
// Update the info table with information from the currently-selected model, and
// update the displayed model.
void onSelectionChanged(wxDataViewEvent& ev);
void onRelatedEntitySelectionChange(wxDataViewEvent& ev);
void onRelatedEntityActivated(wxDataViewEvent& ev);
// Connected to the ModelCache/SkinCache signal, fires after the refresh commands are done
void onSkinsOrModelsReloaded();
void onModelLoaded(const model::ModelNodePtr& modelNode);
void onMainFrameShuttingDown();
protected:
void _onDeleteEvent(wxCloseEvent& ev);
public:
/**
* Display the Model Selector instance, constructing it on first use, and
* return the VFS path of the model selected by the user. When the
* ModelSelector is displayed it will enter a recursive gtk_main loop,
* blocking execution of the calling function until destroyed.
*
* @curModel: the name of the currently selected model the tree will browse to
* Leave this empty to leave the treeview focus where it was when
* the dialog was closed.
*
* @showOptions: whether to show the advanced options tab.
*/
static Result chooseModel(const std::string& curModel = "", bool showOptions = true, bool showSkins = true);
// Starts the background population thread
static void Populate();
};
}