mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-21 21:17:49 +02:00
Merged CClickableHex class into BattleFieldController
This commit is contained in:
parent
c3b79c786b
commit
d3c85a19cb
@ -27,6 +27,7 @@
|
|||||||
#include "../gui/CGuiHandler.h"
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../gui/CursorHandler.h"
|
#include "../gui/CursorHandler.h"
|
||||||
#include "../adventureMap/CInGameConsole.h"
|
#include "../adventureMap/CInGameConsole.h"
|
||||||
|
#include "../windows/CCreatureWindow.h"
|
||||||
|
|
||||||
#include "../../CCallback.h"
|
#include "../../CCallback.h"
|
||||||
#include "../../lib/BattleFieldHandler.h"
|
#include "../../lib/BattleFieldHandler.h"
|
||||||
@ -76,20 +77,11 @@ BattleFieldController::BattleFieldController(BattleInterface & owner):
|
|||||||
|
|
||||||
backgroundWithHexes = std::make_unique<Canvas>(Point(background->width(), background->height()));
|
backgroundWithHexes = std::make_unique<Canvas>(Point(background->width(), background->height()));
|
||||||
|
|
||||||
for (int h = 0; h < GameConstants::BFIELD_SIZE; ++h)
|
|
||||||
{
|
|
||||||
auto hex = std::make_shared<ClickableHex>();
|
|
||||||
hex->myNumber = h;
|
|
||||||
hex->pos = hexPositionAbsolute(h);
|
|
||||||
hex->myInterface = &owner;
|
|
||||||
bfield.push_back(hex);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto accessibility = owner.curInt->cb->getAccesibility();
|
auto accessibility = owner.curInt->cb->getAccesibility();
|
||||||
for(int i = 0; i < accessibility.size(); i++)
|
for(int i = 0; i < accessibility.size(); i++)
|
||||||
stackCountOutsideHexes[i] = (accessibility[i] == EAccessibility::ACCESSIBLE);
|
stackCountOutsideHexes[i] = (accessibility[i] == EAccessibility::ACCESSIBLE);
|
||||||
|
|
||||||
addUsedEvents(MOVE);
|
addUsedEvents(LCLICK | RCLICK | MOVE);
|
||||||
LOCPLINT->cingconsole->pos = this->pos;
|
LOCPLINT->cingconsole->pos = this->pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,6 +104,29 @@ void BattleFieldController::mouseMoved(const SDL_MouseMotionEvent &event)
|
|||||||
owner.actionsController->onHexHovered(selectedHex);
|
owner.actionsController->onHexHovered(selectedHex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BattleFieldController::clickLeft(tribool down, bool previousState)
|
||||||
|
{
|
||||||
|
if(!down)
|
||||||
|
{
|
||||||
|
BattleHex selectedHex = getHoveredHex();
|
||||||
|
|
||||||
|
if (selectedHex != BattleHex::INVALID)
|
||||||
|
owner.actionsController->onHexClicked(selectedHex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BattleFieldController::clickRight(tribool down, bool previousState)
|
||||||
|
{
|
||||||
|
if(down)
|
||||||
|
{
|
||||||
|
BattleHex selectedHex = getHoveredHex();
|
||||||
|
|
||||||
|
auto selectedStack = owner.curInt->cb->battleGetStackByPos(selectedHex, true);
|
||||||
|
|
||||||
|
if (selectedStack != nullptr)
|
||||||
|
GH.pushIntT<CStackWindow>(selectedStack, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BattleFieldController::renderBattlefield(Canvas & canvas)
|
void BattleFieldController::renderBattlefield(Canvas & canvas)
|
||||||
{
|
{
|
||||||
@ -230,15 +245,15 @@ std::set<BattleHex> BattleFieldController::getHighlightedHexesSpellRange()
|
|||||||
if(!settings["battle"]["mouseShadow"].Bool())
|
if(!settings["battle"]["mouseShadow"].Bool())
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
const spells::Caster *caster = nullptr;
|
const spells::Caster *caster = nullptr;
|
||||||
const CSpell *spell = nullptr;
|
const CSpell *spell = nullptr;
|
||||||
|
|
||||||
spells::Mode mode = owner.actionsController->getCurrentCastMode();
|
spells::Mode mode = owner.actionsController->getCurrentCastMode();
|
||||||
spell = owner.actionsController->getCurrentSpell();
|
spell = owner.actionsController->getCurrentSpell();
|
||||||
caster = owner.actionsController->getCurrentSpellcaster();
|
caster = owner.actionsController->getCurrentSpellcaster();
|
||||||
|
|
||||||
if(caster && spell) //when casting spell
|
if(caster && spell) //when casting spell
|
||||||
{
|
{
|
||||||
// printing shaded hex(es)
|
// printing shaded hex(es)
|
||||||
spells::BattleCast event(owner.curInt->cb.get(), caster, mode, spell);
|
spells::BattleCast event(owner.curInt->cb.get(), caster, mode, spell);
|
||||||
auto shaded = spell->battleMechanics(&event)->rangeInHexes(hoveredHex);
|
auto shaded = spell->battleMechanics(&event)->rangeInHexes(hoveredHex);
|
||||||
@ -297,16 +312,16 @@ std::set<BattleHex> BattleFieldController::getHighlightedHexesMovementTarget()
|
|||||||
void BattleFieldController::showHighlightedHexes(Canvas & canvas)
|
void BattleFieldController::showHighlightedHexes(Canvas & canvas)
|
||||||
{
|
{
|
||||||
std::set<BattleHex> hoveredStack = getHighlightedHexesStackRange();
|
std::set<BattleHex> hoveredStack = getHighlightedHexesStackRange();
|
||||||
std::set<BattleHex> hoveredSpell = getHighlightedHexesSpellRange();
|
std::set<BattleHex> hoveredSpell = getHighlightedHexesSpellRange();
|
||||||
std::set<BattleHex> hoveredMove = getHighlightedHexesMovementTarget();
|
std::set<BattleHex> hoveredMove = getHighlightedHexesMovementTarget();
|
||||||
|
|
||||||
if (getHoveredHex() == BattleHex::INVALID)
|
if (getHoveredHex() == BattleHex::INVALID)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto const & hoveredMouse = owner.actionsController->currentActionSpellcasting(getHoveredHex()) ? hoveredSpell : hoveredMove;
|
auto const & hoveredMouse = owner.actionsController->currentActionSpellcasting(getHoveredHex()) ? hoveredSpell : hoveredMove;
|
||||||
|
|
||||||
for(int b=0; b<GameConstants::BFIELD_SIZE; ++b)
|
for(int b=0; b<GameConstants::BFIELD_SIZE; ++b)
|
||||||
{
|
{
|
||||||
bool stack = hoveredStack.count(b);
|
bool stack = hoveredStack.count(b);
|
||||||
bool mouse = hoveredMouse.count(b);
|
bool mouse = hoveredMouse.count(b);
|
||||||
|
|
||||||
@ -348,9 +363,18 @@ bool BattleFieldController::isPixelInHex(Point const & position)
|
|||||||
|
|
||||||
BattleHex BattleFieldController::getHoveredHex()
|
BattleHex BattleFieldController::getHoveredHex()
|
||||||
{
|
{
|
||||||
for ( auto const & hex : bfield)
|
Point hoverPos = GH.getCursorPosition();
|
||||||
if (hex->hovered && hex->strictHovered)
|
|
||||||
return hex->myNumber;
|
for (int h = 0; h < GameConstants::BFIELD_SIZE; ++h)
|
||||||
|
{
|
||||||
|
Rect hexPosition = hexPositionAbsolute(h);
|
||||||
|
|
||||||
|
if (!hexPosition.isInside(hoverPos))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (isPixelInHex(hoverPos - hexPosition.topLeft()))
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
return BattleHex::INVALID;
|
return BattleHex::INVALID;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ class Point;
|
|||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|
||||||
class ClickableHex;
|
|
||||||
class BattleHero;
|
class BattleHero;
|
||||||
class Canvas;
|
class Canvas;
|
||||||
class IImage;
|
class IImage;
|
||||||
@ -50,8 +49,6 @@ class BattleFieldController : public CIntObject
|
|||||||
/// hexes that when in front of a unit cause it's amount box to move back
|
/// hexes that when in front of a unit cause it's amount box to move back
|
||||||
std::array<bool, GameConstants::BFIELD_SIZE> stackCountOutsideHexes;
|
std::array<bool, GameConstants::BFIELD_SIZE> stackCountOutsideHexes;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<ClickableHex>> bfield;
|
|
||||||
|
|
||||||
void showHighlightedHex(Canvas & to, BattleHex hex, bool darkBorder);
|
void showHighlightedHex(Canvas & to, BattleHex hex, bool darkBorder);
|
||||||
|
|
||||||
std::set<BattleHex> getHighlightedHexesStackRange();
|
std::set<BattleHex> getHighlightedHexesStackRange();
|
||||||
@ -66,9 +63,11 @@ class BattleFieldController : public CIntObject
|
|||||||
BattleHex::EDir selectAttackDirection(BattleHex myNumber, const Point & point);
|
BattleHex::EDir selectAttackDirection(BattleHex myNumber, const Point & point);
|
||||||
|
|
||||||
void mouseMoved(const SDL_MouseMotionEvent &event) override;
|
void mouseMoved(const SDL_MouseMotionEvent &event) override;
|
||||||
|
void clickLeft(tribool down, bool previousState) override;
|
||||||
|
void clickRight(tribool down, bool previousState) override;
|
||||||
|
|
||||||
void showAll(SDL_Surface * to) override;
|
void showAll(SDL_Surface * to) override;
|
||||||
void show(SDL_Surface * to) override;
|
void show(SDL_Surface * to) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BattleFieldController(BattleInterface & owner);
|
BattleFieldController(BattleInterface & owner);
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ class Canvas;
|
|||||||
class BattleResultWindow;
|
class BattleResultWindow;
|
||||||
class StackQueue;
|
class StackQueue;
|
||||||
class CPlayerInterface;
|
class CPlayerInterface;
|
||||||
class ClickableHex;
|
|
||||||
class CAnimation;
|
class CAnimation;
|
||||||
struct BattleEffect;
|
struct BattleEffect;
|
||||||
class IImage;
|
class IImage;
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
#include "../widgets/Images.h"
|
#include "../widgets/Images.h"
|
||||||
#include "../widgets/TextControls.h"
|
#include "../widgets/TextControls.h"
|
||||||
#include "../windows/CMessage.h"
|
#include "../windows/CMessage.h"
|
||||||
#include "../windows/CCreatureWindow.h"
|
|
||||||
#include "../windows/CSpellWindow.h"
|
#include "../windows/CSpellWindow.h"
|
||||||
#include "../render/CAnimation.h"
|
#include "../render/CAnimation.h"
|
||||||
#include "../adventureMap/CInGameConsole.h"
|
#include "../adventureMap/CInGameConsole.h"
|
||||||
@ -681,46 +680,6 @@ void BattleResultWindow::bExitf()
|
|||||||
CCS->videoh->close();
|
CCS->videoh->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClickableHex::hover(bool on)
|
|
||||||
{
|
|
||||||
hovered = on;
|
|
||||||
//Hoverable::hover(on);
|
|
||||||
}
|
|
||||||
|
|
||||||
ClickableHex::ClickableHex()
|
|
||||||
: myNumber(-1)
|
|
||||||
, strictHovered(false)
|
|
||||||
, myInterface(nullptr)
|
|
||||||
{
|
|
||||||
addUsedEvents(LCLICK | RCLICK | HOVER | MOVE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClickableHex::mouseMoved(const SDL_MouseMotionEvent &sEvent)
|
|
||||||
{
|
|
||||||
strictHovered = myInterface->fieldController->isPixelInHex(Point(sEvent.x-pos.x, sEvent.y-pos.y));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClickableHex::clickLeft(tribool down, bool previousState)
|
|
||||||
{
|
|
||||||
if(!down && hovered && strictHovered) //we've been really clicked!
|
|
||||||
{
|
|
||||||
myInterface->actionsController->onHexClicked(myNumber);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClickableHex::clickRight(tribool down, bool previousState)
|
|
||||||
{
|
|
||||||
const CStack * myst = myInterface->getCurrentPlayerInterface()->cb->battleGetStackByPos(myNumber); //stack info
|
|
||||||
if(hovered && strictHovered && myst!=nullptr)
|
|
||||||
{
|
|
||||||
if(!myst->alive()) return;
|
|
||||||
if(down)
|
|
||||||
{
|
|
||||||
GH.pushIntT<CStackWindow>(myst, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StackQueue::StackQueue(bool Embedded, BattleInterface & owner)
|
StackQueue::StackQueue(bool Embedded, BattleInterface & owner)
|
||||||
: embedded(Embedded),
|
: embedded(Embedded),
|
||||||
owner(owner)
|
owner(owner)
|
||||||
|
@ -172,22 +172,6 @@ public:
|
|||||||
void show(SDL_Surface * to = 0) override;
|
void show(SDL_Surface * to = 0) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Class which stands for a single hex field on a battlefield
|
|
||||||
class ClickableHex : public CIntObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ui32 myNumber; //number of hex in commonly used format
|
|
||||||
bool strictHovered; //for determining if hex is hovered by mouse (this is different problem than hex's graphic hovering)
|
|
||||||
BattleInterface * myInterface; //interface that owns me
|
|
||||||
|
|
||||||
//for user interactions
|
|
||||||
void hover (bool on) override;
|
|
||||||
void mouseMoved (const SDL_MouseMotionEvent &sEvent) override;
|
|
||||||
void clickLeft(tribool down, bool previousState) override;
|
|
||||||
void clickRight(tribool down, bool previousState) override;
|
|
||||||
ClickableHex();
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Shows the stack queue
|
/// Shows the stack queue
|
||||||
class StackQueue : public CIntObject
|
class StackQueue : public CIntObject
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user