diff --git a/include/ientity.h b/include/ientity.h index be6c4b5869..36fa2e13c6 100644 --- a/include/ientity.h +++ b/include/ientity.h @@ -317,12 +317,25 @@ class ITargetManager }; typedef std::shared_ptr 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; diff --git a/radiant/entity/EntitySettings.cpp b/radiant/entity/EntitySettings.cpp index 48c7bcb82f..445f3aa81f 100644 --- a/radiant/entity/EntitySettings.cpp +++ b/radiant/entity/EntitySettings.cpp @@ -1,7 +1,5 @@ #include "EntitySettings.h" -#include "iuimanager.h" - #include "registry/registry.h" #include "registry/adaptors.h" @@ -9,7 +7,7 @@ namespace entity { EntitySettings::EntitySettings() : - _lightVertexColoursLoaded(false) + _lightVertexColours(static_cast(LightEditVertexType::NumberOfVertexTypes)) { // Wire up all booleans to update on registry value changes initialiseAndObserveKey(RKEY_SHOW_ENTITY_NAMES, _renderEntityNames); @@ -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(LightEditVertexType::StartEndDeselected)] = Vector3(0,1,1); + _lightVertexColours[static_cast(LightEditVertexType::StartEndSelected)] = Vector3(0,0,1); + _lightVertexColours[static_cast(LightEditVertexType::Inactive)] = Vector3(1,0,0); + _lightVertexColours[static_cast(LightEditVertexType::Deselected)] = Vector3(0,1,0); + _lightVertexColours[static_cast(LightEditVertexType::Selected)] = Vector3(0,0,1); } void EntitySettings::initialiseAndObserveKey(const std::string& key, bool& targetBool) @@ -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 diff --git a/radiant/entity/EntitySettings.h b/radiant/entity/EntitySettings.h index 265f6ede25..2e07c4f037 100644 --- a/radiant/entity/EntitySettings.h +++ b/radiant/entity/EntitySettings.h @@ -31,17 +31,6 @@ typedef std::shared_ptr 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; @@ -64,9 +53,7 @@ class EntitySettings : bool _showEntityAngles; // Cached colour values - Vector3 _lightVertexColours[NUM_LIGHT_VERTEX_COLOURS]; - - bool _lightVertexColoursLoaded; + std::vector _lightVertexColours; std::vector _registryConnections; @@ -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(type)]; + } + + void setLightVertexColour(LightEditVertexType type, const Vector3& value) override + { + assert(type != LightEditVertexType::NumberOfVertexTypes); + _lightVertexColours[static_cast(type)] = value; - return _lightVertexColours[type]; + onSettingsChanged(); } bool getRenderEntityNames() const override @@ -176,7 +167,6 @@ class EntitySettings : private: void onSettingsChanged(); void initialiseAndObserveKey(const std::string& key, bool& targetBool); - void loadLightVertexColours(); }; } // namespace entity diff --git a/radiant/entity/light/LightNode.cpp b/radiant/entity/light/LightNode.cpp index f294e2866b..6357efebef 100644 --- a/radiant/entity/light/LightNode.cpp +++ b/radiant/entity/light/LightNode.cpp @@ -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).colourLightTarget() = (_lightTargetInstance.isSelected()) ? colourVertexSelected : colourVertexDeselected; @@ -341,13 +341,13 @@ void LightNode::renderComponents(RenderableCollector& collector, const VolumeTes if (_lightCenterInstance.isSelected()) { const_cast(_light).getDoom3Radius().setCenterColour( - EntitySettings::InstancePtr()->getLightVertexColour(EntitySettings::VERTEX_SELECTED)); + EntitySettings::InstancePtr()->getLightVertexColour(LightEditVertexType::Selected)); _light.renderLightCentre(collector, volume, localToWorld()); } else { const_cast(_light).getDoom3Radius().setCenterColour( - EntitySettings::InstancePtr()->getLightVertexColour(EntitySettings::VERTEX_DESELECTED)); + EntitySettings::InstancePtr()->getLightVertexColour(LightEditVertexType::Deselected)); _light.renderLightCentre(collector, volume, localToWorld()); } } @@ -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).colourLightStart() = colourStartEndInactive; const_cast(_light).colourLightEnd() = colourStartEndInactive; @@ -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).getDoom3Radius().setCenterColour(colourVertexInactive); _light.renderLightCentre(collector, volume, localToWorld()); diff --git a/radiant/ui/UserInterfaceModule.cpp b/radiant/ui/UserInterfaceModule.cpp index a3499202c1..26f6dad22e 100644 --- a/radiant/ui/UserInterfaceModule.cpp +++ b/radiant/ui/UserInterfaceModule.cpp @@ -36,6 +36,7 @@ #include "textool/TexTool.h" #include "modelexport/ExportAsModelDialog.h" #include "ui/filters/FilterOrthoContextMenuItem.h" +#include "uimanager/colourscheme/ColourSchemeEditor.h" namespace ui { @@ -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 diff --git a/radiant/ui/UserInterfaceModule.h b/radiant/ui/UserInterfaceModule.h index 2779f2b958..1236ea08c6 100644 --- a/radiant/ui/UserInterfaceModule.h +++ b/radiant/ui/UserInterfaceModule.h @@ -27,6 +27,7 @@ class UserInterfaceModule : std::unique_ptr _longOperationHandler; sigc::connection _entitySettingsConn; + sigc::connection _coloursUpdatedConn; public: // RegisterableModule @@ -37,6 +38,8 @@ class UserInterfaceModule : private: void registerUICommands(); + void initialiseEntitySettings(); + void applyEntityVertexColours(); void refreshShadersCmd(const cmd::ArgumentList& args); }; diff --git a/radiant/uimanager/colourscheme/ColourSchemeEditor.cpp b/radiant/uimanager/colourscheme/ColourSchemeEditor.cpp index d8b807a606..a01f4f1ac6 100644 --- a/radiant/uimanager/colourscheme/ColourSchemeEditor.cpp +++ b/radiant/uimanager/colourscheme/ColourSchemeEditor.cpp @@ -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(); @@ -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; } @@ -350,4 +352,10 @@ void ColourSchemeEditor::DisplayDialog(const cmd::ArgumentList& args) editor->Destroy(); } +sigc::signal& ColourSchemeEditor::signal_ColoursChanged() +{ + static sigc::signal _signal; + return _signal; +} + } // namespace ui diff --git a/radiant/uimanager/colourscheme/ColourSchemeEditor.h b/radiant/uimanager/colourscheme/ColourSchemeEditor.h index 293482b45c..106ef3dc31 100644 --- a/radiant/uimanager/colourscheme/ColourSchemeEditor.h +++ b/radiant/uimanager/colourscheme/ColourSchemeEditor.h @@ -54,10 +54,12 @@ class ColourSchemeEditor : int ShowModal(); + // Signal for client code to get notified on colour changes + static sigc::signal& signal_ColoursChanged(); + private: // private helper functions void populateTree(); - void createTreeView(); void constructWindow(); wxSizer* constructColourSelector(ColourItem& colour, const std::string& name); void updateColourSelectors(); @@ -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(); };