Skip to content

Commit 6218501

Browse files
authored
[GEN] Backport left click deselect functionality with Alternate Mouse Setup from Zero Hour (#332)
1 parent 84aa95b commit 6218501

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

Generals/Code/GameEngine/Include/GameClient/InGameUI.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ friend class Drawable; // for selection/deselection transactions
416416
virtual void placeBuildAvailable( const ThingTemplate *build, Drawable *buildDrawable ); ///< built thing being placed
417417
virtual const ThingTemplate *getPendingPlaceType( void ); ///< get item we're trying to place
418418
virtual const ObjectID getPendingPlaceSourceObjectID( void ); ///< get producing object
419+
virtual Bool getPreventLeftClickDeselectionInAlternateMouseModeForOneClick() const { return m_preventLeftClickDeselectionInAlternateMouseModeForOneClick; }
420+
virtual void setPreventLeftClickDeselectionInAlternateMouseModeForOneClick( Bool set ) { m_preventLeftClickDeselectionInAlternateMouseModeForOneClick = set; }
419421
virtual void setPlacementStart( const ICoord2D *start ); ///< placement anchor point (for choosing angles)
420422
virtual void setPlacementEnd( const ICoord2D *end ); ///< set target placement point (for choosing angles)
421423
virtual Bool isPlacementAnchored( void ); ///< is placement arrow anchor set
@@ -692,6 +694,7 @@ friend class Drawable; // for selection/deselection transactions
692694
BuildProgress m_buildProgress[ MAX_BUILD_PROGRESS ]; ///< progress for building units
693695
const ThingTemplate * m_pendingPlaceType; ///< type of built thing we're trying to place
694696
ObjectID m_pendingPlaceSourceObjectID; ///< source object of the thing constructing the item
697+
Bool m_preventLeftClickDeselectionInAlternateMouseModeForOneClick;
695698
Drawable ** m_placeIcon; ///< array for drawables to appear at the cursor when building in the world
696699
Bool m_placeAnchorInProgress; ///< is place angle interface for placement active
697700
ICoord2D m_placeAnchorStart; ///< place angle anchor start

Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ InGameUI::InGameUI()
897897
m_placeIcon[ i ] = NULL;
898898
m_pendingPlaceType = NULL;
899899
m_pendingPlaceSourceObjectID = INVALID_ID;
900+
m_preventLeftClickDeselectionInAlternateMouseModeForOneClick = FALSE;
900901
m_placeAnchorStart.x = m_placeAnchorStart.y = 0;
901902
m_placeAnchorEnd.x = m_placeAnchorEnd.y = 0;
902903
m_placeAnchorInProgress = FALSE;
@@ -2869,6 +2870,10 @@ void InGameUI::placeBuildAvailable( const ThingTemplate *build, Drawable *buildD
28692870
// place something, it is overwritten
28702871
//
28712872
m_pendingPlaceType = build;
2873+
2874+
//Keep the prev pending place for left click deselection prevention in alternate mouse mode.
2875+
//We want to keep our dozer selected after initiating construction.
2876+
setPreventLeftClickDeselectionInAlternateMouseModeForOneClick( m_pendingPlaceSourceObjectID != INVALID_ID );
28722877
m_pendingPlaceSourceObjectID = INVALID_ID;
28732878

28742879
Object *sourceObject = NULL;

Generals/Code/GameEngine/Source/GameClient/MessageStream/GUICommandTranslator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,10 @@ GameMessageDisposition GUICommandTranslator::translateGameMessage(const GameMess
492492

493493
// get out of GUI command mode if we completed the command one way or another
494494
if( commandStatus == COMMAND_COMPLETE )
495+
{
496+
TheInGameUI->setPreventLeftClickDeselectionInAlternateMouseModeForOneClick( TRUE );
495497
TheInGameUI->setGUICommand( NULL );
498+
}
496499
} // end if
497500

498501
break;

Generals/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,30 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
870870
buildRegion( &m_selectFeedbackAnchor, &msg->getArgument(0)->pixel, &selectionRegion );
871871
dragMsg->appendPixelRegionArgument( selectionRegion );
872872
}
873+
else
874+
{
875+
// left click behavior (not right drag)
876+
877+
//Added support to cancel the GUI command without deselecting the unit(s) involved
878+
//when you right click.
879+
if( !TheInGameUI->getGUICommand() && !TheKeyboard->isShift() && !TheKeyboard->isCtrl() && !TheKeyboard->isAlt() )
880+
{
881+
//No GUI command mode, so deselect everyone if we're in alternate mouse mode.
882+
if( TheGlobalData->m_useAlternateMouse && TheInGameUI->getPendingPlaceSourceObjectID() == INVALID_ID )
883+
{
884+
if( !TheInGameUI->getPreventLeftClickDeselectionInAlternateMouseModeForOneClick() )
885+
{
886+
deselectAll();
887+
}
888+
else
889+
{
890+
//Prevent deselection of unit if it just issued some type of UI order such as attack move, guard,
891+
//initiating construction of a new structure.
892+
TheInGameUI->setPreventLeftClickDeselectionInAlternateMouseModeForOneClick( FALSE );
893+
}
894+
}
895+
}
896+
}
873897

874898
break;
875899
}

0 commit comments

Comments
 (0)