From f4bff876d50511180f04ecbd1850a02cf13107dd Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 7 Jan 2024 16:38:37 +0100 Subject: [PATCH 1/2] make queue interactable --- client/battle/BattleFieldController.cpp | 22 +++++++++++++--------- client/battle/BattleInterfaceClasses.cpp | 9 +++++++++ client/battle/BattleInterfaceClasses.h | 1 + 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/client/battle/BattleFieldController.cpp b/client/battle/BattleFieldController.cpp index b0ee095b5..378273bc8 100644 --- a/client/battle/BattleFieldController.cpp +++ b/client/battle/BattleFieldController.cpp @@ -11,6 +11,7 @@ #include "BattleFieldController.h" #include "BattleInterface.h" +#include "BattleWindow.h" #include "BattleActionsController.h" #include "BattleInterfaceClasses.h" #include "BattleEffectsController.h" @@ -360,10 +361,7 @@ std::set BattleFieldController::getMovementRangeForHoveredStack() if (!settings["battle"]["movementHighlightOnHover"].Bool() && !GH.isKeyboardShiftDown()) return result; - auto hoveredHex = getHoveredHex(); - - // add possible movement hexes for stack under mouse - const CStack * const hoveredStack = owner.getBattle()->battleGetStackByPos(hoveredHex, true); + auto hoveredStack = getHoveredStack(); if(hoveredStack) { std::vector v = owner.getBattle()->battleGetAvailableHexes(hoveredStack, true, true, nullptr); @@ -590,11 +588,9 @@ void BattleFieldController::showHighlightedHexes(Canvas & canvas) std::set hoveredSpellHexes = getHighlightedHexesForSpellRange(); std::set hoveredMoveHexes = getHighlightedHexesForMovementTarget(); - BattleHex hoveredHex = getHoveredHex(); - if(hoveredHex == BattleHex::INVALID) - return; - const CStack * hoveredStack = getHoveredStack(); + if(!hoveredStack) + return; // skip range limit calculations if unit hovered is not a shooter if(hoveredStack && hoveredStack->isShooter()) @@ -608,7 +604,7 @@ void BattleFieldController::showHighlightedHexes(Canvas & canvas) calculateRangeLimitAndHighlightImages(shootingRangeDistance, shootingRangeLimitImages, shootingRangeLimitHexes, shootingRangeLimitHexesHighligts); } - auto const & hoveredMouseHexes = owner.actionsController->currentActionSpellcasting(getHoveredHex()) ? hoveredSpellHexes : hoveredMoveHexes; + auto const & hoveredMouseHexes = getHoveredHex() != BattleHex::INVALID && owner.actionsController->currentActionSpellcasting(getHoveredHex()) ? hoveredSpellHexes : hoveredMoveHexes; for(int hex = 0; hex < GameConstants::BFIELD_SIZE; ++hex) { @@ -676,6 +672,14 @@ const CStack* BattleFieldController::getHoveredStack() auto hoveredHex = getHoveredHex(); const CStack* hoveredStack = owner.getBattle()->battleGetStackByPos(hoveredHex, true); + if(owner.windowObject->getQueueHoveredUnitId().has_value()) + { + auto stacks = owner.getBattle()->battleGetAllStacks(); + for(const CStack * stack : stacks) + if(stack->unitId() == *owner.windowObject->getQueueHoveredUnitId()) + hoveredStack = stack; + } + return hoveredStack; } diff --git a/client/battle/BattleInterfaceClasses.cpp b/client/battle/BattleInterfaceClasses.cpp index 721caf49b..b8667fdc3 100644 --- a/client/battle/BattleInterfaceClasses.cpp +++ b/client/battle/BattleInterfaceClasses.cpp @@ -36,6 +36,7 @@ #include "../widgets/TextControls.h" #include "../widgets/MiscWidgets.h" #include "../windows/CMessage.h" +#include "../windows/CCreatureWindow.h" #include "../windows/CSpellWindow.h" #include "../render/CAnimation.h" #include "../render/IRenderHandler.h" @@ -1053,3 +1054,11 @@ void StackQueue::StackBox::show(Canvas & to) if(isBoundUnitHighlighted()) to.drawBorder(background->pos, Colors::CYAN, 2); } + +void StackQueue::StackBox::showPopupWindow(const Point & cursorPosition) +{ + auto stacks = owner->owner.getBattle()->battleGetAllStacks(); + for(const CStack * stack : stacks) + if(boundUnitID.has_value() && stack->unitId() == *boundUnitID) + GH.windows().createAndPushWindow(stack, true); +} diff --git a/client/battle/BattleInterfaceClasses.h b/client/battle/BattleInterfaceClasses.h index 0be01c484..e1e9c4263 100644 --- a/client/battle/BattleInterfaceClasses.h +++ b/client/battle/BattleInterfaceClasses.h @@ -230,6 +230,7 @@ class StackQueue : public CIntObject void show(Canvas & to) override; void showAll(Canvas & to) override; + void showPopupWindow(const Point & cursorPosition) override; bool isBoundUnitHighlighted() const; public: From 7a6722bc4589b2f09c00dbe9bef7c48b9fa15d88 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 7 Jan 2024 18:12:17 +0100 Subject: [PATCH 2/2] fix spell hover --- client/battle/BattleFieldController.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/battle/BattleFieldController.cpp b/client/battle/BattleFieldController.cpp index 378273bc8..d55c22360 100644 --- a/client/battle/BattleFieldController.cpp +++ b/client/battle/BattleFieldController.cpp @@ -588,8 +588,9 @@ void BattleFieldController::showHighlightedHexes(Canvas & canvas) std::set hoveredSpellHexes = getHighlightedHexesForSpellRange(); std::set hoveredMoveHexes = getHighlightedHexesForMovementTarget(); + BattleHex hoveredHex = getHoveredHex(); const CStack * hoveredStack = getHoveredStack(); - if(!hoveredStack) + if(!hoveredStack && hoveredHex == BattleHex::INVALID) return; // skip range limit calculations if unit hovered is not a shooter @@ -604,7 +605,7 @@ void BattleFieldController::showHighlightedHexes(Canvas & canvas) calculateRangeLimitAndHighlightImages(shootingRangeDistance, shootingRangeLimitImages, shootingRangeLimitHexes, shootingRangeLimitHexesHighligts); } - auto const & hoveredMouseHexes = getHoveredHex() != BattleHex::INVALID && owner.actionsController->currentActionSpellcasting(getHoveredHex()) ? hoveredSpellHexes : hoveredMoveHexes; + auto const & hoveredMouseHexes = hoveredHex != BattleHex::INVALID && owner.actionsController->currentActionSpellcasting(getHoveredHex()) ? hoveredSpellHexes : hoveredMoveHexes; for(int hex = 0; hex < GameConstants::BFIELD_SIZE; ++hex) {