From 1fb2a026ec0d75f306e9a54f0a88b10beb4a6ccf Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Fri, 19 Jan 2024 23:31:21 +0100 Subject: [PATCH] enable doubleclick --- client/windows/GUIClasses.cpp | 18 +++++++++++++----- client/windows/GUIClasses.h | 5 ++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index 94c11a178..8fed1bd40 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -459,8 +459,8 @@ CTavernWindow::CTavernWindow(const CGObjectInstance * TavernObj, const std::func oldSelected = -1; - h1 = std::make_shared(selected, 0, 72, 299, h[0]); - h2 = std::make_shared(selected, 1, 162, 299, h[1]); + h1 = std::make_shared(selected, 0, 72, 299, h[0], [&]() { if(!recruit->isBlocked()) recruitb(); }); + h2 = std::make_shared(selected, 1, 162, 299, h[1], [&]() { if(!recruit->isBlocked()) recruitb(); }); title = std::make_shared(197, 32, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->jktexts[37]); cost = std::make_shared(320, 328, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, std::to_string(GameConstants::HERO_GOLD_COST)); @@ -569,15 +569,23 @@ void CTavernWindow::HeroPortrait::clickPressed(const Point & cursorPosition) *_sel = _id; } +void CTavernWindow::HeroPortrait::clickDouble(const Point & cursorPosition) +{ + clickPressed(cursorPosition); + + if(onChoose) + onChoose(); +} + void CTavernWindow::HeroPortrait::showPopupWindow(const Point & cursorPosition) { if(h) GH.windows().createAndPushWindow(std::make_shared(h)); } -CTavernWindow::HeroPortrait::HeroPortrait(int & sel, int id, int x, int y, const CGHeroInstance * H) - : CIntObject(LCLICK | SHOW_POPUP | HOVER), - h(H), _sel(&sel), _id(id) +CTavernWindow::HeroPortrait::HeroPortrait(int & sel, int id, int x, int y, const CGHeroInstance * H, std::function OnChoose) + : CIntObject(LCLICK | DOUBLECLICK | SHOW_POPUP | HOVER), + h(H), _sel(&sel), _id(id), onChoose(OnChoose) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); h = H; diff --git a/client/windows/GUIClasses.h b/client/windows/GUIClasses.h index 1d57d7454..281d30e16 100644 --- a/client/windows/GUIClasses.h +++ b/client/windows/GUIClasses.h @@ -206,10 +206,13 @@ public: std::string description; // "XXX is a level Y ZZZ with N artifacts" const CGHeroInstance * h; + std::function onChoose; + void clickPressed(const Point & cursorPosition) override; + void clickDouble(const Point & cursorPosition) override; void showPopupWindow(const Point & cursorPosition) override; void hover (bool on) override; - HeroPortrait(int & sel, int id, int x, int y, const CGHeroInstance * H); + HeroPortrait(int & sel, int id, int x, int y, const CGHeroInstance * H, std::function OnChoose = nullptr); private: int *_sel;