1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +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.deleteFolder" : "Do you want to delete following folder?",
"vcmi.lobby.deleteMode" : "Switch to delete mode and back", "vcmi.lobby.deleteMode" : "Switch to delete mode and back",
"vcmi.lobby.battleOnlyMode" : "Battle only mode", "vcmi.lobby.battleOnlyMode" : "Battle only mode",
"vcmi.lobby.battleOnlyModeBattleground" : "Battleground", "vcmi.lobby.battleOnlyModeBattlefield" : "Battlefield",
"vcmi.lobby.battleOnlyModeBattlegroundSelect" : "Select Battleground", "vcmi.lobby.battleOnlyModeBattlefieldSelect" : "Select Battlefield",
"vcmi.lobby.battleOnlyModeHeroSelect" : "Select Hero", "vcmi.lobby.battleOnlyModeHeroSelect" : "Select Hero",
"vcmi.lobby.battleOnlyModeCreatureSelect" : "Select Creature", "vcmi.lobby.battleOnlyModeCreatureSelect" : "Select Creature",
"vcmi.lobby.battleOnlyModeSelect" : "Select", "vcmi.lobby.battleOnlyModeSelect" : "Select",

View File

@@ -139,8 +139,8 @@
"vcmi.lobby.deleteFolder" : "Möchtet Ihr folgenden Ordner löschen?", "vcmi.lobby.deleteFolder" : "Möchtet Ihr folgenden Ordner löschen?",
"vcmi.lobby.deleteMode" : "In den Löschmodus wechseln und zurück", "vcmi.lobby.deleteMode" : "In den Löschmodus wechseln und zurück",
"vcmi.lobby.battleOnlyMode" : "Nur Kämpfen Modus", "vcmi.lobby.battleOnlyMode" : "Nur Kämpfen Modus",
"vcmi.lobby.battleOnlyModeBattleground" : "Schlachtfeld", "vcmi.lobby.battleOnlyModeBattlefield" : "Schlachtfeld",
"vcmi.lobby.battleOnlyModeBattlegroundSelect" : "Schlachtfeld auswählen", "vcmi.lobby.battleOnlyModeBattlefieldSelect" : "Schlachtfeld auswählen",
"vcmi.lobby.battleOnlyModeHeroSelect" : "Helden auswählen", "vcmi.lobby.battleOnlyModeHeroSelect" : "Helden auswählen",
"vcmi.lobby.battleOnlyModeCreatureSelect" : "Kreatur auswählen", "vcmi.lobby.battleOnlyModeCreatureSelect" : "Kreatur auswählen",
"vcmi.lobby.battleOnlyModeSelect" : "Wä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); 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")); 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::string> texts;
std::vector<std::shared_ptr<IImage>> images; std::vector<std::shared_ptr<IImage>> images;
auto terrains = LIBRARY->terrainTypeHandler->objects; auto & terrains = LIBRARY->terrainTypeHandler->objects;
for (const auto & terrain : terrains) for (const auto & terrain : terrains)
{ {
texts.push_back(terrain->getNameTranslated()); texts.push_back(terrain->getNameTranslated());
@@ -99,20 +99,17 @@ BattleOnlyModeWindow::BattleOnlyModeWindow()
images.push_back(image); images.push_back(image);
} }
auto factions = LIBRARY->townh->objects; auto factions = LIBRARY->townh->getDefaultAllowed();
factions.erase(std::remove_if(factions.begin(), factions.end(), [](const std::shared_ptr<CFaction>& n) {
return !n->town;
}), factions.end());
for (const auto & faction : factions) 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); image->scaleTo(Point(35, 23), EScalingAlgorithm::NEAREST);
images.push_back(image); 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) if(terrains.size() > index)
{ {
selectedTerrain = terrains[index]->getId(); selectedTerrain = terrains[index]->getId();
@@ -121,7 +118,9 @@ BattleOnlyModeWindow::BattleOnlyModeWindow()
else else
{ {
selectedTerrain = TerrainId::NONE; 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(); setTerrainButtonText();
setOkButtonEnabled(); setOkButtonEnabled();
@@ -171,7 +170,7 @@ void BattleOnlyModeWindow::init()
void BattleOnlyModeWindow::setTerrainButtonText() 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() void BattleOnlyModeWindow::setOkButtonEnabled()
@@ -240,20 +239,20 @@ void BattleOnlyModeHeroSelector::setHeroIcon()
} }
heroImage->addLClickCallback([this](){ heroImage->addLClickCallback([this](){
auto heroes = LIBRARY->heroh->objects; auto allowedSet = LIBRARY->heroh->getDefaultAllowed();
std::sort(heroes.begin(), heroes.end(), [](const std::shared_ptr<CHero>& a, const std::shared_ptr<CHero>& b) { std::vector<HeroTypeID> heroes(allowedSet.begin(), allowedSet.end());
if (a->heroClass->getId() == b->heroClass->getId()) std::sort(heroes.begin(), heroes.end(), [](auto a, auto b) {
return a->getNameTranslated() < b->getNameTranslated(); auto heroA = a.toHeroType();
if (a->heroClass->faction == b->heroClass->faction) auto heroB = b.toHeroType();
return a->heroClass->getId() < b->heroClass->getId(); if (heroA->heroClass->getId() == heroB->heroClass->getId())
return a->heroClass->faction < b->heroClass->faction; 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) { int selectedIndex = !selectedHero ? 0 : (1 + std::distance(heroes.begin(), std::find_if(heroes.begin(), heroes.end(), [this](auto heroID) {
return heroPtr.get() == selectedHero->getHeroType(); return heroID == selectedHero->getHeroType()->getId();
}))); })));
std::vector<std::string> texts; std::vector<std::string> texts;
@@ -263,9 +262,9 @@ void BattleOnlyModeHeroSelector::setHeroIcon()
images.push_back(nullptr); images.push_back(nullptr);
for (const auto & h : heroes) 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); image->scaleTo(Point(35, 23), EScalingAlgorithm::NEAREST);
images.push_back(image); images.push_back(image);
} }
@@ -279,10 +278,10 @@ void BattleOnlyModeHeroSelector::setHeroIcon()
index--; index--;
auto hero = heroes[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 templates = factory->getTemplates();
auto obj = std::dynamic_pointer_cast<CGHeroInstance>(factory->create(parent.cb.get(), templates.front())); auto obj = std::dynamic_pointer_cast<CGHeroInstance>(factory->create(parent.cb.get(), templates.front()));
obj->setHeroType(hero->getId()); obj->setHeroType(hero);
selectedHero = obj; selectedHero = obj;
setHeroIcon(); setHeroIcon();
@@ -293,7 +292,7 @@ void BattleOnlyModeHeroSelector::setHeroIcon()
return; return;
index--; index--;
ENGINE->windows().createAndPushWindow<CHeroOverview>(heroes[index]->getId()); ENGINE->windows().createAndPushWindow<CHeroOverview>(heroes.at(index));
}; };
ENGINE->windows().pushWindow(window); ENGINE->windows().pushWindow(window);
}); });
@@ -321,20 +320,20 @@ void BattleOnlyModeHeroSelector::setCreatureIcons()
} }
creatureImage[i]->addLClickCallback([this, i](){ creatureImage[i]->addLClickCallback([this, i](){
auto creatures = LIBRARY->creh->objects; auto allowedSet = LIBRARY->creh->getDefaultAllowed();
std::sort(creatures.begin(), creatures.end(), [](const std::shared_ptr<CCreature>& a, const std::shared_ptr<CCreature>& b) { std::vector<CreatureID> creatures(allowedSet.begin(), allowedSet.end());
if (a->getLevel() == b->getLevel()) std::sort(creatures.begin(), creatures.end(), [](auto a, auto b) {
return a->getNameSingularTranslated() < b->getNameSingularTranslated(); auto creatureA = a.toCreature();
if (a->getFactionID() == b->getFactionID()) auto creatureB = b.toCreature();
return a->getLevel() < b->getLevel(); if (creatureA->getLevel() == creatureB->getLevel())
return a->getFactionID() < b->getFactionID(); 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) { int selectedIndex = selectedArmy->slotEmpty(SlotID(i)) ? 0 : (1 + std::distance(creatures.begin(), std::find_if(creatures.begin(), creatures.end(), [this, i](auto creatureID) {
return creaturePtr->getId() == selectedArmy->Slots().at(SlotID(i))->getId(); return creatureID == selectedArmy->Slots().at(SlotID(i))->getId();
}))); })));
std::vector<std::string> texts; std::vector<std::string> texts;
@@ -344,9 +343,9 @@ void BattleOnlyModeHeroSelector::setCreatureIcons()
images.push_back(nullptr); images.push_back(nullptr);
for (const auto & c : creatures) 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); image->scaleTo(Point(23, 23), EScalingAlgorithm::NEAREST);
images.push_back(image); images.push_back(image);
} }
@@ -359,7 +358,8 @@ void BattleOnlyModeHeroSelector::setCreatureIcons()
return; return;
} }
index--; index--;
auto creature = creatures[index];
auto creature = creatures.at(index).toCreature();
selectedArmy->setCreature(SlotID(i), creature->getId(), 100); selectedArmy->setCreature(SlotID(i), creature->getId(), 100);
selectedArmyInput[SlotID(i)]->setText("100"); selectedArmyInput[SlotID(i)]->setText("100");
setCreatureIcons(); setCreatureIcons();
@@ -369,7 +369,7 @@ void BattleOnlyModeHeroSelector::setCreatureIcons()
return; return;
index--; index--;
ENGINE->windows().createAndPushWindow<CStackWindow>(creatures.at(index).get(), true); ENGINE->windows().createAndPushWindow<CStackWindow>(creatures.at(index).toCreature(), true);
}; };
ENGINE->windows().pushWindow(window); ENGINE->windows().pushWindow(window);
}); });

View File

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

View File

@@ -94,7 +94,7 @@ void CIdentifierStorage::requestIdentifier(const ObjectCallback & callback) cons
checkIdentifier(callback.type); checkIdentifier(callback.type);
checkIdentifier(callback.name); checkIdentifier(callback.name);
//assert(!callback.localScope.empty()); assert(!callback.localScope.empty());
if (state != ELoadingState::FINISHED) // enqueue request if loading is still in progress if (state != ELoadingState::FINISHED) // enqueue request if loading is still in progress
scheduledRequests.push_back(callback); 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) 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 scopeAndFullName = vstd::splitStringToPair(fullName, ':');
auto typeAndName = vstd::splitStringToPair(scopeAndFullName.second, '.'); auto typeAndName = vstd::splitStringToPair(scopeAndFullName.second, '.');