mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Style cleanup
This commit is contained in:
parent
62151cd20c
commit
ab8b407294
13
Global.h
13
Global.h
@ -726,17 +726,18 @@ namespace vstd
|
||||
}
|
||||
|
||||
/// converts number into string using metric system prefixes, e.g. 'k' or 'M' to keep resulting strings within specified size
|
||||
template<typename IntType>
|
||||
std::string formatMetric(IntType number, int maxLength)
|
||||
/// Note that resulting string may have more symbols than digits: minus sign and prefix symbol
|
||||
template<typename Arithmetic>
|
||||
std::string formatMetric(Arithmetic number, int maxDigits)
|
||||
{
|
||||
IntType max = pow(10, maxLength);
|
||||
Arithmetic max = std::pow(10, maxDigits);
|
||||
if (std::abs(number) < max)
|
||||
return boost::lexical_cast<std::string>(number);
|
||||
return std::to_string(number);
|
||||
|
||||
std::string symbols = " kMGTPE";
|
||||
auto iter = symbols.begin();
|
||||
|
||||
while (number >= max)
|
||||
while (std::abs(number) >= max)
|
||||
{
|
||||
number /= 1000;
|
||||
iter++;
|
||||
@ -745,8 +746,6 @@ namespace vstd
|
||||
}
|
||||
return std::to_string(number) + *iter;
|
||||
}
|
||||
|
||||
using boost::math::round;
|
||||
}
|
||||
using vstd::operator-=;
|
||||
|
||||
|
@ -77,9 +77,9 @@ std::string CResDataBar::buildDateString()
|
||||
std::string pattern = "%s: %d, %s: %d, %s: %d";
|
||||
|
||||
auto formatted = boost::format(pattern)
|
||||
% CGI->generaltexth->allTexts[62] % LOCPLINT->cb->getDate(Date::MONTH)
|
||||
% CGI->generaltexth->allTexts[63] % LOCPLINT->cb->getDate(Date::WEEK)
|
||||
% CGI->generaltexth->allTexts[64] % LOCPLINT->cb->getDate(Date::DAY_OF_WEEK);
|
||||
% 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);
|
||||
|
||||
return boost::str(formatted);
|
||||
}
|
||||
@ -91,9 +91,9 @@ void CResDataBar::draw(SDL_Surface * to)
|
||||
{
|
||||
std::string text = boost::lexical_cast<std::string>(LOCPLINT->cb->getResourceAmount(i));
|
||||
|
||||
graphics->fonts[FONT_SMALL]->renderTextLeft(to, text, Colors::WHITE, Point(txtpos[i].first,txtpos[i].second));
|
||||
graphics->fonts[FONT_SMALL]->renderTextLeft(to, text, Colors::WHITE, Point(txtpos[i].first, txtpos[i].second));
|
||||
}
|
||||
graphics->fonts[FONT_SMALL]->renderTextLeft(to, buildDateString(), Colors::WHITE, Point(txtpos[7].first,txtpos[7].second));
|
||||
graphics->fonts[FONT_SMALL]->renderTextLeft(to, buildDateString(), Colors::WHITE, Point(txtpos[7].first, txtpos[7].second));
|
||||
}
|
||||
|
||||
void CResDataBar::show(SDL_Surface * to)
|
||||
|
@ -525,9 +525,9 @@ void BattleInterface::setAnimSpeed(int set)
|
||||
int BattleInterface::getAnimSpeed() const
|
||||
{
|
||||
if(settings["session"]["spectate"].Bool() && !settings["session"]["spectate-battle-speed"].isNull())
|
||||
return static_cast<int>(vstd::round(settings["session"]["spectate-battle-speed"].Float()));
|
||||
return static_cast<int>(std::round(settings["session"]["spectate-battle-speed"].Float()));
|
||||
|
||||
return static_cast<int>(vstd::round(settings["battle"]["speedFactor"].Float()));
|
||||
return static_cast<int>(std::round(settings["battle"]["speedFactor"].Float()));
|
||||
}
|
||||
|
||||
CPlayerInterface *BattleInterface::getCurrentPlayerInterface() const
|
||||
|
@ -312,7 +312,7 @@ void CreatureAnimation::playOnce( ECreatureAnimType type )
|
||||
|
||||
inline int getBorderStrength(float time)
|
||||
{
|
||||
float borderStrength = fabs(vstd::round(time) - time) * 2; // generate value in range 0-1
|
||||
float borderStrength = fabs(std::round(time) - time) * 2; // generate value in range 0-1
|
||||
|
||||
return static_cast<int>(borderStrength * 155 + 100); // scale to 0-255
|
||||
}
|
||||
|
@ -187,9 +187,9 @@ std::string CMinorResDataBar::buildDateString()
|
||||
std::string pattern = "%s: %d, %s: %d, %s: %d";
|
||||
|
||||
auto formatted = boost::format(pattern)
|
||||
% CGI->generaltexth->allTexts[62] % LOCPLINT->cb->getDate(Date::MONTH)
|
||||
% CGI->generaltexth->allTexts[63] % LOCPLINT->cb->getDate(Date::WEEK)
|
||||
% CGI->generaltexth->allTexts[64] % LOCPLINT->cb->getDate(Date::DAY_OF_WEEK);
|
||||
% 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);
|
||||
|
||||
return boost::str(formatted);
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ void CBuildingRect::clickRight(tribool down, bool previousState)
|
||||
else
|
||||
{
|
||||
int level = ( bid - BuildingID::DWELL_FIRST ) % GameConstants::CREATURES_PER_TOWN;
|
||||
GH.pushIntT<CDwellingInfoBox>(parent->pos.x+parent->pos.w/2, parent->pos.y+parent->pos.h/2, town, level);
|
||||
GH.pushIntT<CDwellingInfoBox>(parent->pos.x+parent->pos.w / 2, parent->pos.y+parent->pos.h /2, town, level);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1065,7 +1065,7 @@ void CCreaInfo::clickRight(tribool down, bool previousState)
|
||||
if(down)
|
||||
{
|
||||
if (showAvailable)
|
||||
GH.pushIntT<CDwellingInfoBox>(GH.screenDimensions().x/2, GH.screenDimensions().y/2, town, level);
|
||||
GH.pushIntT<CDwellingInfoBox>(GH.screenDimensions().x / 2, GH.screenDimensions().y / 2, town, level);
|
||||
else
|
||||
CRClickPopup::createAndPush(genGrowthText(), std::make_shared<CComponent>(CComponent::creature, creature->idNumber));
|
||||
}
|
||||
|
@ -504,13 +504,13 @@ void CTradeWindow::getPositionsFor(std::vector<Rect> &poss, bool Left, EType typ
|
||||
|
||||
const std::vector<Rect> tmp =
|
||||
{
|
||||
Rect(Point(x + 0*dx, y + 0*dx), Point(h, w) ),
|
||||
Rect(Point(x + 1*dx, y + 0*dx), Point(h, w) ),
|
||||
Rect(Point(x + 2*dx, y + 0*dx), Point(h, w) ),
|
||||
Rect(Point(x + 0*dx, y + 1*dy), Point(h, w) ),
|
||||
Rect(Point(x + 1*dx, y + 1*dy), Point(h, w) ),
|
||||
Rect(Point(x + 2*dx, y + 1*dy), Point(h, w) ),
|
||||
Rect(Point(x + 1*dx, y + 2*dy), Point(h, w) )
|
||||
Rect(Point(x + 0 * dx, y + 0 * dx), Point(h, w) ),
|
||||
Rect(Point(x + 1 * dx, y + 0 * dx), Point(h, w) ),
|
||||
Rect(Point(x + 2 * dx, y + 0 * dx), Point(h, w) ),
|
||||
Rect(Point(x + 0 * dx, y + 1 * dy), Point(h, w) ),
|
||||
Rect(Point(x + 1 * dx, y + 1 * dy), Point(h, w) ),
|
||||
Rect(Point(x + 2 * dx, y + 1 * dy), Point(h, w) ),
|
||||
Rect(Point(x + 1 * dx, y + 2 * dy), Point(h, w) )
|
||||
};
|
||||
|
||||
vstd::concatenate(poss, tmp);
|
||||
|
@ -1157,7 +1157,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
||||
int skill = hero->secSkills[g].first,
|
||||
level = hero->secSkills[g].second; // <1, 3>
|
||||
secSkillAreas[b].push_back(std::make_shared<LRClickableAreaWTextComp>());
|
||||
secSkillAreas[b][g]->pos = Rect(Point(pos.x + 32 + g*36 + b*454 , pos.y + (qeLayout ? 83 : 88)), Point(32, 32) );
|
||||
secSkillAreas[b][g]->pos = Rect(Point(pos.x + 32 + g * 36 + b * 454 , pos.y + (qeLayout ? 83 : 88)), Point(32, 32) );
|
||||
secSkillAreas[b][g]->baseType = 1;
|
||||
|
||||
secSkillAreas[b][g]->type = skill;
|
||||
@ -1172,12 +1172,12 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
||||
heroAreas[b] = std::make_shared<CHeroArea>(257 + 228*b, 13, hero);
|
||||
|
||||
specialtyAreas[b] = std::make_shared<LRClickableAreaWText>();
|
||||
specialtyAreas[b]->pos = Rect(Point(pos.x + 69 + 490*b, pos.y + (qeLayout ? 41 : 45)), Point(32, 32));
|
||||
specialtyAreas[b]->pos = Rect(Point(pos.x + 69 + 490 * b, pos.y + (qeLayout ? 41 : 45)), Point(32, 32));
|
||||
specialtyAreas[b]->hoverText = CGI->generaltexth->heroscrn[27];
|
||||
specialtyAreas[b]->text = hero->type->getSpecialtyDescriptionTranslated();
|
||||
|
||||
experienceAreas[b] = std::make_shared<LRClickableAreaWText>();
|
||||
experienceAreas[b]->pos = Rect(Point(pos.x + 105 + 490*b, pos.y + (qeLayout ? 41 : 45)), Point(32, 32));
|
||||
experienceAreas[b]->pos = Rect(Point(pos.x + 105 + 490 * b, pos.y + (qeLayout ? 41 : 45)), Point(32, 32));
|
||||
experienceAreas[b]->hoverText = CGI->generaltexth->heroscrn[9];
|
||||
experienceAreas[b]->text = CGI->generaltexth->allTexts[2];
|
||||
boost::algorithm::replace_first(experienceAreas[b]->text, "%d", boost::lexical_cast<std::string>(hero->level));
|
||||
@ -1185,7 +1185,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
||||
boost::algorithm::replace_first(experienceAreas[b]->text, "%d", boost::lexical_cast<std::string>(hero->exp));
|
||||
|
||||
spellPointsAreas[b] = std::make_shared<LRClickableAreaWText>();
|
||||
spellPointsAreas[b]->pos = Rect(Point(pos.x + 141 + 490*b, pos.y + (qeLayout ? 41 : 45)), Point(32, 32));
|
||||
spellPointsAreas[b]->pos = Rect(Point(pos.x + 141 + 490 * b, pos.y + (qeLayout ? 41 : 45)), Point(32, 32));
|
||||
spellPointsAreas[b]->hoverText = CGI->generaltexth->heroscrn[22];
|
||||
spellPointsAreas[b]->text = CGI->generaltexth->allTexts[205];
|
||||
boost::algorithm::replace_first(spellPointsAreas[b]->text, "%s", hero->getNameTranslated());
|
||||
|
@ -245,8 +245,8 @@ CInfoPopup::CInfoPopup(SDL_Surface *Bitmap, bool Free)
|
||||
|
||||
if(bitmap)
|
||||
{
|
||||
pos.x = GH.screenDimensions().x/2 - bitmap->w/2;
|
||||
pos.y = GH.screenDimensions().y/2 - bitmap->h/2;
|
||||
pos.x = GH.screenDimensions().x / 2 - bitmap->w / 2;
|
||||
pos.y = GH.screenDimensions().y / 2 - bitmap->h / 2;
|
||||
pos.h = bitmap->h;
|
||||
pos.w = bitmap->w;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user