From 814241e8366ac7f528aeda39428343776a4bb724 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 19 May 2024 04:23:53 +0200 Subject: [PATCH] converted to window --- client/battle/BattleInterfaceClasses.cpp | 30 ++++++++++++++++++++---- client/battle/BattleInterfaceClasses.h | 7 ++++-- client/battle/BattleWindow.cpp | 9 +++---- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/client/battle/BattleInterfaceClasses.cpp b/client/battle/BattleInterfaceClasses.cpp index 0dc794d5b..f34f3091e 100644 --- a/client/battle/BattleInterfaceClasses.cpp +++ b/client/battle/BattleInterfaceClasses.cpp @@ -417,11 +417,13 @@ BattleHero::BattleHero(const BattleInterface & owner, const CGHeroInstance * her addUsedEvents(TIME); } -QuickSpellPanel::QuickSpellPanel() - : CIntObject(LCLICK | SHOW_POPUP) +QuickSpellPanel::QuickSpellPanel(std::shared_ptr initWidget) + : CWindowObject(NEEDS_ANIMATED_BACKGROUND), initWidget(initWidget) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); + addUsedEvents(LCLICK | SHOW_POPUP | MOVE); + setEnabled(false); pos = Rect(0, 0, 52, 372); @@ -452,13 +454,33 @@ void QuickSpellPanel::show(Canvas & to) void QuickSpellPanel::clickReleased(const Point & cursorPosition) { if(!pos.isInside(cursorPosition)) - setEnabled(false); + close(); + + if(initWidget->pos.isInside(cursorPosition)) + { + initWidget->clickPressed(cursorPosition); + initWidget->clickReleased(cursorPosition); + } } void QuickSpellPanel::showPopupWindow(const Point & cursorPosition) { if(!pos.isInside(cursorPosition)) - setEnabled(false); + close(); + + if(initWidget->pos.isInside(cursorPosition)) + { + initWidget->showPopupWindow(cursorPosition); + } +} + +void QuickSpellPanel::mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) +{ + if( cursorPosition.x <= initWidget->pos.x - 20 || + cursorPosition.x >= initWidget->pos.x + initWidget->pos.w + 20 || + cursorPosition.y <= initWidget->pos.y - pos.h - 20 || + (cursorPosition.y >= initWidget->pos.y && !initWidget->pos.isInside(cursorPosition))) + close(); } bool QuickSpellPanel::receiveEvent(const Point & position, int eventType) const diff --git a/client/battle/BattleInterfaceClasses.h b/client/battle/BattleInterfaceClasses.h index c62f7279c..d5c8ceff1 100644 --- a/client/battle/BattleInterfaceClasses.h +++ b/client/battle/BattleInterfaceClasses.h @@ -147,7 +147,7 @@ public: BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender); }; -class QuickSpellPanel : public CIntObject +class QuickSpellPanel : public CWindowObject { private: std::shared_ptr background; @@ -158,8 +158,11 @@ private: bool receiveEvent(const Point & position, int eventType) const override; void clickReleased(const Point & cursorPosition) override; void showPopupWindow(const Point & cursorPosition) override; + void mouseMoved(const Point & cursorPosition, const Point & lastUpdateDistance) override; + + std::shared_ptr initWidget; public: - QuickSpellPanel(); + QuickSpellPanel(std::shared_ptr initWidget); void show(Canvas & to) override; }; diff --git a/client/battle/BattleWindow.cpp b/client/battle/BattleWindow.cpp index 0b8cddb5e..a2dc2bdc2 100644 --- a/client/battle/BattleWindow.cpp +++ b/client/battle/BattleWindow.cpp @@ -104,20 +104,17 @@ BattleWindow::BattleWindow(BattleInterface & owner): auto hero = owner.getBattle()->battleGetMyHero(); if(GH.screenDimensions().x >= 1000 && hero && owner.getBattle()->battleCanCastSpell(hero, spells::Mode::HERO) != ESpellCastProblem::NO_SPELLBOOK && settings["general"]["enableUiEnhancements"].Bool()) { - quickSpellPanelWindow = std::make_shared(); + quickSpellPanelWindow = std::make_shared(w); quickSpellPanelWindow->moveTo(Point(w->pos.x - 2, w->pos.y - 378)); w->addHoverCallback([this, w](bool on) { if(on) - quickSpellPanelWindow->setEnabled(true); - else - if(GH.getCursorPosition().x <= w->pos.x || GH.getCursorPosition().x >= w->pos.x + w->pos.w || GH.getCursorPosition().y >= w->pos.y + w->pos.h) - quickSpellPanelWindow->setEnabled(false); + GH.windows().pushWindow(quickSpellPanelWindow); }); w->addPanningCallback([this](const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) { if((currentPosition - initialPosition).y < -20) - quickSpellPanelWindow->setEnabled(true); + GH.windows().pushWindow(quickSpellPanelWindow); }); } }