Skip to content

[GEN] Backport left click deselect functionality with Alternate Mouse Setup from Zero Hour #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions Generals/Code/GameEngine/Include/GameClient/InGameUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ friend class Drawable; // for selection/deselection transactions
virtual void placeBuildAvailable( const ThingTemplate *build, Drawable *buildDrawable ); ///< built thing being placed
virtual const ThingTemplate *getPendingPlaceType( void ); ///< get item we're trying to place
virtual const ObjectID getPendingPlaceSourceObjectID( void ); ///< get producing object
// TheSuperHackers @feature @ShizCalev 04/04/2025 - Backports Zero Hour's alt-mouse mode's left click deselect functionality
virtual Bool getPreventLeftClickDeselectionInAlternateMouseModeForOneClick() const { return m_preventLeftClickDeselectionInAlternateMouseModeForOneClick; }
virtual void setPreventLeftClickDeselectionInAlternateMouseModeForOneClick( Bool set ) { m_preventLeftClickDeselectionInAlternateMouseModeForOneClick = set; }
virtual void setPlacementStart( const ICoord2D *start ); ///< placement anchor point (for choosing angles)
virtual void setPlacementEnd( const ICoord2D *end ); ///< set target placement point (for choosing angles)
virtual Bool isPlacementAnchored( void ); ///< is placement arrow anchor set
Expand Down Expand Up @@ -692,6 +695,7 @@ friend class Drawable; // for selection/deselection transactions
BuildProgress m_buildProgress[ MAX_BUILD_PROGRESS ]; ///< progress for building units
const ThingTemplate * m_pendingPlaceType; ///< type of built thing we're trying to place
ObjectID m_pendingPlaceSourceObjectID; ///< source object of the thing constructing the item
Bool m_preventLeftClickDeselectionInAlternateMouseModeForOneClick; // TheSuperHackers @feature @ShizCalev 04/04/2025 - Backports Zero Hour's alt-mouse mode's left click deselect functionality
Drawable ** m_placeIcon; ///< array for drawables to appear at the cursor when building in the world
Bool m_placeAnchorInProgress; ///< is place angle interface for placement active
ICoord2D m_placeAnchorStart; ///< place angle anchor start
Expand Down
6 changes: 6 additions & 0 deletions Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ InGameUI::InGameUI()
m_placeIcon[ i ] = NULL;
m_pendingPlaceType = NULL;
m_pendingPlaceSourceObjectID = INVALID_ID;
m_preventLeftClickDeselectionInAlternateMouseModeForOneClick = FALSE; // TheSuperHackers @feature @ShizCalev 04/04/2025 - Backports Zero Hour's alt-mouse mode's left click deselect functionality
m_placeAnchorStart.x = m_placeAnchorStart.y = 0;
m_placeAnchorEnd.x = m_placeAnchorEnd.y = 0;
m_placeAnchorInProgress = FALSE;
Expand Down Expand Up @@ -2878,6 +2879,11 @@ void InGameUI::placeBuildAvailable( const ThingTemplate *build, Drawable *buildD
// place something, it is overwritten
//
m_pendingPlaceType = build;
// TheSuperHackers @feature @ShizCalev 04/04/2025 - Backports Zero Hour's alt-mouse mode's left click deselect functionality

//Keep the prev pending place for left click deselection prevention in alternate mouse mode.
//We want to keep our dozer selected after initiating construction.
setPreventLeftClickDeselectionInAlternateMouseModeForOneClick( m_pendingPlaceSourceObjectID != INVALID_ID );
m_pendingPlaceSourceObjectID = INVALID_ID;

Object *sourceObject = NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ GameMessageDisposition GUICommandTranslator::translateGameMessage(const GameMess

// get out of GUI command mode if we completed the command one way or another
if( commandStatus == COMMAND_COMPLETE )
{
TheInGameUI->setPreventLeftClickDeselectionInAlternateMouseModeForOneClick( TRUE ); // TheSuperHackers @feature @ShizCalev 04/04/2025 - Backports Zero Hour's alt-mouse mode's left click deselect functionality
TheInGameUI->setGUICommand( NULL );
}
} // end if

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,31 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
buildRegion( &m_selectFeedbackAnchor, &msg->getArgument(0)->pixel, &selectionRegion );
dragMsg->appendPixelRegionArgument( selectionRegion );
}
// TheSuperHackers @feature @ShizCalev 04/04/2025 - Backports Zero Hour's alt-mouse mode's left click deselect functionality
else
{
// left click behavior (not right drag)

//Added support to cancel the GUI command without deselecting the unit(s) involved
//when you right click.
if( !TheInGameUI->getGUICommand() && !TheKeyboard->isShift() && !TheKeyboard->isCtrl() && !TheKeyboard->isAlt() )
{
//No GUI command mode, so deselect everyone if we're in alternate mouse mode.
if( TheGlobalData->m_useAlternateMouse && TheInGameUI->getPendingPlaceSourceObjectID() == INVALID_ID )
{
if( !TheInGameUI->getPreventLeftClickDeselectionInAlternateMouseModeForOneClick() )
{
deselectAll();
}
else
{
//Prevent deselection of unit if it just issued some type of UI order such as attack move, guard,
//initiating construction of a new structure.
TheInGameUI->setPreventLeftClickDeselectionInAlternateMouseModeForOneClick( FALSE );
}
}
}
}

break;
}
Expand Down