mirror of
https://github.com/vcmi/vcmi.git
synced 2025-05-31 22:59:54 +02:00
use spellbook to select
This commit is contained in:
parent
5562402646
commit
f54b84ead9
@ -469,11 +469,12 @@ void QuickSpellPanel::create()
|
||||
}
|
||||
});
|
||||
button->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin("spellint"), !spellIdentifier.empty() ? id.num + 1 : 0));
|
||||
button->addPopupCallback([this, i](){
|
||||
auto panelSelect = std::make_shared<QuickSpellPanelSelect>(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<CSpellWindow>(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<std::shared_ptr<CSpell>> 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<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), Rect(0, 0, pos.w, pos.h));
|
||||
rect = std::make_shared<TransparentFilledRectangle>(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<CSpell> spell = spellList[i];
|
||||
auto button = std::make_shared<CButton>(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<CComponent>(ComponentType::SPELL, spell->id));
|
||||
});
|
||||
button->setOverlay(std::make_shared<CAnimImage>(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)
|
||||
{
|
||||
|
@ -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<CFilledTexture> background;
|
||||
std::shared_ptr<TransparentFilledRectangle> rect;
|
||||
std::vector<std::shared_ptr<CButton>> 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:
|
||||
|
@ -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<void(SpellID)> 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;
|
||||
|
@ -115,8 +115,11 @@ class CSpellWindow : public CWindowObject
|
||||
|
||||
std::shared_ptr<IImage> createBigSpellBook();
|
||||
|
||||
bool openOnBattleSpells;
|
||||
std::function<void(SpellID)> 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<void(SpellID)> onSpellSelect = nullptr);
|
||||
~CSpellWindow();
|
||||
|
||||
void fexitb();
|
||||
|
Loading…
x
Reference in New Issue
Block a user