1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

code review

This commit is contained in:
Laserlicht
2025-10-25 13:21:58 +02:00
parent 34ddc9343d
commit da2b565225
5 changed files with 51 additions and 51 deletions

View File

@@ -139,8 +139,8 @@
"vcmi.lobby.deleteFolder" : "Do you want to delete following folder?",
"vcmi.lobby.deleteMode" : "Switch to delete mode and back",
"vcmi.lobby.battleOnlyMode" : "Battle only mode",
"vcmi.lobby.battleOnlyModeBattleground" : "Battleground",
"vcmi.lobby.battleOnlyModeBattlegroundSelect" : "Select Battleground",
"vcmi.lobby.battleOnlyModeBattlefield" : "Battlefield",
"vcmi.lobby.battleOnlyModeBattlefieldSelect" : "Select Battlefield",
"vcmi.lobby.battleOnlyModeHeroSelect" : "Select Hero",
"vcmi.lobby.battleOnlyModeCreatureSelect" : "Select Creature",
"vcmi.lobby.battleOnlyModeSelect" : "Select",

View File

@@ -139,8 +139,8 @@
"vcmi.lobby.deleteFolder" : "Möchtet Ihr folgenden Ordner löschen?",
"vcmi.lobby.deleteMode" : "In den Löschmodus wechseln und zurück",
"vcmi.lobby.battleOnlyMode" : "Nur Kämpfen Modus",
"vcmi.lobby.battleOnlyModeBattleground" : "Schlachtfeld",
"vcmi.lobby.battleOnlyModeBattlegroundSelect" : "Schlachtfeld auswählen",
"vcmi.lobby.battleOnlyModeBattlefield" : "Schlachtfeld",
"vcmi.lobby.battleOnlyModeBattlefieldSelect" : "Schlachtfeld auswählen",
"vcmi.lobby.battleOnlyModeHeroSelect" : "Helden auswählen",
"vcmi.lobby.battleOnlyModeCreatureSelect" : "Kreatur auswählen",
"vcmi.lobby.battleOnlyModeSelect" : "Wählen",

View File

@@ -80,11 +80,11 @@ BattleOnlyModeWindow::BattleOnlyModeWindow()
buttonAbort = std::make_shared<CButton>(Point(265, 203), AnimationPath::builtin("MuBcanc"), CButton::tooltip(), [this](){ close(); }, EShortcut::GLOBAL_CANCEL);
title = std::make_shared<CLabel>(260, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, LIBRARY->generaltexth->translate("vcmi.lobby.battleOnlyMode"));
battlegroundSelector = std::make_shared<CButton>(Point(29, 174), AnimationPath::builtin("GSPButtonClear"), CButton::tooltip(), [this](){
battlefieldSelector = std::make_shared<CButton>(Point(29, 174), AnimationPath::builtin("GSPButtonClear"), CButton::tooltip(), [this](){
std::vector<std::string> texts;
std::vector<std::shared_ptr<IImage>> images;
auto terrains = LIBRARY->terrainTypeHandler->objects;
auto & terrains = LIBRARY->terrainTypeHandler->objects;
for (const auto & terrain : terrains)
{
texts.push_back(terrain->getNameTranslated());
@@ -99,20 +99,17 @@ BattleOnlyModeWindow::BattleOnlyModeWindow()
images.push_back(image);
}
auto factions = LIBRARY->townh->objects;
factions.erase(std::remove_if(factions.begin(), factions.end(), [](const std::shared_ptr<CFaction>& n) {
return !n->town;
}), factions.end());
auto factions = LIBRARY->townh->getDefaultAllowed();
for (const auto & faction : factions)
{
texts.push_back(faction->getNameTranslated());
texts.push_back(faction.toFaction()->getNameTranslated());
auto image = ENGINE->renderHandler().loadImage(AnimationPath::builtin("ITPA"), faction->town->clientInfo.icons[true][false] + 2, 0, EImageBlitMode::OPAQUE);
auto image = ENGINE->renderHandler().loadImage(AnimationPath::builtin("ITPA"), faction.toFaction()->town->clientInfo.icons[true][false] + 2, 0, EImageBlitMode::OPAQUE);
image->scaleTo(Point(35, 23), EScalingAlgorithm::NEAREST);
images.push_back(image);
}
ENGINE->windows().createAndPushWindow<CObjectListWindow>(texts, nullptr, LIBRARY->generaltexth->translate("vcmi.lobby.battleOnlyModeBattleground"), LIBRARY->generaltexth->translate("vcmi.lobby.battleOnlyModeBattlegroundSelect"), [this, terrains, factions](int index){
ENGINE->windows().createAndPushWindow<CObjectListWindow>(texts, nullptr, LIBRARY->generaltexth->translate("vcmi.lobby.battleOnlyModeBattlefield"), LIBRARY->generaltexth->translate("vcmi.lobby.battleOnlyModeBattlefieldSelect"), [this, terrains, factions](int index){
if(terrains.size() > index)
{
selectedTerrain = terrains[index]->getId();
@@ -121,7 +118,9 @@ BattleOnlyModeWindow::BattleOnlyModeWindow()
else
{
selectedTerrain = TerrainId::NONE;
selectedTown = factions[index - terrains.size()]->getId();
auto it = std::next(factions.begin(), index - terrains.size());
if (it != factions.end())
selectedTown = *it;
}
setTerrainButtonText();
setOkButtonEnabled();
@@ -171,7 +170,7 @@ void BattleOnlyModeWindow::init()
void BattleOnlyModeWindow::setTerrainButtonText()
{
battlegroundSelector->setTextOverlay(LIBRARY->generaltexth->translate("vcmi.lobby.battleOnlyModeBattleground") + ": " + (selectedTerrain != TerrainId::NONE ? selectedTerrain.toEntity(LIBRARY)->getNameTranslated() : selectedTown.toEntity(LIBRARY)->getNameTranslated()), EFonts::FONT_SMALL, Colors::WHITE);
battlefieldSelector->setTextOverlay(LIBRARY->generaltexth->translate("vcmi.lobby.battleOnlyModeBattlefield") + ": " + (selectedTerrain != TerrainId::NONE ? selectedTerrain.toEntity(LIBRARY)->getNameTranslated() : selectedTown.toEntity(LIBRARY)->getNameTranslated()), EFonts::FONT_SMALL, Colors::WHITE);
}
void BattleOnlyModeWindow::setOkButtonEnabled()
@@ -240,20 +239,20 @@ void BattleOnlyModeHeroSelector::setHeroIcon()
}
heroImage->addLClickCallback([this](){
auto heroes = LIBRARY->heroh->objects;
std::sort(heroes.begin(), heroes.end(), [](const std::shared_ptr<CHero>& a, const std::shared_ptr<CHero>& b) {
if (a->heroClass->getId() == b->heroClass->getId())
return a->getNameTranslated() < b->getNameTranslated();
if (a->heroClass->faction == b->heroClass->faction)
return a->heroClass->getId() < b->heroClass->getId();
return a->heroClass->faction < b->heroClass->faction;
auto allowedSet = LIBRARY->heroh->getDefaultAllowed();
std::vector<HeroTypeID> heroes(allowedSet.begin(), allowedSet.end());
std::sort(heroes.begin(), heroes.end(), [](auto a, auto b) {
auto heroA = a.toHeroType();
auto heroB = b.toHeroType();
if (heroA->heroClass->getId() == heroB->heroClass->getId())
return heroA->getNameTranslated() < heroB->getNameTranslated();
if (heroA->heroClass->faction == heroB->heroClass->faction)
return heroA->heroClass->getId() < heroB->heroClass->getId();
return heroA->heroClass->faction < heroB->heroClass->faction;
});
heroes.erase(std::remove_if(heroes.begin(), heroes.end(), [](const std::shared_ptr<CHero>& n) {
return n->special;
}), heroes.end());
int selectedIndex = !selectedHero ? 0 : (1 + std::distance(heroes.begin(), std::find_if(heroes.begin(), heroes.end(), [this](const std::shared_ptr<CHero>& heroPtr) {
return heroPtr.get() == selectedHero->getHeroType();
int selectedIndex = !selectedHero ? 0 : (1 + std::distance(heroes.begin(), std::find_if(heroes.begin(), heroes.end(), [this](auto heroID) {
return heroID == selectedHero->getHeroType()->getId();
})));
std::vector<std::string> texts;
@@ -263,9 +262,9 @@ void BattleOnlyModeHeroSelector::setHeroIcon()
images.push_back(nullptr);
for (const auto & h : heroes)
{
texts.push_back(h->getNameTranslated());
texts.push_back(h.toHeroType()->getNameTranslated());
auto image = ENGINE->renderHandler().loadImage(AnimationPath::builtin("PortraitsSmall"), h->imageIndex, 0, EImageBlitMode::OPAQUE);
auto image = ENGINE->renderHandler().loadImage(AnimationPath::builtin("PortraitsSmall"), h.toHeroType()->imageIndex, 0, EImageBlitMode::OPAQUE);
image->scaleTo(Point(35, 23), EScalingAlgorithm::NEAREST);
images.push_back(image);
}
@@ -279,10 +278,10 @@ void BattleOnlyModeHeroSelector::setHeroIcon()
index--;
auto hero = heroes[index];
auto factory = LIBRARY->objtypeh->getHandlerFor(Obj::HERO, hero->heroClass->getId());
auto factory = LIBRARY->objtypeh->getHandlerFor(Obj::HERO, hero.toHeroType()->heroClass->getId());
auto templates = factory->getTemplates();
auto obj = std::dynamic_pointer_cast<CGHeroInstance>(factory->create(parent.cb.get(), templates.front()));
obj->setHeroType(hero->getId());
obj->setHeroType(hero);
selectedHero = obj;
setHeroIcon();
@@ -293,7 +292,7 @@ void BattleOnlyModeHeroSelector::setHeroIcon()
return;
index--;
ENGINE->windows().createAndPushWindow<CHeroOverview>(heroes[index]->getId());
ENGINE->windows().createAndPushWindow<CHeroOverview>(heroes.at(index));
};
ENGINE->windows().pushWindow(window);
});
@@ -321,20 +320,20 @@ void BattleOnlyModeHeroSelector::setCreatureIcons()
}
creatureImage[i]->addLClickCallback([this, i](){
auto creatures = LIBRARY->creh->objects;
std::sort(creatures.begin(), creatures.end(), [](const std::shared_ptr<CCreature>& a, const std::shared_ptr<CCreature>& b) {
if (a->getLevel() == b->getLevel())
return a->getNameSingularTranslated() < b->getNameSingularTranslated();
if (a->getFactionID() == b->getFactionID())
return a->getLevel() < b->getLevel();
return a->getFactionID() < b->getFactionID();
auto allowedSet = LIBRARY->creh->getDefaultAllowed();
std::vector<CreatureID> creatures(allowedSet.begin(), allowedSet.end());
std::sort(creatures.begin(), creatures.end(), [](auto a, auto b) {
auto creatureA = a.toCreature();
auto creatureB = b.toCreature();
if (creatureA->getLevel() == creatureB->getLevel())
return creatureA->getNameSingularTranslated() < creatureB->getNameSingularTranslated();
if (creatureA->getFactionID() == creatureB->getFactionID())
return creatureA->getLevel() < creatureB->getLevel();
return creatureA->getFactionID() < creatureB->getFactionID();
});
creatures.erase(std::remove_if(creatures.begin(), creatures.end(), [](const std::shared_ptr<CCreature>& n) {
return n->special;
}), creatures.end());
int selectedIndex = selectedArmy->slotEmpty(SlotID(i)) ? 0 : (1 + std::distance(creatures.begin(), std::find_if(creatures.begin(), creatures.end(), [this, i](const std::shared_ptr<CCreature>& creaturePtr) {
return creaturePtr->getId() == selectedArmy->Slots().at(SlotID(i))->getId();
int selectedIndex = selectedArmy->slotEmpty(SlotID(i)) ? 0 : (1 + std::distance(creatures.begin(), std::find_if(creatures.begin(), creatures.end(), [this, i](auto creatureID) {
return creatureID == selectedArmy->Slots().at(SlotID(i))->getId();
})));
std::vector<std::string> texts;
@@ -344,9 +343,9 @@ void BattleOnlyModeHeroSelector::setCreatureIcons()
images.push_back(nullptr);
for (const auto & c : creatures)
{
texts.push_back(c->getNameSingularTranslated());
texts.push_back(c.toCreature()->getNameSingularTranslated());
auto image = ENGINE->renderHandler().loadImage(AnimationPath::builtin("CPRSMALL"), c->getIconIndex(), 0, EImageBlitMode::OPAQUE);
auto image = ENGINE->renderHandler().loadImage(AnimationPath::builtin("CPRSMALL"), c.toCreature()->getIconIndex(), 0, EImageBlitMode::OPAQUE);
image->scaleTo(Point(23, 23), EScalingAlgorithm::NEAREST);
images.push_back(image);
}
@@ -359,7 +358,8 @@ void BattleOnlyModeHeroSelector::setCreatureIcons()
return;
}
index--;
auto creature = creatures[index];
auto creature = creatures.at(index).toCreature();
selectedArmy->setCreature(SlotID(i), creature->getId(), 100);
selectedArmyInput[SlotID(i)]->setText("100");
setCreatureIcons();
@@ -369,7 +369,7 @@ void BattleOnlyModeHeroSelector::setCreatureIcons()
return;
index--;
ENGINE->windows().createAndPushWindow<CStackWindow>(creatures.at(index).get(), true);
ENGINE->windows().createAndPushWindow<CStackWindow>(creatures.at(index).toCreature(), true);
};
ENGINE->windows().pushWindow(window);
});

View File

@@ -71,7 +71,7 @@ private:
std::shared_ptr<CButton> buttonAbort;
std::shared_ptr<CLabel> title;
std::shared_ptr<CButton> battlegroundSelector;
std::shared_ptr<CButton> battlefieldSelector;
std::shared_ptr<CButton> buttonReset;
std::shared_ptr<BattleOnlyModeHeroSelector> heroSelector1;
std::shared_ptr<BattleOnlyModeHeroSelector> heroSelector2;

View File

@@ -94,7 +94,7 @@ void CIdentifierStorage::requestIdentifier(const ObjectCallback & callback) cons
checkIdentifier(callback.type);
checkIdentifier(callback.name);
//assert(!callback.localScope.empty());
assert(!callback.localScope.empty());
if (state != ELoadingState::FINISHED) // enqueue request if loading is still in progress
scheduledRequests.push_back(callback);
@@ -126,7 +126,7 @@ CIdentifierStorage::ObjectCallback CIdentifierStorage::ObjectCallback::fromNameW
CIdentifierStorage::ObjectCallback CIdentifierStorage::ObjectCallback::fromNameAndType(const std::string & scope, const std::string & type, const std::string & fullName, const std::function<void(si32)> & callback, bool optional, bool bypassDependenciesCheck, bool caseSensitive)
{
//assert(!scope.empty());
assert(!scope.empty());
auto scopeAndFullName = vstd::splitStringToPair(fullName, ':');
auto typeAndName = vstd::splitStringToPair(scopeAndFullName.second, '.');