mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Merge pull request #4864 from Laserlicht/creature_window_rework
Creature window rework
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "../widgets/Images.h"
|
||||
#include "../widgets/TextControls.h"
|
||||
#include "../widgets/ObjectLists.h"
|
||||
#include "../widgets/GraphicalPrimitiveCanvas.h"
|
||||
#include "../windows/InfoWindows.h"
|
||||
#include "../gui/CGuiHandler.h"
|
||||
#include "../gui/Shortcut.h"
|
||||
@@ -250,6 +251,47 @@ CStackWindow::BonusLineSection::BonusLineSection(CStackWindow * owner, size_t li
|
||||
Point(214, 4)
|
||||
};
|
||||
|
||||
auto drawBonusSource = [this](int leftRight, Point p, BonusInfo & bi)
|
||||
{
|
||||
std::map<BonusSource, ColorRGBA> bonusColors = {
|
||||
{BonusSource::ARTIFACT, Colors::GREEN},
|
||||
{BonusSource::ARTIFACT_INSTANCE, Colors::GREEN},
|
||||
{BonusSource::CREATURE_ABILITY, Colors::YELLOW},
|
||||
{BonusSource::SPELL_EFFECT, Colors::ORANGE},
|
||||
{BonusSource::SECONDARY_SKILL, Colors::PURPLE},
|
||||
{BonusSource::HERO_SPECIAL, Colors::PURPLE},
|
||||
{BonusSource::STACK_EXPERIENCE, Colors::CYAN},
|
||||
{BonusSource::COMMANDER, Colors::CYAN},
|
||||
};
|
||||
|
||||
std::map<BonusSource, std::string> bonusNames = {
|
||||
{BonusSource::ARTIFACT, CGI->generaltexth->translate("vcmi.bonusSource.artifact")},
|
||||
{BonusSource::ARTIFACT_INSTANCE, CGI->generaltexth->translate("vcmi.bonusSource.artifact")},
|
||||
{BonusSource::CREATURE_ABILITY, CGI->generaltexth->translate("vcmi.bonusSource.creature")},
|
||||
{BonusSource::SPELL_EFFECT, CGI->generaltexth->translate("vcmi.bonusSource.spell")},
|
||||
{BonusSource::SECONDARY_SKILL, CGI->generaltexth->translate("vcmi.bonusSource.hero")},
|
||||
{BonusSource::HERO_SPECIAL, CGI->generaltexth->translate("vcmi.bonusSource.hero")},
|
||||
{BonusSource::STACK_EXPERIENCE, CGI->generaltexth->translate("vcmi.bonusSource.commander")},
|
||||
{BonusSource::COMMANDER, CGI->generaltexth->translate("vcmi.bonusSource.commander")},
|
||||
};
|
||||
|
||||
auto c = bonusColors.count(bi.bonusSource) ? bonusColors[bi.bonusSource] : ColorRGBA(192, 192, 192);
|
||||
std::string t = bonusNames.count(bi.bonusSource) ? bonusNames[bi.bonusSource] : CGI->generaltexth->translate("vcmi.bonusSource.other");
|
||||
int maxLen = 50;
|
||||
EFonts f = FONT_TINY;
|
||||
Point pText = p + Point(3, 40);
|
||||
|
||||
// 1px Black border
|
||||
bonusSource[leftRight].push_back(std::make_shared<CLabel>(pText.x - 1, pText.y, f, ETextAlignment::TOPLEFT, Colors::BLACK, t, maxLen));
|
||||
bonusSource[leftRight].push_back(std::make_shared<CLabel>(pText.x + 1, pText.y, f, ETextAlignment::TOPLEFT, Colors::BLACK, t, maxLen));
|
||||
bonusSource[leftRight].push_back(std::make_shared<CLabel>(pText.x, pText.y - 1, f, ETextAlignment::TOPLEFT, Colors::BLACK, t, maxLen));
|
||||
bonusSource[leftRight].push_back(std::make_shared<CLabel>(pText.x, pText.y + 1, f, ETextAlignment::TOPLEFT, Colors::BLACK, t, maxLen));
|
||||
bonusSource[leftRight].push_back(std::make_shared<CLabel>(pText.x, pText.y, f, ETextAlignment::TOPLEFT, c, t, maxLen));
|
||||
|
||||
frame[leftRight] = std::make_shared<GraphicalPrimitiveCanvas>(Rect(p.x, p.y, 52, 52));
|
||||
frame[leftRight]->addRectangle(Point(0, 0), Point(52, 52), c);
|
||||
};
|
||||
|
||||
for(size_t leftRight : {0, 1})
|
||||
{
|
||||
auto position = offset[leftRight];
|
||||
@@ -259,8 +301,9 @@ CStackWindow::BonusLineSection::BonusLineSection(CStackWindow * owner, size_t li
|
||||
{
|
||||
BonusInfo & bi = parent->activeBonuses[bonusIndex];
|
||||
icon[leftRight] = std::make_shared<CPicture>(bi.imagePath, position.x, position.y);
|
||||
name[leftRight] = std::make_shared<CLabel>(position.x + 60, position.y + 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, bi.name);
|
||||
description[leftRight] = std::make_shared<CMultiLineLabel>(Rect(position.x + 60, position.y + 17, 137, 30), FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, bi.description);
|
||||
name[leftRight] = std::make_shared<CLabel>(position.x + 60, position.y + 2, FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, bi.name, 137);
|
||||
description[leftRight] = std::make_shared<CMultiLineLabel>(Rect(position.x + 60, position.y + 20, 137, 26), FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, bi.description);
|
||||
drawBonusSource(leftRight, Point(position.x - 1, position.y - 1), bi);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -284,7 +327,7 @@ CStackWindow::BonusesSection::BonusesSection(CStackWindow * owner, int yOffset,
|
||||
return std::make_shared<BonusLineSection>(owner, index);
|
||||
};
|
||||
|
||||
lines = std::make_shared<CListBox>(onCreate, Point(0, 0), Point(0, itemHeight), visibleSize, totalSize, 0, 1, Rect(pos.w - 15, 0, pos.h, pos.h));
|
||||
lines = std::make_shared<CListBox>(onCreate, Point(0, 0), Point(0, itemHeight), visibleSize, totalSize, 0, totalSize > 3 ? 1 : 0, Rect(pos.w - 15, 0, pos.h, pos.h));
|
||||
}
|
||||
|
||||
CStackWindow::ButtonsSection::ButtonsSection(CStackWindow * owner, int yOffset)
|
||||
@@ -533,7 +576,7 @@ CStackWindow::MainSection::MainSection(CStackWindow * owner, int yOffset, bool s
|
||||
animation->setAmount(parent->info->creatureCount);
|
||||
}
|
||||
|
||||
name = std::make_shared<CLabel>(215, 12, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, parent->info->getName());
|
||||
name = std::make_shared<CLabel>(215, 13, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, parent->info->getName());
|
||||
|
||||
const BattleInterface* battleInterface = LOCPLINT->battleInt.get();
|
||||
const CStack* battleStack = parent->info->stack;
|
||||
@@ -786,6 +829,12 @@ void CStackWindow::initBonusesList()
|
||||
BonusList output;
|
||||
BonusList input;
|
||||
input = *(info->stackNode->getBonuses(CSelector(Bonus::Permanent), Selector::all));
|
||||
std::sort(input.begin(), input.end(), [this](std::shared_ptr<Bonus> v1, std::shared_ptr<Bonus> & v2){
|
||||
if (v1->source != v2->source)
|
||||
return v1->source == BonusSource::CREATURE_ABILITY || (v1->source < v2->source);
|
||||
else
|
||||
return info->stackNode->bonusToString(v1, false) < info->stackNode->bonusToString(v2, false);
|
||||
});
|
||||
|
||||
while(!input.empty())
|
||||
{
|
||||
@@ -801,6 +850,7 @@ void CStackWindow::initBonusesList()
|
||||
bonusInfo.name = info->stackNode->bonusToString(b, false);
|
||||
bonusInfo.description = info->stackNode->bonusToString(b, true);
|
||||
bonusInfo.imagePath = info->stackNode->bonusToGraphics(b);
|
||||
bonusInfo.bonusSource = b->source;
|
||||
|
||||
//if it's possible to give any description or image for this kind of bonus
|
||||
//TODO: figure out why half of bonuses don't have proper description
|
||||
|
||||
Reference in New Issue
Block a user