2017-07-13 10:26:03 +02:00
|
|
|
/*
|
2023-02-01 16:42:03 +02:00
|
|
|
* CResDataBar.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
|
|
|
|
*
|
|
|
|
*/
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "CResDataBar.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
2023-02-02 21:15:13 +02:00
|
|
|
#include "../render/Colors.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../widgets/Images.h"
|
2014-07-13 20:53:37 +03:00
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
2023-04-26 14:44:10 +02:00
|
|
|
#include "../../lib/ResourceSet.h"
|
2023-01-30 19:55:32 +02:00
|
|
|
|
2023-04-26 14:44:10 +02:00
|
|
|
CResDataBar::CResDataBar(const std::string & imageName, const Point & position)
|
2008-12-08 00:38:04 +02:00
|
|
|
{
|
2023-04-26 14:44:10 +02:00
|
|
|
pos.x += position.x;
|
|
|
|
pos.y += position.y;
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
2023-04-26 14:44:10 +02:00
|
|
|
background = std::make_shared<CPicture>(imageName, 0, 0);
|
2018-04-07 13:34:11 +02:00
|
|
|
background->colorize(LOCPLINT->playerID);
|
|
|
|
|
2023-01-30 13:58:13 +02:00
|
|
|
pos.w = background->pos.w;
|
|
|
|
pos.h = background->pos.h;
|
2008-12-08 00:38:04 +02:00
|
|
|
|
2012-06-02 18:16:54 +03:00
|
|
|
addUsedEvents(RCLICK);
|
2008-12-08 00:38:04 +02:00
|
|
|
}
|
2012-06-02 18:16:54 +03:00
|
|
|
|
2023-04-26 14:44:10 +02:00
|
|
|
CResDataBar::CResDataBar(const std::string & defname, int x, int y, int offx, int offy, int resdist, int datedist):
|
|
|
|
CResDataBar(defname, Point(x,y))
|
2007-09-16 20:21:23 +03:00
|
|
|
{
|
2023-04-26 14:44:10 +02:00
|
|
|
for (int i = 0; i < 7 ; i++)
|
|
|
|
resourcePositions[GameResID(i)] = Point( offx + resdist*i, offy );
|
2018-04-07 13:34:11 +02:00
|
|
|
|
2023-04-26 14:44:10 +02:00
|
|
|
datePosition = resourcePositions[EGameResID::GOLD] + Point(datedist, 0);
|
|
|
|
}
|
2007-09-16 20:21:23 +03:00
|
|
|
|
2023-04-26 14:44:10 +02:00
|
|
|
void CResDataBar::setDatePosition(const Point & position)
|
|
|
|
{
|
|
|
|
datePosition = position;
|
|
|
|
}
|
2023-02-03 18:55:25 +02:00
|
|
|
|
2023-04-26 14:44:10 +02:00
|
|
|
void CResDataBar::setResourcePosition(const GameResID & resource, const Point & position)
|
|
|
|
{
|
|
|
|
resourcePositions[resource] = position;
|
2007-09-16 20:21:23 +03:00
|
|
|
}
|
2008-12-08 00:38:04 +02:00
|
|
|
|
2023-02-03 18:55:25 +02:00
|
|
|
std::string CResDataBar::buildDateString()
|
|
|
|
{
|
|
|
|
std::string pattern = "%s: %d, %s: %d, %s: %d";
|
|
|
|
|
|
|
|
auto formatted = boost::format(pattern)
|
2023-02-08 13:56:09 +02:00
|
|
|
% CGI->generaltexth->translate("core.genrltxt.62") % LOCPLINT->cb->getDate(Date::MONTH)
|
|
|
|
% CGI->generaltexth->translate("core.genrltxt.63") % LOCPLINT->cb->getDate(Date::WEEK)
|
|
|
|
% CGI->generaltexth->translate("core.genrltxt.64") % LOCPLINT->cb->getDate(Date::DAY_OF_WEEK);
|
2023-02-03 18:55:25 +02:00
|
|
|
|
|
|
|
return boost::str(formatted);
|
|
|
|
}
|
|
|
|
|
2009-04-14 15:47:09 +03:00
|
|
|
void CResDataBar::draw(SDL_Surface * to)
|
2007-09-16 20:21:23 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
//TODO: all this should be labels, but they require proper text update on change
|
2023-04-26 14:44:10 +02:00
|
|
|
for (auto & entry : resourcePositions)
|
2007-09-16 20:21:23 +03:00
|
|
|
{
|
2023-04-26 14:44:10 +02:00
|
|
|
std::string text = std::to_string(LOCPLINT->cb->getResourceAmount(entry.first));
|
2012-12-19 20:24:53 +03:00
|
|
|
|
2023-04-26 14:44:10 +02:00
|
|
|
graphics->fonts[FONT_SMALL]->renderTextLeft(to, text, Colors::WHITE, pos.topLeft() + entry.second);
|
2007-09-16 20:21:23 +03:00
|
|
|
}
|
2023-04-26 14:44:10 +02:00
|
|
|
|
|
|
|
if (datePosition)
|
|
|
|
graphics->fonts[FONT_SMALL]->renderTextLeft(to, buildDateString(), Colors::WHITE, pos.topLeft() + *datePosition);
|
2007-09-16 20:21:23 +03:00
|
|
|
}
|
2009-08-11 19:05:33 +03:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
void CResDataBar::showAll(SDL_Surface * to)
|
2011-04-07 20:54:08 +03:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
CIntObject::showAll(to);
|
2011-04-07 20:54:08 +03:00
|
|
|
draw(to);
|
|
|
|
}
|
|
|
|
|
2023-02-10 23:29:13 +02:00
|
|
|
void CResDataBar::colorize(PlayerColor player)
|
|
|
|
{
|
|
|
|
background->colorize(player);
|
|
|
|
}
|