2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* CSpellWindow.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2008-09-10 15:19:48 +03:00
|
|
|
#include "CSpellWindow.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2015-04-11 08:24:51 +02:00
|
|
|
#include "../../lib/ScopeGuard.h"
|
|
|
|
|
2014-07-13 18:39:45 +03:00
|
|
|
#include "GUIClasses.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "InfoWindows.h"
|
2016-02-02 10:11:54 +02:00
|
|
|
#include "CCastleInterface.h"
|
2008-09-10 15:19:48 +03:00
|
|
|
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
|
|
|
#include "../CVideoHandler.h"
|
|
|
|
|
2022-12-09 13:38:46 +02:00
|
|
|
#include "../battle/BattleInterface.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../gui/CGuiHandler.h"
|
|
|
|
#include "../widgets/MiscWidgets.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../widgets/CComponent.h"
|
2016-10-17 03:05:33 +02:00
|
|
|
#include "../widgets/TextControls.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../adventureMap/CAdvMapInt.h"
|
|
|
|
#include "../render/CAnimation.h"
|
2023-02-02 21:15:13 +02:00
|
|
|
#include "../renderSDL/SDL_Extensions.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
|
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
2015-02-02 10:25:26 +02:00
|
|
|
#include "../../lib/spells/CSpellHandler.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "../../lib/spells/Problem.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../../lib/GameConstants.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
2008-09-10 15:19:48 +03:00
|
|
|
|
2023-01-17 22:01:35 +02:00
|
|
|
CSpellWindow::InteractiveArea::InteractiveArea(const Rect & myRect, std::function<void()> funcL, int helpTextId, CSpellWindow * _owner)
|
2008-09-10 15:19:48 +03:00
|
|
|
{
|
2012-06-02 18:16:54 +03:00
|
|
|
addUsedEvents(LCLICK | RCLICK | HOVER);
|
2008-09-10 15:19:48 +03:00
|
|
|
pos = myRect;
|
2008-09-11 15:29:22 +03:00
|
|
|
onLeft = funcL;
|
2016-10-16 08:03:13 +02:00
|
|
|
hoverText = CGI->generaltexth->zelp[helpTextId].first;
|
|
|
|
helpText = CGI->generaltexth->zelp[helpTextId].second;
|
|
|
|
owner = _owner;
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
2016-10-16 08:17:23 +02:00
|
|
|
void CSpellWindow::InteractiveArea::clickLeft(tribool down, bool previousState)
|
2008-09-10 15:19:48 +03:00
|
|
|
{
|
|
|
|
if(!down)
|
2008-09-11 15:29:22 +03:00
|
|
|
onLeft();
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
2016-10-16 08:17:23 +02:00
|
|
|
void CSpellWindow::InteractiveArea::clickRight(tribool down, bool previousState)
|
2008-09-11 15:29:22 +03:00
|
|
|
{
|
2023-02-10 15:50:46 +02:00
|
|
|
if (down)
|
|
|
|
CRClickPopup::createAndPush(helpText);
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
2016-10-16 08:17:23 +02:00
|
|
|
void CSpellWindow::InteractiveArea::hover(bool on)
|
2008-09-11 15:29:22 +03:00
|
|
|
{
|
|
|
|
if(on)
|
2022-12-19 22:04:50 +02:00
|
|
|
owner->statusBar->write(hoverText);
|
2008-09-11 15:29:22 +03:00
|
|
|
else
|
2016-10-16 08:03:13 +02:00
|
|
|
owner->statusBar->clear();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
2016-10-16 09:32:12 +02:00
|
|
|
class SpellbookSpellSorter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool operator()(const CSpell * A, const CSpell * B)
|
|
|
|
{
|
|
|
|
if(A->level < B->level)
|
|
|
|
return true;
|
|
|
|
if(A->level > B->level)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
for(ui8 schoolId = 0; schoolId < 4; schoolId++)
|
|
|
|
{
|
|
|
|
if(A->school.at((ESpellSchool)schoolId) && !B->school.at((ESpellSchool)schoolId))
|
|
|
|
return true;
|
|
|
|
if(!A->school.at((ESpellSchool)schoolId) && B->school.at((ESpellSchool)schoolId))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-01-02 00:06:42 +02:00
|
|
|
return A->getNameTranslated() < B->getNameTranslated();
|
2016-10-16 09:32:12 +02:00
|
|
|
}
|
|
|
|
} spellsorter;
|
|
|
|
|
2016-10-16 08:27:22 +02:00
|
|
|
CSpellWindow::CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells):
|
2012-06-15 20:08:19 +03:00
|
|
|
CWindowObject(PLAYER_COLORED, "SpelBack"),
|
2009-07-03 22:57:14 +03:00
|
|
|
battleSpellsOnly(openOnBattleSpells),
|
2008-12-23 15:59:03 +02:00
|
|
|
selectedTab(4),
|
2010-07-21 13:09:29 +03:00
|
|
|
currentPage(0),
|
2010-02-19 18:02:34 +02:00
|
|
|
myHero(_myHero),
|
|
|
|
myInt(_myInt)
|
2008-09-10 15:19:48 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
* support for new hero bonuses (BLOCK_MORALE, SECONDARY_SKILL_PREMY (archery), AIR_SPELL_DMG_PREMY, EARTH_SPELL_DMG_PREMY, FIRE_SPELL_DMG_PREMY, WATER_SPELL_DMG_PREMY, BLOCK_SPELLS_ABOVE_LEVEL, SPELL_IMMUNITY, BLOCK_MORALE, FIRE_SPELLS, AIR_SPELLS, WATER_SPELLS, EARTH_SPELLS, SPELL, SPELLS_OF_LEVEL). It means that following artifacts are now supported:
- Orb of the Firmament
- Orb of Silt
- Orb of Tempestuous Fire
- Orb of Driving Rain
- Bow of Elven Cherrywood
- Bowstring of the Unicorn's Mane
- Angel Feather Arrows
- Tome of Fire Magic
- Tome of Air Magic
- Tome of Water Magic
- Tome of Earth Magic
- Recanter's Cloak
- Orb of Inhibition
- Pendant of Dispassion
- Pendant of Second Sight
- Pendant of Holiness
- Pendant of Life
- Pendant of Death
- Pendant of Free Will
- Pendant of Negativity
- Pendant of Total Recall
- Spellbinder's Hat
- Spirit of Oppression
- Sphere of Permanence
I hope I listed them all here :). Please try them and report if something's wrong.
2009-05-03 19:14:16 +03:00
|
|
|
//initializing castable spells
|
2016-10-16 09:32:12 +02:00
|
|
|
mySpells.reserve(CGI->spellh->objects.size());
|
|
|
|
for(const CSpell * spell : CGI->spellh->objects)
|
* support for new hero bonuses (BLOCK_MORALE, SECONDARY_SKILL_PREMY (archery), AIR_SPELL_DMG_PREMY, EARTH_SPELL_DMG_PREMY, FIRE_SPELL_DMG_PREMY, WATER_SPELL_DMG_PREMY, BLOCK_SPELLS_ABOVE_LEVEL, SPELL_IMMUNITY, BLOCK_MORALE, FIRE_SPELLS, AIR_SPELLS, WATER_SPELLS, EARTH_SPELLS, SPELL, SPELLS_OF_LEVEL). It means that following artifacts are now supported:
- Orb of the Firmament
- Orb of Silt
- Orb of Tempestuous Fire
- Orb of Driving Rain
- Bow of Elven Cherrywood
- Bowstring of the Unicorn's Mane
- Angel Feather Arrows
- Tome of Fire Magic
- Tome of Air Magic
- Tome of Water Magic
- Tome of Earth Magic
- Recanter's Cloak
- Orb of Inhibition
- Pendant of Dispassion
- Pendant of Second Sight
- Pendant of Holiness
- Pendant of Life
- Pendant of Death
- Pendant of Free Will
- Pendant of Negativity
- Pendant of Total Recall
- Spellbinder's Hat
- Spirit of Oppression
- Sphere of Permanence
I hope I listed them all here :). Please try them and report if something's wrong.
2009-05-03 19:14:16 +03:00
|
|
|
{
|
2016-10-16 09:32:12 +02:00
|
|
|
if(!spell->isCreatureAbility() && myHero->canCastThisSpell(spell))
|
|
|
|
mySpells.push_back(spell);
|
* support for new hero bonuses (BLOCK_MORALE, SECONDARY_SKILL_PREMY (archery), AIR_SPELL_DMG_PREMY, EARTH_SPELL_DMG_PREMY, FIRE_SPELL_DMG_PREMY, WATER_SPELL_DMG_PREMY, BLOCK_SPELLS_ABOVE_LEVEL, SPELL_IMMUNITY, BLOCK_MORALE, FIRE_SPELLS, AIR_SPELLS, WATER_SPELLS, EARTH_SPELLS, SPELL, SPELLS_OF_LEVEL). It means that following artifacts are now supported:
- Orb of the Firmament
- Orb of Silt
- Orb of Tempestuous Fire
- Orb of Driving Rain
- Bow of Elven Cherrywood
- Bowstring of the Unicorn's Mane
- Angel Feather Arrows
- Tome of Fire Magic
- Tome of Air Magic
- Tome of Water Magic
- Tome of Earth Magic
- Recanter's Cloak
- Orb of Inhibition
- Pendant of Dispassion
- Pendant of Second Sight
- Pendant of Holiness
- Pendant of Life
- Pendant of Death
- Pendant of Free Will
- Pendant of Negativity
- Pendant of Total Recall
- Spellbinder's Hat
- Spirit of Oppression
- Sphere of Permanence
I hope I listed them all here :). Please try them and report if something's wrong.
2009-05-03 19:14:16 +03:00
|
|
|
}
|
2016-10-16 09:32:12 +02:00
|
|
|
std::sort(mySpells.begin(), mySpells.end(), spellsorter);
|
2008-09-15 19:46:54 +03:00
|
|
|
|
2008-09-12 16:06:53 +03:00
|
|
|
//initializing sizes of spellbook's parts
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : sitesPerTabAdv)
|
|
|
|
elem = 0;
|
|
|
|
for(auto & elem : sitesPerTabBattle)
|
|
|
|
elem = 0;
|
2010-07-21 13:09:29 +03:00
|
|
|
|
2016-10-16 09:32:12 +02:00
|
|
|
for(const auto spell : mySpells)
|
2008-09-12 16:06:53 +03:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
int * sitesPerOurTab = spell->isCombat() ? sitesPerTabBattle : sitesPerTabAdv;
|
2008-09-15 19:46:54 +03:00
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
++sitesPerOurTab[4];
|
2016-02-02 10:11:54 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
spell->forEachSchool([&sitesPerOurTab](const spells::SchoolInfo & school, bool & stop)
|
2015-01-30 08:39:36 +02:00
|
|
|
{
|
|
|
|
++sitesPerOurTab[(ui8)school.id];
|
|
|
|
});
|
2008-09-12 16:06:53 +03:00
|
|
|
}
|
|
|
|
if(sitesPerTabAdv[4] % 12 == 0)
|
|
|
|
sitesPerTabAdv[4]/=12;
|
|
|
|
else
|
|
|
|
sitesPerTabAdv[4] = sitesPerTabAdv[4]/12 + 1;
|
|
|
|
|
|
|
|
for(int v=0; v<4; ++v)
|
|
|
|
{
|
|
|
|
if(sitesPerTabAdv[v] <= 10)
|
|
|
|
sitesPerTabAdv[v] = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if((sitesPerTabAdv[v] - 10) % 12 == 0)
|
|
|
|
sitesPerTabAdv[v] = (sitesPerTabAdv[v] - 10) / 12 + 1;
|
|
|
|
else
|
|
|
|
sitesPerTabAdv[v] = (sitesPerTabAdv[v] - 10) / 12 + 2;
|
|
|
|
}
|
|
|
|
}
|
2014-03-07 16:21:09 +03:00
|
|
|
|
2008-09-12 16:06:53 +03:00
|
|
|
if(sitesPerTabBattle[4] % 12 == 0)
|
|
|
|
sitesPerTabBattle[4]/=12;
|
|
|
|
else
|
|
|
|
sitesPerTabBattle[4] = sitesPerTabBattle[4]/12 + 1;
|
|
|
|
|
|
|
|
for(int v=0; v<4; ++v)
|
|
|
|
{
|
|
|
|
if(sitesPerTabBattle[v] <= 10)
|
|
|
|
sitesPerTabBattle[v] = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if((sitesPerTabBattle[v] - 10) % 12 == 0)
|
|
|
|
sitesPerTabBattle[v] = (sitesPerTabBattle[v] - 10) / 12 + 1;
|
|
|
|
else
|
|
|
|
sitesPerTabBattle[v] = (sitesPerTabBattle[v] - 10) / 12 + 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//numbers of spell pages computed
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
leftCorner = std::make_shared<CPicture>("SpelTrnL.bmp", 97, 77);
|
|
|
|
rightCorner = std::make_shared<CPicture>("SpelTrnR.bmp", 487, 72);
|
2016-02-02 10:11:54 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
spellIcons = std::make_shared<CAnimation>("Spells");
|
2016-02-02 10:11:54 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
schoolTab = std::make_shared<CAnimImage>("SpelTab", selectedTab, 0, 524, 88);
|
|
|
|
schoolPicture = std::make_shared<CAnimImage>("Schools", 0, 0, 117, 74);
|
2016-10-16 14:27:35 +02:00
|
|
|
|
|
|
|
schoolBorders[0] = std::make_shared<CAnimation>("SplevA.def");
|
|
|
|
schoolBorders[1] = std::make_shared<CAnimation>("SplevF.def");
|
|
|
|
schoolBorders[2] = std::make_shared<CAnimation>("SplevW.def");
|
|
|
|
schoolBorders[3] = std::make_shared<CAnimation>("SplevE.def");
|
|
|
|
|
|
|
|
for(auto item : schoolBorders)
|
2018-04-07 13:34:11 +02:00
|
|
|
item->preload();
|
2023-03-09 15:36:46 +02:00
|
|
|
mana = std::make_shared<CLabel>(435, 426, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, std::to_string(myHero->mana));
|
2018-08-26 18:09:56 +02:00
|
|
|
statusBar = CGStatusBar::create(7, 569, "Spelroll.bmp");
|
2008-09-11 15:29:22 +03:00
|
|
|
|
2023-02-03 19:17:59 +02:00
|
|
|
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 479 + pos.x, 405 + pos.y, 36, 56), std::bind(&CSpellWindow::fexitb, this), 460, this));
|
|
|
|
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 221 + pos.x, 405 + pos.y, 36, 56), std::bind(&CSpellWindow::fbattleSpellsb, this), 453, this));
|
|
|
|
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 355 + pos.x, 405 + pos.y, 36, 56), std::bind(&CSpellWindow::fadvSpellsb, this), 452, this));
|
|
|
|
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 418 + pos.x, 405 + pos.y, 36, 56), std::bind(&CSpellWindow::fmanaPtsb, this), 459, this));
|
|
|
|
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 549 + pos.x, 94 + pos.y, 36, 56), std::bind(&CSpellWindow::selectSchool, this, 0), 454, this));
|
|
|
|
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 549 + pos.x, 151 + pos.y, 45, 35), std::bind(&CSpellWindow::selectSchool, this, 3), 457, this));
|
|
|
|
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 549 + pos.x, 210 + pos.y, 45, 35), std::bind(&CSpellWindow::selectSchool, this, 1), 455, this));
|
|
|
|
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 549 + pos.x, 270 + pos.y, 45, 35), std::bind(&CSpellWindow::selectSchool, this, 2), 456, this));
|
|
|
|
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 549 + pos.x, 330 + pos.y, 45, 35), std::bind(&CSpellWindow::selectSchool, this, 4), 458, this));
|
|
|
|
|
|
|
|
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 97 + pos.x, 77 + pos.y, leftCorner->pos.h, leftCorner->pos.w ), std::bind(&CSpellWindow::fLcornerb, this), 450, this));
|
|
|
|
interactiveAreas.push_back(std::make_shared<InteractiveArea>( Rect( 487 + pos.x, 72 + pos.y, rightCorner->pos.h, rightCorner->pos.w ), std::bind(&CSpellWindow::fRcornerb, this), 451, this));
|
2008-09-15 19:46:54 +03:00
|
|
|
|
|
|
|
//areas for spells
|
2009-01-07 21:40:19 +02:00
|
|
|
int xpos = 117 + pos.x, ypos = 90 + pos.y;
|
2008-09-15 19:46:54 +03:00
|
|
|
|
|
|
|
for(int v=0; v<12; ++v)
|
|
|
|
{
|
2023-02-03 19:17:59 +02:00
|
|
|
spellAreas[v] = std::make_shared<SpellArea>( Rect(xpos, ypos, 65, 78), this);
|
2008-09-15 19:46:54 +03:00
|
|
|
|
|
|
|
if(v == 5) //to right page
|
|
|
|
{
|
2009-01-07 21:40:19 +02:00
|
|
|
xpos = 336 + pos.x; ypos = 90 + pos.y;
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(v%2 == 0)
|
|
|
|
{
|
|
|
|
xpos+=85;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xpos -= 85; ypos+=97;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
|
2013-11-03 21:16:25 +03:00
|
|
|
selectedTab = battleSpellsOnly ? myInt->spellbookSettings.spellbookLastTabBattle : myInt->spellbookSettings.spellbookLastTabAdvmap;
|
2018-04-07 13:34:11 +02:00
|
|
|
schoolTab->setFrame(selectedTab, 0);
|
2016-10-16 14:27:35 +02:00
|
|
|
int cp = battleSpellsOnly ? myInt->spellbookSettings.spellbookLastPageBattle : myInt->spellbookSettings.spellbokLastPageAdvmap;
|
2013-11-03 21:16:25 +03:00
|
|
|
// spellbook last page battle index is not reset after battle, so this needs to stay here
|
2016-10-16 14:27:35 +02:00
|
|
|
vstd::abetween(cp, 0, std::max(0, pagesWithinCurrentTab() - 1));
|
|
|
|
setCurrentPage(cp);
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2012-06-02 18:16:54 +03:00
|
|
|
addUsedEvents(KEYBOARD);
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CSpellWindow::~CSpellWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fexitb()
|
|
|
|
{
|
2016-10-17 04:42:29 +02:00
|
|
|
(myInt->battleInt ? myInt->spellbookSettings.spellbookLastTabBattle : myInt->spellbookSettings.spellbookLastTabAdvmap) = selectedTab;
|
|
|
|
(myInt->battleInt ? myInt->spellbookSettings.spellbookLastPageBattle : myInt->spellbookSettings.spellbokLastPageAdvmap) = currentPage;
|
2010-07-21 13:09:29 +03:00
|
|
|
|
2018-07-25 00:36:48 +02:00
|
|
|
close();
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
2008-09-11 15:29:22 +03:00
|
|
|
void CSpellWindow::fadvSpellsb()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(battleSpellsOnly == true)
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
2009-06-20 04:42:19 +03:00
|
|
|
turnPageRight();
|
2009-06-20 05:14:25 +03:00
|
|
|
battleSpellsOnly = false;
|
2016-10-16 14:27:35 +02:00
|
|
|
setCurrentPage(0);
|
2009-06-20 05:14:25 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fbattleSpellsb()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(battleSpellsOnly == false)
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
2009-06-20 04:42:19 +03:00
|
|
|
turnPageLeft();
|
2009-06-20 05:14:25 +03:00
|
|
|
battleSpellsOnly = true;
|
2016-10-16 14:27:35 +02:00
|
|
|
setCurrentPage(0);
|
2009-06-20 05:14:25 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fmanaPtsb()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
void CSpellWindow::selectSchool(int school)
|
2008-09-11 15:29:22 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(selectedTab != school)
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(selectedTab < school)
|
2013-10-27 16:05:01 +03:00
|
|
|
turnPageLeft();
|
|
|
|
else
|
|
|
|
turnPageRight();
|
2010-07-21 13:09:29 +03:00
|
|
|
selectedTab = school;
|
2018-04-07 13:34:11 +02:00
|
|
|
schoolTab->setFrame(selectedTab, 0);
|
2016-10-16 14:27:35 +02:00
|
|
|
setCurrentPage(0);
|
2009-06-20 05:14:25 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-12 16:06:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fLcornerb()
|
|
|
|
{
|
2014-03-07 16:21:09 +03:00
|
|
|
if(currentPage>0)
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
2009-06-20 04:42:19 +03:00
|
|
|
turnPageLeft();
|
2016-10-16 14:27:35 +02:00
|
|
|
setCurrentPage(currentPage - 1);
|
2009-06-20 04:42:19 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2010-07-21 13:09:29 +03:00
|
|
|
GH.breakEventHandling();
|
2008-09-12 16:06:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fRcornerb()
|
|
|
|
{
|
2014-03-07 16:21:09 +03:00
|
|
|
if((currentPage + 1) < (pagesWithinCurrentTab()))
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
2009-06-20 04:42:19 +03:00
|
|
|
turnPageRight();
|
2016-10-16 14:27:35 +02:00
|
|
|
setCurrentPage(currentPage + 1);
|
2009-06-20 04:42:19 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2010-07-21 13:09:29 +03:00
|
|
|
GH.breakEventHandling();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
2012-09-30 13:35:17 +03:00
|
|
|
void CSpellWindow::show(SDL_Surface * to)
|
|
|
|
{
|
|
|
|
statusBar->show(to);
|
|
|
|
}
|
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
void CSpellWindow::computeSpellsPerArea()
|
|
|
|
{
|
2016-10-16 09:32:12 +02:00
|
|
|
std::vector<const CSpell *> spellsCurSite;
|
|
|
|
spellsCurSite.reserve(mySpells.size());
|
|
|
|
for(const CSpell * spell : mySpells)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
if(spell->isCombat() ^ !battleSpellsOnly
|
2016-10-16 09:32:12 +02:00
|
|
|
&& ((selectedTab == 4) || spell->school.at((ESpellSchool)selectedTab))
|
2008-09-15 19:46:54 +03:00
|
|
|
)
|
|
|
|
{
|
2016-10-16 09:32:12 +02:00
|
|
|
spellsCurSite.push_back(spell);
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
2016-10-16 09:32:12 +02:00
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
if(selectedTab == 4)
|
|
|
|
{
|
|
|
|
if(spellsCurSite.size() > 12)
|
|
|
|
{
|
2016-10-16 09:32:12 +02:00
|
|
|
spellsCurSite = std::vector<const CSpell *>(spellsCurSite.begin() + currentPage*12, spellsCurSite.end());
|
2008-09-15 19:46:54 +03:00
|
|
|
if(spellsCurSite.size() > 12)
|
|
|
|
{
|
|
|
|
spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //selectedTab == 0, 1, 2 or 3
|
|
|
|
{
|
|
|
|
if(spellsCurSite.size() > 10)
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
if(currentPage == 0)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
|
|
|
spellsCurSite.erase(spellsCurSite.begin()+10, spellsCurSite.end());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-16 09:32:12 +02:00
|
|
|
spellsCurSite = std::vector<const CSpell *>(spellsCurSite.begin() + (currentPage-1)*12 + 10, spellsCurSite.end());
|
2008-09-15 19:46:54 +03:00
|
|
|
if(spellsCurSite.size() > 12)
|
|
|
|
{
|
|
|
|
spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//applying
|
2010-07-21 13:09:29 +03:00
|
|
|
if(selectedTab == 4 || currentPage != 0)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t c=0; c<12; ++c)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2016-10-16 09:32:12 +02:00
|
|
|
if(c < spellsCurSite.size())
|
2008-12-23 15:59:03 +02:00
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
spellAreas[c]->setSpell(spellsCurSite[c]);
|
2008-12-23 15:59:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-16 09:32:12 +02:00
|
|
|
spellAreas[c]->setSpell(nullptr);
|
2008-12-23 15:59:03 +02:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-16 09:32:12 +02:00
|
|
|
spellAreas[0]->setSpell(nullptr);
|
|
|
|
spellAreas[1]->setSpell(nullptr);
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t c=0; c<10; ++c)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2016-10-16 09:32:12 +02:00
|
|
|
if(c < spellsCurSite.size())
|
2010-07-21 13:09:29 +03:00
|
|
|
spellAreas[c+2]->setSpell(spellsCurSite[c]);
|
2008-09-15 19:46:54 +03:00
|
|
|
else
|
2016-10-16 09:32:12 +02:00
|
|
|
spellAreas[c+2]->setSpell(nullptr);
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
redraw();
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
2016-10-16 14:27:35 +02:00
|
|
|
void CSpellWindow::setCurrentPage(int value)
|
|
|
|
{
|
|
|
|
currentPage = value;
|
2018-04-07 13:34:11 +02:00
|
|
|
schoolPicture->visible = selectedTab!=4 && currentPage == 0;
|
2016-10-16 14:27:35 +02:00
|
|
|
if(selectedTab != 4)
|
2018-04-07 13:34:11 +02:00
|
|
|
schoolPicture->setFrame(selectedTab, 0);
|
2016-10-16 14:27:35 +02:00
|
|
|
leftCorner->visible = currentPage != 0;
|
|
|
|
rightCorner->visible = (currentPage+1) < pagesWithinCurrentTab();
|
2016-10-17 03:05:33 +02:00
|
|
|
|
2023-03-09 15:36:46 +02:00
|
|
|
mana->setText(std::to_string(myHero->mana));//just in case, it will be possible to cast spell without closing book
|
2016-10-16 14:27:35 +02:00
|
|
|
}
|
|
|
|
|
2009-06-20 04:42:19 +03:00
|
|
|
void CSpellWindow::turnPageLeft()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(settings["video"]["spellbookAnimation"].Bool())
|
2018-07-25 00:36:48 +02:00
|
|
|
CCS->videoh->openAndPlayVideo("PGTRNLFT.SMK", pos.x+13, pos.y+15);
|
2009-06-20 04:42:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::turnPageRight()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(settings["video"]["spellbookAnimation"].Bool())
|
2018-07-25 00:36:48 +02:00
|
|
|
CCS->videoh->openAndPlayVideo("PGTRNRGH.SMK", pos.x+13, pos.y+15);
|
2009-06-20 04:42:19 +03:00
|
|
|
}
|
|
|
|
|
2023-02-02 18:42:44 +02:00
|
|
|
void CSpellWindow::keyPressed(const SDL_Keycode & key)
|
2009-07-03 22:57:14 +03:00
|
|
|
{
|
2023-02-02 18:02:25 +02:00
|
|
|
if(key == SDLK_ESCAPE || key == SDLK_RETURN)
|
2015-04-11 08:24:51 +02:00
|
|
|
{
|
2009-07-03 22:57:14 +03:00
|
|
|
fexitb();
|
2015-04-11 08:24:51 +02:00
|
|
|
return;
|
2016-02-02 10:11:54 +02:00
|
|
|
}
|
2023-02-02 18:02:25 +02:00
|
|
|
else
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
2023-02-02 18:02:25 +02:00
|
|
|
switch(key)
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
|
|
|
case SDLK_LEFT:
|
|
|
|
fLcornerb();
|
|
|
|
break;
|
|
|
|
case SDLK_RIGHT:
|
|
|
|
fRcornerb();
|
|
|
|
break;
|
|
|
|
case SDLK_UP:
|
|
|
|
case SDLK_DOWN:
|
2010-08-27 19:20:35 +03:00
|
|
|
{
|
2023-02-02 18:02:25 +02:00
|
|
|
bool down = key == SDLK_DOWN;
|
2011-12-14 00:23:17 +03:00
|
|
|
static const int schoolsOrder[] = { 0, 3, 1, 2, 4 };
|
2010-07-21 13:09:29 +03:00
|
|
|
int index = -1;
|
|
|
|
while(schoolsOrder[++index] != selectedTab);
|
|
|
|
index += (down ? 1 : -1);
|
2011-12-14 00:23:17 +03:00
|
|
|
vstd::abetween(index, 0, ARRAY_COUNT(schoolsOrder) - 1);
|
2010-07-21 13:09:29 +03:00
|
|
|
if(selectedTab != schoolsOrder[index])
|
|
|
|
selectSchool(schoolsOrder[index]);
|
|
|
|
break;
|
|
|
|
}
|
2012-09-30 15:19:14 +03:00
|
|
|
case SDLK_c:
|
|
|
|
fbattleSpellsb();
|
|
|
|
break;
|
|
|
|
case SDLK_a:
|
|
|
|
fadvSpellsb();
|
|
|
|
break;
|
2010-08-27 19:20:35 +03:00
|
|
|
default://to get rid of warnings
|
|
|
|
break;
|
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
|
|
|
|
//alt + 1234567890-= casts spell from 1 - 12 slot
|
2023-02-02 16:15:39 +02:00
|
|
|
if(GH.isKeyboardAltDown())
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
2023-02-02 18:02:25 +02:00
|
|
|
SDL_Keycode hlpKey = key;
|
2011-12-17 21:59:59 +03:00
|
|
|
if(CGuiHandler::isNumKey(hlpKey, false))
|
2010-07-21 22:50:15 +03:00
|
|
|
{
|
|
|
|
if(hlpKey == SDLK_KP_PLUS)
|
|
|
|
hlpKey = SDLK_EQUALS;
|
|
|
|
else
|
2011-12-17 21:59:59 +03:00
|
|
|
hlpKey = CGuiHandler::numToDigit(hlpKey);
|
2010-07-21 22:50:15 +03:00
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
|
2015-06-21 00:38:05 +02:00
|
|
|
static const SDL_Keycode spellSelectors[] = {SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS};
|
2010-07-21 13:09:29 +03:00
|
|
|
|
|
|
|
int index = -1;
|
|
|
|
while(++index < ARRAY_COUNT(spellSelectors) && spellSelectors[index] != hlpKey);
|
|
|
|
if(index >= ARRAY_COUNT(spellSelectors))
|
|
|
|
return;
|
|
|
|
|
|
|
|
//try casting spell
|
|
|
|
spellAreas[index]->clickLeft(false, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-16 08:03:13 +02:00
|
|
|
int CSpellWindow::pagesWithinCurrentTab()
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
|
|
|
return battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab];
|
2009-07-03 22:57:14 +03:00
|
|
|
}
|
|
|
|
|
2023-01-17 22:01:35 +02:00
|
|
|
CSpellWindow::SpellArea::SpellArea(Rect pos, CSpellWindow * owner)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
|
|
|
this->pos = pos;
|
|
|
|
this->owner = owner;
|
2012-06-02 18:16:54 +03:00
|
|
|
addUsedEvents(LCLICK | RCLICK | HOVER);
|
2010-07-21 13:09:29 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
schoolLevel = -1;
|
2016-10-16 09:32:12 +02:00
|
|
|
mySpell = nullptr;
|
2016-10-16 12:22:07 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2016-10-17 04:05:48 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
image = std::make_shared<CAnimImage>(owner->spellIcons, 0, 0);
|
2016-10-16 12:22:07 +02:00
|
|
|
image->visible = false;
|
2016-10-17 04:05:48 +02:00
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
name = std::make_shared<CLabel>(39, 70, FONT_TINY, ETextAlignment::CENTER);
|
|
|
|
level = std::make_shared<CLabel>(39, 82, FONT_TINY, ETextAlignment::CENTER);
|
|
|
|
cost = std::make_shared<CLabel>(39, 94, FONT_TINY, ETextAlignment::CENTER);
|
2016-10-18 01:15:43 +02:00
|
|
|
|
|
|
|
for(auto l : {name, level, cost})
|
2022-12-19 22:04:50 +02:00
|
|
|
l->setAutoRedraw(false);
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CSpellWindow::SpellArea::~SpellArea() = default;
|
2016-10-16 11:58:18 +02:00
|
|
|
|
2009-08-11 19:05:33 +03:00
|
|
|
void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2016-11-27 22:41:17 +02:00
|
|
|
if(mySpell && !down)
|
2008-10-17 19:30:56 +03:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
auto spellCost = owner->myInt->cb->getSpellCost(mySpell, owner->myHero);
|
2010-07-21 13:09:29 +03:00
|
|
|
if(spellCost > owner->myHero->mana) //insufficient mana
|
|
|
|
{
|
2016-10-01 17:18:46 +02:00
|
|
|
owner->myInt->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[206]) % spellCost % owner->myHero->mana));
|
2010-07-26 23:56:39 +03:00
|
|
|
return;
|
2010-07-21 13:09:29 +03:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
//anything that is not combat spell is adventure spell
|
|
|
|
//this not an error in general to cast even creature ability with hero
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const bool combatSpell = mySpell->isCombat();
|
|
|
|
if(combatSpell == mySpell->isAdventure())
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
logGlobal->error("Spell have invalid flags");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool inCombat = owner->myInt->battleInt != nullptr;
|
|
|
|
const bool inCastle = owner->myInt->castleInt != nullptr;
|
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
//battle spell on adv map or adventure map spell during combat => display infowindow, not cast
|
2017-07-20 06:08:49 +02:00
|
|
|
if((combatSpell ^ inCombat) || inCastle)
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
std::vector<std::shared_ptr<CComponent>> hlp(1, std::make_shared<CComponent>(CComponent::spell, mySpell->id, 0));
|
2023-01-02 00:06:42 +02:00
|
|
|
owner->myInt->showInfoDialog(mySpell->getDescriptionTranslated(schoolLevel), hlp);
|
2010-07-21 13:09:29 +03:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
else if(combatSpell)
|
2008-10-17 20:43:25 +03:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
spells::detail::ProblemImpl problem;
|
|
|
|
if(mySpell->canBeCast(problem, owner->myInt->cb.get(), spells::Mode::HERO, owner->myHero))
|
2011-02-10 16:44:21 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
owner->myInt->battleInt->castThisSpell(mySpell->id);
|
|
|
|
owner->fexitb();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<std::string> texts;
|
|
|
|
problem.getAll(texts);
|
|
|
|
if(!texts.empty())
|
|
|
|
owner->myInt->showInfoDialog(texts.front());
|
|
|
|
else
|
2022-12-27 22:19:05 +02:00
|
|
|
owner->myInt->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.spellUnknownProblem"));
|
2011-02-10 16:44:21 +02:00
|
|
|
}
|
2008-10-17 20:43:25 +03:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
else //adventure spell
|
2010-01-29 18:19:12 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
const CGHeroInstance * h = owner->myHero;
|
2018-07-25 00:36:48 +02:00
|
|
|
GH.popInts(1);
|
2016-02-02 10:11:54 +02:00
|
|
|
|
2017-07-19 01:06:05 +02:00
|
|
|
auto guard = vstd::makeScopeGuard([this]()
|
2015-04-11 08:24:51 +02:00
|
|
|
{
|
2017-07-03 20:38:00 +02:00
|
|
|
owner->myInt->spellbookSettings.spellbookLastTabAdvmap = owner->selectedTab;
|
|
|
|
owner->myInt->spellbookSettings.spellbokLastPageAdvmap = owner->currentPage;
|
2016-02-02 10:11:54 +02:00
|
|
|
});
|
2010-03-11 01:16:30 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(mySpell->getTargetType() == spells::AimType::LOCATION)
|
2016-10-16 09:32:12 +02:00
|
|
|
adventureInt->enterCastingMode(mySpell);
|
2017-07-20 06:08:49 +02:00
|
|
|
else if(mySpell->getTargetType() == spells::AimType::NO_TARGET)
|
2016-10-17 04:42:29 +02:00
|
|
|
owner->myInt->cb->castSpell(h, mySpell->id);
|
2015-01-30 09:05:52 +02:00
|
|
|
else
|
|
|
|
logGlobal->error("Invalid spell target type");
|
2010-01-29 18:19:12 +02:00
|
|
|
}
|
2008-10-17 19:30:56 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
|
2009-08-11 19:05:33 +03:00
|
|
|
void CSpellWindow::SpellArea::clickRight(tribool down, bool previousState)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2016-11-27 22:41:17 +02:00
|
|
|
if(mySpell && down)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2009-11-08 16:44:58 +02:00
|
|
|
std::string dmgInfo;
|
2017-07-20 06:08:49 +02:00
|
|
|
auto causedDmg = owner->myInt->cb->estimateSpellDamage(mySpell, owner->myHero);
|
2016-10-16 09:32:12 +02:00
|
|
|
if(causedDmg == 0 || mySpell->id == SpellID::TITANS_LIGHTNING_BOLT) //Titan's Lightning Bolt already has damage info included
|
2022-11-15 02:20:55 +02:00
|
|
|
dmgInfo.clear();
|
2009-11-08 16:44:58 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
dmgInfo = CGI->generaltexth->allTexts[343];
|
2023-03-09 15:36:46 +02:00
|
|
|
boost::algorithm::replace_first(dmgInfo, "%d", std::to_string(causedDmg));
|
2009-11-08 16:44:58 +02:00
|
|
|
}
|
|
|
|
|
2023-01-02 00:06:42 +02:00
|
|
|
CRClickPopup::createAndPush(mySpell->getDescriptionTranslated(schoolLevel) + dmgInfo, std::make_shared<CComponent>(CComponent::spell, mySpell->id));
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::SpellArea::hover(bool on)
|
|
|
|
{
|
2016-10-16 09:32:12 +02:00
|
|
|
if(mySpell)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2008-09-16 18:23:44 +03:00
|
|
|
if(on)
|
2023-01-02 00:06:42 +02:00
|
|
|
owner->statusBar->write(boost::to_string(boost::format("%s (%s)") % mySpell->getNameTranslated() % CGI->generaltexth->allTexts[171+mySpell->level]));
|
2008-09-16 18:23:44 +03:00
|
|
|
else
|
|
|
|
owner->statusBar->clear();
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-16 09:32:12 +02:00
|
|
|
void CSpellWindow::SpellArea::setSpell(const CSpell * spell)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
schoolBorder.reset();
|
2016-10-16 12:22:07 +02:00
|
|
|
image->visible = false;
|
2016-10-17 04:05:48 +02:00
|
|
|
name->setText("");
|
|
|
|
level->setText("");
|
|
|
|
cost->setText("");
|
2016-10-16 09:32:12 +02:00
|
|
|
mySpell = spell;
|
|
|
|
if(mySpell)
|
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
int32_t whichSchool = 0; //0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic,
|
2016-10-16 09:32:12 +02:00
|
|
|
schoolLevel = owner->myHero->getSpellSchoolLevel(mySpell, &whichSchool);
|
2018-04-07 13:34:11 +02:00
|
|
|
auto spellCost = owner->myInt->cb->getSpellCost(mySpell, owner->myHero);
|
2016-10-16 09:43:49 +02:00
|
|
|
|
2016-10-16 12:22:07 +02:00
|
|
|
image->setFrame(mySpell->id);
|
|
|
|
image->visible = true;
|
2018-04-07 13:34:11 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
schoolBorder = std::make_shared<CAnimImage>(owner->schoolBorders[owner->selectedTab >= 4 ? whichSchool : owner->selectedTab], schoolLevel);
|
|
|
|
}
|
2016-10-17 04:05:48 +02:00
|
|
|
|
|
|
|
SDL_Color firstLineColor, secondLineColor;
|
|
|
|
if(spellCost > owner->myHero->mana) //hero cannot cast this spell
|
|
|
|
{
|
|
|
|
firstLineColor = Colors::WHITE;
|
2023-01-30 00:12:43 +02:00
|
|
|
secondLineColor = Colors::ORANGE;
|
2016-10-17 04:05:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
firstLineColor = Colors::YELLOW;
|
|
|
|
secondLineColor = Colors::WHITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
name->color = firstLineColor;
|
2023-01-02 00:06:42 +02:00
|
|
|
name->setText(mySpell->getNameTranslated());
|
2016-10-17 04:05:48 +02:00
|
|
|
|
|
|
|
level->color = secondLineColor;
|
|
|
|
if(schoolLevel > 0)
|
|
|
|
{
|
|
|
|
boost::format fmt("%s/%s");
|
|
|
|
fmt % CGI->generaltexth->allTexts[171 + mySpell->level];
|
2022-12-27 22:19:05 +02:00
|
|
|
fmt % CGI->generaltexth->levels[3+(schoolLevel-1)];//lines 4-6
|
2016-10-17 04:05:48 +02:00
|
|
|
level->setText(fmt.str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
level->setText(CGI->generaltexth->allTexts[171 + mySpell->level]);
|
|
|
|
|
|
|
|
cost->color = secondLineColor;
|
|
|
|
boost::format costfmt("%s: %d");
|
|
|
|
costfmt % CGI->generaltexth->allTexts[387] % spellCost;
|
|
|
|
cost->setText(costfmt.str());
|
2016-10-16 09:32:12 +02:00
|
|
|
}
|
2013-11-03 21:16:25 +03:00
|
|
|
}
|