1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

Get rid of CDefHandler in CPreGame.

* also fixes difficulty icon in campaign screen
This commit is contained in:
AlexVinS 2016-10-17 13:35:53 +03:00
parent e0303f791a
commit a223793405
2 changed files with 78 additions and 69 deletions

View File

@ -8,7 +8,6 @@
#include "gui/SDL_Extensions.h" #include "gui/SDL_Extensions.h"
#include "CGameInfo.h" #include "CGameInfo.h"
#include "gui/CCursorHandler.h" #include "gui/CCursorHandler.h"
#include "CDefHandler.h"
#include "../lib/CGeneralTextHandler.h" #include "../lib/CGeneralTextHandler.h"
#include "../lib/CTownHandler.h" #include "../lib/CTownHandler.h"
#include "../lib/CHeroHandler.h" #include "../lib/CHeroHandler.h"
@ -503,14 +502,16 @@ void CGPreGame::loadGraphics()
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
new CFilledTexture("DIBOXBCK", pos); new CFilledTexture("DIBOXBCK", pos);
victory = CDefHandler::giveDef("SCNRVICT.DEF"); victoryIcons = std::make_shared<CAnimation>("SCNRVICT.DEF");
loss = CDefHandler::giveDef("SCNRLOSS.DEF"); victoryIcons->load();
lossIcons = std::make_shared<CAnimation>("SCNRLOSS.DEF");
lossIcons->load();
} }
void CGPreGame::disposeGraphics() void CGPreGame::disposeGraphics()
{ {
delete victory; victoryIcons->unload();
delete loss; lossIcons->unload();
} }
void CGPreGame::update() void CGPreGame::update()
@ -1296,7 +1297,7 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const std::function<void(CM
slider = new CSlider(Point(372, 86), tabType != CMenuScreen::saveGame ? 480 : 430, std::bind(&SelectionTab::sliderMove, this, _1), positions, curItems.size(), 0, false, CSlider::BLUE); slider = new CSlider(Point(372, 86), tabType != CMenuScreen::saveGame ? 480 : 430, std::bind(&SelectionTab::sliderMove, this, _1), positions, curItems.size(), 0, false, CSlider::BLUE);
slider->addUsedEvents(WHEEL); slider->addUsedEvents(WHEEL);
formatIcons = make_unique<CAnimation>("SCSELC.DEF"); formatIcons = std::make_shared<CAnimation>("SCSELC.DEF");
formatIcons->load(); formatIcons->load();
sortingBy = _format; sortingBy = _format;
@ -1326,7 +1327,7 @@ SelectionTab::SelectionTab(CMenuScreen::EState Type, const std::function<void(CM
SelectionTab::~SelectionTab() SelectionTab::~SelectionTab()
{ {
formatIcons->unload();
} }
void SelectionTab::sortBy( int criteria ) void SelectionTab::sortBy( int criteria )
@ -1477,14 +1478,25 @@ void SelectionTab::printMaps(SDL_Surface *to)
} }
IImage * icon = formatIcons->getImage(frame,group); IImage * icon = formatIcons->getImage(frame,group);
if(icon) if(icon)
{
icon->draw(to, pos.x + 88, pos.y + 117 + line * 25); icon->draw(to, pos.x + 88, pos.y + 117 + line * 25);
icon->decreaseRef();
}
//victory conditions //victory conditions
blitAtLoc(CGP->victory->ourImages[currentItem->mapHeader->victoryIconIndex].bitmap, 306, 117 + line * 25, to); icon = CGP->victoryIcons->getImage(currentItem->mapHeader->victoryIconIndex,0);
if(icon)
{
icon->draw(to, pos.x + 306, pos.y + 117 + line * 25);
icon->decreaseRef();
}
//loss conditions //loss conditions
blitAtLoc(CGP->loss->ourImages[currentItem->mapHeader->defeatIconIndex].bitmap, 339, 117 + line * 25, to); icon = CGP->lossIcons->getImage(currentItem->mapHeader->defeatIconIndex,0);
if(icon)
{
icon->draw(to, pos.x + 339, pos.y + 117 + line * 25);
icon->decreaseRef();
}
} }
else //if campaign else //if campaign
{ {
@ -1986,8 +1998,8 @@ void CChatBox::addNewMessage(const std::string &text)
} }
InfoCard::InfoCard( bool Network ) InfoCard::InfoCard( bool Network )
: bg(nullptr), network(Network), chatOn(false), chat(nullptr), playerListBg(nullptr), : sizes(nullptr), bg(nullptr), network(Network), chatOn(false), chat(nullptr), playerListBg(nullptr),
difficulty(nullptr), sizes(nullptr), sFlags(nullptr) difficulty(nullptr)
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
CIntObject::type |= REDRAW_PARENT; CIntObject::type |= REDRAW_PARENT;
@ -2013,8 +2025,11 @@ InfoCard::InfoCard( bool Network )
parent->children.pop_back(); parent->children.pop_back();
pos.w = bg->pos.w; pos.w = bg->pos.w;
pos.h = bg->pos.h; pos.h = bg->pos.h;
sizes = CDefHandler::giveDef("SCNRMPSZ.DEF"); sizes = new CAnimImage("SCNRMPSZ", 4, 0, 318, 22);//let it be custom size (frame 4) by default
sFlags = CDefHandler::giveDef("ITGFLAGS.DEF"); sizes->recActions &= ~(SHOWALL | UPDATE);//explicit draw
sFlags = std::make_shared<CAnimation>("ITGFLAGS.DEF");
sFlags->load();
difficulty = new CToggleGroup(0); difficulty = new CToggleGroup(0);
{ {
static const char *difButns[] = {"GSPBUT3.DEF", "GSPBUT4.DEF", "GSPBUT5.DEF", "GSPBUT6.DEF", "GSPBUT7.DEF"}; static const char *difButns[] = {"GSPBUT3.DEF", "GSPBUT4.DEF", "GSPBUT5.DEF", "GSPBUT6.DEF", "GSPBUT7.DEF"};
@ -2039,12 +2054,16 @@ InfoCard::InfoCard( bool Network )
} }
} }
victory = new CAnimImage("SCNRVICT",0, 0, 24, 302);
victory->recActions &= ~(SHOWALL | UPDATE);//explicit draw
loss = new CAnimImage("SCNRLOSS", 0, 0, 24, 359);
loss->recActions &= ~(SHOWALL | UPDATE);//explicit draw
} }
InfoCard::~InfoCard() InfoCard::~InfoCard()
{ {
delete sizes; if(sFlags)
delete sFlags; sFlags->unload();
} }
void InfoCard::showAll(SDL_Surface * to) void InfoCard::showAll(SDL_Surface * to)
@ -2092,27 +2111,17 @@ void InfoCard::showAll(SDL_Surface * to)
{ {
if(SEL->screenType != CMenuScreen::campaignList) if(SEL->screenType != CMenuScreen::campaignList)
{ {
int temp = -1;
if(!chatOn) if(!chatOn)
{ {
CDefHandler * loss = CGP ? CGP->loss : CDefHandler::giveDef("SCNRLOSS.DEF");
CDefHandler * victory = CGP ? CGP->victory : CDefHandler::giveDef("SCNRVICT.DEF");
CMapHeader * header = SEL->current->mapHeader.get(); CMapHeader * header = SEL->current->mapHeader.get();
//victory conditions //victory conditions
printAtLoc(header->victoryMessage, 60, 307, FONT_SMALL, Colors::WHITE, to); printAtLoc(header->victoryMessage, 60, 307, FONT_SMALL, Colors::WHITE, to);
blitAtLoc(victory->ourImages[header->victoryIconIndex].bitmap, 24, 302, to); //victory cond descr victory->setFrame(header->victoryIconIndex);
victory->showAll(to);
//loss conditoins //loss conditoins
printAtLoc(header->defeatMessage, 60, 366, FONT_SMALL, Colors::WHITE, to); printAtLoc(header->defeatMessage, 60, 366, FONT_SMALL, Colors::WHITE, to);
blitAtLoc(loss->ourImages[header->defeatIconIndex].bitmap, 24, 359, to); //loss cond loss->setFrame(header->defeatIconIndex);
loss->showAll(to);
if (!CGP)
{
delete loss;
delete victory;
}
} }
//difficulty //difficulty
@ -2124,23 +2133,22 @@ void InfoCard::showAll(SDL_Surface * to)
switch (SEL->current->mapHeader->width) switch (SEL->current->mapHeader->width)
{ {
case 36: case 36:
temp=0; sizes->setFrame(0);
break; break;
case 72: case 72:
temp=1; sizes->setFrame(1);
break; break;
case 108: case 108:
temp=2; sizes->setFrame(2);
break; break;
case 144: case 144:
temp=3; sizes->setFrame(3);
break; break;
default: default:
temp=4; sizes->setFrame(4);
break; break;
} }
blitAtLoc(sizes->ourImages[temp].bitmap, 318, 22, to); sizes->showAll(to);
if(SEL->screenType == CMenuScreen::loadGame) if(SEL->screenType == CMenuScreen::loadGame)
printToLoc((static_cast<const CMapInfo*>(SEL->current))->date,308,34, FONT_SMALL, Colors::WHITE, to); printToLoc((static_cast<const CMapInfo*>(SEL->current))->date,308,34, FONT_SMALL, Colors::WHITE, to);
@ -2159,8 +2167,10 @@ void InfoCard::showAll(SDL_Surface * to)
for (auto i = SEL->sInfo.playerInfos.cbegin(); i != SEL->sInfo.playerInfos.cend(); i++) for (auto i = SEL->sInfo.playerInfos.cbegin(); i != SEL->sInfo.playerInfos.cend(); i++)
{ {
int *myx = ((i->first == playerColor || SEL->current->mapHeader->players[i->first.getNum()].team == myT) ? &fx : &ex); int *myx = ((i->first == playerColor || SEL->current->mapHeader->players[i->first.getNum()].team == myT) ? &fx : &ex);
blitAtLoc(sFlags->ourImages[i->first.getNum()].bitmap, *myx, 399, to); IImage * flag = sFlags->getImage(i->first.getNum(),0);
*myx += sFlags->ourImages[i->first.getNum()].bitmap->w; flag->draw(to, pos.x + *myx, pos.y + 399);
*myx += flag->width();
flag->decreaseRef();
} }
std::string tob; std::string tob;
@ -2255,7 +2265,9 @@ void InfoCard::showTeamsPopup()
int curx = 128 - 9*flags.size(); int curx = 128 - 9*flags.size();
for(auto & flag : flags) for(auto & flag : flags)
{ {
blitAt(sFlags->ourImages[flag].bitmap, curx, 75 + 50*i, bmp); IImage * icon = sFlags->getImage(flag,0);
icon->draw(bmp, curx, 75 + 50*i);
icon->decreaseRef();
curx += 18; curx += 18;
} }
} }
@ -3242,7 +3254,8 @@ void CBonusSelection::init()
graphics->fonts[FONT_BIG]->renderTextLeft(background, CGI->generaltexth->allTexts[508], Colors::YELLOW, Point(481, 28)); graphics->fonts[FONT_BIG]->renderTextLeft(background, CGI->generaltexth->allTexts[508], Colors::YELLOW, Point(481, 28));
//map size icon //map size icon
sizes = CDefHandler::giveDef("SCNRMPSZ.DEF"); sizes = new CAnimImage("SCNRMPSZ",4,0,735, 26);
sizes->recActions &= ~(SHOWALL | UPDATE);//explicit draw
//campaign description //campaign description
graphics->fonts[FONT_SMALL]->renderTextLeft(background, CGI->generaltexth->allTexts[38], Colors::YELLOW, Point(481, 63)); graphics->fonts[FONT_SMALL]->renderTextLeft(background, CGI->generaltexth->allTexts[38], Colors::YELLOW, Point(481, 63));
@ -3293,14 +3306,10 @@ void CBonusSelection::init()
graphics->fonts[FONT_MEDIUM]->renderTextLeft(background, difficulty.back(), Colors::WHITE, Point(689, 432)); graphics->fonts[FONT_MEDIUM]->renderTextLeft(background, difficulty.back(), Colors::WHITE, Point(689, 432));
//difficulty pics //difficulty pics
for (int b=0; b<ARRAY_COUNT(diffPics); ++b) for (size_t b=0; b < diffPics.size(); ++b)
{ {
CDefEssential * cde = CDefHandler::giveDefEss("GSPBUT" + boost::lexical_cast<std::string>(b+3) + ".DEF"); diffPics[b] = new CAnimImage("GSPBUT" + boost::lexical_cast<std::string>(b+3) + ".DEF", 0, 0, 709, 455);
SDL_Surface * surfToDuplicate = cde->ourImages[0].bitmap; diffPics[b]->recActions &= ~(SHOWALL | UPDATE);//explicit draw
diffPics[b] = SDL_ConvertSurface(surfToDuplicate, surfToDuplicate->format,
surfToDuplicate->flags);
delete cde;
} }
//difficulty selection buttons //difficulty selection buttons
@ -3311,7 +3320,8 @@ void CBonusSelection::init()
} }
//load miniflags //load miniflags
sFlags = CDefHandler::giveDef("ITGFLAGS.DEF"); sFlags = std::make_shared<CAnimation>("ITGFLAGS.DEF");
sFlags->load();
} }
CBonusSelection::CBonusSelection(std::shared_ptr<CCampaignState> _ourCampaign) : ourCampaign(_ourCampaign) CBonusSelection::CBonusSelection(std::shared_ptr<CCampaignState> _ourCampaign) : ourCampaign(_ourCampaign)
@ -3328,13 +3338,8 @@ CBonusSelection::CBonusSelection(const std::string & campaignFName)
CBonusSelection::~CBonusSelection() CBonusSelection::~CBonusSelection()
{ {
SDL_FreeSurface(background); SDL_FreeSurface(background);
delete sizes;
delete ourHeader; delete ourHeader;
delete sFlags; sFlags->unload();
for (auto & elem : diffPics)
{
SDL_FreeSurface(elem);
}
} }
void CBonusSelection::goBack() void CBonusSelection::goBack()
@ -3433,8 +3438,6 @@ void CBonusSelection::selectMap(int mapNr, bool initialSelect)
void CBonusSelection::show(SDL_Surface * to) void CBonusSelection::show(SDL_Surface * to)
{ {
//blitAt(background, pos.x, pos.y, to);
//map name //map name
std::string mapName = ourHeader->name; std::string mapName = ourHeader->name;
@ -3468,7 +3471,8 @@ void CBonusSelection::show(SDL_Surface * to)
temp=4; temp=4;
break; break;
} }
blitAtLoc(sizes->ourImages[temp].bitmap, 735, 26, to); sizes->setFrame(temp);
sizes->showAll(to);
//flags //flags
int fx = 496 + graphics->fonts[FONT_SMALL]->getStringWidth(CGI->generaltexth->allTexts[390]); int fx = 496 + graphics->fonts[FONT_SMALL]->getStringWidth(CGI->generaltexth->allTexts[390]);
@ -3478,12 +3482,15 @@ void CBonusSelection::show(SDL_Surface * to)
for (auto i = startInfo.playerInfos.cbegin(); i != startInfo.playerInfos.cend(); i++) for (auto i = startInfo.playerInfos.cbegin(); i != startInfo.playerInfos.cend(); i++)
{ {
int *myx = ((i->first == playerColor || ourHeader->players[i->first.getNum()].team == myT) ? &fx : &ex); int *myx = ((i->first == playerColor || ourHeader->players[i->first.getNum()].team == myT) ? &fx : &ex);
blitAtLoc(sFlags->ourImages[i->first.getNum()].bitmap, *myx, 405, to);
*myx += sFlags->ourImages[i->first.getNum()].bitmap->w; IImage * flag = sFlags->getImage(i->first.getNum(),0);
flag->draw(to, pos.x + *myx, pos.y + 405);
*myx += flag->width();
flag->decreaseRef();
} }
//difficulty //difficulty
blitAtLoc(diffPics[startInfo.difficulty], 709, 455, to); diffPics[startInfo.difficulty]->showAll(to);
CIntObject::show(to); CIntObject::show(to);
} }

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
//#include "../lib/filesystem/Filesystem.h"
#include "../lib/StartInfo.h" #include "../lib/StartInfo.h"
#include "../lib/FunctionList.h" #include "../lib/FunctionList.h"
#include "../lib/mapping/CMapInfo.h" #include "../lib/mapping/CMapInfo.h"
@ -36,6 +35,8 @@ class CMultiLineLabel;
class CToggleButton; class CToggleButton;
class CToggleGroup; class CToggleGroup;
class CTabbedInt; class CTabbedInt;
class IImage;
class CAnimation;
class CAnimImage; class CAnimImage;
class CButton; class CButton;
class CLabel; class CLabel;
@ -124,6 +125,8 @@ public:
class InfoCard : public CIntObject class InfoCard : public CIntObject
{ {
CAnimImage * victory, * loss, *sizes;
std::shared_ptr<CAnimation> sFlags;
public: public:
CPicture *bg; CPicture *bg;
CMenuScreen::EState type; CMenuScreen::EState type;
@ -135,7 +138,6 @@ public:
CPicture *playerListBg; CPicture *playerListBg;
CToggleGroup *difficulty; CToggleGroup *difficulty;
CDefHandler *sizes, *sFlags;
void changeSelection(const CMapInfo *to); void changeSelection(const CMapInfo *to);
void showAll(SDL_Surface * to) override; void showAll(SDL_Surface * to) override;
@ -151,7 +153,7 @@ public:
class SelectionTab : public CIntObject class SelectionTab : public CIntObject
{ {
private: private:
std::unique_ptr<CAnimation> formatIcons; std::shared_ptr<CAnimation> formatIcons;
void parseMaps(const std::unordered_set<ResourceID> &files); void parseMaps(const std::unordered_set<ResourceID> &files);
void parseGames(const std::unordered_set<ResourceID> &files, bool multi); void parseGames(const std::unordered_set<ResourceID> &files, bool multi);
@ -528,10 +530,10 @@ private:
std::vector<CRegion *> regions; std::vector<CRegion *> regions;
CRegion * highlightedRegion; CRegion * highlightedRegion;
CToggleGroup * bonuses; CToggleGroup * bonuses;
SDL_Surface * diffPics[5]; //pictures of difficulties, user-selectable (or not if campaign locks this) std::array<CAnimImage *, 5> diffPics; //pictures of difficulties, user-selectable (or not if campaign locks this)
CButton * diffLb, * diffRb; //buttons for changing difficulty CButton * diffLb, * diffRb; //buttons for changing difficulty
CDefHandler * sizes; //icons of map sizes CAnimImage * sizes;//icons of map sizes
CDefHandler * sFlags; std::shared_ptr<CAnimation> sFlags;
// Data // Data
std::shared_ptr<CCampaignState> ourCampaign; std::shared_ptr<CCampaignState> ourCampaign;
@ -609,7 +611,7 @@ class CGPreGame : public CIntObject, public IUpdateable
public: public:
CMenuScreen * menu; CMenuScreen * menu;
CDefHandler *victory, *loss; std::shared_ptr<CAnimation> victoryIcons, lossIcons;
~CGPreGame(); ~CGPreGame();
void update() override; void update() override;