mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
get rid of CDefHandler in CSpellWindow
This commit is contained in:
parent
2a6bab119b
commit
ba5b65ff93
@ -78,6 +78,7 @@ CPicture::CPicture(const Rect &r, ui32 color, bool screenFormat /*= false*/)
|
||||
|
||||
CPicture::CPicture(SDL_Surface *BG, const Rect &SrcRect, int x /*= 0*/, int y /*= 0*/, bool free /*= false*/)
|
||||
{
|
||||
visible = true;
|
||||
needRefresh = false;
|
||||
srcRect = new Rect(SrcRect);
|
||||
pos.x += x;
|
||||
@ -112,19 +113,20 @@ CPicture::~CPicture()
|
||||
|
||||
void CPicture::init()
|
||||
{
|
||||
visible = true;
|
||||
needRefresh = false;
|
||||
srcRect = nullptr;
|
||||
}
|
||||
|
||||
void CPicture::show(SDL_Surface * to)
|
||||
{
|
||||
if (needRefresh)
|
||||
if (visible && needRefresh)
|
||||
showAll(to);
|
||||
}
|
||||
|
||||
void CPicture::showAll(SDL_Surface * to)
|
||||
{
|
||||
if(bg)
|
||||
if(bg && visible)
|
||||
{
|
||||
if(srcRect)
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
Rect * srcRect; //if nullptr then whole surface will be used
|
||||
bool freeSurf; //whether surface will be freed upon CPicture destruction
|
||||
bool needRefresh;//Surface needs to be displayed each frame
|
||||
|
||||
bool visible;
|
||||
operator SDL_Surface*()
|
||||
{
|
||||
return bg;
|
||||
|
@ -8,8 +8,6 @@
|
||||
#include "InfoWindows.h"
|
||||
#include "CCastleInterface.h"
|
||||
|
||||
#include "../CBitmapHandler.h"
|
||||
#include "../CDefHandler.h"
|
||||
#include "../CGameInfo.h"
|
||||
#include "../CMessage.h"
|
||||
#include "../CMT.h"
|
||||
@ -171,17 +169,21 @@ CSpellWindow::CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _m
|
||||
|
||||
//numbers of spell pages computed
|
||||
|
||||
leftCorner = BitmapHandler::loadBitmap("SpelTrnL.bmp", true);
|
||||
rightCorner = BitmapHandler::loadBitmap("SpelTrnR.bmp", true);
|
||||
leftCorner = new CPicture("SpelTrnL.bmp", 97, 77);
|
||||
rightCorner = new CPicture("SpelTrnR.bmp", 487, 72);
|
||||
|
||||
spells = std::make_shared<CAnimation>("Spells");
|
||||
|
||||
spellTab = CDefHandler::giveDef("SpelTab.def");
|
||||
schools = CDefHandler::giveDef("Schools.def");
|
||||
schoolBorders[0] = CDefHandler::giveDef("SplevA.def");
|
||||
schoolBorders[1] = CDefHandler::giveDef("SplevF.def");
|
||||
schoolBorders[2] = CDefHandler::giveDef("SplevW.def");
|
||||
schoolBorders[3] = CDefHandler::giveDef("SplevE.def");
|
||||
spellTab = new CAnimImage("SpelTab", selectedTab, 0, 524, 88);
|
||||
schools = new CAnimImage("Schools",0,0,117,74);
|
||||
|
||||
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)
|
||||
item->load();
|
||||
|
||||
statusBar = new CGStatusBar(7, 569, "Spelroll.bmp");
|
||||
|
||||
@ -205,10 +207,10 @@ CSpellWindow::CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _m
|
||||
temp_rect = genRect(36, 56, 549 + pos.x, 330 + pos.y);
|
||||
new InteractiveArea(temp_rect, std::bind(&CSpellWindow::selectSchool, this, 4), 458, this);
|
||||
|
||||
lCorner = genRect(leftCorner->h, leftCorner->w, 97 + pos.x, 77 + pos.y);
|
||||
new InteractiveArea(lCorner, std::bind(&CSpellWindow::fLcornerb, this), 450, this);
|
||||
rCorner = genRect(rightCorner->h, rightCorner->w, 487 + pos.x, 72 + pos.y);
|
||||
new InteractiveArea(rCorner, std::bind(&CSpellWindow::fRcornerb, this), 451, this);
|
||||
temp_rect = genRect(leftCorner->bg->h, leftCorner->bg->w, 97 + pos.x, 77 + pos.y);
|
||||
new InteractiveArea(temp_rect, std::bind(&CSpellWindow::fLcornerb, this), 450, this);
|
||||
temp_rect = genRect(rightCorner->bg->h, rightCorner->bg->w, 487 + pos.x, 72 + pos.y);
|
||||
new InteractiveArea(temp_rect, std::bind(&CSpellWindow::fRcornerb, this), 451, this);
|
||||
|
||||
//areas for spells
|
||||
int xpos = 117 + pos.x, ypos = 90 + pos.y;
|
||||
@ -236,24 +238,19 @@ CSpellWindow::CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _m
|
||||
}
|
||||
|
||||
selectedTab = battleSpellsOnly ? myInt->spellbookSettings.spellbookLastTabBattle : myInt->spellbookSettings.spellbookLastTabAdvmap;
|
||||
currentPage = battleSpellsOnly ? myInt->spellbookSettings.spellbookLastPageBattle : myInt->spellbookSettings.spellbokLastPageAdvmap;
|
||||
|
||||
int cp = 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, std::max(0, pagesWithinCurrentTab() - 1));
|
||||
|
||||
vstd::abetween(cp, 0, std::max(0, pagesWithinCurrentTab() - 1));
|
||||
setCurrentPage(cp);
|
||||
computeSpellsPerArea();
|
||||
addUsedEvents(KEYBOARD);
|
||||
}
|
||||
|
||||
CSpellWindow::~CSpellWindow()
|
||||
{
|
||||
for(auto item : schoolBorders)
|
||||
item->unload();
|
||||
spells->unload();
|
||||
SDL_FreeSurface(leftCorner);
|
||||
SDL_FreeSurface(rightCorner);
|
||||
delete spellTab;
|
||||
delete schools;
|
||||
for(auto & elem : schoolBorders)
|
||||
delete elem;
|
||||
}
|
||||
|
||||
void CSpellWindow::fexitb()
|
||||
@ -270,7 +267,7 @@ void CSpellWindow::fadvSpellsb()
|
||||
{
|
||||
turnPageRight();
|
||||
battleSpellsOnly = false;
|
||||
currentPage = 0;
|
||||
setCurrentPage(0);
|
||||
}
|
||||
computeSpellsPerArea();
|
||||
}
|
||||
@ -281,7 +278,7 @@ void CSpellWindow::fbattleSpellsb()
|
||||
{
|
||||
turnPageLeft();
|
||||
battleSpellsOnly = true;
|
||||
currentPage = 0;
|
||||
setCurrentPage(0);
|
||||
}
|
||||
computeSpellsPerArea();
|
||||
}
|
||||
@ -299,7 +296,8 @@ void CSpellWindow::selectSchool(int school)
|
||||
else
|
||||
turnPageRight();
|
||||
selectedTab = school;
|
||||
currentPage = 0;
|
||||
spellTab->setFrame(selectedTab, 0);
|
||||
setCurrentPage(0);
|
||||
}
|
||||
computeSpellsPerArea();
|
||||
}
|
||||
@ -309,7 +307,7 @@ void CSpellWindow::fLcornerb()
|
||||
if(currentPage>0)
|
||||
{
|
||||
turnPageLeft();
|
||||
--currentPage;
|
||||
setCurrentPage(currentPage - 1);
|
||||
}
|
||||
computeSpellsPerArea();
|
||||
GH.breakEventHandling();
|
||||
@ -320,7 +318,7 @@ void CSpellWindow::fRcornerb()
|
||||
if((currentPage + 1) < (pagesWithinCurrentTab()))
|
||||
{
|
||||
turnPageRight();
|
||||
++currentPage;
|
||||
setCurrentPage(currentPage + 1);
|
||||
}
|
||||
computeSpellsPerArea();
|
||||
GH.breakEventHandling();
|
||||
@ -329,25 +327,8 @@ void CSpellWindow::fRcornerb()
|
||||
void CSpellWindow::showAll(SDL_Surface * to)
|
||||
{
|
||||
CWindowObject::showAll(to);
|
||||
blitAt(spellTab->ourImages[selectedTab].bitmap, 524 + pos.x, 88 + pos.y, to);
|
||||
|
||||
printAtMiddleLoc(boost::lexical_cast<std::string>(myHero->mana), 435, 426, FONT_SMALL, Colors::YELLOW, to);
|
||||
|
||||
//printing school images
|
||||
if(selectedTab!=4 && currentPage == 0)
|
||||
{
|
||||
blitAt(schools->ourImages[selectedTab].bitmap, 117 + pos.x, 74 + pos.y, to);
|
||||
}
|
||||
|
||||
//printing corners
|
||||
if(currentPage!=0)
|
||||
{
|
||||
blitAt(leftCorner, lCorner.x, lCorner.y, to);
|
||||
}
|
||||
if((currentPage+1) < (pagesWithinCurrentTab()) )
|
||||
{
|
||||
blitAt(rightCorner, rCorner.x, rCorner.y, to);
|
||||
}
|
||||
}
|
||||
|
||||
void CSpellWindow::show(SDL_Surface * to)
|
||||
@ -428,6 +409,16 @@ void CSpellWindow::computeSpellsPerArea()
|
||||
redraw();
|
||||
}
|
||||
|
||||
void CSpellWindow::setCurrentPage(int value)
|
||||
{
|
||||
currentPage = value;
|
||||
schools->visible = selectedTab!=4 && currentPage == 0;
|
||||
if(selectedTab != 4)
|
||||
schools->setFrame(selectedTab, 0);
|
||||
leftCorner->visible = currentPage != 0;
|
||||
rightCorner->visible = (currentPage+1) < pagesWithinCurrentTab();
|
||||
}
|
||||
|
||||
void CSpellWindow::turnPageLeft()
|
||||
{
|
||||
if (settings["video"]["spellbookAnimation"].Bool())
|
||||
@ -519,6 +510,7 @@ CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
|
||||
|
||||
spellCost = whichSchool = schoolLevel = -1;
|
||||
mySpell = nullptr;
|
||||
schoolBorder = nullptr;
|
||||
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL;
|
||||
image = new CAnimImage(owner->spells, 0, 0);
|
||||
@ -527,7 +519,8 @@ CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
|
||||
|
||||
CSpellWindow::SpellArea::~SpellArea()
|
||||
{
|
||||
|
||||
if(schoolBorder)
|
||||
schoolBorder->decreaseRef();
|
||||
}
|
||||
|
||||
void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
|
||||
@ -787,9 +780,11 @@ void CSpellWindow::SpellArea::showAll(SDL_Surface * to)
|
||||
{
|
||||
if(!mySpell)
|
||||
return;
|
||||
|
||||
schoolBorder->draw(to, pos.x, pos.y);
|
||||
CIntObject::showAll(to);
|
||||
|
||||
blitAt(owner->schoolBorders[owner->selectedTab >= 4 ? whichSchool : owner->selectedTab]->ourImages[schoolLevel].bitmap, pos.x, pos.y, to); //printing border (indicates level of magic school)
|
||||
// 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
|
||||
@ -823,6 +818,8 @@ void CSpellWindow::SpellArea::showAll(SDL_Surface * to)
|
||||
|
||||
void CSpellWindow::SpellArea::setSpell(const CSpell * spell)
|
||||
{
|
||||
if(schoolBorder)
|
||||
schoolBorder->decreaseRef();
|
||||
image->visible = false;
|
||||
mySpell = spell;
|
||||
if(mySpell)
|
||||
@ -832,5 +829,6 @@ void CSpellWindow::SpellArea::setSpell(const CSpell * spell)
|
||||
|
||||
image->setFrame(mySpell->id);
|
||||
image->visible = true;
|
||||
schoolBorder = owner->schoolBorders[whichSchool]->getImage(schoolLevel,0);
|
||||
}
|
||||
}
|
||||
|
@ -13,9 +13,10 @@
|
||||
*/
|
||||
|
||||
struct SDL_Surface;
|
||||
class CDefHandler;
|
||||
struct SDL_Rect;
|
||||
class IImage;
|
||||
class CAnimImage;
|
||||
class CPicture;
|
||||
class CGHeroInstance;
|
||||
class CGStatusBar;
|
||||
class CPlayerInterface;
|
||||
@ -35,6 +36,7 @@ private:
|
||||
int spellCost;
|
||||
CSpellWindow * owner;
|
||||
CAnimImage * image;
|
||||
IImage * schoolBorder;
|
||||
|
||||
SpellArea(SDL_Rect pos, CSpellWindow * owner);
|
||||
~SpellArea();
|
||||
@ -62,15 +64,13 @@ private:
|
||||
InteractiveArea(const SDL_Rect & myRect, std::function<void()> funcL, int helpTextId, CSpellWindow * _owner);//c-tor
|
||||
};
|
||||
|
||||
SDL_Surface * leftCorner, * rightCorner;
|
||||
|
||||
SDL_Rect lCorner, rCorner;
|
||||
CPicture * leftCorner, * rightCorner;
|
||||
|
||||
std::shared_ptr<CAnimation> spells; //pictures of spells
|
||||
|
||||
CDefHandler * spellTab, //school select
|
||||
* schools, //schools' pictures
|
||||
* schoolBorders [4]; //schools' 'borders': [0]: air, [1]: fire, [2]: water, [3]: earth
|
||||
CAnimImage * spellTab; //school select
|
||||
CAnimImage * schools; //schools' pictures
|
||||
std::array< std::shared_ptr<CAnimation>, 4> schoolBorders; //schools' 'borders': [0]: air, [1]: fire, [2]: water, [3]: earth
|
||||
|
||||
SpellArea * spellAreas[12];
|
||||
CGStatusBar * statusBar;
|
||||
@ -84,14 +84,14 @@ private:
|
||||
std::vector<const CSpell *> mySpells; //all spels in this spellbook
|
||||
|
||||
const CGHeroInstance * myHero; //hero whose spells are presented
|
||||
CPlayerInterface * myInt;
|
||||
|
||||
void computeSpellsPerArea(); //recalculates spellAreas::mySpell
|
||||
|
||||
void setCurrentPage(int value);
|
||||
void turnPageLeft();
|
||||
void turnPageRight();
|
||||
|
||||
CPlayerInterface * myInt;
|
||||
|
||||
public:
|
||||
|
||||
CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells = true); //c-tor
|
||||
|
Loading…
Reference in New Issue
Block a user