From f75ccc308b3da875155a82e4d73ee3fab4c9bab6 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Thu, 21 Dec 2023 23:32:02 +0100 Subject: [PATCH 1/2] right click opens hero info --- client/windows/GUIClasses.cpp | 2 ++ client/windows/GUIClasses.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index d808480d9..9d916f474 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -33,6 +33,7 @@ #include "../widgets/Slider.h" #include "../widgets/TextControls.h" #include "../widgets/ObjectLists.h" +#include "../widgets/MiscWidgets.h" #include "../render/Canvas.h" #include "../render/CAnimation.h" @@ -410,6 +411,7 @@ CLevelWindow::CLevelWindow(const CGHeroInstance * hero, PrimarySkill pskill, std } portrait = std::make_shared(AnimationPath::builtin("PortraitsLarge"), hero->getIconIndex(), 0, 170, 66); + portraitArea = std::make_shared(Rect(170, 66, 58, 64), nullptr, [hero](){ GH.windows().createAndPushWindow(std::make_shared(hero)); }); ok = std::make_shared(Point(297, 413), AnimationPath::builtin("IOKAY"), CButton::tooltip(), std::bind(&CLevelWindow::close, this), EShortcut::GLOBAL_ACCEPT); //%s has gained a level. diff --git a/client/windows/GUIClasses.h b/client/windows/GUIClasses.h index a58001e5c..0d90a1d78 100644 --- a/client/windows/GUIClasses.h +++ b/client/windows/GUIClasses.h @@ -35,6 +35,7 @@ class CGStatusBar; class CTextBox; class CGarrisonInt; class CGarrisonSlot; +class LRClickableArea; enum class EUserEvent; @@ -130,6 +131,7 @@ public: class CLevelWindow : public CWindowObject { std::shared_ptr portrait; + std::shared_ptr portraitArea; std::shared_ptr ok; std::shared_ptr mainTitle; std::shared_ptr levelTitle; From c20f0bdc3ec4a63e3b83ccc00652b12c9a62ae3d Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Fri, 22 Dec 2023 01:30:41 +0100 Subject: [PATCH 2/2] using CHeroArea --- client/widgets/MiscWidgets.cpp | 16 ++++++++++++++-- client/widgets/MiscWidgets.h | 3 +++ client/windows/GUIClasses.cpp | 6 +++--- client/windows/GUIClasses.h | 5 ++--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/client/widgets/MiscWidgets.cpp b/client/widgets/MiscWidgets.cpp index ff1bc50d8..c985e35e6 100644 --- a/client/widgets/MiscWidgets.cpp +++ b/client/widgets/MiscWidgets.cpp @@ -121,9 +121,10 @@ void LRClickableAreaWTextComp::showPopupWindow(const Point & cursorPosition) } CHeroArea::CHeroArea(int x, int y, const CGHeroInstance * hero) - : CIntObject(LCLICK | HOVER), + : CIntObject(LCLICK | SHOW_POPUP | HOVER), hero(hero), - clickFunctor(nullptr) + clickFunctor(nullptr), + clickRFunctor(nullptr) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); @@ -147,12 +148,23 @@ void CHeroArea::addClickCallback(ClickFunctor callback) clickFunctor = callback; } +void CHeroArea::addRClickCallback(ClickFunctor callback) +{ + clickRFunctor = callback; +} + void CHeroArea::clickPressed(const Point & cursorPosition) { if(clickFunctor) clickFunctor(); } +void CHeroArea::showPopupWindow(const Point & cursorPosition) +{ + if(clickRFunctor) + clickRFunctor(); +} + void CHeroArea::hover(bool on) { if (on && hero) diff --git a/client/widgets/MiscWidgets.h b/client/widgets/MiscWidgets.h index 28e306614..59a1004dd 100644 --- a/client/widgets/MiscWidgets.h +++ b/client/widgets/MiscWidgets.h @@ -190,12 +190,15 @@ public: CHeroArea(int x, int y, const CGHeroInstance * hero); void addClickCallback(ClickFunctor callback); + void addRClickCallback(ClickFunctor callback); void clickPressed(const Point & cursorPosition) override; + void showPopupWindow(const Point & cursorPosition) override; void hover(bool on) override; private: const CGHeroInstance * hero; std::shared_ptr portrait; ClickFunctor clickFunctor; + ClickFunctor clickRFunctor; ClickFunctor showPopupHandler; }; diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index 9d916f474..94c11a178 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -33,7 +33,6 @@ #include "../widgets/Slider.h" #include "../widgets/TextControls.h" #include "../widgets/ObjectLists.h" -#include "../widgets/MiscWidgets.h" #include "../render/Canvas.h" #include "../render/CAnimation.h" @@ -410,8 +409,9 @@ CLevelWindow::CLevelWindow(const CGHeroInstance * hero, PrimarySkill pskill, std box = std::make_shared(comps, Rect(75, 300, pos.w - 150, 100)); } - portrait = std::make_shared(AnimationPath::builtin("PortraitsLarge"), hero->getIconIndex(), 0, 170, 66); - portraitArea = std::make_shared(Rect(170, 66, 58, 64), nullptr, [hero](){ GH.windows().createAndPushWindow(std::make_shared(hero)); }); + portrait = std::make_shared(170, 66, hero); + portrait->addClickCallback(nullptr); + portrait->addRClickCallback([hero](){ GH.windows().createAndPushWindow(std::make_shared(hero)); }); ok = std::make_shared(Point(297, 413), AnimationPath::builtin("IOKAY"), CButton::tooltip(), std::bind(&CLevelWindow::close, this), EShortcut::GLOBAL_ACCEPT); //%s has gained a level. diff --git a/client/windows/GUIClasses.h b/client/windows/GUIClasses.h index 0d90a1d78..1d57d7454 100644 --- a/client/windows/GUIClasses.h +++ b/client/windows/GUIClasses.h @@ -35,7 +35,7 @@ class CGStatusBar; class CTextBox; class CGarrisonInt; class CGarrisonSlot; -class LRClickableArea; +class CHeroArea; enum class EUserEvent; @@ -130,8 +130,7 @@ public: /// Raised up level window where you can select one out of two skills class CLevelWindow : public CWindowObject { - std::shared_ptr portrait; - std::shared_ptr portraitArea; + std::shared_ptr portrait; std::shared_ptr ok; std::shared_ptr mainTitle; std::shared_ptr levelTitle;