Skip to content

Commit

Permalink
#5570: Basic light properties are editable
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Apr 9, 2021
1 parent a7e5ae8 commit c10b873
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 64 deletions.
199 changes: 141 additions & 58 deletions install/ui/materialeditor.fbp

Large diffs are not rendered by default.

29 changes: 24 additions & 5 deletions install/ui/materialeditor.xrc
Expand Up @@ -3240,12 +3240,31 @@
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL|wxALL</flag>
<option>1</option>
<flag>wxALIGN_CENTER_VERTICAL</flag>
<border>0</border>
<object class="wxColourPickerCtrl" name="MaterialPreviewLightColour">
<value>#000000</value>
<style>wxCLRP_DEFAULT_STYLE</style>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL|wxALL</flag>
<border>0</border>
<object class="wxColourPickerCtrl" name="MaterialPreviewLightColour">
<value>#000000</value>
<style>wxCLRP_DEFAULT_STYLE</style>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL|wxLEFT</flag>
<border>6</border>
<object class="wxButton" name="MaterialPreviewLightResetColourButton">
<label>Reset to Entity Class Default</label>
<default>0</default>
<markup>0</markup>
<bitmap />
</object>
</object>
</object>
</object>
</object>
Expand Down
32 changes: 31 additions & 1 deletion radiant/ui/materials/editor/MaterialEditor.cpp
Expand Up @@ -24,6 +24,7 @@
#include "wxutil/dialog/MessageBox.h"
#include "wxutil/dataview/ResourceTreeViewToolbar.h"
#include "wxutil/dataview/TreeViewItemStyle.h"
#include "wxutil/EntityClassChooser.h"
#include "wxutil/Bitmap.h"
#include "materials/FrobStageSetup.h"
#include <fmt/format.h>
Expand Down Expand Up @@ -120,7 +121,8 @@ MaterialEditor::MaterialEditor() :
_stageList(new wxutil::TreeModel(STAGE_COLS(), true)),
_stageView(nullptr),
_stageUpdateInProgress(false),
_materialUpdateInProgress(false)
_materialUpdateInProgress(false),
_lightUpdateInProgress(false)
{
loadNamedPanel(this, "MaterialEditorMainPanel");

Expand Down Expand Up @@ -252,6 +254,8 @@ void MaterialEditor::setupPreviewLightProperties(wxWindow* previewPanel)
// Wire up the signals
_preview->signal_LightChanged().connect([this] ()
{
util::ScopedBoolLock lock(_lightUpdateInProgress);

getControl<wxTextCtrl>("MaterialPreviewLightClassname")->SetValue(_preview->getLightClassname());

auto colour = _preview->getLightColour() * 255.0;
Expand All @@ -260,6 +264,32 @@ void MaterialEditor::setupPreviewLightProperties(wxWindow* previewPanel)
static_cast<wxColour::ChannelType>(colour.y()),
static_cast<wxColour::ChannelType>(colour.z())));
});

getControl<wxTextCtrl>("MaterialPreviewLightClassname")->Bind(wxEVT_TEXT, [this](wxCommandEvent& ev)
{
if (_lightUpdateInProgress) return;
_preview->setLightClassname(ev.GetString().ToStdString());
});

getControl<wxColourPickerCtrl>("MaterialPreviewLightColour")->Bind(wxEVT_COLOURPICKER_CURRENT_CHANGED,
[this](wxColourPickerEvent& ev)
{
if (_lightUpdateInProgress) return;
auto colour = ev.GetColour();
_preview->setLightColour(Vector3(colour.Red() / 255.0, colour.Green() / 255.0, colour.Blue() / 255.0));
});

getControl<wxButton>("MaterialPreviewLightChooseClassnameButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev)
{
auto textCtrl = getControl<wxTextCtrl>("MaterialPreviewLightClassname");
auto newClassName = wxutil::EntityClassChooser::chooseEntityClass(textCtrl->GetValue().ToStdString());
textCtrl->SetValue(newClassName);
});

getControl<wxButton>("MaterialPreviewLightResetColourButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent& ev)
{
_preview->resetLightColour();
});
}

void MaterialEditor::_onClose(wxCommandEvent& ev)
Expand Down
1 change: 1 addition & 0 deletions radiant/ui/materials/editor/MaterialEditor.h
Expand Up @@ -84,6 +84,7 @@ class MaterialEditor :

bool _stageUpdateInProgress;
bool _materialUpdateInProgress;
bool _lightUpdateInProgress;

private:
MaterialEditor();
Expand Down
15 changes: 15 additions & 0 deletions radiant/ui/materials/editor/MaterialPreview.cpp
Expand Up @@ -11,6 +11,7 @@
#include "wxutil/dialog/MessageBox.h"
#include "wxutil/Bitmap.h"
#include <wx/toolbar.h>
#include "entitylib.h"
#include "gamelib.h"

namespace ui
Expand Down Expand Up @@ -309,7 +310,10 @@ std::string MaterialPreview::getLightClassname()

void MaterialPreview::setLightClassname(const std::string& className)
{
if (!_light || className.empty()) return;

_light = changeEntityClassname(_light, className);
_sigLightChanged.emit();
}

Vector3 MaterialPreview::getLightColour()
Expand All @@ -328,7 +332,18 @@ Vector3 MaterialPreview::getLightColour()

void MaterialPreview::setLightColour(const Vector3& colour)
{
if (!_light) return;

Node_getEntity(_light)->setKeyValue("_color", string::to_string(colour));
_sigLightChanged.emit();
}

void MaterialPreview::resetLightColour()
{
if (!_light) return;

Node_getEntity(_light)->setKeyValue("_color", "");
_sigLightChanged.emit();
}

}
2 changes: 2 additions & 0 deletions radiant/ui/materials/editor/MaterialPreview.h
Expand Up @@ -47,10 +47,12 @@ class MaterialPreview :

void enableFrobHighlight(bool enable);

// Light management
std::string getLightClassname();
void setLightClassname(const std::string& className);
Vector3 getLightColour();
void setLightColour(const Vector3& colour);
void resetLightColour();

sigc::signal<void>& signal_LightChanged();

Expand Down

0 comments on commit c10b873

Please sign in to comment.