| 1 |
#include "MaterialEditor.h" |
| 2 |
|
| 3 |
#include "i18n.h" |
| 4 |
#include "ishaderexpression.h" |
| 5 |
#include "ishaderclipboard.h" |
| 6 |
|
| 7 |
#include <wx/panel.h> |
| 8 |
#include <wx/splitter.h> |
| 9 |
#include <wx/textctrl.h> |
| 10 |
#include <wx/collpane.h> |
| 11 |
#include <wx/spinctrl.h> |
| 12 |
#include <wx/combo.h> |
| 13 |
#include <wx/dataview.h> |
| 14 |
#include <wx/button.h> |
| 15 |
#include <wx/choice.h> |
| 16 |
#include <wx/combobox.h> |
| 17 |
#include <wx/notebook.h> |
| 18 |
#include <wx/radiobut.h> |
| 19 |
#include <wx/collpane.h> |
| 20 |
#include <wx/statbmp.h> |
| 21 |
#include <wx/clrpicker.h> |
| 22 |
|
| 23 |
#include "os/file.h" |
| 24 |
#include "wxutil/sourceview/SourceView.h" |
| 25 |
#include "wxutil/FileChooser.h" |
| 26 |
#include "wxutil/dialog/MessageBox.h" |
| 27 |
#include "wxutil/dataview/ResourceTreeViewToolbar.h" |
| 28 |
#include "wxutil/dataview/TreeViewItemStyle.h" |
| 29 |
#include "wxutil/EntityClassChooser.h" |
| 30 |
#include "wxutil/Bitmap.h" |
| 31 |
#include "wxutil/decl/DeclFileInfo.h" |
| 32 |
#include "materials/FrobStageSetup.h" |
| 33 |
#include "parser/DefBlockSyntaxParser.h" |
| 34 |
#include <fmt/format.h> |
| 35 |
#include "gamelib.h" |
| 36 |
#include "string/join.h" |
| 37 |
#include "materials/ParseLib.h" |
| 38 |
#include "ExpressionBinding.h" |
| 39 |
#include "RadioButtonBinding.h" |
| 40 |
#include "SpinCtrlBinding.h" |
| 41 |
#include "CheckBoxBinding.h" |
| 42 |
#include "MapExpressionEntry.h" |
| 43 |
#include "TexturePreview.h" |
| 44 |
#include "../MaterialChooser.h" |
| 45 |
|
| 46 |
namespace ui |
| 47 |
{ |
| 48 |
|
| 49 |
namespace |
| 50 |
{ |
| 51 |
const char* const DIALOG_TITLE = N_("Material Editor"); |
| 52 |
|
| 53 |
constexpr const char* const ICON_STAGE_VISIBLE = "visible.png"; |
| 54 |
constexpr const char* const ICON_STAGE_INVISIBLE = "invisible.png"; |
| 55 |
constexpr const char* const ICON_GLOBAL_SETTINGS = "icon_texture.png"; |
| 56 |
|
| 57 |
const std::string RKEY_ROOT = "user/ui/materialEditor/"; |
| 58 |
const std::string RKEY_SPLIT_POS = RKEY_ROOT + "splitPos"; |
| 59 |
const std::string RKEY_WINDOW_STATE = RKEY_ROOT + "window"; |
| 60 |
|
| 61 |
const std::string RKEY_LIGHTING_MODE_ENABLED = RKEY_ROOT + "lightModeEnabled"; |
| 62 |
const std::string RKEY_LAST_SELECTED_MATERIAL = RKEY_ROOT + "lastSelectedMaterial"; |
| 63 |
const std::string RKEY_PREVIEW_LIGHT_CLASSNAME = RKEY_ROOT + "previewLightClassname"; |
| 64 |
const std::string RKEY_PREVIEW_ROOM_MATERIAL = RKEY_ROOT + "previewRoomMaterial"; |
| 65 |
const std::string RKEY_PREVIEW_OBJECT_TYPE = RKEY_ROOT + "previewObjectType"; |
| 66 |
const std::string RKEY_PREVIEW_ORIGIN = RKEY_ROOT + "previewViewOrigin"; |
| 67 |
const std::string RKEY_PREVIEW_ANGLES = RKEY_ROOT + "previewViewAngles"; |
| 68 |
|
| 69 |
const char* const CUSTOM_BLEND_TYPE = N_("Custom"); |
| 70 |
|
| 71 |
// Columns for the stages list |
| 72 |
struct StageColumns : |
| 73 |
public wxutil::TreeModel::ColumnRecord |
| 74 |
{ |
| 75 |
StageColumns() : |
| 76 |
enabled(add(wxutil::TreeModel::Column::Boolean)), |
| 77 |
icon(add(wxutil::TreeModel::Column::Icon)), |
| 78 |
name(add(wxutil::TreeModel::Column::String)), |
| 79 |
index(add(wxutil::TreeModel::Column::Integer)), |
| 80 |
visible(add(wxutil::TreeModel::Column::Boolean)), |
| 81 |
global(add(wxutil::TreeModel::Column::Boolean)) |
| 82 |
{} |
| 83 |
|
| 84 |
wxutil::TreeModel::Column enabled; |
| 85 |
wxutil::TreeModel::Column icon; |
| 86 |
wxutil::TreeModel::Column name; |
| 87 |
wxutil::TreeModel::Column index; |
| 88 |
wxutil::TreeModel::Column visible; |
| 89 |
wxutil::TreeModel::Column global; |
| 90 |
}; |
| 91 |
|
| 92 |
StageColumns& STAGE_COLS() |
| 93 |
{ |
| 94 |
static StageColumns _i; |
| 95 |
return _i; |
| 96 |
} |
| 97 |
|
| 98 |
bool stageQualifiesAsColoured(const IShaderLayer::Ptr& layer) |
| 99 |
{ |
| 100 |
auto red = layer->getColourExpression(IShaderLayer::COMP_RED); |
| 101 |
auto green = layer->getColourExpression(IShaderLayer::COMP_GREEN); |
| 102 |
auto blue = layer->getColourExpression(IShaderLayer::COMP_BLUE); |
| 103 |
auto alpha = layer->getColourExpression(IShaderLayer::COMP_ALPHA); |
| 104 |
|
| 105 |
return red && red->getExpressionString() == "parm0" && |
| 106 |
green && green->getExpressionString() == "parm1" && |
| 107 |
blue && blue->getExpressionString() == "parm2" && |
| 108 |
alpha && alpha->getExpressionString() == "parm3"; |
| 109 |
} |
| 110 |
|
| 111 |
IShaderLayer::Type determineStageTypeToCreate(const MaterialPtr& material) |
| 112 |
{ |
| 113 |
bool hasDiffuse = false; |
| 114 |
bool hasBump = false; |
| 115 |
bool hasSpecular = false; |
| 116 |
|
| 117 |
material->foreachLayer([&](const IShaderLayer::Ptr& layer) |
| 118 |
{ |
| 119 |
hasDiffuse |= layer->getType() == IShaderLayer::DIFFUSE; |
| 120 |
hasBump |= layer->getType() == IShaderLayer::BUMP; |
| 121 |
hasSpecular |= layer->getType() == IShaderLayer::SPECULAR; |
| 122 |
return true; |
| 123 |
}); |
| 124 |
|
| 125 |
return !hasDiffuse ? IShaderLayer::DIFFUSE : |
| 126 |
!hasBump ? IShaderLayer::BUMP : |
| 127 |
!hasSpecular ? IShaderLayer::SPECULAR : |
| 128 |
IShaderLayer::BLEND; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
MaterialEditor::MaterialEditor() : |
| 133 |
DialogBase(DIALOG_TITLE), |
| 134 |
_treeView(nullptr), |
| 135 |
_stageList(new wxutil::TreeModel(STAGE_COLS(), true)), |
| 136 |
_stageView(nullptr), |
| 137 |
_stageUpdateInProgress(false), |
| 138 |
_materialUpdateInProgress(false), |
| 139 |
_previewSceneUpdateInProgress(false), |
| 140 |
_updateFromSourceTextInProgress(false), |
| 141 |
_sourceTextUpdateInProgress(false) |
| 142 |
{ |
| 143 |
loadNamedPanel(this, "MaterialEditorMainPanel"); |
| 144 |
|
| 145 |
makeLabelBold(this, "MaterialEditorDefinitionLabel"); |
| 146 |
makeLabelBold(this, "MaterialEditorStagePropertiesLabel"); |
| 147 |
makeLabelBold(this, "MaterialEditorMaterialStagesLabel"); |
| 148 |
|
| 149 |
// Wire up the buttons |
| 150 |
getControl<wxButton>("MaterialEditorCloseButton")->Bind(wxEVT_BUTTON, &MaterialEditor::_onClose, this); |
| 151 |
getControl<wxButton>("MaterialEditorReloadImagesButton")->Bind(wxEVT_BUTTON, &MaterialEditor::_onReloadImages, this); |
| 152 |
|
| 153 |
auto oldInfoPanel = getControl<wxPanel>("MaterialEditorSaveNotePanel"); |
| 154 |
auto declFileInfo = new wxutil::DeclFileInfo(oldInfoPanel->GetParent(), decl::Type::Material); |
| 155 |
replaceControl(oldInfoPanel, declFileInfo); |
| 156 |
|
| 157 |
// Add the treeview |
| 158 |
setupMaterialTreeView(); |
| 159 |
|
| 160 |
// Setup the splitter and preview |
| 161 |
auto* splitter = getControl<wxSplitterWindow>("MaterialEditorSplitter"); |
| 162 |
splitter->SetSashPosition(GetSize().GetWidth() * 0.6f); |
| 163 |
splitter->SetMinimumPaneSize(10); // disallow unsplitting |
| 164 |
|
| 165 |
// Set up the preview |
| 166 |
auto* previewPanel = getControl<wxPanel>("MaterialEditorPreviewPanel"); |
| 167 |
_preview.reset(new MaterialPreview(previewPanel)); |
| 168 |
|
| 169 |
previewPanel->GetSizer()->Add(_preview->getWidget(), 1, wxEXPAND); |
| 170 |
setupSourceTextPanel(previewPanel); |
| 171 |
setupPreviewLightProperties(previewPanel); |
| 172 |
|
| 173 |
setupBasicMaterialPage(); |
| 174 |
setupMaterialProperties(); |
| 175 |
setupMaterialStageView(); |
| 176 |
setupMaterialStageProperties(); |
| 177 |
setupMaterialSurfaceFlags(); |
| 178 |
setupMaterialShaderFlags(); |
| 179 |
setupMaterialLightFlags(); |
| 180 |
setupMaterialDeformPage(); |
| 181 |
|
| 182 |
// Set the default size of the window |
| 183 |
FitToScreen(0.8f, 0.9f); |
| 184 |
|
| 185 |
Layout(); |
| 186 |
Fit(); |
| 187 |
|
| 188 |
// Connect the window position tracker |
| 189 |
_windowPosition.loadFromPath(RKEY_WINDOW_STATE); |
| 190 |
_windowPosition.connect(this); |
| 191 |
_windowPosition.applyPosition(); |
| 192 |
|
| 193 |
_panedPosition.connect(splitter); |
| 194 |
_panedPosition.loadFromPath(RKEY_SPLIT_POS); |
| 195 |
|
| 196 |
CenterOnParent(); |
| 197 |
|
| 198 |
updateControlsFromMaterial(); |
| 199 |
} |
| 200 |
|
| 201 |
MaterialEditor::~MaterialEditor() |
| 202 |
{ |
| 203 |
_materialChanged.disconnect(); |
| 204 |
_materialBindings.clear(); |
| 205 |
_stageBindings.clear(); |
| 206 |
|
| 207 |
auto notebook = getControl<wxNotebook>("MaterialStageSettingsNotebook"); |
| 208 |
|
| 209 |
// Remove all umapped pages to avoid memory leaks |
| 210 |
for (const auto& pair : _notebookPages) |
| 211 |
{ |
| 212 |
if (notebook->FindPage(pair.second.first) == -1) |
| 213 |
{ |
| 214 |
pair.second.first->Destroy(); |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
_notebookPages.clear(); |
| 219 |
} |
| 220 |
|
| 221 |
int MaterialEditor::ShowModal() |
| 222 |
{ |
| 223 |
// Restore the position |
| 224 |
_windowPosition.applyPosition(); |
| 225 |
|
| 226 |
_treeView->Populate(); |
| 227 |
|
| 228 |
if (!_materialToPreselect.empty()) |
| 229 |
{ |
| 230 |
_treeView->SetSelectedDeclName(_materialToPreselect); |
| 231 |
} |
| 232 |
|
| 233 |
loadSettings(); |
| 234 |
|
| 235 |
int returnCode = DialogBase::ShowModal(); |
| 236 |
|
| 237 |
saveSettings(); |
| 238 |
|
| 239 |
// Tell the position tracker to save the information |
| 240 |
_windowPosition.saveToPath(RKEY_WINDOW_STATE); |
| 241 |
|
| 242 |
return returnCode; |
| 243 |
} |
| 244 |
|
| 245 |
int MaterialEditor::ShowModal(const std::string& materialToPreselect) |
| 246 |
{ |
| 247 |
_materialToPreselect = materialToPreselect; |
| 248 |
|
| 249 |
// If we don't get any input from the arguments, use the |
| 250 |
// currently selected material for starters |
| 251 |
if (_materialToPreselect.empty()) |
| 252 |
{ |
| 253 |
_materialToPreselect = GlobalShaderClipboard().getShaderName(); |
| 254 |
} |
| 255 |
|
| 256 |
return ShowModal(); |
| 257 |
} |
| 258 |
|
| 259 |
void MaterialEditor::loadSettings() |
| 260 |
{ |
| 261 |
if (_materialToPreselect.empty()) |
| 262 |
{ |
| 263 |
_materialToPreselect = registry::getValue<std::string>(RKEY_LAST_SELECTED_MATERIAL); |
| 264 |
|
| 265 |
if (!_materialToPreselect.empty()) |
| 266 |
{ |
| 267 |
_treeView->SetSelectedDeclName(_materialToPreselect); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
_preview->setStartupLightingMode(registry::getValue<bool>(RKEY_LIGHTING_MODE_ENABLED)); |
| 272 |
|
| 273 |
auto storedClassname = registry::getValue<std::string>(RKEY_PREVIEW_LIGHT_CLASSNAME); |
| 274 |
|
| 275 |
if (!storedClassname.empty()) |
| 276 |
{ |
| 277 |
_preview->setLightClassname(storedClassname); |
| 278 |
} |
| 279 |
|
| 280 |
auto storedRoomMaterial = registry::getValue<std::string>(RKEY_PREVIEW_ROOM_MATERIAL); |
| 281 |
|
| 282 |
if (!storedRoomMaterial.empty()) |
| 283 |
{ |
| 284 |
_preview->setRoomMaterial(storedRoomMaterial); |
| 285 |
} |
| 286 |
|
| 287 |
auto storedTestModelType = registry::getValue<std::string>(RKEY_PREVIEW_OBJECT_TYPE); |
| 288 |
|
| 289 |
if (!storedTestModelType.empty()) |
| 290 |
{ |
| 291 |
_preview->setTestModelType(MaterialPreview::GetTestModelType(storedTestModelType)); |
| 292 |
} |
| 293 |
|
| 294 |
if (!registry::getValue<std::string>(RKEY_PREVIEW_ORIGIN).empty() && |
| 295 |
!registry::getValue<std::string>(RKEY_PREVIEW_ANGLES).empty()) |
| 296 |
{ |
| 297 |
_preview->setViewOrigin(registry::getValue<Vector3>(RKEY_PREVIEW_ORIGIN)); |
| 298 |
_preview->setViewAngles(registry::getValue<Vector3>(RKEY_PREVIEW_ANGLES)); |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
void MaterialEditor::saveSettings() |
| 303 |
{ |
| 304 |
registry::setValue(RKEY_LAST_SELECTED_MATERIAL, _treeView->GetSelectedDeclName()); |
| 305 |
registry::setValue(RKEY_LIGHTING_MODE_ENABLED, _preview->getLightingModeEnabled()); |
| 306 |
registry::setValue(RKEY_PREVIEW_LIGHT_CLASSNAME, _preview->getLightClassname()); |
| 307 |
registry::setValue(RKEY_PREVIEW_ROOM_MATERIAL, _preview->getRoomMaterial()); |
| 308 |
registry::setValue(RKEY_PREVIEW_OBJECT_TYPE, MaterialPreview::GetTestModelTypeName(_preview->getTestModelType())); |
| 309 |
registry::setValue(RKEY_PREVIEW_ORIGIN, _preview->getViewOrigin()); |
| 310 |
registry::setValue(RKEY_PREVIEW_ANGLES, _preview->getViewAngles()); |
| 311 |
} |
| 312 |
|
| 313 |
void MaterialEditor::setupSourceTextPanel(wxWindow* previewPanel) |
| 314 |
{ |
| 315 |
auto sourceTextPanel = new wxCollapsiblePane(previewPanel, wxID_ANY, _("Material Source Text")); |
| 316 |
_sourceView = new wxutil::D3MaterialSourceViewCtrl(sourceTextPanel->GetPane()); |
| 317 |
_sourceView->SetMinSize(wxSize(-1, 400)); |
| 318 |
|
| 319 |
_sourceView->Bind(wxEVT_STC_MODIFIED, &MaterialEditor::_onSourceTextChanged, this); |
| 320 |
|
| 321 |
sourceTextPanel->Bind(wxEVT_COLLAPSIBLEPANE_CHANGED, [=](wxCollapsiblePaneEvent& ev) |
| 322 |
{ |
| 323 |
previewPanel->Layout(); |
| 324 |
}); |
| 325 |
|
| 326 |
auto paneSizer = new wxBoxSizer(wxVERTICAL); |
| 327 |
paneSizer->Add(_sourceView, 1, wxGROW | wxEXPAND); |
| 328 |
sourceTextPanel->GetPane()->SetSizer(paneSizer); |
| 329 |
sourceTextPanel->Collapse(); |
| 330 |
|
| 331 |
previewPanel->GetSizer()->Add(sourceTextPanel, 0, wxEXPAND); |
| 332 |
} |
| 333 |
|
| 334 |
void MaterialEditor::setupPreviewLightProperties(wxWindow* previewPanel) |
| 335 |
{ |
| 336 |
auto collapsiblePane = new wxCollapsiblePane(previewPanel, wxID_ANY, _("Preview Scene Properties")); |
| 337 |
|
| 338 |
auto propertyPanel = getControl<wxPanel>("MaterialPreviewScenePanel"); |
| 339 |
propertyPanel->GetContainingSizer()->Detach(propertyPanel); |
| 340 |
propertyPanel->Reparent(collapsiblePane->GetPane()); |
| 341 |
propertyPanel->SetMinSize(wxSize(-1, 100)); |
| 342 |
|
| 343 |
collapsiblePane->Bind(wxEVT_COLLAPSIBLEPANE_CHANGED, [=](wxCollapsiblePaneEvent& ev) |
| 344 |
{ |
| 345 |
previewPanel->Layout(); |
| 346 |
}); |
| 347 |
|
| 348 |
auto paneSizer = new wxBoxSizer(wxVERTICAL); |
| 349 |
paneSizer->Add(propertyPanel, 1, wxGROW | wxEXPAND); |
| 350 |
collapsiblePane->GetPane()->SetSizer(paneSizer); |
| 351 |
collapsiblePane->Collapse(); |
| 352 |
|
| 353 |
previewPanel->GetSizer()->Add(collapsiblePane, 0, wxEXPAND); |
| 354 |
|
| 355 |
// Wire up the signals |
| 356 |
_preview->signal_SceneChanged().connect([this] () |
| 357 |
{ |
| 358 |
util::ScopedBoolLock lock(_previewSceneUpdateInProgress); |
| 359 |
|
| 360 |
getControl<wxTextCtrl>("MaterialPreviewLightClassname")->SetValue(_preview->getLightClassname()); |
| 361 |
getControl<wxTextCtrl>("MaterialPreviewRoomMaterial")->SetValue(_preview->getRoomMaterial()); |
| 362 |
|
| 363 |
auto colour = _preview->getLightColour() * 255.0; |
| 364 |
getControl<wxColourPickerCtrl>("MaterialPreviewLightColour")->SetColour( |
| 365 |
wxColour(static_cast<wxColour::ChannelType>(colour.x()), |
| 366 |
static_cast<wxColour::ChannelType>(colour.y()), |
| 367 |
static_cast<wxColour::ChannelType>(colour.z()))); |
| 368 |
}); |
| 369 |
|
| 370 |
getControl<wxTextCtrl>("MaterialPreviewLightClassname")->Bind(wxEVT_TEXT, [this](wxCommandEvent& ev) |
| 371 |
{ |
| 372 |
if (_previewSceneUpdateInProgress) return; |
| 373 |
_preview->setLightClassname(ev.GetString().ToStdString()); |
| 374 |
}); |
| 375 |
|
| 376 |
getControl<wxTextCtrl>("MaterialPreviewRoomMaterial")->Bind(wxEVT_TEXT, [this](wxCommandEvent& ev) |
| 377 |
{ |
| 378 |
if (_previewSceneUpdateInProgress) return; |
| 379 |
_preview->setRoomMaterial(ev.GetString().ToStdString()); |
| 380 |
}); |
| 381 |
|
| 382 |
#if defined(__WXMSW__) && wxCHECK_VERSION(3,1,3) |
| 383 |
const auto& colourEvtType = wxEVT_COLOURPICKER_CURRENT_CHANGED; |
| 384 |
#else |
| 385 |
const auto& colourEvtType = wxEVT_COLOURPICKER_CHANGED; |
| 386 |
#endif |
| 387 |
getControl<wxColourPickerCtrl>("MaterialPreviewLightColour")->Bind(colourEvtType, |
| 388 |
[this](wxColourPickerEvent& ev) |
| 389 |
{ |
| 390 |
if (_previewSceneUpdateInProgress) return; |
| 391 |
auto colour = ev.GetColour(); |
| 392 |
_preview->setLightColour(Vector3(colour.Red() / 255.0, colour.Green() / 255.0, colour.Blue() / 255.0)); |
| 393 |
}); |
| 394 |
|
| 395 |
getControl<wxButton>("MaterialPreviewLightChooseClassnameButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev) |
| 396 |
{ |
| 397 |
auto textCtrl = getControl<wxTextCtrl>("MaterialPreviewLightClassname"); |
| 398 |
auto newClassName = wxutil::EntityClassChooser::ChooseEntityClass( |
| 399 |
wxutil::EntityClassChooser::Purpose::SelectClassname, textCtrl->GetValue().ToStdString()); |
| 400 |
|
| 401 |
if (!newClassName.empty()) |
| 402 |
{ |
| 403 |
textCtrl->SetValue(newClassName); |
| 404 |
} |
| 405 |
}); |
| 406 |
|
| 407 |
getControl<wxButton>("MaterialPreviewLightResetColourButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev) |
| 408 |
{ |
| 409 |
_preview->resetLightColour(); |
| 410 |
}); |
| 411 |
|
| 412 |
getControl<wxButton>("MaterialPreviewRoomMaterialButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev) |
| 413 |
{ |
| 414 |
auto textCtrl = getControl<wxTextCtrl>("MaterialPreviewRoomMaterial"); |
| 415 |
auto selector = new MaterialChooser(this, MaterialSelector::TextureFilter::Regular, textCtrl); |
| 416 |
selector->ShowModal(); |
| 417 |
selector->Destroy(); |
| 418 |
}); |
| 419 |
} |
| 420 |
|
| 421 |
void MaterialEditor::_onReloadImages(wxCommandEvent& ev) |
| 422 |
{ |
| 423 |
if (!_material) return; |
| 424 |
|
| 425 |
_material->refreshImageMaps(); |
| 426 |
updateBasicImagePreview(); |
| 427 |
} |
| 428 |
|
| 429 |
decl::DeclarationBlockSyntax MaterialEditor::getBlockSyntaxFromSourceView() |
| 430 |
{ |
| 431 |
auto fullText = _sourceView->GetValue().ToStdString(); |
| 432 |
|
| 433 |
parser::DefBlockSyntaxParser<const std::string> parser(fullText); |
| 434 |
|
| 435 |
auto syntaxTree = parser.parse(); |
| 436 |
auto block = syntaxTree->findFirstBlock([](const parser::DefBlockSyntax::Ptr&) { return true; }); |
| 437 |
|
| 438 |
if (!block) return {}; |
| 439 |
|
| 440 |
// We don't need to fill in every field of the syntax, the contents are important |
| 441 |
decl::DeclarationBlockSyntax syntax; |
| 442 |
|
| 443 |
syntax.name = _material->getName(); |
| 444 |
syntax.typeName = decl::getTypeName(decl::Type::Material); |
| 445 |
syntax.contents = block->getBlockContents(); |
| 446 |
|
| 447 |
return syntax; |
| 448 |
} |
| 449 |
|
| 450 |
void MaterialEditor::_onSourceTextChanged(wxStyledTextEvent& ev) |
| 451 |
{ |
| 452 |
if (!_material || _materialUpdateInProgress || _sourceTextUpdateInProgress) return; |
| 453 |
|
| 454 |
constexpr auto ObservedModificationTypes = wxSTC_MOD_INSERTTEXT | wxSTC_MOD_DELETETEXT | |
| 455 |
wxSTC_PERFORMED_UNDO | wxSTC_PERFORMED_REDO; |
| 456 |
|
| 457 |
if ((ev.GetModificationType() & ObservedModificationTypes) == 0) |
| 458 |
{ |
| 459 |
return; |
| 460 |
} |
| 461 |
|
| 462 |
// Block source text updates |
| 463 |
util::ScopedBoolLock lock(_updateFromSourceTextInProgress); |
| 464 |
|
| 465 |
auto syntax = getBlockSyntaxFromSourceView(); |
| 466 |
|
| 467 |
if (syntax.name.empty()) |
| 468 |
{ |
| 469 |
return; |
| 470 |
} |
| 471 |
|
| 472 |
if (_material->updateFromSourceText(syntax.contents).success) |
| 473 |
{ |
| 474 |
// Update the controls on success |
| 475 |
updateControlsFromMaterial(); |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
bool MaterialEditor::okToCloseDialog() |
| 480 |
{ |
| 481 |
// Check all unsaved materials |
| 482 |
std::list<MaterialPtr> modifiedMaterials; |
| 483 |
GlobalMaterialManager().foreachMaterial([&](const MaterialPtr& material) |
| 484 |
{ |
| 485 |
if (material->isModified()) |
| 486 |
{ |
| 487 |
modifiedMaterials.push_back(material); |
| 488 |
} |
| 489 |
}); |
| 490 |
|
| 491 |
for (const auto& material : modifiedMaterials) |
| 492 |
{ |
| 493 |
selectMaterial(material); |
| 494 |
|
| 495 |
// Prompt user to save or discard |
| 496 |
if (!askUserAboutModifiedMaterial()) |
| 497 |
{ |
| 498 |
return false; // cancel the close event |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
// At this point, everything is saved |
| 503 |
return true; |
| 504 |
} |
| 505 |
|
| 506 |
bool MaterialEditor::_onDeleteEvent() |
| 507 |
{ |
| 508 |
// Return true if preClose() vetoes the close event |
| 509 |
return !okToCloseDialog(); |
| 510 |
} |
| 511 |
|
| 512 |
void MaterialEditor::_onClose(wxCommandEvent& ev) |
| 513 |
{ |
| 514 |
// Check if it's ok to close the dialog |
| 515 |
if (okToCloseDialog()) |
| 516 |
{ |
| 517 |
EndModal(wxID_CLOSE); |
| 518 |
} |
| 519 |
} |
| 520 |
|
| 521 |
void MaterialEditor::ShowDialog(const cmd::ArgumentList& args) |
| 522 |
{ |
| 523 |
auto* editor = new MaterialEditor; |
| 524 |
|
| 525 |
std::string materialToPreselect; |
| 526 |
|
| 527 |
if (!args.empty()) |
| 528 |
{ |
| 529 |
materialToPreselect = args[0].getString(); |
| 530 |
} |
| 531 |
|
| 532 |
editor->ShowModal(materialToPreselect); |
| 533 |
editor->Destroy(); |
| 534 |
} |
| 535 |
|
| 536 |
void MaterialEditor::setupMaterialTreeView() |
| 537 |
{ |
| 538 |
auto* panel = getControl<wxPanel>("MaterialEditorTreeView"); |
| 539 |
_treeView = new MaterialTreeView(panel); |
| 540 |
_treeView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &MaterialEditor::_onMaterialSelectionChanged, this); |
| 541 |
|
| 542 |
auto* treeToolbar = new wxutil::ResourceTreeViewToolbar(panel, _treeView); |
| 543 |
treeToolbar->EnableFavouriteManagement(false); |
| 544 |
|
| 545 |
auto definitionLabel = getControl<wxStaticText>("MaterialEditorDefinitionLabel"); |
| 546 |
definitionLabel->GetContainingSizer()->Detach(definitionLabel); |
| 547 |
definitionLabel->Reparent(treeToolbar); |
| 548 |
treeToolbar->GetLeftSizer()->Add(definitionLabel, 0, wxALIGN_LEFT); |
| 549 |
|
| 550 |
panel->GetSizer()->Add(treeToolbar, 0, wxEXPAND | wxBOTTOM, 6); |
| 551 |
panel->GetSizer()->Add(_treeView, 1, wxEXPAND); |
| 552 |
|
| 553 |
auto newButton = getControl<wxButton>("MaterialEditorNewDefButton"); |
| 554 |
newButton->Bind(wxEVT_BUTTON, &MaterialEditor::_onNewMaterial, this); |
| 555 |
|
| 556 |
auto saveButton = getControl<wxButton>("MaterialEditorSaveDefButton"); |
| 557 |
saveButton->Disable(); |
| 558 |
saveButton->Bind(wxEVT_BUTTON, &MaterialEditor::_onSaveMaterial, this); |
| 559 |
|
| 560 |
auto deleteButton = getControl<wxButton>("MaterialEditorDeleteDefButton"); |
| 561 |
deleteButton->Disable(); |
| 562 |
deleteButton->Bind(wxEVT_BUTTON, &MaterialEditor::_onDeleteMaterial, this); |
| 563 |
|
| 564 |
auto copyButton = getControl<wxButton>("MaterialEditorCopyDefButton"); |
| 565 |
copyButton->Disable(); |
| 566 |
copyButton->Bind(wxEVT_BUTTON, &MaterialEditor::_onCopyMaterial, this); |
| 567 |
|
| 568 |
auto revertButton = getControl<wxButton>("MaterialEditorRevertButton"); |
| 569 |
revertButton->Disable(); |
| 570 |
revertButton->Bind(wxEVT_BUTTON, &MaterialEditor::_onRevertMaterial, this); |
| 571 |
|
| 572 |
auto unlockButton = getControl<wxButton>("MaterialEditorUnlockButton"); |
| 573 |
unlockButton->Disable(); |
| 574 |
unlockButton->Bind(wxEVT_BUTTON, &MaterialEditor::_onUnlockMaterial, this); |
| 575 |
unlockButton->Bind(wxEVT_ENTER_WINDOW, [unlockButton](wxMouseEvent&) |
| 576 |
{ |
| 577 |
if (!unlockButton->IsEnabled()) { return; } |
| 578 |
unlockButton->SetForegroundColour(wxNullColour); |
| 579 |
}); |
| 580 |
unlockButton->Bind(wxEVT_LEAVE_WINDOW, [unlockButton](wxMouseEvent&) |
| 581 |
{ |
| 582 |
if (!unlockButton->IsEnabled()) { return; } |
| 583 |
unlockButton->SetForegroundColour(*wxWHITE); |
| 584 |
}); |
| 585 |
} |
| 586 |
|
| 587 |
void MaterialEditor::_onBasicMapEntryChanged(const std::string& entryName, IShaderLayer::Type type) |
| 588 |
{ |
| 589 |
if (!_material || _materialUpdateInProgress) |
| 590 |
{ |
| 591 |
return; |
| 592 |
} |
| 593 |
|
| 594 |
auto textCtrl = getControl<MapExpressionEntry>(entryName)->GetTextCtrl(); |
| 595 |
|
| 596 |
auto newValue = textCtrl->GetValue().ToStdString(); |
| 597 |
|
| 598 |
// Clearing the text control is the same as removing the stage |
| 599 |
if (newValue.empty()) |
| 600 |
{ |
| 601 |
// Remove the corresponding stage |
| 602 |
auto stageToRemove = findMaterialStageByType(type); |
| 603 |
|
| 604 |
if (stageToRemove.first) |
| 605 |
{ |
| 606 |
_material->removeLayer(stageToRemove.second); |
| 607 |
updateStageListFromMaterial(); |
| 608 |
onMaterialChanged(); |
| 609 |
updateBasicImagePreview(); |
| 610 |
updateBasicFrobStageControls(); |
| 611 |
} |
| 612 |
|
| 613 |
return; |
| 614 |
} |
| 615 |
|
| 616 |
// Non-empty text, create the stage if necessary |
| 617 |
auto existingStage = findMaterialStageByType(type); |
| 618 |
IEditableShaderLayer::Ptr stage; |
| 619 |
bool stageCreated = false; |
| 620 |
|
| 621 |
if (existingStage.first) |
| 622 |
{ |
| 623 |
stage = _material->getEditableLayer(existingStage.second); |
| 624 |
} |
| 625 |
|
| 626 |
if (!stage) |
| 627 |
{ |
| 628 |
auto index = _material->addLayer(type); |
| 629 |
|
| 630 |
stage = _material->getEditableLayer(index); |
| 631 |
stageCreated = true; |
| 632 |
} |
| 633 |
|
| 634 |
applyMapExpressionToStage(stage, textCtrl->GetValue().ToStdString()); |
| 635 |
|
| 636 |
if (stageCreated) |
| 637 |
{ |
| 638 |
updateStageListFromMaterial(); |
| 639 |
} |
| 640 |
|
| 641 |
updateStageControls(); |
| 642 |
updateBasicImagePreview(); |
| 643 |
updateBasicFrobStageControls(); |
| 644 |
onMaterialChanged(); |
| 645 |
} |
| 646 |
|
| 647 |
void MaterialEditor::setupBasicMaterialPage() |
| 648 |
{ |
| 649 |
convertTextCtrlToMapExpressionEntry("BasicEditorImageEntry"); |
| 650 |
convertTextCtrlToMapExpressionEntry("BasicDiffuseImageEntry"); |
| 651 |
convertTextCtrlToMapExpressionEntry("BasicBumpImageEntry"); |
| 652 |
convertTextCtrlToMapExpressionEntry("BasicSpecularImageEntry"); |
| 653 |
|
| 654 |
auto nameEntry = getControl<wxTextCtrl>("BasicName"); |
| 655 |
nameEntry->Bind(wxEVT_TEXT, &MaterialEditor::_onMaterialNameChanged, this); |
| 656 |
|
| 657 |
auto editorImageEntry = getControl<MapExpressionEntry>("BasicEditorImageEntry")->GetTextCtrl(); |
| 658 |
editorImageEntry->Bind(wxEVT_TEXT, [this, editorImageEntry](wxCommandEvent&) |
| 659 |
{ |
| 660 |
if (!_material || _materialUpdateInProgress) return; |
| 661 |
|
| 662 |
_material->setEditorImageExpressionFromString(editorImageEntry->GetValue().ToStdString()); |
| 663 |
updateStageBlendControls(); |
| 664 |
updateBasicImagePreview(); |
| 665 |
updateBasicFrobStageControls(); |
| 666 |
onMaterialChanged(); |
| 667 |
}); |
| 668 |
|
| 669 |
auto description = getControl<wxTextCtrl>("BasicDescription"); |
| 670 |
description->Bind(wxEVT_TEXT, [description, this](wxCommandEvent& ev) |
| 671 |
{ |
| 672 |
if (_material && !_materialUpdateInProgress) |
| 673 |
{ |
| 674 |
_material->setDescription(description->GetValue().ToStdString()); |
| 675 |
updateMaterialPropertiesFromMaterial(); |
| 676 |
onMaterialChanged(); |
| 677 |
} |
| 678 |
}); |
| 679 |
|
| 680 |
auto* typeDropdown = getControl<wxChoice>("BasicMaterialType"); |
| 681 |
|
| 682 |
typeDropdown->AppendString(""); // empty string for undefined |
| 683 |
|
| 684 |
for (const auto& pair : shaders::SurfaceTypeMapping) |
| 685 |
{ |
| 686 |
typeDropdown->AppendString(pair.first); |
| 687 |
} |
| 688 |
|
| 689 |
typeDropdown->Bind(wxEVT_CHOICE, &MaterialEditor::_onMaterialTypeChoice, this); |
| 690 |
|
| 691 |
auto diffuseMapEntry = getControl<MapExpressionEntry>("BasicDiffuseImageEntry")->GetTextCtrl(); |
| 692 |
diffuseMapEntry->Bind(wxEVT_TEXT, [this](wxCommandEvent&) { _onBasicMapEntryChanged("BasicDiffuseImageEntry", IShaderLayer::DIFFUSE); }); |
| 693 |
auto bumpMapEntry = getControl<MapExpressionEntry>("BasicBumpImageEntry")->GetTextCtrl(); |
| 694 |
bumpMapEntry->Bind(wxEVT_TEXT, [this](wxCommandEvent&) { _onBasicMapEntryChanged("BasicBumpImageEntry", IShaderLayer::BUMP); }); |
| 695 |
auto specularMapEntry = getControl<MapExpressionEntry>("BasicSpecularImageEntry")->GetTextCtrl(); |
| 696 |
specularMapEntry->Bind(wxEVT_TEXT, [this](wxCommandEvent&) { _onBasicMapEntryChanged("BasicSpecularImageEntry", IShaderLayer::SPECULAR); }); |
| 697 |
|
| 698 |
auto editorImgTabImage = getControl<wxStaticBitmap>("BasicEditorImageTabImage"); |
| 699 |
replaceControl(editorImgTabImage, new TexturePreview(editorImgTabImage->GetParent(), TexturePreview::ImageType::EditorImage)); |
| 700 |
|
| 701 |
auto diffuseTabImage = getControl<wxStaticBitmap>("BasicDiffuseTabImage"); |
| 702 |
replaceControl(diffuseTabImage, new TexturePreview(diffuseTabImage->GetParent(), TexturePreview::ImageType::Diffuse)); |
| 703 |
|
| 704 |
auto bumpTabImage = getControl<wxStaticBitmap>("BasicBumpTabImage"); |
| 705 |
replaceControl(bumpTabImage, new TexturePreview(bumpTabImage->GetParent(), TexturePreview::ImageType::Bump)); |
| 706 |
|
| 707 |
auto specularTabImage = getControl<wxStaticBitmap>("BasicSpecularTabImage"); |
| 708 |
replaceControl(specularTabImage, new TexturePreview(specularTabImage->GetParent(), TexturePreview::ImageType::Specular)); |
| 709 |
|
| 710 |
auto addFrob = getControl<wxButton>("BasicAddFrobStages"); |
| 711 |
auto removeFrob = getControl<wxButton>("BasicRemoveFrobStages"); |
| 712 |
auto testFrob = getControl<wxButton>("BasicTestFrobStages"); |
| 713 |
|
| 714 |
addFrob->Bind(wxEVT_BUTTON, &MaterialEditor::_onBasicAddFrobStages, this); |
| 715 |
removeFrob->Bind(wxEVT_BUTTON, &MaterialEditor::_onBasicRemoveFrobStages, this); |
| 716 |
|
| 717 |
testFrob->Bind(wxEVT_LEFT_DOWN, &MaterialEditor::_onBasicTestFrobStages, this); |
| 718 |
testFrob->Bind(wxEVT_LEFT_UP, &MaterialEditor::_onBasicTestFrobStages, this); |
| 719 |
} |
| 720 |
|
| 721 |
void MaterialEditor::createDecalColourBinding(const std::string& controlName, const std::function<double(const MaterialPtr&)>& loadFunc) |
| 722 |
{ |
| 723 |
_materialBindings.emplace(std::make_shared<SpinCtrlBinding<wxSpinCtrlDouble, MaterialPtr>>( |
| 724 |
getControl<wxSpinCtrlDouble>(controlName), |
| 725 |
loadFunc, |
| 726 |
[this](const MaterialPtr& material, double _) |
| 727 |
{ |
| 728 |
if (_materialUpdateInProgress || !_material) return; |
| 729 |
assignDecalInfoToMaterial(material, true); |
| 730 |
}, |
| 731 |
[this]() { onMaterialChanged(); })); |
| 732 |
} |
| 733 |
|
| 734 |
void MaterialEditor::setupMaterialProperties() |
| 735 |
{ |
| 736 |
// Convert int-valued spinctrls to double-valued ones |
| 737 |
convertToSpinCtrlDouble(this, "MaterialPolygonOffsetValue", -100, 100, 0.1, 1); |
| 738 |
convertToSpinCtrlDouble(this, "MaterialEditorDecalInfoStaySeconds", 0, 999999, 0.1, 2); |
| 739 |
convertToSpinCtrlDouble(this, "MaterialEditorDecalInfoFadeSeconds", 0, 999999, 0.1, 2); |
| 740 |
convertToSpinCtrlDouble(this, "MaterialDecalInfoStartRed", 0.0, 1.0, 0.1, 2); |
| 741 |
convertToSpinCtrlDouble(this, "MaterialDecalInfoStartGreen", 0.0, 1.0, 0.1, 2); |
| 742 |
convertToSpinCtrlDouble(this, "MaterialDecalInfoStartBlue", 0.0, 1.0, 0.1, 2); |
| 743 |
convertToSpinCtrlDouble(this, "MaterialDecalInfoStartAlpha", 0.0, 1.0, 0.1, 2); |
| 744 |
convertToSpinCtrlDouble(this, "MaterialDecalInfoEndRed", 0.0, 1.0, 0.1, 2); |
| 745 |
convertToSpinCtrlDouble(this, "MaterialDecalInfoEndGreen", 0.0, 1.0, 0.1, 2); |
| 746 |
convertToSpinCtrlDouble(this, "MaterialDecalInfoEndBlue", 0.0, 1.0, 0.1, 2); |
| 747 |
convertToSpinCtrlDouble(this, "MaterialDecalInfoEndAlpha", 0.0, 1.0, 0.1, 2); |
| 748 |
convertToSpinCtrlDouble(this, "MaterialStagePrivatePolygonOffset", -100, 100, 0.1, 1); |
| 749 |
|
| 750 |
#if defined(__WXMSW__) |
| 751 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoStartRed")->SetMaxSize(wxSize(80, -1)); |
| 752 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoStartGreen")->SetMaxSize(wxSize(80, -1)); |
| 753 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoStartBlue")->SetMaxSize(wxSize(80, -1)); |
| 754 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoStartAlpha")->SetMaxSize(wxSize(80, -1)); |
| 755 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoEndRed")->SetMaxSize(wxSize(80, -1)); |
| 756 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoEndGreen")->SetMaxSize(wxSize(80, -1)); |
| 757 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoEndBlue")->SetMaxSize(wxSize(80, -1)); |
| 758 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoEndAlpha")->SetMaxSize(wxSize(80, -1)); |
| 759 |
#endif |
| 760 |
|
| 761 |
// Place map expression controls where needed |
| 762 |
convertTextCtrlToMapExpressionEntry("MaterialStageImageMap"); |
| 763 |
convertTextCtrlToMapExpressionEntry("MaterialLightFalloffMap"); |
| 764 |
convertTextCtrlToMapExpressionEntry("MaterialEditorImage"); |
| 765 |
|
| 766 |
auto nameEntry = getControl<wxTextCtrl>("MaterialName"); |
| 767 |
nameEntry->Bind(wxEVT_TEXT, &MaterialEditor::_onMaterialNameChanged, this); |
| 768 |
|
| 769 |
auto editorImage = getControl<MapExpressionEntry>("MaterialEditorImage"); |
| 770 |
_materialBindings.emplace(std::make_shared<ExpressionBinding<MaterialPtr>>(editorImage->GetTextCtrl(), |
| 771 |
[](const MaterialPtr& material) |
| 772 |
{ |
| 773 |
auto expr = material->getEditorImageExpression(); |
| 774 |
return expr ? expr->getExpressionString() : std::string(); |
| 775 |
}, |
| 776 |
[this](const MaterialPtr& material, const std::string& value) |
| 777 |
{ |
| 778 |
if (_materialUpdateInProgress || !_material) return; |
| 779 |
material->setEditorImageExpressionFromString(value); |
| 780 |
}, |
| 781 |
[this]() { onMaterialChanged(); })); |
| 782 |
|
| 783 |
auto* typeDropdown = getControl<wxChoice>("MaterialType"); |
| 784 |
|
| 785 |
typeDropdown->AppendString(""); // empty string for undefined |
| 786 |
|
| 787 |
for (const auto& pair : shaders::SurfaceTypeMapping) |
| 788 |
{ |
| 789 |
typeDropdown->AppendString(pair.first); |
| 790 |
} |
| 791 |
|
| 792 |
typeDropdown->Bind(wxEVT_CHOICE, &MaterialEditor::_onMaterialTypeChoice, this); |
| 793 |
|
| 794 |
auto* sortDropdown = getControl<wxComboBox>("MaterialSortValue"); |
| 795 |
|
| 796 |
sortDropdown->AppendString(""); // empty string for undefined |
| 797 |
|
| 798 |
for (const auto& pair : shaders::PredefinedSortValues) |
| 799 |
{ |
| 800 |
sortDropdown->AppendString(pair.first); |
| 801 |
} |
| 802 |
|
| 803 |
sortDropdown->Bind(wxEVT_COMBOBOX, &MaterialEditor::_onSortRequestChanged, this); |
| 804 |
sortDropdown->Bind(wxEVT_TEXT, &MaterialEditor::_onSortRequestChanged, this); |
| 805 |
|
| 806 |
auto description = getControl<wxTextCtrl>("MaterialDescription"); |
| 807 |
description->Bind(wxEVT_TEXT, [description, this](wxCommandEvent& ev) |
| 808 |
{ |
| 809 |
if (_material && !_materialUpdateInProgress) |
| 810 |
{ |
| 811 |
_material->setDescription(description->GetValue().ToStdString()); |
| 812 |
updateBasicPageFromMaterial(); |
| 813 |
onMaterialChanged(); |
| 814 |
} |
| 815 |
}); |
| 816 |
|
| 817 |
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(getControl<wxCheckBox>("MaterialHasSortValue"), |
| 818 |
[](const MaterialPtr& material) |
| 819 |
{ |
| 820 |
return (material->getMaterialFlags() & Material::FLAG_HAS_SORT_DEFINED) != 0; |
| 821 |
}, |
| 822 |
[this](const MaterialPtr& material, const bool& value) |
| 823 |
{ |
| 824 |
if (!value) |
| 825 |
{ |
| 826 |
material->resetSortRequest(); |
| 827 |
} |
| 828 |
else |
| 829 |
{ |
| 830 |
auto sortValue = getControl<wxComboBox>("MaterialSortValue")->GetValue().ToStdString(); |
| 831 |
material->setSortRequest(!sortValue.empty() ? |
| 832 |
shaders::getSortRequestValueForString(sortValue) : |
| 833 |
static_cast<float>(Material::SORT_OPAQUE)); |
| 834 |
} |
| 835 |
}, |
| 836 |
[this]() { onMaterialChanged(); })); |
| 837 |
|
| 838 |
_materialBindings.emplace(std::make_shared<SpinCtrlBinding<wxSpinCtrlDouble, MaterialPtr>>( |
| 839 |
getControl<wxSpinCtrlDouble>("MaterialPolygonOffsetValue"), |
| 840 |
[](const MaterialPtr& material) { return material->getPolygonOffset(); }, |
| 841 |
[this](const MaterialPtr& material, const double& value) |
| 842 |
{ |
| 843 |
material->setPolygonOffset(value); |
| 844 |
getControl<wxCheckBox>("MaterialFlagHasPolygonOffset")->SetValue((material->getMaterialFlags() & Material::FLAG_POLYGONOFFSET) != 0); |
| 845 |
}, |
| 846 |
[this]() { onMaterialChanged(); })); |
| 847 |
|
| 848 |
getControl<wxCheckBox>("MaterialHasSpectrum")->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& ev) |
| 849 |
{ |
| 850 |
getControl<wxSpinCtrl>("MaterialSpectrumValue")->Enable(ev.IsChecked()); |
| 851 |
}); |
| 852 |
|
| 853 |
auto hasDecalInfo = getControl<wxCheckBox>("MaterialHasDecalInfo"); |
| 854 |
hasDecalInfo->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& ev) |
| 855 |
{ |
| 856 |
getControl<wxPanel>("MaterialDecalInfoPanel")->Enable(ev.IsChecked()); |
| 857 |
}); |
| 858 |
|
| 859 |
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(hasDecalInfo, |
| 860 |
[](const MaterialPtr& material) |
| 861 |
{ |
| 862 |
return material->getParseFlags() & Material::PF_HasDecalInfo; |
| 863 |
}, |
| 864 |
[this](const MaterialPtr& material, bool value) |
| 865 |
{ |
| 866 |
if (_materialUpdateInProgress || !_material) return; |
| 867 |
|
| 868 |
// Set the decal info structure from the control contents |
| 869 |
assignDecalInfoToMaterial(material, value); |
| 870 |
}, |
| 871 |
[this]() { onMaterialChanged(); })); |
| 872 |
|
| 873 |
_materialBindings.emplace(std::make_shared<SpinCtrlBinding<wxSpinCtrlDouble, MaterialPtr>>( |
| 874 |
getControl<wxSpinCtrlDouble>("MaterialEditorDecalInfoStaySeconds"), |
| 875 |
[](const MaterialPtr& material) |
| 876 |
{ |
| 877 |
return material->getDecalInfo().stayMilliSeconds / 1000.0; |
| 878 |
}, |
| 879 |
[this](const MaterialPtr& material, double _) |
| 880 |
{ |
| 881 |
if (_materialUpdateInProgress || !_material) return; |
| 882 |
assignDecalInfoToMaterial(material, true); |
| 883 |
}, |
| 884 |
[this]() { onMaterialChanged(); })); |
| 885 |
|
| 886 |
_materialBindings.emplace(std::make_shared<SpinCtrlBinding<wxSpinCtrlDouble, MaterialPtr>>( |
| 887 |
getControl<wxSpinCtrlDouble>("MaterialEditorDecalInfoFadeSeconds"), |
| 888 |
[](const MaterialPtr& material) |
| 889 |
{ |
| 890 |
return material->getDecalInfo().fadeMilliSeconds / 1000.0; |
| 891 |
}, |
| 892 |
[this](const MaterialPtr& material, double _) |
| 893 |
{ |
| 894 |
if (_materialUpdateInProgress || !_material) return; |
| 895 |
assignDecalInfoToMaterial(material, true); |
| 896 |
}, |
| 897 |
[this]() { onMaterialChanged(); })); |
| 898 |
|
| 899 |
createDecalColourBinding("MaterialDecalInfoStartRed", [](const MaterialPtr& material) { return material->getDecalInfo().startColour.x(); }); |
| 900 |
createDecalColourBinding("MaterialDecalInfoStartGreen", [](const MaterialPtr& material) { return material->getDecalInfo().startColour.y(); }); |
| 901 |
createDecalColourBinding("MaterialDecalInfoStartBlue", [](const MaterialPtr& material) { return material->getDecalInfo().startColour.z(); }); |
| 902 |
createDecalColourBinding("MaterialDecalInfoStartAlpha", [](const MaterialPtr& material) { return material->getDecalInfo().startColour.w(); }); |
| 903 |
|
| 904 |
createDecalColourBinding("MaterialDecalInfoEndRed", [](const MaterialPtr& material) { return material->getDecalInfo().endColour.x(); }); |
| 905 |
createDecalColourBinding("MaterialDecalInfoEndGreen", [](const MaterialPtr& material) { return material->getDecalInfo().endColour.y(); }); |
| 906 |
createDecalColourBinding("MaterialDecalInfoEndBlue", [](const MaterialPtr& material) { return material->getDecalInfo().endColour.z(); }); |
| 907 |
createDecalColourBinding("MaterialDecalInfoEndAlpha", [](const MaterialPtr& material) { return material->getDecalInfo().endColour.w(); }); |
| 908 |
|
| 909 |
// For light fall off images, only cameracubemap and map are allowed |
| 910 |
auto lightFallOffCubeMapType = getControl<wxChoice>("MaterialLightFalloffCubeMapType"); |
| 911 |
lightFallOffCubeMapType->AppendString(shaders::getStringForMapType(IShaderLayer::MapType::Map)); |
| 912 |
lightFallOffCubeMapType->AppendString(shaders::getStringForMapType(IShaderLayer::MapType::CameraCubeMap)); |
| 913 |
|
| 914 |
lightFallOffCubeMapType->Bind(wxEVT_CHOICE, [this, lightFallOffCubeMapType] (wxCommandEvent& ev) |
| 915 |
{ |
| 916 |
if (_materialUpdateInProgress || !_material) return; |
| 917 |
_material->setLightFalloffCubeMapType(shaders::getMapTypeForString(lightFallOffCubeMapType->GetStringSelection().ToStdString())); |
| 918 |
}); |
| 919 |
|
| 920 |
auto lightFalloffMap = getControl<MapExpressionEntry>("MaterialLightFalloffMap"); |
| 921 |
_materialBindings.emplace(std::make_shared<ExpressionBinding<MaterialPtr>>(lightFalloffMap->GetTextCtrl(), |
| 922 |
[](const MaterialPtr& material) |
| 923 |
{ |
| 924 |
auto expr = material->getLightFalloffExpression(); |
| 925 |
return expr ? expr->getExpressionString() : std::string(); |
| 926 |
}, |
| 927 |
[this](const MaterialPtr& material, const std::string& value) |
| 928 |
{ |
| 929 |
if (_materialUpdateInProgress || !_material) return; |
| 930 |
material->setLightFalloffExpressionFromString(value); |
| 931 |
}, |
| 932 |
[this]() { onMaterialChanged(); })); |
| 933 |
|
| 934 |
_materialBindings.emplace(std::make_shared<SpinCtrlBinding<wxSpinCtrl, MaterialPtr>>(getControl<wxSpinCtrl>("MaterialSpectrumValue"), |
| 935 |
[](const MaterialPtr& material) { return material->getSpectrum(); }, |
| 936 |
[this](const MaterialPtr& material, const int& value) |
| 937 |
{ |
| 938 |
if (_materialUpdateInProgress || !_material) return; |
| 939 |
material->setSpectrum(value); |
| 940 |
}, |
| 941 |
[this]() { onMaterialChanged(); })); |
| 942 |
} |
| 943 |
|
| 944 |
void MaterialEditor::setupSurfaceFlag(const std::string& controlName, Material::SurfaceFlags flag) |
| 945 |
{ |
| 946 |
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(getControl<wxCheckBox>(controlName), |
| 947 |
[=](const MaterialPtr& material) |
| 948 |
{ |
| 949 |
return (material->getSurfaceFlags() & flag) != 0; |
| 950 |
}, |
| 951 |
[this, flag](const MaterialPtr& material, const bool& value) |
| 952 |
{ |
| 953 |
if (_materialUpdateInProgress || !_material) return; |
| 954 |
|
| 955 |
if (value) |
| 956 |
{ |
| 957 |
_material->setSurfaceFlag(flag); |
| 958 |
} |
| 959 |
else |
| 960 |
{ |
| 961 |
_material->clearSurfaceFlag(flag); |
| 962 |
} |
| 963 |
}, |
| 964 |
[this]() { onMaterialChanged(); })); |
| 965 |
} |
| 966 |
|
| 967 |
void MaterialEditor::setupMaterialFlag(const std::string& controlName, Material::Flags flag) |
| 968 |
{ |
| 969 |
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(getControl<wxCheckBox>(controlName), |
| 970 |
[=](const MaterialPtr& material) |
| 971 |
{ |
| 972 |
return (material->getMaterialFlags() & flag) != 0; |
| 973 |
}, |
| 974 |
[=](const MaterialPtr& material, const bool& newValue) |
| 975 |
{ |
| 976 |
if (newValue) |
| 977 |
{ |
| 978 |
material->setMaterialFlag(flag); |
| 979 |
} |
| 980 |
else |
| 981 |
{ |
| 982 |
material->clearMaterialFlag(flag); |
| 983 |
} |
| 984 |
}, |
| 985 |
[this]() // post-update |
| 986 |
{ |
| 987 |
onMaterialChanged(); |
| 988 |
updateMaterialPropertiesFromMaterial(); |
| 989 |
})); |
| 990 |
} |
| 991 |
|
| 992 |
void MaterialEditor::setupMaterialLightFlags() |
| 993 |
{ |
| 994 |
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(getControl<wxCheckBox>("MaterialIsAmbientLight"), |
| 995 |
[](const MaterialPtr& material) { return material->isAmbientLight(); }, |
| 996 |
[=](const MaterialPtr& material, const bool& newValue) |
| 997 |
{ |
| 998 |
material->setIsAmbientLight(newValue); |
| 999 |
}, |
| 1000 |
[this]() // post-update |
| 1001 |
{ |
| 1002 |
onMaterialChanged(); |
| 1003 |
updateMaterialPropertiesFromMaterial(); |
| 1004 |
})); |
| 1005 |
|
| 1006 |
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(getControl<wxCheckBox>("MaterialIsAmbientCubicLight"), |
| 1007 |
[](const MaterialPtr& material) { return material->isAmbientLight() && material->isCubicLight(); }, |
| 1008 |
[=](const MaterialPtr& material, const bool& newValue) |
| 1009 |
{ |
| 1010 |
material->setIsAmbientLight(newValue); |
| 1011 |
material->setIsCubicLight(newValue); |
| 1012 |
}, |
| 1013 |
[this]() // post-update |
| 1014 |
{ |
| 1015 |
onMaterialChanged(); |
| 1016 |
updateMaterialPropertiesFromMaterial(); |
| 1017 |
})); |
| 1018 |
|
| 1019 |
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(getControl<wxCheckBox>("MaterialIsFogLight"), |
| 1020 |
[](const MaterialPtr& material) { return material->isFogLight(); }, |
| 1021 |
[=](const MaterialPtr& material, const bool& newValue) |
| 1022 |
{ |
| 1023 |
material->setIsFogLight(newValue); |
| 1024 |
}, |
| 1025 |
[this]() // post-update |
| 1026 |
{ |
| 1027 |
onMaterialChanged(); |
| 1028 |
updateMaterialPropertiesFromMaterial(); |
| 1029 |
})); |
| 1030 |
|
| 1031 |
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(getControl<wxCheckBox>("MaterialIsCubicLight"), |
| 1032 |
[](const MaterialPtr& material) { return material->isCubicLight(); }, |
| 1033 |
[=](const MaterialPtr& material, const bool& newValue) |
| 1034 |
{ |
| 1035 |
material->setIsCubicLight(newValue); |
| 1036 |
}, |
| 1037 |
[this]() // post-update |
| 1038 |
{ |
| 1039 |
onMaterialChanged(); |
| 1040 |
updateMaterialPropertiesFromMaterial(); |
| 1041 |
})); |
| 1042 |
|
| 1043 |
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(getControl<wxCheckBox>("MaterialIsBlendLight"), |
| 1044 |
[](const MaterialPtr& material) { return material->isBlendLight(); }, |
| 1045 |
[=](const MaterialPtr& material, const bool& newValue) |
| 1046 |
{ |
| 1047 |
material->setIsBlendLight(newValue); |
| 1048 |
}, |
| 1049 |
[this]() // post-update |
| 1050 |
{ |
| 1051 |
onMaterialChanged(); |
| 1052 |
updateMaterialPropertiesFromMaterial(); |
| 1053 |
})); |
| 1054 |
} |
| 1055 |
|
| 1056 |
void MaterialEditor::setupMaterialShaderFlags() |
| 1057 |
{ |
| 1058 |
setupMaterialFlag("MaterialNoShadows", Material::FLAG_NOSHADOWS); |
| 1059 |
setupMaterialFlag("MaterialNoSelfShadow", Material::FLAG_NOSELFSHADOW); |
| 1060 |
setupMaterialFlag("MaterialForceShadows", Material::FLAG_FORCESHADOWS); |
| 1061 |
setupMaterialFlag("MaterialTranslucent", Material::FLAG_TRANSLUCENT); |
| 1062 |
setupMaterialFlag("MaterialNoFog", Material::FLAG_NOFOG); |
| 1063 |
setupMaterialFlag("MaterialFlagNoOverlays", Material::FLAG_NOOVERLAYS); |
| 1064 |
setupMaterialFlag("MaterialFlagForceOverlays", Material::FLAG_FORCEOVERLAYS); |
| 1065 |
setupMaterialFlag("MaterialFlagForceOpaque", Material::FLAG_FORCEOPAQUE); |
| 1066 |
setupMaterialFlag("MaterialFlagNoPortalFog", Material::FLAG_NOPORTALFOG); |
| 1067 |
setupMaterialFlag("MaterialFlagUnsmoothedTangents", Material::FLAG_UNSMOOTHEDTANGENTS); |
| 1068 |
setupMaterialFlag("MaterialFlagMirror", Material::FLAG_MIRROR); |
| 1069 |
setupMaterialFlag("MaterialFlagHasPolygonOffset", Material::FLAG_POLYGONOFFSET); |
| 1070 |
setupMaterialFlag("MaterialFlagIsLightGemSurf", Material::FLAG_ISLIGHTGEMSURF); |
| 1071 |
|
| 1072 |
// Cull types |
| 1073 |
auto cullTypes = getControl<wxChoice>("MaterialCullType"); |
| 1074 |
|
| 1075 |
for (const auto& pair : shaders::CullTypes) |
| 1076 |
{ |
| 1077 |
cullTypes->AppendString(pair.first); |
| 1078 |
} |
| 1079 |
|
| 1080 |
cullTypes->Bind(wxEVT_CHOICE, [this, cullTypes](wxCommandEvent& ev) |
| 1081 |
{ |
| 1082 |
if (!_material || _materialUpdateInProgress) return; |
| 1083 |
_material->setCullType(shaders::getCullTypeForString(cullTypes->GetStringSelection().ToStdString())); |
| 1084 |
onMaterialChanged(); |
| 1085 |
}); |
| 1086 |
|
| 1087 |
// Global Clamping |
| 1088 |
auto clampDropdown = getControl<wxChoice>("MaterialClampType"); |
| 1089 |
for (const auto& pair : shaders::ClampTypeNames) |
| 1090 |
{ |
| 1091 |
clampDropdown->AppendString(pair.first); |
| 1092 |
} |
| 1093 |
|
| 1094 |
clampDropdown->Bind(wxEVT_CHOICE, [this, clampDropdown](wxCommandEvent& ev) |
| 1095 |
{ |
| 1096 |
if (!_material || _materialUpdateInProgress) return; |
| 1097 |
|
| 1098 |
if (_material) |
| 1099 |
{ |
| 1100 |
_material->setClampType(shaders::getClampTypeForString(clampDropdown->GetStringSelection().ToStdString())); |
| 1101 |
onMaterialChanged(); |
| 1102 |
} |
| 1103 |
}); |
| 1104 |
|
| 1105 |
// DECAL_MACRO |
| 1106 |
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(getControl<wxCheckBox>("MaterialHasDecalMacro"), |
| 1107 |
[](const MaterialPtr& material) { return material->getParseFlags() & Material::PF_HasDecalMacro; }, |
| 1108 |
[](const MaterialPtr& material, const bool& newValue) {})); |
| 1109 |
|
| 1110 |
// TWOSIDED_DECAL_MACRO |
| 1111 |
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(getControl<wxCheckBox>("MaterialHasTwoSidedDecalMacro"), |
| 1112 |
[](const MaterialPtr& material) { return material->getParseFlags() & Material::PF_HasTwoSidedDecalMacro; }, |
| 1113 |
[](const MaterialPtr& material, const bool& newValue) {})); |
| 1114 |
|
| 1115 |
// GLASS_MACRO |
| 1116 |
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(getControl<wxCheckBox>("MaterialHasGlassMacro"), |
| 1117 |
[](const MaterialPtr& material) { return material->getParseFlags() & Material::PF_HasGlassMacro; }, |
| 1118 |
[](const MaterialPtr& material, const bool& newValue) {})); |
| 1119 |
|
| 1120 |
// PARTICLE_MACRO |
| 1121 |
_materialBindings.emplace(std::make_shared<CheckBoxBinding<MaterialPtr>>(getControl<wxCheckBox>("MaterialHasParticleMacro"), |
| 1122 |
[](const MaterialPtr& material) { return material->getParseFlags() & Material::PF_HasParticleMacro; }, |
| 1123 |
[](const MaterialPtr& material, const bool& newValue) {})); |
| 1124 |
} |
| 1125 |
|
| 1126 |
void MaterialEditor::setupMaterialSurfaceFlags() |
| 1127 |
{ |
| 1128 |
setupSurfaceFlag("MaterialSurfaceFlagSolid", Material::SurfaceFlags::SURF_SOLID); |
| 1129 |
setupSurfaceFlag("MaterialSurfaceFlagWater", Material::SurfaceFlags::SURF_WATER); |
| 1130 |
setupSurfaceFlag("MaterialSurfaceFlagPlayerclip", Material::SurfaceFlags::SURF_PLAYERCLIP); |
| 1131 |
setupSurfaceFlag("MaterialSurfaceFlagMonsterclip", Material::SurfaceFlags::SURF_MONSTERCLIP); |
| 1132 |
setupSurfaceFlag("MaterialSurfaceFlagMoveableClip", Material::SurfaceFlags::SURF_MOVEABLECLIP); |
| 1133 |
setupSurfaceFlag("MaterialSurfaceFlagIkclip", Material::SurfaceFlags::SURF_IKCLIP); |
| 1134 |
setupSurfaceFlag("MaterialSurfaceFlagBlood", Material::SurfaceFlags::SURF_BLOOD); |
| 1135 |
setupSurfaceFlag("MaterialSurfaceFlagTrigger", Material::SurfaceFlags::SURF_TRIGGER); |
| 1136 |
setupSurfaceFlag("MaterialSurfaceFlagAassolid", Material::SurfaceFlags::SURF_AASSOLID); |
| 1137 |
setupSurfaceFlag("MaterialSurfaceFlagAasobstacle", Material::SurfaceFlags::SURF_AASOBSTACLE); |
| 1138 |
setupSurfaceFlag("MaterialSurfaceFlagFlashlighttrigger", Material::SurfaceFlags::SURF_FLASHLIGHT_TRIGGER); |
| 1139 |
setupSurfaceFlag("MaterialSurfaceFlagNonsolid", Material::SurfaceFlags::SURF_NONSOLID); |
| 1140 |
setupSurfaceFlag("MaterialSurfaceFlagNullnormal", Material::SurfaceFlags::SURF_NULLNORMAL); |
| 1141 |
setupSurfaceFlag("MaterialSurfaceFlagAreaportal", Material::SurfaceFlags::SURF_AREAPORTAL); |
| 1142 |
setupSurfaceFlag("MaterialSurfaceFlagQernocarve", Material::SurfaceFlags::SURF_NOCARVE); |
| 1143 |
setupSurfaceFlag("MaterialSurfaceFlagDiscrete", Material::SurfaceFlags::SURF_DISCRETE); |
| 1144 |
setupSurfaceFlag("MaterialSurfaceFlagNofragment", Material::SurfaceFlags::SURF_NOFRAGMENT); |
| 1145 |
setupSurfaceFlag("MaterialSurfaceFlagSlick", Material::SurfaceFlags::SURF_SLICK); |
| 1146 |
setupSurfaceFlag("MaterialSurfaceFlagCollision", Material::SurfaceFlags::SURF_COLLISION); |
| 1147 |
setupSurfaceFlag("MaterialSurfaceFlagNoimpact", Material::SurfaceFlags::SURF_NOIMPACT); |
| 1148 |
setupSurfaceFlag("MaterialSurfaceFlagNodamage", Material::SurfaceFlags::SURF_NODAMAGE); |
| 1149 |
setupSurfaceFlag("MaterialSurfaceFlagLadder", Material::SurfaceFlags::SURF_LADDER); |
| 1150 |
setupSurfaceFlag("MaterialSurfaceFlagNosteps", Material::SurfaceFlags::SURF_NOSTEPS); |
| 1151 |
setupSurfaceFlag("MaterialHasGuiSurf", Material::SurfaceFlags::SURF_GUISURF); |
| 1152 |
} |
| 1153 |
|
| 1154 |
void MaterialEditor::setupMaterialDeformPage() |
| 1155 |
{ |
| 1156 |
auto* dropdown = getControl<wxChoice>("MaterialEditorDeformChoice"); |
| 1157 |
|
| 1158 |
dropdown->AppendString(_("None")); |
| 1159 |
|
| 1160 |
for (const auto& pair : shaders::DeformTypeNames) |
| 1161 |
{ |
| 1162 |
dropdown->AppendString(pair.first); |
| 1163 |
} |
| 1164 |
|
| 1165 |
_deformPanels[Material::DEFORM_FLARE] = getControl<wxPanel>("DeformFlarePanel"); |
| 1166 |
_deformPanels[Material::DEFORM_EXPAND] = getControl<wxPanel>("DeformExpandPanel"); |
| 1167 |
_deformPanels[Material::DEFORM_MOVE] = getControl<wxPanel>("DeformMovePanel"); |
| 1168 |
_deformPanels[Material::DEFORM_TURBULENT] = getControl<wxPanel>("DeformTurbulentPanel"); |
| 1169 |
_deformPanels[Material::DEFORM_PARTICLE] = getControl<wxPanel>("DeformParticlePanel"); |
| 1170 |
_deformPanels[Material::DEFORM_PARTICLE2] = getControl<wxPanel>("DeformParticle2Panel"); |
| 1171 |
} |
| 1172 |
|
| 1173 |
void MaterialEditor::setupMaterialStageView() |
| 1174 |
{ |
| 1175 |
_iconVisible = wxutil::GetLocalBitmap(ICON_STAGE_VISIBLE); |
| 1176 |
_iconInvisible = wxutil::GetLocalBitmap(ICON_STAGE_INVISIBLE); |
| 1177 |
|
| 1178 |
// Stage view |
| 1179 |
auto* panel = getControl<wxPanel>("MaterialEditorStageView"); |
| 1180 |
|
| 1181 |
_stageView = wxutil::TreeView::CreateWithModel(panel, _stageList.get(), wxDV_NO_HEADER); |
| 1182 |
panel->GetSizer()->Add(_stageView, 1, wxEXPAND); |
| 1183 |
|
| 1184 |
_stageView->AppendBitmapColumn(_("Enabled"), STAGE_COLS().icon.getColumnIndex(), |
| 1185 |
wxDATAVIEW_CELL_ACTIVATABLE, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE); |
| 1186 |
_stageView->AppendTextColumn(_("Stage"), STAGE_COLS().name.getColumnIndex(), |
| 1187 |
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE); |
| 1188 |
|
| 1189 |
_stageView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &MaterialEditor::_onStageListSelectionChanged, this); |
| 1190 |
_stageView->Bind(wxEVT_DATAVIEW_ITEM_ACTIVATED, &MaterialEditor::_onStageListItemActivated, this); |
| 1191 |
|
| 1192 |
getControl<wxButton>("MaterialEditorAddStageButton")->Bind(wxEVT_BUTTON, &MaterialEditor::_onAddStage, this); |
| 1193 |
getControl<wxButton>("MaterialEditorRemoveStageButton")->Bind(wxEVT_BUTTON, &MaterialEditor::_onRemoveStage, this); |
| 1194 |
getControl<wxButton>("MaterialEditorToggleStageButton")->Bind(wxEVT_BUTTON, &MaterialEditor::_onToggleStage, this); |
| 1195 |
getControl<wxButton>("MaterialEditorMoveUpStageButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { moveStagePosition(-1); }); |
| 1196 |
getControl<wxButton>("MaterialEditorMoveDownStageButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { moveStagePosition(+1); }); |
| 1197 |
getControl<wxButton>("MaterialEditorDuplicateStageButton")->Bind(wxEVT_BUTTON, &MaterialEditor::_onDuplicateStage, this); |
| 1198 |
|
| 1199 |
auto row = _stageList->AddItem(); |
| 1200 |
|
| 1201 |
row[STAGE_COLS().global] = true; |
| 1202 |
row[STAGE_COLS().index] = -1; |
| 1203 |
row[STAGE_COLS().icon] = wxVariant(wxutil::GetLocalBitmap(ICON_GLOBAL_SETTINGS)); |
| 1204 |
row[STAGE_COLS().name] = _("Global Settings"); |
| 1205 |
row[STAGE_COLS().enabled] = true; |
| 1206 |
|
| 1207 |
wxDataViewItemAttr globalStyle; |
| 1208 |
globalStyle.SetColour(wxColor(15, 15, 15)); |
| 1209 |
globalStyle.SetBold(true); |
| 1210 |
row[STAGE_COLS().name].setAttr(globalStyle); |
| 1211 |
|
| 1212 |
row.SendItemAdded(); |
| 1213 |
|
| 1214 |
auto notebook = getControl<wxNotebook>("MaterialStageSettingsNotebook"); |
| 1215 |
for (int i = 0; i < notebook->GetPageCount(); ++i) |
| 1216 |
{ |
| 1217 |
auto page = notebook->GetPage(i); |
| 1218 |
_notebookPages.emplace(i, std::make_pair(page, notebook->GetPageText(i))); |
| 1219 |
} |
| 1220 |
} |
| 1221 |
|
| 1222 |
void MaterialEditor::setupStageFlag(const std::string& controlName, IShaderLayer::Flags flag) |
| 1223 |
{ |
| 1224 |
_stageBindings.emplace(std::make_shared<CheckBoxBinding<IShaderLayer::Ptr>>(getControl<wxCheckBox>(controlName), |
| 1225 |
[=](const IShaderLayer::Ptr& layer) |
| 1226 |
{ |
| 1227 |
return (layer->getStageFlags() & flag) == flag; |
| 1228 |
}, |
| 1229 |
[=](const IEditableShaderLayer::Ptr& layer, const bool& value) |
| 1230 |
{ |
| 1231 |
if (value) |
| 1232 |
{ |
| 1233 |
layer->setStageFlag(flag); |
| 1234 |
} |
| 1235 |
else |
| 1236 |
{ |
| 1237 |
layer->clearStageFlag(flag); |
| 1238 |
} |
| 1239 |
}, |
| 1240 |
std::bind(&MaterialEditor::onMaterialChanged, this), |
| 1241 |
std::bind(&MaterialEditor::getEditableStageForSelection, this))); |
| 1242 |
} |
| 1243 |
|
| 1244 |
void MaterialEditor::createExpressionBinding(const std::string& textCtrlName, |
| 1245 |
const std::function<shaders::IShaderExpression::Ptr(const IShaderLayer::Ptr&)>& loadFunc, |
| 1246 |
const std::function<void(const IEditableShaderLayer::Ptr&, const std::string&)>& saveFunc) |
| 1247 |
{ |
| 1248 |
_stageBindings.emplace(std::make_shared<ExpressionBinding<IShaderLayer::Ptr>>( |
| 1249 |
getControl<wxTextCtrl>(textCtrlName), |
| 1250 |
[loadFunc] (const IShaderLayer::Ptr& layer) |
| 1251 |
{ |
| 1252 |
auto expr = loadFunc(layer); |
| 1253 |
return expr ? expr->getExpressionString() : std::string(); |
| 1254 |
}, |
| 1255 |
saveFunc, |
| 1256 |
std::bind(&MaterialEditor::onMaterialChanged, this), |
| 1257 |
std::bind(&MaterialEditor::getEditableStageForSelection, this))); |
| 1258 |
} |
| 1259 |
|
| 1260 |
void MaterialEditor::createRadioButtonBinding(const std::string& ctrlName, |
| 1261 |
const std::function<bool(const IShaderLayer::Ptr&)>& loadFunc, |
| 1262 |
const std::function<void(const IEditableShaderLayer::Ptr&, bool)>& saveFunc) |
| 1263 |
{ |
| 1264 |
_stageBindings.emplace(std::make_shared<RadioButtonBinding<IShaderLayer::Ptr>>( |
| 1265 |
getControl<wxRadioButton>(ctrlName), |
| 1266 |
loadFunc, |
| 1267 |
saveFunc, |
| 1268 |
std::bind(&MaterialEditor::onMaterialChanged, this), |
| 1269 |
std::bind(&MaterialEditor::getEditableStageForSelection, this))); |
| 1270 |
} |
| 1271 |
|
| 1272 |
void MaterialEditor::createSpinCtrlBinding(const std::string& ctrlName, |
| 1273 |
const std::function<int(const IShaderLayer::Ptr&)>& loadFunc, |
| 1274 |
const std::function<void(const IEditableShaderLayer::Ptr&, int)>& saveFunc) |
| 1275 |
{ |
| 1276 |
_stageBindings.emplace(std::make_shared<SpinCtrlBinding<wxSpinCtrl, IShaderLayer::Ptr>>( |
| 1277 |
getControl<wxSpinCtrl>(ctrlName), |
| 1278 |
loadFunc, |
| 1279 |
saveFunc, |
| 1280 |
std::bind(&MaterialEditor::onMaterialChanged, this), |
| 1281 |
std::bind(&MaterialEditor::getEditableStageForSelection, this))); |
| 1282 |
} |
| 1283 |
|
| 1284 |
void MaterialEditor::createSpinCtrlDoubleBinding(const std::string& ctrlName, |
| 1285 |
const std::function<double(const IShaderLayer::Ptr&)>& loadFunc, |
| 1286 |
const std::function<void(const IEditableShaderLayer::Ptr&, double)>& saveFunc) |
| 1287 |
{ |
| 1288 |
_stageBindings.emplace(std::make_shared<SpinCtrlBinding<wxSpinCtrlDouble, IShaderLayer::Ptr>>( |
| 1289 |
getControl<wxSpinCtrlDouble>(ctrlName), |
| 1290 |
loadFunc, |
| 1291 |
saveFunc, |
| 1292 |
std::bind(&MaterialEditor::onMaterialChanged, this), |
| 1293 |
std::bind(&MaterialEditor::getEditableStageForSelection, this))); |
| 1294 |
} |
| 1295 |
|
| 1296 |
void MaterialEditor::applyMapExpressionToStage(const IEditableShaderLayer::Ptr& stage, const std::string& value) |
| 1297 |
{ |
| 1298 |
// Try to keep an existing frob highlight stage intact |
| 1299 |
bool hadFrobHighlightStage = false; |
| 1300 |
|
| 1301 |
if (stage->getType() == IShaderLayer::DIFFUSE) |
| 1302 |
{ |
| 1303 |
hadFrobHighlightStage = shaders::FrobStageSetup::IsPresent(_material); |
| 1304 |
|
| 1305 |
if (hadFrobHighlightStage) |
| 1306 |
{ |
| 1307 |
shaders::FrobStageSetup::RemoveFromMaterial(_material); |
| 1308 |
} |
| 1309 |
} |
| 1310 |
|
| 1311 |
stage->setMapExpressionFromString(value); |
| 1312 |
|
| 1313 |
if (hadFrobHighlightStage) |
| 1314 |
{ |
| 1315 |
shaders::FrobStageSetup::AddToMaterial(_material); |
| 1316 |
} |
| 1317 |
} |
| 1318 |
|
| 1319 |
void MaterialEditor::setupMaterialStageProperties() |
| 1320 |
{ |
| 1321 |
auto stageImageMap = getControl<MapExpressionEntry>("MaterialStageImageMap"); |
| 1322 |
_stageBindings.emplace(std::make_shared<ExpressionBinding<IShaderLayer::Ptr>>(stageImageMap->GetTextCtrl(), |
| 1323 |
[](const IShaderLayer::Ptr& stage) |
| 1324 |
{ |
| 1325 |
auto expr = stage->getMapExpression(); |
| 1326 |
return expr ? expr->getExpressionString() : std::string(); |
| 1327 |
}, |
| 1328 |
[this](const IEditableShaderLayer::Ptr& stage, const std::string& value) |
| 1329 |
{ |
| 1330 |
if (_stageUpdateInProgress) return; |
| 1331 |
applyMapExpressionToStage(stage, value); |
| 1332 |
}, |
| 1333 |
[this]() { onMaterialChanged(); updateBasicPageFromMaterial(); }, |
| 1334 |
std::bind(&MaterialEditor::getEditableStageForSelection, this))); |
| 1335 |
|
| 1336 |
setupStageFlag("MaterialStageFlagMaskRed", IShaderLayer::FLAG_MASK_RED); |
| 1337 |
setupStageFlag("MaterialStageFlagMaskGreen", IShaderLayer::FLAG_MASK_GREEN); |
| 1338 |
setupStageFlag("MaterialStageFlagMaskBlue", IShaderLayer::FLAG_MASK_BLUE); |
| 1339 |
setupStageFlag("MaterialStageFlagMaskAlpha", IShaderLayer::FLAG_MASK_ALPHA); |
| 1340 |
|
| 1341 |
_stageBindings.emplace(std::make_shared<CheckBoxBinding<IShaderLayer::Ptr>>(getControl<wxCheckBox>("MaterialStageFlagMaskColour"), |
| 1342 |
[=](const IShaderLayer::Ptr& layer) |
| 1343 |
{ |
| 1344 |
auto colourFlags = IShaderLayer::FLAG_MASK_RED | IShaderLayer::FLAG_MASK_GREEN | IShaderLayer::FLAG_MASK_BLUE; |
| 1345 |
return (layer->getStageFlags() & colourFlags) == colourFlags; |
| 1346 |
}, |
| 1347 |
[=](const IEditableShaderLayer::Ptr& layer, const bool& value) |
| 1348 |
{ |
| 1349 |
if (value) |
| 1350 |
{ |
| 1351 |
layer->setStageFlag(IShaderLayer::FLAG_MASK_RED); |
| 1352 |
layer->setStageFlag(IShaderLayer::FLAG_MASK_GREEN); |
| 1353 |
layer->setStageFlag(IShaderLayer::FLAG_MASK_BLUE); |
| 1354 |
} |
| 1355 |
else |
| 1356 |
{ |
| 1357 |
layer->clearStageFlag(IShaderLayer::FLAG_MASK_RED); |
| 1358 |
layer->clearStageFlag(IShaderLayer::FLAG_MASK_GREEN); |
| 1359 |
layer->clearStageFlag(IShaderLayer::FLAG_MASK_BLUE); |
| 1360 |
} |
| 1361 |
}, |
| 1362 |
std::bind(&MaterialEditor::onMaterialChanged, this), |
| 1363 |
std::bind(&MaterialEditor::getEditableStageForSelection, this))); |
| 1364 |
|
| 1365 |
setupStageFlag("MaterialStageFlagMaskDepth", IShaderLayer::FLAG_MASK_DEPTH); |
| 1366 |
setupStageFlag("MaterialStageIgnoreAlphaTest", IShaderLayer::FLAG_IGNORE_ALPHATEST); |
| 1367 |
|
| 1368 |
createExpressionBinding("MaterialStageAlphaTestExpression", |
| 1369 |
[](const IShaderLayer::Ptr& layer) { return layer->getAlphaTestExpression(); }, |
| 1370 |
[this](const IEditableShaderLayer::Ptr& layer, const std::string& value) |
| 1371 |
{ |
| 1372 |
layer->setAlphaTestExpressionFromString(value); |
| 1373 |
}); |
| 1374 |
|
| 1375 |
for (const auto& value : { "diffusemap", "bumpmap", "specularmap", "blend", "add", "filter", "modulate", "none" }) |
| 1376 |
{ |
| 1377 |
getControl<wxChoice>("MaterialStageBlendType")->Append(value); |
| 1378 |
} |
| 1379 |
|
| 1380 |
getControl<wxChoice>("MaterialStageBlendType")->Append(_(CUSTOM_BLEND_TYPE)); |
| 1381 |
|
| 1382 |
for (const auto& value : { |
| 1383 |
"gl_one", "gl_zero", "gl_dst_color", "gl_one_minus_dst_color", "gl_src_alpha", |
| 1384 |
"gl_one_minus_src_alpha", "gl_dst_alpha", "gl_one_minus_dst_alpha", "gl_src_alpha_saturate" |
| 1385 |
}) |
| 1386 |
{ |
| 1387 |
getControl<wxChoice>("MaterialStageBlendTypeSrc")->Append(value); |
| 1388 |
} |
| 1389 |
|
| 1390 |
for (const auto& value : { |
| 1391 |
"gl_one", "gl_zero", "gl_src_color", "gl_one_minus_src_color", "gl_src_alpha", |
| 1392 |
"gl_one_minus_src_alpha", "gl_dst_alpha", "gl_one_minus_dst_alpha" |
| 1393 |
}) |
| 1394 |
{ |
| 1395 |
getControl<wxChoice>("MaterialStageBlendTypeDest")->Append(value); |
| 1396 |
} |
| 1397 |
|
| 1398 |
getControl<wxChoice>("MaterialStageBlendType")->Bind(wxEVT_CHOICE, &MaterialEditor::_onStageBlendTypeChanged, this);; |
| 1399 |
getControl<wxChoice>("MaterialStageBlendTypeSrc")->Bind(wxEVT_CHOICE, &MaterialEditor::_onStageBlendTypeChanged, this);; |
| 1400 |
getControl<wxChoice>("MaterialStageBlendTypeDest")->Bind(wxEVT_CHOICE, &MaterialEditor::_onStageBlendTypeChanged, this);; |
| 1401 |
|
| 1402 |
auto mapTypeDropdown = getControl<wxChoice>("MaterialStageMapType"); |
| 1403 |
|
| 1404 |
for (const auto& value : shaders::MapTypeNames) |
| 1405 |
{ |
| 1406 |
mapTypeDropdown->Append(value.first); |
| 1407 |
} |
| 1408 |
|
| 1409 |
mapTypeDropdown->Bind(wxEVT_CHOICE, &MaterialEditor::_onStageMapTypeChanged, this); |
| 1410 |
|
| 1411 |
createSpinCtrlBinding("MaterialStageRenderMapWidth", |
| 1412 |
[](const IShaderLayer::Ptr& layer) { return static_cast<int>(layer->getRenderMapSize().x()); }, |
| 1413 |
[this](const IEditableShaderLayer::Ptr& layer, const int& value) |
| 1414 |
{ |
| 1415 |
auto currentSize = layer->getRenderMapSize(); |
| 1416 |
layer->setRenderMapSize(Vector2(value, currentSize.y())); |
| 1417 |
}); |
| 1418 |
createSpinCtrlBinding("MaterialStageRenderMapHeight", |
| 1419 |
[](const IShaderLayer::Ptr& layer) { return static_cast<int>(layer->getRenderMapSize().y()); }, |
| 1420 |
[this](const IEditableShaderLayer::Ptr& layer, const int& value) |
| 1421 |
{ |
| 1422 |
auto currentSize = layer->getRenderMapSize(); |
| 1423 |
layer->setRenderMapSize(Vector2(currentSize.x(), value)); |
| 1424 |
}); |
| 1425 |
|
| 1426 |
getControl<wxCheckBox>("MaterialStageSoundMapWaveform")->Bind(wxEVT_CHECKBOX, [this] (wxCommandEvent& ev) |
| 1427 |
{ |
| 1428 |
if (this->_stageUpdateInProgress) return; |
| 1429 |
auto stage = getEditableStageForSelection(); |
| 1430 |
if (!stage) return; |
| 1431 |
|
| 1432 |
stage->setSoundMapWaveForm(ev.IsChecked()); |
| 1433 |
}); |
| 1434 |
|
| 1435 |
getControl<wxCheckBox>("MaterialStageVideoMapLoop")->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& ev) |
| 1436 |
{ |
| 1437 |
if (this->_stageUpdateInProgress) return; |
| 1438 |
auto stage = getEditableStageForSelection(); |
| 1439 |
if (!stage) return; |
| 1440 |
|
| 1441 |
auto filePath = getControl<MapExpressionEntry>("MaterialStageImageMap")->GetValue().ToStdString(); |
| 1442 |
stage->setVideoMapProperties(filePath, ev.IsChecked()); |
| 1443 |
}); |
| 1444 |
|
| 1445 |
createSpinCtrlDoubleBinding("MaterialStagePrivatePolygonOffset", |
| 1446 |
[](const IShaderLayer::Ptr& layer) { return layer->getPrivatePolygonOffset(); }, |
| 1447 |
[this](const IEditableShaderLayer::Ptr& layer, const double& value) |
| 1448 |
{ |
| 1449 |
layer->setPrivatePolygonOffset(value); |
| 1450 |
}); |
| 1451 |
|
| 1452 |
// Texture |
| 1453 |
setupStageFlag("MaterialStageFilterNearest", IShaderLayer::FLAG_FILTER_NEAREST); |
| 1454 |
setupStageFlag("MaterialStageFilterLinear", IShaderLayer::FLAG_FILTER_LINEAR); |
| 1455 |
setupStageFlag("MaterialStageHighQuality", IShaderLayer::FLAG_HIGHQUALITY); |
| 1456 |
setupStageFlag("MaterialStageForceHighQuality", IShaderLayer::FLAG_FORCE_HIGHQUALITY); |
| 1457 |
setupStageFlag("MaterialStageNoPicMip", IShaderLayer::FLAG_NO_PICMIP); |
| 1458 |
setupStageFlag("MaterialStageIgnoreDepth", IShaderLayer::FLAG_IGNORE_DEPTH); |
| 1459 |
|
| 1460 |
auto texgenDropdown = getControl<wxChoice>("MaterialStageTexGenType"); |
| 1461 |
texgenDropdown->AppendString(""); |
| 1462 |
|
| 1463 |
for (const auto& pair : shaders::TexGenTypeNames) |
| 1464 |
{ |
| 1465 |
texgenDropdown->AppendString(pair.first); |
| 1466 |
} |
| 1467 |
|
| 1468 |
texgenDropdown->Bind(wxEVT_CHOICE, [this, texgenDropdown](wxCommandEvent& ev) |
| 1469 |
{ |
| 1470 |
auto stage = getEditableStageForSelection(); |
| 1471 |
|
| 1472 |
if (stage) |
| 1473 |
{ |
| 1474 |
stage->setTexGenType(shaders::getTexGenTypeForString(texgenDropdown->GetStringSelection().ToStdString())); |
| 1475 |
updateStageTextureControls(); |
| 1476 |
} |
| 1477 |
}); |
| 1478 |
|
| 1479 |
createExpressionBinding("MaterialStageWobbleSkyX", |
| 1480 |
[](const IShaderLayer::Ptr& layer) { return layer->getExpression(IShaderLayer::Expression::TexGenParam1); }, |
| 1481 |
[this](const IEditableShaderLayer::Ptr& layer, const std::string& value) |
| 1482 |
{ |
| 1483 |
layer->setTexGenExpressionFromString(0, value); |
| 1484 |
}); |
| 1485 |
createExpressionBinding("MaterialStageWobbleSkyY", |
| 1486 |
[](const IShaderLayer::Ptr& layer) { return layer->getExpression(IShaderLayer::Expression::TexGenParam2); }, |
| 1487 |
[this](const IEditableShaderLayer::Ptr& layer, const std::string& value) |
| 1488 |
{ |
| 1489 |
layer->setTexGenExpressionFromString(1, value); |
| 1490 |
}); |
| 1491 |
createExpressionBinding("MaterialStageWobbleSkyZ", |
| 1492 |
[](const IShaderLayer::Ptr& layer) { return layer->getExpression(IShaderLayer::Expression::TexGenParam3); }, |
| 1493 |
[this](const IEditableShaderLayer::Ptr& layer, const std::string& value) |
| 1494 |
{ |
| 1495 |
layer->setTexGenExpressionFromString(2, value); |
| 1496 |
}); |
| 1497 |
|
| 1498 |
// Clamp Type |
| 1499 |
auto clampDropdown = getControl<wxChoice>("MaterialStageClampType"); |
| 1500 |
for (const auto& pair : shaders::ClampTypeNames) |
| 1501 |
{ |
| 1502 |
clampDropdown->AppendString(pair.first); |
| 1503 |
} |
| 1504 |
|
| 1505 |
clampDropdown->Bind(wxEVT_CHOICE, [this, clampDropdown](wxCommandEvent& ev) |
| 1506 |
{ |
| 1507 |
auto stage = getEditableStageForSelection(); |
| 1508 |
|
| 1509 |
if (stage) |
| 1510 |
{ |
| 1511 |
stage->setClampType(shaders::getClampTypeForString(clampDropdown->GetStringSelection().ToStdString())); |
| 1512 |
onMaterialChanged(); |
| 1513 |
} |
| 1514 |
}); |
| 1515 |
|
| 1516 |
auto transformDropdown = getControl<wxChoice>("MaterialStageAddTransformChoice"); |
| 1517 |
for (const auto& pair : shaders::TransformTypeNames) |
| 1518 |
{ |
| 1519 |
transformDropdown->AppendString(pair.first); |
| 1520 |
} |
| 1521 |
|
| 1522 |
getControl<wxButton>("MaterialStageAddTransformButton")->Bind(wxEVT_BUTTON, &MaterialEditor::_onAddStageTransform, this); |
| 1523 |
getControl<wxButton>("MaterialStageRemoveTransformButton")->Bind(wxEVT_BUTTON, &MaterialEditor::_onRemoveStageTransform, this); |
| 1524 |
|
| 1525 |
// Add the transformation listview |
| 1526 |
auto transformationPanel = getControl<wxPanel>("MaterialStageTransformations"); |
| 1527 |
_stageTransformations = wxutil::TreeModel::Ptr(new wxutil::TreeModel(_stageTransformationColumns, true)); |
| 1528 |
|
| 1529 |
_stageTransformView = wxutil::TreeView::CreateWithModel(transformationPanel, _stageTransformations.get()); |
| 1530 |
_stageTransformView->AppendTextColumn(_("#"), _stageTransformationColumns.index.getColumnIndex(), |
| 1531 |
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE); |
| 1532 |
_stageTransformView->AppendTextColumn(_("Type"), _stageTransformationColumns.type.getColumnIndex(), |
| 1533 |
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE); |
| 1534 |
_stageTransformView->AppendTextColumn(_("Expression 1"), _stageTransformationColumns.expression1.getColumnIndex(), |
| 1535 |
wxDATAVIEW_CELL_EDITABLE, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE); |
| 1536 |
_stageTransformView->AppendTextColumn(_("Expression 2"), _stageTransformationColumns.expression2.getColumnIndex(), |
| 1537 |
wxDATAVIEW_CELL_EDITABLE, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE); |
| 1538 |
|
| 1539 |
_stageTransformView->Bind(wxEVT_DATAVIEW_ITEM_EDITING_DONE, &MaterialEditor::_onStageTransformEdited, this); |
| 1540 |
_stageTransformView->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this] (wxDataViewEvent&) |
| 1541 |
{ |
| 1542 |
getControl<wxButton>("MaterialStageRemoveTransformButton")->Enable(_stageTransformView->GetSelection().IsOk()); |
| 1543 |
}); |
| 1544 |
|
| 1545 |
transformationPanel->GetSizer()->Add(_stageTransformView, 1, wxEXPAND); |
| 1546 |
|
| 1547 |
createExpressionBinding("MaterialStageCondition", |
| 1548 |
[](const IShaderLayer::Ptr& layer) { return layer->getConditionExpression(); }, |
| 1549 |
[](const IEditableShaderLayer::Ptr& layer, const std::string& value) { layer->setConditionExpressionFromString(value); }); |
| 1550 |
|
| 1551 |
_stageBindings.emplace(std::make_shared<CheckBoxBinding<IShaderLayer::Ptr>>(getControl<wxCheckBox>("MaterialStageColored"), |
| 1552 |
[](const IShaderLayer::Ptr& layer) { return stageQualifiesAsColoured(layer); }, |
| 1553 |
[this](const IEditableShaderLayer::Ptr& layer, const bool& value) { _onStageColoredChecked(layer, value); }, |
| 1554 |
std::bind(&MaterialEditor::onMaterialChanged, this), |
| 1555 |
std::bind(&MaterialEditor::getEditableStageForSelection, this))); |
| 1556 |
|
| 1557 |
createRadioButtonBinding("MaterialStageNoVertexColourFlag", |
| 1558 |
[](const IShaderLayer::Ptr& layer) { return layer->getVertexColourMode() == IShaderLayer::VERTEX_COLOUR_NONE; }, |
| 1559 |
[](const IEditableShaderLayer::Ptr& layer, bool value) { if (value) layer->setVertexColourMode(IShaderLayer::VERTEX_COLOUR_NONE); }); |
| 1560 |
createRadioButtonBinding("MaterialStageVertexColourFlag", |
| 1561 |
[](const IShaderLayer::Ptr& layer) { return layer->getVertexColourMode() == IShaderLayer::VERTEX_COLOUR_MULTIPLY; }, |
| 1562 |
[](const IEditableShaderLayer::Ptr& layer, bool value) { if (value) layer->setVertexColourMode(IShaderLayer::VERTEX_COLOUR_MULTIPLY); }); |
| 1563 |
createRadioButtonBinding("MaterialStageInverseVertexColourFlag", |
| 1564 |
[](const IShaderLayer::Ptr& layer) { return layer->getVertexColourMode() == IShaderLayer::VERTEX_COLOUR_INVERSE_MULTIPLY; }, |
| 1565 |
[](const IEditableShaderLayer::Ptr& layer, bool value) { if (value) layer->setVertexColourMode(IShaderLayer::VERTEX_COLOUR_INVERSE_MULTIPLY); }); |
| 1566 |
|
| 1567 |
createExpressionBinding("MaterialStageRed", |
| 1568 |
[](const IShaderLayer::Ptr& layer) { return layer->getColourExpression(IShaderLayer::COMP_RED); }, |
| 1569 |
[this](const IEditableShaderLayer::Ptr& layer, const std::string& value) |
| 1570 |
{ |
| 1571 |
layer->setColourExpressionFromString(IShaderLayer::COMP_RED, value); |
| 1572 |
updateStageColoredStatus(); |
| 1573 |
}); |
| 1574 |
createExpressionBinding("MaterialStageGreen", |
| 1575 |
[](const IShaderLayer::Ptr& layer) { return layer->getColourExpression(IShaderLayer::COMP_GREEN); }, |
| 1576 |
[this](const IEditableShaderLayer::Ptr& layer, const std::string& value) |
| 1577 |
{ |
| 1578 |
layer->setColourExpressionFromString(IShaderLayer::COMP_GREEN, value); |
| 1579 |
updateStageColoredStatus(); |
| 1580 |
}); |
| 1581 |
createExpressionBinding("MaterialStageBlue", |
| 1582 |
[](const IShaderLayer::Ptr& layer) { return layer->getColourExpression(IShaderLayer::COMP_BLUE); }, |
| 1583 |
[this](const IEditableShaderLayer::Ptr& layer, const std::string& value) |
| 1584 |
{ |
| 1585 |
layer->setColourExpressionFromString(IShaderLayer::COMP_BLUE, value); |
| 1586 |
updateStageColoredStatus(); |
| 1587 |
}); |
| 1588 |
createExpressionBinding("MaterialStageAlpha", |
| 1589 |
[](const IShaderLayer::Ptr& layer) { return layer->getColourExpression(IShaderLayer::COMP_ALPHA); }, |
| 1590 |
[this](const IEditableShaderLayer::Ptr& layer, const std::string& value) |
| 1591 |
{ |
| 1592 |
layer->setColourExpressionFromString(IShaderLayer::COMP_ALPHA, value); |
| 1593 |
updateStageColoredStatus(); |
| 1594 |
}); |
| 1595 |
|
| 1596 |
auto parameterPanel = getControl<wxPanel>("MaterialStageProgramParameters"); |
| 1597 |
_stageProgramParameters = wxutil::TreeModel::Ptr(new wxutil::TreeModel(_stageProgramColumns, true)); |
| 1598 |
|
| 1599 |
auto paramsView = wxutil::TreeView::CreateWithModel(parameterPanel, _stageProgramParameters.get(), wxDV_NO_HEADER); |
| 1600 |
paramsView->AppendTextColumn("Index", _stageProgramColumns.index.getColumnIndex(), |
| 1601 |
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE); |
| 1602 |
paramsView->AppendTextColumn("Type", _stageProgramColumns.type.getColumnIndex(), |
| 1603 |
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE); |
| 1604 |
paramsView->AppendTextColumn("Expression", _stageProgramColumns.expression.getColumnIndex(), |
| 1605 |
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE); |
| 1606 |
|
| 1607 |
parameterPanel->GetSizer()->Add(paramsView, 1, wxEXPAND); |
| 1608 |
} |
| 1609 |
|
| 1610 |
void MaterialEditor::updateStageColoredStatus() |
| 1611 |
{ |
| 1612 |
auto selectedStage = getSelectedStage(); |
| 1613 |
|
| 1614 |
if (!selectedStage) return; |
| 1615 |
|
| 1616 |
bool stageIsColoured = stageQualifiesAsColoured(selectedStage); |
| 1617 |
|
| 1618 |
getControl<wxCheckBox>("MaterialStageColored")->SetValue(stageIsColoured); |
| 1619 |
|
| 1620 |
getControl<wxTextCtrl>("MaterialStageRed")->Enable(!stageIsColoured); |
| 1621 |
getControl<wxTextCtrl>("MaterialStageGreen")->Enable(!stageIsColoured); |
| 1622 |
getControl<wxTextCtrl>("MaterialStageBlue")->Enable(!stageIsColoured); |
| 1623 |
getControl<wxTextCtrl>("MaterialStageAlpha")->Enable(!stageIsColoured); |
| 1624 |
} |
| 1625 |
|
| 1626 |
bool MaterialEditor::saveCurrentMaterial() |
| 1627 |
{ |
| 1628 |
if (!_material->isModified()) |
| 1629 |
{ |
| 1630 |
return true; |
| 1631 |
} |
| 1632 |
|
| 1633 |
if (_material->getShaderFileInfo().fullPath().empty()) |
| 1634 |
{ |
| 1635 |
auto mtrExtension = shaders::getMaterialFileExtension(); |
| 1636 |
auto materialsFolderName = shaders::getMaterialsFolderName(); |
| 1637 |
|
| 1638 |
while (true) |
| 1639 |
{ |
| 1640 |
// Ask the user where to save it |
| 1641 |
wxutil::FileChooser chooser(this, _("Select Material file"), false, "material", "." + mtrExtension); |
| 1642 |
|
| 1643 |
fs::path materialsPath = game::current::getWriteableGameResourcePath(); |
| 1644 |
materialsPath /= materialsFolderName; |
| 1645 |
|
| 1646 |
if (!os::fileOrDirExists(materialsPath.string())) |
| 1647 |
{ |
| 1648 |
rMessage() << "Ensuring materials path: " << materialsPath << std::endl; |
| 1649 |
fs::create_directories(materialsPath); |
| 1650 |
} |
| 1651 |
|
| 1652 |
// Point the file chooser to that new file |
| 1653 |
chooser.setCurrentPath(materialsPath.string()); |
| 1654 |
chooser.askForOverwrite(false); |
| 1655 |
|
| 1656 |
auto result = chooser.display(); |
| 1657 |
|
| 1658 |
if (result.empty()) |
| 1659 |
{ |
| 1660 |
return false; // save aborted |
| 1661 |
} |
| 1662 |
|
| 1663 |
try |
| 1664 |
{ |
| 1665 |
// Setting the path might fail if it's invalid, try to set it and break the loop |
| 1666 |
_material->setShaderFileName(os::standardPath(result)); |
| 1667 |
break; |
| 1668 |
} |
| 1669 |
catch (const std::invalid_argument& ex) |
| 1670 |
{ |
| 1671 |
// Invalid path, notify user and get ready for the next round |
| 1672 |
wxutil::Messagebox::ShowError(ex.what(), this); |
| 1673 |
} |
| 1674 |
} |
| 1675 |
} |
| 1676 |
|
| 1677 |
try |
| 1678 |
{ |
| 1679 |
// Write to the specified .mtr file |
| 1680 |
GlobalMaterialManager().saveMaterial(_material->getName()); |
| 1681 |
|
| 1682 |
_material = GlobalMaterialManager().getMaterial(_material->getName()); |
| 1683 |
selectMaterial(_material); |
| 1684 |
} |
| 1685 |
catch (const std::runtime_error& ex) |
| 1686 |
{ |
| 1687 |
rError() << "Could not save file: " << ex.what() << std::endl; |
| 1688 |
wxutil::Messagebox::ShowError(ex.what(), this); |
| 1689 |
|
| 1690 |
return false; // failure means to abort the process |
| 1691 |
} |
| 1692 |
|
| 1693 |
updateMaterialTreeItem(); |
| 1694 |
updateMaterialControlSensitivity(); |
| 1695 |
|
| 1696 |
return true; |
| 1697 |
} |
| 1698 |
|
| 1699 |
void MaterialEditor::deleteCurrentMaterial() |
| 1700 |
{ |
| 1701 |
auto materialFileInfo = _material->getShaderFileInfo().isEmpty() ? |
| 1702 |
_("") : " " + _material->getShaderFileInfo().fullPath(); |
| 1703 |
|
| 1704 |
if (wxutil::Messagebox::Show(_("Confirm Removal"), |
| 1705 |
fmt::format(_("The selected material {0} will be removed,\nincluding its source text in the .mtr file{1}.\n" |
| 1706 |
"This action cannot be undone. Are you sure you want to remove this material?"), |
| 1707 |
_material->getName(), materialFileInfo), IDialog::MESSAGE_ASK, this) == IDialog::RESULT_NO) |
| 1708 |
{ |
| 1709 |
return; |
| 1710 |
} |
| 1711 |
|
| 1712 |
try |
| 1713 |
{ |
| 1714 |
GlobalMaterialManager().removeMaterial(_material->getName()); |
| 1715 |
} |
| 1716 |
catch (const std::runtime_error& ex) |
| 1717 |
{ |
| 1718 |
rError() << "Could not delete the material: " << ex.what() << std::endl; |
| 1719 |
wxutil::Messagebox::ShowError(ex.what(), this); |
| 1720 |
} |
| 1721 |
|
| 1722 |
handleMaterialSelectionChange(); |
| 1723 |
} |
| 1724 |
|
| 1725 |
void MaterialEditor::revertCurrentMaterial() |
| 1726 |
{ |
| 1727 |
if (!_material) return; |
| 1728 |
|
| 1729 |
if (_material->isModified() && _material->getShaderFileInfo().name.empty()) |
| 1730 |
{ |
| 1731 |
// This material has been created and not been saved yet, |
| 1732 |
// discarding it means removing it |
| 1733 |
GlobalMaterialManager().removeMaterial(_material->getName()); |
| 1734 |
selectMaterial(MaterialPtr()); |
| 1735 |
return; |
| 1736 |
} |
| 1737 |
|
| 1738 |
_material->revertModifications(); |
| 1739 |
|
| 1740 |
onMaterialChanged(); |
| 1741 |
} |
| 1742 |
|
| 1743 |
bool MaterialEditor::askUserAboutModifiedMaterial() |
| 1744 |
{ |
| 1745 |
if (!_material) return true; |
| 1746 |
|
| 1747 |
// Get the original name |
| 1748 |
std::string origName = _material->getName(); |
| 1749 |
|
| 1750 |
// Does not make sense to save a null material |
| 1751 |
assert(!origName.empty()); |
| 1752 |
|
| 1753 |
// The material we're editing has been changed from the saved one |
| 1754 |
wxutil::Messagebox box(_("Save Changes"), |
| 1755 |
fmt::format(_("Do you want to save the changes to the material\n{0}?"), origName), |
| 1756 |
IDialog::MESSAGE_SAVECONFIRMATION, this); |
| 1757 |
|
| 1758 |
auto result = box.run(); |
| 1759 |
|
| 1760 |
if (result == IDialog::RESULT_YES) |
| 1761 |
{ |
| 1762 |
// User wants to save, return true if save was successful |
| 1763 |
return saveCurrentMaterial(); |
| 1764 |
} |
| 1765 |
else if (result == IDialog::RESULT_NO) |
| 1766 |
{ |
| 1767 |
// Discard changes |
| 1768 |
revertCurrentMaterial(); |
| 1769 |
return true; |
| 1770 |
} |
| 1771 |
else if (result == IDialog::RESULT_CANCELLED) |
| 1772 |
{ |
| 1773 |
return false; // user cancelled |
| 1774 |
} |
| 1775 |
|
| 1776 |
// User doesn't want to save |
| 1777 |
return true; |
| 1778 |
} |
| 1779 |
|
| 1780 |
bool MaterialEditor::isAllowedToChangeMaterial() |
| 1781 |
{ |
| 1782 |
return true; |
| 1783 |
} |
| 1784 |
|
| 1785 |
void MaterialEditor::handleMaterialSelectionChange() |
| 1786 |
{ |
| 1787 |
_selectedMaterialItem = _treeView->GetSelection(); |
| 1788 |
|
| 1789 |
_materialChanged.disconnect(); |
| 1790 |
|
| 1791 |
// Update the preview if a texture is selected |
| 1792 |
if (_selectedMaterialItem.IsOk() && !_treeView->IsDirectorySelected()) |
| 1793 |
{ |
| 1794 |
_material = GlobalMaterialManager().getMaterial(_treeView->GetSelectedDeclName()); |
| 1795 |
|
| 1796 |
_materialChanged = _material->sig_materialChanged().connect([this]() |
| 1797 |
{ |
| 1798 |
updateSourceView(); |
| 1799 |
updateMaterialTreeItem(); |
| 1800 |
}); |
| 1801 |
} |
| 1802 |
else |
| 1803 |
{ |
| 1804 |
_material.reset(); |
| 1805 |
} |
| 1806 |
|
| 1807 |
updateControlsFromMaterial(); |
| 1808 |
} |
| 1809 |
|
| 1810 |
void MaterialEditor::_onMaterialNameChanged(wxCommandEvent& ev) |
| 1811 |
{ |
| 1812 |
if (_materialUpdateInProgress || !_material) return; |
| 1813 |
|
| 1814 |
auto nameEntry = static_cast<wxTextCtrl*>(ev.GetEventObject()); |
| 1815 |
|
| 1816 |
GlobalMaterialManager().renameMaterial(_material->getName(), nameEntry->GetValue().ToStdString()); |
| 1817 |
auto item = _treeView->GetTreeModel()->FindString(_material->getName(), _treeView->Columns().declName); |
| 1818 |
|
| 1819 |
// Make sure the item is selected again, it will be de-selected by the rename operation |
| 1820 |
_treeView->Select(item); |
| 1821 |
_treeView->EnsureVisible(item); |
| 1822 |
|
| 1823 |
updateMaterialPropertiesFromMaterial(); |
| 1824 |
onMaterialChanged(); |
| 1825 |
} |
| 1826 |
|
| 1827 |
void MaterialEditor::_onMaterialSelectionChanged(wxDataViewEvent& ev) |
| 1828 |
{ |
| 1829 |
// Check if the material has been modified and ask for save |
| 1830 |
if (!isAllowedToChangeMaterial()) |
| 1831 |
{ |
| 1832 |
// Revert the selection and cancel the operation |
| 1833 |
_treeView->Select(_selectedMaterialItem); |
| 1834 |
return; |
| 1835 |
} |
| 1836 |
|
| 1837 |
handleMaterialSelectionChange(); |
| 1838 |
} |
| 1839 |
|
| 1840 |
void MaterialEditor::_onSaveMaterial(wxCommandEvent& ev) |
| 1841 |
{ |
| 1842 |
if (!_material) return; |
| 1843 |
|
| 1844 |
saveCurrentMaterial(); |
| 1845 |
} |
| 1846 |
|
| 1847 |
void MaterialEditor::_onDeleteMaterial(wxCommandEvent& ev) |
| 1848 |
{ |
| 1849 |
if (!_material) return; |
| 1850 |
|
| 1851 |
deleteCurrentMaterial(); |
| 1852 |
} |
| 1853 |
|
| 1854 |
void MaterialEditor::selectMaterial(const MaterialPtr& material) |
| 1855 |
{ |
| 1856 |
if (!material) |
| 1857 |
{ |
| 1858 |
_treeView->UnselectAll(); |
| 1859 |
handleMaterialSelectionChange(); |
| 1860 |
return; |
| 1861 |
} |
| 1862 |
|
| 1863 |
auto newItem = _treeView->GetTreeModel()->FindString(material->getName(), _treeView->Columns().declName); |
| 1864 |
|
| 1865 |
if (newItem.IsOk()) |
| 1866 |
{ |
| 1867 |
_treeView->Select(newItem); |
| 1868 |
_treeView->EnsureVisible(newItem); |
| 1869 |
|
| 1870 |
handleMaterialSelectionChange(); |
| 1871 |
updateMaterialTreeItem(); |
| 1872 |
} |
| 1873 |
} |
| 1874 |
|
| 1875 |
void MaterialEditor::_onNewMaterial(wxCommandEvent& ev) |
| 1876 |
{ |
| 1877 |
// Clear the filter before creating a new material |
| 1878 |
_treeView->ClearFilterText(); |
| 1879 |
|
| 1880 |
auto materialName = "textures/darkmod/map_specific/unnamed"; |
| 1881 |
auto newMaterial = GlobalMaterialManager().createEmptyMaterial(materialName); |
| 1882 |
|
| 1883 |
selectMaterial(newMaterial); |
| 1884 |
} |
| 1885 |
|
| 1886 |
void MaterialEditor::copySelectedMaterial() |
| 1887 |
{ |
| 1888 |
if (!_material) return; |
| 1889 |
|
| 1890 |
auto newMaterialName = _material->getName() + _("_copy"); |
| 1891 |
auto newMaterial = GlobalMaterialManager().copyMaterial(_material->getName(), newMaterialName); |
| 1892 |
|
| 1893 |
selectMaterial(newMaterial); |
| 1894 |
} |
| 1895 |
|
| 1896 |
void MaterialEditor::_onCopyMaterial(wxCommandEvent& ev) |
| 1897 |
{ |
| 1898 |
copySelectedMaterial(); |
| 1899 |
} |
| 1900 |
|
| 1901 |
void MaterialEditor::_onRevertMaterial(wxCommandEvent& ev) |
| 1902 |
{ |
| 1903 |
if (!_material) return; |
| 1904 |
|
| 1905 |
// The material we're editing has been changed from the saved one |
| 1906 |
wxutil::Messagebox box(_("Discard Changes"), |
| 1907 |
fmt::format(_("Do you want to discard all the changes to the material\n{0}?"), _material->getName()), |
| 1908 |
IDialog::MESSAGE_ASK, this); |
| 1909 |
|
| 1910 |
if (box.run() == IDialog::RESULT_YES) |
| 1911 |
{ |
| 1912 |
revertCurrentMaterial(); |
| 1913 |
updateControlsFromMaterial(); |
| 1914 |
} |
| 1915 |
} |
| 1916 |
|
| 1917 |
void MaterialEditor::_onUnlockMaterial(wxCommandEvent& ev) |
| 1918 |
{ |
| 1919 |
copySelectedMaterial(); |
| 1920 |
} |
| 1921 |
|
| 1922 |
void MaterialEditor::_onStageListSelectionChanged(wxDataViewEvent& ev) |
| 1923 |
{ |
| 1924 |
auto item = _stageView->GetSelection(); |
| 1925 |
|
| 1926 |
if (!_material || !item.IsOk()) return; |
| 1927 |
auto row = wxutil::TreeModel::Row(item, *_stageList); |
| 1928 |
|
| 1929 |
updateSettingsNotebook(); |
| 1930 |
updateStageControls(); |
| 1931 |
updateStageButtonSensitivity(); |
| 1932 |
} |
| 1933 |
|
| 1934 |
void MaterialEditor::updateSettingsNotebook() |
| 1935 |
{ |
| 1936 |
auto item = _stageView->GetSelection(); |
| 1937 |
|
| 1938 |
bool isGlobal = true; |
| 1939 |
|
| 1940 |
if (_material && item.IsOk()) |
| 1941 |
{ |
| 1942 |
auto row = wxutil::TreeModel::Row(item, *_stageList); |
| 1943 |
isGlobal = row[STAGE_COLS().global].getBool(); |
| 1944 |
} |
| 1945 |
|
| 1946 |
auto notebook = getControl<wxNotebook>("MaterialStageSettingsNotebook"); |
| 1947 |
auto desiredPrefix = isGlobal ? "Material" : "Stage"; |
| 1948 |
|
| 1949 |
// Remove unwanted pages |
| 1950 |
for (int i = notebook->GetPageCount() - 1; i >= 0; --i) |
| 1951 |
{ |
| 1952 |
if (!notebook->GetPage(i)->GetName().StartsWith(desiredPrefix)) |
| 1953 |
{ |
| 1954 |
notebook->RemovePage(i); |
| 1955 |
} |
| 1956 |
} |
| 1957 |
|
| 1958 |
// Add missing pages |
| 1959 |
for (const auto& pair : _notebookPages) |
| 1960 |
{ |
| 1961 |
auto page = pair.second.first; |
| 1962 |
if (page->GetName().StartsWith(desiredPrefix) && notebook->FindPage(page) == -1) |
| 1963 |
{ |
| 1964 |
notebook->AddPage(page, pair.second.second); |
| 1965 |
} |
| 1966 |
} |
| 1967 |
|
| 1968 |
// Update settings title |
| 1969 |
getControl<wxStaticText>("MaterialEditorStagePropertiesLabel")->SetLabel(isGlobal ? |
| 1970 |
_("Global Material Settings") : _("Stage Settings")); |
| 1971 |
} |
| 1972 |
|
| 1973 |
void MaterialEditor::updateStageButtonSensitivity() |
| 1974 |
{ |
| 1975 |
auto item = _stageView->GetSelection(); |
| 1976 |
|
| 1977 |
bool materialCanBeModified = _material && GlobalMaterialManager().materialCanBeModified(_material->getName()); |
| 1978 |
|
| 1979 |
if (materialCanBeModified && item.IsOk()) |
| 1980 |
{ |
| 1981 |
auto row = wxutil::TreeModel::Row(item, *_stageList); |
| 1982 |
auto index = row[STAGE_COLS().index].getInteger(); |
| 1983 |
auto isGlobalStage = row[STAGE_COLS().global].getBool(); |
| 1984 |
auto layersCount = _material->getNumLayers(); |
| 1985 |
|
| 1986 |
getControl<wxButton>("MaterialEditorRemoveStageButton")->Enable(!isGlobalStage); |
| 1987 |
getControl<wxButton>("MaterialEditorToggleStageButton")->Enable(!isGlobalStage); |
| 1988 |
getControl<wxButton>("MaterialEditorMoveUpStageButton")->Enable(!isGlobalStage && index > 0); |
| 1989 |
getControl<wxButton>("MaterialEditorMoveDownStageButton")->Enable(!isGlobalStage && index + 1 < layersCount); |
| 1990 |
getControl<wxButton>("MaterialEditorDuplicateStageButton")->Enable(!isGlobalStage); |
| 1991 |
getControl<wxButton>("MaterialEditorAddStageButton")->Enable(); |
| 1992 |
} |
| 1993 |
else |
| 1994 |
{ |
| 1995 |
getControl<wxButton>("MaterialEditorRemoveStageButton")->Disable(); |
| 1996 |
getControl<wxButton>("MaterialEditorToggleStageButton")->Disable(); |
| 1997 |
getControl<wxButton>("MaterialEditorMoveUpStageButton")->Disable(); |
| 1998 |
getControl<wxButton>("MaterialEditorMoveDownStageButton")->Disable(); |
| 1999 |
getControl<wxButton>("MaterialEditorDuplicateStageButton")->Disable(); |
| 2000 |
getControl<wxButton>("MaterialEditorAddStageButton")->Enable(materialCanBeModified); |
| 2001 |
} |
| 2002 |
} |
| 2003 |
|
| 2004 |
void MaterialEditor::_onStageListItemActivated(wxDataViewEvent& ev) |
| 2005 |
{ |
| 2006 |
toggleSelectedStage(); |
| 2007 |
} |
| 2008 |
|
| 2009 |
void MaterialEditor::updateMaterialControlSensitivity() |
| 2010 |
{ |
| 2011 |
getControl<wxButton>("MaterialEditorNewDefButton")->Enable(true); |
| 2012 |
|
| 2013 |
auto canBeModified = _material && GlobalMaterialManager().materialCanBeModified(_material->getName()); |
| 2014 |
|
| 2015 |
getControl<wxButton>("MaterialEditorSaveDefButton")->Enable(_material && |
| 2016 |
_material->isModified() && canBeModified); |
| 2017 |
getControl<wxButton>("MaterialEditorDeleteDefButton")->Enable(_material && canBeModified); |
| 2018 |
|
| 2019 |
getControl<wxButton>("MaterialEditorCopyDefButton")->Enable(_material != nullptr); |
| 2020 |
getControl<wxButton>("MaterialEditorRevertButton")->Enable(_material && _material->isModified()); |
| 2021 |
|
| 2022 |
auto unlockButton = getControl<wxButton>("MaterialEditorUnlockButton"); |
| 2023 |
unlockButton->Show(_material != nullptr); |
| 2024 |
unlockButton->Enable(_material && !canBeModified); |
| 2025 |
unlockButton->SetBackgroundColour(unlockButton->IsEnabled() ? wxColour(255, 70, 70) : wxNullColour); |
| 2026 |
unlockButton->SetLabelText(unlockButton->IsEnabled() ? _("Unlock Editing") : _("Is editable")); |
| 2027 |
unlockButton->SetForegroundColour(unlockButton->IsEnabled() ? *wxWHITE : wxNullColour); |
| 2028 |
|
| 2029 |
getControl<wxButton>("MaterialEditorReloadImagesButton")->Enable(_material != nullptr); |
| 2030 |
} |
| 2031 |
|
| 2032 |
std::pair<IShaderLayer::Ptr, std::size_t> MaterialEditor::findMaterialStageByType(IShaderLayer::Type type) |
| 2033 |
{ |
| 2034 |
if (!_material) return std::pair<IShaderLayer::Ptr, std::size_t>(); |
| 2035 |
|
| 2036 |
std::pair<IShaderLayer::Ptr, std::size_t> result; |
| 2037 |
|
| 2038 |
std::size_t i = 0; |
| 2039 |
|
| 2040 |
_material->foreachLayer([&](const IShaderLayer::Ptr& layer) |
| 2041 |
{ |
| 2042 |
if (layer->getType() == type) |
| 2043 |
{ |
| 2044 |
result = std::make_pair(layer, i); |
| 2045 |
return false; |
| 2046 |
} |
| 2047 |
|
| 2048 |
++i; |
| 2049 |
return true; |
| 2050 |
}); |
| 2051 |
|
| 2052 |
return result; |
| 2053 |
} |
| 2054 |
|
| 2055 |
void MaterialEditor::updateBasicPageFromMaterial() |
| 2056 |
{ |
| 2057 |
util::ScopedBoolLock lock(_materialUpdateInProgress); |
| 2058 |
|
| 2059 |
auto nameEntry = getControl<wxTextCtrl>("BasicName"); |
| 2060 |
nameEntry->SetValue(_material ? _material->getName() : ""); |
| 2061 |
|
| 2062 |
getControl<wxTextCtrl>("BasicDescription")->SetValue(_material ? _material->getDescription() : ""); |
| 2063 |
|
| 2064 |
// Type dropdown |
| 2065 |
auto* materialTypeDropdown = getControl<wxChoice>("BasicMaterialType"); |
| 2066 |
|
| 2067 |
if (!_material || _material->getSurfaceType() == Material::SURFTYPE_DEFAULT) |
| 2068 |
{ |
| 2069 |
materialTypeDropdown->Select(0); |
| 2070 |
} |
| 2071 |
else |
| 2072 |
{ |
| 2073 |
auto surfType = shaders::getStringForSurfaceType(_material->getSurfaceType()); |
| 2074 |
materialTypeDropdown->Select(materialTypeDropdown->FindString(surfType)); |
| 2075 |
} |
| 2076 |
|
| 2077 |
updateBasicImagePreview(); |
| 2078 |
|
| 2079 |
auto editorImageMap = getControl<MapExpressionEntry>("BasicEditorImageEntry"); |
| 2080 |
auto diffuseImageMap = getControl<MapExpressionEntry>("BasicDiffuseImageEntry"); |
| 2081 |
auto bumpImageMap = getControl<MapExpressionEntry>("BasicBumpImageEntry"); |
| 2082 |
auto specularImageMap = getControl<MapExpressionEntry>("BasicSpecularImageEntry"); |
| 2083 |
|
| 2084 |
auto editorImg = _material ? _material->getEditorImageExpression() : shaders::IMapExpression::Ptr(); |
| 2085 |
editorImageMap->SetValue(editorImg ? editorImg->getExpressionString() : ""); |
| 2086 |
|
| 2087 |
auto diffuse = findMaterialStageByType(IShaderLayer::DIFFUSE).first; |
| 2088 |
auto expression = diffuse ? diffuse->getMapExpression() : shaders::IMapExpression::Ptr(); |
| 2089 |
diffuseImageMap->SetValue(expression ? expression->getExpressionString() : ""); |
| 2090 |
|
| 2091 |
auto bump = findMaterialStageByType(IShaderLayer::BUMP).first; |
| 2092 |
expression = bump ? bump->getMapExpression() : shaders::IMapExpression::Ptr(); |
| 2093 |
bumpImageMap->SetValue(expression ? expression->getExpressionString() : ""); |
| 2094 |
|
| 2095 |
auto specular = findMaterialStageByType(IShaderLayer::SPECULAR).first; |
| 2096 |
expression = specular ? specular->getMapExpression() : shaders::IMapExpression::Ptr(); |
| 2097 |
specularImageMap->SetValue(expression ? expression->getExpressionString() : ""); |
| 2098 |
|
| 2099 |
updateBasicFrobStageControls(); |
| 2100 |
} |
| 2101 |
|
| 2102 |
void MaterialEditor::updateBasicFrobStageControls() |
| 2103 |
{ |
| 2104 |
auto addFrob = getControl<wxButton>("BasicAddFrobStages"); |
| 2105 |
auto removeFrob = getControl<wxButton>("BasicRemoveFrobStages"); |
| 2106 |
|
| 2107 |
bool hasFrobStages = shaders::FrobStageSetup::IsPresent(_material); |
| 2108 |
bool materialCanBeModified = _material && GlobalMaterialManager().materialCanBeModified(_material->getName()); |
| 2109 |
|
| 2110 |
// We can add the frob stage if a diffuse map is present |
| 2111 |
addFrob->Enable(materialCanBeModified && !hasFrobStages && !shaders::FrobStageSetup::GetDiffuseMap(_material).empty()); |
| 2112 |
removeFrob->Enable(materialCanBeModified && hasFrobStages); |
| 2113 |
|
| 2114 |
auto testFrob = getControl<wxButton>("BasicTestFrobStages"); |
| 2115 |
testFrob->Enable(materialCanBeModified && hasFrobStages); |
| 2116 |
} |
| 2117 |
|
| 2118 |
void MaterialEditor::updateBasicImagePreview() |
| 2119 |
{ |
| 2120 |
auto editorImgTabImage = getControl<TexturePreview>("BasicEditorImageTabImage"); |
| 2121 |
auto diffuseTabImage = getControl<TexturePreview>("BasicDiffuseTabImage"); |
| 2122 |
auto bumpTabImage = getControl<TexturePreview>("BasicBumpTabImage"); |
| 2123 |
auto specularTabImage = getControl<TexturePreview>("BasicSpecularTabImage"); |
| 2124 |
|
| 2125 |
editorImgTabImage->SetMaterial(_material); |
| 2126 |
diffuseTabImage->SetMaterial(_material); |
| 2127 |
bumpTabImage->SetMaterial(_material); |
| 2128 |
specularTabImage->SetMaterial(_material); |
| 2129 |
} |
| 2130 |
|
| 2131 |
void MaterialEditor::updateControlsFromMaterial() |
| 2132 |
{ |
| 2133 |
util::ScopedBoolLock lock(_materialUpdateInProgress); |
| 2134 |
|
| 2135 |
_preview->setMaterial(_material); |
| 2136 |
|
| 2137 |
updateMaterialControlSensitivity(); |
| 2138 |
updateMaterialPropertiesFromMaterial(); |
| 2139 |
updateStageListFromMaterial(); |
| 2140 |
updateSettingsNotebook(); |
| 2141 |
|
| 2142 |
auto notebook = getControl<wxNotebook>("MaterialStageSettingsNotebook"); |
| 2143 |
notebook->SetSelection(0); // select the first page |
| 2144 |
} |
| 2145 |
|
| 2146 |
inline std::string getDeformExpressionSafe(const MaterialPtr& material, std::size_t index) |
| 2147 |
{ |
| 2148 |
auto expr = material->getDeformExpression(index); |
| 2149 |
return expr ? expr->getExpressionString() : std::string(); |
| 2150 |
} |
| 2151 |
|
| 2152 |
void MaterialEditor::updateDeformControlsFromMaterial() |
| 2153 |
{ |
| 2154 |
if (_material) |
| 2155 |
{ |
| 2156 |
// Deform |
| 2157 |
auto deformTypeName = shaders::getStringForDeformType(_material->getDeformType()); |
| 2158 |
auto deformDropdown = getControl<wxChoice>("MaterialEditorDeformChoice"); |
| 2159 |
|
| 2160 |
if (!deformTypeName.empty()) |
| 2161 |
{ |
| 2162 |
deformDropdown->Select(deformDropdown->FindString(deformTypeName)); |
| 2163 |
|
| 2164 |
switch (_material->getDeformType()) |
| 2165 |
{ |
| 2166 |
case Material::DEFORM_FLARE: |
| 2167 |
getControl<wxTextCtrl>("MaterialDeformFlareSize")->SetValue(getDeformExpressionSafe(_material, 0)); |
| 2168 |
break; |
| 2169 |
case Material::DEFORM_EXPAND: |
| 2170 |
getControl<wxTextCtrl>("MaterialDeformExpandAmount")->SetValue(getDeformExpressionSafe(_material, 0)); |
| 2171 |
break; |
| 2172 |
case Material::DEFORM_MOVE: |
| 2173 |
getControl<wxTextCtrl>("MaterialDeformMoveAmount")->SetValue(getDeformExpressionSafe(_material, 0)); |
| 2174 |
break; |
| 2175 |
case Material::DEFORM_TURBULENT: |
| 2176 |
getControl<wxTextCtrl>("MaterialDeformTurbulentTableName")->SetValue(_material->getDeformDeclName()); |
| 2177 |
getControl<wxTextCtrl>("MaterialDeformTurbulentRange")->SetValue(getDeformExpressionSafe(_material, 0)); |
| 2178 |
getControl<wxTextCtrl>("MaterialDeformTurbulentTimeOffset")->SetValue(getDeformExpressionSafe(_material, 1)); |
| 2179 |
getControl<wxTextCtrl>("MaterialDeformTurbulentDomain")->SetValue(getDeformExpressionSafe(_material, 2)); |
| 2180 |
break; |
| 2181 |
case Material::DEFORM_PARTICLE: |
| 2182 |
getControl<wxTextCtrl>("MaterialDeformParticleDeclName")->SetValue(_material->getDeformDeclName()); |
| 2183 |
break; |
| 2184 |
case Material::DEFORM_PARTICLE2: |
| 2185 |
getControl<wxTextCtrl>("MaterialDeformParticle2DeclName")->SetValue(_material->getDeformDeclName()); |
| 2186 |
break; |
| 2187 |
} |
| 2188 |
} |
| 2189 |
else |
| 2190 |
{ |
| 2191 |
deformDropdown->Select(0); |
| 2192 |
} |
| 2193 |
|
| 2194 |
// Hide the unrelated deform controls |
| 2195 |
for (const auto& pair : _deformPanels) |
| 2196 |
{ |
| 2197 |
pair.second->Show(_material->getDeformType() == pair.first); |
| 2198 |
} |
| 2199 |
} |
| 2200 |
else // no material |
| 2201 |
{ |
| 2202 |
getControl<wxChoice>("MaterialEditorDeformChoice")->Select(0); |
| 2203 |
|
| 2204 |
for (const auto& pair : _deformPanels) |
| 2205 |
{ |
| 2206 |
pair.second->Hide(); |
| 2207 |
} |
| 2208 |
} |
| 2209 |
|
| 2210 |
getControl<wxPanel>("MaterialPageDeform")->Layout(); |
| 2211 |
} |
| 2212 |
|
| 2213 |
inline std::string getBlendFuncString(const std::pair<std::string, std::string>& pair) |
| 2214 |
{ |
| 2215 |
return !pair.second.empty() ? fmt::format("{0}, {1}", pair.first, pair.second) : pair.first; |
| 2216 |
} |
| 2217 |
|
| 2218 |
inline std::string getNameForLayer(const IShaderLayer& layer) |
| 2219 |
{ |
| 2220 |
switch (layer.getType()) |
| 2221 |
{ |
| 2222 |
case IShaderLayer::DIFFUSE: |
| 2223 |
return "diffuse"; |
| 2224 |
case IShaderLayer::BUMP: |
| 2225 |
return "bump"; |
| 2226 |
case IShaderLayer::SPECULAR: |
| 2227 |
return "specular"; |
| 2228 |
case IShaderLayer::BLEND: |
| 2229 |
return fmt::format("blend {0}", getBlendFuncString(layer.getBlendFuncStrings())); |
| 2230 |
} |
| 2231 |
|
| 2232 |
return std::string("-"); |
| 2233 |
} |
| 2234 |
|
| 2235 |
void MaterialEditor::updateStageListFromMaterial() |
| 2236 |
{ |
| 2237 |
// Remove all non-global items |
| 2238 |
_stageList->RemoveItems([&](const wxutil::TreeModel::Row& row) |
| 2239 |
{ |
| 2240 |
return !row[STAGE_COLS().global].getBool(); |
| 2241 |
}); |
| 2242 |
|
| 2243 |
getControl<wxPanel>("MaterialEditorStageListPanel")->Enable(_material != nullptr); |
| 2244 |
|
| 2245 |
if (!_material) return; |
| 2246 |
|
| 2247 |
int index = 0; |
| 2248 |
_material->foreachLayer([&](const IShaderLayer::Ptr& layer) |
| 2249 |
{ |
| 2250 |
auto row = _stageList->AddItem(); |
| 2251 |
|
| 2252 |
row[STAGE_COLS().enabled] = layer->isEnabled(); |
| 2253 |
row[STAGE_COLS().icon] = wxVariant(layer->isEnabled() ? _iconVisible : _iconInvisible); |
| 2254 |
row[STAGE_COLS().index] = index; |
| 2255 |
row[STAGE_COLS().name] = getNameForLayer(*layer); |
| 2256 |
row[STAGE_COLS().visible] = true; |
| 2257 |
row[STAGE_COLS().global] = false; |
| 2258 |
|
| 2259 |
row.SendItemAdded(); |
| 2260 |
|
| 2261 |
++index; |
| 2262 |
return true; |
| 2263 |
}); |
| 2264 |
|
| 2265 |
// Pre-select the global settings page |
| 2266 |
auto globalSettings = _stageList->FindItem([&](const wxutil::TreeModel::Row& row) |
| 2267 |
{ |
| 2268 |
return row[STAGE_COLS().global].getBool(); |
| 2269 |
}); |
| 2270 |
_stageView->Select(globalSettings); |
| 2271 |
} |
| 2272 |
|
| 2273 |
void MaterialEditor::updateMaterialPropertiesFromMaterial() |
| 2274 |
{ |
| 2275 |
util::ScopedBoolLock lock(_materialUpdateInProgress); |
| 2276 |
|
| 2277 |
bool materialCanBeModified = _material && GlobalMaterialManager().materialCanBeModified(_material->getName()); |
| 2278 |
|
| 2279 |
getControl<wxPanel>("BasicEditorPanel")->Enable(materialCanBeModified); |
| 2280 |
getControl<wxPanel>("MaterialNameAndDescription")->Enable(materialCanBeModified); |
| 2281 |
getControl<wxPanel>("MaterialEditorImagePanel")->Enable(materialCanBeModified); |
| 2282 |
|
| 2283 |
// Enable/disable the settings pages |
| 2284 |
for (const auto& pair : _notebookPages) |
| 2285 |
{ |
| 2286 |
pair.second.first->Enable(materialCanBeModified); |
| 2287 |
} |
| 2288 |
|
| 2289 |
auto nameEntry = getControl<wxTextCtrl>("MaterialName"); |
| 2290 |
nameEntry->Enable(materialCanBeModified); |
| 2291 |
nameEntry->SetValue(_material ? _material->getName() : ""); |
| 2292 |
updateMaterialNameControl(); |
| 2293 |
|
| 2294 |
// Update all registered bindings |
| 2295 |
for (const auto& binding : _materialBindings) |
| 2296 |
{ |
| 2297 |
binding->setSource(_material); |
| 2298 |
binding->updateFromSource(); |
| 2299 |
} |
| 2300 |
|
| 2301 |
updateBasicPageFromMaterial(); |
| 2302 |
updateDeformControlsFromMaterial(); |
| 2303 |
updateSourceView(); |
| 2304 |
|
| 2305 |
if (_material) |
| 2306 |
{ |
| 2307 |
getControl<wxTextCtrl>("MaterialDescription")->SetValue(_material->getDescription()); |
| 2308 |
|
| 2309 |
auto declFileInfo = getControl<wxutil::DeclFileInfo>("MaterialEditorSaveNotePanel"); |
| 2310 |
declFileInfo->Show(); |
| 2311 |
declFileInfo->setName(_material->getName()); |
| 2312 |
declFileInfo->setPath(_material->getShaderFileInfo().fullPath()); |
| 2313 |
|
| 2314 |
// Type dropdown |
| 2315 |
auto* materialTypeDropdown = getControl<wxChoice>("MaterialType"); |
| 2316 |
if (_material->getSurfaceType() == Material::SURFTYPE_DEFAULT) |
| 2317 |
{ |
| 2318 |
materialTypeDropdown->Select(0); |
| 2319 |
} |
| 2320 |
else |
| 2321 |
{ |
| 2322 |
auto surfType = shaders::getStringForSurfaceType(_material->getSurfaceType()); |
| 2323 |
materialTypeDropdown->Select(materialTypeDropdown->FindString(surfType)); |
| 2324 |
} |
| 2325 |
|
| 2326 |
// Sort dropdown |
| 2327 |
auto* materialSortDropdown = getControl<wxComboBox>("MaterialSortValue"); |
| 2328 |
if (_material->getMaterialFlags() & Material::FLAG_HAS_SORT_DEFINED) |
| 2329 |
{ |
| 2330 |
auto predefinedName = shaders::getStringForSortRequestValue(_material->getSortRequest()); |
| 2331 |
|
| 2332 |
if (!predefinedName.empty()) |
| 2333 |
{ |
| 2334 |
materialSortDropdown->Select(materialSortDropdown->FindString(predefinedName)); |
| 2335 |
} |
| 2336 |
else |
| 2337 |
{ |
| 2338 |
materialSortDropdown->SetValue(string::to_string(_material->getSortRequest())); |
| 2339 |
} |
| 2340 |
} |
| 2341 |
else |
| 2342 |
{ |
| 2343 |
materialSortDropdown->Select(0); |
| 2344 |
} |
| 2345 |
|
| 2346 |
// Clamping |
| 2347 |
auto clampDropdown = getControl<wxChoice>("MaterialClampType"); |
| 2348 |
auto clampTypeString = shaders::getStringForClampType(_material->getClampType()); |
| 2349 |
clampDropdown->SetStringSelection(clampTypeString); |
| 2350 |
|
| 2351 |
// Culling |
| 2352 |
auto cullTypes = getControl<wxChoice>("MaterialCullType"); |
| 2353 |
auto cullTypeString = shaders::getStringForCullType(_material->getCullType()); |
| 2354 |
cullTypes->SetStringSelection(cullTypeString); |
| 2355 |
|
| 2356 |
// Light Falloff type |
| 2357 |
auto lightFalloffCubeMapType = _material->getLightFalloffCubeMapType(); |
| 2358 |
getControl<wxChoice>("MaterialLightFalloffCubeMapType")->SetStringSelection(shaders::getStringForMapType(lightFalloffCubeMapType)); |
| 2359 |
|
| 2360 |
// Spectrum |
| 2361 |
bool hasSpectrum = (_material->getParseFlags() & Material::PF_HasSpectrum) != 0 || _material->getSpectrum() != 0; |
| 2362 |
getControl<wxCheckBox>("MaterialHasSpectrum")->SetValue(hasSpectrum); |
| 2363 |
getControl<wxSpinCtrl>("MaterialSpectrumValue")->Enable(hasSpectrum); |
| 2364 |
getControl<wxSpinCtrl>("MaterialSpectrumValue")->SetValue(_material->getSpectrum()); |
| 2365 |
|
| 2366 |
// DecalInfo |
| 2367 |
bool hasDecalInfo = _material->getParseFlags() & Material::PF_HasDecalInfo; |
| 2368 |
getControl<wxCheckBox>("MaterialHasDecalInfo")->SetValue(hasDecalInfo); |
| 2369 |
getControl<wxPanel>("MaterialDecalInfoPanel")->Enable(hasDecalInfo); |
| 2370 |
|
| 2371 |
getControl<wxCheckBox>("MaterialHasRenderBump")->SetValue(!_material->getRenderBumpArguments().empty()); |
| 2372 |
//getControl<wxTextCtrl>("MaterialRenderBumpArguments")->Enable(!_material->getRenderBumpArguments().empty()); |
| 2373 |
getControl<wxTextCtrl>("MaterialRenderBumpArguments")->SetValue(_material->getRenderBumpArguments()); |
| 2374 |
|
| 2375 |
getControl<wxCheckBox>("MaterialHasRenderBumpFlat")->SetValue(!_material->getRenderBumpFlatArguments().empty()); |
| 2376 |
//getControl<wxTextCtrl>("MaterialRenderBumpFlatArguments")->Enable(!_material->getRenderBumpFlatArguments().empty()); |
| 2377 |
getControl<wxTextCtrl>("MaterialRenderBumpFlatArguments")->SetValue(_material->getRenderBumpFlatArguments()); |
| 2378 |
|
| 2379 |
// guisurf |
| 2380 |
auto guisurfArgument = _material->getGuiSurfArgument(); |
| 2381 |
getControl<wxTextCtrl>("MaterialGuiSurfPath")->SetValue(guisurfArgument); |
| 2382 |
|
| 2383 |
bool isEntityGui = (_material->getSurfaceFlags() & (Material::SURF_ENTITYGUI | Material::SURF_ENTITYGUI2 | Material::SURF_ENTITYGUI3)) != 0; |
| 2384 |
|
| 2385 |
//getControl<wxTextCtrl>("MaterialGuiSurfPath")->Enable(!isEntityGui); |
| 2386 |
//getControl<wxPanel>("MaterialGuiSurfPanel")->Enable(_material->getSurfaceFlags() & Material::SURF_GUISURF); |
| 2387 |
|
| 2388 |
getControl<wxRadioButton>("MaterialGuiSurfRegular")->SetValue(!isEntityGui); |
| 2389 |
getControl<wxRadioButton>("MaterialGuiSurfEntity")->SetValue(_material->getSurfaceFlags() & Material::SURF_ENTITYGUI); |
| 2390 |
getControl<wxRadioButton>("MaterialGuiSurfEntity2")->SetValue(_material->getSurfaceFlags() & Material::SURF_ENTITYGUI2); |
| 2391 |
getControl<wxRadioButton>("MaterialGuiSurfEntity3")->SetValue(_material->getSurfaceFlags() & Material::SURF_ENTITYGUI3); |
| 2392 |
} |
| 2393 |
else |
| 2394 |
{ |
| 2395 |
getControl<wxPanel>("MaterialEditorSaveNotePanel")->Hide(); |
| 2396 |
getControl<wxTextCtrl>("MaterialGuiSurfPath")->SetValue(""); |
| 2397 |
|
| 2398 |
getControl<wxCheckBox>("MaterialHasRenderBump")->SetValue(false); |
| 2399 |
getControl<wxTextCtrl>("MaterialRenderBumpArguments")->SetValue(""); |
| 2400 |
|
| 2401 |
getControl<wxCheckBox>("MaterialHasRenderBumpFlat")->SetValue(false); |
| 2402 |
getControl<wxTextCtrl>("MaterialRenderBumpFlatArguments")->SetValue(""); |
| 2403 |
|
| 2404 |
getControl<wxCheckBox>("MaterialHasDecalInfo")->SetValue(false); |
| 2405 |
getControl<wxSpinCtrlDouble>("MaterialEditorDecalInfoStaySeconds")->SetValue(0); |
| 2406 |
getControl<wxSpinCtrlDouble>("MaterialEditorDecalInfoFadeSeconds")->SetValue(0); |
| 2407 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoStartRed")->SetValue(""); |
| 2408 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoStartGreen")->SetValue(""); |
| 2409 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoStartBlue")->SetValue(""); |
| 2410 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoStartAlpha")->SetValue(""); |
| 2411 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoEndRed")->SetValue(""); |
| 2412 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoEndGreen")->SetValue(""); |
| 2413 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoEndBlue")->SetValue(""); |
| 2414 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoEndAlpha")->SetValue(""); |
| 2415 |
|
| 2416 |
getControl<wxCheckBox>("MaterialHasSpectrum")->SetValue(false); |
| 2417 |
getControl<wxSpinCtrl>("MaterialSpectrumValue")->SetValue(0); |
| 2418 |
getControl<wxTextCtrl>("MaterialDescription")->SetValue(""); |
| 2419 |
} |
| 2420 |
} |
| 2421 |
|
| 2422 |
void MaterialEditor::updateSourceView() |
| 2423 |
{ |
| 2424 |
if (_updateFromSourceTextInProgress || _sourceTextUpdateInProgress) return; // avoid feedback loops |
| 2425 |
|
| 2426 |
util::ScopedBoolLock lock(_sourceTextUpdateInProgress); |
| 2427 |
|
| 2428 |
if (_material) |
| 2429 |
{ |
| 2430 |
// Surround the definition with curly braces, these are not included |
| 2431 |
auto definition = fmt::format("{0}\n{{{1}}}", _material->getName(), _material->getDefinition()); |
| 2432 |
_sourceView->SetValue(definition); |
| 2433 |
} |
| 2434 |
else |
| 2435 |
{ |
| 2436 |
_sourceView->SetValue(""); |
| 2437 |
} |
| 2438 |
} |
| 2439 |
|
| 2440 |
void MaterialEditor::selectStageByIndex(std::size_t index) |
| 2441 |
{ |
| 2442 |
auto item = _stageList->FindInteger(index, STAGE_COLS().index); |
| 2443 |
|
| 2444 |
if (item.IsOk()) |
| 2445 |
{ |
| 2446 |
_stageView->Select(item); |
| 2447 |
} |
| 2448 |
else |
| 2449 |
{ |
| 2450 |
_stageView->UnselectAll(); |
| 2451 |
} |
| 2452 |
|
| 2453 |
updateSettingsNotebook(); |
| 2454 |
updateStageControls(); |
| 2455 |
updateStageButtonSensitivity(); |
| 2456 |
} |
| 2457 |
|
| 2458 |
IShaderLayer::Ptr MaterialEditor::getSelectedStage() |
| 2459 |
{ |
| 2460 |
auto selectedStageItem = _stageView->GetSelection(); |
| 2461 |
|
| 2462 |
if (!selectedStageItem.IsOk() || !_material) return IShaderLayer::Ptr(); |
| 2463 |
|
| 2464 |
wxutil::TreeModel::Row stageRow(selectedStageItem, *_stageList); |
| 2465 |
int stageIndex = stageRow[STAGE_COLS().index].getInteger(); |
| 2466 |
|
| 2467 |
if (stageIndex >= 0 && stageIndex < _material->getNumLayers()) |
| 2468 |
{ |
| 2469 |
return _material->getLayer(stageIndex); |
| 2470 |
} |
| 2471 |
|
| 2472 |
return IShaderLayer::Ptr(); |
| 2473 |
} |
| 2474 |
|
| 2475 |
IEditableShaderLayer::Ptr MaterialEditor::getEditableStageForSelection() |
| 2476 |
{ |
| 2477 |
auto selectedStageItem = _stageView->GetSelection(); |
| 2478 |
|
| 2479 |
if (!selectedStageItem.IsOk() || !_material) return IEditableShaderLayer::Ptr(); |
| 2480 |
|
| 2481 |
wxutil::TreeModel::Row stageRow(selectedStageItem, *_stageList); |
| 2482 |
int stageIndex = stageRow[STAGE_COLS().index].getInteger(); |
| 2483 |
|
| 2484 |
return stageIndex != -1 ? _material->getEditableLayer(stageIndex) : IEditableShaderLayer::Ptr(); |
| 2485 |
} |
| 2486 |
|
| 2487 |
void MaterialEditor::updateStageBlendControls() |
| 2488 |
{ |
| 2489 |
auto selectedStage = getSelectedStage(); |
| 2490 |
|
| 2491 |
auto blendType = getControl<wxChoice>("MaterialStageBlendType"); |
| 2492 |
auto blendTypeSrc = getControl<wxChoice>("MaterialStageBlendTypeSrc"); |
| 2493 |
auto blendTypeDest = getControl<wxChoice>("MaterialStageBlendTypeDest"); |
| 2494 |
|
| 2495 |
if (selectedStage) |
| 2496 |
{ |
| 2497 |
blendType->Enable(); |
| 2498 |
auto blendTypeStrings = selectedStage->getBlendFuncStrings(); |
| 2499 |
|
| 2500 |
blendTypeSrc->Enable(!blendTypeStrings.second.empty()); |
| 2501 |
blendTypeDest->Enable(!blendTypeStrings.second.empty()); |
| 2502 |
|
| 2503 |
if (blendTypeStrings.second.empty()) |
| 2504 |
{ |
| 2505 |
blendType->SetStringSelection(blendTypeStrings.first); |
| 2506 |
|
| 2507 |
blendTypeSrc->SetStringSelection("gl_one"); |
| 2508 |
blendTypeDest->SetStringSelection("gl_zero"); |
| 2509 |
|
| 2510 |
// Get the actual src and dest blend types this shortcut is working with |
| 2511 |
for (const auto& pair : shaders::BlendTypeShortcuts) |
| 2512 |
{ |
| 2513 |
if (blendTypeStrings.first == pair.first) |
| 2514 |
{ |
| 2515 |
blendTypeSrc->SetStringSelection(pair.second.first); |
| 2516 |
blendTypeDest->SetStringSelection(pair.second.second); |
| 2517 |
break; |
| 2518 |
} |
| 2519 |
} |
| 2520 |
} |
| 2521 |
else |
| 2522 |
{ |
| 2523 |
blendType->SetStringSelection(_(CUSTOM_BLEND_TYPE)); |
| 2524 |
blendTypeSrc->SetStringSelection(blendTypeStrings.first); |
| 2525 |
blendTypeDest->SetStringSelection(blendTypeStrings.second); |
| 2526 |
} |
| 2527 |
} |
| 2528 |
else |
| 2529 |
{ |
| 2530 |
blendType->Disable(); |
| 2531 |
blendTypeSrc->Disable(); |
| 2532 |
blendTypeDest->Disable(); |
| 2533 |
} |
| 2534 |
} |
| 2535 |
|
| 2536 |
void MaterialEditor::updateStageTextureControls() |
| 2537 |
{ |
| 2538 |
auto selectedStage = getSelectedStage(); |
| 2539 |
|
| 2540 |
auto texgenDropdown = getControl<wxChoice>("MaterialStageTexGenType"); |
| 2541 |
|
| 2542 |
if (selectedStage) |
| 2543 |
{ |
| 2544 |
// Clamp Type |
| 2545 |
auto clampDropdown = getControl<wxChoice>("MaterialStageClampType"); |
| 2546 |
auto clampTypeString = shaders::getStringForClampType(selectedStage->getClampType()); |
| 2547 |
clampDropdown->SetStringSelection(clampTypeString); |
| 2548 |
|
| 2549 |
auto texgenName = shaders::getStringForTexGenType(selectedStage->getTexGenType()); |
| 2550 |
texgenDropdown->Select(texgenDropdown->FindString(texgenName)); |
| 2551 |
|
| 2552 |
getControl<wxPanel>("MaterialStageWobblySkyPanel")->Show(selectedStage->getTexGenType() == IShaderLayer::TEXGEN_WOBBLESKY); |
| 2553 |
} |
| 2554 |
else |
| 2555 |
{ |
| 2556 |
texgenDropdown->Select(0); |
| 2557 |
getControl<wxPanel>("MaterialStageWobblySkyPanel")->Hide(); |
| 2558 |
} |
| 2559 |
} |
| 2560 |
|
| 2561 |
void MaterialEditor::updateStageProgramControls() |
| 2562 |
{ |
| 2563 |
_stageProgramParameters->Clear(); |
| 2564 |
|
| 2565 |
auto selectedStage = getSelectedStage(); |
| 2566 |
|
| 2567 |
if (selectedStage) |
| 2568 |
{ |
| 2569 |
getControl<wxTextCtrl>("MaterialStageVertexProgram")->SetValue(selectedStage->getVertexProgram()); |
| 2570 |
getControl<wxTextCtrl>("MaterialStageFragmentProgram")->SetValue(selectedStage->getFragmentProgram()); |
| 2571 |
|
| 2572 |
_stageProgramParameters->Clear(); |
| 2573 |
|
| 2574 |
for (int i = 0; i < selectedStage->getNumVertexParms(); ++i) |
| 2575 |
{ |
| 2576 |
const auto& parm = selectedStage->getVertexParm(i); |
| 2577 |
|
| 2578 |
if (parm.index == -1) continue; // undefined param |
| 2579 |
|
| 2580 |
auto row = _stageProgramParameters->AddItem(); |
| 2581 |
|
| 2582 |
row[_stageProgramColumns.type] = "vertexParm"; |
| 2583 |
row[_stageProgramColumns.index] = string::to_string(parm.index); |
| 2584 |
|
| 2585 |
std::string expression; |
| 2586 |
|
| 2587 |
for (int expr = 0; parm.expressions[expr] && expr < 4; ++expr) |
| 2588 |
{ |
| 2589 |
expression += expression.empty() ? "" : " "; |
| 2590 |
expression += parm.expressions[expr]->getExpressionString(); |
| 2591 |
} |
| 2592 |
|
| 2593 |
row[_stageProgramColumns.expression] = expression; |
| 2594 |
|
| 2595 |
row.SendItemAdded(); |
| 2596 |
} |
| 2597 |
|
| 2598 |
for (int i = 0; i < selectedStage->getNumFragmentMaps(); ++i) |
| 2599 |
{ |
| 2600 |
const auto& parm = selectedStage->getFragmentMap(i); |
| 2601 |
|
| 2602 |
if (parm.index == -1) continue; // undefined param |
| 2603 |
|
| 2604 |
auto row = _stageProgramParameters->AddItem(); |
| 2605 |
|
| 2606 |
row[_stageProgramColumns.type] = "fragmentMap"; |
| 2607 |
row[_stageProgramColumns.index] = string::to_string(parm.index); |
| 2608 |
|
| 2609 |
std::string expression = string::join(parm.options, " "); |
| 2610 |
|
| 2611 |
expression += expression.empty() ? "" : " "; |
| 2612 |
expression += parm.map ? parm.map->getExpressionString() : ""; |
| 2613 |
|
| 2614 |
row[_stageProgramColumns.expression] = expression; |
| 2615 |
|
| 2616 |
row.SendItemAdded(); |
| 2617 |
} |
| 2618 |
} |
| 2619 |
else |
| 2620 |
{ |
| 2621 |
getControl<wxTextCtrl>("MaterialStageVertexProgram")->SetValue(""); |
| 2622 |
getControl<wxTextCtrl>("MaterialStageFragmentProgram")->SetValue(""); |
| 2623 |
} |
| 2624 |
} |
| 2625 |
|
| 2626 |
void MaterialEditor::updateStageTransformControls() |
| 2627 |
{ |
| 2628 |
_stageTransformations->Clear(); |
| 2629 |
|
| 2630 |
auto selectedStage = getSelectedStage(); |
| 2631 |
|
| 2632 |
if (!selectedStage) |
| 2633 |
{ |
| 2634 |
return; |
| 2635 |
} |
| 2636 |
|
| 2637 |
getControl<wxButton>("MaterialStageRemoveTransformButton")->Enable(_stageTransformView->GetSelection().IsOk()); |
| 2638 |
|
| 2639 |
const auto& transformations = selectedStage->getTransformations(); |
| 2640 |
|
| 2641 |
for (int i = 0; i < transformations.size(); ++i) |
| 2642 |
{ |
| 2643 |
const auto& transformation = transformations[i]; |
| 2644 |
|
| 2645 |
auto row = _stageTransformations->AddItem(); |
| 2646 |
|
| 2647 |
row[_stageTransformationColumns.type] = shaders::getStringForTransformType(transformation.type); |
| 2648 |
row[_stageTransformationColumns.index] = string::to_string(i); |
| 2649 |
|
| 2650 |
row[_stageTransformationColumns.expression1] = transformation.expression1 ? |
| 2651 |
transformation.expression1->getExpressionString() : std::string(); |
| 2652 |
row[_stageTransformationColumns.expression2] = transformation.expression2 ? |
| 2653 |
transformation.expression2->getExpressionString() : std::string(); |
| 2654 |
|
| 2655 |
row.SendItemAdded(); |
| 2656 |
} |
| 2657 |
} |
| 2658 |
|
| 2659 |
void MaterialEditor::updateStageControls() |
| 2660 |
{ |
| 2661 |
util::ScopedBoolLock lock(_stageUpdateInProgress); |
| 2662 |
|
| 2663 |
auto selectedStage = getSelectedStage(); |
| 2664 |
|
| 2665 |
// Update all registered bindings |
| 2666 |
for (const auto& binding : _stageBindings) |
| 2667 |
{ |
| 2668 |
binding->setSource(selectedStage); |
| 2669 |
binding->updateFromSource(); |
| 2670 |
} |
| 2671 |
|
| 2672 |
updateStageBlendControls(); |
| 2673 |
updateStageTextureControls(); |
| 2674 |
updateStageProgramControls(); |
| 2675 |
updateStageTransformControls(); |
| 2676 |
updateStageColoredStatus(); |
| 2677 |
|
| 2678 |
if (selectedStage) |
| 2679 |
{ |
| 2680 |
selectedStage->evaluateExpressions(0); // initialise the values of this stage |
| 2681 |
|
| 2682 |
auto imageMap = getControl<MapExpressionEntry>("MaterialStageImageMap"); |
| 2683 |
auto videoMapLoop = getControl<wxCheckBox>("MaterialStageVideoMapLoop"); |
| 2684 |
auto soundMapWave = getControl<wxCheckBox>("MaterialStageSoundMapWaveform"); |
| 2685 |
|
| 2686 |
auto renderMapWidth = getControl<wxSpinCtrl>("MaterialStageRenderMapWidth"); |
| 2687 |
auto renderMapHeight = getControl<wxSpinCtrl>("MaterialStageRenderMapHeight"); |
| 2688 |
|
| 2689 |
auto mapType = getControl<wxChoice>("MaterialStageMapType"); |
| 2690 |
mapType->SetStringSelection(shaders::getStringForMapType(selectedStage->getMapType())); |
| 2691 |
|
| 2692 |
if (selectedStage->getMapType() != IShaderLayer::MapType::SoundMap) |
| 2693 |
{ |
| 2694 |
soundMapWave->SetValue(false); |
| 2695 |
} |
| 2696 |
|
| 2697 |
if (selectedStage->getMapType() == IShaderLayer::MapType::SoundMap) |
| 2698 |
{ |
| 2699 |
imageMap->Disable(); |
| 2700 |
} |
| 2701 |
else |
| 2702 |
{ |
| 2703 |
imageMap->Enable(); |
| 2704 |
videoMapLoop->SetValue(false); |
| 2705 |
soundMapWave->SetValue(false); |
| 2706 |
renderMapWidth->SetValue(0); |
| 2707 |
renderMapHeight->SetValue(0); |
| 2708 |
} |
| 2709 |
|
| 2710 |
switch (selectedStage->getMapType()) |
| 2711 |
{ |
| 2712 |
case IShaderLayer::MapType::VideoMap: |
| 2713 |
{ |
| 2714 |
auto videoMapExpression = std::dynamic_pointer_cast<shaders::IVideoMapExpression>(selectedStage->getMapExpression()); |
| 2715 |
videoMapLoop->SetValue(videoMapExpression ? videoMapExpression->isLooping() : false); |
| 2716 |
} |
| 2717 |
break; |
| 2718 |
case IShaderLayer::MapType::SoundMap: |
| 2719 |
{ |
| 2720 |
auto soundMapExpression = std::dynamic_pointer_cast<shaders::ISoundMapExpression>(selectedStage->getMapExpression()); |
| 2721 |
soundMapWave->SetValue(soundMapExpression ? soundMapExpression->isWaveform() : false); |
| 2722 |
} |
| 2723 |
break; |
| 2724 |
case IShaderLayer::MapType::RemoteRenderMap: |
| 2725 |
case IShaderLayer::MapType::MirrorRenderMap: |
| 2726 |
renderMapWidth->SetValue(static_cast<int>(selectedStage->getRenderMapSize().x())); |
| 2727 |
renderMapHeight->SetValue(static_cast<int>(selectedStage->getRenderMapSize().y())); |
| 2728 |
break; |
| 2729 |
} |
| 2730 |
|
| 2731 |
// Show the specialised map type controls |
| 2732 |
videoMapLoop->Show(selectedStage->getMapType() == IShaderLayer::MapType::VideoMap); |
| 2733 |
soundMapWave->Show(selectedStage->getMapType() == IShaderLayer::MapType::SoundMap); |
| 2734 |
getControl<wxPanel>("MaterialStageRenderMapPanel")->Show(selectedStage->getMapType() == IShaderLayer::MapType::MirrorRenderMap || |
| 2735 |
selectedStage->getMapType() == IShaderLayer::MapType::RemoteRenderMap); |
| 2736 |
|
| 2737 |
getControl<wxPanel>("StagePageBlending")->Layout(); |
| 2738 |
|
| 2739 |
// Vertex Colours |
| 2740 |
getControl<wxRadioButton>("MaterialStageNoVertexColourFlag")->SetValue(selectedStage->getVertexColourMode() == IShaderLayer::VERTEX_COLOUR_NONE); |
| 2741 |
getControl<wxRadioButton>("MaterialStageVertexColourFlag")->SetValue(selectedStage->getVertexColourMode() == IShaderLayer::VERTEX_COLOUR_MULTIPLY); |
| 2742 |
getControl<wxRadioButton>("MaterialStageInverseVertexColourFlag")->SetValue(selectedStage->getVertexColourMode() == IShaderLayer::VERTEX_COLOUR_INVERSE_MULTIPLY); |
| 2743 |
} |
| 2744 |
else |
| 2745 |
{ |
| 2746 |
getControl<wxRadioButton>("MaterialStageNoVertexColourFlag")->SetValue(true); |
| 2747 |
} |
| 2748 |
} |
| 2749 |
|
| 2750 |
void MaterialEditor::_onMaterialTypeChoice(wxCommandEvent& ev) |
| 2751 |
{ |
| 2752 |
if (!_material || _materialUpdateInProgress) return; |
| 2753 |
|
| 2754 |
auto selectedString = static_cast<wxChoice*>(ev.GetEventObject())->GetStringSelection(); |
| 2755 |
_material->setSurfaceType(shaders::getSurfaceTypeForString(selectedString.ToStdString())); |
| 2756 |
|
| 2757 |
updateMaterialPropertiesFromMaterial(); |
| 2758 |
} |
| 2759 |
|
| 2760 |
void MaterialEditor::_onAddStageTransform(wxCommandEvent& ev) |
| 2761 |
{ |
| 2762 |
auto selectedStage = getEditableStageForSelection(); |
| 2763 |
|
| 2764 |
if (selectedStage) |
| 2765 |
{ |
| 2766 |
auto typeString = getControl<wxChoice>("MaterialStageAddTransformChoice")->GetStringSelection(); |
| 2767 |
auto type = shaders::getTransformTypeForString(typeString.ToStdString()); |
| 2768 |
|
| 2769 |
selectedStage->appendTransformation(IShaderLayer::Transformation{ type }); |
| 2770 |
|
| 2771 |
updateStageControls(); |
| 2772 |
onMaterialChanged(); |
| 2773 |
} |
| 2774 |
} |
| 2775 |
|
| 2776 |
void MaterialEditor::_onRemoveStageTransform(wxCommandEvent& ev) |
| 2777 |
{ |
| 2778 |
auto stage = getEditableStageForSelection(); |
| 2779 |
|
| 2780 |
if (stage && _stageTransformView->GetSelection().IsOk()) |
| 2781 |
{ |
| 2782 |
wxutil::TreeModel::Row row(_stageTransformView->GetSelection(), *_stageTransformations); |
| 2783 |
|
| 2784 |
auto index = row[_stageTransformationColumns.index].getInteger(); |
| 2785 |
stage->removeTransformation(index); |
| 2786 |
|
| 2787 |
updateStageControls(); |
| 2788 |
onMaterialChanged(); |
| 2789 |
} |
| 2790 |
} |
| 2791 |
|
| 2792 |
void MaterialEditor::_onStageTransformEdited(wxDataViewEvent& ev) |
| 2793 |
{ |
| 2794 |
if (ev.IsEditCancelled()) return; |
| 2795 |
|
| 2796 |
auto stage = getEditableStageForSelection(); |
| 2797 |
|
| 2798 |
if (!stage) return; |
| 2799 |
|
| 2800 |
wxutil::TreeModel::Row row(ev.GetItem(), *_stageTransformations); |
| 2801 |
|
| 2802 |
// The iter points to the edited cell now, get the actor number |
| 2803 |
int transformIndex = row[_stageTransformationColumns.index].getInteger(); |
| 2804 |
std::string transformTypeString = row[_stageTransformationColumns.type]; |
| 2805 |
|
| 2806 |
if (transformIndex < 0 || transformIndex > stage->getTransformations().size()) |
| 2807 |
{ |
| 2808 |
return; |
| 2809 |
} |
| 2810 |
|
| 2811 |
std::string expression1, expression2; |
| 2812 |
auto type = shaders::getTransformTypeForString(transformTypeString); |
| 2813 |
|
| 2814 |
#if wxCHECK_VERSION(3, 1, 0) |
| 2815 |
// wx 3.1+ delivers the new value through the event |
| 2816 |
if (ev.GetColumn() == _stageTransformationColumns.expression1.getColumnIndex()) |
| 2817 |
{ |
| 2818 |
expression1 = ev.GetValue().GetString().ToStdString(); |
| 2819 |
expression2 = row[_stageTransformationColumns.expression2]; |
| 2820 |
} |
| 2821 |
else if (ev.GetColumn() == _stageTransformationColumns.expression2.getColumnIndex()) |
| 2822 |
{ |
| 2823 |
expression1 = row[_stageTransformationColumns.expression1]; |
| 2824 |
expression2 = ev.GetValue().GetString().ToStdString(); |
| 2825 |
} |
| 2826 |
#else |
| 2827 |
// wx 3.0.x has the values set in the model |
| 2828 |
expression1 = row[_stageTransformationColumns.expression1]; |
| 2829 |
expression2 = row[_stageTransformationColumns.expression2]; |
| 2830 |
#endif |
| 2831 |
|
| 2832 |
stage->updateTransformation(transformIndex, type, expression1, expression2); |
| 2833 |
onMaterialChanged(); |
| 2834 |
} |
| 2835 |
|
| 2836 |
void MaterialEditor::_onStageColoredChecked(const IEditableShaderLayer::Ptr& stage, bool newValue) |
| 2837 |
{ |
| 2838 |
bool stageIsCurrentlyColoured = stageQualifiesAsColoured(stage); |
| 2839 |
|
| 2840 |
if (newValue && !stageIsCurrentlyColoured) |
| 2841 |
{ |
| 2842 |
stage->setColourExpressionFromString(IShaderLayer::COMP_RED, "parm0"); |
| 2843 |
stage->setColourExpressionFromString(IShaderLayer::COMP_GREEN, "parm1"); |
| 2844 |
stage->setColourExpressionFromString(IShaderLayer::COMP_BLUE, "parm2"); |
| 2845 |
stage->setColourExpressionFromString(IShaderLayer::COMP_ALPHA, "parm3"); |
| 2846 |
} |
| 2847 |
else if (!newValue && stageIsCurrentlyColoured) |
| 2848 |
{ |
| 2849 |
stage->setColourExpressionFromString(IShaderLayer::COMP_RED, ""); |
| 2850 |
stage->setColourExpressionFromString(IShaderLayer::COMP_GREEN, ""); |
| 2851 |
stage->setColourExpressionFromString(IShaderLayer::COMP_BLUE, ""); |
| 2852 |
stage->setColourExpressionFromString(IShaderLayer::COMP_ALPHA, ""); |
| 2853 |
} |
| 2854 |
|
| 2855 |
updateStageControls(); |
| 2856 |
} |
| 2857 |
|
| 2858 |
void MaterialEditor::_onStageMapTypeChanged(wxCommandEvent& ev) |
| 2859 |
{ |
| 2860 |
auto stage = getEditableStageForSelection(); |
| 2861 |
if (!stage) return; |
| 2862 |
|
| 2863 |
auto mapTypeString = getControl<wxChoice>("MaterialStageMapType")->GetStringSelection(); |
| 2864 |
stage->setMapType(shaders::getMapTypeForString(mapTypeString.ToStdString())); |
| 2865 |
|
| 2866 |
updateStageControls(); |
| 2867 |
} |
| 2868 |
|
| 2869 |
void MaterialEditor::_onStageBlendTypeChanged(wxCommandEvent& ev) |
| 2870 |
{ |
| 2871 |
auto stage = getEditableStageForSelection(); |
| 2872 |
if (!stage) return; |
| 2873 |
|
| 2874 |
std::pair<std::string, std::string> blendFuncStrings; |
| 2875 |
|
| 2876 |
auto blendTypeString = getControl<wxChoice>("MaterialStageBlendType")->GetStringSelection(); |
| 2877 |
|
| 2878 |
if (blendTypeString == _(CUSTOM_BLEND_TYPE)) |
| 2879 |
{ |
| 2880 |
blendFuncStrings.first = getControl<wxChoice>("MaterialStageBlendTypeSrc")->GetStringSelection(); |
| 2881 |
blendFuncStrings.second = getControl<wxChoice>("MaterialStageBlendTypeDest")->GetStringSelection(); |
| 2882 |
} |
| 2883 |
else |
| 2884 |
{ |
| 2885 |
// It's one of diffuse/bump/specular or a blend shortcut like add/modulate |
| 2886 |
blendFuncStrings.first = blendTypeString; |
| 2887 |
} |
| 2888 |
|
| 2889 |
stage->setBlendFuncStrings(blendFuncStrings); |
| 2890 |
|
| 2891 |
updateNameOfSelectedStage(); |
| 2892 |
updateStageControls(); |
| 2893 |
onMaterialChanged(); |
| 2894 |
} |
| 2895 |
|
| 2896 |
void MaterialEditor::_onAddStage(wxCommandEvent& ev) |
| 2897 |
{ |
| 2898 |
std::size_t index = _material->addLayer(determineStageTypeToCreate(_material)); |
| 2899 |
|
| 2900 |
updateControlsFromMaterial(); |
| 2901 |
selectStageByIndex(index); |
| 2902 |
} |
| 2903 |
|
| 2904 |
void MaterialEditor::_onRemoveStage(wxCommandEvent& ev) |
| 2905 |
{ |
| 2906 |
auto item = _stageView->GetSelection(); |
| 2907 |
if (!_material || !item.IsOk()) return; |
| 2908 |
|
| 2909 |
auto row = wxutil::TreeModel::Row(item, *_stageList); |
| 2910 |
auto index = row[STAGE_COLS().index].getInteger(); |
| 2911 |
|
| 2912 |
_material->removeLayer(index); |
| 2913 |
updateStageListFromMaterial(); |
| 2914 |
|
| 2915 |
auto layersCount = _material->getNumLayers(); |
| 2916 |
|
| 2917 |
while (index > 0) |
| 2918 |
{ |
| 2919 |
if (index < layersCount) |
| 2920 |
{ |
| 2921 |
selectStageByIndex(index); |
| 2922 |
return; |
| 2923 |
} |
| 2924 |
|
| 2925 |
--index; |
| 2926 |
} |
| 2927 |
} |
| 2928 |
|
| 2929 |
void MaterialEditor::toggleSelectedStage() |
| 2930 |
{ |
| 2931 |
if (!_stageView->GetSelection().IsOk()) return; |
| 2932 |
|
| 2933 |
wxutil::TreeModel::Row row(_stageView->GetSelection(), *_stageList); |
| 2934 |
|
| 2935 |
if (!_material || !GlobalMaterialManager().materialCanBeModified(_material->getName()) || |
| 2936 |
row[STAGE_COLS().global].getBool()) |
| 2937 |
{ |
| 2938 |
return; |
| 2939 |
} |
| 2940 |
|
| 2941 |
auto stage = getEditableStageForSelection(); |
| 2942 |
|
| 2943 |
if (!stage) return; |
| 2944 |
|
| 2945 |
bool newState = !row[STAGE_COLS().enabled].getBool(); |
| 2946 |
stage->setEnabled(newState); |
| 2947 |
|
| 2948 |
row[STAGE_COLS().enabled] = newState; |
| 2949 |
row[STAGE_COLS().icon] = wxVariant(newState ? _iconVisible : _iconInvisible); |
| 2950 |
row.SendItemChanged(); |
| 2951 |
|
| 2952 |
onMaterialChanged(); |
| 2953 |
} |
| 2954 |
|
| 2955 |
void MaterialEditor::_onToggleStage(wxCommandEvent& ev) |
| 2956 |
{ |
| 2957 |
toggleSelectedStage(); |
| 2958 |
} |
| 2959 |
|
| 2960 |
void MaterialEditor::_onDuplicateStage(wxCommandEvent& ev) |
| 2961 |
{ |
| 2962 |
auto item = _stageView->GetSelection(); |
| 2963 |
if (!_material || !item.IsOk()) return; |
| 2964 |
|
| 2965 |
auto row = wxutil::TreeModel::Row(item, *_stageList); |
| 2966 |
auto index = row[STAGE_COLS().index].getInteger(); |
| 2967 |
|
| 2968 |
auto newIndex = _material->duplicateLayer(index); |
| 2969 |
updateStageListFromMaterial(); |
| 2970 |
selectStageByIndex(newIndex); |
| 2971 |
} |
| 2972 |
|
| 2973 |
void MaterialEditor::updateNameOfSelectedStage() |
| 2974 |
{ |
| 2975 |
auto item = _stageView->GetSelection(); |
| 2976 |
if (!item.IsOk()) return; |
| 2977 |
|
| 2978 |
auto row = wxutil::TreeModel::Row(item, *_stageList); |
| 2979 |
|
| 2980 |
row[STAGE_COLS().name] = getNameForLayer(*getSelectedStage()); |
| 2981 |
row.SendItemChanged(); |
| 2982 |
} |
| 2983 |
|
| 2984 |
void MaterialEditor::moveStagePosition(int direction) |
| 2985 |
{ |
| 2986 |
auto item = _stageView->GetSelection(); |
| 2987 |
if (!_material || !item.IsOk()) return; |
| 2988 |
|
| 2989 |
auto row = wxutil::TreeModel::Row(item, *_stageList); |
| 2990 |
auto index = row[STAGE_COLS().index].getInteger(); |
| 2991 |
|
| 2992 |
int newPosition = index + direction; |
| 2993 |
|
| 2994 |
if (newPosition >= 0 && newPosition < _material->getNumLayers()) |
| 2995 |
{ |
| 2996 |
_material->swapLayerPosition(static_cast<std::size_t>(index), static_cast<std::size_t>(newPosition)); |
| 2997 |
onMaterialChanged(); |
| 2998 |
updateStageListFromMaterial(); |
| 2999 |
selectStageByIndex(static_cast<std::size_t>(newPosition)); |
| 3000 |
} |
| 3001 |
} |
| 3002 |
|
| 3003 |
void MaterialEditor::_onSortRequestChanged(wxCommandEvent& ev) |
| 3004 |
{ |
| 3005 |
if (!_material || _materialUpdateInProgress) return; |
| 3006 |
|
| 3007 |
auto sortDropdown = getControl<wxComboBox>("MaterialSortValue"); |
| 3008 |
auto value = sortDropdown->GetValue().ToStdString(); |
| 3009 |
_material->setSortRequest(shaders::getSortRequestValueForString(value)); |
| 3010 |
|
| 3011 |
onMaterialChanged(); |
| 3012 |
} |
| 3013 |
|
| 3014 |
void MaterialEditor::updateMaterialNameControl() |
| 3015 |
{ |
| 3016 |
if (!_material) return; |
| 3017 |
|
| 3018 |
auto nameControl = getControl<wxTextCtrl>("MaterialName"); |
| 3019 |
if (nameControl->GetValue() != _material->getName()) |
| 3020 |
{ |
| 3021 |
nameControl->SetForegroundColour(wxColor(220, 0, 0)); |
| 3022 |
} |
| 3023 |
else |
| 3024 |
{ |
| 3025 |
nameControl->SetForegroundColour(wxNullColour); |
| 3026 |
} |
| 3027 |
} |
| 3028 |
|
| 3029 |
void MaterialEditor::updateMaterialTreeItem() |
| 3030 |
{ |
| 3031 |
if (!_material) return; |
| 3032 |
|
| 3033 |
const auto& columns = _treeView->Columns(); |
| 3034 |
auto item = _treeView->GetTreeModel()->FindString(_material->getName(), columns.declName); |
| 3035 |
|
| 3036 |
if (!item.IsOk()) |
| 3037 |
{ |
| 3038 |
return; |
| 3039 |
} |
| 3040 |
|
| 3041 |
bool isModified = _material->isModified(); |
| 3042 |
|
| 3043 |
wxutil::TreeModel::Row row(item, *_treeView->GetModel()); |
| 3044 |
|
| 3045 |
if (!row[columns.isFolder].getBool()) |
| 3046 |
row[columns.iconAndName].setAttr(wxutil::TreeViewItemStyle::Modified(isModified)); |
| 3047 |
else |
| 3048 |
row[columns.iconAndName].setAttr(wxDataViewItemAttr()); |
| 3049 |
|
| 3050 |
wxDataViewIconText value = row[columns.iconAndName]; |
| 3051 |
|
| 3052 |
if (!isModified && value.GetText().EndsWith("*")) |
| 3053 |
{ |
| 3054 |
value.SetText(value.GetText().RemoveLast(1)); |
| 3055 |
row[columns.iconAndName] = wxVariant(value); |
| 3056 |
} |
| 3057 |
else if (isModified && !value.GetText().EndsWith("*")) |
| 3058 |
{ |
| 3059 |
value.SetText(value.GetText() + "*"); |
| 3060 |
row[columns.iconAndName] = wxVariant(value); |
| 3061 |
} |
| 3062 |
|
| 3063 |
row.SendItemChanged(); |
| 3064 |
} |
| 3065 |
|
| 3066 |
void MaterialEditor::onMaterialChanged() |
| 3067 |
{ |
| 3068 |
updateMaterialPropertiesFromMaterial(); |
| 3069 |
updateMaterialTreeItem(); |
| 3070 |
updateMaterialControlSensitivity(); |
| 3071 |
updateSourceView(); |
| 3072 |
} |
| 3073 |
|
| 3074 |
void MaterialEditor::convertTextCtrlToMapExpressionEntry(const std::string& ctrlName) |
| 3075 |
{ |
| 3076 |
auto windowToPlaceDialogsOn = getControl<wxWindow>("MaterialEditorLeftArea"); |
| 3077 |
|
| 3078 |
auto oldCtrl = findNamedObject<wxTextCtrl>(this, ctrlName); |
| 3079 |
replaceControl(oldCtrl, new MapExpressionEntry(oldCtrl->GetParent(), windowToPlaceDialogsOn)); |
| 3080 |
} |
| 3081 |
|
| 3082 |
void MaterialEditor::_onBasicAddFrobStages(wxCommandEvent& ev) |
| 3083 |
{ |
| 3084 |
if (!_material || !GlobalMaterialManager().materialCanBeModified(_material->getName())) |
| 3085 |
{ |
| 3086 |
return; |
| 3087 |
} |
| 3088 |
|
| 3089 |
try |
| 3090 |
{ |
| 3091 |
shaders::FrobStageSetup::AddToMaterial(_material); |
| 3092 |
} |
| 3093 |
catch (const std::runtime_error& ex) |
| 3094 |
{ |
| 3095 |
wxutil::Messagebox::ShowError(ex.what(), this); |
| 3096 |
rError() << ex.what() << std::endl; |
| 3097 |
} |
| 3098 |
|
| 3099 |
updateControlsFromMaterial(); |
| 3100 |
onMaterialChanged(); |
| 3101 |
} |
| 3102 |
|
| 3103 |
void MaterialEditor::_onBasicRemoveFrobStages(wxCommandEvent& ev) |
| 3104 |
{ |
| 3105 |
if (!_material || !GlobalMaterialManager().materialCanBeModified(_material->getName())) |
| 3106 |
{ |
| 3107 |
return; |
| 3108 |
} |
| 3109 |
|
| 3110 |
try |
| 3111 |
{ |
| 3112 |
shaders::FrobStageSetup::RemoveFromMaterial(_material); |
| 3113 |
} |
| 3114 |
catch (const std::runtime_error& ex) |
| 3115 |
{ |
| 3116 |
wxutil::Messagebox::ShowError(ex.what(), this); |
| 3117 |
rError() << ex.what() << std::endl; |
| 3118 |
} |
| 3119 |
|
| 3120 |
updateControlsFromMaterial(); |
| 3121 |
onMaterialChanged(); |
| 3122 |
} |
| 3123 |
|
| 3124 |
void MaterialEditor::_onBasicTestFrobStages(wxMouseEvent& ev) |
| 3125 |
{ |
| 3126 |
_preview->enableFrobHighlight(ev.ButtonDown()); |
| 3127 |
ev.Skip(); |
| 3128 |
} |
| 3129 |
|
| 3130 |
void MaterialEditor::assignDecalInfoToMaterial(const MaterialPtr& material, bool isEnabled) |
| 3131 |
{ |
| 3132 |
Material::DecalInfo info; |
| 3133 |
bool wasEnabled = material->getParseFlags() & Material::PF_HasDecalInfo; |
| 3134 |
|
| 3135 |
if (isEnabled) |
| 3136 |
{ |
| 3137 |
info.stayMilliSeconds = static_cast<int>(getControl<wxSpinCtrlDouble>("MaterialEditorDecalInfoStaySeconds")->GetValue() * 1000); |
| 3138 |
info.fadeMilliSeconds = static_cast<int>(getControl<wxSpinCtrlDouble>("MaterialEditorDecalInfoFadeSeconds")->GetValue() * 1000); |
| 3139 |
|
| 3140 |
info.startColour = Vector4( |
| 3141 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoStartRed")->GetValue(), |
| 3142 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoStartGreen")->GetValue(), |
| 3143 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoStartBlue")->GetValue(), |
| 3144 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoStartAlpha")->GetValue() |
| 3145 |
); |
| 3146 |
|
| 3147 |
info.endColour = Vector4( |
| 3148 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoEndRed")->GetValue(), |
| 3149 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoEndGreen")->GetValue(), |
| 3150 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoEndBlue")->GetValue(), |
| 3151 |
getControl<wxSpinCtrlDouble>("MaterialDecalInfoEndAlpha")->GetValue() |
| 3152 |
); |
| 3153 |
|
| 3154 |
if (!wasEnabled && info.stayMilliSeconds == 0) |
| 3155 |
{ |
| 3156 |
info.stayMilliSeconds = 1; // make sure the value is > 0 otherwise the flag doesn't get set |
| 3157 |
} |
| 3158 |
} |
| 3159 |
|
| 3160 |
material->setDecalInfo(info); |
| 3161 |
} |
| 3162 |
|
| 3163 |
} |