2017-11-01 15:58:49 +02:00
|
|
|
/*
|
|
|
|
* CreatureCostBox.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CreatureCostBox.h"
|
2018-04-07 13:34:11 +02:00
|
|
|
#include "widgets/Images.h"
|
|
|
|
#include "widgets/TextControls.h"
|
2017-11-01 15:58:49 +02:00
|
|
|
#include "gui/CGuiHandler.h"
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CreatureCostBox::CreatureCostBox(Rect position, std::string titleText)
|
|
|
|
{
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2018-04-07 13:34:11 +02:00
|
|
|
|
2023-07-03 18:24:12 +02:00
|
|
|
setRedrawParent(true);
|
2022-12-15 23:24:03 +02:00
|
|
|
pos = position + pos.topLeft();
|
2018-04-07 13:34:11 +02:00
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
title = std::make_shared<CLabel>(pos.w/2, 10, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, titleText);
|
2018-04-07 13:34:11 +02:00
|
|
|
}
|
2017-11-01 15:58:49 +02:00
|
|
|
|
|
|
|
void CreatureCostBox::set(TResources res)
|
|
|
|
{
|
|
|
|
for(auto & item : resources)
|
2023-03-09 15:36:46 +02:00
|
|
|
item.second.first->setText(std::to_string(res[item.first]));
|
2017-11-01 15:58:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CreatureCostBox::createItems(TResources res)
|
|
|
|
{
|
|
|
|
resources.clear();
|
|
|
|
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2018-04-07 13:34:11 +02:00
|
|
|
|
2017-11-01 15:58:49 +02:00
|
|
|
TResources::nziterator iter(res);
|
2018-04-07 13:34:11 +02:00
|
|
|
while(iter.valid())
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
2024-01-17 14:50:00 +02:00
|
|
|
auto image = std::make_shared<CAnimImage>(AnimationPath::builtin("RESOURCE"), iter->resType);
|
|
|
|
auto text = std::make_shared<CLabel>(15, 43, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, "0");
|
2017-11-01 15:58:49 +02:00
|
|
|
|
|
|
|
resources.insert(std::make_pair(iter->resType, std::make_pair(text, image)));
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
if(!resources.empty())
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
2024-04-28 07:54:19 +02:00
|
|
|
int curx = pos.w / 2;
|
|
|
|
int spacing = 48;
|
2024-05-06 17:33:30 +02:00
|
|
|
int resourcesCount = static_cast<int>(resources.size());
|
2024-04-28 07:54:19 +02:00
|
|
|
if (resources.size() > 2)
|
|
|
|
{
|
|
|
|
spacing = 32;
|
2024-05-06 17:33:30 +02:00
|
|
|
curx -= (15 + 16 * (resourcesCount - 1));
|
2024-04-28 07:54:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-05-06 17:33:30 +02:00
|
|
|
curx -= ((16 * resourcesCount) + (8 * (resourcesCount - 1)));
|
2024-04-28 07:54:19 +02:00
|
|
|
}
|
2017-11-01 15:58:49 +02:00
|
|
|
//reverse to display gold as first resource
|
2018-10-29 17:56:14 +02:00
|
|
|
for(auto & currentRes : boost::adaptors::reverse(resources))
|
2017-11-01 15:58:49 +02:00
|
|
|
{
|
2024-04-28 12:40:55 +02:00
|
|
|
currentRes.second.first->moveBy(Point(curx + 2, 22));
|
2018-10-29 17:56:14 +02:00
|
|
|
currentRes.second.second->moveBy(Point(curx, 22));
|
2024-04-28 07:54:19 +02:00
|
|
|
curx += spacing;
|
2017-11-01 15:58:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
redraw();
|
|
|
|
}
|