1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Minor improvements to swipe in battle

This commit is contained in:
Ivan Savenko
2023-05-31 13:08:12 +03:00
parent b20109c830
commit 84934d931a
4 changed files with 18 additions and 31 deletions

View File

@@ -96,31 +96,22 @@ void BattleFieldController::panning(bool on, const Point & initialPosition, cons
void BattleFieldController::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) void BattleFieldController::gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance)
{ {
if (pos.isInside(currentPosition)) hoveredHex = getHexAtPosition(initialPosition);
{ currentAttackOriginPoint = currentPosition;
hoveredHex = getHexAtPosition(initialPosition);
currentAttackDirection = selectAttackDirection(getHoveredHex(), currentPosition);
if (pos.isInside(initialPosition))
owner.actionsController->onHexHovered(getHoveredHex()); owner.actionsController->onHexHovered(getHoveredHex());
}
else
{
hoveredHex = BattleHex::INVALID;
}
} }
void BattleFieldController::mouseMoved(const Point & cursorPosition) void BattleFieldController::mouseMoved(const Point & cursorPosition)
{ {
hoveredHex = getHexAtPosition(cursorPosition); hoveredHex = getHexAtPosition(cursorPosition);
currentAttackDirection = selectAttackDirection(getHoveredHex(), cursorPosition); currentAttackOriginPoint = cursorPosition;
if (!pos.isInside(cursorPosition)) if (pos.isInside(cursorPosition))
{ owner.actionsController->onHexHovered(getHoveredHex());
else
owner.actionsController->onHoverEnded(); owner.actionsController->onHoverEnded();
return;
}
owner.actionsController->onHexHovered(getHoveredHex());
} }
void BattleFieldController::clickLeft(tribool down, bool previousState) void BattleFieldController::clickLeft(tribool down, bool previousState)
@@ -161,7 +152,7 @@ void BattleFieldController::renderBattlefield(Canvas & canvas)
void BattleFieldController::showBackground(Canvas & canvas) void BattleFieldController::showBackground(Canvas & canvas)
{ {
if (owner.stacksController->getActiveStack() != nullptr ) //&& creAnims[stacksController->getActiveStack()->unitId()]->isIdle() //show everything with range if (owner.stacksController->getActiveStack() != nullptr )
showBackgroundImageWithHexes(canvas); showBackgroundImageWithHexes(canvas);
else else
showBackgroundImage(canvas); showBackgroundImage(canvas);
@@ -193,7 +184,7 @@ void BattleFieldController::showBackgroundImage(Canvas & canvas)
void BattleFieldController::showBackgroundImageWithHexes(Canvas & canvas) void BattleFieldController::showBackgroundImageWithHexes(Canvas & canvas)
{ {
canvas.draw(*backgroundWithHexes.get(), Point(0, 0)); canvas.draw(*backgroundWithHexes, Point(0, 0));
} }
void BattleFieldController::redrawBackgroundWithHexes() void BattleFieldController::redrawBackgroundWithHexes()
@@ -457,7 +448,7 @@ void BattleFieldController::setBattleCursor(BattleHex myNumber)
Cursor::Combat::HIT_NORTH, Cursor::Combat::HIT_NORTH,
}; };
auto direction = static_cast<size_t>(currentAttackDirection); auto direction = static_cast<size_t>(selectAttackDirection(getHoveredHex(), currentAttackOriginPoint));
assert(direction != -1); assert(direction != -1);
if (direction != -1) if (direction != -1)
@@ -540,7 +531,7 @@ BattleHex::EDir BattleFieldController::selectAttackDirection(BattleHex myNumber,
BattleHex BattleFieldController::fromWhichHexAttack(BattleHex attackTarget) BattleHex BattleFieldController::fromWhichHexAttack(BattleHex attackTarget)
{ {
BattleHex::EDir direction = currentAttackDirection; BattleHex::EDir direction = selectAttackDirection(getHoveredHex(), currentAttackOriginPoint);
const CStack * attacker = owner.stacksController->getActiveStack(); const CStack * attacker = owner.stacksController->getActiveStack();

View File

@@ -10,14 +10,12 @@
#pragma once #pragma once
#include "../../lib/battle/BattleHex.h" #include "../../lib/battle/BattleHex.h"
#include "../../lib/Point.h"
#include "../gui/CIntObject.h" #include "../gui/CIntObject.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class CStack; class CStack;
class Rect; class Rect;
class Point;
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END
class BattleHero; class BattleHero;
@@ -40,7 +38,7 @@ class BattleFieldController : public CIntObject
std::unique_ptr<Canvas> backgroundWithHexes; std::unique_ptr<Canvas> backgroundWithHexes;
/// direction which will be used to perform attack with current cursor position /// direction which will be used to perform attack with current cursor position
BattleHex::EDir currentAttackDirection; Point currentAttackOriginPoint;
/// hex currently under mouse hover /// hex currently under mouse hover
BattleHex hoveredHex; BattleHex hoveredHex;

View File

@@ -24,10 +24,10 @@ void InputSourceMouse::handleEventMouseMotion(const SDL_MouseMotionEvent & motio
Point newPosition(motion.x, motion.y); Point newPosition(motion.x, motion.y);
Point distance(-motion.xrel, -motion.yrel); Point distance(-motion.xrel, -motion.yrel);
GH.input().setCursorPosition(newPosition);
if (mouseButtonsMask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) if (mouseButtonsMask & SDL_BUTTON(SDL_BUTTON_MIDDLE))
GH.events().dispatchGesturePanning(middleClickPosition, newPosition, distance); GH.events().dispatchGesturePanning(middleClickPosition, newPosition, distance);
else
GH.input().setCursorPosition(newPosition);
mouseButtonsMask = motion.state; mouseButtonsMask = motion.state;
} }

View File

@@ -72,17 +72,15 @@ enum class TouchState
struct TouchInputParameters struct TouchInputParameters
{ {
/// Speed factor of mouse pointer when relative mode is used
double relativeModeSpeedFactor = 1.0; double relativeModeSpeedFactor = 1.0;
/// tap for period longer than specified here will be qualified as "long tap", triggering corresponding gesture /// tap for period longer than specified here will be qualified as "long tap", triggering corresponding gesture
uint32_t longPressTimeMilliseconds = 500; uint32_t longPressTimeMilliseconds = 750;
/// moving finger for distance larger than specified will be qualified as panning gesture instead of long press /// moving finger for distance larger than specified will be qualified as panning gesture instead of long press
uint32_t panningSensitivityThreshold = 16; uint32_t panningSensitivityThreshold = 10;
bool useHoldGesture = true;
bool usePanGesture = true;
bool usePinchGesture = true;
bool useRelativeMode = false; bool useRelativeMode = false;
}; };