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)
|
|
|
|
{
|
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
|
|
|
|
type |= REDRAW_PARENT;
|
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)
|
|
|
|
item.second.first->setText(boost::lexical_cast<std::string>(res[item.first]));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreatureCostBox::createItems(TResources res)
|
|
|
|
{
|
|
|
|
resources.clear();
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
|
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
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
ImagePtr image = std::make_shared<CAnimImage>("RESOURCE", iter->resType);
|
2022-11-26 23:12:20 +02:00
|
|
|
LabelPtr 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
|
|
|
{
|
2020-10-01 10:38:06 +02:00
|
|
|
int curx = pos.w / 2 - (16 * (int)resources.size()) - (8 * ((int)resources.size() - 1));
|
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
|
|
|
{
|
2018-10-29 17:56:14 +02:00
|
|
|
currentRes.second.first->moveBy(Point(curx, 22));
|
|
|
|
currentRes.second.second->moveBy(Point(curx, 22));
|
2017-11-01 15:58:49 +02:00
|
|
|
curx += 48;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
redraw();
|
|
|
|
}
|