1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +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 "../CGameInfo.h"
#include "../gui/CursorHandler.h" #include "../gui/CursorHandler.h"
#include "../gui/CGuiHandler.h" #include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../CMT.h" #include "../CMT.h"
#include "../PlayerLocalState.h" #include "../PlayerLocalState.h"
#include "../CPlayerInterface.h" #include "../CPlayerInterface.h"
@@ -57,6 +58,8 @@ AdventureMapInterface::AdventureMapInterface():
widget = std::make_shared<AdventureMapWidget>(shortcuts); widget = std::make_shared<AdventureMapWidget>(shortcuts);
shortcuts->setState(EAdventureState::MAKING_TURN); shortcuts->setState(EAdventureState::MAKING_TURN);
widget->getMapView()->onViewMapActivated(); widget->getMapView()->onViewMapActivated();
addUsedEvents(KEYBOARD);
} }
void AdventureMapInterface::onMapViewMoved(const Rect & visibleArea, int mapLevel) void AdventureMapInterface::onMapViewMoved(const Rect & visibleArea, int mapLevel)
@@ -234,6 +237,9 @@ void AdventureMapInterface::centerOnObject(const CGObjectInstance * obj)
void AdventureMapInterface::keyPressed(EShortcut key) void AdventureMapInterface::keyPressed(EShortcut key)
{ {
if (key == EShortcut::GLOBAL_CANCEL && spellBeingCasted)
hotkeyAbortCastingMode();
//fake mouse use to trigger onTileHovered() //fake mouse use to trigger onTileHovered()
GH.fakeMouseMove(); GH.fakeMouseMove();
} }

View File

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

View File

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

View File

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

View File

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