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(gameengine): mod decals and mod command bars laid out as authored

Olcay Seygan527f8372036c
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBarScheme.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBarScheme.h
index 19ad3455b..7a9580a7c 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBarScheme.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBarScheme.h
@@ -53,6 +53,8 @@
//-----------------------------------------------------------------------------
// SYSTEM INCLUDES ////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
+#include <map>
+#include <vector>
//-----------------------------------------------------------------------------
// USER INCLUDES //////////////////////////////////////////////////////////////
@@ -282,6 +284,9 @@ public:
Bool isCurrentSchemeMod( void ) const { return getCurrentSchemeMod() >= 0; }
/// a mod scheme's painting, cut at the panel seams and each piece drawn where its panel stands
void drawModPainting( ICoord2D offset, Bool foreground );
+ /// where the mod's own ControlBar.wnd puts the window with this decorated name, in 800x600 design
+ /// units; FALSE when the mod ships no ControlBar.wnd or no window of that name
+ Bool findModWindowRect( Int mod, const AsciiString& decoratedName, Real *x, Real *y, Real *w, Real *h ) const;
// parse Functions for the INI file
@@ -299,6 +304,7 @@ public:
private:
ControlBarScheme *findSchemeForSide( const AsciiString& side, Int mod ) const; ///< the widest of that side's schemes from mod (-1 ours) the screen can wear
ControlBarScheme *findSchemeForFaction( const AsciiString& side, Int mod ) const; ///< a mod faction's own scheme, else ours
+ void readModWindowRects( void ); ///< fills m_modWindowRects
ControlBarScheme *m_currentScheme; ///< the current scheme that everythign uses
Coord2D m_multiplyer;
@@ -306,6 +312,11 @@ private:
typedef std::list< ControlBarScheme* > ControlBarSchemeList; ///< list of control bar schemes
ControlBarSchemeList m_schemeList;
+ /// -modfactions: each mod's ControlBar.wnd rectangles by window name key, read once in init
+ struct ModWindowRect { Real x, y, w, h; };
+ typedef std::map< UnsignedInt, ModWindowRect > ModWindowRectMap;
+ std::vector< ModWindowRectMap > m_modWindowRects;
+
};
//-----------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
index 3bbec462a..8f9c35412 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/INI/INI.cpp
@@ -645,7 +645,10 @@ Bool ModNamespace::isAsset( const Names &names, const std::string &word )
return TRUE;
// an animation is "<hierarchy>.<animation>", and the file is the animation's
const size_t dot = name.find( '.' );
- return dot != std::string::npos && names.assets.count( name.substr( dot + 1 ) ) != 0;
+ if (dot != std::string::npos)
+ return names.assets.count( name.substr( dot + 1 ) ) != 0;
+ // a shadow or radius decal names its texture with no extension, and the engine appends ".tga"
+ return names.assets.count( name + ".tga" ) != 0;
}
Bool ModNamespace::isAssetField( const std::string &field )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 5f98fc6c3..86e499cb2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -1664,6 +1664,16 @@ static Bool barIsClassic( void )
return TheGlobalData != NULL && TheGlobalData->isClassicUI();
}
+/// -modfactions: a mod's bar is up. Its painting was made for EA's layout, one stretch per axis over
+/// the whole screen, so under it the panels are not at one scale and not pulled apart: the three
+/// transforms below are the loader's own, and the windows go where the mod authored them.
+static Int barModIndex( void )
+{
+ if( TheControlBar == NULL || TheControlBar->getControlBarSchemeManager() == NULL )
+ return -1;
+ return TheControlBar->getControlBarSchemeManager()->getCurrentSchemeMod();
+}
+
/// Where a panel's design x 0 lands on screen.
static Real panelOriginX( Int panel, Real dispW, Real s )
{
@@ -1828,12 +1838,16 @@ Bool ControlBarPanelDesignToScreen( Int panel, const IRegion2D *design,
const Real loadScaleY = dispH / CONTROL_BAR_DESIGN_H;
const Real s = loadScaleX < loadScaleY ? loadScaleX : loadScaleY;
- const Real originX = panelOriginX( panel, dispW, s );
+ // a mod's bar keeps the loader's stretch, panels and all (barModIndex)
+ const Bool stretch = barModIndex() >= 0;
+ const Real sx = stretch ? loadScaleX : s;
+ const Real sy = stretch ? loadScaleY : s;
+ const Real originX = stretch ? 0.0f : panelOriginX( panel, dispW, s );
- rectOut->lo.x = REAL_TO_INT_FLOOR( originX + design->lo.x * s );
- rectOut->hi.x = REAL_TO_INT_CEIL ( originX + design->hi.x * s );
- rectOut->lo.y = REAL_TO_INT_FLOOR( dispH - ( CONTROL_BAR_DESIGN_H - design->lo.y ) * s );
- rectOut->hi.y = REAL_TO_INT_CEIL ( dispH - ( CONTROL_BAR_DESIGN_H - design->hi.y ) * s );
+ rectOut->lo.x = REAL_TO_INT_FLOOR( originX + design->lo.x * sx );
+ rectOut->hi.x = REAL_TO_INT_CEIL ( originX + design->hi.x * sx );
+ rectOut->lo.y = REAL_TO_INT_FLOOR( dispH - ( CONTROL_BAR_DESIGN_H - design->lo.y ) * sy );
+ rectOut->hi.y = REAL_TO_INT_CEIL ( dispH - ( CONTROL_BAR_DESIGN_H - design->hi.y ) * sy );
//
// The screen has three edges the bar touches and each belongs to one panel: the left panel owns
@@ -2012,8 +2026,7 @@ const ControlBarPlate *ControlBarPlateForSide( const AsciiString& side, Int pane
// -modfactions: a mod's bar wears the mod's own painting (drawModPainting), never our plates,
// so nothing shifts its windows off the mod's layout or masks its clicks with our art
- if( TheControlBar && TheControlBar->getControlBarSchemeManager() &&
- TheControlBar->getControlBarSchemeManager()->isCurrentSchemeMod() )
+ if( barModIndex() >= 0 )
return NULL;
// the boss bar is Chinese and the observer bar is American - EA built each out of that art
@@ -2039,6 +2052,20 @@ static const char *shortWindowName( GameWindow *win )
return colon ? colon + 1 : name;
}
+/// The windows ControlBarScheme::init puts at the scheme's own UL/LR rather than where the .wnd has them.
+static Bool isSchemePlacedWindow( const char *shortName )
+{
+ static const char *names[] =
+ {
+ "PopupCommunicator", "ButtonIdleWorker", "ButtonOptions", "ButtonPlaceBeacon", "MoneyDisplay",
+ "PowerWindow", "ButtonGeneral", "ButtonLarge", "WinUAttack", NULL
+ };
+ for( const char **n = names; *n; n++ )
+ if( strcmp( shortName, *n ) == 0 )
+ return TRUE;
+ return FALSE;
+}
+
//-------------------------------------------------------------------------------------------------
// Where a plate is transparent ---------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
@@ -2258,7 +2285,10 @@ void ControlBar::placeInPanel( GameWindow *win, Int panel,
const Real loadScaleX = dispW / CONTROL_BAR_DESIGN_W;
const Real loadScaleY = dispH / CONTROL_BAR_DESIGN_H;
const Real s = ControlBarUniformScale();
- const Real originX = panelOriginX( panel, dispW, s );
+ const Int mod = barModIndex();
+ const Real sx = mod >= 0 ? loadScaleX : s;
+ const Real sy = mod >= 0 ? loadScaleY : s;
+ const Real originX = mod >= 0 ? 0.0f : panelOriginX( panel, dispW, s );
ICoord2D rel, size;
win->winGetPosition( &rel.x, &rel.y );
@@ -2278,13 +2308,24 @@ void ControlBar::placeInPanel( GameWindow *win, Int panel,
place.designH = size.y / loadScaleY;
}
- Int newX = REAL_TO_INT_FLOOR( originX + place.designX * s );
- Int newY = REAL_TO_INT_FLOOR( dispH - ( CONTROL_BAR_DESIGN_H - place.designY ) * s );
- Int newW = REAL_TO_INT_CEIL( place.designW * s );
- Int newH = REAL_TO_INT_CEIL( place.designH * s );
-
const char *shortName = shortWindowName( win );
+ //
+ // Under a mod's bar a window the mod's own ControlBar.wnd places goes where that file says, since
+ // that is what the painting was made around. Not the ones ControlBarScheme::init has just put at
+ // the scheme's UL/LR (the mod's file leaves those at 0,0 100x100), and not the nameless panes.
+ // place.design* stays ours, so the window comes back to our layout when our bar does.
+ //
+ Real designX = place.designX, designY = place.designY, designW = place.designW, designH = place.designH;
+ if( mod >= 0 && shortName[ 0 ] != 0 && !isSchemePlacedWindow( shortName ) )
+ m_controlBarSchemeManager->findModWindowRect( mod, win->winGetInstanceData()->m_decoratedNameString,
+ &designX, &designY, &designW, &designH );
+
+ Int newX = REAL_TO_INT_FLOOR( originX + designX * sx );
+ Int newY = REAL_TO_INT_FLOOR( dispH - ( CONTROL_BAR_DESIGN_H - designY ) * sy );
+ Int newW = REAL_TO_INT_CEIL( designW * sx );
+ Int newH = REAL_TO_INT_CEIL( designH * sy );
+
//
// A plate is its side's own painting rather than a cut of the shipped one, so where it draws the
// money box and the grid field is the plate's business and not ControlBarScheme.ini's. Where
@@ -2777,8 +2818,9 @@ void ControlBar::layoutPanels( void )
parent->winGetScreenPosition( &barOrigin.x, &barOrigin.y );
// the frame itself stays full width - it draws nothing and passes input through
+ const Real sy = barModIndex() >= 0 ? dispH / CONTROL_BAR_DESIGN_H : s; // a mod's bar is stretched
const Int parentTop =
- REAL_TO_INT_FLOOR( dispH - ( CONTROL_BAR_DESIGN_H - CONTROL_BAR_DESIGN_TOP ) * s );
+ REAL_TO_INT_FLOOR( dispH - ( CONTROL_BAR_DESIGN_H - CONTROL_BAR_DESIGN_TOP ) * sy );
parent->winSetPosition( 0, parentTop );
parent->winSetSize( REAL_TO_INT_CEIL( dispW ), REAL_TO_INT_CEIL( dispH ) - parentTop );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp
index 789ddbd25..81c5b423c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarScheme.cpp
@@ -55,6 +55,11 @@
//-----------------------------------------------------------------------------
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
#include "Lib/Clock.h"
+#include <string>
+#include "Common/file.h"
+#include "Common/FileSystem.h"
+#include "Common/GlobalData.h"
+#include "Common/NameKeyGenerator.h"
#include "Common/Player.h"
#include "Common/PlayerTemplate.h"
@@ -970,6 +975,7 @@ void ControlBarSchemeManager::init( void )
ini.load( AsciiString( "Data\\INI\\ControlBarSchemeReforged.ini" ), INI_LOAD_MULTIFILE, NULL );
// -modfactions: each mod's own bars, "M<n>~" names, worn only by that mod's factions
INI::loadModPasses( "Data\\INI\\ControlBarScheme.ini", NULL );
+ readModWindowRects();
// //Load the user modified control bar schemes
// WIN32_FIND_DATA findData;
@@ -1116,10 +1122,73 @@ Int ControlBarSchemeManager::getCurrentSchemeMod( void ) const
}
//-----------------------------------------------------------------------------
-/** A mod's bar is one painting authored for 800x600 (or its ScreenCreationRes) and our bar stands in
- * three panels at one scale, so the painting is cut where the panels meet and each piece is drawn
- * through its own panel's placement, the way the windows above it are placed. Classic and Reforged
- * alike: the windows are laid out the same way in both. */
+/** A mod's bar is painted for the window rectangles of the mod's own ControlBar.wnd: ShockWave's are
+ * EA's (the same 96 rectangles as ours, at 800x600), The End of Days' are a 1920x1080 layout of its
+ * own with the command grid at 668-1308 and the radar at 5-327. The windows stay ours, but under a
+ * mod's bar layoutPanels gives each the rectangle the mod's file names for it (findModWindowRect).
+ * Only SCREENRECT and NAME are read; nothing of the mod's callbacks or draw data is. */
+//-----------------------------------------------------------------------------
+void ControlBarSchemeManager::readModWindowRects( void )
+{
+ m_modWindowRects.clear();
+ if( TheGlobalData == NULL || !TheGlobalData->m_modFactions )
+ return;
+
+ m_modWindowRects.resize( TheGlobalData->m_mods.size() );
+ for( Int mod = 0; mod < (Int)TheGlobalData->m_mods.size(); ++mod )
+ {
+ TheFileSystem->setFocus( mod );
+ File *file = TheFileSystem->openFile( "Window\\ControlBar.wnd" );
+ TheFileSystem->setFocus( FILE_FOCUS_ALL );
+ if( file == NULL )
+ continue;
+ const Int length = file->size();
+ char *raw = file->readEntireAndClose();
+ const std::string text( raw, length ); // the read is not terminated
+ delete [] raw;
+
+ // SCREENRECT = UPPERLEFT: x y, BOTTOMRIGHT: x y, CREATIONRESOLUTION: w h; NAME = "...";
+ for( const char *rect = strstr( text.c_str(), "SCREENRECT" ); rect; rect = strstr( rect + 1, "SCREENRECT" ) )
+ {
+ Int ulx, uly, lrx, lry, resx, resy;
+ char name[ 128 ];
+ if( sscanf( rect, "SCREENRECT = UPPERLEFT: %d %d , BOTTOMRIGHT: %d %d , CREATIONRESOLUTION: %d %d ; NAME = \"%127[^\"]\"",
+ &ulx, &uly, &lrx, &lry, &resx, &resy, name ) != 7 || resx <= 0 || resy <= 0 )
+ continue;
+
+ ModWindowRect r;
+ r.x = ulx * 800.0f / resx;
+ r.y = uly * 600.0f / resy;
+ r.w = ( lrx - ulx ) * 800.0f / resx;
+ r.h = ( lry - uly ) * 600.0f / resy;
+ m_modWindowRects[ mod ][ TheNameKeyGenerator->nameToKey( AsciiString( name ) ) ] = r;
+ }
+ DEBUG_LOG(( "MODNS M%d~ ControlBar.wnd: %d windows\n", mod + 1, (Int)m_modWindowRects[ mod ].size() ));
+ }
+}
+
+Bool ControlBarSchemeManager::findModWindowRect( Int mod, const AsciiString& decoratedName,
+ Real *x, Real *y, Real *w, Real *h ) const
+{
+ if( mod < 0 || mod >= (Int)m_modWindowRects.size() )
+ return FALSE;
+ ModWindowRectMap::const_iterator it = m_modWindowRects[ mod ].find( TheNameKeyGenerator->nameToKey( decoratedName ) );
+ if( it == m_modWindowRects[ mod ].end() )
+ return FALSE;
+ *x = it->second.x;
+ *y = it->second.y;
+ *w = it->second.w;
+ *h = it->second.h;
+ return TRUE;
+}
+
+//-----------------------------------------------------------------------------
+/** A mod's bar is laid out EA's way, one stretch per axis over the whole screen (see
+ * ControlBarPanelDesignToScreen), so the three panel transforms are one and the same and the
+ * painting goes back together at the seams below. The cut only shows while one panel slides or
+ * stands down on its own - the observer's hidden middle - and each piece then travels with its
+ * panel. The seams lie in the gaps of The End of Days' painting (radar to 142, middle 247-552,
+ * right from 677, in design units) and inside ShockWave's one-piece one. */
//-----------------------------------------------------------------------------
void ControlBarSchemeManager::drawModPainting( ICoord2D offset, Bool foreground )
{
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index bd1e67e0e..9d1c7f86c 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -17360,6 +17360,9 @@ TEST(modfactions_prefix_the_mods_own_art)
strcpy( line, " ParticleName = EXSmoke.tga" ); // INI says .tga, the mod ships the .dds
CHECK( names.rewriteLine( line, sizeof( line ) ) );
CHECK_STR( line, " ParticleName = M1~EXSmoke.tga" );
+ strcpy( line, " ShadowTexture = EXSmoke" ); // a decal names its texture bare, the engine adds .tga
+ CHECK( names.rewriteLine( line, sizeof( line ) ) );
+ CHECK_STR( line, " ShadowTexture = M1~EXSmoke" );
strcpy( line, " Sounds = vrange01a vrange01b" );
CHECK( names.rewriteLine( line, sizeof( line ) ) );
CHECK_STR( line, " Sounds = M1~vrange01a vrange01b" );