1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

show handicap resources

This commit is contained in:
Laserlicht
2024-07-16 02:01:55 +02:00
parent afd580b76a
commit af2b6a0051
5 changed files with 60 additions and 6 deletions

View File

@@ -79,10 +79,6 @@ void OptionsTab::recreate()
entries.insert(std::make_pair(pInfo.first, std::make_shared<PlayerOptionsEntry>(pInfo.second, * this)));
}
/*TResources resources = TResources();
resources[EGameResID::GOLD] = 50000;
CSH->setPlayerHandicap((PlayerColor)0, resources);*/
OptionsTabBase::recreate();
}
@@ -927,6 +923,30 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, con
}
labelWhoCanPlay = std::make_shared<CMultiLineLabel>(Rect(6, 23, 45, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->arraytxt[206 + whoCanPlay]);
labelHandicap = std::make_shared<CMultiLineLabel>(Rect(56, 24, 49, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, s->handicap.empty() ? CGI->generaltexth->arraytxt[210] : MetaString::createFromTextID("vcmi.lobby.handicap").toString());
handicap = std::make_shared<LRClickableArea>(Rect(56, 24, 49, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), [this](){
TResources resources = TResources();
resources[EGameResID::GOLD] = 50000;
CSH->setPlayerHandicap(s->color, resources);
}, [this](){
if(s->handicap.empty())
CRClickPopup::createAndPush(MetaString::createFromTextID("core.help.124.help").toString());
else
{
auto str = MetaString::createFromTextID("vcmi.lobby.handicap");
str.appendRawString(":\n");
for(auto & res : EGameResID::ALL_RESOURCES())
if(s->handicap[res] != 0)
{
str.appendRawString("\n");
str.appendName(res);
str.appendRawString(": ");
str.appendRawString(std::to_string(s->handicap[res]));
}
CRClickPopup::createAndPush(str.toString());
}
});
if(SEL->screenType == ESelectionScreen::newGame)
{
buttonTownLeft = std::make_shared<CButton>(Point(107, 5), AnimationPath::builtin("ADOPLFA.DEF"), CGI->generaltexth->zelp[132], std::bind(&IServerAPI::setPlayerOption, CSH, LobbyChangePlayerOption::TOWN, -1, s->color));

View File

@@ -27,6 +27,7 @@ class CComponentBox;
class CTextBox;
class CButton;
class CSlider;
class LRClickableArea;
class FilledTexturePlayerColored;
@@ -192,6 +193,8 @@ private:
std::shared_ptr<SelectedBox> town;
std::shared_ptr<SelectedBox> hero;
std::shared_ptr<SelectedBox> bonus;
std::shared_ptr<LRClickableArea> handicap;
std::shared_ptr<CMultiLineLabel> labelHandicap;
enum {HUMAN_OR_CPU, HUMAN, CPU} whoCanPlay;
PlayerOptionsEntry(const PlayerSettings & S, const OptionsTab & parentTab);

View File

@@ -367,6 +367,11 @@ void MetaString::appendName(const CreatureID & id, TQuantity count)
appendNamePlural(id);
}
void MetaString::appendName(const GameResID& id)
{
appendTextID(TextIdentifier("core.restypes", id.getNum()).get());
}
void MetaString::appendNameSingular(const CreatureID & id)
{
appendTextID(id.toEntity(VLC)->getNameSingularTextID());

View File

@@ -80,6 +80,7 @@ public:
void appendName(const SpellID& id);
void appendName(const PlayerColor& id);
void appendName(const CreatureID & id, TQuantity count);
void appendName(const GameResID& id);
void appendNameSingular(const CreatureID & id);
void appendNamePlural(const CreatureID & id);
void appendEOL();

View File

@@ -784,7 +784,24 @@ void CVCMIServer::setPlayerHandicap(PlayerColor color, TResources handicap)
str.appendTextID("vcmi.lobby.handicap");
str.appendRawString(" ");
str.appendName(color);
str.appendRawString(":\n" + handicap.toString());
str.appendRawString(":");
if(handicap.empty())
{
str.appendRawString(" ");
str.appendTextID("core.genrltxt.523");
announceTxt(str);
return;
}
for(auto & res : EGameResID::ALL_RESOURCES())
if(handicap[res] != 0)
{
str.appendRawString(" ");
str.appendName(res);
str.appendRawString(":");
str.appendRawString(std::to_string(handicap[res]));
}
announceTxt(str);
}
@@ -1041,7 +1058,15 @@ void CVCMIServer::multiplayerWelcomeMessage()
str.appendTextID("vcmi.lobby.handicap");
str.appendRawString(" ");
str.appendName(pi.first);
str.appendRawString(": " + pi.second.handicap.toString());
str.appendRawString(":");
for(auto & res : EGameResID::ALL_RESOURCES())
if(pi.second.handicap[res] != 0)
{
str.appendRawString(" ");
str.appendName(res);
str.appendRawString(":");
str.appendRawString(std::to_string(pi.second.handicap[res]));
}
announceTxt(str);
}