Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Core/GameEngine/Include/GameClient/CommandXlat.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ class CommandTranslator : public GameMessageTranslator
Bool m_teamExists; ///< is there a currently selected "team"?

// these are for determining if a drag occurred or it was just a sloppy click
ICoord2D m_mouseRightDragAnchor; // the location of a possible mouse drag start
ICoord2D m_mouseRightDragLift; // the location of a possible mouse drag end
UnsignedInt m_mouseRightDown; // when the mouse down happened
UnsignedInt m_mouseRightUp; // when the mouse up happened
ICoord2D m_rightMouseDownAnchor; // the location of a possible mouse drag start
ICoord2D m_rightMouseUpAnchor; // the location of a possible mouse drag end
UnsignedInt m_rightMouseDownTimeMs; // when the mouse down happened
UnsignedInt m_rightMouseUpTimeMs; // when the mouse up happened
Coord3D m_rightMouseDownCameraPos;
Coord3D m_rightMouseUpCameraPos;

GameMessage::Type createMoveToLocationMessage( Drawable *draw, const Coord3D *dest, CommandEvaluateType commandType );
GameMessage::Type createAttackMessage( Drawable *draw, Drawable *other, CommandEvaluateType commandType );
Expand Down
9 changes: 8 additions & 1 deletion Core/GameEngine/Include/GameClient/Mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,14 @@ class Mouse : public SubsystemInterface
void onGameModeChanged(GameMode prev, GameMode next);
void onGamePaused(Bool paused);

Bool isClick(const ICoord2D *anchor, const ICoord2D *dest, UnsignedInt previousMouseClick, UnsignedInt currentMouseClick);
Bool isClick(
const ICoord2D &mouseAnchor0,
const ICoord2D &mouseAnchor1,
const Coord3D &cameraPos0,
const Coord3D &cameraPos1,
UnsignedInt mouseClickTimeMs0,
UnsignedInt mouseClickTimeMs1
);

AsciiString m_tooltipFontName; ///< tooltip font
Int m_tooltipFontSize; ///< tooltip font
Expand Down
11 changes: 5 additions & 6 deletions Core/GameEngine/Include/GameClient/SelectionXlat.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@ class SelectionTranslator : public GameMessageTranslator

Bool m_leftMouseButtonIsDown;
Bool m_dragSelecting;
Bool m_displayedMaxWarning; // did we already display a warning about selecting too many units?
UnsignedInt m_lastGroupSelTime;
Int m_lastGroupSelGroup;
ICoord2D m_selectFeedbackAnchor; // Note: Used for drawing feedback only.
ICoord2D m_deselectFeedbackAnchor; // Note: Used for drawing feedback only.
Bool m_displayedMaxWarning; // did we already display a warning about selecting too many units?
UnsignedInt m_lastClick; ///< timer used for checking double click for type selection
ICoord2D m_leftMouseDownAnchor; // Note: Used for drawing feedback only.
ICoord2D m_rightMouseDownAnchor; // Note: Used for drawing feedback only.
UnsignedInt m_rightMouseDownTimeMs; ///< timer used for checking double click for type selection
Coord3D m_rightMouseDownCameraPos;

SelectCountMap m_selectCountMap;

Coord3D m_deselectDownCameraPosition;

Bool selectFriends( Drawable *draw, GameMessage *createTeamMsg, Bool dragSelecting );
Bool killThemKillThemAll( Drawable *draw, GameMessage *killThemAllMsg );

Expand Down
21 changes: 13 additions & 8 deletions Core/GameEngine/Source/GameClient/Input/Mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,18 +384,23 @@ void Mouse::checkForDrag()
//-------------------------------------------------------------------------------------------------
/** Check for mouse click, using allowed drag forgiveness */
//-------------------------------------------------------------------------------------------------
Bool Mouse::isClick(const ICoord2D *anchor, const ICoord2D *dest, UnsignedInt previousMouseClick, UnsignedInt currentMouseClick)
Bool Mouse::isClick(
const ICoord2D &mouseAnchor0,
const ICoord2D &mouseAnchor1,
const Coord3D &cameraPos0,
const Coord3D &cameraPos1,
UnsignedInt mouseClickTimeMs0,
UnsignedInt mouseClickTimeMs1)
{
ICoord2D delta;
delta.x = anchor->x - dest->x;
delta.y = anchor->y - dest->y;

ICoord2D mouseAnchorDelta = mouseAnchor1 - mouseAnchor0;
Coord3D cameraPosDelta = cameraPos1 - cameraPos0;
UnsignedInt timeMsDelta = mouseClickTimeMs1 - mouseClickTimeMs0;

// if the mouse hasn't moved further than the tolerance distance
// or the click took less than the tolerance duration
if ( abs(delta.x) > m_dragTolerance
|| abs(delta.y) > m_dragTolerance
|| currentMouseClick - previousMouseClick > m_dragToleranceMS)
if ( timeMsDelta > m_dragToleranceMS
|| mouseAnchorDelta.lengthSqr() > sqr(m_dragTolerance)
|| cameraPosDelta.lengthSqr() > sqr(m_dragTolerance3D) )
{
return FALSE;
}
Expand Down
35 changes: 22 additions & 13 deletions Core/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1445,13 +1445,13 @@ GameMessage::Type CommandTranslator::createEnterMessage( Drawable *enter,
CommandTranslator::CommandTranslator() :
m_objective(0),
m_teamExists(false),
m_mouseRightDown(0),
m_mouseRightUp(0)
m_rightMouseDownTimeMs(0),
m_rightMouseUpTimeMs(0)
{
m_mouseRightDragAnchor.x = 0;
m_mouseRightDragAnchor.y = 0;
m_mouseRightDragLift.x = 0;
m_mouseRightDragLift.y = 0;
m_rightMouseDownAnchor.zero();
m_rightMouseUpAnchor.zero();
m_rightMouseDownCameraPos.zero();
m_rightMouseUpCameraPos.zero();
}

//====================================================================================
Expand Down Expand Up @@ -3864,11 +3864,13 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
case GameMessage::MSG_RAW_MOUSE_RIGHT_DOUBLE_CLICK:
case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN:
{
// There are two ways in which we can ignore this as a deselect:
// There are three ways in which we can ignore this as a deselect:
// 1) 2-D position on screen
// 2) Time has exceeded the time which we allow for this to be a click.
m_mouseRightDragAnchor = msg->getArgument( 0 )->pixel;
m_mouseRightDown = (UnsignedInt) msg->getArgument( 2 )->integer;
// 3) 3-D camera position has changed
m_rightMouseDownAnchor = msg->getArgument( 0 )->pixel;
m_rightMouseDownTimeMs = (UnsignedInt) msg->getArgument( 2 )->integer;
m_rightMouseDownCameraPos = TheTacticalView->getPosition();

break;
}
Expand All @@ -3877,14 +3879,18 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP:
{
// register this event for determining if the click was fast or short enough not to be a drag
m_mouseRightDragLift = msg->getArgument( 0 )->pixel;
m_mouseRightUp = (UnsignedInt) msg->getArgument( 2 )->integer;
m_rightMouseUpAnchor = msg->getArgument( 0 )->pixel;
m_rightMouseUpTimeMs = (UnsignedInt) msg->getArgument( 2 )->integer;
m_rightMouseUpCameraPos = TheTacticalView->getPosition();

//Kris: July 7, 2003. Added this code to deselect build placement mode when right clicked. This fixes
//a bug where you couldn't cancel the sneak attack mode via right click. This only happened when you
//didn't have anything selected which is possible via the shortcut bar. Normally, it would get deselected
//via the deselect drawable code.
if( TheMouse->isClick(&m_mouseRightDragAnchor, &m_mouseRightDragLift, m_mouseRightDown, m_mouseRightUp) )
if( TheMouse->isClick(
m_rightMouseDownAnchor, m_rightMouseUpAnchor,
m_rightMouseDownCameraPos, m_rightMouseUpCameraPos,
m_rightMouseDownTimeMs, m_rightMouseUpTimeMs) )
{
TheInGameUI->placeBuildAvailable( nullptr, nullptr );
}
Expand Down Expand Up @@ -3916,7 +3922,10 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
{
// right click is only actioned here if we're in alternate mouse mode
if (TheGlobalData->m_useAlternateMouse
&& TheMouse->isClick(&m_mouseRightDragAnchor, &m_mouseRightDragLift, m_mouseRightDown, m_mouseRightUp))
&& TheMouse->isClick(
m_rightMouseDownAnchor, m_rightMouseUpAnchor,
m_rightMouseDownCameraPos, m_rightMouseUpCameraPos,
m_rightMouseDownTimeMs, m_rightMouseUpTimeMs))
{
Bool isPoint = (msg->getArgument(0)->pixelRegion.height() == 0 && msg->getArgument(0)->pixelRegion.width() == 0);

Expand Down
36 changes: 16 additions & 20 deletions Core/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,10 @@ SelectionTranslator::SelectionTranslator()
m_dragSelecting = FALSE;
m_lastGroupSelTime = 0;
m_lastGroupSelGroup = -1;
m_selectFeedbackAnchor.x = 0;
m_selectFeedbackAnchor.y = 0;
m_deselectFeedbackAnchor.x = 0;
m_deselectFeedbackAnchor.y = 0;
m_lastClick = 0;
m_deselectDownCameraPosition.zero();
m_leftMouseDownAnchor.zero();
m_rightMouseDownAnchor.zero();
m_rightMouseDownTimeMs = 0;
m_rightMouseDownCameraPos.zero();
m_displayedMaxWarning = FALSE;
m_selectCountMap.clear();

Expand Down Expand Up @@ -403,8 +401,8 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
{
ICoord2D delta;

delta.x = abs(pixel.x - m_selectFeedbackAnchor.x);
delta.y = abs(pixel.y - m_selectFeedbackAnchor.y);
delta.x = abs(pixel.x - m_leftMouseDownAnchor.x);
delta.y = abs(pixel.y - m_leftMouseDownAnchor.y);

// if mouse has moved while left button is down, begin drag selection
if (delta.x > TheMouse->m_dragTolerance || delta.y > TheMouse->m_dragTolerance)
Expand All @@ -425,7 +423,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa

// build rectangular region defined by the drag selection
IRegion2D pixelRegion;
buildRegion( &m_selectFeedbackAnchor, &pixel, &pixelRegion );
buildRegion( &m_leftMouseDownAnchor, &pixel, &pixelRegion );
hintMsg->appendPixelRegionArgument( pixelRegion );
}
}
Expand Down Expand Up @@ -883,7 +881,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
{
// cannot actually start area selection yet - have to wait for cursor to move a bit
m_leftMouseButtonIsDown = true;
m_selectFeedbackAnchor = msg->getArgument( 0 )->pixel;
m_leftMouseDownAnchor = msg->getArgument( 0 )->pixel;
break;
}

Expand All @@ -907,7 +905,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
GameMessage *dragMsg = TheMessageStream->appendMessage( GameMessage::MSG_END_AREA_SELECTION_HINT );

IRegion2D selectionRegion;
buildRegion( &m_selectFeedbackAnchor, &msg->getArgument(0)->pixel, &selectionRegion );
buildRegion( &m_leftMouseDownAnchor, &msg->getArgument(0)->pixel, &selectionRegion );
dragMsg->appendPixelRegionArgument( selectionRegion );
}
else
Expand Down Expand Up @@ -946,24 +944,22 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
// 1) 2-D position on screen
// 2) Time has exceeded the time which we allow for this to be a click.
// 3) 3-D camera position has changed
m_deselectFeedbackAnchor = msg->getArgument( 0 )->pixel;
m_lastClick = (UnsignedInt) msg->getArgument( 2 )->integer;
m_deselectDownCameraPosition = TheTacticalView->getPosition();
m_rightMouseDownAnchor = msg->getArgument( 0 )->pixel;
m_rightMouseDownTimeMs = (UnsignedInt) msg->getArgument( 2 )->integer;
m_rightMouseDownCameraPos = TheTacticalView->getPosition();

break;
}

//-----------------------------------------------------------------------------
case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP:
{
Coord3D cameraPos = TheTacticalView->getPosition();
cameraPos.sub(&m_deselectDownCameraPosition);

ICoord2D pixel = msg->getArgument( 0 )->pixel;
UnsignedInt currentTime = (UnsignedInt) msg->getArgument( 2 )->integer;
const ICoord2D anchor = msg->getArgument( 0 )->pixel;
const UnsignedInt timeMs = (UnsignedInt) msg->getArgument( 2 )->integer;
const Coord3D cameraPos = TheTacticalView->getPosition();

// right click behavior (not right drag)
if (TheMouse->isClick(&m_deselectFeedbackAnchor, &pixel, m_lastClick, currentTime))
if (TheMouse->isClick(m_rightMouseDownAnchor, anchor, m_rightMouseDownCameraPos, cameraPos, m_rightMouseDownTimeMs, timeMs))
{
//Added support to cancel the GUI command without deselecting the unit(s) involved
//when you right click.
Expand Down
Loading
Loading