2008-09-10 15:19:48 +03:00
|
|
|
#include "CSpellWindow.h"
|
2008-09-12 11:51:46 +03:00
|
|
|
#include "Graphics.h"
|
|
|
|
#include "../hch/CDefHandler.h"
|
|
|
|
#include "../hch/CObjectHandler.h"
|
2008-09-12 16:06:53 +03:00
|
|
|
#include "../hch/CSpellHandler.h"
|
2008-09-15 19:46:54 +03:00
|
|
|
#include "../hch/CGeneralTextHandler.h"
|
2008-09-12 11:51:46 +03:00
|
|
|
#include "../CAdvmapInterface.h"
|
2008-10-17 19:30:56 +03:00
|
|
|
#include "../CBattleInterface.h"
|
2008-09-12 11:51:46 +03:00
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../SDL_Extensions.h"
|
2008-09-15 19:46:54 +03:00
|
|
|
#include "../CMessage.h"
|
2008-09-10 15:19:48 +03:00
|
|
|
#include <boost/bind.hpp>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
extern SDL_Surface * screen;
|
|
|
|
extern SDL_Color tytulowy, zwykly ;
|
|
|
|
extern TTF_Font *GEOR16;
|
|
|
|
|
2008-09-25 17:09:31 +03:00
|
|
|
SpellbookInteractiveArea::SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function<void()> funcL, const std::string & textR, boost::function<void()> funcHon, boost::function<void()> funcHoff)
|
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;
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
2008-09-11 15:29:22 +03:00
|
|
|
void SpellbookInteractiveArea::clickLeft(boost::logic::tribool down)
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-11 15:29:22 +03:00
|
|
|
void SpellbookInteractiveArea::clickRight(boost::logic::tribool down)
|
|
|
|
{
|
|
|
|
LOCPLINT->adventureInt->handleRightClick(textOnRclick, down, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpellbookInteractiveArea::hover(bool on)
|
|
|
|
{
|
|
|
|
Hoverable::hover(on);
|
|
|
|
if(on)
|
|
|
|
{
|
|
|
|
onHoverOn();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
onHoverOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpellbookInteractiveArea::activate()
|
2008-09-10 15:19:48 +03:00
|
|
|
{
|
|
|
|
ClickableL::activate();
|
2008-09-11 15:29:22 +03:00
|
|
|
ClickableR::activate();
|
|
|
|
Hoverable::activate();
|
2008-09-12 16:06:53 +03:00
|
|
|
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
2008-09-11 15:29:22 +03:00
|
|
|
void SpellbookInteractiveArea::deactivate()
|
2008-09-10 15:19:48 +03:00
|
|
|
{
|
|
|
|
ClickableL::deactivate();
|
2008-09-11 15:29:22 +03:00
|
|
|
ClickableR::deactivate();
|
|
|
|
Hoverable::deactivate();
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
2008-09-12 16:06:53 +03:00
|
|
|
CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHero): selectedTab(4), spellSite(0), battleSpellsOnly(true)
|
2008-09-10 15:19:48 +03:00
|
|
|
{
|
2008-09-12 16:06:53 +03:00
|
|
|
//for testing only
|
2008-09-15 19:46:54 +03:00
|
|
|
//mySpells = myHero->spells;
|
2008-09-12 16:06:53 +03:00
|
|
|
for(ui32 v=0; v<CGI->spellh->spells.size(); ++v)
|
|
|
|
{
|
2008-09-15 19:46:54 +03:00
|
|
|
if(!CGI->spellh->spells[v].creatureAbility)
|
|
|
|
mySpells.insert(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int b=0; b<4; ++b) schoolLvls[b] = 0;
|
|
|
|
for(int b=0; b<myHero->secSkills.size(); ++b)
|
|
|
|
{
|
|
|
|
switch(myHero->secSkills[b].first)
|
|
|
|
{
|
|
|
|
case 14: //fire magic
|
|
|
|
schoolLvls[1] = myHero->secSkills[b].second;
|
|
|
|
break;
|
|
|
|
case 15: //air magic
|
|
|
|
schoolLvls[0] = myHero->secSkills[b].second;
|
|
|
|
break;
|
|
|
|
case 16: //water magic
|
|
|
|
schoolLvls[2] = myHero->secSkills[b].second;
|
|
|
|
break;
|
|
|
|
case 17: //earth magic
|
|
|
|
schoolLvls[3] = myHero->secSkills[b].second;
|
|
|
|
break;
|
|
|
|
}
|
2008-09-12 16:06:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//initializing sizes of spellbook's parts
|
|
|
|
for(int b=0; b<5; ++b)
|
|
|
|
sitesPerTabAdv[b] = 0;
|
|
|
|
for(int b=0; b<5; ++b)
|
|
|
|
sitesPerTabBattle[b] = 0;
|
2008-09-15 19:46:54 +03:00
|
|
|
for(std::set<ui32>::const_iterator g = mySpells.begin(); g!=mySpells.end(); ++g)
|
2008-09-12 16:06:53 +03:00
|
|
|
{
|
2008-09-15 19:46:54 +03:00
|
|
|
if(CGI->spellh->spells[*g].combatSpell)
|
|
|
|
{
|
|
|
|
++(sitesPerTabBattle[4]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++(sitesPerTabAdv[4]);
|
|
|
|
}
|
|
|
|
|
2008-09-12 16:06:53 +03:00
|
|
|
if(CGI->spellh->spells[*g].air)
|
|
|
|
{
|
|
|
|
if(CGI->spellh->spells[*g].combatSpell)
|
|
|
|
{
|
|
|
|
++(sitesPerTabBattle[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++(sitesPerTabAdv[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(CGI->spellh->spells[*g].fire)
|
|
|
|
{
|
|
|
|
if(CGI->spellh->spells[*g].combatSpell)
|
|
|
|
{
|
|
|
|
++(sitesPerTabBattle[1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++(sitesPerTabAdv[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(CGI->spellh->spells[*g].water)
|
|
|
|
{
|
|
|
|
if(CGI->spellh->spells[*g].combatSpell)
|
|
|
|
{
|
|
|
|
++(sitesPerTabBattle[2]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++(sitesPerTabAdv[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(CGI->spellh->spells[*g].earth)
|
|
|
|
{
|
|
|
|
if(CGI->spellh->spells[*g].combatSpell)
|
|
|
|
{
|
|
|
|
++(sitesPerTabBattle[3]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++(sitesPerTabAdv[3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2008-09-10 15:19:48 +03:00
|
|
|
pos = myRect;
|
|
|
|
background = BitmapHandler::loadBitmap("SpelBack.bmp");
|
|
|
|
graphics->blueToPlayersAdv(background, myHero->tempOwner);
|
|
|
|
|
|
|
|
std::stringstream mana;
|
|
|
|
mana<<myHero->mana;
|
|
|
|
CSDL_Ext::printAtMiddle(mana.str(), 434, 425, GEOR16, tytulowy, background);
|
|
|
|
|
2008-09-12 16:06:53 +03:00
|
|
|
leftCorner = BitmapHandler::loadBitmap("SpelTrnL.bmp", true);
|
|
|
|
rightCorner = BitmapHandler::loadBitmap("SpelTrnR.bmp", true);
|
2008-09-10 15:19:48 +03:00
|
|
|
spells = CDefHandler::giveDef("Spells.def");
|
|
|
|
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
|
|
|
|
|
|
|
|
2008-09-10 15:19:48 +03:00
|
|
|
statusBar = new CStatusBar(97, 571, "Spelroll.bmp");
|
2008-09-11 21:42:21 +03:00
|
|
|
SDL_Rect temp_rect = genRect(45, 35, 569, 407);
|
2008-11-28 03:36:34 +02:00
|
|
|
exitBtn = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fexitb, this), CGI->generaltexth->zelp[460].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[460].first)), boost::bind(&CStatusBar::clear, statusBar));
|
2008-09-11 21:42:21 +03:00
|
|
|
temp_rect = genRect(45, 35, 311, 407);
|
2008-11-28 03:36:34 +02:00
|
|
|
battleSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fbattleSpellsb, this), CGI->generaltexth->zelp[453].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[453].first)), boost::bind(&CStatusBar::clear, statusBar));
|
2008-09-11 21:42:21 +03:00
|
|
|
temp_rect = genRect(45, 35, 445, 407);
|
2008-11-28 03:36:34 +02:00
|
|
|
adventureSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fadvSpellsb, this), CGI->generaltexth->zelp[452].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[452].first)), boost::bind(&CStatusBar::clear, statusBar));
|
2008-09-11 21:42:21 +03:00
|
|
|
temp_rect = genRect(45, 35, 508, 407);
|
2008-11-28 03:36:34 +02:00
|
|
|
manaPoints = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fmanaPtsb, this), CGI->generaltexth->zelp[459].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[459].first)), boost::bind(&CStatusBar::clear, statusBar));
|
2008-09-11 15:29:22 +03:00
|
|
|
|
2008-09-11 21:42:21 +03:00
|
|
|
temp_rect = genRect(36, 56, 639, 96);
|
2008-11-28 03:36:34 +02:00
|
|
|
selectSpellsA = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsAb, this), CGI->generaltexth->zelp[454].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[454].first)), boost::bind(&CStatusBar::clear, statusBar));
|
2008-09-11 21:42:21 +03:00
|
|
|
temp_rect = genRect(36, 56, 639, 153);
|
2008-11-28 03:36:34 +02:00
|
|
|
selectSpellsE = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsEb, this), CGI->generaltexth->zelp[457].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[457].first)), boost::bind(&CStatusBar::clear, statusBar));
|
2008-09-11 21:42:21 +03:00
|
|
|
temp_rect = genRect(36, 56, 639, 212);
|
2008-11-28 03:36:34 +02:00
|
|
|
selectSpellsF = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsFb, this), CGI->generaltexth->zelp[455].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[455].first)), boost::bind(&CStatusBar::clear, statusBar));
|
2008-09-11 21:42:21 +03:00
|
|
|
temp_rect = genRect(36, 56, 639, 272);
|
2008-11-28 03:36:34 +02:00
|
|
|
selectSpellsW = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsWb, this), CGI->generaltexth->zelp[456].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[456].first)), boost::bind(&CStatusBar::clear, statusBar));
|
2008-09-11 21:42:21 +03:00
|
|
|
temp_rect = genRect(36, 56, 639, 332);
|
2008-11-28 03:36:34 +02:00
|
|
|
selectSpellsAll = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsAllb, this), CGI->generaltexth->zelp[458].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[458].first)), boost::bind(&CStatusBar::clear, statusBar));
|
2008-09-12 16:06:53 +03:00
|
|
|
|
|
|
|
temp_rect = genRect(leftCorner->h, leftCorner->w, 187, 79);
|
2008-11-28 03:36:34 +02:00
|
|
|
lCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fLcornerb, this), CGI->generaltexth->zelp[450].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[450].first)), boost::bind(&CStatusBar::clear, statusBar));
|
2008-09-12 16:06:53 +03:00
|
|
|
temp_rect = genRect(rightCorner->h, rightCorner->w, 577, 76);
|
2008-11-28 03:36:34 +02:00
|
|
|
rCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fRcornerb, this), CGI->generaltexth->zelp[451].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[451].first)), boost::bind(&CStatusBar::clear, statusBar));
|
2008-09-15 19:46:54 +03:00
|
|
|
|
|
|
|
//areas for spells
|
|
|
|
int xpos = 207, ypos = 92;
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
xpos = 426; ypos = 92;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(v%2 == 0)
|
|
|
|
{
|
|
|
|
xpos+=85;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xpos -= 85; ypos+=97;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
computeSpellsPerArea();
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CSpellWindow::~CSpellWindow()
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(background);
|
|
|
|
SDL_FreeSurface(leftCorner);
|
|
|
|
SDL_FreeSurface(rightCorner);
|
|
|
|
delete spells;
|
|
|
|
delete spellTab;
|
|
|
|
delete schools;
|
2008-09-15 19:46:54 +03:00
|
|
|
for(int b=0; b<4; ++b)
|
|
|
|
delete schoolBorders[b];
|
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
|
|
|
|
|
|
|
for(int g=0; g<12; ++g)
|
|
|
|
{
|
|
|
|
delete spellAreas[g];
|
|
|
|
}
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fexitb()
|
|
|
|
{
|
|
|
|
deactivate();
|
|
|
|
|
|
|
|
for(int g=0; g<LOCPLINT->objsToBlit.size(); ++g)
|
|
|
|
{
|
|
|
|
if(dynamic_cast<CSpellWindow*>(LOCPLINT->objsToBlit[g]))
|
|
|
|
{
|
|
|
|
LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete this;
|
|
|
|
LOCPLINT->curint->activate();
|
|
|
|
}
|
|
|
|
|
2008-09-11 15:29:22 +03:00
|
|
|
void CSpellWindow::fadvSpellsb()
|
|
|
|
{
|
2008-09-12 16:06:53 +03:00
|
|
|
battleSpellsOnly = false;
|
2008-09-15 19:46:54 +03:00
|
|
|
spellSite = 0;
|
|
|
|
computeSpellsPerArea();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fbattleSpellsb()
|
|
|
|
{
|
2008-09-12 16:06:53 +03:00
|
|
|
battleSpellsOnly = true;
|
2008-09-15 19:46:54 +03:00
|
|
|
spellSite = 0;
|
|
|
|
computeSpellsPerArea();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fmanaPtsb()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fspellsAb()
|
|
|
|
{
|
|
|
|
selectedTab = 0;
|
2008-09-12 16:06:53 +03:00
|
|
|
spellSite = 0;
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fspellsEb()
|
|
|
|
{
|
|
|
|
selectedTab = 3;
|
2008-09-12 16:06:53 +03:00
|
|
|
spellSite = 0;
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fspellsFb()
|
|
|
|
{
|
|
|
|
selectedTab = 1;
|
2008-09-12 16:06:53 +03:00
|
|
|
spellSite = 0;
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fspellsWb()
|
|
|
|
{
|
|
|
|
selectedTab = 2;
|
2008-09-12 16:06:53 +03:00
|
|
|
spellSite = 0;
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fspellsAllb()
|
|
|
|
{
|
|
|
|
selectedTab = 4;
|
2008-09-12 16:06:53 +03:00
|
|
|
spellSite = 0;
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-12 16:06:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fLcornerb()
|
|
|
|
{
|
|
|
|
if(spellSite>0)
|
|
|
|
--spellSite;
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-12 16:06:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::fRcornerb()
|
|
|
|
{
|
|
|
|
if((spellSite + 1) < (battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab]))
|
|
|
|
++spellSite;
|
2008-09-15 19:46:54 +03:00
|
|
|
computeSpellsPerArea();
|
2008-09-11 15:29:22 +03:00
|
|
|
}
|
|
|
|
|
2008-09-10 15:19:48 +03:00
|
|
|
void CSpellWindow::show(SDL_Surface *to)
|
|
|
|
{
|
|
|
|
if(to == NULL) //evaluating to
|
|
|
|
to = screen;
|
|
|
|
|
|
|
|
SDL_BlitSurface(background, NULL, to, &pos);
|
|
|
|
blitAt(spellTab->ourImages[selectedTab].bitmap, 614, 96, to);
|
|
|
|
|
|
|
|
statusBar->show();
|
2008-09-12 16:06:53 +03:00
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
//printing school images
|
2008-09-12 16:06:53 +03:00
|
|
|
if(selectedTab!=4 && spellSite == 0)
|
|
|
|
{
|
|
|
|
blitAt(schools->ourImages[selectedTab].bitmap, 207, 76, to);
|
|
|
|
}
|
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
//printing corners
|
2008-09-12 16:06:53 +03:00
|
|
|
if(spellSite!=0)
|
|
|
|
{
|
|
|
|
blitAt(leftCorner, lCorner->pos.x, lCorner->pos.y, to);
|
|
|
|
}
|
|
|
|
if((spellSite+1) != (battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab]) )
|
|
|
|
{
|
|
|
|
blitAt(rightCorner, rCorner->pos.x, rCorner->pos.y, to);
|
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
|
|
|
|
//printing spell info
|
|
|
|
for(int b=0; b<12; ++b)
|
|
|
|
{
|
|
|
|
if(spellAreas[b]->mySpell == -1)
|
|
|
|
continue;
|
|
|
|
int b2 = -1;
|
|
|
|
|
|
|
|
blitAt(spells->ourImages[spellAreas[b]->mySpell].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to);
|
|
|
|
|
|
|
|
Uint8 bestSchool = -1, bestslvl = 0;
|
|
|
|
if(CGI->spellh->spells[spellAreas[b]->mySpell].air)
|
|
|
|
if(schoolLvls[0] >= bestslvl)
|
|
|
|
{
|
|
|
|
bestSchool = 0;
|
|
|
|
bestslvl = schoolLvls[0];
|
|
|
|
}
|
|
|
|
if(CGI->spellh->spells[spellAreas[b]->mySpell].fire)
|
|
|
|
if(schoolLvls[1] >= bestslvl)
|
|
|
|
{
|
|
|
|
bestSchool = 1;
|
|
|
|
bestslvl = schoolLvls[1];
|
|
|
|
}
|
|
|
|
if(CGI->spellh->spells[spellAreas[b]->mySpell].water)
|
|
|
|
if(schoolLvls[2] >= bestslvl)
|
|
|
|
{
|
|
|
|
bestSchool = 2;
|
|
|
|
bestslvl = schoolLvls[2];
|
|
|
|
}
|
|
|
|
if(CGI->spellh->spells[spellAreas[b]->mySpell].earth)
|
|
|
|
if(schoolLvls[3] >= bestslvl)
|
|
|
|
{
|
|
|
|
bestSchool = 3;
|
|
|
|
bestslvl = schoolLvls[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
//printing border (indicates level of magic school)
|
|
|
|
blitAt(schoolBorders[bestSchool]->ourImages[bestslvl].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to);
|
|
|
|
|
|
|
|
//printing spell's name
|
|
|
|
CSDL_Ext::printAtMiddle(CGI->spellh->spells[spellAreas[b]->mySpell].name, spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 70, GEORM, tytulowy, to);
|
|
|
|
//printing lvl
|
|
|
|
CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[171 + CGI->spellh->spells[spellAreas[b]->mySpell].level], spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 82, GEORM, zwykly, to);
|
|
|
|
//printing cost
|
|
|
|
std::stringstream ss;
|
|
|
|
ss<<CGI->generaltexth->allTexts[387]<<": "<<CGI->spellh->spells[spellAreas[b]->mySpell].costs[bestslvl];
|
|
|
|
|
|
|
|
CSDL_Ext::printAtMiddle(ss.str(), spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 94, GEORM, zwykly, to);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-16 18:23:44 +03:00
|
|
|
class SpellbookSpellSorter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool operator()(const int & a, const int & b)
|
|
|
|
{
|
|
|
|
CSpell A = CGI->spellh->spells[a];
|
|
|
|
CSpell B = CGI->spellh->spells[b];
|
|
|
|
if(A.level<B.level)
|
|
|
|
return true;
|
|
|
|
if(A.level>B.level)
|
|
|
|
return false;
|
|
|
|
if(A.air && !B.air)
|
|
|
|
return true;
|
|
|
|
if(!A.air && B.air)
|
|
|
|
return false;
|
|
|
|
if(A.fire && !B.fire)
|
|
|
|
return true;
|
|
|
|
if(!A.fire && B.fire)
|
|
|
|
return false;
|
|
|
|
if(A.water && !B.water)
|
|
|
|
return true;
|
|
|
|
if(!A.water && B.water)
|
|
|
|
return false;
|
|
|
|
if(A.earth && !B.earth)
|
|
|
|
return true;
|
|
|
|
if(!A.earth && B.earth)
|
|
|
|
return false;
|
|
|
|
return A.name < B.name;
|
|
|
|
}
|
|
|
|
} spellsorter;
|
|
|
|
|
2008-09-15 19:46:54 +03:00
|
|
|
void CSpellWindow::computeSpellsPerArea()
|
|
|
|
{
|
|
|
|
std::vector<ui32> spellsCurSite;
|
|
|
|
for(std::set<ui32>::const_iterator it = mySpells.begin(); it != mySpells.end(); ++it)
|
|
|
|
{
|
|
|
|
if(CGI->spellh->spells[*it].combatSpell ^ !battleSpellsOnly
|
|
|
|
&& ((CGI->spellh->spells[*it].air && selectedTab == 0) ||
|
|
|
|
(CGI->spellh->spells[*it].fire && selectedTab == 1) ||
|
|
|
|
(CGI->spellh->spells[*it].water && selectedTab == 2) ||
|
|
|
|
(CGI->spellh->spells[*it].earth && selectedTab == 3) ||
|
|
|
|
selectedTab == 4 )
|
|
|
|
)
|
|
|
|
{
|
|
|
|
spellsCurSite.push_back(*it);
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
spellsCurSite = std::vector<ui32>(spellsCurSite.begin() + spellSite*12, spellsCurSite.end());
|
|
|
|
if(spellsCurSite.size() > 12)
|
|
|
|
{
|
|
|
|
spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //selectedTab == 0, 1, 2 or 3
|
|
|
|
{
|
|
|
|
if(spellsCurSite.size() > 10)
|
|
|
|
{
|
|
|
|
if(spellSite == 0)
|
|
|
|
{
|
|
|
|
spellsCurSite.erase(spellsCurSite.begin()+10, spellsCurSite.end());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
spellsCurSite = std::vector<ui32>(spellsCurSite.begin() + (spellSite-1)*12 + 10, spellsCurSite.end());
|
|
|
|
if(spellsCurSite.size() > 12)
|
|
|
|
{
|
|
|
|
spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//applying
|
|
|
|
if(selectedTab == 4 || spellSite != 0)
|
|
|
|
{
|
|
|
|
for(int c=0; c<12; ++c)
|
|
|
|
{
|
|
|
|
if(c<spellsCurSite.size())
|
|
|
|
spellAreas[c]->mySpell = spellsCurSite[c];
|
|
|
|
else
|
|
|
|
spellAreas[c]->mySpell = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
spellAreas[0]->mySpell = -1;
|
|
|
|
spellAreas[1]->mySpell = -1;
|
|
|
|
for(int c=0; c<10; ++c)
|
|
|
|
{
|
|
|
|
if(c<spellsCurSite.size())
|
|
|
|
spellAreas[c+2]->mySpell = spellsCurSite[c];
|
|
|
|
else
|
|
|
|
spellAreas[c+2]->mySpell = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::activate()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
lCorner->activate();
|
|
|
|
rCorner->activate();
|
2008-09-15 19:46:54 +03:00
|
|
|
|
|
|
|
for(int g=0; g<12; ++g)
|
|
|
|
{
|
|
|
|
spellAreas[g]->activate();
|
|
|
|
}
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::deactivate()
|
|
|
|
{
|
|
|
|
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-12 16:06:53 +03:00
|
|
|
|
|
|
|
lCorner->deactivate();
|
|
|
|
rCorner->deactivate();
|
2008-09-15 19:46:54 +03:00
|
|
|
|
|
|
|
for(int g=0; g<12; ++g)
|
|
|
|
{
|
|
|
|
spellAreas[g]->deactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
|
|
|
|
{
|
|
|
|
this->pos = pos;
|
|
|
|
this->owner = owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::SpellArea::clickLeft(boost::logic::tribool down)
|
|
|
|
{
|
2008-10-17 20:43:25 +03:00
|
|
|
if(!down && mySpell!=-1)
|
2008-10-17 19:30:56 +03:00
|
|
|
{
|
2008-10-17 20:43:25 +03:00
|
|
|
//we will cast a spell
|
|
|
|
if(dynamic_cast<CBattleInterface*>(LOCPLINT->curint)) //if battle window is open
|
|
|
|
{
|
|
|
|
dynamic_cast<CBattleInterface*>(LOCPLINT->curint)->castThisSpell(mySpell);
|
|
|
|
}
|
|
|
|
owner->fexitb();
|
2008-10-17 19:30:56 +03:00
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::SpellArea::clickRight(boost::logic::tribool down)
|
|
|
|
{
|
2008-09-16 18:23:44 +03:00
|
|
|
if(down && mySpell != -1)
|
2008-09-15 19:46:54 +03:00
|
|
|
{
|
|
|
|
CInfoPopup *vinya = new CInfoPopup();
|
|
|
|
vinya->free = true;
|
|
|
|
vinya->bitmap = CMessage::drawBoxTextBitmapSub
|
|
|
|
(LOCPLINT->playerID,
|
|
|
|
CGI->spellh->spells[mySpell].descriptions[0], this->owner->spells->ourImages[mySpell].bitmap
|
|
|
|
,
|
|
|
|
CGI->spellh->spells[mySpell].name,30,30);
|
|
|
|
vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
|
|
|
|
vinya->pos.y = screen->h/2 - vinya->bitmap->h/2;
|
|
|
|
vinya->activate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::SpellArea::hover(bool on)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
ss<<CGI->spellh->spells[mySpell].name<<" ("<<CGI->generaltexth->allTexts[171+CGI->spellh->spells[mySpell].level]<<")";
|
|
|
|
owner->statusBar->print(ss.str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
owner->statusBar->clear();
|
|
|
|
}
|
2008-09-15 19:46:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::SpellArea::activate()
|
|
|
|
{
|
|
|
|
ClickableL::activate();
|
|
|
|
ClickableR::activate();
|
|
|
|
Hoverable::activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellWindow::SpellArea::deactivate()
|
|
|
|
{
|
|
|
|
ClickableL::deactivate();
|
|
|
|
ClickableR::deactivate();
|
|
|
|
Hoverable::deactivate();
|
2008-09-10 15:19:48 +03:00
|
|
|
}
|