Skip to content

Commit 568a162

Browse files
authored
feat(client): Make opacity and shadows of build placement preview objects customizable (#1592)
Adds new fields ObjectPlacementOpacity=0..1 and ObjectPlacementShadows=Yes/No to GameData.ini
1 parent c0f8b79 commit 568a162

File tree

6 files changed

+60
-30
lines changed

6 files changed

+60
-30
lines changed

Generals/Code/GameEngine/Include/Common/GlobalData.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ class GlobalData : public SubsystemInterface
425425

426426
AsciiString m_specialPowerViewObjectName; ///< Created when certain special powers are fired so players can watch.
427427

428+
Real m_objectPlacementOpacity; ///< Sets the opacity of build preview objects.
429+
Bool m_objectPlacementShadows; ///< Enables or disables shadows of build preview objects.
430+
428431
std::vector<AsciiString> m_standardPublicBones;
429432

430433
Real m_standardMinefieldDensity;

Generals/Code/GameEngine/Source/Common/GlobalData.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ GlobalData* GlobalData::m_theOriginal = NULL;
398398
{ "EnforceMaxCameraHeight", INI::parseBool, NULL, offsetof( GlobalData, m_enforceMaxCameraHeight ) },
399399
{ "KeyboardScrollSpeedFactor", INI::parseReal, NULL, offsetof( GlobalData, m_keyboardScrollFactor ) },
400400
{ "KeyboardDefaultScrollSpeedFactor", INI::parseReal, NULL, offsetof( GlobalData, m_keyboardDefaultScrollFactor ) },
401+
{ "KeyboardCameraRotateSpeed", INI::parseReal, NULL, offsetof( GlobalData, m_keyboardCameraRotateSpeed ) },
401402
{ "MovementPenaltyDamageState", INI::parseIndexList, TheBodyDamageTypeNames, offsetof( GlobalData, m_movementPenaltyDamageState ) },
402403

403404
// you cannot set this; it always has a value of 100%.
@@ -457,6 +458,11 @@ GlobalData* GlobalData::m_theOriginal = NULL;
457458

458459
{ "SpecialPowerViewObject", INI::parseAsciiString, NULL, offsetof( GlobalData, m_specialPowerViewObjectName ) },
459460

461+
// TheSuperHackers @feature Customize the opacity (0..1) and shadows of build preview objects. Shadows are enabled by default.
462+
// Note that disabling shadows loses a fair bit of contrast visually and warrants raising the opacity.
463+
{ "ObjectPlacementOpacity", INI::parseReal, NULL, offsetof( GlobalData, m_objectPlacementOpacity ) },
464+
{ "ObjectPlacementShadows", INI::parseBool, NULL, offsetof( GlobalData, m_objectPlacementShadows ) },
465+
460466
{ "StandardPublicBone", INI::parseAsciiStringVectorAppend, NULL, offsetof(GlobalData, m_standardPublicBones) },
461467
{ "ShowMetrics", INI::parseBool, NULL, offsetof( GlobalData, m_showMetrics ) },
462468
{ "DefaultStartingCash", INI::parseUnsignedInt, NULL, offsetof( GlobalData, m_defaultStartingCash ) },
@@ -486,7 +492,6 @@ GlobalData* GlobalData::m_theOriginal = NULL;
486492
{ "NetworkPlayerTimeoutTime", INI::parseInt, NULL, offsetof(GlobalData, m_networkPlayerTimeoutTime) },
487493
{ "NetworkDisconnectScreenNotifyTime", INI::parseInt, NULL, offsetof(GlobalData, m_networkDisconnectScreenNotifyTime) },
488494

489-
{ "KeyboardCameraRotateSpeed", INI::parseReal, NULL, offsetof( GlobalData, m_keyboardCameraRotateSpeed ) },
490495
{ "PlayStats", INI::parseInt, NULL, offsetof( GlobalData, m_playStats ) },
491496

492497
#if defined(RTS_DEBUG)
@@ -868,6 +873,9 @@ GlobalData::GlobalData()
868873
m_standardMinefieldDensity = 0.01f;
869874
m_standardMinefieldDistance = 40.0f;
870875

876+
m_objectPlacementOpacity = 0.45f;
877+
m_objectPlacementShadows = TRUE;
878+
871879
m_groupSelectMinSelectSize = 5;
872880
m_groupSelectVolumeBase = 0.5f;
873881
m_groupSelectVolumeIncrement = 0.02f;

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@
8787

8888

8989
// ------------------------------------------------------------------------------------------------
90-
static const Real placementOpacity = 0.45f;
91-
static const RGBColor illegalBuildColor = { 1.0, 0.0, 0.0 };
90+
static const RGBColor IllegalBuildColor = { 1.0, 0.0, 0.0 };
9291

9392
//-------------------------------------------------------------------------------------------------
9493
/// The InGameUI singleton instance.
@@ -1467,8 +1466,9 @@ void InGameUI::handleBuildPlacements( void )
14671466
BuildAssistant::SHROUD_REVEALED,
14681467
builderObject,
14691468
NULL );
1469+
14701470
if( lbc != LBC_OK )
1471-
m_placeIcon[ 0 ]->colorTint( &illegalBuildColor );
1471+
m_placeIcon[ 0 ]->colorTint( &IllegalBuildColor );
14721472
else
14731473
m_placeIcon[ 0 ]->colorTint( NULL );
14741474

@@ -1528,8 +1528,11 @@ void InGameUI::handleBuildPlacements( void )
15281528
{
15291529

15301530
if( m_placeIcon[ i ] == NULL )
1531-
m_placeIcon[ i ] = TheThingFactory->newDrawable( m_pendingPlaceType,
1532-
DRAWABLE_STATUS_SHADOWS | DRAWABLE_STATUS_NO_STATE_PARTICLES );
1531+
{
1532+
UnsignedInt drawableStatus = DRAWABLE_STATUS_NO_STATE_PARTICLES;
1533+
drawableStatus |= TheGlobalData->m_objectPlacementShadows ? DRAWABLE_STATUS_SHADOWS : 0;
1534+
m_placeIcon[ i ] = TheThingFactory->newDrawable( m_pendingPlaceType, drawableStatus );
1535+
}
15331536

15341537
}
15351538

@@ -1553,11 +1556,11 @@ void InGameUI::handleBuildPlacements( void )
15531556
for( i = 0; i < tileBuildInfo->tilesUsed; i++ )
15541557
{
15551558

1556-
// set the drawble position
1559+
// set the drawable position
15571560
m_placeIcon[ i ]->setPosition( &tileBuildInfo->positions[ i ] );
15581561

1559-
// set opacity for the drawble
1560-
m_placeIcon[ i ]->setDrawableOpacity( placementOpacity );
1562+
// set opacity for the drawable
1563+
m_placeIcon[ i ]->setDrawableOpacity( TheGlobalData->m_objectPlacementOpacity );
15611564

15621565
// set the drawable angle
15631566
m_placeIcon[ i ]->setOrientation( angle );
@@ -3039,8 +3042,12 @@ void InGameUI::placeBuildAvailable( const ThingTemplate *build, Drawable *buildD
30393042
///@ todo when message stream order more formalized eliminate this
30403043
// TheInGameUI->deselectAllDrawables();
30413044

3042-
// create a drawble of what we are building to be "attached" at the cursor
3043-
draw = TheThingFactory->newDrawable( build, DRAWABLE_STATUS_SHADOWS | DRAWABLE_STATUS_NO_STATE_PARTICLES );
3045+
{
3046+
// create a drawable of what we are building to be "attached" at the cursor
3047+
UnsignedInt drawableStatus = DRAWABLE_STATUS_NO_STATE_PARTICLES;
3048+
drawableStatus |= TheGlobalData->m_objectPlacementShadows ? DRAWABLE_STATUS_SHADOWS : 0;
3049+
draw = TheThingFactory->newDrawable( build, drawableStatus );
3050+
}
30443051
if (sourceObject)
30453052
{
30463053
if (TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT)
@@ -3058,14 +3065,11 @@ void InGameUI::placeBuildAvailable( const ThingTemplate *build, Drawable *buildD
30583065
//
30593066
Real angle = build->getPlacementViewAngle();
30603067

3061-
// don't forget to take into account the current view angle
3062-
// angle += TheTacticalView->getAngle(); Don't do this - makes odd angled building placements. jba.
3063-
30643068
// set the angle in the icon we just created
30653069
draw->setOrientation( angle );
30663070

30673071
// set the build icon attached to the cursor to be "see-thru"
3068-
draw->setDrawableOpacity( placementOpacity );
3072+
draw->setDrawableOpacity( TheGlobalData->m_objectPlacementOpacity );
30693073

30703074
// set the "icon" in the icon array at the first index
30713075
DEBUG_ASSERTCRASH( m_placeIcon[ 0 ] == NULL, ("placeBuildAvailable, build icon array is not empty!") );

GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ class GlobalData : public SubsystemInterface
436436

437437
AsciiString m_specialPowerViewObjectName; ///< Created when certain special powers are fired so players can watch.
438438

439+
Real m_objectPlacementOpacity; ///< Sets the opacity of build preview objects.
440+
Bool m_objectPlacementShadows; ///< Enables or disables shadows of build preview objects.
441+
439442
std::vector<AsciiString> m_standardPublicBones;
440443

441444
Real m_standardMinefieldDensity;

GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ GlobalData* GlobalData::m_theOriginal = NULL;
398398
{ "EnforceMaxCameraHeight", INI::parseBool, NULL, offsetof( GlobalData, m_enforceMaxCameraHeight ) },
399399
{ "KeyboardScrollSpeedFactor", INI::parseReal, NULL, offsetof( GlobalData, m_keyboardScrollFactor ) },
400400
{ "KeyboardDefaultScrollSpeedFactor", INI::parseReal, NULL, offsetof( GlobalData, m_keyboardDefaultScrollFactor ) },
401+
{ "KeyboardCameraRotateSpeed", INI::parseReal, NULL, offsetof( GlobalData, m_keyboardCameraRotateSpeed ) },
401402
{ "MovementPenaltyDamageState", INI::parseIndexList, TheBodyDamageTypeNames, offsetof( GlobalData, m_movementPenaltyDamageState ) },
402403

403404
// you cannot set this; it always has a value of 100%.
@@ -457,6 +458,11 @@ GlobalData* GlobalData::m_theOriginal = NULL;
457458

458459
{ "SpecialPowerViewObject", INI::parseAsciiString, NULL, offsetof( GlobalData, m_specialPowerViewObjectName ) },
459460

461+
// TheSuperHackers @feature Customize the opacity (0..1) and shadows of build preview objects. Shadows are enabled by default.
462+
// Note that disabling shadows loses a fair bit of contrast visually and warrants raising the opacity.
463+
{ "ObjectPlacementOpacity", INI::parseReal, NULL, offsetof( GlobalData, m_objectPlacementOpacity ) },
464+
{ "ObjectPlacementShadows", INI::parseBool, NULL, offsetof( GlobalData, m_objectPlacementShadows ) },
465+
460466
{ "StandardPublicBone", INI::parseAsciiStringVectorAppend, NULL, offsetof(GlobalData, m_standardPublicBones) },
461467
{ "ShowMetrics", INI::parseBool, NULL, offsetof( GlobalData, m_showMetrics ) },
462468
{ "DefaultStartingCash", Money::parseMoneyAmount, NULL, offsetof( GlobalData, m_defaultStartingCash ) },
@@ -486,7 +492,6 @@ GlobalData* GlobalData::m_theOriginal = NULL;
486492
{ "NetworkPlayerTimeoutTime", INI::parseInt, NULL, offsetof(GlobalData, m_networkPlayerTimeoutTime) },
487493
{ "NetworkDisconnectScreenNotifyTime", INI::parseInt, NULL, offsetof(GlobalData, m_networkDisconnectScreenNotifyTime) },
488494

489-
{ "KeyboardCameraRotateSpeed", INI::parseReal, NULL, offsetof( GlobalData, m_keyboardCameraRotateSpeed ) },
490495
{ "PlayStats", INI::parseInt, NULL, offsetof( GlobalData, m_playStats ) },
491496

492497
#if defined(RTS_DEBUG)
@@ -874,6 +879,9 @@ GlobalData::GlobalData()
874879
m_standardMinefieldDensity = 0.01f;
875880
m_standardMinefieldDistance = 40.0f;
876881

882+
m_objectPlacementOpacity = 0.45f;
883+
m_objectPlacementShadows = TRUE;
884+
877885
m_groupSelectMinSelectSize = 5;
878886
m_groupSelectVolumeBase = 0.5f;
879887
m_groupSelectVolumeIncrement = 0.02f;

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@
9191

9292

9393
// ------------------------------------------------------------------------------------------------
94-
static const Real placementOpacity = 0.45f;
95-
static const RGBColor illegalBuildColor = { 1.0, 0.0, 0.0 };
94+
static const RGBColor IllegalBuildColor = { 1.0, 0.0, 0.0 };
9695

9796
//-------------------------------------------------------------------------------------------------
9897
/// The InGameUI singleton instance.
@@ -1523,8 +1522,9 @@ void InGameUI::handleBuildPlacements( void )
15231522
BuildAssistant::IGNORE_STEALTHED,
15241523
builderObject,
15251524
NULL );
1525+
15261526
if( lbc != LBC_OK )
1527-
m_placeIcon[ 0 ]->colorTint( &illegalBuildColor );
1527+
m_placeIcon[ 0 ]->colorTint( &IllegalBuildColor );
15281528
else
15291529
m_placeIcon[ 0 ]->colorTint( NULL );
15301530

@@ -1584,8 +1584,11 @@ void InGameUI::handleBuildPlacements( void )
15841584
{
15851585

15861586
if( m_placeIcon[ i ] == NULL )
1587-
m_placeIcon[ i ] = TheThingFactory->newDrawable( m_pendingPlaceType,
1588-
DRAWABLE_STATUS_SHADOWS | DRAWABLE_STATUS_NO_STATE_PARTICLES );
1587+
{
1588+
UnsignedInt drawableStatus = DRAWABLE_STATUS_NO_STATE_PARTICLES;
1589+
drawableStatus |= TheGlobalData->m_objectPlacementShadows ? DRAWABLE_STATUS_SHADOWS : 0;
1590+
m_placeIcon[ i ] = TheThingFactory->newDrawable( m_pendingPlaceType, drawableStatus );
1591+
}
15891592

15901593
}
15911594

@@ -1609,11 +1612,11 @@ void InGameUI::handleBuildPlacements( void )
16091612
for( i = 0; i < tileBuildInfo->tilesUsed; i++ )
16101613
{
16111614

1612-
// set the drawble position
1615+
// set the drawable position
16131616
m_placeIcon[ i ]->setPosition( &tileBuildInfo->positions[ i ] );
16141617

1615-
// set opacity for the drawble
1616-
m_placeIcon[ i ]->setDrawableOpacity( placementOpacity );
1618+
// set opacity for the drawable
1619+
m_placeIcon[ i ]->setDrawableOpacity( TheGlobalData->m_objectPlacementOpacity );
16171620

16181621
// set the drawable angle
16191622
m_placeIcon[ i ]->setOrientation( angle );
@@ -3119,8 +3122,12 @@ void InGameUI::placeBuildAvailable( const ThingTemplate *build, Drawable *buildD
31193122
///@ todo when message stream order more formalized eliminate this
31203123
// TheInGameUI->deselectAllDrawables();
31213124

3122-
// create a drawble of what we are building to be "attached" at the cursor
3123-
draw = TheThingFactory->newDrawable( build, DRAWABLE_STATUS_SHADOWS | DRAWABLE_STATUS_NO_STATE_PARTICLES );
3125+
{
3126+
// create a drawable of what we are building to be "attached" at the cursor
3127+
UnsignedInt drawableStatus = DRAWABLE_STATUS_NO_STATE_PARTICLES;
3128+
drawableStatus |= TheGlobalData->m_objectPlacementShadows ? DRAWABLE_STATUS_SHADOWS : 0;
3129+
draw = TheThingFactory->newDrawable( build, drawableStatus );
3130+
}
31243131
if (sourceObject)
31253132
{
31263133
if (TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT)
@@ -3138,14 +3145,11 @@ void InGameUI::placeBuildAvailable( const ThingTemplate *build, Drawable *buildD
31383145
//
31393146
Real angle = build->getPlacementViewAngle();
31403147

3141-
// don't forget to take into account the current view angle
3142-
// angle += TheTacticalView->getAngle(); Don't do this - makes odd angled building placements. jba.
3143-
31443148
// set the angle in the icon we just created
31453149
draw->setOrientation( angle );
31463150

31473151
// set the build icon attached to the cursor to be "see-thru"
3148-
draw->setDrawableOpacity( placementOpacity );
3152+
draw->setDrawableOpacity( TheGlobalData->m_objectPlacementOpacity );
31493153

31503154
// set the "icon" in the icon array at the first index
31513155
DEBUG_ASSERTCRASH( m_placeIcon[ 0 ] == NULL, ("placeBuildAvailable, build icon array is not empty!") );

0 commit comments

Comments
 (0)