mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-19 21:10:12 +02:00
Create items only if action is possible
This commit is contained in:
parent
a45a0d1c40
commit
cb28a90a3b
@ -350,14 +350,27 @@ void CGarrisonSlot::gesture(bool on, const Point & initialPosition, const Point
|
||||
if (!on)
|
||||
return;
|
||||
|
||||
if (!myStack)
|
||||
return;
|
||||
|
||||
bool stackExists = myStack != nullptr;
|
||||
bool hasSameUnit = stackExists && !owner->army(upg)->getCreatureSlots(myStack->type, ID).empty();
|
||||
bool hasEmptySlots = stackExists && owner->army(upg)->getFreeSlot() != SlotID();
|
||||
bool exchangeMode = stackExists && owner->upperArmy() && owner->lowerArmy();
|
||||
|
||||
std::vector<RadialMenuConfig> menuElements = {
|
||||
{ RadialMenuConfig::ITEM_NW, "stackMerge", "Merge same units", [this](){owner->bulkMergeStacks(this);} },
|
||||
{ RadialMenuConfig::ITEM_NE, "stackInfo", "Show unit information", [this](){viewInfo();} },
|
||||
{ RadialMenuConfig::ITEM_WW, "stackSplitOne", "Split off single unit", [this](){splitIntoParts(this->getGarrison(), 1); } },
|
||||
{ RadialMenuConfig::ITEM_EE, "stackSplitEqual", "Split unit equally", [this](){owner->bulkSmartSplitStack(this);} },
|
||||
{ RadialMenuConfig::ITEM_SW, "heroMove", "Move unit to another army", [this](){owner->moveStackToAnotherArmy(this);} },
|
||||
{ RadialMenuConfig::ITEM_NW, hasSameUnit, "stackMerge", "Merge same units", [this](){owner->bulkMergeStacks(this);} },
|
||||
{ RadialMenuConfig::ITEM_NE, stackExists, "stackInfo", "Show unit information", [this](){viewInfo();} },
|
||||
{ RadialMenuConfig::ITEM_WW, hasEmptySlots, "stackSplitOne", "Split off single unit", [this](){splitIntoParts(this->getGarrison(), 1); } },
|
||||
{ RadialMenuConfig::ITEM_EE, hasEmptySlots, "stackSplitEqual", "Split unit equally", [this](){owner->bulkSmartSplitStack(this);} },
|
||||
{ RadialMenuConfig::ITEM_SW, exchangeMode, "heroMove", "Move unit to another army", [this](){owner->moveStackToAnotherArmy(this);} },
|
||||
};
|
||||
|
||||
// additional options to consider:
|
||||
// - Ctrl + Shift + Click - splits from current stack, stacks of 1 in all free slots
|
||||
// - Alt + Shift + Click - dismiss stack with confirmation window
|
||||
// Split unit (same as button)
|
||||
|
||||
GH.windows().createAndPushWindow<RadialMenu>(pos.center(), menuElements);
|
||||
}
|
||||
|
||||
|
@ -33,13 +33,13 @@ RadialMenu::RadialMenu(const Point & positionToCenter, const std::vector<RadialM
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||
pos += positionToCenter;
|
||||
|
||||
addItem(Point(0,0), "itemEmpty", "", [](){});
|
||||
addItem(Point(0,0), true, "itemEmpty", "", [](){});
|
||||
|
||||
Point itemSize = items.back()->pos.dimensions();
|
||||
moveBy(-itemSize / 2);
|
||||
|
||||
for (auto const & item : menuConfig)
|
||||
addItem(item.itemPosition, item.imageName, item.hoverText, item.callback);
|
||||
addItem(item.itemPosition, item.enabled, item.imageName, item.hoverText, item.callback);
|
||||
|
||||
statusBar = CGStatusBar::create(-80, -100, "radialMenu/statusBar");
|
||||
|
||||
@ -51,8 +51,11 @@ RadialMenu::RadialMenu(const Point & positionToCenter, const std::vector<RadialM
|
||||
addUsedEvents(GESTURE);
|
||||
}
|
||||
|
||||
void RadialMenu::addItem(const Point & offset, const std::string & path, const std::string & hoverText, const std::function<void()>& callback )
|
||||
void RadialMenu::addItem(const Point & offset, bool enabled, const std::string & path, const std::string & hoverText, const std::function<void()>& callback )
|
||||
{
|
||||
if (!enabled)
|
||||
return;
|
||||
|
||||
auto item = std::make_shared<RadialMenuItem>(path, hoverText, callback);
|
||||
|
||||
item->moveBy(offset);
|
||||
|
@ -27,6 +27,7 @@ struct RadialMenuConfig
|
||||
static constexpr Point ITEM_SE = Point(+40, +70);
|
||||
|
||||
Point itemPosition;
|
||||
bool enabled;
|
||||
std::string imageName;
|
||||
std::string hoverText;
|
||||
std::function<void()> callback;
|
||||
@ -51,7 +52,7 @@ class RadialMenu : public CIntObject
|
||||
|
||||
std::shared_ptr<CGStatusBar> statusBar;
|
||||
|
||||
void addItem(const Point & offset, const std::string & path, const std::string & hoverText, const std::function<void()> & callback);
|
||||
void addItem(const Point & offset, bool enabled, const std::string & path, const std::string & hoverText, const std::function<void()> & callback);
|
||||
|
||||
std::shared_ptr<RadialMenuItem> findNearestItem(const Point & cursorPosition) const;
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user