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"
|
|
|
|
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "CAdvmapInterface.h"
|
2014-07-13 18:39:45 +03:00
|
|
|
#include "GUIClasses.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "InfoWindows.h"
|
2008-09-10 15:19:48 +03:00
|
|
|
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../CBitmapHandler.h"
|
|
|
|
#include "../CDefHandler.h"
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CMessage.h"
|
|
|
|
#include "../CMT.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
|
|
|
#include "../CVideoHandler.h"
|
|
|
|
#include "../Graphics.h"
|
|
|
|
|
|
|
|
#include "../battle/CBattleInterface.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../gui/CAnimation.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../gui/CGuiHandler.h"
|
|
|
|
#include "../gui/SDL_Extensions.h"
|
|
|
|
#include "../widgets/MiscWidgets.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../widgets/CComponent.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
|
|
|
|
#include "../../lib/BattleState.h"
|
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/CHeroHandler.h"
|
2015-02-02 10:25:26 +02:00
|
|
|
#include "../../lib/spells/CSpellHandler.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../../lib/GameConstants.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../../lib/CGameState.h"
|
|
|
|
#include "../../lib/mapObjects/CGTownInstance.h"
|
2008-09-10 15:19:48 +03:00
|
|
|
|
2009-04-15 17:03:31 +03: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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
SpellbookInteractiveArea::SpellbookInteractiveArea(const SDL_Rect & myRect, std::function<void()> funcL,
|
|
|
|
const std::string & textR, std::function<void()> funcHon, std::function<void()> funcHoff, CPlayerInterface * _myInt)
|
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;
|
|
|
|
textOnRclick = textR;
|
|
|
|
onHoverOn = funcHon;
|
|
|
|
onHoverOff = funcHoff;
|
2010-02-19 18:02:34 +02:00
|
|
|
myInt = _myInt;
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
2009-08-11 19:05:33 +03:00
|
|
|
void SpellbookInteractiveArea::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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-11 19:05:33 +03:00
|
|
|
void SpellbookInteractiveArea::clickRight(tribool down, bool previousState)
|
2008-09-11 15:29:22 +03:00
|
|
|
{
|
2010-03-21 00:17:19 +02:00
|
|
|
adventureInt->handleRightClick(textOnRclick, down);
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpellbookInteractiveArea::hover(bool on)
|
|
|
|
{
|
2009-08-11 19:05:33 +03:00
|
|
|
//Hoverable::hover(on);
|
2008-09-11 15:29:22 +03:00
|
|
|
if(on)
|
|
|
|
{
|
|
|
|
onHoverOn();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
onHoverOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-15 20:08:19 +03:00
|
|
|
CSpellWindow::CSpellWindow(const SDL_Rect &, const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells):
|
|
|
|
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
|
|
|
{
|
* 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
|
2014-03-07 16:21:09 +03:00
|
|
|
for(ui32 v=0; v<CGI->spellh->objects.size(); ++v)
|
* 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
|
|
|
{
|
2014-03-07 16:21:09 +03:00
|
|
|
if( !CGI->spellh->objects[v]->creatureAbility && myHero->canCastThisSpell(CGI->spellh->objects[v]) )
|
2013-02-11 02:24:57 +03:00
|
|
|
mySpells.insert(SpellID(v));
|
* 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
|
|
|
}
|
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
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto g : mySpells)
|
2008-09-12 16:06:53 +03:00
|
|
|
{
|
2014-03-07 16:21:09 +03:00
|
|
|
const CSpell &s = *CGI->spellh->objects[g];
|
2010-07-21 13:09:29 +03:00
|
|
|
Uint8 *sitesPerOurTab = s.combatSpell ? sitesPerTabBattle : sitesPerTabAdv;
|
2008-09-15 19:46:54 +03:00
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
++sitesPerOurTab[4];
|
2015-01-30 08:39:36 +02:00
|
|
|
|
|
|
|
s.forEachSchool([&sitesPerOurTab](const SpellSchoolInfo & school, bool & stop)
|
|
|
|
{
|
|
|
|
++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
|
|
|
|
|
|
|
|
leftCorner = BitmapHandler::loadBitmap("SpelTrnL.bmp", true);
|
|
|
|
rightCorner = BitmapHandler::loadBitmap("SpelTrnR.bmp", true);
|
2014-03-10 19:00:58 +03:00
|
|
|
|
|
|
|
spells = new CAnimation("Spells.def");
|
|
|
|
|
2008-09-10 15:19:48 +03:00
|
|
|
spellTab = CDefHandler::giveDef("SpelTab.def");
|
|
|
|
schools = CDefHandler::giveDef("Schools.def");
|
2008-09-15 19:46:54 +03:00
|
|
|
schoolBorders[0] = CDefHandler::giveDef("SplevA.def");
|
|
|
|
schoolBorders[1] = CDefHandler::giveDef("SplevF.def");
|
|
|
|
schoolBorders[2] = CDefHandler::giveDef("SplevW.def");
|
|
|
|
schoolBorders[3] = CDefHandler::giveDef("SplevE.def");
|
2008-09-10 15:19:48 +03:00
|
|
|
|
2008-09-11 15:29:22 +03:00
|
|
|
|
|
|
|
|
2012-12-22 23:05:08 +03:00
|
|
|
statusBar = new CGStatusBar(7 + pos.x, 569 + pos.y, "Spelroll.bmp");
|
2009-01-07 21:40:19 +02:00
|
|
|
SDL_Rect temp_rect = genRect(45, 35, 479 + pos.x, 405 + pos.y);
|
2014-08-04 21:33:59 +03:00
|
|
|
exitBtn = new SpellbookInteractiveArea(temp_rect, std::bind(&CSpellWindow::fexitb, this), CGI->generaltexth->zelp[460].second, std::bind(&CGStatusBar::setText, statusBar, (CGI->generaltexth->zelp[460].first)), std::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(45, 35, 221 + pos.x, 405 + pos.y);
|
2014-08-04 21:33:59 +03:00
|
|
|
battleSpells = new SpellbookInteractiveArea(temp_rect, std::bind(&CSpellWindow::fbattleSpellsb, this), CGI->generaltexth->zelp[453].second, std::bind(&CGStatusBar::setText, statusBar, (CGI->generaltexth->zelp[453].first)), std::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(45, 35, 355 + pos.x, 405 + pos.y);
|
2014-08-04 21:33:59 +03:00
|
|
|
adventureSpells = new SpellbookInteractiveArea(temp_rect, std::bind(&CSpellWindow::fadvSpellsb, this), CGI->generaltexth->zelp[452].second, std::bind(&CGStatusBar::setText, statusBar, (CGI->generaltexth->zelp[452].first)), std::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(45, 35, 418 + pos.x, 405 + pos.y);
|
2014-08-04 21:33:59 +03:00
|
|
|
manaPoints = new SpellbookInteractiveArea(temp_rect, std::bind(&CSpellWindow::fmanaPtsb, this), CGI->generaltexth->zelp[459].second, std::bind(&CGStatusBar::setText, statusBar, (CGI->generaltexth->zelp[459].first)), std::bind(&CGStatusBar::clear, statusBar), myInt);
|
2008-09-11 15:29:22 +03:00
|
|
|
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 94 + pos.y);
|
2014-08-04 21:33:59 +03:00
|
|
|
selectSpellsA = new SpellbookInteractiveArea(temp_rect, std::bind(&CSpellWindow::selectSchool, this, 0), CGI->generaltexth->zelp[454].second, std::bind(&CGStatusBar::setText, statusBar, (CGI->generaltexth->zelp[454].first)), std::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 151 + pos.y);
|
2014-08-04 21:33:59 +03:00
|
|
|
selectSpellsE = new SpellbookInteractiveArea(temp_rect, std::bind(&CSpellWindow::selectSchool, this, 3), CGI->generaltexth->zelp[457].second, std::bind(&CGStatusBar::setText, statusBar, (CGI->generaltexth->zelp[457].first)), std::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 210 + pos.y);
|
2014-08-04 21:33:59 +03:00
|
|
|
selectSpellsF = new SpellbookInteractiveArea(temp_rect, std::bind(&CSpellWindow::selectSchool, this, 1), CGI->generaltexth->zelp[455].second, std::bind(&CGStatusBar::setText, statusBar, (CGI->generaltexth->zelp[455].first)), std::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 270 + pos.y);
|
2014-08-04 21:33:59 +03:00
|
|
|
selectSpellsW = new SpellbookInteractiveArea(temp_rect, std::bind(&CSpellWindow::selectSchool, this, 2), CGI->generaltexth->zelp[456].second, std::bind(&CGStatusBar::setText, statusBar, (CGI->generaltexth->zelp[456].first)), std::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(36, 56, 549 + pos.x, 330 + pos.y);
|
2014-08-04 21:33:59 +03:00
|
|
|
selectSpellsAll = new SpellbookInteractiveArea(temp_rect, std::bind(&CSpellWindow::selectSchool, this, 4), CGI->generaltexth->zelp[458].second, std::bind(&CGStatusBar::setText, statusBar, (CGI->generaltexth->zelp[458].first)), std::bind(&CGStatusBar::clear, statusBar), myInt);
|
2008-09-12 16:06:53 +03:00
|
|
|
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(leftCorner->h, leftCorner->w, 97 + pos.x, 77 + pos.y);
|
2014-08-04 21:33:59 +03:00
|
|
|
lCorner = new SpellbookInteractiveArea(temp_rect, std::bind(&CSpellWindow::fLcornerb, this), CGI->generaltexth->zelp[450].second, std::bind(&CGStatusBar::setText, statusBar, (CGI->generaltexth->zelp[450].first)), std::bind(&CGStatusBar::clear, statusBar), myInt);
|
2009-01-07 21:40:19 +02:00
|
|
|
temp_rect = genRect(rightCorner->h, rightCorner->w, 487 + pos.x, 72 + pos.y);
|
2014-08-04 21:33:59 +03:00
|
|
|
rCorner = new SpellbookInteractiveArea(temp_rect, std::bind(&CSpellWindow::fRcornerb, this), CGI->generaltexth->zelp[451].second, std::bind(&CGStatusBar::setText, statusBar, (CGI->generaltexth->zelp[451].first)), std::bind(&CGStatusBar::clear, statusBar), myInt);
|
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)
|
|
|
|
{
|
|
|
|
temp_rect = genRect(65, 78, xpos, ypos);
|
|
|
|
spellAreas[v] = new SpellArea(temp_rect, this);
|
|
|
|
|
|
|
|
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;
|
|
|
|
currentPage = battleSpellsOnly ? myInt->spellbookSettings.spellbookLastPageBattle : myInt->spellbookSettings.spellbokLastPageAdvmap;
|
|
|
|
|
|
|
|
// spellbook last page battle index is not reset after battle, so this needs to stay here
|
|
|
|
vstd::abetween(currentPage, 0, pagesWithinCurrentTab() - 1);
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(leftCorner);
|
|
|
|
SDL_FreeSurface(rightCorner);
|
2014-03-10 19:00:58 +03:00
|
|
|
spells->unload();
|
2008-09-10 15:19:48 +03:00
|
|
|
delete spells;
|
|
|
|
delete spellTab;
|
|
|
|
delete schools;
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : schoolBorders)
|
|
|
|
delete elem;
|
2008-09-10 15:19:48 +03:00
|
|
|
|
|
|
|
delete exitBtn;
|
2008-09-11 15:29:22 +03:00
|
|
|
delete battleSpells;
|
|
|
|
delete adventureSpells;
|
|
|
|
delete manaPoints;
|
2008-09-10 15:19:48 +03:00
|
|
|
delete statusBar;
|
2008-09-11 15:29:22 +03:00
|
|
|
|
|
|
|
delete selectSpellsA;
|
|
|
|
delete selectSpellsE;
|
|
|
|
delete selectSpellsF;
|
|
|
|
delete selectSpellsW;
|
|
|
|
delete selectSpellsAll;
|
2008-09-12 16:06:53 +03:00
|
|
|
|
|
|
|
delete lCorner;
|
|
|
|
delete rCorner;
|
2008-09-15 19:46:54 +03:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : spellAreas)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
delete elem;
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fexitb()
|
|
|
|
{
|
2013-11-03 21:16:25 +03:00
|
|
|
(LOCPLINT->battleInt ? myInt->spellbookSettings.spellbookLastTabBattle : myInt->spellbookSettings.spellbookLastTabAdvmap) = selectedTab;
|
|
|
|
(LOCPLINT->battleInt ? myInt->spellbookSettings.spellbookLastPageBattle : myInt->spellbookSettings.spellbokLastPageAdvmap) = currentPage;
|
2010-07-21 13:09:29 +03:00
|
|
|
|
2009-08-07 01:36:51 +03:00
|
|
|
GH.popIntTotally(this);
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
2008-09-11 15:29:22 +03:00
|
|
|
void CSpellWindow::fadvSpellsb()
|
|
|
|
{
|
2014-03-07 16:21:09 +03: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;
|
2010-07-21 13:09:29 +03:00
|
|
|
currentPage = 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()
|
|
|
|
{
|
2014-03-07 16:21:09 +03: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;
|
2010-07-21 13:09:29 +03:00
|
|
|
currentPage = 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
|
|
|
{
|
2014-03-07 16:21:09 +03:00
|
|
|
if (selectedTab != school)
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
2013-10-27 16:05:01 +03:00
|
|
|
if (selectedTab < school)
|
|
|
|
turnPageLeft();
|
|
|
|
else
|
|
|
|
turnPageRight();
|
2010-07-21 13:09:29 +03:00
|
|
|
selectedTab = school;
|
|
|
|
currentPage = 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();
|
2010-07-21 13:09:29 +03:00
|
|
|
--currentPage;
|
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();
|
2010-07-21 13:09:29 +03:00
|
|
|
++currentPage;
|
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
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
void CSpellWindow::showAll(SDL_Surface * to)
|
2008-09-10 15:19:48 +03:00
|
|
|
{
|
2012-06-15 20:08:19 +03:00
|
|
|
CWindowObject::showAll(to);
|
2009-06-20 05:14:25 +03:00
|
|
|
blitAt(spellTab->ourImages[selectedTab].bitmap, 524 + pos.x, 88 + pos.y, to);
|
2010-02-02 18:24:53 +02:00
|
|
|
|
|
|
|
std::ostringstream mana;
|
|
|
|
mana<<myHero->mana;
|
2012-12-19 20:24:53 +03:00
|
|
|
printAtMiddleLoc(mana.str(), 435, 426, FONT_SMALL, Colors::YELLOW, to);
|
2014-03-07 16:21:09 +03:00
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
statusBar->showAll(to);
|
2008-09-12 16:06:53 +03:00
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
//printing school images
|
2010-07-21 13:09:29 +03:00
|
|
|
if(selectedTab!=4 && currentPage == 0)
|
2008-09-12 16:06:53 +03:00
|
|
|
{
|
2009-01-07 21:40:19 +02:00
|
|
|
blitAt(schools->ourImages[selectedTab].bitmap, 117 + pos.x, 74 + pos.y, to);
|
2008-09-12 16:06:53 +03:00
|
|
|
}
|
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
//printing corners
|
2010-07-21 13:09:29 +03:00
|
|
|
if(currentPage!=0)
|
2008-09-12 16:06:53 +03:00
|
|
|
{
|
|
|
|
blitAt(leftCorner, lCorner->pos.x, lCorner->pos.y, to);
|
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
if((currentPage+1) < (pagesWithinCurrentTab()) )
|
2008-09-12 16:06:53 +03:00
|
|
|
{
|
|
|
|
blitAt(rightCorner, rCorner->pos.x, rCorner->pos.y, to);
|
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
|
|
|
|
//printing spell info
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : spellAreas)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
elem->showAll(to);
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-30 13:35:17 +03:00
|
|
|
void CSpellWindow::show(SDL_Surface * to)
|
|
|
|
{
|
|
|
|
statusBar->show(to);
|
|
|
|
}
|
|
|
|
|
2008-09-16 18:23:44 +03:00
|
|
|
class SpellbookSpellSorter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool operator()(const int & a, const int & b)
|
|
|
|
{
|
2014-03-07 16:21:09 +03:00
|
|
|
const CSpell & A = *CGI->spellh->objects[a];
|
|
|
|
const CSpell & B = *CGI->spellh->objects[b];
|
2008-09-16 18:23:44 +03:00
|
|
|
if(A.level<B.level)
|
|
|
|
return true;
|
|
|
|
if(A.level>B.level)
|
2015-01-30 08:39:36 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-09-16 18:23:44 +03:00
|
|
|
return A.name < B.name;
|
|
|
|
}
|
|
|
|
} spellsorter;
|
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
void CSpellWindow::computeSpellsPerArea()
|
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
std::vector<SpellID> spellsCurSite;
|
2015-01-30 08:39:36 +02:00
|
|
|
for(const SpellID & spellID : mySpells)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2015-01-30 08:39:36 +02:00
|
|
|
CSpell * s = spellID.toSpell();
|
|
|
|
|
|
|
|
if(s->combatSpell ^ !battleSpellsOnly
|
|
|
|
&& ((selectedTab == 4) || (s->school[(ESpellSchool)selectedTab]))
|
2008-09-15 19:46:54 +03:00
|
|
|
)
|
|
|
|
{
|
2015-01-30 08:39:36 +02:00
|
|
|
spellsCurSite.push_back(spellID);
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
2008-09-16 18:23:44 +03:00
|
|
|
std::sort(spellsCurSite.begin(), spellsCurSite.end(), spellsorter);
|
2008-09-15 19:46:54 +03:00
|
|
|
if(selectedTab == 4)
|
|
|
|
{
|
|
|
|
if(spellsCurSite.size() > 12)
|
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
spellsCurSite = std::vector<SpellID>(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
|
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
spellsCurSite = std::vector<SpellID>(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
|
|
|
{
|
2008-12-23 15:59:03 +02:00
|
|
|
if(c<spellsCurSite.size())
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
spellAreas[c]->setSpell(spellsCurSite[c]);
|
2008-12-23 15:59:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
spellAreas[c]->setSpell(SpellID::NONE);
|
2008-12-23 15:59:03 +02:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-11 02:24:57 +03:00
|
|
|
spellAreas[0]->setSpell(SpellID::NONE);
|
|
|
|
spellAreas[1]->setSpell(SpellID::NONE);
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t c=0; c<10; ++c)
|
2008-09-15 19:46:54 +03: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
|
2013-02-11 02:24:57 +03:00
|
|
|
spellAreas[c+2]->setSpell(SpellID::NONE);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::activate()
|
|
|
|
{
|
2012-06-02 18:16:54 +03:00
|
|
|
CIntObject::activate();
|
2008-09-10 15:19:48 +03:00
|
|
|
exitBtn->activate();
|
2008-09-11 15:29:22 +03:00
|
|
|
battleSpells->activate();
|
|
|
|
adventureSpells->activate();
|
|
|
|
manaPoints->activate();
|
|
|
|
|
|
|
|
selectSpellsA->activate();
|
|
|
|
selectSpellsE->activate();
|
|
|
|
selectSpellsF->activate();
|
|
|
|
selectSpellsW->activate();
|
|
|
|
selectSpellsAll->activate();
|
2008-09-12 16:06:53 +03:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : spellAreas)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
elem->activate();
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
|
|
|
|
lCorner->activate();
|
|
|
|
rCorner->activate();
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::deactivate()
|
|
|
|
{
|
2012-06-02 18:16:54 +03:00
|
|
|
CIntObject::deactivate();
|
2008-09-10 15:19:48 +03:00
|
|
|
exitBtn->deactivate();
|
2008-09-11 15:29:22 +03:00
|
|
|
battleSpells->deactivate();
|
|
|
|
adventureSpells->deactivate();
|
|
|
|
manaPoints->deactivate();
|
|
|
|
|
|
|
|
selectSpellsA->deactivate();
|
|
|
|
selectSpellsE->deactivate();
|
|
|
|
selectSpellsF->deactivate();
|
|
|
|
selectSpellsW->deactivate();
|
|
|
|
selectSpellsAll->deactivate();
|
2008-09-15 19:46:54 +03:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : spellAreas)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
elem->deactivate();
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
|
|
|
|
lCorner->deactivate();
|
|
|
|
rCorner->deactivate();
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
|
2009-06-20 04:42:19 +03:00
|
|
|
void CSpellWindow::turnPageLeft()
|
|
|
|
{
|
2013-10-27 16:05:01 +03:00
|
|
|
if (settings["video"]["spellbookAnimation"].Bool())
|
|
|
|
CCS->videoh->openAndPlayVideo("PGTRNLFT.SMK", pos.x+13, pos.y+15, screen);
|
2009-06-20 04:42:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::turnPageRight()
|
|
|
|
{
|
2013-10-27 16:05:01 +03:00
|
|
|
if (settings["video"]["spellbookAnimation"].Bool())
|
|
|
|
CCS->videoh->openAndPlayVideo("PGTRNRGH.SMK", pos.x+13, pos.y+15, screen);
|
2009-06-20 04:42:19 +03:00
|
|
|
}
|
|
|
|
|
2009-07-03 22:57:14 +03:00
|
|
|
void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key)
|
|
|
|
{
|
|
|
|
if(key.keysym.sym == SDLK_ESCAPE || key.keysym.sym == 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;
|
|
|
|
}
|
2010-07-21 13:09:29 +03:00
|
|
|
|
|
|
|
if(key.state == SDL_PRESSED)
|
|
|
|
{
|
|
|
|
switch(key.keysym.sym)
|
|
|
|
{
|
|
|
|
case SDLK_LEFT:
|
|
|
|
fLcornerb();
|
|
|
|
break;
|
|
|
|
case SDLK_RIGHT:
|
|
|
|
fRcornerb();
|
|
|
|
break;
|
|
|
|
case SDLK_UP:
|
|
|
|
case SDLK_DOWN:
|
2010-08-27 19:20:35 +03:00
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
bool down = key.keysym.sym == 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
|
|
|
|
if(LOCPLINT->altPressed())
|
|
|
|
{
|
2015-06-21 00:38:05 +02:00
|
|
|
SDL_Keycode hlpKey = key.keysym.sym;
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Uint8 CSpellWindow::pagesWithinCurrentTab()
|
|
|
|
{
|
|
|
|
return battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab];
|
2009-07-03 22:57:14 +03:00
|
|
|
}
|
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
spellCost = whichSchool = schoolLevel = -1;
|
|
|
|
mySpell = SpellID::NONE;
|
2008-09-15 19:46:54 +03: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
|
|
|
{
|
2015-01-30 09:05:52 +02:00
|
|
|
if(!down && mySpell != SpellID::NONE)
|
2008-10-17 19:30:56 +03:00
|
|
|
{
|
2015-01-30 09:05:52 +02:00
|
|
|
const CSpell * sp = mySpell.toSpell();
|
2010-07-21 13:09:29 +03:00
|
|
|
|
2010-03-11 01:16:30 +02:00
|
|
|
int spellCost = owner->myInt->cb->getSpellCost(sp, owner->myHero);
|
2010-07-21 13:09:29 +03:00
|
|
|
if(spellCost > owner->myHero->mana) //insufficient mana
|
|
|
|
{
|
|
|
|
char msgBuf[500];
|
|
|
|
sprintf(msgBuf, CGI->generaltexth->allTexts[206].c_str(), spellCost, owner->myHero->mana);
|
|
|
|
owner->myInt->showInfoDialog(std::string(msgBuf));
|
2010-07-26 23:56:39 +03:00
|
|
|
return;
|
2010-07-21 13:09:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//battle spell on adv map or adventure map spell during combat => display infowindow, not cast
|
2015-01-30 09:05:52 +02:00
|
|
|
if((sp->isCombatSpell() && !owner->myInt->battleInt)
|
|
|
|
|| (sp->isAdventureSpell() && owner->myInt->battleInt))
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
2011-12-22 16:05:19 +03:00
|
|
|
std::vector<CComponent*> hlp(1, new CComponent(CComponent::spell, mySpell, 0));
|
2014-03-17 16:11:10 +03:00
|
|
|
LOCPLINT->showInfoDialog(sp->getLevelInfo(schoolLevel).description, hlp);
|
2010-07-21 13:09:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-17 20:43:25 +03:00
|
|
|
//we will cast a spell
|
2010-07-21 13:09:29 +03:00
|
|
|
if(sp->combatSpell && owner->myInt->battleInt && owner->myInt->cb->battleCanCastSpell()) //if battle window is open
|
2008-10-17 20:43:25 +03:00
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
ESpellCastProblem::ESpellCastProblem problem = owner->myInt->cb->battleCanCastThisSpell(sp);
|
2011-02-10 16:44:21 +02:00
|
|
|
switch (problem)
|
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
case ESpellCastProblem::OK:
|
2011-02-10 16:44:21 +02:00
|
|
|
{
|
2015-01-30 08:39:36 +02:00
|
|
|
owner->myInt->battleInt->castThisSpell(mySpell);
|
2015-04-11 08:24:51 +02:00
|
|
|
owner->fexitb();
|
|
|
|
return;
|
2011-02-10 16:44:21 +02:00
|
|
|
}
|
2011-02-21 15:27:31 +02:00
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case ESpellCastProblem::ANOTHER_ELEMENTAL_SUMMONED:
|
2011-02-10 16:44:21 +02:00
|
|
|
{
|
|
|
|
std::string text = CGI->generaltexth->allTexts[538], summoner, elemental, caster;
|
|
|
|
std::vector<const CStack *> stacks = owner->myInt->cb->battleGetStacks();
|
2013-06-29 16:05:48 +03:00
|
|
|
for(const CStack * s : stacks)
|
2011-02-15 21:54:55 +02:00
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
if(vstd::contains(s->state, EBattleStackState::SUMMONED))
|
2011-02-15 21:54:55 +02:00
|
|
|
{
|
|
|
|
elemental = s->getCreature()->namePl;
|
2013-01-20 23:29:35 +03:00
|
|
|
summoner = owner->myInt->cb->battleGetHeroInfo(!s->attackerOwned).name;
|
2011-02-15 21:54:55 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-02-10 16:44:21 +02:00
|
|
|
if (owner->myHero->type->sex)
|
|
|
|
{ //female
|
|
|
|
caster = CGI->generaltexth->allTexts[540];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ //male
|
|
|
|
caster = CGI->generaltexth->allTexts[539];
|
|
|
|
}
|
2011-02-15 21:54:55 +02:00
|
|
|
text = boost::str(boost::format(text) % summoner % elemental % caster);
|
|
|
|
|
2011-02-10 16:44:21 +02:00
|
|
|
|
|
|
|
owner->myInt->showInfoDialog(text);
|
|
|
|
}
|
2011-02-21 15:27:31 +02:00
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case ESpellCastProblem::SPELL_LEVEL_LIMIT_EXCEEDED:
|
2011-02-21 15:27:31 +02:00
|
|
|
{
|
2012-08-26 12:07:48 +03:00
|
|
|
//Recanter's Cloak or similar effect. Try to retrieve bonus
|
2012-09-20 19:55:21 +03:00
|
|
|
const Bonus *b = owner->myHero->getBonusLocalFirst(Selector::type(Bonus::BLOCK_MAGIC_ABOVE));
|
2012-08-26 12:07:48 +03:00
|
|
|
//TODO what about other values and non-artifact sources?
|
|
|
|
if(b && b->val == 2 && b->source == Bonus::ARTIFACT)
|
|
|
|
{
|
|
|
|
std::string artName = CGI->arth->artifacts[b->sid]->Name();
|
|
|
|
//The %s prevents %s from casting 3rd level or higher spells.
|
2014-03-07 16:21:09 +03:00
|
|
|
owner->myInt->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[536])
|
2012-08-26 12:07:48 +03:00
|
|
|
% artName % owner->myHero->name));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// General message:
|
|
|
|
// %s recites the incantations but they seem to have no effect.
|
|
|
|
std::string text = CGI->generaltexth->allTexts[541], caster = owner->myHero->name;
|
|
|
|
text = boost::str(boost::format(text) % caster);
|
|
|
|
owner->myInt->showInfoDialog(text);
|
|
|
|
}
|
2011-02-21 15:27:31 +02:00
|
|
|
}
|
|
|
|
break;
|
2011-12-14 00:23:17 +03:00
|
|
|
case ESpellCastProblem::NO_APPROPRIATE_TARGET:
|
2011-02-21 18:53:23 +02:00
|
|
|
{
|
|
|
|
owner->myInt->showInfoDialog(CGI->generaltexth->allTexts[185]);
|
|
|
|
}
|
|
|
|
break;
|
2011-02-10 16:44:21 +02:00
|
|
|
}
|
2008-10-17 20:43:25 +03:00
|
|
|
}
|
2015-01-30 09:05:52 +02:00
|
|
|
else if(sp->isAdventureSpell() && !owner->myInt->battleInt) //adventure spell and not in battle
|
2010-01-29 18:19:12 +02:00
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
const CGHeroInstance *h = owner->myHero;
|
2015-04-11 08:24:51 +02:00
|
|
|
GH.popInt(owner);
|
2015-01-30 09:05:52 +02:00
|
|
|
|
2015-04-11 08:24:51 +02:00
|
|
|
auto guard = vstd::makeScopeGuard([this]
|
|
|
|
{
|
|
|
|
(LOCPLINT->battleInt ? owner->myInt->spellbookSettings.spellbookLastTabBattle : owner->myInt->spellbookSettings.spellbookLastTabAdvmap) = owner->selectedTab;
|
|
|
|
(LOCPLINT->battleInt ? owner->myInt->spellbookSettings.spellbookLastPageBattle : owner->myInt->spellbookSettings.spellbokLastPageAdvmap) = owner->currentPage;
|
|
|
|
delete owner;
|
|
|
|
});
|
2010-03-11 01:16:30 +02:00
|
|
|
|
2015-01-30 09:05:52 +02:00
|
|
|
if(mySpell == SpellID::TOWN_PORTAL)
|
2010-07-21 13:09:29 +03:00
|
|
|
{
|
2015-01-30 09:05:52 +02:00
|
|
|
//special case
|
|
|
|
//todo: move to mechanics
|
|
|
|
|
|
|
|
std::vector <int> availableTowns;
|
2015-04-01 03:04:02 +02:00
|
|
|
std::vector <const CGTownInstance*> Towns = LOCPLINT->cb->getTownsInfo(false);
|
|
|
|
|
2015-04-01 03:48:50 +02:00
|
|
|
vstd::erase_if(Towns, [this](const CGTownInstance * t)
|
2015-04-01 03:04:02 +02:00
|
|
|
{
|
2015-04-01 03:48:50 +02:00
|
|
|
const auto relations = owner->myInt->cb->getPlayerRelations(t->tempOwner, owner->myInt->playerID);
|
2015-04-01 03:04:02 +02:00
|
|
|
return relations == PlayerRelations::ENEMIES;
|
|
|
|
});
|
2015-04-01 03:48:50 +02:00
|
|
|
|
2015-01-30 09:05:52 +02:00
|
|
|
if (Towns.empty())
|
2010-03-11 01:16:30 +02:00
|
|
|
{
|
2015-04-01 03:48:50 +02:00
|
|
|
owner->myInt->showInfoDialog(CGI->generaltexth->allTexts[124]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int movementCost = (h->getSpellSchoolLevel(sp) >= 3) ? 200 : 300;
|
|
|
|
|
|
|
|
if(h->movement < movementCost)
|
|
|
|
{
|
|
|
|
owner->myInt->showInfoDialog(CGI->generaltexth->allTexts[125]);
|
2015-01-30 09:05:52 +02:00
|
|
|
return;
|
2010-03-11 01:16:30 +02:00
|
|
|
}
|
2015-01-30 09:05:52 +02:00
|
|
|
|
|
|
|
if (h->getSpellSchoolLevel(sp) < 2) //not advanced or expert - teleport to nearest available city
|
2010-08-04 16:41:01 +03:00
|
|
|
{
|
2015-01-30 09:05:52 +02:00
|
|
|
auto nearest = Towns.cbegin(); //nearest town's iterator
|
|
|
|
si32 dist = LOCPLINT->cb->getTown((*nearest)->id)->pos.dist2dSQ(h->pos);
|
2010-08-04 16:41:01 +03:00
|
|
|
|
2015-01-30 09:05:52 +02:00
|
|
|
for (auto i = nearest + 1; i != Towns.cend(); ++i)
|
2010-08-04 16:41:01 +03:00
|
|
|
{
|
2015-01-30 09:05:52 +02:00
|
|
|
const CGTownInstance * dest = LOCPLINT->cb->getTown((*i)->id);
|
|
|
|
si32 curDist = dest->pos.dist2dSQ(h->pos);
|
2014-05-25 21:42:25 +03:00
|
|
|
|
2015-01-30 09:05:52 +02:00
|
|
|
if (curDist < dist)
|
2011-01-15 19:30:46 +02:00
|
|
|
{
|
2015-01-30 09:05:52 +02:00
|
|
|
nearest = i;
|
|
|
|
dist = curDist;
|
2011-01-15 19:30:46 +02:00
|
|
|
}
|
2010-08-04 16:41:01 +03:00
|
|
|
}
|
2015-01-30 09:05:52 +02:00
|
|
|
|
|
|
|
if ((*nearest)->visitingHero)
|
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[123]);
|
2010-08-04 16:41:01 +03:00
|
|
|
else
|
2015-01-30 09:05:52 +02:00
|
|
|
{
|
|
|
|
const CGTownInstance * town = LOCPLINT->cb->getTown((*nearest)->id);
|
|
|
|
LOCPLINT->cb->castSpell(h, mySpell, town->visitablePos());// - town->getVisitableOffset());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ //let the player choose
|
|
|
|
for(auto & Town : Towns)
|
|
|
|
{
|
|
|
|
const CGTownInstance *t = Town;
|
|
|
|
if (t->visitingHero == nullptr) //empty town and this is
|
2011-01-15 19:30:46 +02:00
|
|
|
{
|
2015-01-30 09:05:52 +02:00
|
|
|
availableTowns.push_back(t->id.getNum());//add to the list
|
2011-01-15 19:30:46 +02:00
|
|
|
}
|
2010-08-04 16:41:01 +03:00
|
|
|
}
|
2015-01-30 09:24:30 +02:00
|
|
|
|
|
|
|
auto castTownPortal = [h](int townId)
|
|
|
|
{
|
|
|
|
const CGTownInstance * dest = LOCPLINT->cb->getTown(ObjectInstanceID(townId));
|
|
|
|
LOCPLINT->cb->castSpell(h, SpellID::TOWN_PORTAL, dest->visitablePos());
|
|
|
|
};
|
|
|
|
|
2015-01-30 09:05:52 +02:00
|
|
|
if (availableTowns.empty())
|
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[124]);
|
|
|
|
else
|
|
|
|
GH.pushInt (new CObjectListWindow(availableTowns,
|
|
|
|
new CAnimImage("SPELLSCR",mySpell),
|
|
|
|
CGI->generaltexth->jktexts[40], CGI->generaltexth->jktexts[41],
|
2015-01-30 09:24:30 +02:00
|
|
|
castTownPortal));
|
2015-01-30 09:05:52 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mySpell == SpellID::SUMMON_BOAT)
|
|
|
|
{
|
|
|
|
//special case
|
|
|
|
//todo: move to mechanics
|
|
|
|
int3 pos = h->bestLocation();
|
|
|
|
if(pos.x < 0)
|
|
|
|
{
|
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[334]); //There is no place to put the boat.
|
2010-08-04 16:41:01 +03:00
|
|
|
return;
|
|
|
|
}
|
2010-01-29 18:19:12 +02:00
|
|
|
}
|
2015-01-30 09:05:52 +02:00
|
|
|
|
|
|
|
if(sp->getTargetType() == CSpell::LOCATION)
|
|
|
|
{
|
2015-01-30 09:24:30 +02:00
|
|
|
adventureInt->enterCastingMode(sp);
|
2015-01-30 09:05:52 +02:00
|
|
|
}
|
|
|
|
else if(sp->getTargetType() == CSpell::NO_TARGET)
|
|
|
|
{
|
|
|
|
LOCPLINT->cb->castSpell(h, mySpell);
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2008-09-16 18:23:44 +03:00
|
|
|
if(down && mySpell != -1)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2009-11-08 16:44:58 +02:00
|
|
|
std::string dmgInfo;
|
2010-11-15 09:15:10 +02:00
|
|
|
const CGHeroInstance * hero = owner->myHero;
|
2014-03-07 16:21:09 +03:00
|
|
|
int causedDmg = owner->myInt->cb->estimateSpellDamage( CGI->spellh->objects[mySpell], (hero ? hero : nullptr));
|
2015-01-30 17:40:15 +02:00
|
|
|
if(causedDmg == 0 || mySpell == SpellID::TITANS_LIGHTNING_BOLT) //Titan's Lightning Bolt already has damage info included
|
2009-11-08 16:44:58 +02:00
|
|
|
dmgInfo = "";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dmgInfo = CGI->generaltexth->allTexts[343];
|
|
|
|
boost::algorithm::replace_first(dmgInfo, "%d", boost::lexical_cast<std::string>(causedDmg));
|
|
|
|
}
|
|
|
|
|
2014-03-17 16:11:10 +03:00
|
|
|
CRClickPopup::createAndPush(CGI->spellh->objects[mySpell]->getLevelInfo(schoolLevel).description + dmgInfo,
|
2012-12-19 20:24:53 +03:00
|
|
|
new CComponent(CComponent::spell, mySpell));
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::SpellArea::hover(bool on)
|
|
|
|
{
|
2009-08-11 19:05:33 +03:00
|
|
|
//Hoverable::hover(on);
|
2008-09-16 18:23:44 +03:00
|
|
|
if(mySpell != -1)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2008-09-16 18:23:44 +03:00
|
|
|
if(on)
|
|
|
|
{
|
2009-06-17 19:46:16 +03:00
|
|
|
std::ostringstream ss;
|
2014-03-07 16:21:09 +03:00
|
|
|
ss<<CGI->spellh->objects[mySpell]->name<<" ("<<CGI->generaltexth->allTexts[171+CGI->spellh->objects[mySpell]->level]<<")";
|
2013-08-29 16:46:27 +03:00
|
|
|
owner->statusBar->setText(ss.str());
|
2008-09-16 18:23:44 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
owner->statusBar->clear();
|
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
void CSpellWindow::SpellArea::showAll(SDL_Surface * to)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
if(mySpell < 0)
|
|
|
|
return;
|
|
|
|
|
2014-03-10 19:00:58 +03:00
|
|
|
const CSpell * spell = mySpell.toSpell();
|
|
|
|
owner->spells->load(mySpell);
|
|
|
|
|
|
|
|
IImage * icon = owner->spells->getImage(mySpell,0,false);
|
|
|
|
|
|
|
|
if(icon != nullptr)
|
|
|
|
icon->draw(to, pos.x, pos.y);
|
|
|
|
else
|
|
|
|
logGlobal->errorStream() << __FUNCTION__ << ": failed to load spell icon for spell with id " << mySpell;
|
2010-07-21 13:09:29 +03:00
|
|
|
|
|
|
|
blitAt(owner->schoolBorders[owner->selectedTab >= 4 ? whichSchool : owner->selectedTab]->ourImages[schoolLevel].bitmap, pos.x, pos.y, to); //printing border (indicates level of magic school)
|
|
|
|
|
|
|
|
SDL_Color firstLineColor, secondLineColor;
|
|
|
|
if(spellCost > owner->myHero->mana) //hero cannot cast this spell
|
|
|
|
{
|
|
|
|
static const SDL_Color unavailableSpell = {239, 189, 33, 0};
|
2012-11-11 15:23:31 +03:00
|
|
|
firstLineColor = Colors::WHITE;
|
2010-07-21 13:09:29 +03:00
|
|
|
secondLineColor = unavailableSpell;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-11 15:23:31 +03:00
|
|
|
firstLineColor = Colors::YELLOW;
|
|
|
|
secondLineColor = Colors::WHITE;
|
2010-07-21 13:09:29 +03:00
|
|
|
}
|
|
|
|
//printing spell's name
|
2012-12-19 20:24:53 +03:00
|
|
|
printAtMiddleLoc(spell->name, 39, 70, FONT_TINY, firstLineColor, to);
|
2010-07-21 13:09:29 +03:00
|
|
|
//printing lvl
|
2012-12-19 20:24:53 +03:00
|
|
|
printAtMiddleLoc(CGI->generaltexth->allTexts[171 + spell->level], 39, 82, FONT_TINY, secondLineColor, to);
|
2010-07-21 13:09:29 +03:00
|
|
|
//printing cost
|
|
|
|
std::ostringstream ss;
|
|
|
|
ss << CGI->generaltexth->allTexts[387] << ": " << spellCost;
|
2012-12-19 20:24:53 +03:00
|
|
|
printAtMiddleLoc(ss.str(), 39, 94, FONT_TINY, secondLineColor, to);
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
void CSpellWindow::SpellArea::setSpell(SpellID spellID)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
mySpell = spellID;
|
|
|
|
if(mySpell < 0)
|
|
|
|
return;
|
|
|
|
|
2014-03-07 16:21:09 +03:00
|
|
|
const CSpell * spell = CGI->spellh->objects[mySpell];
|
2010-07-21 13:09:29 +03:00
|
|
|
schoolLevel = owner->myHero->getSpellSchoolLevel(spell, &whichSchool);
|
|
|
|
spellCost = owner->myInt->cb->getSpellCost(spell, owner->myHero);
|
2013-11-03 21:16:25 +03:00
|
|
|
}
|