1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Fix cancelling spellcast with escape

This commit is contained in:
Ivan Savenko 2023-05-08 17:30:02 +03:00
parent 243773b6ef
commit c01b74434c
5 changed files with 14 additions and 26 deletions

View File

@ -26,6 +26,7 @@
#include "../CGameInfo.h"
#include "../gui/CursorHandler.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../CMT.h"
#include "../PlayerLocalState.h"
#include "../CPlayerInterface.h"
@ -57,6 +58,8 @@ AdventureMapInterface::AdventureMapInterface():
widget = std::make_shared<AdventureMapWidget>(shortcuts);
shortcuts->setState(EAdventureState::MAKING_TURN);
widget->getMapView()->onViewMapActivated();
addUsedEvents(KEYBOARD);
}
void AdventureMapInterface::onMapViewMoved(const Rect & visibleArea, int mapLevel)
@ -234,6 +237,9 @@ void AdventureMapInterface::centerOnObject(const CGObjectInstance * obj)
void AdventureMapInterface::keyPressed(EShortcut key)
{
if (key == EShortcut::GLOBAL_CANCEL && spellBeingCasted)
hotkeyAbortCastingMode();
//fake mouse use to trigger onTileHovered()
GH.fakeMouseMove();
}

View File

@ -47,9 +47,6 @@ void AdventureMapShortcuts::setState(EAdventureState newState)
void AdventureMapShortcuts::onMapViewMoved(const Rect & visibleArea, int newMapLevel)
{
if(mapLevel == newMapLevel)
return;
mapLevel = newMapLevel;
}
@ -82,7 +79,6 @@ std::vector<AdventureMapShortcutState> AdventureMapShortcuts::getShortcuts()
{ EShortcut::GAME_RESTART_GAME, optionInMapView(), [this]() { this->restartGame(); } },
{ EShortcut::ADVENTURE_VISIT_OBJECT, optionHeroSelected(), [this]() { this->visitObject(); } },
{ EShortcut::ADVENTURE_VIEW_SELECTED, optionInMapView(), [this]() { this->openObject(); } },
{ EShortcut::GLOBAL_CANCEL, optionSpellcasting(), [this]() { this->abortSpellcasting(); } },
{ EShortcut::GAME_OPEN_MARKETPLACE, optionInMapView(), [this]() { this->showMarketplace(); } },
{ EShortcut::ADVENTURE_NEXT_TOWN, optionInMapView(), [this]() { this->nextTown(); } },
{ EShortcut::ADVENTURE_NEXT_OBJECT, optionInMapView(), [this]() { this->nextObject(); } },
@ -130,7 +126,6 @@ void AdventureMapShortcuts::worldViewScale4x()
void AdventureMapShortcuts::switchMapLevel()
{
// with support for future multi-level maps :)
int maxLevels = LOCPLINT->cb->getMapSize().z;
if (maxLevels < 2)
return;
@ -145,20 +140,13 @@ void AdventureMapShortcuts::showQuestlog()
void AdventureMapShortcuts::toggleSleepWake()
{
const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
if (!h)
if (!optionHeroSelected())
return;
bool newSleep = !LOCPLINT->localState->isHeroSleeping(h);
if (newSleep)
LOCPLINT->localState->setHeroAsleep(h);
if (optionHeroAwake())
setHeroSleeping();
else
LOCPLINT->localState->setHeroAwaken(h);
owner.onHeroChanged(h);
if (newSleep)
nextHero();
setHeroAwake();
}
void AdventureMapShortcuts::setHeroSleeping()
@ -193,7 +181,7 @@ void AdventureMapShortcuts::moveHeroAlongPath()
void AdventureMapShortcuts::showSpellbook()
{
if (!LOCPLINT->localState->getCurrentHero()) //checking necessary values
if (!LOCPLINT->localState->getCurrentHero())
return;
owner.centerOnObject(LOCPLINT->localState->getCurrentHero());
@ -324,11 +312,6 @@ void AdventureMapShortcuts::openObject()
LOCPLINT->openTownWindow(t);
}
void AdventureMapShortcuts::abortSpellcasting()
{
owner.hotkeyAbortCastingMode();
}
void AdventureMapShortcuts::showMarketplace()
{
//check if we have any marketplace

View File

@ -58,7 +58,6 @@ class AdventureMapShortcuts
void restartGame();
void visitObject();
void openObject();
void abortSpellcasting();
void showMarketplace();
void nextTown();
void nextObject();

View File

@ -133,7 +133,6 @@ std::shared_ptr<IImage> AdventureMapWidget::loadImage(const std::string & name)
if(images.count(resource.getName()) == 0)
images[resource.getName()] = IImage::createFromFile(resource.getName());
;
return images[resource.getName()];
}
@ -212,6 +211,7 @@ std::shared_ptr<CIntObject> AdventureMapWidget::buildMapContainer(const JsonNode
addWidget(entry["name"].String(), widget);
result->ownedChildren.push_back(widget);
// FIXME: remove cast and replace it with better check
if (std::dynamic_pointer_cast<CLabel>(widget) || std::dynamic_pointer_cast<CLabelGroup>(widget))
result->addChild(widget.get(), true);
else

View File

@ -168,7 +168,7 @@ void ScreenHandler::recreateWindowAndScreenBuffers()
void ScreenHandler::updateWindowState()
{
#if !defined(VCMI_MOBILE)
#ifdef VCMI_MOBILE
int displayIndex = getPreferredDisplayIndex();
switch(getPreferredWindowMode())
@ -332,7 +332,7 @@ void ScreenHandler::onScreenResize()
void ScreenHandler::validateSettings()
{
#if !defined(VCMI_MOBILE)
#ifdef VCMI_MOBILE
{
int displayIndex = settings["video"]["displayIndex"].Integer();
int displaysCount = SDL_GetNumVideoDisplays();