Skip to content

Commit

Permalink
#401: Stitch Patch Textures disabled without selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mott committed Aug 10, 2022
1 parent 22851ca commit ca5609c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
9 changes: 8 additions & 1 deletion libs/selectionlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ inline void assignNodeToSelectionGroups(const scene::INodePtr& node, const IGrou
namespace pred
{
/// Return true if there is at least one selected brush
inline bool haveSelectedBrush()
inline bool haveBrush()
{
return GlobalSelectionSystem().getSelectionInfo().brushCount > 0;
}
Expand All @@ -253,6 +253,13 @@ namespace pred
return info.totalCount == n && info.entityCount == n;
}

/// Return true if the exact given number of patches are selected (and nothing else)
inline bool havePatchesExact(int n)
{
const auto& info = GlobalSelectionSystem().getSelectionInfo();
return info.totalCount == n && info.patchCount == n;
}

/// Return true if at least one patch is selected
inline bool havePatch()
{
Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/UserInterfaceModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ void UserInterfaceModule::registerUICommands()

GlobalCommandSystem().addCommand("ExportCollisionModelDialog", ExportCollisionModelDialog::Show);
GlobalCommandSystem().addWithCheck("QueryBrushPrefabSidesDialog", QuerySidesDialog::Show,
selection::pred::haveSelectedBrush, {cmd::ARGTYPE_INT});
selection::pred::haveBrush, {cmd::ARGTYPE_INT});

// Set up the CloneSelection command to react on key up events only
GlobalEventManager().addCommand("CloneSelection", "CloneSelection", true); // react on keyUp
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/brush/BrushModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void BrushModuleImpl::registerBrushCommands()
GlobalCommandSystem().addCommand("TextureNatural", selection::algorithm::naturalTexture);
GlobalCommandSystem().addWithCheck("MakeVisportal",
cmd::noArgs(selection::algorithm::makeVisportal),
selection::pred::haveSelectedBrush);
selection::pred::haveBrush);
GlobalCommandSystem().addCommand("SurroundWithMonsterclip", selection::algorithm::surroundWithMonsterclip);

GlobalCommandSystem().addCommand("ResizeSelectedBrushesToBounds", selection::algorithm::resizeSelectedBrushesToBounds,
Expand Down
10 changes: 5 additions & 5 deletions radiantcore/brush/csg/CSG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,13 @@ void mergeSelectedBrushes(const cmd::ArgumentList& args)

void registerCommands()
{
using selection::pred::haveSelectedBrush;
using selection::pred::haveBrush;

GlobalCommandSystem().addWithCheck("CSGSubtract", subtractBrushesFromUnselected,
haveSelectedBrush);
GlobalCommandSystem().addWithCheck("CSGMerge", mergeSelectedBrushes, haveSelectedBrush);
GlobalCommandSystem().addWithCheck("CSGHollow", hollowSelectedBrushes, haveSelectedBrush);
GlobalCommandSystem().addWithCheck("CSGRoom", makeRoomForSelectedBrushes, haveSelectedBrush);
haveBrush);
GlobalCommandSystem().addWithCheck("CSGMerge", mergeSelectedBrushes, haveBrush);
GlobalCommandSystem().addWithCheck("CSGHollow", hollowSelectedBrushes, haveBrush);
GlobalCommandSystem().addWithCheck("CSGRoom", makeRoomForSelectedBrushes, haveBrush);
}

} // namespace algorithm
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/clipper/Clipper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void Clipper::initialiseModule(const IApplicationContext& ctx)

// Register the clip commands
auto haveSomethingToClip = [this] {
return clipMode() && selection::pred::haveSelectedBrush();
return clipMode() && selection::pred::haveBrush();
};
GlobalCommandSystem().addWithCheck(
"ClipSelected", cmd::noArgs([this] { clipSelectionCmd(); }), haveSomethingToClip
Expand Down
25 changes: 15 additions & 10 deletions radiantcore/patch/PatchModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "patch/algorithm/Prefab.h"
#include "patch/algorithm/General.h"
#include "selection/algorithm/Patch.h"
#include "selectionlib.h"

#include "module/StaticModule.h"
#include "messages/TextureChanged.h"
Expand Down Expand Up @@ -104,16 +105,20 @@ void PatchModule::registerPatchCommands()
GlobalCommandSystem().addCommand("PatchAppendRowBeginning", selection::algorithm::appendPatchRowsAtBeginning);
GlobalCommandSystem().addCommand("PatchAppendRowEnd", selection::algorithm::appendPatchRowsAtEnd);

GlobalCommandSystem().addCommand("InvertCurve", selection::algorithm::invertPatch);
GlobalCommandSystem().addCommand("RedisperseRows", selection::algorithm::redispersePatchRows);
GlobalCommandSystem().addCommand("RedisperseCols", selection::algorithm::redispersePatchCols);
GlobalCommandSystem().addCommand("MatrixTranspose", selection::algorithm::transposePatch);
GlobalCommandSystem().addCommand("CapSelectedPatches", selection::algorithm::capPatch, { cmd::ARGTYPE_STRING });
GlobalCommandSystem().addCommand("ThickenSelectedPatches", selection::algorithm::thickenPatches,
{ cmd::ARGTYPE_DOUBLE, cmd::ARGTYPE_INT, cmd::ARGTYPE_INT }); // thickness, create_seams, axis
GlobalCommandSystem().addCommand("StitchPatchTexture", patch::algorithm::stitchTextures);
GlobalCommandSystem().addCommand("BulgePatch", patch::algorithm::bulge, { cmd::ARGTYPE_DOUBLE });
GlobalCommandSystem().addCommand("WeldSelectedPatches", patch::algorithm::weldSelectedPatches);
GlobalCommandSystem().addCommand("InvertCurve", selection::algorithm::invertPatch);
GlobalCommandSystem().addCommand("RedisperseRows", selection::algorithm::redispersePatchRows);
GlobalCommandSystem().addCommand("RedisperseCols", selection::algorithm::redispersePatchCols);
GlobalCommandSystem().addCommand("MatrixTranspose", selection::algorithm::transposePatch);
GlobalCommandSystem().addCommand("CapSelectedPatches", selection::algorithm::capPatch,
{cmd::ARGTYPE_STRING});
GlobalCommandSystem().addCommand(
"ThickenSelectedPatches", selection::algorithm::thickenPatches,
{cmd::ARGTYPE_DOUBLE, cmd::ARGTYPE_INT, cmd::ARGTYPE_INT} // thickness, create_seams, axis
);
GlobalCommandSystem().addWithCheck("StitchPatchTexture", patch::algorithm::stitchTextures,
[] { return selection::pred::havePatchesExact(2); });
GlobalCommandSystem().addCommand("BulgePatch", patch::algorithm::bulge, {cmd::ARGTYPE_DOUBLE});
GlobalCommandSystem().addCommand("WeldSelectedPatches", patch::algorithm::weldSelectedPatches);
}

module::StaticModuleRegistration<PatchModule> patchModule;
Expand Down

0 comments on commit ca5609c

Please sign in to comment.