Skip to content

Commit

Permalink
#5231: Add NotificationMessage type to be sent to the UI. Start refac…
Browse files Browse the repository at this point in the history
…toring the selection::algorithm::Primitives file.
  • Loading branch information
codereader committed May 29, 2020
1 parent 0589d2c commit c118ba4
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 36 deletions.
35 changes: 35 additions & 0 deletions libs/messages/NotificationMessage.h
@@ -0,0 +1,35 @@
#pragma once

#include "imessagebus.h"
#include "iradiant.h"

namespace radiant
{

/**
* Message object sent to the MessageBus to notify about something.
*/
class NotificationMessage :
public IMessage
{
private:
std::string _message;
public:
NotificationMessage(const std::string& message) :
_message(message)
{}

const std::string& getMessage() const
{
return _message;
}

// Convenience method, creating an instance and dispatching it to the message bus
static void Send(const std::string& message)
{
NotificationMessage msg(message);
GlobalRadiantCore().getMessageBus().sendMessage(msg);
}
};

}
12 changes: 12 additions & 0 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -155,6 +155,9 @@ void UserInterfaceModule::initialiseModule(const ApplicationContext& ctx)
_textureChangedListener = GlobalRadiantCore().getMessageBus().addListener(
radiant::TypeListener(UserInterfaceModule::HandleTextureChanged));

_notificationListener = GlobalRadiantCore().getMessageBus().addListener(
radiant::TypeListener(UserInterfaceModule::HandleNotificationMessage));

// Initialise the AAS UI
AasControlDialog::Init();

Expand All @@ -165,6 +168,7 @@ void UserInterfaceModule::shutdownModule()
{
GlobalRadiantCore().getMessageBus().removeListener(_textureChangedListener);
GlobalRadiantCore().getMessageBus().removeListener(_execFailedListener);
GlobalRadiantCore().getMessageBus().removeListener(_notificationListener);

_coloursUpdatedConn.disconnect();
_entitySettingsConn.disconnect();
Expand All @@ -182,6 +186,14 @@ void UserInterfaceModule::handleCommandExecutionFailure(radiant::CommandExecutio
wxutil::Messagebox::ShowError(msg.getMessage(), parentWindow);
}

void UserInterfaceModule::HandleNotificationMessage(radiant::NotificationMessage& msg)
{
auto parentWindow = module::GlobalModuleRegistry().moduleExists(MODULE_MAINFRAME) ?
GlobalMainFrame().getWxTopLevelWindow() : nullptr;

wxutil::Messagebox::Show(_("Notification"), msg.getMessage(), IDialog::MessageType::MESSAGE_CONFIRM, parentWindow);
}

void UserInterfaceModule::initialiseEntitySettings()
{
auto& settings = GlobalEntityModule().getSettings();
Expand Down
3 changes: 3 additions & 0 deletions radiant/ui/UserInterfaceModule.h
Expand Up @@ -11,6 +11,7 @@
#include "MapFileProgressHandler.h"
#include "messages/CommandExecutionFailed.h"
#include "messages/TextureChanged.h"
#include "messages/NotificationMessage.h"

namespace ui
{
Expand All @@ -35,6 +36,7 @@ class UserInterfaceModule :

std::size_t _execFailedListener;
std::size_t _textureChangedListener;
std::size_t _notificationListener;

public:
// RegisterableModule
Expand All @@ -53,6 +55,7 @@ class UserInterfaceModule :

void handleCommandExecutionFailure(radiant::CommandExecutionFailedMessage& msg);
static void HandleTextureChanged(radiant::TextureChangedMessage& msg);
static void HandleNotificationMessage(radiant::NotificationMessage& msg);
};

}
5 changes: 5 additions & 0 deletions radiant/xyview/tools/BrushCreatorTool.cpp
Expand Up @@ -8,6 +8,7 @@
#include "selectionlib.h"
#include "selection/algorithm/Primitives.h"
#include "ui/texturebrowser/TextureBrowser.h"
#include "command/ExecutionNotPossible.h"
#include "map/Map.h"
#include "XYMouseToolEvent.h"

Expand Down Expand Up @@ -115,6 +116,10 @@ MouseTool::Result BrushCreatorTool::onMouseMove(Event& ev)
GlobalTextureBrowser().getSelectedShader()
);
}
catch (cmd::ExecutionNotPossible & ex)
{
return Result::Ignored;
}
catch (std::bad_cast&)
{
return Result::Ignored;
Expand Down
63 changes: 34 additions & 29 deletions radiantcore/selection/algorithm/Primitives.cpp
Expand Up @@ -8,29 +8,29 @@
#include "itextstream.h"
#include "iundo.h"
#include "igame.h"
#include "imainframe.h"
#include "iorthoview.h"

#include "brush/BrushModule.h"
#include "brush/BrushVisit.h"
#include "patch/PatchSceneWalk.h"
#include "patch/PatchNode.h"
#include "string/string.h"
#include "brush/export/CollisionModel.h"
#include "wxutil/dialog/MessageBox.h"
#include "map/Map.h"
#include "os/fs.h"
#include "gamelib.h"
#include "ui/modelselector/ModelSelector.h"
#include "ui/texturebrowser/TextureBrowser.h"
#include "ui/brush/QuerySidesDialog.h"
#include "selection/shaderclipboard/ShaderClipboard.h"
#include "scenelib.h"
#include "selectionlib.h"
#include "command/ExecutionFailure.h"
#include "command/ExecutionNotPossible.h"
#include "messages/NotificationMessage.h"

#include "string/case_conv.h"
#include <fmt/format.h>

#include "ModelFinder.h"
#include "xyview/GlobalXYWnd.h"

namespace selection
{
Expand All @@ -45,9 +45,9 @@ namespace
const char* const GKEY_VISPORTAL_SHADER = "/defaults/visportalShader";
const char* const GKEY_MONSTERCLIP_SHADER = "/defaults/monsterClipShader";

const std::string ERRSTR_WRONG_SELECTION =
"Can't export, create and select a func_* entity\
containing the collision hull primitives.";
const char* const ERRSTR_WRONG_SELECTION =
N_("Can't export, create and select a func_* entity\
containing the collision hull primitives.");
}

void forEachSelectedFaceComponent(const std::function<void(Face&)>& functor)
Expand Down Expand Up @@ -135,7 +135,8 @@ void createCMFromSelection(const cmd::ArgumentList& args) {
// Check the current selection state
const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo();

if (info.totalCount == info.entityCount && info.totalCount == 1) {
if (info.totalCount == info.entityCount && info.totalCount == 1)
{
// Retrieve the node, instance and entity
const scene::INodePtr& entityNode = GlobalSelectionSystem().ultimateSelected();

Expand Down Expand Up @@ -192,11 +193,12 @@ void createCMFromSelection(const cmd::ArgumentList& args) {
rMessage() << "CollisionModel saved to " << cmPath.string() << std::endl;
}
else {
wxutil::Messagebox::ShowError(
fmt::format("Couldn't save to file: {0}", cmPath.string()));
throw cmd::ExecutionFailure(
fmt::format(_("Couldn't save to file: {0}"), cmPath.string()));
}
}
catch (const fs::filesystem_error& f) {
catch (const fs::filesystem_error& f)
{
rError() << "CollisionModel: " << f.what() << std::endl;
}

Expand All @@ -210,9 +212,9 @@ void createCMFromSelection(const cmd::ArgumentList& args) {
Node_setSelected(entityNode, true);
}
}
else {
wxutil::Messagebox::ShowError(
_(ERRSTR_WRONG_SELECTION.c_str()));
else
{
throw cmd::ExecutionNotPossible(_(ERRSTR_WRONG_SELECTION));
}
}

Expand All @@ -239,8 +241,9 @@ class DecalPatchCreator
// Create a new decal patch
scene::INodePtr patchNode = GlobalPatchModule().createPatch(patch::PatchDefType::Def3);

if (patchNode == NULL) {
wxutil::Messagebox::ShowError(_("Could not create patch."));
if (patchNode == NULL)
{
throw cmd::ExecutionFailure(_("Could not create patch."));
return;
}

Expand Down Expand Up @@ -320,7 +323,7 @@ class DecalPatchCreator
patch->FlipTexture(1);

// Insert the patch into worldspawn
scene::INodePtr worldSpawnNode = GlobalMap().findOrInsertWorldspawn();
scene::INodePtr worldSpawnNode = GlobalMapModule().findOrInsertWorldspawn();
assert(worldSpawnNode); // This must be non-NULL, otherwise we won't have faces

worldSpawnNode->addChildNode(patchNode);
Expand Down Expand Up @@ -354,11 +357,12 @@ class DecalPatchCreator
}
};

void createDecalsForSelectedFaces(const cmd::ArgumentList& args) {
void createDecalsForSelectedFaces(const cmd::ArgumentList& args)
{
// Sanity check
if (FaceInstance::Selection().empty())
{
wxutil::Messagebox::ShowError(_("No faces selected."));
throw cmd::ExecutionNotPossible(_("No faces selected."));
return;
}

Expand All @@ -377,8 +381,9 @@ void createDecalsForSelectedFaces(const cmd::ArgumentList& args) {
// Check how many faces were not suitable
int unsuitableWindings = creator.getNumUnsuitableWindings();

if (unsuitableWindings > 0) {
wxutil::Messagebox::ShowError(
if (unsuitableWindings > 0)
{
radiant::NotificationMessage::Send(
fmt::format(_("{0:d} faces were not suitable (had more than 4 vertices)."), unsuitableWindings)
);
}
Expand All @@ -390,7 +395,7 @@ void makeVisportal(const cmd::ArgumentList& args)

if (brushes.size() <= 0)
{
wxutil::Messagebox::ShowError(_("No brushes selected."));
throw cmd::ExecutionNotPossible(_("No brushes selected."));
return;
}

Expand Down Expand Up @@ -466,7 +471,7 @@ void surroundWithMonsterclip(const cmd::ArgumentList& args)
brushNode->assignToLayers(model->getLayers());

if (brushNode != NULL) {
scene::addNodeToContainer(brushNode, GlobalMap().findOrInsertWorldspawn());
scene::addNodeToContainer(brushNode, GlobalMapModule().findOrInsertWorldspawn());

Brush* theBrush = Node_getBrush(brushNode);

Expand All @@ -487,7 +492,7 @@ void resizeBrushesToBounds(const AABB& aabb, const std::string& shader)
{
if (GlobalSelectionSystem().getSelectionInfo().brushCount == 0)
{
wxutil::Messagebox::ShowError(_("No brushes selected."));
throw cmd::ExecutionNotPossible(_("No brushes selected."));
return;
}

Expand All @@ -501,7 +506,7 @@ void resizeBrushesToBounds(const AABB& aabb, const std::string& shader)

int GetViewAxis()
{
switch(GlobalXYWnd().getActiveViewType())
switch(GlobalXYWndManager().getActiveViewType())
{
case XY:
return 2;
Expand Down Expand Up @@ -587,7 +592,7 @@ void brushMakePrefab(const cmd::ArgumentList& args)
if (GlobalSelectionSystem().getSelectionInfo().brushCount == 0)
{
// Display a modal error dialog
wxutil::Messagebox::ShowError(_("At least one brush must be selected for this operation."));
throw cmd::ExecutionNotPossible(_("At least one brush must be selected for this operation."));
return;
}

Expand All @@ -602,7 +607,7 @@ void brushMakePrefab(const cmd::ArgumentList& args)
int minSides = 3;
int maxSides = static_cast<int>(Brush::PRISM_MAX_SIDES);

const std::string& shader = GlobalTextureBrowser().getSelectedShader();
const std::string& shader = GlobalShaderClipboard().getSource().getShader();

switch (type)
{
Expand Down Expand Up @@ -664,7 +669,7 @@ void brushMakeSided(const cmd::ArgumentList& args)
}

std::size_t numSides = static_cast<std::size_t>(input);
constructBrushPrefabs(eBrushPrism, numSides, GlobalTextureBrowser().getSelectedShader());
constructBrushPrefabs(eBrushPrism, numSides, GlobalShaderClipboard().getSource().getShader());
}

void brushSetDetailFlag(const cmd::ArgumentList& args)
Expand Down
7 changes: 0 additions & 7 deletions radiantcore/selection/algorithm/Primitives.h
Expand Up @@ -124,13 +124,6 @@ namespace selection {
*/
void resizeBrushesToBounds(const AABB& aabb, const std::string& shader);

/**
* Construct a defined brush prefab type out of the given brush.
*/
void constructBrushPrefab(Brush& brush, EBrushPrefab type, const AABB& bounds,
std::size_t sides, const std::string& shader,
const TextureProjection& projection);

/**
* Constructs a prefab of the given brush type, for each selected brush.
* The given number of sides and the given shader are assigned to the newly designed brush.
Expand Down

0 comments on commit c118ba4

Please sign in to comment.