Skip to content

Commit

Permalink
#5430: Apply entity class colours each time the colour schemes are ch…
Browse files Browse the repository at this point in the history
…anged or loaded.
  • Loading branch information
codereader committed Nov 24, 2020
1 parent 1994e93 commit 77ebdae
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/ieclasscolours.h
Expand Up @@ -34,6 +34,9 @@ class IColourManager :

// Removes the override colour for the given entity class
virtual void removeOverrideColour(const std::string& eclass) = 0;

// Removes all registered overrides
virtual void clearOverrideColours() = 0;
};

}
Expand Down
5 changes: 5 additions & 0 deletions radiantcore/eclass/EClassColourManager.cpp
Expand Up @@ -39,6 +39,11 @@ void EClassColourManager::removeOverrideColour(const std::string& eclass)
_overrides.erase(eclass);
}

void EClassColourManager::clearOverrideColours()
{
_overrides.clear();
}

const std::string& EClassColourManager::getName() const
{
static std::string _name(MODULE_ECLASS_COLOUR_MANAGER);
Expand Down
1 change: 1 addition & 0 deletions radiantcore/eclass/EClassColourManager.h
Expand Up @@ -19,6 +19,7 @@ class EClassColourManager :
void applyColours(const IEntityClassPtr& eclass) override;
void foreachOverrideColour(const std::function<void(const std::string&, const Vector3&)>& functor) override;
void removeOverrideColour(const std::string& eclass) override;
void clearOverrideColours() override;

// RegisterableModule implementation

Expand Down
18 changes: 16 additions & 2 deletions radiantcore/settings/ColourSchemeManager.cpp
@@ -1,6 +1,7 @@
#include "ColourSchemeManager.h"
#include "iregistry.h"
#include "itextstream.h"
#include "ieclasscolours.h"

#include "module/StaticModule.h"

Expand Down Expand Up @@ -122,6 +123,8 @@ void ColourSchemeManager::saveColourSchemes()
// Flush the whole colour scheme structure and re-load it from the registry.
// This is to remove any remaining artifacts.
restoreColourSchemes();

emitEclassOverrides();
}

void ColourSchemeManager::loadColourSchemes()
Expand Down Expand Up @@ -209,6 +212,7 @@ const StringSet& ColourSchemeManager::getDependencies() const
if (_dependencies.empty())
{
_dependencies.insert(MODULE_XMLREGISTRY);
_dependencies.insert(MODULE_ECLASS_COLOUR_MANAGER);
}

return _dependencies;
Expand All @@ -219,10 +223,20 @@ void ColourSchemeManager::initialiseModule(const IApplicationContext& ctx)
rMessage() << getName() << "::initialiseModule called." << std::endl;

loadColourSchemes();
emitEclassOverrides();
}

void ColourSchemeManager::shutdownModule()
{}
void ColourSchemeManager::emitEclassOverrides()
{
auto& colourManager = GlobalEclassColourManager();
colourManager.clearOverrideColours();

// Apply the overrides for the known entity classes
auto& activeScheme = getActiveScheme();

colourManager.addOverrideColour("worldspawn", activeScheme.getColour("default_brush").getColour());
colourManager.addOverrideColour("light", activeScheme.getColour("light_volumes").getColour());
}

module::StaticModule<ColourSchemeManager> colourSchemeManagerModule;

Expand Down
2 changes: 1 addition & 1 deletion radiantcore/settings/ColourSchemeManager.h
Expand Up @@ -47,10 +47,10 @@ class ColourSchemeManager :
const std::string& getName() const override;
const StringSet& getDependencies() const override;
void initialiseModule(const IApplicationContext& ctx) override;
void shutdownModule() override;

private:
void saveScheme(const std::string& name);
void emitEclassOverrides();
};

} // namespace
2 changes: 1 addition & 1 deletion test/WorldspawnColour.cpp
Expand Up @@ -100,7 +100,7 @@ TEST_F(Quake4WorldspawnColourTest, SchemeBrushColourIsUsed)
TEST_F(RadiantTest, SchemeBrushColourIsUsed)
{
// This setup does have a worldspawn
EXPECT_TRUE(GlobalEntityClassManager().findClass("worldspawn"));
EXPECT_TRUE(GlobalEntityClassManager().findOrInsert("worldspawn", true));

// Create a worldspawn
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
Expand Down

0 comments on commit 77ebdae

Please sign in to comment.