1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

allow double click for bonus selection

This commit is contained in:
Laserlicht 2024-09-06 00:08:18 +02:00
parent 6179521364
commit 7ae8514657
3 changed files with 20 additions and 4 deletions

View File

@ -350,7 +350,10 @@ void CBonusSelection::createBonusesIcons()
break; break;
} }
std::shared_ptr<CToggleButton> bonusButton = std::make_shared<CToggleButton>(Point(475 + i * 68, 455), AnimationPath::builtin("campaignBonusSelection"), CButton::tooltip(desc.toString(), desc.toString())); std::shared_ptr<CToggleButton> bonusButton = std::make_shared<CToggleButton>(Point(475 + i * 68, 455), AnimationPath::builtin("campaignBonusSelection"), CButton::tooltip(desc.toString(), desc.toString()), nullptr, EShortcut::NONE, false, [this](){
if(buttonStart->isActive() && !buttonStart->isBlocked())
CBonusSelection::startMap();
});
if(picNumber != -1) if(picNumber != -1)
bonusButton->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin(picName), picNumber)); bonusButton->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin(picName), picNumber));

View File

@ -446,10 +446,13 @@ void CToggleBase::setAllowDeselection(bool on)
} }
CToggleButton::CToggleButton(Point position, const AnimationPath &defName, const std::pair<std::string, std::string> &help, CToggleButton::CToggleButton(Point position, const AnimationPath &defName, const std::pair<std::string, std::string> &help,
CFunctionList<void(bool)> callback, EShortcut key, bool playerColoredButton): CFunctionList<void(bool)> callback, EShortcut key, bool playerColoredButton,
CFunctionList<void()> callbackSelected):
CButton(position, defName, help, 0, key, playerColoredButton), CButton(position, defName, help, 0, key, playerColoredButton),
CToggleBase(callback) CToggleBase(callback),
callbackSelected(callbackSelected)
{ {
addUsedEvents(DOUBLECLICK);
} }
void CToggleButton::doSelect(bool on) void CToggleButton::doSelect(bool on)
@ -516,6 +519,12 @@ void CToggleButton::clickCancel(const Point & cursorPosition)
doSelect(isSelected()); doSelect(isSelected());
} }
void CToggleButton::clickDouble(const Point & cursorPosition)
{
if(callbackSelected)
callbackSelected();
}
void CToggleGroup::addCallback(const std::function<void(int)> & callback) void CToggleGroup::addCallback(const std::function<void(int)> & callback)
{ {
onChange += callback; onChange += callback;

View File

@ -166,13 +166,17 @@ class CToggleButton : public CButton, public CToggleBase
void doSelect(bool on) override; void doSelect(bool on) override;
void setEnabled(bool enabled) override; void setEnabled(bool enabled) override;
CFunctionList<void()> callbackSelected;
public: public:
CToggleButton(Point position, const AnimationPath &defName, const std::pair<std::string, std::string> &help, CToggleButton(Point position, const AnimationPath &defName, const std::pair<std::string, std::string> &help,
CFunctionList<void(bool)> Callback = 0, EShortcut key = {}, bool playerColoredButton = false ); CFunctionList<void(bool)> Callback = nullptr, EShortcut key = {}, bool playerColoredButton = false,
CFunctionList<void()> CallbackSelected = nullptr );
void clickPressed(const Point & cursorPosition) override; void clickPressed(const Point & cursorPosition) override;
void clickReleased(const Point & cursorPosition) override; void clickReleased(const Point & cursorPosition) override;
void clickCancel(const Point & cursorPosition) override; void clickCancel(const Point & cursorPosition) override;
void clickDouble(const Point & cursorPosition) override;
// bring overrides into scope // bring overrides into scope
//using CButton::addCallback; //using CButton::addCallback;