From d3ced6b703494c6d3840ea373edd14236cd2d8d2 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Tue, 19 Sep 2023 19:51:31 +0300 Subject: [PATCH] Block revisit object shortcut if no visit is possible --- client/adventureMap/AdventureMapShortcuts.cpp | 14 +++++++++++++- client/adventureMap/AdventureMapShortcuts.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/client/adventureMap/AdventureMapShortcuts.cpp b/client/adventureMap/AdventureMapShortcuts.cpp index faae694fb..9087b835f 100644 --- a/client/adventureMap/AdventureMapShortcuts.cpp +++ b/client/adventureMap/AdventureMapShortcuts.cpp @@ -79,7 +79,7 @@ std::vector AdventureMapShortcuts::getShortcuts() { EShortcut::ADVENTURE_DIG_GRAIL, optionHeroSelected(), [this]() { this->digGrail(); } }, { EShortcut::ADVENTURE_VIEW_PUZZLE, optionSidePanelActive(),[this]() { this->viewPuzzleMap(); } }, { EShortcut::GAME_RESTART_GAME, optionInMapView(), [this]() { this->restartGame(); } }, - { EShortcut::ADVENTURE_VISIT_OBJECT, optionHeroSelected(), [this]() { this->visitObject(); } }, + { EShortcut::ADVENTURE_VISIT_OBJECT, optionCanVisitObject(), [this]() { this->visitObject(); } }, { EShortcut::ADVENTURE_VIEW_SELECTED, optionInMapView(), [this]() { this->openObject(); } }, { EShortcut::GAME_OPEN_MARKETPLACE, optionInMapView(), [this]() { this->showMarketplace(); } }, { EShortcut::ADVENTURE_ZOOM_IN, optionSidePanelActive(),[this]() { this->zoom(+1); } }, @@ -422,6 +422,18 @@ bool AdventureMapShortcuts::optionHeroAwake() return optionInMapView() && hero && !LOCPLINT->localState->isHeroSleeping(hero); } +bool AdventureMapShortcuts::optionCanVisitObject() +{ + if (!optionHeroSelected()) + return false; + + auto * hero = LOCPLINT->localState->getCurrentHero(); + auto objects = LOCPLINT->cb->getVisitableObjs(hero->visitablePos()); + + assert(vstd::contains(objects,hero)); + return objects.size() > 1; // there is object other than our hero +} + bool AdventureMapShortcuts::optionHeroSelected() { return optionInMapView() && LOCPLINT->localState->getCurrentHero() != nullptr; diff --git a/client/adventureMap/AdventureMapShortcuts.h b/client/adventureMap/AdventureMapShortcuts.h index 8e86779a7..30775c0c0 100644 --- a/client/adventureMap/AdventureMapShortcuts.h +++ b/client/adventureMap/AdventureMapShortcuts.h @@ -77,6 +77,7 @@ public: bool optionHeroSelected(); bool optionHeroCanMove(); bool optionHasNextHero(); + bool optionCanVisitObject(); bool optionSpellcasting(); bool optionInMapView(); bool optionInWorldView();