1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

use CAnimImage for world view legend

This commit is contained in:
AlexVinS
2016-10-18 05:46:07 +03:00
parent 36ac9ac86c
commit 365c64a345
4 changed files with 33 additions and 37 deletions

View File

@@ -17,6 +17,8 @@
#include "../gui/CGuiHandler.h" #include "../gui/CGuiHandler.h"
#include "../gui/SDL_Pixels.h" #include "../gui/SDL_Pixels.h"
#include "../widgets/Images.h"
#include "../windows/InfoWindows.h" #include "../windows/InfoWindows.h"
#include "../windows/CAdvmapInterface.h" #include "../windows/CAdvmapInterface.h"
#include "../windows/GUIClasses.h" #include "../windows/GUIClasses.h"
@@ -1256,11 +1258,11 @@ void CAdvMapPanel::addChildToPanel(CIntObject * obj, ui8 actions /* = 0 */)
addChild(obj, false); addChild(obj, false);
} }
CAdvMapWorldViewPanel::CAdvMapWorldViewPanel(SDL_Surface * bg, Point position, int spaceBottom, const PlayerColor &color) CAdvMapWorldViewPanel::CAdvMapWorldViewPanel(std::shared_ptr<CAnimation> _icons, SDL_Surface * bg, Point position, int spaceBottom, const PlayerColor &color)
: CAdvMapPanel(bg, position) : CAdvMapPanel(bg, position), icons(_icons)
{ {
fillerHeight = bg ? spaceBottom - pos.y - pos.h : 0; fillerHeight = bg ? spaceBottom - pos.y - pos.h : 0;
if (fillerHeight > 0) if (fillerHeight > 0)
{ {
tmpBackgroundFiller = CMessage::drawDialogBox(pos.w, fillerHeight, color); tmpBackgroundFiller = CMessage::drawDialogBox(pos.w, fillerHeight, color);
@@ -1275,23 +1277,16 @@ CAdvMapWorldViewPanel::~CAdvMapWorldViewPanel()
SDL_FreeSurface(tmpBackgroundFiller); SDL_FreeSurface(tmpBackgroundFiller);
} }
void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor &color, const CDefHandler *def, int indexOffset) void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor &color, int indexOffset)
{ {
for (auto &pic : currentIcons) assert(iconsData.size() == currentIcons.size());
{
removeChild(pic);
delete pic;
}
currentIcons.clear();
for (auto &data : iconsData) for(size_t idx = 0; idx < iconsData.size(); idx++)
{ {
auto pic = new CPicture(def->ourImages[data.first + indexOffset].bitmap, data.second.x, data.second.y, false); const auto & data = iconsData.at(idx);
pic->recActions |= SHOWALL; currentIcons[idx]->setFrame(data.first + indexOffset);
currentIcons.push_back(pic);
addChildToPanel(pic);
} }
if (fillerHeight > 0) if (fillerHeight > 0)
{ {
if (tmpBackgroundFiller) if (tmpBackgroundFiller)
@@ -1300,18 +1295,17 @@ void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor &color, const CDefHan
} }
} }
void CAdvMapWorldViewPanel::addChildIcon(std::pair<int, Point> data, const CDefHandler *def, int indexOffset) void CAdvMapWorldViewPanel::addChildIcon(std::pair<int, Point> data, int indexOffset)
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL;
iconsData.push_back(data); iconsData.push_back(data);
auto pic = new CPicture(def->ourImages[data.first + indexOffset].bitmap, data.second.x, data.second.y, false); currentIcons.push_back(new CAnimImage(icons, data.first + indexOffset, 0, data.second.x, data.second.y));
currentIcons.push_back(pic);
addChildToPanel(pic);
} }
void CAdvMapWorldViewPanel::showAll(SDL_Surface * to) void CAdvMapWorldViewPanel::showAll(SDL_Surface * to)
{ {
if (tmpBackgroundFiller) if (tmpBackgroundFiller)
{ {
blitAt(tmpBackgroundFiller, pos.x, pos.y + pos.h, to); blitAt(tmpBackgroundFiller, pos.x, pos.y + pos.h, to);
} }

View File

@@ -4,6 +4,8 @@
#include "../../lib/FunctionList.h" #include "../../lib/FunctionList.h"
class CArmedInstance; class CArmedInstance;
class CAnimation;
class CAnimImage;
class CShowableAnim; class CShowableAnim;
class CGGarrison; class CGGarrison;
class CGObjectInstance; class CGObjectInstance;
@@ -340,17 +342,18 @@ class CAdvMapWorldViewPanel : public CAdvMapPanel
/// data that allows reconstruction of panel info icons /// data that allows reconstruction of panel info icons
std::vector<std::pair<int, Point>> iconsData; std::vector<std::pair<int, Point>> iconsData;
/// ptrs to child-pictures constructed from iconsData /// ptrs to child-pictures constructed from iconsData
std::vector<CPicture *> currentIcons; std::vector<CAnimImage *> currentIcons;
/// temporary surface drawn below world view panel on higher resolutions (won't be needed when world view panel is configured for extraResolutions mod) /// temporary surface drawn below world view panel on higher resolutions (won't be needed when world view panel is configured for extraResolutions mod)
SDL_Surface * tmpBackgroundFiller; SDL_Surface * tmpBackgroundFiller;
int fillerHeight; int fillerHeight;
std::shared_ptr<CAnimation> icons;
public: public:
CAdvMapWorldViewPanel(SDL_Surface * bg, Point position, int spaceBottom, const PlayerColor &color); CAdvMapWorldViewPanel(std::shared_ptr<CAnimation> _icons, SDL_Surface * bg, Point position, int spaceBottom, const PlayerColor &color);
virtual ~CAdvMapWorldViewPanel(); virtual ~CAdvMapWorldViewPanel();
void addChildIcon(std::pair<int, Point> data, const CDefHandler *def, int indexOffset); void addChildIcon(std::pair<int, Point> data, int indexOffset);
/// recreates all pictures from given def to recolor them according to current player color /// recreates all pictures from given def to recolor them according to current player color
void recolorIcons(const PlayerColor &color, const CDefHandler *def, int indexOffset); void recolorIcons(const PlayerColor &color, int indexOffset);
void showAll(SDL_Surface * to) override; void showAll(SDL_Surface * to) override;
}; };

View File

@@ -321,9 +321,6 @@ void CTerrainRect::show(SDL_Surface * to)
showPath(&pos, to); showPath(&pos, to);
} }
} }
//SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
//SDL_FreeSurface(teren);
} }
void CTerrainRect::showAll(SDL_Surface * to) void CTerrainRect::showAll(SDL_Surface * to)
@@ -503,6 +500,8 @@ CAdvMapInt::CAdvMapInt():
} }
worldViewIconsDef = CDefHandler::giveDef("VwSymbol.def"); worldViewIconsDef = CDefHandler::giveDef("VwSymbol.def");
worldViewIcons = std::make_shared<CAnimation>("VwSymbol");//todo: customize with ADVOPT
for (int g=0; g<ADVOPT.gemG.size(); ++g) for (int g=0; g<ADVOPT.gemG.size(); ++g)
{ {
gems.push_back(new CAnimImage(ADVOPT.gemG[g], 0, 0, ADVOPT.gemX[g], ADVOPT.gemY[g])); gems.push_back(new CAnimImage(ADVOPT.gemG[g], 0, 0, ADVOPT.gemX[g], ADVOPT.gemY[g]));
@@ -531,7 +530,7 @@ CAdvMapInt::CAdvMapInt():
panelMain = new CAdvMapPanel(nullptr, Point(0, 0)); panelMain = new CAdvMapPanel(nullptr, Point(0, 0));
// TODO correct drawing position // TODO correct drawing position
panelWorldView = new CAdvMapWorldViewPanel(bgWorldView, Point(heroList.pos.x - 2, 195), panelSpaceBottom, LOCPLINT->playerID); panelWorldView = new CAdvMapWorldViewPanel(worldViewIcons, bgWorldView, Point(heroList.pos.x - 2, 195), panelSpaceBottom, LOCPLINT->playerID);
panelMain->addChildColorableButton(kingOverview); panelMain->addChildColorableButton(kingOverview);
panelMain->addChildColorableButton(underground); panelMain->addChildColorableButton(underground);
@@ -600,16 +599,17 @@ CAdvMapInt::CAdvMapInt():
int iconColorMultiplier = player.getNum() * 19; int iconColorMultiplier = player.getNum() * 19;
int wvLeft = heroList.pos.x - 2; // TODO correct drawing position int wvLeft = heroList.pos.x - 2; // TODO correct drawing position
//int wvTop = 195;
for (int i = 0; i < 5; ++i) for (int i = 0; i < 5; ++i)
{ {
panelWorldView->addChildIcon(std::pair<int, Point>(i, Point(wvLeft + 5, 253 + i * 20)), worldViewIconsDef, iconColorMultiplier); panelWorldView->addChildIcon(std::pair<int, Point>(i, Point(5, 58 + i * 20)), iconColorMultiplier);
panelWorldView->addChildToPanel(new CLabel(wvLeft + 45, 263 + i * 20, EFonts::FONT_SMALL, EAlignment::TOPLEFT, panelWorldView->addChildToPanel(new CLabel(wvLeft + 45, 263 + i * 20, EFonts::FONT_SMALL, EAlignment::TOPLEFT,
Colors::WHITE, CGI->generaltexth->allTexts[612 + i])); Colors::WHITE, CGI->generaltexth->allTexts[612 + i]));
} }
for (int i = 0; i < 7; ++i) for (int i = 0; i < 7; ++i)
{ {
panelWorldView->addChildIcon(std::pair<int, Point>(i + 5, Point(wvLeft + 5, 377 + i * 20)), worldViewIconsDef, iconColorMultiplier); panelWorldView->addChildIcon(std::pair<int, Point>(i + 5, Point(5, 182 + i * 20)), iconColorMultiplier);
panelWorldView->addChildIcon(std::pair<int, Point>(i + 12, Point(wvLeft + 160, 377 + i * 20)), worldViewIconsDef, iconColorMultiplier); panelWorldView->addChildIcon(std::pair<int, Point>(i + 12, Point(160, 182 + i * 20)), iconColorMultiplier);
panelWorldView->addChildToPanel(new CLabel(wvLeft + 45, 387 + i * 20, EFonts::FONT_SMALL, EAlignment::TOPLEFT, panelWorldView->addChildToPanel(new CLabel(wvLeft + 45, 387 + i * 20, EFonts::FONT_SMALL, EAlignment::TOPLEFT,
Colors::WHITE, CGI->generaltexth->allTexts[619 + i])); Colors::WHITE, CGI->generaltexth->allTexts[619 + i]));
} }
@@ -1377,11 +1377,8 @@ void CAdvMapInt::setPlayer(PlayerColor Player)
panelMain->setPlayerColor(player); panelMain->setPlayerColor(player);
panelWorldView->setPlayerColor(player); panelWorldView->setPlayerColor(player);
panelWorldView->recolorIcons(player, worldViewIconsDef, player.getNum() * 19); panelWorldView->recolorIcons(player, player.getNum() * 19);
graphics->blueToPlayersAdv(resdatabar.bg,player); graphics->blueToPlayersAdv(resdatabar.bg,player);
//heroList.updateHList();
//townList.genList();
} }
void CAdvMapInt::startTurn() void CAdvMapInt::startTurn()

View File

@@ -176,7 +176,9 @@ public:
CAdvMapWorldViewPanel *panelWorldView; // panel that holds all buttons and other ui in world view CAdvMapWorldViewPanel *panelWorldView; // panel that holds all buttons and other ui in world view
CAdvMapPanel *activeMapPanel; // currently active panel (either main or world view, depending on current mode) CAdvMapPanel *activeMapPanel; // currently active panel (either main or world view, depending on current mode)
CDefHandler * worldViewIconsDef; // images for world view overlay CDefHandler * worldViewIconsDef; // images for world view overlay(DEPRECATED)
std::shared_ptr<CAnimation> worldViewIcons;// images for world view overlay
const CSpell *spellBeingCasted; //nullptr if none const CSpell *spellBeingCasted; //nullptr if none