1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Miscellaneous fixes to creature window:

- implemented missing stack size indicator
- fixed detection of battle presence
- fixed placement of spell icons
This commit is contained in:
Ivan Savenko 2014-09-19 16:31:01 +03:00
parent 818a766fd6
commit ca47ddca5c
3 changed files with 38 additions and 7 deletions

View File

@ -432,11 +432,28 @@ CCreaturePic::CCreaturePic(int x, int y, const CCreature *cre, bool Big, bool An
bg = new CPicture(CGI->townh->factions[faction]->creatureBg130);
else
bg = new CPicture(CGI->townh->factions[faction]->creatureBg120);
bg->needRefresh = true;
anim = new CCreatureAnim(0, 0, cre->animDefName, Rect());
anim->clipRect(cre->isDoubleWide()?170:150, 155, bg->pos.w, bg->pos.h);
anim->startPreview(cre->hasBonusOfType(Bonus::SIEGE_WEAPON));
amount = new CLabel(bg->pos.w, bg->pos.h, FONT_MEDIUM, BOTTOMRIGHT, Colors::WHITE);
pos.w = bg->pos.w;
pos.h = bg->pos.h;
}
void CCreaturePic::show(SDL_Surface *to)
{
// redraw everything in a proper order
bg->showAll(to);
anim->show(to);
amount->showAll(to);
}
void CCreaturePic::setAmount(int newAmount)
{
if (newAmount != 0)
amount->setText(boost::lexical_cast<std::string>(newAmount));
else
amount->setText("");
}

View File

@ -12,6 +12,7 @@
*
*/
class CLabel;
class CCreatureAnim;
class CComponent;
class CGGarrison;
@ -85,9 +86,13 @@ class CCreaturePic : public CIntObject
private:
CPicture *bg;
CCreatureAnim *anim; //displayed animation
CLabel * amount;
void show(SDL_Surface *to);
public:
CCreaturePic(int x, int y, const CCreature *cre, bool Big=true, bool Animated=true); //c-tor
void setAmount(int newAmount);
};
/// Resource bar like that at the bottom of the adventure map screen

View File

@ -56,6 +56,7 @@ struct StackWindowInfo
const CCreature * creature;
const CCommanderInstance * commander;
const CStackInstance * stackNode;
const CStack * stack;
const CGHeroInstance * owner;
// temporary objects which should be kept as copy if needed
@ -92,6 +93,7 @@ StackWindowInfo::StackWindowInfo():
creature(nullptr),
commander(nullptr),
stackNode(nullptr),
stack(nullptr),
owner(nullptr),
creatureCount(0),
popupWindow(false)
@ -214,7 +216,13 @@ void CStackWindow::CWindowSection::createStackInfo(bool showExp, bool showArt)
else
createBackground("info-panel-0");
new CCreaturePic(5, 41, parent->info->creature);
auto pic = new CCreaturePic(5, 41, parent->info->creature);
if (parent->info->stackNode != nullptr && parent->info->commander == nullptr)
{
//normal stack, not a commander and not non-existing stack (e.g. recruitment dialog)
pic->setAmount(parent->info->stackNode->count);
}
std::string visibleName;
if (parent->info->commander != nullptr)
@ -234,7 +242,7 @@ void CStackWindow::CWindowSection::createStackInfo(bool showExp, bool showArt)
printStatBase(EStat::HEALTH, CGI->generaltexth->allTexts[388], parent->info->creature->valOfBonuses(Bonus::STACK_HEALTH), parent->info->stackNode->valOfBonuses(Bonus::STACK_HEALTH));
printStatBase(EStat::SPEED, CGI->generaltexth->zelp[441].first, parent->info->creature->Speed(), parent->info->stackNode->Speed());
const CStack * battleStack = dynamic_cast<const CStack*>(parent->info->stackNode);
const CStack * battleStack = parent->info->stack;
bool shooter = parent->info->stackNode->hasBonusOfType(Bonus::SHOOTER) && parent->info->stackNode->valOfBonuses(Bonus::SHOTS);
bool caster = parent->info->stackNode->valOfBonuses(Bonus::CASTS);
@ -293,13 +301,13 @@ void CStackWindow::CWindowSection::createStackInfo(bool showExp, bool showArt)
void CStackWindow::CWindowSection::createActiveSpells()
{
static const Point firstPos(7 ,4); // position of 1st spell box
static const Point firstPos(6, 2); // position of 1st spell box
static const Point offset(54, 0); // offset of each spell box from previous
OBJ_CONSTRUCTION_CAPTURING_ALL;
createBackground("spell-effects");
const CStack * battleStack = dynamic_cast<const CStack*>(parent->info->stackNode);
const CStack * battleStack = parent->info->stack;
assert(battleStack); // Section should be created only for battles
@ -316,7 +324,7 @@ void CStackWindow::CWindowSection::createActiveSpells()
int duration = battleStack->getBonusLocalFirst(Selector::source(Bonus::SPELL_EFFECT,effect))->turnsRemain;
boost::replace_first (spellText, "%d", boost::lexical_cast<std::string>(duration));
new CAnimImage("SpellInt", effect + 1, 0, firstPos.x + offset.x * printed, firstPos.x + offset.y * printed);
new CAnimImage("SpellInt", effect + 1, 0, firstPos.x + offset.x * printed, firstPos.y + offset.y * printed);
new LRClickableAreaWText(Rect(firstPos + offset * printed, Point(50, 38)), spellText, spellText);
if (++printed >= 8) // interface limit reached
break;
@ -689,7 +697,7 @@ void CStackWindow::initSections()
pos.w = currentSection->pos.w;
pos.h += currentSection->pos.h;
if (dynamic_cast<const CStack*>(info->stackNode)) // in battle
if (info->stack) // in battle
{
currentSection = new CWindowSection(this);
currentSection->pos.y += pos.h;
@ -790,6 +798,7 @@ CStackWindow::CStackWindow(const CStack * stack, bool popup):
CWindowObject(BORDERED | (popup ? RCLICK_POPUP : 0)),
info(new StackWindowInfo())
{
info->stack = stack;
info->stackNode = stack->base;
info->creature = stack->type;
info->creatureCount = stack->count;