diff --git a/client/battle/BattleInterfaceClasses.cpp b/client/battle/BattleInterfaceClasses.cpp index 62d37c989..516ddceed 100644 --- a/client/battle/BattleInterfaceClasses.cpp +++ b/client/battle/BattleInterfaceClasses.cpp @@ -469,11 +469,12 @@ void QuickSpellPanel::create() } }); button->setOverlay(std::make_shared(AnimationPath::builtin("spellint"), !spellIdentifier.empty() ? id.num + 1 : 0)); - button->addPopupCallback([this, i](){ - auto panelSelect = std::make_shared(this); - panelSelect->spellSlot = i; - panelSelect->moveTo(Point(pos.x + 54, pos.y + 4)); - GH.windows().pushWindow(panelSelect); + button->addPopupCallback([this, i, hero](){ + GH.windows().createAndPushWindow(hero, owner.curInt.get(), true, [this, i](SpellID spell){ + Settings configID = persistentStorage.write["quickSpell"][std::to_string(i)]; + configID->String() = spell.toSpell()->identifier; + create(); + }); }); if(!id.hasValue() || !id.toSpell()->canBeCast(owner.getBattle().get(), spells::Mode::HERO, hero)) @@ -492,56 +493,6 @@ void QuickSpellPanel::show(Canvas & to) CIntObject::show(to); } -QuickSpellPanelSelect::QuickSpellPanelSelect(QuickSpellPanel * Parent) - : parent(Parent) -{ - OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); - - addUsedEvents(LCLICK); - - std::vector> spellList; - for (auto const & s : VLC->spellh->objects) - if (s->isCombat() && !s->isSpecial() && !s->isCreatureAbility()) - spellList.push_back(s); - - auto ceil = [](int x, int y){ return(x + y - 1) / y; }; - int columnsNeeded = ceil(spellList.size(), NUM_PER_COLUMN); - - pos = Rect(pos.x, pos.y, columnsNeeded * 50 + 2, 2 + 37 * NUM_PER_COLUMN); - background = std::make_shared(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, pos.w, pos.h)); - rect = std::make_shared(Rect(0, 0, pos.w + 1, pos.h + 1), ColorRGBA(0, 0, 0, 0), ColorRGBA(241, 216, 120, 255)); - - for(int i = 0; i < spellList.size(); i++) - { - int y = i % NUM_PER_COLUMN; - int x = i / NUM_PER_COLUMN; - std::shared_ptr spell = spellList[i]; - auto button = std::make_shared(Point(2 + 50 * x, 1 + 37 * y), AnimationPath::builtin("spellint"), CButton::tooltip(), [this, spell](){ - close(); - GH.windows().totalRedraw(); - Settings configID = persistentStorage.write["quickSpell"][std::to_string(spellSlot)]; - configID->String() = spell->identifier; - parent->create(); - }); - button->addPopupCallback([spell](){ - CRClickPopup::createAndPush(spell->getDescriptionTranslated(0), std::make_shared(ComponentType::SPELL, spell->id)); - }); - button->setOverlay(std::make_shared(AnimationPath::builtin("spellint"), spellList[i]->getId().num + 1)); - buttons.push_back(button); - } -} - -void QuickSpellPanelSelect::clickReleased(const Point & cursorPosition) -{ - if(!pos.isInside(cursorPosition) && !parent->pos.isInside(cursorPosition)) - close(); -} - -bool QuickSpellPanelSelect::receiveEvent(const Point & position, int eventType) const -{ - return true; // capture click also outside of window -} - HeroInfoBasicPanel::HeroInfoBasicPanel(const InfoAboutHero & hero, Point * position, bool initializeBackground) : CIntObject(0) { diff --git a/client/battle/BattleInterfaceClasses.h b/client/battle/BattleInterfaceClasses.h index 5fe9049eb..9cce7143e 100644 --- a/client/battle/BattleInterfaceClasses.h +++ b/client/battle/BattleInterfaceClasses.h @@ -149,24 +149,6 @@ public: BattleHero(const BattleInterface & owner, const CGHeroInstance * hero, bool defender); }; -class QuickSpellPanelSelect : public CWindowObject -{ -private: - const int NUM_PER_COLUMN = 16; - - std::shared_ptr background; - std::shared_ptr rect; - std::vector> buttons; - QuickSpellPanel * parent; -public: - QuickSpellPanelSelect(QuickSpellPanel * Parent); - - bool receiveEvent(const Point & position, int eventType) const override; - void clickReleased(const Point & cursorPosition) override; - - int spellSlot; -}; - class QuickSpellPanel : public CIntObject { private: diff --git a/client/windows/CSpellWindow.cpp b/client/windows/CSpellWindow.cpp index 5c89602c3..e91cbbada 100644 --- a/client/windows/CSpellWindow.cpp +++ b/client/windows/CSpellWindow.cpp @@ -98,13 +98,15 @@ public: } }; -CSpellWindow::CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells): +CSpellWindow::CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells, std::function onSpellSelect): CWindowObject(PLAYER_COLORED | (settings["gameTweaks"]["enableLargeSpellbook"].Bool() ? BORDERED : 0)), battleSpellsOnly(openOnBattleSpells), selectedTab(4), currentPage(0), myHero(_myHero), myInt(_myInt), + openOnBattleSpells(openOnBattleSpells), + onSpellSelect(onSpellSelect), isBigSpellbook(settings["gameTweaks"]["enableLargeSpellbook"].Bool()), spellsPerPage(24), offL(-11), @@ -293,6 +295,14 @@ void CSpellWindow::processSpells() for(auto const & spell : CGI->spellh->objects) { bool searchTextFound = !searchBox || boost::algorithm::contains(boost::algorithm::to_lower_copy(spell->getNameTranslated()), boost::algorithm::to_lower_copy(searchBox->getText())); + + if(onSpellSelect) + { + if(spell->isCombat() == openOnBattleSpells && !spell->isSpecial() && !spell->isCreatureAbility()) + mySpells.push_back(spell.get()); + continue; + } + if(!spell->isCreatureAbility() && myHero->canCastThisSpell(spell.get()) && searchTextFound) mySpells.push_back(spell.get()); } @@ -602,6 +612,13 @@ void CSpellWindow::SpellArea::clickPressed(const Point & cursorPosition) { if(mySpell) { + if(owner->onSpellSelect) + { + owner->onSpellSelect(mySpell->id); + owner->fexitb(); + return; + } + auto spellCost = owner->myInt->cb->getSpellCost(mySpell, owner->myHero); if(spellCost > owner->myHero->mana) //insufficient mana { @@ -738,7 +755,7 @@ void CSpellWindow::SpellArea::setSpell(const CSpell * spell) } ColorRGBA firstLineColor, secondLineColor; - if(spellCost > owner->myHero->mana) //hero cannot cast this spell + if(spellCost > owner->myHero->mana || !owner->onSpellSelect) //hero cannot cast this spell { firstLineColor = Colors::WHITE; secondLineColor = Colors::ORANGE; diff --git a/client/windows/CSpellWindow.h b/client/windows/CSpellWindow.h index 16401a752..f9a761547 100644 --- a/client/windows/CSpellWindow.h +++ b/client/windows/CSpellWindow.h @@ -115,8 +115,11 @@ class CSpellWindow : public CWindowObject std::shared_ptr createBigSpellBook(); + bool openOnBattleSpells; + std::function onSpellSelect; //external processing of selected spell + public: - CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells = true); + CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells = true, std::function onSpellSelect = nullptr); ~CSpellWindow(); void fexitb();