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.

fix(gameclient): classic wide bar clicks through, powers stay square

Olcay Seygan4c2f04786310
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc4126cd4..01f3c069a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1091,6 +1091,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- Classic Graphics, on the Graphics page, puts the game back the way it looked in 2003 in one click: its own textures and ground in place of the upscaled ones, the old hard shadows, the round dark patch under every tree where Reforged lays the tree's own outline on the ground, and no glow or sharpening over the picture. Leave it off and you have Reforged. The rest of the options stay yours either way, and the box takes effect the next time the game starts.
- Interface, in the launcher, picks between Classic and Reforged. Classic is the command bar, mouse and hotkeys of Zero Hour 1.04 that your hands still remember; Reforged is the console in the middle, right-click orders and the key grid this version built. Every player starts on Classic, and a game started without the launcher is Classic too. The choice is yours alone: two players on different styles still play the same match and the same replay. It takes effect the next time the game starts. Classic's screen is EA's again: the one-piece command bar in each side's own painting, the radar with its flashing under-attack lamp, the beacon button, six lines of messages in the top left that fade as they did, superweapon countdowns written out by name, the old chat line and quit menu, lettering at the old sizes, and Tab opening diplomacy. On a 16:9 or 21:9 screen every menu outside a match sits in a 4:3 frame in the middle at its drawn shape, backdrop and border included, with black down both sides the way a 4:3 game looks on a wide monitor; in a match the options and save screens keep that 4:3 frame over the battlefield. The command bar runs edge to edge up to 16:9, as it always did. Past that, on 21:9 or 32:9, the match's own furniture keeps the 16:9 layout in the middle of the screen: the bar, your general's powers beside it, the build tooltip over it, the promotion screen, the superweapon countdowns, the messages, the chat line, the quit menu and diplomacy sit where a 16:9 screen has them, and the battlefield runs on past both ends, 320 pixels either side at 2560x1080. On 16:10 and anything wider the bar is one painted for 16:9, so it is not pulled out of shape the way EA's 4:3 one was: the radar and your selection sit at its two ends, the build grid has a longer field, the money box is in the middle and the power bar is nearly twice as long. A 4:3 or 5:4 screen keeps EA's bar as it was. The wide bar is the work of moddb_dev, from the "C&C Generals HD User Interface" mod on ModDB, itself built on pWn3d_1337's Operation Firestorm interface, and it is here with its author's permission. The mouse and keys are 1.04's as well. The left button selects and gives the order, so an enemy under it is an attack and a bunker under your infantry is a way in; the right button drops your selection or takes back a half-given order, and a right drag scrolls the map. Ctrl held is force fire. Alt held lays waypoints, and the white path joining them is drawn again. A guard order holds the range it always held, Shift and a number adds that group to what you have selected, and a build button is one unit a click. The keys are your language's own key map from the game's files, with nothing of Reforged's grid laid over it, and a build button's key is the letter 1.04 gave it, taken from the English name in every language, so a Turkish or German player presses the same key an English one does. The letter sits in the button's corner on the dark badge Reforged puts its grid keys on, in the middle of a square plate the same size for every letter, larger than Reforged's and in gold while the button can be pressed; the tooltip's name is plain white with no letter picked out. A structure is selected on its own, as it always was. The radar shows no money piles or tech buildings, and the clock plate, the frame counter and the experience bar under the portrait stay off the screen. So does the peace time plate, though a host's truce still holds. The money readout is the money alone, with no income figure beside it. Health bars and garrison squares look and behave as they do in Reforged, and the Health Bars and empty garrison squares settings are back on Classic's options page. The build buttons are the pictures alone, without the seconds, price and power figures. Those seconds were measured against the wall clock, so on a match running just under full speed a 120 second build read 125. An upgrade bought for a group of buildings goes to the one whose buttons you see. In a network game a Classic player's camera is not sent to observers, as it never was in 1.04. The camera zooms ten units a notch, on the middle of the screen unless you tick Zoom to Cursor, as near and as far as Reforged's camera goes, turns without snapping unless you tick Snap Camera Rotation, and scrolls from the last three pixels of a full screen and not at all in a window, whatever the options say. It runs past the edge of the map as far as Reforged's camera does, 200 units unless `CameraBoundaryMargin` says otherwise, so a base in a corner comes to the middle of the screen in either interface. A move order puts 1.04's animated ring on the ground where it lands, and no marker or line stays behind it. None of it reaches the battle itself: Classic sends the game only the orders 1.04 sent, so a Classic player and a Reforged one share a match, and a replay plays back the same in either.
- Classic shows what a factory is building again. Select one with anything queued and its queue takes the portrait's place, the unit in production wearing its build clock, and a click on any entry cancels it; the portrait comes back when the queue runs dry. Until now a Classic factory could queue a hundred units with nothing on screen to count them by. The queue stops at nine, the number of slots that show it, and the build buttons grey out at nine as they did in 1.04. Your general's powers climb the right edge of the screen from the top of the bar, one over the other, as they did in 1.04, and the empty strip above them no longer swallows clicks on the battlefield. They carry how many are ready, with no key letter and no recharge seconds, and the promotion screen carries no number keys either, since Classic's number keys pick teams. Every button on that screen takes its click again: the right half used to sit under the powers bar's empty frame and the bottom row under the command bar's top edge, and a click there went nowhere.
+- Classic's wide command bar lets the battlefield have the ground it shows. Over the build grid's two shoulders the painting starts lower than the bar's old click area did, and a strip of battlefield about 80 pixels deep at 1920x1080 could be seen but not clicked; a unit standing there could not be selected or sent anywhere. A click now goes wherever the painting is see-through. Your general's powers beside that bar are square again too: they were drawn a third wider than tall, stretched to fit EA's 4:3 bar while the wide bar next to them kept its shape. The promotion screen keeps its shape on that bar as well, in the middle of the screen.
- Supply piles stop shouting their cash over the whole map. A small pile shows its amount only while your cursor is on it or close by, in a smaller font; a big supply dock keeps its label all the time. Classic has the same labels now, with the radar still leaving the piles off.
- The Esc menu and the general's promotion screen close the way they open, in both interfaces. Both used to vanish in a single frame, and Classic's Esc menu had lost its opening flash as well. Classic plays 1.04's flash and fade, forwards to open and backwards to close; Reforged fades its pages out over a little more than a tenth of a second, as fast as they fade in.
- Every graphics setting is on the Graphics and Effects pages. Shadows, clouds, ground lighting, soft water edges, trees, extra animations, heat haze, texture resolution and the particle limit used to hide in a popup that only opened if you picked Custom from the detail box on another page, so choosing High never showed you what High turns on. Pick a preset now and its settings change in front of you; touch any one of them and the box reads Custom. Texture filtering and the number of anisotropic samples, which needed a text editor, sit there too.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBarScheme.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBarScheme.h
index dd5333e93..721202607 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBarScheme.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBarScheme.h
@@ -283,6 +283,11 @@ public:
Int getCurrentOverhangX( void ) const
{ return m_currentScheme ? m_currentScheme->getOverhangX() : 0; }
+ /** Whether the painting on screen is solid at this screen point, its layers placed the way
+ * drawBackground and drawForeground put them with the same offset. A texture that is not a
+ * 32-bit targa counts as solid all over its part. */
+ Bool isPaintedAt( Int x, Int y, ICoord2D offset ) const;
+
// parse Functions for the INI file
const FieldParse *getFieldParse() const { return m_controlBarSchemeFieldParseTable; } ///< returns the parsing fields
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 97365f074..6dc42f374 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -1810,16 +1810,18 @@ void ControlBarLayoutUniform( GameWindow *root, Real anchorFracX, Real anchorFra
Real originY = dispH * anchorFracY - CONTROL_BAR_DESIGN_H * anchorFracY * s;
//
- // Classic keeps the loader's stretch, as the game shipped, inside the HUD's 16:9 frame: the powers'
- // column down the frame's right edge beside the bar, the promotion screen over the frame
+ // Classic keeps the bar's own stretch inside the HUD's 16:9 frame (classicScales): the powers'
+ // column down the frame's right edge beside the bar, the promotion screen over the frame. Under
+ // EA's 4:3 bar that is the loader's stretch, as the game shipped it. Under the 16:9 bar it is the
+ // wide painting's, which is nearly square at 16:9; stretching EA's 800 across the frame drew the
+ // general's powers a third wider than tall beside a bar that is not stretched at all.
//
if( barIsClassic() )
{
const UIRect hud = TheHudRect();
- originX = (Real)hud.x;
+ classicScales( dispW, dispH, &s, &sy );
+ originX = hud.x + hud.w * anchorFracX - CONTROL_BAR_DESIGN_W * anchorFracX * s;
originY = 0.0f;
- s = hud.w / CONTROL_BAR_DESIGN_W;
- sy = loadScaleY;
}
ICoord2D rootOrigin;
@@ -2224,13 +2226,13 @@ void ControlBar::triggerRadarAttackGlow( void )
//-------------------------------------------------------------------------------------------------
Bool ControlBar::letsClickThrough( GameWindow *window, Int x, Int y )
{
- // EA's bar: its input-blocking panes are the shape of the bar, and they keep their clicks
- if( barIsClassic() )
- return FALSE;
-
GameWindow *frame = window->winGetParent();
if( frame == NULL || m_controlBarSchemeManager == NULL || TheDisplay == NULL )
return FALSE;
+
+ // EA's 4:3 bar: its input-blocking panes are the shape of the bar, and they keep their clicks
+ if( barIsClassic() && m_controlBarSchemeManager->getCurrentOverhangX() == 0 )
+ return FALSE;
if( frame->winGetWindowId() != (Int)TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ControlBarParent" ) )
return FALSE;
@@ -2238,6 +2240,23 @@ Bool ControlBar::letsClickThrough( GameWindow *window, Int x, Int y )
if( shortName[ 0 ] != 0 && strcmp( shortName, "CenterBackground" ) != 0 )
return FALSE;
+ //
+ // The Classic 16:9 bar's panes are EA's panel rectangles widened by the overhang, and its painting
+ // starts up to 46 design units below their tops over the command grid's shoulders, so the painting
+ // itself decides: transparent there is battlefield.
+ //
+ if( barIsClassic() )
+ {
+ if( window->winPointInChild( x, y, TRUE ) != window )
+ return FALSE;
+
+ ICoord2D now, offset;
+ frame->winGetScreenPosition( &now.x, &now.y );
+ offset.x = now.x - m_panelOrigin.x;
+ offset.y = now.y - m_panelOrigin.y;
+ return m_controlBarSchemeManager->isPaintedAt( x, y, offset ) == FALSE;
+ }
+
// the CSS page is what is drawn, so what it drew solid is what is solid. Asked before the
// children, because a see-through child the page does not draw - the observer's info window
// spans the whole centre - would otherwise keep a click on bare battlefield
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp
index bc468658c..d4f30bf0d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp
@@ -56,6 +56,10 @@
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
#include "Lib/Clock.h"
+#include <map>
+
+#include "Common/file.h"
+#include "Common/FileSystem.h"
#include "Common/Player.h"
#include "Common/PlayerTemplate.h"
#include "Common/Recorder.h"
@@ -1060,6 +1064,84 @@ void ControlBarSchemeManager::drawBackground( ICoord2D offset )
m_currentScheme->drawBackground( m_multiplyer, offset );
}
+//
+// A painting's mask is read off its whole texture the first time a click lands over it, and kept for
+// the session; ControlBarPlateMaskFromTarga is the reader the Reforged plates use. A texture that
+// does not read leaves the mask empty, and an empty mask is solid everywhere.
+//
+typedef std::map< const Image *, std::vector<UnsignedByte> > SchemeImageMaskMap;
+static SchemeImageMaskMap theSchemeImageMasks;
+
+static const std::vector<UnsignedByte> &schemeImageMask( const Image *image )
+{
+ SchemeImageMaskMap::iterator it = theSchemeImageMasks.find( image );
+ if( it != theSchemeImageMasks.end() )
+ return it->second;
+
+ std::vector<UnsignedByte> &mask = theSchemeImageMasks[ image ];
+ AsciiString path;
+ path.format( "Art\\Textures\\%s", image->getFilename().str() );
+ File *file = TheFileSystem->openFile( path.str(), File::READ | File::BINARY );
+ if( file == NULL )
+ {
+ DEBUG_LOG(( "CONTROLBAR SCHEME MASK %s did not open, its part catches every click\n", path.str() ));
+ return mask;
+ }
+
+ const Int length = file->size();
+ char *bytes = file->readEntireAndClose();
+ const ICoord2D *texture = image->getTextureSize();
+ if( ControlBarPlateMaskFromTarga( (const UnsignedByte *)bytes, length, texture->x, texture->y, mask ) == FALSE )
+ {
+ DEBUG_LOG(( "CONTROLBAR SCHEME MASK %s is not a 32-bit targa of %dx%d, its part catches every click\n",
+ path.str(), texture->x, texture->y ));
+ mask.clear();
+ }
+ delete [] bytes;
+ return mask;
+}
+
+//-----------------------------------------------------------------------------
+Bool ControlBarSchemeManager::isPaintedAt( Int x, Int y, ICoord2D offset ) const
+{
+ if( m_currentScheme == NULL )
+ return FALSE;
+
+ offset.x += TheHudRect().x;
+ for( Int i = 0; i < MAX_CONTROL_BAR_SCHEME_IMAGE_LAYERS; i++ )
+ {
+ for( ControlBarScheme::ControlBarSchemeImageList::const_iterator it = m_currentScheme->m_layer[ i ].begin();
+ it != m_currentScheme->m_layer[ i ].end(); ++it )
+ {
+ const ControlBarSchemeImage *part = *it;
+ if( part->m_image == NULL )
+ continue;
+
+ // the rectangle drawForeground and drawBackground draw it into
+ const Int left = REAL_TO_INT_FLOOR( part->m_position.x * m_multiplyer.x ) + offset.x;
+ const Int top = REAL_TO_INT_FLOOR( part->m_position.y * m_multiplyer.y ) + offset.y;
+ const Int right = REAL_TO_INT_CEIL( ( part->m_position.x + part->m_size.x ) * m_multiplyer.x - 0.01f ) + offset.x;
+ const Int bottom = REAL_TO_INT_CEIL( ( part->m_position.y + part->m_size.y ) * m_multiplyer.y - 0.01f ) + offset.y;
+ if( x < left || y < top || x >= right || y >= bottom )
+ continue;
+
+ const std::vector<UnsignedByte> &mask = schemeImageMask( part->m_image );
+ if( mask.empty() )
+ return TRUE;
+
+ const Region2D *uv = part->m_image->getUV();
+ const ICoord2D *texture = part->m_image->getTextureSize();
+ const Real u = uv->lo.x + ( uv->hi.x - uv->lo.x ) * ( x - left + 0.5f ) / ( right - left );
+ const Real v = uv->lo.y + ( uv->hi.y - uv->lo.y ) * ( y - top + 0.5f ) / ( bottom - top );
+ const Int texelX = REAL_TO_INT_FLOOR( u * texture->x );
+ const Int texelY = REAL_TO_INT_FLOOR( v * texture->y );
+ if( mask[ texelY * texture->x + texelX ] )
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
//-----------------------------------------------------------------------------
/** Which side's artwork the bar on screen is wearing, when the scheme's own name is not a side
* anything else knows - "Observer". ControlBar.ini builds that bar entirely out of one faction's