2017-07-13 10:26:03 +02:00
|
|
|
/*
|
2023-02-01 16:42:03 +02:00
|
|
|
* CAdvMapPanel.cpp, part of VCMI engine
|
2017-07-13 10:26:03 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2014-07-15 10:14:49 +03:00
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CAdvMapPanel.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../widgets/Buttons.h"
|
|
|
|
#include "../widgets/Images.h"
|
|
|
|
#include "../render/CAnimation.h"
|
|
|
|
#include "../render/IImage.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-01-30 19:55:32 +02:00
|
|
|
|
2023-01-30 18:25:47 +02:00
|
|
|
CAdvMapPanel::CAdvMapPanel(std::shared_ptr<IImage> bg, Point position)
|
|
|
|
: CIntObject()
|
|
|
|
, background(bg)
|
2015-01-15 01:22:20 +02:00
|
|
|
{
|
|
|
|
defActions = 255;
|
|
|
|
recActions = 255;
|
|
|
|
pos.x += position.x;
|
|
|
|
pos.y += position.y;
|
2015-01-29 21:34:53 +02:00
|
|
|
if (bg)
|
|
|
|
{
|
2023-01-30 18:25:47 +02:00
|
|
|
pos.w = bg->width();
|
|
|
|
pos.h = bg->height();
|
2015-01-29 21:34:53 +02:00
|
|
|
}
|
2015-01-15 01:22:20 +02:00
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CAdvMapPanel::addChildColorableButton(std::shared_ptr<CButton> button)
|
2015-01-15 01:22:20 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
colorableButtons.push_back(button);
|
|
|
|
addChildToPanel(button, ACTIVATE | DEACTIVATE);
|
2015-01-15 01:22:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CAdvMapPanel::setPlayerColor(const PlayerColor & clr)
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
for(auto & button : colorableButtons)
|
2015-01-15 01:22:20 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
button->setPlayerColor(clr);
|
2015-01-15 01:22:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CAdvMapPanel::showAll(SDL_Surface * to)
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
if(background)
|
2023-01-30 18:25:47 +02:00
|
|
|
background->draw(to, pos.x, pos.y);
|
2015-01-15 01:22:20 +02:00
|
|
|
|
|
|
|
CIntObject::showAll(to);
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CAdvMapPanel::addChildToPanel(std::shared_ptr<CIntObject> obj, ui8 actions)
|
2015-01-15 01:22:20 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
otherObjects.push_back(obj);
|
2015-01-15 01:22:20 +02:00
|
|
|
obj->recActions |= actions | SHOWALL;
|
2018-04-07 13:34:11 +02:00
|
|
|
obj->recActions &= ~DISPOSE;
|
|
|
|
addChild(obj.get(), false);
|
2015-01-15 01:22:20 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 18:25:47 +02:00
|
|
|
CAdvMapWorldViewPanel::CAdvMapWorldViewPanel(std::shared_ptr<CAnimation> _icons, std::shared_ptr<IImage> bg, Point position, int spaceBottom, const PlayerColor &color)
|
2016-10-18 04:46:07 +02:00
|
|
|
: CAdvMapPanel(bg, position), icons(_icons)
|
2015-01-15 01:22:20 +02:00
|
|
|
{
|
2018-07-25 00:36:48 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
int fillerHeight = bg ? spaceBottom - pos.y - pos.h : 0;
|
2016-10-18 04:46:07 +02:00
|
|
|
|
2018-07-25 00:36:48 +02:00
|
|
|
if(fillerHeight > 0)
|
2015-01-29 19:39:46 +02:00
|
|
|
{
|
2018-07-25 00:36:48 +02:00
|
|
|
backgroundFiller = std::make_shared<CFilledTexture>("DIBOXBCK", Rect(0, pos.h, pos.w, fillerHeight));
|
2015-01-29 19:39:46 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-15 01:22:20 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
void CAdvMapWorldViewPanel::recolorIcons(const PlayerColor & color, int indexOffset)
|
2015-01-15 01:22:20 +02:00
|
|
|
{
|
2016-10-18 04:46:07 +02:00
|
|
|
assert(iconsData.size() == currentIcons.size());
|
2015-01-15 01:22:20 +02:00
|
|
|
|
2016-10-18 04:46:07 +02:00
|
|
|
for(size_t idx = 0; idx < iconsData.size(); idx++)
|
2015-01-15 01:22:20 +02:00
|
|
|
{
|
2016-10-18 04:46:07 +02:00
|
|
|
const auto & data = iconsData.at(idx);
|
|
|
|
currentIcons[idx]->setFrame(data.first + indexOffset);
|
2015-01-15 01:22:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-18 04:46:07 +02:00
|
|
|
void CAdvMapWorldViewPanel::addChildIcon(std::pair<int, Point> data, int indexOffset)
|
2015-01-15 01:22:20 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE);
|
2015-01-15 01:22:20 +02:00
|
|
|
iconsData.push_back(data);
|
2018-04-07 13:34:11 +02:00
|
|
|
currentIcons.push_back(std::make_shared<CAnimImage>(icons, data.first + indexOffset, 0, data.second.x, data.second.y));
|
2015-01-15 01:22:20 +02:00
|
|
|
}
|
2023-02-01 14:01:48 +02:00
|
|
|
|