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"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../renderSDL/SDL_Extensions.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-01-30 19:55:32 +02:00
|
|
|
|
2008-11-12 20:26:23 +02:00
|
|
|
#define ADVOPT (conf.go()->ac)
|
2009-01-12 22:05:56 +02:00
|
|
|
|
2009-08-11 19:05:33 +03:00
|
|
|
void CResDataBar::clickRight(tribool down, bool previousState)
|
2007-09-16 20:21:23 +03:00
|
|
|
{
|
|
|
|
}
|
2012-06-02 18:16:54 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CResDataBar::CResDataBar(const std::string & defname, int x, int y, int offx, int offy, int resdist, int datedist)
|
2008-12-08 00:38:04 +02:00
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
pos.x += x;
|
|
|
|
pos.y += y;
|
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
background = std::make_shared<CPicture>(defname, 0, 0);
|
|
|
|
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
|
|
|
|
|
|
|
txtpos.resize(8);
|
|
|
|
for (int i = 0; i < 8 ; i++)
|
|
|
|
{
|
|
|
|
txtpos[i].first = pos.x + offx + resdist*i;
|
|
|
|
txtpos[i].second = pos.y + offy;
|
|
|
|
}
|
|
|
|
txtpos[7].first = txtpos[6].first + datedist;
|
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
|
|
|
|
2007-09-16 20:21:23 +03:00
|
|
|
CResDataBar::CResDataBar()
|
|
|
|
{
|
2018-04-07 13:34:11 +02:00
|
|
|
pos.x += ADVOPT.resdatabarX;
|
|
|
|
pos.y += ADVOPT.resdatabarY;
|
|
|
|
|
|
|
|
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
|
|
|
|
background = std::make_shared<CPicture>(ADVOPT.resdatabarG, 0, 0);
|
|
|
|
background->colorize(LOCPLINT->playerID);
|
|
|
|
|
2023-01-30 13:58:13 +02:00
|
|
|
pos.w = background->pos.w;
|
|
|
|
pos.h = background->pos.h;
|
2007-09-16 20:21:23 +03:00
|
|
|
|
2008-11-28 03:36:34 +02:00
|
|
|
txtpos.resize(8);
|
|
|
|
for (int i = 0; i < 8 ; i++)
|
|
|
|
{
|
|
|
|
txtpos[i].first = pos.x + ADVOPT.resOffsetX + ADVOPT.resDist*i;
|
|
|
|
txtpos[i].second = pos.y + ADVOPT.resOffsetY;
|
|
|
|
}
|
|
|
|
txtpos[7].first = txtpos[6].first + ADVOPT.resDateDist;
|
2023-02-03 18:55:25 +02:00
|
|
|
|
2007-09-16 20:21:23 +03:00
|
|
|
}
|
2008-12-08 00:38:04 +02:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CResDataBar::~CResDataBar() = default;
|
|
|
|
|
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
|
2013-02-09 15:56:35 +03:00
|
|
|
for (auto i=Res::WOOD; i<=Res::GOLD; vstd::advance(i, 1))
|
2007-09-16 20:21:23 +03:00
|
|
|
{
|
2012-12-19 20:24:53 +03:00
|
|
|
std::string text = boost::lexical_cast<std::string>(LOCPLINT->cb->getResourceAmount(i));
|
|
|
|
|
2023-02-08 13:56:09 +02:00
|
|
|
graphics->fonts[FONT_SMALL]->renderTextLeft(to, text, Colors::WHITE, Point(txtpos[i].first, txtpos[i].second));
|
2007-09-16 20:21:23 +03:00
|
|
|
}
|
2023-02-08 13:56:09 +02:00
|
|
|
graphics->fonts[FONT_SMALL]->renderTextLeft(to, buildDateString(), Colors::WHITE, Point(txtpos[7].first, txtpos[7].second));
|
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::show(SDL_Surface * to)
|
2009-08-11 19:05:33 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2011-04-07 20:54:08 +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);
|
|
|
|
}
|
|
|
|
|