/
ModelSelector.h
153 lines (115 loc) · 4.13 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
#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>
namespace ui
{
/**
* Data structure containing the model, the skin name and the options to be returned from
* the Model Selector.
*/
struct ModelSelectorResult
{
// Model and skin strings
std::string model;
std::string skin;
// options
bool createClip;
// Constructor
ModelSelectorResult(const std::string& m, const std::string& s, const bool clip)
: model(m), skin(s), createClip(clip) {}
};
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
{
private:
wxPanel* _dialogPanel;
// Model preview widget
wxutil::ModelPreviewPtr _modelPreview;
// Main tree view with model hierarchy
ModelTreeView* _treeView;
// Key/value table for model information
wxutil::KeyValueTable* _infoTable;
// Materials list table
MaterialsList* _materialsList;
// The window position tracker
wxutil::WindowPosition _position;
wxutil::PanedPosition _panedPosition;
// Last selected model, which will be returned by showAndBlock() once the
// recursive main loop exits.
std::string _lastModel;
std::string _lastSkin;
// Whether to show advanced options panel
bool _showOptions;
sigc::connection _modelsReloadedConn;
sigc::connection _skinsReloadedConn;
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
ModelSelectorResult showAndBlock(const std::string& curModel,
bool showOptions,
bool showSkins);
// Helper functions to configure GUI components
void setupAdvancedPanel(wxWindow* parent);
void setupTreeView(wxWindow* parent);
// Populate the tree view with models
void populateModels();
void showInfoForSelectedModel();
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);
void _onItemActivated( wxDataViewEvent& ev );
// Update the info table with information from the currently-selected model, and
// update the displayed model.
void onSelectionChanged(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 ModelSelectorResult chooseModel(
const std::string& curModel = "", bool showOptions = true, bool showSkins = true);
// Starts the background population thread
static void Populate();
};
}