1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Additional Wooden Hill Fort message

More verbose info-message for unavailable upgrades (creature levels 5 and higher). Some minor refactors.

Added other statusbar message if it's standard Hill Fort
This commit is contained in:
MichalZr6
2024-08-01 12:13:25 +02:00
parent 88f3e982e0
commit 162e2ab22e
4 changed files with 67 additions and 29 deletions

View File

@@ -283,6 +283,9 @@
"vcmi.adventureMap.revisitObject.hover" : "Revisit Object",
"vcmi.adventureMap.revisitObject.help" : "{Revisit Object}\n\nIf a hero currently stands on a Map Object, he can revisit the location.",
"vcmi.adventureMap.miniHillFort.notAvailableUpgrade.message" : "This building cannot upgrade creatures of level 5 and higher.",
"vcmi.adventureMap.miniHillFort.statusBar.info" : "Upgrade creatures levels 1 - 5 at double the normal price",
"vcmi.adventureMap.HillFort.statusBar.info" : "Upgrades creatures. Levels 1 - 4 are less expensive than in associated town",
"vcmi.battleWindow.pressKeyToSkipIntro" : "Press any key to start battle immediately",
"vcmi.battleWindow.damageEstimation.melee" : "Attack %CREATURE (%DAMAGE).",

View File

@@ -280,6 +280,9 @@
"vcmi.adventureMap.revisitObject.hover" : "Odwiedź obiekt ponownie",
"vcmi.adventureMap.revisitObject.help" : "{Odwiedź obiekt ponownie}\n\nJeżeli bohater aktualnie stoi na polu odwiedzającym obiekt za pomocą tego przycisku może go odwiedzić ponownie.",
"vcmi.adventureMap.miniHillFort.notAvailableUpgrade.message" : "Ten budynek nie ma możliwości ulepszenia jednostek poziomu 5 i wyższych.",
"vcmi.adventureMap.miniHillFort.statusBar.info" : "Ulepsza jednostki poziomu 1 - 5 za podwójną cenę",
"vcmi.adventureMap.HillFort.statusBar.info" : "Ulepsza jednostki. Koszt ulepszenia dla poziomów 1 - 4 są bardziej korzystne niż w mieście",
"vcmi.battleWindow.pressKeyToSkipIntro" : "Naciśnij dowolny klawisz by rozpocząć bitwę natychmiastowo",
"vcmi.battleWindow.damageEstimation.melee" : "Atakuj %CREATURE (%DAMAGE).",

View File

@@ -1129,6 +1129,12 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance * visitor, const CGObjectI
statusbar = CGStatusBar::create(std::make_shared<CPicture>(background->getSurface(), Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
garr = std::make_shared<CGarrisonInt>(Point(108, 60), 18, Point(), hero, nullptr);
if(object->typeName == "miniHillFort")
statusbar->write(VLC->generaltexth->translate("vcmi.adventureMap.miniHillFort.statusBar.info"));
else if(object->typeName == "hillFort")
statusbar->write(VLC->generaltexth->translate("vcmi.adventureMap.HillFort.statusBar.info"));
updateGarrisons();
}
@@ -1146,11 +1152,25 @@ void CHillFortWindow::updateGarrisons()
TResources totalSum; // totalSum[resource ID] = value
auto getImgIdx = [](CHillFortWindow::State st) -> std::size_t
{
switch (st)
{
case State::EMPTY:
return 0;
case State::UNAVAILABLE:
case State::ALREADY_UPGRADED:
return 1;
default:
return static_cast<std::size_t>(st);
}
};
for(int i=0; i<slotsCount; i++)
{
std::fill(costs[i].begin(), costs[i].end(), 0);
int newState = getState(SlotID(i));
if(newState != -1)
State newState = getState(SlotID(i));
if(newState != State::EMPTY)
{
UpgradeInfo info;
LOCPLINT->cb->fillUpgradeInfo(hero, SlotID(i), info);
@@ -1162,29 +1182,29 @@ void CHillFortWindow::updateGarrisons()
}
currState[i] = newState;
upgrade[i]->setImage(AnimationPath::builtin(currState[i] == -1 ? slotImages[0] : slotImages[currState[i]]));
upgrade[i]->block(currState[i] == -1);
upgrade[i]->setImage(AnimationPath::builtin(slotImages[getImgIdx(currState[i])]));
upgrade[i]->block(currState[i] == State::EMPTY);
upgrade[i]->addHoverText(EButtonState::NORMAL, getTextForSlot(SlotID(i)));
}
//"Upgrade all" slot
int newState = 2;
State newState = State::MAKE_UPGRADE;
{
TResources myRes = LOCPLINT->cb->getResourceAmount();
bool allUpgraded = true;//All creatures are upgraded?
for(int i=0; i<slotsCount; i++)
allUpgraded &= currState[i] == 1 || currState[i] == -1;
allUpgraded &= currState[i] == State::ALREADY_UPGRADED || currState[i] == State::EMPTY || currState[i] == State::UNAVAILABLE;
if(allUpgraded)
newState = 1;
if (allUpgraded)
newState = State::ALREADY_UPGRADED;
if(!totalSum.canBeAfforded(myRes))
newState = 0;
newState = State::UNAFORDABLE;
}
currState[slotsCount] = newState;
upgradeAll->setImage(AnimationPath::builtin(allImages[newState]));
upgradeAll->setImage(AnimationPath::builtin(allImages[static_cast<std::size_t>(newState)]));
garr->recreateSlots();
@@ -1197,7 +1217,7 @@ void CHillFortWindow::updateGarrisons()
slotLabels[i][j]->setText("");
}
//if can upgrade or can not afford, draw cost
if(currState[i] == 0 || currState[i] == 2)
if(currState[i] == State::UNAFORDABLE || currState[i] == State::MAKE_UPGRADE)
{
if(costs[i].nonZero())
{
@@ -1246,16 +1266,20 @@ void CHillFortWindow::makeDeal(SlotID slot)
int offset = (slot.getNum() == slotsCount)?2:0;
switch(currState[slot.getNum()])
{
case 0:
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[314 + offset], std::vector<std::shared_ptr<CComponent>>(), soundBase::sound_todo);
break;
case 1:
case State::ALREADY_UPGRADED:
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[313 + offset], std::vector<std::shared_ptr<CComponent>>(), soundBase::sound_todo);
break;
case 2:
for(int i=0; i<slotsCount; i++)
case State::UNAFORDABLE:
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[314 + offset], std::vector<std::shared_ptr<CComponent>>(), soundBase::sound_todo);
break;
case State::UNAVAILABLE:
LOCPLINT->showInfoDialog(VLC->generaltexth->translate("vcmi.adventureMap.miniHillFort.notAvailableUpgrade.message"),
std::vector<std::shared_ptr<CComponent>>(), soundBase::sound_todo);
break;
case State::MAKE_UPGRADE:
for(int i = 0; i < slotsCount; i++)
{
if(slot.getNum() ==i || ( slot.getNum() == slotsCount && currState[i] == 2 ))//this is activated slot or "upgrade all"
if(slot.getNum() == i || ( slot.getNum() == slotsCount && currState[i] == State::MAKE_UPGRADE ))//this is activated slot or "upgrade all"
{
UpgradeInfo info;
LOCPLINT->cb->fillUpgradeInfo(hero, SlotID(i), info);
@@ -1281,22 +1305,28 @@ std::string CHillFortWindow::getTextForSlot(SlotID slot)
return str;
}
int CHillFortWindow::getState(SlotID slot)
CHillFortWindow::State CHillFortWindow::getState(SlotID slot)
{
TResources myRes = LOCPLINT->cb->getResourceAmount();
if(hero->slotEmpty(slot))//no creature here
return -1;
if(hero->slotEmpty(slot))
return State::EMPTY;
UpgradeInfo info;
LOCPLINT->cb->fillUpgradeInfo(hero, slot, info);
if(!info.newID.size())//already upgraded
return 1;
if (!info.newID.size())
{
// new Hill Fort allows upgrades level 5 and below
if (hero->getStack(slot).type->getLevel() >= 5 && hero->getCreature(slot)->hasUpgrades())
return State::UNAVAILABLE;
return State::ALREADY_UPGRADED;
}
if(!(info.cost[0] * hero->getStackCount(slot)).canBeAfforded(myRes))
return 0;
return State::UNAFORDABLE;
return 2;//can upgrade
return State::MAKE_UPGRADE;
}
CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner):

View File

@@ -444,9 +444,11 @@ public:
class CHillFortWindow : public CStatusbarWindow, public IGarrisonHolder
{
private:
static const int slotsCount = 7;
enum class State { UNAFORDABLE, ALREADY_UPGRADED, MAKE_UPGRADE, EMPTY, UNAVAILABLE };
static constexpr std::size_t slotsCount = 7;
//todo: mithril support
static const int resCount = 7;
static constexpr std::size_t resCount = 7;
const CGObjectInstance * fort;
const CGHeroInstance * hero;
@@ -458,7 +460,7 @@ private:
std::array<std::shared_ptr<CLabel>, resCount> totalLabels;
std::array<std::shared_ptr<CButton>, slotsCount> upgrade;//upgrade single creature
std::array<int, slotsCount + 1> currState;//current state of slot - to avoid calls to getState or updating buttons
std::array<State, slotsCount + 1> currState;//current state of slot - to avoid calls to getState or updating buttons
//there is a place for only 2 resources per slot
std::array< std::array<std::shared_ptr<CAnimImage>, 2>, slotsCount> slotIcons;
@@ -473,7 +475,7 @@ private:
std::string getTextForSlot(SlotID slot);
void makeDeal(SlotID slot);//-1 for upgrading all creatures
int getState(SlotID slot); //-1 = no creature 0=can't upgrade, 1=upgraded, 2=can upgrade
State getState(SlotID slot);
public:
CHillFortWindow(const CGHeroInstance * visitor, const CGObjectInstance * object);
void updateGarrisons() override;//update buttons after garrison changes