|
@@ -433,6 +433,50 @@ QuickSpellPanel::QuickSpellPanel(BattleInterface & owner)
|
|
|
create();
|
|
|
}
|
|
|
|
|
|
+std::vector<std::tuple<SpellID, bool>> QuickSpellPanel::getSpells()
|
|
|
+{
|
|
|
+ std::vector<SpellID> spellIds;
|
|
|
+ std::vector<bool> spellIdsFromSetting;
|
|
|
+ for(int i = 0; i < QUICKSPELL_SLOTS; i++)
|
|
|
+ {
|
|
|
+ std::string spellIdentifier = persistentStorage["quickSpell"][std::to_string(i)].String();
|
|
|
+ SpellID id;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ id = SpellID::decode(spellIdentifier);
|
|
|
+ }
|
|
|
+ catch(const IdentifierResolutionException& e)
|
|
|
+ {
|
|
|
+ id = SpellID::NONE;
|
|
|
+ }
|
|
|
+ spellIds.push_back(id);
|
|
|
+ spellIdsFromSetting.push_back(id != SpellID::NONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ // autofill empty slots with spells if possible
|
|
|
+ auto hero = owner.getBattle()->battleGetMyHero();
|
|
|
+ for(int i = 0; i < QUICKSPELL_SLOTS; i++)
|
|
|
+ {
|
|
|
+ if(spellIds[i] != SpellID::NONE)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ for(const auto & availableSpellID : CGI->spellh->getDefaultAllowed())
|
|
|
+ {
|
|
|
+ const auto * availableSpell = availableSpellID.toSpell();
|
|
|
+ if(!availableSpell->isAdventure() && !availableSpell->isCreatureAbility() && hero->canCastThisSpell(availableSpell) && !vstd::contains(spellIds, availableSpell->getId()))
|
|
|
+ {
|
|
|
+ spellIds[i] = availableSpell->getId();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ std::vector<std::tuple<SpellID, bool>> ret;
|
|
|
+ for(int i = 0; i < QUICKSPELL_SLOTS; i++)
|
|
|
+ ret.push_back(std::make_tuple(spellIds[i], spellIdsFromSetting[i]));
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
void QuickSpellPanel::create()
|
|
|
{
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
@@ -447,18 +491,11 @@ void QuickSpellPanel::create()
|
|
|
if(!hero)
|
|
|
return;
|
|
|
|
|
|
- for(int i = 0; i < 12; i++) {
|
|
|
- std::string spellIdentifier = persistentStorage["quickSpell"][std::to_string(i)].String();
|
|
|
-
|
|
|
+ auto spells = getSpells();
|
|
|
+ for(int i = 0; i < QUICKSPELL_SLOTS; i++) {
|
|
|
SpellID id;
|
|
|
- try
|
|
|
- {
|
|
|
- id = SpellID::decode(spellIdentifier);
|
|
|
- }
|
|
|
- catch(const IdentifierResolutionException& e)
|
|
|
- {
|
|
|
- id = SpellID::NONE;
|
|
|
- }
|
|
|
+ bool fromSettings;
|
|
|
+ std::tie(id, fromSettings) = spells[i];
|
|
|
|
|
|
auto button = std::make_shared<CButton>(Point(2, 7 + 50 * i), AnimationPath::builtin("spellint"), CButton::tooltip(), [this, id, hero](){
|
|
|
if(id.hasValue() && id.toSpell()->canBeCast(owner.getBattle().get(), spells::Mode::HERO, hero))
|
|
@@ -466,16 +503,19 @@ void QuickSpellPanel::create()
|
|
|
owner.castThisSpell(id);
|
|
|
}
|
|
|
});
|
|
|
- button->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin("spellint"), !spellIdentifier.empty() ? id.num + 1 : 0));
|
|
|
+ button->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin("spellint"), id != SpellID::NONE ? id.num + 1 : 0));
|
|
|
button->addPopupCallback([this, i, hero](){
|
|
|
GH.input().hapticFeedback();
|
|
|
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;
|
|
|
+ configID->String() = spell == SpellID::NONE ? "" : spell.toSpell()->identifier;
|
|
|
create();
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ if(fromSettings)
|
|
|
+ buttonsIsAutoGenerated.push_back(std::make_shared<TransparentFilledRectangle>(Rect(45, 37 + 50 * i, 5, 5), Colors::ORANGE));
|
|
|
+
|
|
|
if(!id.hasValue() || !id.toSpell()->canBeCast(owner.getBattle().get(), spells::Mode::HERO, hero))
|
|
|
{
|
|
|
buttonsDisabled.push_back(std::make_shared<TransparentFilledRectangle>(Rect(2, 7 + 50 * i, 48, 36), ColorRGBA(0, 0, 0, 172)));
|