1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#include "BrushModule.h"
#include "i18n.h"
#include "iradiant.h"
#include "itextstream.h"
#include "ifilter.h"
#include "igame.h"
#include "ilayer.h"
#include "brush/BrushNode.h"
#include "brush/BrushClipPlane.h"
#include "brush/BrushVisit.h"
#include "gamelib.h"
#include "selectionlib.h"
#include "registry/registry.h"
#include "ipreferencesystem.h"
#include "module/StaticModule.h"
#include "messages/TextureChanged.h"
#include "selection/algorithm/Primitives.h"
// ---------------------------------------------------------------------------------------
namespace brush
{
void BrushModuleImpl::constructPreferences()
{
// Add a page to the given group
IPreferencePage& page = GlobalPreferenceSystem().getPage(_("Settings/Primitives"));
// Add the default texture scale preference and connect it to the according registryKey
// Note: this should be moved somewhere else, I think
page.appendEntry(_("Default texture scale"), "user/ui/textures/defaultTextureScale");
// The checkbox to enable/disable the texture lock option
page.appendCheckBox(_("Enable Texture Lock (for Brushes)"), "user/ui/brush/textureLock");
}
void BrushModuleImpl::construct()
{
registerBrushCommands();
Brush::m_maxWorldCoord = game::current::getValue<float>("/defaults/maxWorldCoord");
}
void BrushModuleImpl::destroy()
{
Brush::m_maxWorldCoord = 0;
}
void BrushModuleImpl::keyChanged()
{
_textureLockEnabled = registry::getValue<bool>(RKEY_ENABLE_TEXTURE_LOCK);
}
bool BrushModuleImpl::textureLockEnabled() const {
return _textureLockEnabled;
}
void BrushModuleImpl::setTextureLock(bool enabled)
{
registry::setValue(RKEY_ENABLE_TEXTURE_LOCK, enabled);
}
void BrushModuleImpl::toggleTextureLock() {
setTextureLock(!textureLockEnabled());
}
// ------------ BrushCreator implementation --------------------------------------------
scene::INodePtr BrushModuleImpl::createBrush()
{
scene::INodePtr node = std::make_shared<BrushNode>();
if (GlobalMapModule().getRoot())
{
// All brushes are created in the active layer by default
node->moveToLayer(GlobalMapModule().getRoot()->getLayerManager().getActiveLayer());
}
return node;
}
IBrushSettings& BrushModuleImpl::getSettings()
{
return *_settings;
}
// RegisterableModule implementation
const std::string& BrushModuleImpl::getName() const {
static std::string _name(MODULE_BRUSHCREATOR);
return _name;
}
const StringSet& BrushModuleImpl::getDependencies() const {
static StringSet _dependencies;
if (_dependencies.empty()) {
_dependencies.insert(MODULE_GAMEMANAGER);
_dependencies.insert(MODULE_XMLREGISTRY);
_dependencies.insert(MODULE_PREFERENCESYSTEM);
}
return _dependencies;
}
void BrushModuleImpl::initialiseModule(const IApplicationContext& ctx) {
construct();
_settings.reset(new BrushSettings);
_textureLockEnabled = registry::getValue<bool>(RKEY_ENABLE_TEXTURE_LOCK);
GlobalRegistry().signalForKey(RKEY_ENABLE_TEXTURE_LOCK).connect(
sigc::mem_fun(this, &BrushModuleImpl::keyChanged)
);
// add the preference settings
constructPreferences();
// Set up the link to send TextureChangedMessages
_brushFaceShaderChanged = Brush::signal_faceShaderChanged().connect(
[] { radiant::TextureChangedMessage::Send(); });
_faceTexDefChanged = Face::signal_texdefChanged().connect(
[] { radiant::TextureChangedMessage::Send(); });
}
void BrushModuleImpl::shutdownModule()
{
rMessage() << "BrushModuleImpl::shutdownModule called." << std::endl;
_brushFaceShaderChanged.disconnect();
_faceTexDefChanged.disconnect();
destroy();
}
void BrushModuleImpl::registerBrushCommands()
{
GlobalCommandSystem().addCommand("BrushMakePrefab", selection::algorithm::brushMakePrefab, { cmd::ARGTYPE_INT, cmd::ARGTYPE_INT | cmd::ARGTYPE_OPTIONAL });
GlobalCommandSystem().addCommand("BrushMakeSided", selection::algorithm::brushMakeSided, { cmd::ARGTYPE_INT });
GlobalCommandSystem().addCommand("TextureNatural", selection::algorithm::naturalTexture);
GlobalCommandSystem().addWithCheck("MakeVisportal",
cmd::noArgs(selection::algorithm::makeVisportal),
selection::pred::haveBrush);
GlobalCommandSystem().addCommand("SurroundWithMonsterclip", selection::algorithm::surroundWithMonsterclip);
GlobalCommandSystem().addCommand("ResizeSelectedBrushesToBounds", selection::algorithm::resizeSelectedBrushesToBounds,
{ cmd::ARGTYPE_VECTOR3, cmd::ARGTYPE_VECTOR3, cmd::ARGTYPE_STRING });
}
// -------------------------------------------------------------------------------------
// Define a static BrushModule
module::StaticModuleRegistration<BrushModuleImpl> staticBrushModule;
}
// greebo: The accessor function for the brush module containing the static instance
brush::BrushModuleImpl& GlobalBrush()
{
return *std::static_pointer_cast<brush::BrushModuleImpl>(
module::GlobalModuleRegistry().getModule(MODULE_BRUSHCREATOR)
);
}
|