| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <sigc++/connection.h> |
| 4 |
#include <sigc++/trackable.h> |
| 5 |
#include "icommandsystem.h" |
| 6 |
#include "ishaders.h" |
| 7 |
|
| 8 |
#include "wxutil/dialog/DialogBase.h" |
| 9 |
#include "wxutil/WindowPosition.h" |
| 10 |
#include "wxutil/PanedPosition.h" |
| 11 |
#include "wxutil/XmlResourceBasedWidget.h" |
| 12 |
#include "MaterialPreview.h" |
| 13 |
#include "wxutil/sourceview/SourceView.h" |
| 14 |
|
| 15 |
#include "../MaterialTreeView.h" |
| 16 |
#include "Binding.h" |
| 17 |
|
| 18 |
namespace ui |
| 19 |
{ |
| 20 |
|
| 21 |
class MaterialEditor : |
| 22 |
public wxutil::DialogBase, |
| 23 |
private wxutil::XmlResourceBasedWidget, |
| 24 |
public sigc::trackable |
| 25 |
{ |
| 26 |
private: |
| 27 |
MaterialTreeView* _treeView; |
| 28 |
wxDataViewItem _selectedMaterialItem; |
| 29 |
|
| 30 |
wxutil::TreeModel::Ptr _stageList; |
| 31 |
wxutil::TreeView* _stageView; |
| 32 |
wxBitmap _iconVisible; |
| 33 |
wxBitmap _iconInvisible; |
| 34 |
|
| 35 |
std::multimap<int, std::pair<wxWindow*, wxString>> _notebookPages; |
| 36 |
|
| 37 |
wxutil::WindowPosition _windowPosition; |
| 38 |
wxutil::PanedPosition _panedPosition; |
| 39 |
|
| 40 |
std::unique_ptr<MaterialPreview> _preview; |
| 41 |
wxutil::D3MaterialSourceViewCtrl* _sourceView; |
| 42 |
|
| 43 |
MaterialPtr _material; |
| 44 |
sigc::connection _materialChanged; |
| 45 |
|
| 46 |
std::set<std::shared_ptr<Binding<MaterialPtr>>> _materialBindings; |
| 47 |
std::set<std::shared_ptr<Binding<IShaderLayer::Ptr>>> _stageBindings; |
| 48 |
std::map<Material::DeformType, wxPanel*> _deformPanels; |
| 49 |
|
| 50 |
struct StageProgramColumns : |
| 51 |
public wxutil::TreeModel::ColumnRecord |
| 52 |
{ |
| 53 |
StageProgramColumns() : |
| 54 |
type(add(wxutil::TreeModel::Column::String)), |
| 55 |
index(add(wxutil::TreeModel::Column::String)), |
| 56 |
expression(add(wxutil::TreeModel::Column::String)) |
| 57 |
{} |
| 58 |
|
| 59 |
wxutil::TreeModel::Column type; |
| 60 |
wxutil::TreeModel::Column index; |
| 61 |
wxutil::TreeModel::Column expression; |
| 62 |
}; |
| 63 |
|
| 64 |
struct StageTransformColumns : |
| 65 |
public wxutil::TreeModel::ColumnRecord |
| 66 |
{ |
| 67 |
StageTransformColumns() : |
| 68 |
type(add(wxutil::TreeModel::Column::String)), |
| 69 |
index(add(wxutil::TreeModel::Column::String)), |
| 70 |
expression1(add(wxutil::TreeModel::Column::String)), |
| 71 |
expression2(add(wxutil::TreeModel::Column::String)) |
| 72 |
{} |
| 73 |
|
| 74 |
wxutil::TreeModel::Column type; |
| 75 |
wxutil::TreeModel::Column index; |
| 76 |
wxutil::TreeModel::Column expression1; |
| 77 |
wxutil::TreeModel::Column expression2; |
| 78 |
}; |
| 79 |
|
| 80 |
StageProgramColumns _stageProgramColumns; |
| 81 |
wxutil::TreeModel::Ptr _stageProgramParameters; |
| 82 |
|
| 83 |
StageTransformColumns _stageTransformationColumns; |
| 84 |
wxutil::TreeModel::Ptr _stageTransformations; |
| 85 |
wxutil::TreeView* _stageTransformView; |
| 86 |
|
| 87 |
bool _stageUpdateInProgress; |
| 88 |
bool _materialUpdateInProgress; |
| 89 |
bool _previewSceneUpdateInProgress; |
| 90 |
bool _updateFromSourceTextInProgress; |
| 91 |
bool _sourceTextUpdateInProgress; |
| 92 |
|
| 93 |
std::string _materialToPreselect; |
| 94 |
|
| 95 |
private: |
| 96 |
MaterialEditor(); |
| 97 |
~MaterialEditor(); |
| 98 |
|
| 99 |
public: |
| 100 |
int ShowModal() override; |
| 101 |
int ShowModal(const std::string& materialToPreselect); |
| 102 |
|
| 103 |
static void ShowDialog(const cmd::ArgumentList& args); |
| 104 |
|
| 105 |
protected: |
| 106 |
// Intercept close commands from pressing ESC keys |
| 107 |
bool _onDeleteEvent() override; |
| 108 |
|
| 109 |
private: |
| 110 |
void loadSettings(); |
| 111 |
void saveSettings(); |
| 112 |
|
| 113 |
// Asks user to save each unmodified material. |
| 114 |
// Returns true if it is safe to go ahead and close the dialog |
| 115 |
bool okToCloseDialog(); |
| 116 |
|
| 117 |
void setupBasicMaterialPage(); |
| 118 |
void setupMaterialTreeView(); |
| 119 |
void setupMaterialStageView(); |
| 120 |
void setupMaterialStageProperties(); |
| 121 |
void setupMaterialProperties(); |
| 122 |
void setupMaterialSurfaceFlags(); |
| 123 |
void setupMaterialShaderFlags(); |
| 124 |
void setupMaterialLightFlags(); |
| 125 |
void setupMaterialDeformPage(); |
| 126 |
void setupSurfaceFlag(const std::string& controlName, Material::SurfaceFlags flag); |
| 127 |
void setupMaterialFlag(const std::string& controlName, Material::Flags flag); |
| 128 |
void setupStageFlag(const std::string& controlName, IShaderLayer::Flags flags); |
| 129 |
void setupSourceTextPanel(wxWindow* previewPanel); |
| 130 |
void setupPreviewLightProperties(wxWindow* previewPanel); |
| 131 |
|
| 132 |
void createExpressionBinding(const std::string& textCtrlName, |
| 133 |
const std::function<shaders::IShaderExpression::Ptr(const IShaderLayer::Ptr&)>& loadFunc, |
| 134 |
const std::function<void(const IEditableShaderLayer::Ptr&, const std::string&)>& saveFunc); |
| 135 |
void createRadioButtonBinding(const std::string& ctrlName, |
| 136 |
const std::function<bool(const IShaderLayer::Ptr&)>& loadFunc, |
| 137 |
const std::function<void(const IEditableShaderLayer::Ptr&, bool)>& saveFunc); |
| 138 |
|
| 139 |
void createSpinCtrlBinding(const std::string& ctrlName, |
| 140 |
const std::function<int(const IShaderLayer::Ptr&)>& loadFunc, |
| 141 |
const std::function<void(const IEditableShaderLayer::Ptr&, int)>& saveFunc); |
| 142 |
void createSpinCtrlDoubleBinding(const std::string& ctrlName, |
| 143 |
const std::function<double(const IShaderLayer::Ptr&)>& loadFunc, |
| 144 |
const std::function<void(const IEditableShaderLayer::Ptr&, double)>& saveFunc); |
| 145 |
|
| 146 |
void updateControlsFromMaterial(); |
| 147 |
void updateDeformControlsFromMaterial(); |
| 148 |
void updateStageListFromMaterial(); |
| 149 |
void updateMaterialPropertiesFromMaterial(); |
| 150 |
|
| 151 |
void selectStageByIndex(std::size_t index); |
| 152 |
void selectMaterial(const MaterialPtr& material); |
| 153 |
IShaderLayer::Ptr getSelectedStage(); |
| 154 |
IEditableShaderLayer::Ptr getEditableStageForSelection(); |
| 155 |
std::pair<IShaderLayer::Ptr, std::size_t> findMaterialStageByType(IShaderLayer::Type type); |
| 156 |
void assignDecalInfoToMaterial(const MaterialPtr& material, bool isEnabled); |
| 157 |
void createDecalColourBinding(const std::string& controlName, const std::function<double(const MaterialPtr&)>& loadFunc); |
| 158 |
|
| 159 |
void updateBasicPageFromMaterial(); |
| 160 |
void updateBasicImagePreview(); |
| 161 |
void updateBasicFrobStageControls(); |
| 162 |
void updateStageControls(); |
| 163 |
void updateStageBlendControls(); |
| 164 |
void updateStageTextureControls(); |
| 165 |
void updateStageProgramControls(); |
| 166 |
void updateStageTransformControls(); |
| 167 |
void updateStageColoredStatus(); |
| 168 |
void updateNameOfSelectedStage(); |
| 169 |
void moveStagePosition(int direction); |
| 170 |
void updateStageButtonSensitivity(); |
| 171 |
void updateSettingsNotebook(); |
| 172 |
void updateMaterialControlSensitivity(); |
| 173 |
void updateSourceView(); |
| 174 |
void updateMaterialTreeItem(); |
| 175 |
void updateMaterialNameControl(); |
| 176 |
void handleMaterialSelectionChange(); |
| 177 |
|
| 178 |
bool isAllowedToChangeMaterial(); |
| 179 |
bool askUserAboutModifiedMaterial(); |
| 180 |
bool saveCurrentMaterial(); |
| 181 |
void deleteCurrentMaterial(); |
| 182 |
void revertCurrentMaterial(); |
| 183 |
void copySelectedMaterial(); |
| 184 |
|
| 185 |
void _onMaterialNameChanged(wxCommandEvent& ev); |
| 186 |
void _onMaterialSelectionChanged(wxDataViewEvent& ev); |
| 187 |
void _onNewMaterial(wxCommandEvent& ev); |
| 188 |
void _onSaveMaterial(wxCommandEvent& ev); |
| 189 |
void _onDeleteMaterial(wxCommandEvent& ev); |
| 190 |
void _onCopyMaterial(wxCommandEvent& ev); |
| 191 |
void _onRevertMaterial(wxCommandEvent& ev); |
| 192 |
void _onUnlockMaterial(wxCommandEvent& ev); |
| 193 |
void _onStageListSelectionChanged(wxDataViewEvent& ev); |
| 194 |
void _onStageListItemActivated(wxDataViewEvent& ev); |
| 195 |
void _onMaterialTypeChoice(wxCommandEvent& ev); |
| 196 |
void _onAddStageTransform(wxCommandEvent& ev); |
| 197 |
void _onRemoveStageTransform(wxCommandEvent& ev); |
| 198 |
void _onStageTransformEdited(wxDataViewEvent& ev); |
| 199 |
void _onStageColoredChecked(const IEditableShaderLayer::Ptr& layer, bool newValue); |
| 200 |
void _onStageMapTypeChanged(wxCommandEvent& ev); |
| 201 |
void _onStageBlendTypeChanged(wxCommandEvent& ev); |
| 202 |
void _onAddStage(wxCommandEvent& ev); |
| 203 |
void _onRemoveStage(wxCommandEvent& ev); |
| 204 |
void _onToggleStage(wxCommandEvent& ev); |
| 205 |
void _onDuplicateStage(wxCommandEvent& ev); |
| 206 |
void _onSortRequestChanged(wxCommandEvent& ev); |
| 207 |
void _onBasicMapEntryChanged(const std::string& entryName, IShaderLayer::Type type); |
| 208 |
void _onBasicAddFrobStages(wxCommandEvent& ev); |
| 209 |
void _onBasicRemoveFrobStages(wxCommandEvent& ev); |
| 210 |
void _onBasicTestFrobStages(wxMouseEvent& ev); |
| 211 |
void _onClose(wxCommandEvent& ev); |
| 212 |
void _onReloadImages(wxCommandEvent& ev); |
| 213 |
void _onSourceTextChanged(wxStyledTextEvent& ev); |
| 214 |
|
| 215 |
void applyMapExpressionToStage(const IEditableShaderLayer::Ptr& stage, const std::string& value); |
| 216 |
void toggleSelectedStage(); |
| 217 |
void onMaterialChanged(); |
| 218 |
void convertTextCtrlToMapExpressionEntry(const std::string& ctrlName); |
| 219 |
|
| 220 |
decl::DeclarationBlockSyntax getBlockSyntaxFromSourceView(); |
| 221 |
|
| 222 |
// Shortcut |
| 223 |
template<typename ObjectClass> |
| 224 |
ObjectClass* getControl(const std::string& name) |
| 225 |
{ |
| 226 |
return findNamedObject<ObjectClass>(this, name); |
| 227 |
} |
| 228 |
}; |
| 229 |
|
| 230 |
} |