Skip to content
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

Customizable Bars of Health Points #1395

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions Phobos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<ClCompile Include="src\Misc\RetryDialog.cpp" />
<ClCompile Include="src\New\Type\Affiliated\DroppodTypeClass.cpp" />
<ClCompile Include="src\New\Type\DigitalDisplayTypeClass.cpp" />
<ClCompile Include="src\New\Type\BarTypeClass.cpp" />
<ClCompile Include="src\New\Type\RadTypeClass.cpp" />
<ClCompile Include="src\New\Type\ShieldTypeClass.cpp" />
<ClCompile Include="src\New\Type\LaserTrailTypeClass.cpp" />
Expand Down Expand Up @@ -215,6 +216,7 @@
<ClInclude Include="src\New\Type\Affiliated\TypeConvertGroup.h" />
<ClInclude Include="src\New\Type\Affiliated\DroppodTypeClass.h" />
<ClInclude Include="src\New\Type\DigitalDisplayTypeClass.h" />
<ClInclude Include="src\New\Type\BarTypeClass.h" />
<ClInclude Include="src\New\Type\RadTypeClass.h" />
<ClInclude Include="src\New\Type\ShieldTypeClass.h" />
<ClInclude Include="src\New\Type\LaserTrailTypeClass.h" />
Expand Down
2 changes: 2 additions & 0 deletions src/Ext/Rules/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <New/Type/LaserTrailTypeClass.h>
#include <New/Type/DigitalDisplayTypeClass.h>
#include <New/Type/AttachEffectTypeClass.h>
#include <New/Type/BarTypeClass.h>

std::unique_ptr<RulesExt::ExtData> RulesExt::Data = nullptr;

Expand All @@ -34,6 +35,7 @@ void RulesExt::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
ShieldTypeClass::LoadFromINIList(pINI);
LaserTrailTypeClass::LoadFromINIList(&CCINIClass::INI_Art.get());
AttachEffectTypeClass::LoadFromINIList(pINI);
BarTypeClass::LoadFromINIList(pINI);

Data->LoadBeforeTypeData(pThis, pINI);
}
Expand Down
60 changes: 60 additions & 0 deletions src/Ext/Techno/Body.Visuals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,63 @@ void TechnoExt::GetValuesForDisplay(TechnoClass* pThis, DisplayInfoType infoType
}
}
}

void TechnoExt::DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLocation, RectangleStruct* pBounds, double barPercentage, double conditionYellow, double conditionRed)
{
const BlitterFlags blitFlagsBG = barType->Board_Background_Translucency.Get(0);
const BlitterFlags blitFlagsFG = barType->Board_Foreground_Translucency.Get(0);
const Point2D sectionOffset = barType->Sections_PositionDelta;
const Vector3D<int> sectionFrames = barType->Sections_Pips;
const int sectionAmount = barType->Sections_Amount;
const int sectionEmptyFrame = barType->Sections_EmptyPip;
const bool drawBackwards = barType->Sections_DrawBackwards;
int sectionsToDraw = (int)round(sectionAmount * barPercentage);
sectionsToDraw = sectionsToDraw == 0 ? 1 : sectionsToDraw;
int frameIdxa = sectionFrames.Z;
int sign = drawBackwards ? 1 : -1;

if (barPercentage > conditionYellow)
frameIdxa = sectionFrames.X;
else if (barPercentage > conditionRed)
frameIdxa = sectionFrames.Y;

pLocation += barType->Bar_Offset;
Point2D boardPosition = pLocation + barType->Board_Offset;

if (barType->Board_Background_File && (pThis->IsSelected || barType->Board_Background_ShowWhenNotSelected))
DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, barType->Board_Background_File.Get(),
0, &boardPosition, pBounds, BlitterFlags(0xE00) | blitFlagsBG, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0);

Point2D position = pLocation;
position += {sign * (int)round(sectionAmount * sectionOffset.X / 2), sign * (int)round(sectionAmount * sectionOffset.Y / 2)};

if (sectionEmptyFrame != -1)
{
for (int i = 0; i < sectionAmount; ++i)
{
position -= {sign * sectionOffset.X, sign * sectionOffset.Y};
DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, barType->Sections_Pips_File.Get(),
sectionEmptyFrame, &position, pBounds, BlitterFlags(0x600), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0);
Fryone marked this conversation as resolved.
Show resolved Hide resolved
}

position = pLocation;
position += {sign * (int)round(sectionAmount * sectionOffset.X / 2), sign * (int)round(sectionAmount * sectionOffset.Y / 2)};
}

if (drawBackwards)
{
for (int i = 0; i < (sectionAmount - sectionsToDraw); ++i)
position -= sectionOffset;
}

for (int i = 0; i < sectionsToDraw; ++i)
{
position -= {sign * sectionOffset.X, sign * sectionOffset.Y};
DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, barType->Sections_Pips_File.Get(),
frameIdxa, &position, pBounds, BlitterFlags(0x600), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0);
Fryone marked this conversation as resolved.
Show resolved Hide resolved
}

if (barType->Board_Foreground_File && (pThis->IsSelected || barType->Board_Foreground_ShowWhenNotSelected))
DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, barType->Board_Foreground_File.Get(),
0, &boardPosition, pBounds, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0);
}
1 change: 1 addition & 0 deletions src/Ext/Techno/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class TechnoExt
static Point2D GetBuildingSelectBracketPosition(TechnoClass* pThis, BuildingSelectBracketPosition bracketPosition);
static void ProcessDigitalDisplays(TechnoClass* pThis);
static void GetValuesForDisplay(TechnoClass* pThis, DisplayInfoType infoType, int& value, int& maxValue);
static void DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLocation, RectangleStruct* pBounds, double barPercentage, double conditionYellow, double conditionRed);

// WeaponHelpers.cpp
static int PickWeaponIndex(TechnoClass* pThis, TechnoClass* pTargetTechno, AbstractClass* pTarget, int weaponIndexOne, int weaponIndexTwo, bool allowFallback = true, bool allowAAFallback = true);
Expand Down
54 changes: 54 additions & 0 deletions src/Ext/Techno/Hooks.Pips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,57 @@ DEFINE_HOOK(0x70A4FB, TechnoClass_DrawPips_SelfHealGain, 0x5)

return SkipGameDrawing;
}

DEFINE_HOOK(0x6F64A9, TechnoClass_DrawHealthBar_HealthAndShieldBar, 0x5)
{
enum { Skip = 0x6F6AB6 };

GET(TechnoClass*, pThis, ECX);
GET_STACK(Point2D*, pLocation, STACK_OFFSET(0x4C, 0x4));
GET_STACK(RectangleStruct*, pBound, STACK_OFFSET(0x4C, 0x8));

const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType());

if (pTypeExt && pTypeExt->HealthBar_Hide)
return Skip;

if (!pTypeExt->HealthBar_BarType)
return 0;

const bool pThisIsInf = pThis->WhatAmI() == AbstractType::Infantry;
const bool pThisIsBld = pThis->WhatAmI() == AbstractType::Building;
const auto thisHBType = pTypeExt->HealthBar_BarType.Get();
const auto thisSBType = pTypeExt->ShieldBar_BarType.Get();
Point2D position = *pLocation;
int length = pThisIsInf ? 8 : 17;

if (pThisIsBld)
{
position.Y -= (static_cast<BuildingClass*>(pThis)->Type->Height + 1) * Unsorted::CellHeightInPixels / 2;
const int pThisBldTypeWidth = static_cast<BuildingClass*>(pThis)->Type->GetFoundationWidth();
length = pThisBldTypeWidth * 7 + (pThisBldTypeWidth / 2);
}
else
{
position.Y -= pThisIsInf ? 25 : 26;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add constants from here to YRpp (I think) to improve readability

position.Y += pThis->GetTechnoType()->PixelSelectionBracketDelta;
}

TechnoExt::DrawBar(pThis, thisHBType, position, pBound, pThis->GetHealthPercentage(), RulesClass::Instance->ConditionYellow, RulesClass::Instance->ConditionRed);
const auto pExt = TechnoExt::ExtMap.Find(pThis);

if (const auto pShieldData = pExt->Shield.get())
{
if (pShieldData->IsAvailable() && (pShieldData->GetHP() > 0))
{
if(thisSBType)
TechnoExt::DrawBar(pThis, thisSBType, position, pBound, pShieldData->GetHealthRatio(), pShieldData->GetType()->GetConditionYellow(), pShieldData->GetType()->GetConditionRed());
else
pShieldData->DrawShieldBar(length, pLocation, pBound);
}
}

TechnoExt::ProcessDigitalDisplays(pThis);

return Skip;
}
6 changes: 6 additions & 0 deletions src/Ext/TechnoType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->Wake_Grapple.Read(exINI, pSection, "Wake.Grapple");
this->Wake_Sinking.Read(exINI, pSection, "Wake.Sinking");

this->HealthBar_BarType.Read(exINI, pSection, "HealthBar.BarType");
this->ShieldBar_BarType.Read(exINI, pSection, "ShieldBar.BarType");

// Ares 0.2
this->RadarJamRadius.Read(exINI, pSection, "RadarJamRadius");

Expand Down Expand Up @@ -688,6 +691,9 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
.Process(this->Wake)
.Process(this->Wake_Grapple)
.Process(this->Wake_Sinking)

.Process(this->HealthBar_BarType)
.Process(this->ShieldBar_BarType)
;
}
void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm)
Expand Down
7 changes: 7 additions & 0 deletions src/Ext/TechnoType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <New/Type/Affiliated/PassengerDeletionTypeClass.h>
#include <New/Type/DigitalDisplayTypeClass.h>
#include <New/Type/Affiliated/DroppodTypeClass.h>
#include <New/Type/BarTypeClass.h>

class Matrix3D;

Expand Down Expand Up @@ -233,6 +234,9 @@ class TechnoTypeExt
Nullable<AnimTypeClass*> Wake_Grapple;
Nullable<AnimTypeClass*> Wake_Sinking;

Nullable<BarTypeClass*> HealthBar_BarType;
Nullable<BarTypeClass*> ShieldBar_BarType;

struct LaserTrailDataEntry
{
ValueableIdx<LaserTrailTypeClass> idxType;
Expand Down Expand Up @@ -461,6 +465,9 @@ class TechnoTypeExt
, Wake { }
, Wake_Grapple { }
, Wake_Sinking { }

, HealthBar_BarType { }
, ShieldBar_BarType { }
{ }

virtual ~ExtData() = default;
Expand Down
10 changes: 0 additions & 10 deletions src/Ext/TechnoType/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@
#include <RocketLocomotionClass.h>
#include <TunnelLocomotionClass.h>

DEFINE_HOOK(0x6F64A9, TechnoClass_DrawHealthBar_Hide, 0x5)
{
GET(TechnoClass*, pThis, ECX);
auto pTypeData = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType());
if (pTypeData && pTypeData->HealthBar_Hide)
return 0x6F6AB6;

return 0;
}

DEFINE_HOOK(0x6F3C56, TechnoClass_GetFLH_TurretMultiOffset, 0x0)
{
LEA_STACK(Matrix3D*, mtx, STACK_OFFSET(0xD8, -0x90));
Expand Down
66 changes: 66 additions & 0 deletions src/New/Type/BarTypeClass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "BarTypeClass.h"

#include <TacticalClass.h>
#include <SpawnManagerClass.h>

#include <Ext/Techno/Body.h>

template<>
const char* Enumerable<BarTypeClass>::GetMainSection()
{
return "BarTypes";
}

void BarTypeClass::LoadFromINI(CCINIClass* pINI)
{
const char* section = this->Name;

INI_EX exINI(pINI);

this->Board_Background_File.Read(exINI, section, "Board.Background.File");
this->Board_Background_ShowWhenNotSelected.Read(exINI, section, "Board.Background.ShowWhenNotSelected");
this->Board_Background_Translucency.Read(exINI, section, "Board.Background.Translucency");
this->Board_Foreground_File.Read(exINI, section, "Board.Foreground.File");
this->Board_Foreground_ShowWhenNotSelected.Read(exINI, section, "Board.Foreground.ShowWhenNotSelected");
this->Board_Foreground_Translucency.Read(exINI, section, "Board.Foreground.Translucency");
this->Board_Offset.Read(exINI, section, "Board.Offset");
this->Bar_Offset.Read(exINI, section, "Bar.Offset");
this->Sections_DrawBackwards.Read(exINI, section, "Sections.DrawBackwards");
this->Sections_Pips_File.Read(exINI, section, "Sections.Pips.File");
this->Sections_Pips.Read(exINI, section, "Sections.Pips");
this->Sections_EmptyPip.Read(exINI, section, "Sections.EmptyPip");
this->Sections_Amount.Read(exINI, section, "Sections.Amount");
this->Sections_PositionDelta.Read(exINI, section, "Sections.PositionDelta");

}

template <typename T>
void BarTypeClass::Serialize(T& Stm)
{
Stm
.Process(this->Board_Background_File)
.Process(this->Board_Background_ShowWhenNotSelected)
.Process(this->Board_Background_Translucency)
.Process(this->Board_Foreground_File)
.Process(this->Board_Foreground_ShowWhenNotSelected)
.Process(this->Board_Foreground_Translucency)
.Process(this->Board_Offset)
.Process(this->Bar_Offset)
.Process(this->Sections_DrawBackwards)
.Process(this->Sections_Pips_File)
.Process(this->Sections_Pips)
.Process(this->Sections_EmptyPip)
.Process(this->Sections_Amount)
.Process(this->Sections_PositionDelta)
;
}

void BarTypeClass::LoadFromStream(PhobosStreamReader& Stm)
{
this->Serialize(Stm);
}

void BarTypeClass::SaveToStream(PhobosStreamWriter& Stm)
{
this->Serialize(Stm);
}
50 changes: 50 additions & 0 deletions src/New/Type/BarTypeClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once
#include <Utilities/Enumerable.h>
#include <Utilities/Template.h>
#include <Utilities/GeneralUtils.h>
#include <Utilities/TemplateDef.h>
#include <Utilities/Anchor.h>

class BarTypeClass final : public Enumerable<BarTypeClass>
{
public:
Nullable<SHPStruct*> Board_Background_File;
Valueable<bool> Board_Background_ShowWhenNotSelected;
Nullable<TranslucencyLevel> Board_Background_Translucency;
Nullable<SHPStruct*> Board_Foreground_File;
Valueable<bool> Board_Foreground_ShowWhenNotSelected;
Nullable<TranslucencyLevel> Board_Foreground_Translucency;
Valueable<Vector2D<int>> Board_Offset;
Valueable<Vector2D<int>> Bar_Offset;
Valueable<bool> Sections_DrawBackwards;
Valueable<SHPStruct*> Sections_Pips_File;
Valueable<Vector3D<int>> Sections_Pips;
Valueable<int> Sections_EmptyPip;
Valueable<int> Sections_Amount;
Valueable<Vector2D<int>> Sections_PositionDelta;

BarTypeClass(const char* pTitle = NONE_STR) : Enumerable<BarTypeClass>(pTitle)
, Board_Background_File { }
, Board_Background_ShowWhenNotSelected { false }
, Board_Background_Translucency { }
, Board_Foreground_File { }
, Board_Foreground_ShowWhenNotSelected { false }
, Board_Foreground_Translucency { }
, Board_Offset { { 0, 0 } }
, Bar_Offset { { 0, 0 } }
, Sections_DrawBackwards { false }
, Sections_Pips_File { FileSystem::PIPS_SHP() }
, Sections_Pips { { 16, 17, 18 } }
, Sections_EmptyPip { -1 }
, Sections_Amount { 17 }
, Sections_PositionDelta { { 2, 0 } }
{ }

void LoadFromINI(CCINIClass* pINI);
void LoadFromStream(PhobosStreamReader& Stm);
void SaveToStream(PhobosStreamWriter& Stm);

private:
template <typename T>
void Serialize(T& Stm);
};
4 changes: 3 additions & 1 deletion src/Phobos.Ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <New/Type/RadTypeClass.h>
#include <New/Type/LaserTrailTypeClass.h>
#include <New/Type/DigitalDisplayTypeClass.h>
#include <New/Type/BarTypeClass.h>

#include <utility>

Expand Down Expand Up @@ -229,7 +230,8 @@ using PhobosTypeRegistry = TypeRegistry<
ShieldClass,
DigitalDisplayTypeClass,
AttachEffectTypeClass,
AttachEffectClass
AttachEffectClass,
BarTypeClass
// other classes
>;

Expand Down