1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

suggestions

This commit is contained in:
SoundSSGood 2024-07-16 00:03:06 +03:00
parent b42c6dbf44
commit ff5ddd76b7
5 changed files with 29 additions and 21 deletions

View File

@ -23,7 +23,12 @@
#include "widgets/CComponent.h" #include "widgets/CComponent.h"
#include "windows/CWindowWithArtifacts.h" #include "windows/CWindowWithArtifacts.h"
bool ArtifactsUIController::askToAssemble(const ArtifactLocation & al, const bool onlyEquipped, std::set<ArtifactID> * ignoredArtifacts) ArtifactsUIController::ArtifactsUIController()
{
numOfMovedArts = 0;
}
bool ArtifactsUIController::askToAssemble(const ArtifactLocation & al, const bool onlyEquipped, const bool checkIgnored)
{ {
if(auto hero = LOCPLINT->cb->getHero(al.artHolder)) if(auto hero = LOCPLINT->cb->getHero(al.artHolder))
{ {
@ -32,13 +37,13 @@ bool ArtifactsUIController::askToAssemble(const ArtifactLocation & al, const boo
logGlobal->error("artifact location %d points to nothing", al.slot.num); logGlobal->error("artifact location %d points to nothing", al.slot.num);
return false; return false;
} }
return askToAssemble(hero, al.slot, onlyEquipped, ignoredArtifacts); return askToAssemble(hero, al.slot, onlyEquipped, checkIgnored);
} }
return false; return false;
} }
bool ArtifactsUIController::askToAssemble(const CGHeroInstance * hero, const ArtifactPosition & slot, bool ArtifactsUIController::askToAssemble(const CGHeroInstance * hero, const ArtifactPosition & slot,
const bool onlyEquipped, std::set<ArtifactID> * ignoredArtifacts) const bool onlyEquipped, const bool checkIgnored)
{ {
assert(hero); assert(hero);
const auto art = hero->getArt(slot); const auto art = hero->getArt(slot);
@ -52,17 +57,17 @@ bool ArtifactsUIController::askToAssemble(const CGHeroInstance * hero, const Art
auto assemblyPossibilities = ArtifactUtils::assemblyPossibilities(hero, art->getTypeId(), onlyEquipped); auto assemblyPossibilities = ArtifactUtils::assemblyPossibilities(hero, art->getTypeId(), onlyEquipped);
if(!assemblyPossibilities.empty()) if(!assemblyPossibilities.empty())
{ {
auto askThread = new boost::thread([this, hero, art, slot, assemblyPossibilities, ignoredArtifacts]() -> void auto askThread = new boost::thread([this, hero, art, slot, assemblyPossibilities, checkIgnored]() -> void
{ {
boost::mutex::scoped_lock askLock(askAssembleArtifactMutex); boost::mutex::scoped_lock askLock(askAssembleArtifactMutex);
for(const auto combinedArt : assemblyPossibilities) for(const auto combinedArt : assemblyPossibilities)
{ {
boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex); boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
if(ignoredArtifacts) if(checkIgnored)
{ {
if(vstd::contains(*ignoredArtifacts, combinedArt->getId())) if(vstd::contains(ignoredArtifacts, combinedArt->getId()))
continue; continue;
ignoredArtifacts->emplace(combinedArt->getId()); ignoredArtifacts.emplace(combinedArt->getId());
} }
bool assembleConfirmed = false; bool assembleConfirmed = false;

View File

@ -20,16 +20,17 @@ VCMI_LIB_NAMESPACE_END
class ArtifactsUIController class ArtifactsUIController
{ {
public:
size_t numOfMovedArts; size_t numOfMovedArts;
size_t numOfArtsAskAssembleSession; size_t numOfArtsAskAssembleSession;
std::set<ArtifactID> ignoredArtifacts; std::set<ArtifactID> ignoredArtifacts;
boost::mutex askAssembleArtifactMutex; boost::mutex askAssembleArtifactMutex;
bool askToAssemble(const ArtifactLocation & al, const bool onlyEquipped = false, std::set<ArtifactID> * ignoredArtifacts = nullptr); public:
ArtifactsUIController();
bool askToAssemble(const ArtifactLocation & al, const bool onlyEquipped = false, const bool checkIgnored = false);
bool askToAssemble(const CGHeroInstance * hero, const ArtifactPosition & slot, const bool onlyEquipped = false, bool askToAssemble(const CGHeroInstance * hero, const ArtifactPosition & slot, const bool onlyEquipped = false,
std::set<ArtifactID> * ignoredArtifacts = nullptr); const bool checkIgnored = false);
bool askToDisassemble(const CGHeroInstance * hero, const ArtifactPosition & slot); bool askToDisassemble(const CGHeroInstance * hero, const ArtifactPosition & slot);
void artifactRemoved(); void artifactRemoved();

View File

@ -131,7 +131,9 @@ struct HeroObjectRetriever
CPlayerInterface::CPlayerInterface(PlayerColor Player): CPlayerInterface::CPlayerInterface(PlayerColor Player):
localState(std::make_unique<PlayerLocalState>(*this)), localState(std::make_unique<PlayerLocalState>(*this)),
movementController(std::make_unique<HeroMovementController>()) movementController(std::make_unique<HeroMovementController>()),
artifactController(std::make_unique<ArtifactsUIController>())
{ {
logGlobal->trace("\tHuman player interface for player %s being constructed", Player.toString()); logGlobal->trace("\tHuman player interface for player %s being constructed", Player.toString());
GH.defActionsDef = 0; GH.defActionsDef = 0;
@ -147,7 +149,6 @@ CPlayerInterface::CPlayerInterface(PlayerColor Player):
isAutoFightOn = false; isAutoFightOn = false;
isAutoFightEndBattle = false; isAutoFightEndBattle = false;
ignoreEvents = false; ignoreEvents = false;
numOfMovedArts = 0;
} }
CPlayerInterface::~CPlayerInterface() CPlayerInterface::~CPlayerInterface()
@ -1707,7 +1708,7 @@ void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj)
void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al) void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al)
{ {
ArtifactsUIController::askToAssemble(al, true, &ignoredArtifacts); artifactController->askToAssemble(al, true, true);
} }
void CPlayerInterface::artifactPut(const ArtifactLocation &al) void CPlayerInterface::artifactPut(const ArtifactLocation &al)
@ -1720,33 +1721,33 @@ void CPlayerInterface::artifactRemoved(const ArtifactLocation &al)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->onHeroChanged(cb->getHero(al.artHolder)); adventureInt->onHeroChanged(cb->getHero(al.artHolder));
ArtifactsUIController::artifactRemoved(); artifactController->artifactRemoved();
} }
void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst) void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->onHeroChanged(cb->getHero(dst.artHolder)); adventureInt->onHeroChanged(cb->getHero(dst.artHolder));
ArtifactsUIController::artifactMoved(); artifactController->artifactMoved();
} }
void CPlayerInterface::bulkArtMovementStart(size_t totalNumOfArts, size_t possibleAssemblyNumOfArts) void CPlayerInterface::bulkArtMovementStart(size_t totalNumOfArts, size_t possibleAssemblyNumOfArts)
{ {
ArtifactsUIController::bulkArtMovementStart(totalNumOfArts, possibleAssemblyNumOfArts); artifactController->bulkArtMovementStart(totalNumOfArts, possibleAssemblyNumOfArts);
} }
void CPlayerInterface::artifactAssembled(const ArtifactLocation &al) void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->onHeroChanged(cb->getHero(al.artHolder)); adventureInt->onHeroChanged(cb->getHero(al.artHolder));
ArtifactsUIController::artifactAssembled(); artifactController->artifactAssembled();
} }
void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al) void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->onHeroChanged(cb->getHero(al.artHolder)); adventureInt->onHeroChanged(cb->getHero(al.artHolder));
ArtifactsUIController::artifactDisassembled(); artifactController->artifactDisassembled();
} }
void CPlayerInterface::waitForAllDialogs() void CPlayerInterface::waitForAllDialogs()

View File

@ -56,7 +56,7 @@ namespace boost
} }
/// Central class for managing user interface logic /// Central class for managing user interface logic
class CPlayerInterface : public CGameInterface, public IUpdateable, public ArtifactsUIController class CPlayerInterface : public CGameInterface, public IUpdateable
{ {
bool ignoreEvents; bool ignoreEvents;
int autosaveCount; int autosaveCount;
@ -65,6 +65,7 @@ class CPlayerInterface : public CGameInterface, public IUpdateable, public Artif
std::unique_ptr<HeroMovementController> movementController; std::unique_ptr<HeroMovementController> movementController;
public: // TODO: make private public: // TODO: make private
std::unique_ptr<ArtifactsUIController> artifactController;
std::shared_ptr<Environment> env; std::shared_ptr<Environment> env;
std::unique_ptr<PlayerLocalState> localState; std::unique_ptr<PlayerLocalState> localState;

View File

@ -117,9 +117,9 @@ void CWindowWithArtifacts::showArtifactAssembling(const CArtifactsOfHeroBase & a
{ {
if(artsInst.getArt(artPlace.slot)) if(artsInst.getArt(artPlace.slot))
{ {
if(LOCPLINT->askToDisassemble(artsInst.getHero(), artPlace.slot)) if(LOCPLINT->artifactController->askToDisassemble(artsInst.getHero(), artPlace.slot))
return; return;
if(LOCPLINT->askToAssemble(artsInst.getHero(), artPlace.slot)) if(LOCPLINT->artifactController->askToAssemble(artsInst.getHero(), artPlace.slot))
return; return;
if(artPlace.text.size()) if(artPlace.text.size())
artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition); artPlace.LRClickableAreaWTextComp::showPopupWindow(cursorPosition);