Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameclient): shift flips the camera's 45 degree steps while held

Olcay Seygan46f809a9508f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 796c0426b..bc83933f1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -228,6 +228,7 @@ found and fixed — EA's own, not port damage.**
- HUD Size grows the console from its middle, and on a narrow screen it stops at the size that still fits.
- The grid under a building you are placing is fainter and its lines thinner, and the red squares where nothing can stand are lighter, so the ground under them shows through. Untick grid placement on the Controls page and the lines go altogether.
- Hold Ctrl while placing a building and grid placement flips for as long as the key is down. With the box unticked the building snaps to the grid and the lines come up, so one flush row is a held key away; with it ticked you get a free hand for the odd building that has to sit between two squares. It works the same in Classic.
+- The camera works the same way with Shift. Turn it with the middle button or the rotate keys while Shift is down and the 45 degree camera steps flip: with the box unticked the view clicks round the eight headings, with it ticked it turns freely, and letting go of Shift mid-turn hands back whatever the box says. A quick square-on look no longer means a trip to the options.
- Your general's promotion screen opens in the middle of the screen, in the Classic interface as well, instead of hanging from the top edge. The battlefield dims behind it, and a click anywhere off the screen closes it without selecting or ordering anything underneath.
## Groups attack-move at their own speed
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index f1a9d020b..831c6b77e 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -625,7 +625,7 @@ GUI:SnapCamera45
END
TOOLTIP:SnapCamera45
-"Rotating the camera clicks to the eight 45 degree headings instead of stopping anywhere."
+"Rotating the camera clicks to the eight 45 degree headings instead of stopping anywhere. Hold Shift while turning to get the other behaviour for that turn."
END
GUI:GridBuild
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index a5ae520b0..379da425c 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15114,7 +15114,7 @@ GUI:SnapCamera45
END
TOOLTIP:SnapCamera45
-"Döndürülen kamera herhangi bir yerde durmak yerine sekiz 45 derecelik yönden birine oturur."
+"Döndürülen kamera herhangi bir yerde durmak yerine sekiz 45 derecelik yönden birine oturur. Döndürürken Shift'i basılı tutarsan o dönüşte diğer davranış geçerli olur."
END
GUI:GridBuild
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 6d6c71523..ad08f636b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -2718,7 +2718,8 @@ void InGameUI::update( void )
// interval, which is what the rotate keys do in Stronghold.
//
const UnsignedInt CAMERA_SNAP_REPEAT_MS = 250;
- if( TheGlobalData->m_snapCameraRotateTo45 )
+ // Shift flips it while held, the same as on the middle-button drag (LookAtXlat).
+ if( TheGlobalData->m_snapCameraRotateTo45 != TheKeyboard->isShift() )
{
if( (m_cameraRotatingLeft || m_cameraRotatingRight) && m_cameraRotatingLeft != m_cameraRotatingRight
&& cameraNowMs - m_cameraSnapRepeatMs >= CAMERA_SNAP_REPEAT_MS )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
index 6a6af50c0..3bcbd1546 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
@@ -602,7 +602,9 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
Real angle = FACTOR * (m_currentPos.x - m_anchor.x);
- if (TheGlobalData->m_snapCameraRotateTo45)
+ // Shift held turns the other way to the option for as long as it is held: free turning
+ // gets the eighths, snapped turning gets the free heading.
+ if (TheGlobalData->m_snapCameraRotateTo45 != TheKeyboard->isShift())
{
// discrete heading: the drag turns an angle we keep to ourselves and the camera
// jumps to the eighth it is nearest, as the mouse crosses each halfway point.
@@ -611,7 +613,8 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
}
else
{
- TheTacticalView->setAngle( TheTacticalView->getAngle() + angle );
+ m_freeRotateAngle = TheTacticalView->getAngle() + angle;
+ TheTacticalView->setAngle( m_freeRotateAngle );
}
m_anchor = msg->getArgument( 0 )->pixel;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
index 3a9a5af05..882e84547 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
@@ -459,7 +459,8 @@ static const char * findGameMessageNameByType(GameMessage::Type type)
* therefore not stop the slot from matching. Every other modifier still has to match exactly,
* and a slot the player deliberately bound to shift is compared as-is. The Force Attack hold is
* the same: shift on top of it queues the circle, so pressing shift must neither end the hold nor
- * stop it from starting. */
+ * stop it from starting. So are the camera's rotate keys: shift held over them flips the 45 degree
+ * steps (InGameUI::update), and a key let go with shift down still has to end the turn. */
//-------------------------------------------------------------------------------------------------
static Bool metaIgnoresShift(const MetaMapRec *map)
{
@@ -467,7 +468,9 @@ static Bool metaIgnoresShift(const MetaMapRec *map)
map->m_meta <= GameMessage::MSG_META_COMMAND_SLOT18;
const Bool forceAttackHold = map->m_meta == GameMessage::MSG_META_BEGIN_FORCEATTACK ||
map->m_meta == GameMessage::MSG_META_END_FORCEATTACK;
- return ( slot || forceAttackHold ) && (map->m_modState & SHIFT) == 0;
+ const Bool cameraRotate = map->m_meta >= GameMessage::MSG_META_BEGIN_CAMERA_ROTATE_LEFT &&
+ map->m_meta <= GameMessage::MSG_META_END_CAMERA_ROTATE_RIGHT;
+ return ( slot || forceAttackHold || cameraRotate ) && (map->m_modState & SHIFT) == 0;
}
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/Tests/test_camera_behavior.inc b/GeneralsMD/Code/Tests/test_camera_behavior.inc
index 83b3ded7f..2f354ceae 100644
--- a/GeneralsMD/Code/Tests/test_camera_behavior.inc
+++ b/GeneralsMD/Code/Tests/test_camera_behavior.inc
@@ -541,6 +541,23 @@ TEST(right_drag_pans_past_the_drag_tolerance_and_middle_drag_turns)
mouse(GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_UP, 350, 300);
CHECK(!f.camera.isMovingCamera());
+ // Shift flips the 45 degree steps for the drag: with them off, the held key lands it on an eighth,
+ // and with them on it turns freely. 0.1 off an eighth is no eighth, so each check can fail.
+ f.view.setAngle( 0.1f );
+ f.keyboard.modifiers(KEY_STATE_LSHIFT);
+ mouse(GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_DOWN, 300, 300);
+ mouse(GameMessage::MSG_RAW_MOUSE_POSITION, 370, 300);
+ CHECK_NEAR(f.view.getAngle(), PI / 4.0f, 0.0001f);
+ mouse(GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_UP, 370, 300);
+ f.global->m_snapCameraRotateTo45 = TRUE;
+ f.view.setAngle( 0.1f );
+ mouse(GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_DOWN, 300, 300);
+ mouse(GameMessage::MSG_RAW_MOUSE_POSITION, 310, 300);
+ CHECK_NEAR(f.view.getAngle(), 0.2f, 0.0001f);
+ mouse(GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_UP, 310, 300);
+ f.keyboard.modifiers(0);
+ f.global->m_snapCameraRotateTo45 = FALSE;
+
// Classic's right drag is the same retail scroll, started by the press itself as 1.04 started it
f.global->m_mouseStyle = MOUSE_STYLE_CLASSIC;
mouse(GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN, 300, 300);