Skip to content

Commit

Permalink
#5231: EntitySettings no longer access the UIManager code directly, t…
Browse files Browse the repository at this point in the history
…his is handled by the UserInterfaceModule now.
  • Loading branch information
codereader committed May 18, 2020
1 parent 1330a2f commit e27015b
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 56 deletions.
13 changes: 13 additions & 0 deletions include/ientity.h
Expand Up @@ -317,12 +317,25 @@ class ITargetManager
};
typedef std::shared_ptr<ITargetManager> ITargetManagerPtr;

enum class LightEditVertexType : std::size_t
{
StartEndDeselected,
StartEndSelected,
Inactive,
Deselected,
Selected,
NumberOfVertexTypes,
};

/**
* Global entity settings affecting appearance, render options, etc.
*/
class IEntitySettings
{
public:
virtual const Vector3& getLightVertexColour(LightEditVertexType type) const = 0;
virtual void setLightVertexColour(LightEditVertexType type, const Vector3& value) = 0;

virtual bool getRenderEntityNames() const = 0;
virtual void setRenderEntityNames(bool value) = 0;

Expand Down
22 changes: 8 additions & 14 deletions radiant/entity/EntitySettings.cpp
@@ -1,15 +1,13 @@
#include "EntitySettings.h"

#include "iuimanager.h"

#include "registry/registry.h"
#include "registry/adaptors.h"

namespace entity
{

EntitySettings::EntitySettings() :
_lightVertexColoursLoaded(false)
_lightVertexColours(static_cast<std::size_t>(LightEditVertexType::NumberOfVertexTypes))
{
// Wire up all booleans to update on registry value changes
initialiseAndObserveKey(RKEY_SHOW_ENTITY_NAMES, _renderEntityNames);
Expand All @@ -19,6 +17,13 @@ EntitySettings::EntitySettings() :
initialiseAndObserveKey(RKEY_ALWAYS_SHOW_LIGHT_VERTICES, _alwaysShowLightVertices);
initialiseAndObserveKey(RKEY_FREE_OBJECT_ROTATION, _freeObjectRotation);
initialiseAndObserveKey(RKEY_SHOW_ENTITY_ANGLES, _showEntityAngles);

// Initialise the default colours
_lightVertexColours[static_cast<std::size_t>(LightEditVertexType::StartEndDeselected)] = Vector3(0,1,1);
_lightVertexColours[static_cast<std::size_t>(LightEditVertexType::StartEndSelected)] = Vector3(0,0,1);
_lightVertexColours[static_cast<std::size_t>(LightEditVertexType::Inactive)] = Vector3(1,0,0);
_lightVertexColours[static_cast<std::size_t>(LightEditVertexType::Deselected)] = Vector3(0,1,0);
_lightVertexColours[static_cast<std::size_t>(LightEditVertexType::Selected)] = Vector3(0,0,1);
}

void EntitySettings::initialiseAndObserveKey(const std::string& key, bool& targetBool)
Expand Down Expand Up @@ -53,15 +58,4 @@ void EntitySettings::onSettingsChanged()
_signalSettingsChanged.emit();
}

void EntitySettings::loadLightVertexColours()
{
_lightVertexColoursLoaded = true;

_lightVertexColours[VERTEX_START_END_DESELECTED] = ColourSchemes().getColour("light_startend_deselected");
_lightVertexColours[VERTEX_START_END_SELECTED] = ColourSchemes().getColour("light_startend_selected");
_lightVertexColours[VERTEX_INACTIVE] = ColourSchemes().getColour("light_vertex_normal");
_lightVertexColours[VERTEX_DESELECTED] = ColourSchemes().getColour("light_vertex_deselected");
_lightVertexColours[VERTEX_SELECTED] = ColourSchemes().getColour("light_vertex_selected");
}

} // namespace entity
32 changes: 11 additions & 21 deletions radiant/entity/EntitySettings.h
Expand Up @@ -31,17 +31,6 @@ typedef std::shared_ptr<EntitySettings> EntitySettingsPtr;
class EntitySettings :
public IEntitySettings
{
public:
enum LightEditVertexType
{
VERTEX_START_END_DESELECTED,
VERTEX_START_END_SELECTED,
VERTEX_INACTIVE,
VERTEX_DESELECTED,
VERTEX_SELECTED,
NUM_LIGHT_VERTEX_COLOURS,
};

private:
// TRUE if entity names should be drawn
bool _renderEntityNames;
Expand All @@ -64,9 +53,7 @@ class EntitySettings :
bool _showEntityAngles;

// Cached colour values
Vector3 _lightVertexColours[NUM_LIGHT_VERTEX_COLOURS];

bool _lightVertexColoursLoaded;
std::vector<Vector3> _lightVertexColours;

std::vector<sigc::connection> _registryConnections;

Expand All @@ -75,14 +62,18 @@ class EntitySettings :
// Private constructor
EntitySettings();
public:
const Vector3& getLightVertexColour(LightEditVertexType type)
const Vector3& getLightVertexColour(LightEditVertexType type) const override
{
if (!_lightVertexColoursLoaded)
{
loadLightVertexColours();
}
assert(type != LightEditVertexType::NumberOfVertexTypes);
return _lightVertexColours[static_cast<std::size_t>(type)];
}

void setLightVertexColour(LightEditVertexType type, const Vector3& value) override
{
assert(type != LightEditVertexType::NumberOfVertexTypes);
_lightVertexColours[static_cast<std::size_t>(type)] = value;

return _lightVertexColours[type];
onSettingsChanged();
}

bool getRenderEntityNames() const override
Expand Down Expand Up @@ -176,7 +167,6 @@ class EntitySettings :
private:
void onSettingsChanged();
void initialiseAndObserveKey(const std::string& key, bool& targetBool);
void loadLightVertexColours();
};

} // namespace entity
19 changes: 9 additions & 10 deletions radiant/entity/light/LightNode.cpp
Expand Up @@ -317,10 +317,10 @@ void LightNode::renderComponents(RenderableCollector& collector, const VolumeTes

EntitySettings& settings = *EntitySettings::InstancePtr();

const Vector3& colourStartEndSelected = settings.getLightVertexColour(EntitySettings::VERTEX_START_END_SELECTED);
const Vector3& colourStartEndDeselected = settings.getLightVertexColour(EntitySettings::VERTEX_START_END_DESELECTED);
const Vector3& colourVertexSelected = settings.getLightVertexColour(EntitySettings::VERTEX_SELECTED);
const Vector3& colourVertexDeselected = settings.getLightVertexColour(EntitySettings::VERTEX_DESELECTED);
const Vector3& colourStartEndSelected = settings.getLightVertexColour(LightEditVertexType::StartEndSelected);
const Vector3& colourStartEndDeselected = settings.getLightVertexColour(LightEditVertexType::StartEndDeselected);
const Vector3& colourVertexSelected = settings.getLightVertexColour(LightEditVertexType::Selected);
const Vector3& colourVertexDeselected = settings.getLightVertexColour(LightEditVertexType::Deselected);

// Update the colour of the light center dot
const_cast<Light&>(_light).colourLightTarget() = (_lightTargetInstance.isSelected()) ? colourVertexSelected : colourVertexDeselected;
Expand All @@ -341,13 +341,13 @@ void LightNode::renderComponents(RenderableCollector& collector, const VolumeTes
if (_lightCenterInstance.isSelected())
{
const_cast<Light&>(_light).getDoom3Radius().setCenterColour(
EntitySettings::InstancePtr()->getLightVertexColour(EntitySettings::VERTEX_SELECTED));
EntitySettings::InstancePtr()->getLightVertexColour(LightEditVertexType::Selected));
_light.renderLightCentre(collector, volume, localToWorld());
}
else
{
const_cast<Light&>(_light).getDoom3Radius().setCenterColour(
EntitySettings::InstancePtr()->getLightVertexColour(EntitySettings::VERTEX_DESELECTED));
EntitySettings::InstancePtr()->getLightVertexColour(LightEditVertexType::Deselected));
_light.renderLightCentre(collector, volume, localToWorld());
}
}
Expand All @@ -365,8 +365,8 @@ void LightNode::renderInactiveComponents(RenderableCollector& collector, const V
if (_light.isProjected())
{
EntitySettings& settings = *EntitySettings::InstancePtr();
const Vector3& colourStartEndInactive = settings.getLightVertexColour(EntitySettings::VERTEX_START_END_DESELECTED);
const Vector3& colourVertexInactive = settings.getLightVertexColour(EntitySettings::VERTEX_DESELECTED);
const Vector3& colourStartEndInactive = settings.getLightVertexColour(LightEditVertexType::StartEndDeselected);
const Vector3& colourVertexInactive = settings.getLightVertexColour(LightEditVertexType::Deselected);

const_cast<Light&>(_light).colourLightStart() = colourStartEndInactive;
const_cast<Light&>(_light).colourLightEnd() = colourStartEndInactive;
Expand All @@ -379,8 +379,7 @@ void LightNode::renderInactiveComponents(RenderableCollector& collector, const V
}
else
{
const Vector3& colourVertexInactive = EntitySettings::InstancePtr()->getLightVertexColour(
EntitySettings::VERTEX_INACTIVE);
const Vector3& colourVertexInactive = EntitySettings::InstancePtr()->getLightVertexColour(LightEditVertexType::Inactive);

const_cast<Light&>(_light).getDoom3Radius().setCenterColour(colourVertexInactive);
_light.renderLightCentre(collector, volume, localToWorld());
Expand Down
32 changes: 29 additions & 3 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -36,6 +36,7 @@
#include "textool/TexTool.h"
#include "modelexport/ExportAsModelDialog.h"
#include "ui/filters/FilterOrthoContextMenuItem.h"
#include "uimanager/colourscheme/ColourSchemeEditor.h"

namespace ui
{
Expand Down Expand Up @@ -130,19 +131,44 @@ void UserInterfaceModule::initialiseModule(const ApplicationContext& ctx)
_eClassColourManager.reset(new EntityClassColourManager);
_longOperationHandler.reset(new LongRunningOperationHandler);

_entitySettingsConn = GlobalEntityModule().getSettings().signal_settingsChanged().connect(
[]() { GlobalMainFrame().updateAllWindows(); }
);
initialiseEntitySettings();
}

void UserInterfaceModule::shutdownModule()
{
_coloursUpdatedConn.disconnect();
_entitySettingsConn.disconnect();

_longOperationHandler.reset();
_eClassColourManager.reset();
}

void UserInterfaceModule::initialiseEntitySettings()
{
auto& settings = GlobalEntityModule().getSettings();

_entitySettingsConn = settings.signal_settingsChanged().connect(
[]() { GlobalMainFrame().updateAllWindows(); }
);

applyEntityVertexColours();

_coloursUpdatedConn = ColourSchemeEditor::signal_ColoursChanged().connect(
sigc::mem_fun(this, &UserInterfaceModule::applyEntityVertexColours)
);
}

void UserInterfaceModule::applyEntityVertexColours()
{
auto& settings = GlobalEntityModule().getSettings();

settings.setLightVertexColour(LightEditVertexType::StartEndDeselected, ColourSchemes().getColour("light_startend_deselected"));
settings.setLightVertexColour(LightEditVertexType::StartEndSelected, ColourSchemes().getColour("light_startend_selected"));
settings.setLightVertexColour(LightEditVertexType::Inactive, ColourSchemes().getColour("light_vertex_normal"));
settings.setLightVertexColour(LightEditVertexType::Deselected, ColourSchemes().getColour("light_vertex_deselected"));
settings.setLightVertexColour(LightEditVertexType::Selected, ColourSchemes().getColour("light_vertex_selected"));
}

void UserInterfaceModule::refreshShadersCmd(const cmd::ArgumentList& args)
{
// Disable screen updates for the scope of this function
Expand Down
3 changes: 3 additions & 0 deletions radiant/ui/UserInterfaceModule.h
Expand Up @@ -27,6 +27,7 @@ class UserInterfaceModule :
std::unique_ptr<LongRunningOperationHandler> _longOperationHandler;

sigc::connection _entitySettingsConn;
sigc::connection _coloursUpdatedConn;

public:
// RegisterableModule
Expand All @@ -37,6 +38,8 @@ class UserInterfaceModule :

private:
void registerUICommands();
void initialiseEntitySettings();
void applyEntityVertexColours();
void refreshShadersCmd(const cmd::ArgumentList& args);
};

Expand Down
14 changes: 11 additions & 3 deletions radiant/uimanager/colourscheme/ColourSchemeEditor.cpp
Expand Up @@ -208,6 +208,8 @@ void ColourSchemeEditor::updateColourSelectors()

void ColourSchemeEditor::updateWindows()
{
signal_ColoursChanged().emit();

// Call the update, so all colours can be previewed
GlobalMainFrame().updateAllWindows();
SceneChangeNotify();
Expand Down Expand Up @@ -335,11 +337,11 @@ int ColourSchemeEditor::ShowModal()
{
// Restore all the colour settings from the XMLRegistry, changes get lost
ColourSchemeManager::Instance().restoreColourSchemes();

// Call the update, so all restored colours are displayed
updateWindows();
}

// Call the update, so all colours are displayed
updateWindows();

return returnCode;
}

Expand All @@ -350,4 +352,10 @@ void ColourSchemeEditor::DisplayDialog(const cmd::ArgumentList& args)
editor->Destroy();
}

sigc::signal<void>& ColourSchemeEditor::signal_ColoursChanged()
{
static sigc::signal<void> _signal;
return _signal;
}

} // namespace ui
8 changes: 3 additions & 5 deletions radiant/uimanager/colourscheme/ColourSchemeEditor.h
Expand Up @@ -54,10 +54,12 @@ class ColourSchemeEditor :

int ShowModal();

// Signal for client code to get notified on colour changes
static sigc::signal<void>& signal_ColoursChanged();

private:
// private helper functions
void populateTree();
void createTreeView();
void constructWindow();
wxSizer* constructColourSelector(ColourItem& colour, const std::string& name);
void updateColourSelectors();
Expand Down Expand Up @@ -88,10 +90,6 @@ class ColourSchemeEditor :
void callbackDelete(wxCommandEvent& ev);
void callbackCopy(wxCommandEvent& ev);

// Destroy window and delete self, called by both Cancel and window
// delete callbacks
void doCancel();

// Updates the windows after a colour change
static void updateWindows();
};
Expand Down

0 comments on commit e27015b

Please sign in to comment.