From 514420d072eb31558eb9f009e347a8d8e9433b74 Mon Sep 17 00:00:00 2001 From: Fryone Date: Wed, 25 Sep 2024 19:36:59 +0300 Subject: [PATCH 01/14] custom health bar types Initial commit --- Phobos.vcxproj | 2 + src/Ext/Rules/Body.cpp | 2 + src/Ext/Techno/Hooks.Pips.cpp | 92 +++++++++++++++++++++++++++++ src/Ext/TechnoType/Body.cpp | 4 ++ src/Ext/TechnoType/Body.h | 5 ++ src/New/Type/HealthBarTypeClass.cpp | 56 ++++++++++++++++++ src/New/Type/HealthBarTypeClass.h | 40 +++++++++++++ src/Phobos.Ext.cpp | 4 +- 8 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 src/New/Type/HealthBarTypeClass.cpp create mode 100644 src/New/Type/HealthBarTypeClass.h diff --git a/Phobos.vcxproj b/Phobos.vcxproj index da0fa52603..8585d70341 100644 --- a/Phobos.vcxproj +++ b/Phobos.vcxproj @@ -74,6 +74,7 @@ + @@ -215,6 +216,7 @@ + diff --git a/src/Ext/Rules/Body.cpp b/src/Ext/Rules/Body.cpp index 336cae4272..cd0cda2db8 100644 --- a/src/Ext/Rules/Body.cpp +++ b/src/Ext/Rules/Body.cpp @@ -9,6 +9,7 @@ #include #include #include +#include std::unique_ptr RulesExt::Data = nullptr; @@ -34,6 +35,7 @@ void RulesExt::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI) ShieldTypeClass::LoadFromINIList(pINI); LaserTrailTypeClass::LoadFromINIList(&CCINIClass::INI_Art.get()); AttachEffectTypeClass::LoadFromINIList(pINI); + HealthBarTypeClass::LoadFromINIList(pINI); Data->LoadBeforeTypeData(pThis, pINI); } diff --git a/src/Ext/Techno/Hooks.Pips.cpp b/src/Ext/Techno/Hooks.Pips.cpp index 064274c7d7..4d97e89491 100644 --- a/src/Ext/Techno/Hooks.Pips.cpp +++ b/src/Ext/Techno/Hooks.Pips.cpp @@ -275,3 +275,95 @@ DEFINE_HOOK(0x70A4FB, TechnoClass_DrawPips_SelfHealGain, 0x5) return SkipGameDrawing; } + +DEFINE_HOOK(0x6F64C1, TechnoClass_DrawHealthBar_BuildingHealthBar, 0xA) +{ + enum { Continue = 0x6F64CB, Skip = 0x6F683C }; + GET(TechnoClass*, pThis, ESI); + + R->EAX(pThis->GetTechnoType()); + + const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType()); + + if(pThis->WhatAmI() == AbstractType::Building && pTypeExt->CustomHealthBarType) + return Skip; + + return Continue; +} + +DEFINE_HOOK(0x6F6846, TechnoClass_DrawHealthBar_CustomHealthBar, 0x6) +{ + enum { Continue = 0x6F68E8, ContinueInf = 0x6F6852, Skip = 0x6F6A58 }; + GET(TechnoClass*, pThis, ESI); + GET_STACK(Point2D*, pLocation, STACK_OFFSET(0x4C, 0x4)); + GET_STACK(RectangleStruct*, pBound, STACK_OFFSET(0x4C, 0x8)); + const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType()); + + bool pThisIsInf = pThis->WhatAmI() == AbstractType::Infantry; + + if(!pTypeExt->CustomHealthBarType) + { + R->AL(pThis->IsSelected); + if(pThisIsInf) + return ContinueInf; + return Continue; + } + + const auto thisHBType = pTypeExt->CustomHealthBarType.Get(); + const auto pipBoardBG = thisHBType->Frame_Background.Get(FileSystem::PIPBRD_SHP()); + const bool pipBoardBGVisibility = thisHBType->Frame_Background_ShowWhenNotSelected.Get(); + const BlitterFlags blitFlags = thisHBType->Frame_Background_Translucency.Get(0); + const auto pipBoardFG = thisHBType->Frame_Foreground.Get(); + const bool pipBoardFGVisibility = thisHBType->Frame_Foreground_ShowWhenNotSelected.Get(); + const int pipsOffset = thisHBType->HealthBar_XOffset.Get(); + const Vector3D pipsFrames = thisHBType->Sections_Pips.Get(); + const int pipsAmount = thisHBType->Sections_Amount.Get(); + const int pipsSize = thisHBType->Sections_Size.Get(); + + int top_adjust = pThisIsInf ? -25 : -26; + int left_adjust = pipsAmount * pipsSize / 2 - pipsSize; + left_adjust = (pipsAmount % 2 == 0) ? left_adjust - 1 : left_adjust; + int border_adjust = (pipsAmount % 2 == 0) ? 1 : 0; + Point2D position; + + if(pThis->WhatAmI() == AbstractType::Building) + top_adjust -= static_cast(pThis)->Type->Height * Unsorted::CellHeightInPixels / 2; + + if(pThis->IsSelected || pipBoardBGVisibility) + { + position.X = pLocation->X + 1 + border_adjust + pipsOffset; + position.Y = pThis->GetTechnoType()->PixelSelectionBracketDelta + pLocation->Y + top_adjust; + DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, pipBoardBG, + 0, &position, pBound, BlitterFlags(0xE00) | blitFlags, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + } + + double health = pThis->GetHealthPercentage(); + int frameIdxa = pipsFrames.Z; + + if (health > RulesClass::Instance->ConditionYellow) + frameIdxa = pipsFrames.X; + else if (health > RulesClass::Instance->ConditionRed) + frameIdxa = pipsFrames.Y; + + int pipsNeeded = (int)round(health * pipsAmount); + pipsNeeded = pipsNeeded <= 0 ? 1 : pipsNeeded; + + for(int i = 0; i < pipsNeeded; ++i) + { + position.X = pLocation->X - left_adjust + pipsOffset + pipsSize * i; + position.Y = pThis->GetTechnoType()->PixelSelectionBracketDelta + pLocation->Y + top_adjust + 1; + DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, FileSystem::PIPS_SHP(), + frameIdxa, &position, pBound, BlitterFlags(0x600), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + } + + if(pipBoardFG && (pThis->IsSelected || pipBoardFGVisibility)) + { + position.X = pLocation->X + 1 + border_adjust + pipsOffset; + position.Y = pThis->GetTechnoType()->PixelSelectionBracketDelta + pLocation->Y + top_adjust; + DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, pipBoardFG, + 0, &position, pBound, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + } + + R->EDI(pLocation); + return Skip; +} diff --git a/src/Ext/TechnoType/Body.cpp b/src/Ext/TechnoType/Body.cpp index aef8425b07..13d7ed94dc 100644 --- a/src/Ext/TechnoType/Body.cpp +++ b/src/Ext/TechnoType/Body.cpp @@ -319,6 +319,8 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) this->Wake_Grapple.Read(exINI, pSection, "Wake.Grapple"); this->Wake_Sinking.Read(exINI, pSection, "Wake.Sinking"); + this->CustomHealthBarType.Read(exINI, pSection, "CustomHealthBarType"); + // Ares 0.2 this->RadarJamRadius.Read(exINI, pSection, "RadarJamRadius"); @@ -688,6 +690,8 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm) .Process(this->Wake) .Process(this->Wake_Grapple) .Process(this->Wake_Sinking) + + .Process(this->CustomHealthBarType) ; } void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm) diff --git a/src/Ext/TechnoType/Body.h b/src/Ext/TechnoType/Body.h index b390188549..7b40c39037 100644 --- a/src/Ext/TechnoType/Body.h +++ b/src/Ext/TechnoType/Body.h @@ -12,6 +12,7 @@ #include #include #include +#include class Matrix3D; @@ -233,6 +234,8 @@ class TechnoTypeExt Nullable Wake_Grapple; Nullable Wake_Sinking; + Valueable CustomHealthBarType; + struct LaserTrailDataEntry { ValueableIdx idxType; @@ -461,6 +464,8 @@ class TechnoTypeExt , Wake { } , Wake_Grapple { } , Wake_Sinking { } + + , CustomHealthBarType {} { } virtual ~ExtData() = default; diff --git a/src/New/Type/HealthBarTypeClass.cpp b/src/New/Type/HealthBarTypeClass.cpp new file mode 100644 index 0000000000..1c9e8cecbe --- /dev/null +++ b/src/New/Type/HealthBarTypeClass.cpp @@ -0,0 +1,56 @@ +#include "HealthBarTypeClass.h" + +#include +#include + +#include + +template<> +const char* Enumerable::GetMainSection() +{ + return "HealthBarTypes"; +} + +void HealthBarTypeClass::LoadFromINI(CCINIClass* pINI) +{ + const char* section = this->Name; + + INI_EX exINI(pINI); + + this->Frame_Background.Read(exINI, section, "Frame.Background"); + this->Frame_Background_ShowWhenNotSelected.Read(exINI, section, "Frame.Background.ShowWhenNotSelected"); + this->Frame_Background_Translucency.Read(exINI, section, "Frame.Background.Translucency"); + this->Frame_Foreground.Read(exINI, section, "Frame.Foreground"); + this->Frame_Foreground_ShowWhenNotSelected.Read(exINI, section, "Frame.Foreground.ShowWhenNotSelected"); + this->HealthBar_XOffset.Read(exINI, section, "HealthBar.OffsetX"); + this->Sections_Pips.Read(exINI, section, "Sections.Pips"); + this->Sections_Amount.Read(exINI, section, "Sections.Amount"); + this->Sections_Size.Read(exINI, section, "Sections.Size"); + +} + +template +void HealthBarTypeClass::Serialize(T& Stm) +{ + Stm + .Process(this->Frame_Background) + .Process(this->Frame_Background_ShowWhenNotSelected) + .Process(this->Frame_Background_Translucency) + .Process(this->Frame_Foreground) + .Process(this->Frame_Foreground_ShowWhenNotSelected) + .Process(this->HealthBar_XOffset) + .Process(this->Sections_Pips) + .Process(this->Sections_Amount) + .Process(this->Sections_Size) + ; +} + +void HealthBarTypeClass::LoadFromStream(PhobosStreamReader& Stm) +{ + this->Serialize(Stm); +} + +void HealthBarTypeClass::SaveToStream(PhobosStreamWriter& Stm) +{ + this->Serialize(Stm); +} diff --git a/src/New/Type/HealthBarTypeClass.h b/src/New/Type/HealthBarTypeClass.h new file mode 100644 index 0000000000..d6af051b43 --- /dev/null +++ b/src/New/Type/HealthBarTypeClass.h @@ -0,0 +1,40 @@ +#pragma once +#include +#include +#include +#include +#include + +class HealthBarTypeClass final : public Enumerable +{ +public: + Nullable Frame_Background; + Valueable Frame_Background_ShowWhenNotSelected; + Nullable Frame_Background_Translucency; + Nullable Frame_Foreground; + Valueable Frame_Foreground_ShowWhenNotSelected; + Valueable HealthBar_XOffset; + Valueable> Sections_Pips; + Valueable Sections_Amount; + Valueable Sections_Size; + + HealthBarTypeClass(const char* pTitle = NONE_STR) : Enumerable(pTitle) + , Frame_Background { } + , Frame_Background_ShowWhenNotSelected { false } + , Frame_Background_Translucency { } + , Frame_Foreground { } + , Frame_Foreground_ShowWhenNotSelected { false } + , HealthBar_XOffset { 0 } + , Sections_Pips { { 16,17,18 } } + , Sections_Amount { 17 } + , Sections_Size { 2 } + { } + + void LoadFromINI(CCINIClass* pINI); + void LoadFromStream(PhobosStreamReader& Stm); + void SaveToStream(PhobosStreamWriter& Stm); + +private: + template + void Serialize(T& Stm); +}; diff --git a/src/Phobos.Ext.cpp b/src/Phobos.Ext.cpp index 9d743dd835..6621d98ff7 100644 --- a/src/Phobos.Ext.cpp +++ b/src/Phobos.Ext.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -229,7 +230,8 @@ using PhobosTypeRegistry = TypeRegistry< ShieldClass, DigitalDisplayTypeClass, AttachEffectTypeClass, - AttachEffectClass + AttachEffectClass, + HealthBarTypeClass // other classes >; From 35350e4f3fbbc48fb98f8ef8e377e690530edf38 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 28 Sep 2024 14:35:31 +0300 Subject: [PATCH 02/14] changed to BarTypes - added emptypip - added draw direction - added border offset - changed overall logic --- Phobos.vcxproj | 4 +- src/Ext/Rules/Body.cpp | 4 +- src/Ext/Techno/Body.Visuals.cpp | 59 ++++++++++++++++++++++++++ src/Ext/Techno/Body.h | 1 + src/Ext/Techno/Hooks.Pips.cpp | 63 +++++----------------------- src/Ext/TechnoType/Body.cpp | 4 +- src/Ext/TechnoType/Body.h | 6 +-- src/New/Type/BarTypeClass.cpp | 64 +++++++++++++++++++++++++++++ src/New/Type/BarTypeClass.h | 48 ++++++++++++++++++++++ src/New/Type/HealthBarTypeClass.cpp | 56 ------------------------- src/New/Type/HealthBarTypeClass.h | 40 ------------------ src/Phobos.Ext.cpp | 4 +- 12 files changed, 193 insertions(+), 160 deletions(-) create mode 100644 src/New/Type/BarTypeClass.cpp create mode 100644 src/New/Type/BarTypeClass.h delete mode 100644 src/New/Type/HealthBarTypeClass.cpp delete mode 100644 src/New/Type/HealthBarTypeClass.h diff --git a/Phobos.vcxproj b/Phobos.vcxproj index 8585d70341..cd71d5691d 100644 --- a/Phobos.vcxproj +++ b/Phobos.vcxproj @@ -74,7 +74,7 @@ - + @@ -216,7 +216,7 @@ - + diff --git a/src/Ext/Rules/Body.cpp b/src/Ext/Rules/Body.cpp index cd0cda2db8..b78731bb52 100644 --- a/src/Ext/Rules/Body.cpp +++ b/src/Ext/Rules/Body.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include std::unique_ptr RulesExt::Data = nullptr; @@ -35,7 +35,7 @@ void RulesExt::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI) ShieldTypeClass::LoadFromINIList(pINI); LaserTrailTypeClass::LoadFromINIList(&CCINIClass::INI_Art.get()); AttachEffectTypeClass::LoadFromINIList(pINI); - HealthBarTypeClass::LoadFromINIList(pINI); + BarTypeClass::LoadFromINIList(pINI); Data->LoadBeforeTypeData(pThis, pINI); } diff --git a/src/Ext/Techno/Body.Visuals.cpp b/src/Ext/Techno/Body.Visuals.cpp index 4b959b1f37..a017906be0 100644 --- a/src/Ext/Techno/Body.Visuals.cpp +++ b/src/Ext/Techno/Body.Visuals.cpp @@ -469,3 +469,62 @@ void TechnoExt::GetValuesForDisplay(TechnoClass* pThis, DisplayInfoType infoType } } } + +void TechnoExt::DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLocation, RectangleStruct* pBounds, double barPercentage, double yellowCond, double redCond) +{ + const BlitterFlags blitFlagsBG = barType->BoardBG_Translucency.Get(0); + const BlitterFlags blitFlagsFG = barType->BoardFG_Translucency.Get(0); + const Point2D sectionOffset = barType->Sections_PositionDelta; + const Vector3D 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; + + if (barPercentage > yellowCond) + frameIdxa = sectionFrames.X; + else if (barPercentage > redCond) + frameIdxa = sectionFrames.Y; + + pLocation += barType->Bar_Offset; + Point2D boardPosition = pLocation + barType->Board_Offset; + + if(barType->BoardBG_File && (pThis->IsSelected || barType->BoardBG_ShowWhenNotSelected)) + DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, barType->BoardBG_File.Get(), + 0, &boardPosition, pBounds, BlitterFlags(0xE00) | blitFlagsBG, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + + Point2D position = pLocation; + position.X += drawBackwards ? (int)round(sectionAmount * sectionOffset.X / 2) : -(int)round(sectionAmount * sectionOffset.X / 2); + position.Y += drawBackwards ? (int)round(sectionAmount * sectionOffset.Y / 2) : -(int)round(sectionAmount * sectionOffset.Y / 2); + + if(sectionEmptyFrame != -1) + { + for(int i = 0; i < sectionAmount; ++i) + { + position += drawBackwards ? -sectionOffset : sectionOffset; + DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, FileSystem::PIPS_SHP(), + sectionEmptyFrame, &position, pBounds, BlitterFlags(0x600), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + } + + position = pLocation; + position.X += drawBackwards ? (int)round(sectionAmount * sectionOffset.X / 2) : -(int)round(sectionAmount * sectionOffset.X / 2); + position.Y += drawBackwards ? (int)round(sectionAmount * sectionOffset.Y / 2) : -(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 += drawBackwards ? -sectionOffset : sectionOffset; + DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, FileSystem::PIPS_SHP(), + frameIdxa, &position, pBounds, BlitterFlags(0x600), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + } + + if(barType->BoardFG_File && (pThis->IsSelected || barType->BoardFG_ShowWhenNotSelected)) + DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, barType->BoardFG_File.Get(), + 0, &boardPosition, pBounds, BlitterFlags(0xE00) | blitFlagsFG, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); +} diff --git a/src/Ext/Techno/Body.h b/src/Ext/Techno/Body.h index 0a90b4f688..f2c6f75ca5 100644 --- a/src/Ext/Techno/Body.h +++ b/src/Ext/Techno/Body.h @@ -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 yellowCond, double redCond); // WeaponHelpers.cpp static int PickWeaponIndex(TechnoClass* pThis, TechnoClass* pTargetTechno, AbstractClass* pTarget, int weaponIndexOne, int weaponIndexTwo, bool allowFallback = true, bool allowAAFallback = true); diff --git a/src/Ext/Techno/Hooks.Pips.cpp b/src/Ext/Techno/Hooks.Pips.cpp index 4d97e89491..ee4d453d04 100644 --- a/src/Ext/Techno/Hooks.Pips.cpp +++ b/src/Ext/Techno/Hooks.Pips.cpp @@ -285,7 +285,7 @@ DEFINE_HOOK(0x6F64C1, TechnoClass_DrawHealthBar_BuildingHealthBar, 0xA) const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType()); - if(pThis->WhatAmI() == AbstractType::Building && pTypeExt->CustomHealthBarType) + if(pThis->WhatAmI() == AbstractType::Building && pTypeExt->HealthBar_BarType) return Skip; return Continue; @@ -301,7 +301,7 @@ DEFINE_HOOK(0x6F6846, TechnoClass_DrawHealthBar_CustomHealthBar, 0x6) bool pThisIsInf = pThis->WhatAmI() == AbstractType::Infantry; - if(!pTypeExt->CustomHealthBarType) + if(!pTypeExt->HealthBar_BarType) { R->AL(pThis->IsSelected); if(pThisIsInf) @@ -309,60 +309,17 @@ DEFINE_HOOK(0x6F6846, TechnoClass_DrawHealthBar_CustomHealthBar, 0x6) return Continue; } - const auto thisHBType = pTypeExt->CustomHealthBarType.Get(); - const auto pipBoardBG = thisHBType->Frame_Background.Get(FileSystem::PIPBRD_SHP()); - const bool pipBoardBGVisibility = thisHBType->Frame_Background_ShowWhenNotSelected.Get(); - const BlitterFlags blitFlags = thisHBType->Frame_Background_Translucency.Get(0); - const auto pipBoardFG = thisHBType->Frame_Foreground.Get(); - const bool pipBoardFGVisibility = thisHBType->Frame_Foreground_ShowWhenNotSelected.Get(); - const int pipsOffset = thisHBType->HealthBar_XOffset.Get(); - const Vector3D pipsFrames = thisHBType->Sections_Pips.Get(); - const int pipsAmount = thisHBType->Sections_Amount.Get(); - const int pipsSize = thisHBType->Sections_Size.Get(); - - int top_adjust = pThisIsInf ? -25 : -26; - int left_adjust = pipsAmount * pipsSize / 2 - pipsSize; - left_adjust = (pipsAmount % 2 == 0) ? left_adjust - 1 : left_adjust; - int border_adjust = (pipsAmount % 2 == 0) ? 1 : 0; - Point2D position; + const auto thisHBType = pTypeExt->HealthBar_BarType.Get(); - if(pThis->WhatAmI() == AbstractType::Building) - top_adjust -= static_cast(pThis)->Type->Height * Unsorted::CellHeightInPixels / 2; - - if(pThis->IsSelected || pipBoardBGVisibility) - { - position.X = pLocation->X + 1 + border_adjust + pipsOffset; - position.Y = pThis->GetTechnoType()->PixelSelectionBracketDelta + pLocation->Y + top_adjust; - DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, pipBoardBG, - 0, &position, pBound, BlitterFlags(0xE00) | blitFlags, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); - } - - double health = pThis->GetHealthPercentage(); - int frameIdxa = pipsFrames.Z; - - if (health > RulesClass::Instance->ConditionYellow) - frameIdxa = pipsFrames.X; - else if (health > RulesClass::Instance->ConditionRed) - frameIdxa = pipsFrames.Y; - - int pipsNeeded = (int)round(health * pipsAmount); - pipsNeeded = pipsNeeded <= 0 ? 1 : pipsNeeded; + Point2D position = *pLocation; - for(int i = 0; i < pipsNeeded; ++i) - { - position.X = pLocation->X - left_adjust + pipsOffset + pipsSize * i; - position.Y = pThis->GetTechnoType()->PixelSelectionBracketDelta + pLocation->Y + top_adjust + 1; - DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, FileSystem::PIPS_SHP(), - frameIdxa, &position, pBound, BlitterFlags(0x600), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); - } + if(pThis->WhatAmI() == AbstractType::Building) + position.Y -= (static_cast(pThis)->Type->Height + 1) * Unsorted::CellHeightInPixels / 2; + else + position.Y -= pThisIsInf ? 25 : 26; - if(pipBoardFG && (pThis->IsSelected || pipBoardFGVisibility)) - { - position.X = pLocation->X + 1 + border_adjust + pipsOffset; - position.Y = pThis->GetTechnoType()->PixelSelectionBracketDelta + pLocation->Y + top_adjust; - DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, pipBoardFG, - 0, &position, pBound, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); - } + position.Y += pThis->GetTechnoType()->PixelSelectionBracketDelta; + TechnoExt::DrawBar(pThis, thisHBType, position, pBound, pThis->GetHealthPercentage(), RulesClass::Instance->ConditionYellow, RulesClass::Instance->ConditionRed); R->EDI(pLocation); return Skip; diff --git a/src/Ext/TechnoType/Body.cpp b/src/Ext/TechnoType/Body.cpp index 13d7ed94dc..fd51a1f946 100644 --- a/src/Ext/TechnoType/Body.cpp +++ b/src/Ext/TechnoType/Body.cpp @@ -319,7 +319,7 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) this->Wake_Grapple.Read(exINI, pSection, "Wake.Grapple"); this->Wake_Sinking.Read(exINI, pSection, "Wake.Sinking"); - this->CustomHealthBarType.Read(exINI, pSection, "CustomHealthBarType"); + this->HealthBar_BarType.Read(exINI, pSection, "HealthBar.BarType"); // Ares 0.2 this->RadarJamRadius.Read(exINI, pSection, "RadarJamRadius"); @@ -691,7 +691,7 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm) .Process(this->Wake_Grapple) .Process(this->Wake_Sinking) - .Process(this->CustomHealthBarType) + .Process(this->HealthBar_BarType) ; } void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm) diff --git a/src/Ext/TechnoType/Body.h b/src/Ext/TechnoType/Body.h index 7b40c39037..35d97e1624 100644 --- a/src/Ext/TechnoType/Body.h +++ b/src/Ext/TechnoType/Body.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include class Matrix3D; @@ -234,7 +234,7 @@ class TechnoTypeExt Nullable Wake_Grapple; Nullable Wake_Sinking; - Valueable CustomHealthBarType; + Valueable HealthBar_BarType; struct LaserTrailDataEntry { @@ -465,7 +465,7 @@ class TechnoTypeExt , Wake_Grapple { } , Wake_Sinking { } - , CustomHealthBarType {} + , HealthBar_BarType {} { } virtual ~ExtData() = default; diff --git a/src/New/Type/BarTypeClass.cpp b/src/New/Type/BarTypeClass.cpp new file mode 100644 index 0000000000..5e4f35da9a --- /dev/null +++ b/src/New/Type/BarTypeClass.cpp @@ -0,0 +1,64 @@ +#include "BarTypeClass.h" + +#include +#include + +#include + +template<> +const char* Enumerable::GetMainSection() +{ + return "BarTypes"; +} + +void BarTypeClass::LoadFromINI(CCINIClass* pINI) +{ + const char* section = this->Name; + + INI_EX exINI(pINI); + + this->BoardBG_File.Read(exINI, section, "BoardBG.File"); + this->BoardBG_ShowWhenNotSelected.Read(exINI, section, "BoardBG.ShowWhenNotSelected"); + this->BoardBG_Translucency.Read(exINI, section, "BoardBG.Translucency"); + this->BoardFG_File.Read(exINI, section, "BoardFG.File"); + this->BoardFG_ShowWhenNotSelected.Read(exINI, section, "BoardFG.ShowWhenNotSelected"); + this->BoardFG_Translucency.Read(exINI, section, "BoardFG.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.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 +void BarTypeClass::Serialize(T& Stm) +{ + Stm + .Process(this->BoardBG_File) + .Process(this->BoardBG_ShowWhenNotSelected) + .Process(this->BoardBG_Translucency) + .Process(this->BoardFG_File) + .Process(this->BoardFG_ShowWhenNotSelected) + .Process(this->BoardFG_Translucency) + .Process(this->Board_Offset) + .Process(this->Bar_Offset) + .Process(this->Sections_DrawBackwards) + .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); +} diff --git a/src/New/Type/BarTypeClass.h b/src/New/Type/BarTypeClass.h new file mode 100644 index 0000000000..e830efdd99 --- /dev/null +++ b/src/New/Type/BarTypeClass.h @@ -0,0 +1,48 @@ +#pragma once +#include +#include +#include +#include +#include + +class BarTypeClass final : public Enumerable +{ +public: + Nullable BoardBG_File; + Valueable BoardBG_ShowWhenNotSelected; + Nullable BoardBG_Translucency; + Nullable BoardFG_File; + Valueable BoardFG_ShowWhenNotSelected; + Nullable BoardFG_Translucency; + Valueable> Board_Offset; + Valueable> Bar_Offset; + Valueable Sections_DrawBackwards; + Valueable> Sections_Pips; + Valueable Sections_EmptyPip; + Valueable Sections_Amount; + Valueable> Sections_PositionDelta; + + BarTypeClass(const char* pTitle = NONE_STR) : Enumerable(pTitle) + , BoardBG_File { } + , BoardBG_ShowWhenNotSelected { false } + , BoardBG_Translucency { } + , BoardFG_File { } + , BoardFG_ShowWhenNotSelected { false } + , BoardFG_Translucency { } + , Board_Offset { { 0,0 } } + , Bar_Offset { { 0,0 } } + , Sections_DrawBackwards { false } + , 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 + void Serialize(T& Stm); +}; diff --git a/src/New/Type/HealthBarTypeClass.cpp b/src/New/Type/HealthBarTypeClass.cpp deleted file mode 100644 index 1c9e8cecbe..0000000000 --- a/src/New/Type/HealthBarTypeClass.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "HealthBarTypeClass.h" - -#include -#include - -#include - -template<> -const char* Enumerable::GetMainSection() -{ - return "HealthBarTypes"; -} - -void HealthBarTypeClass::LoadFromINI(CCINIClass* pINI) -{ - const char* section = this->Name; - - INI_EX exINI(pINI); - - this->Frame_Background.Read(exINI, section, "Frame.Background"); - this->Frame_Background_ShowWhenNotSelected.Read(exINI, section, "Frame.Background.ShowWhenNotSelected"); - this->Frame_Background_Translucency.Read(exINI, section, "Frame.Background.Translucency"); - this->Frame_Foreground.Read(exINI, section, "Frame.Foreground"); - this->Frame_Foreground_ShowWhenNotSelected.Read(exINI, section, "Frame.Foreground.ShowWhenNotSelected"); - this->HealthBar_XOffset.Read(exINI, section, "HealthBar.OffsetX"); - this->Sections_Pips.Read(exINI, section, "Sections.Pips"); - this->Sections_Amount.Read(exINI, section, "Sections.Amount"); - this->Sections_Size.Read(exINI, section, "Sections.Size"); - -} - -template -void HealthBarTypeClass::Serialize(T& Stm) -{ - Stm - .Process(this->Frame_Background) - .Process(this->Frame_Background_ShowWhenNotSelected) - .Process(this->Frame_Background_Translucency) - .Process(this->Frame_Foreground) - .Process(this->Frame_Foreground_ShowWhenNotSelected) - .Process(this->HealthBar_XOffset) - .Process(this->Sections_Pips) - .Process(this->Sections_Amount) - .Process(this->Sections_Size) - ; -} - -void HealthBarTypeClass::LoadFromStream(PhobosStreamReader& Stm) -{ - this->Serialize(Stm); -} - -void HealthBarTypeClass::SaveToStream(PhobosStreamWriter& Stm) -{ - this->Serialize(Stm); -} diff --git a/src/New/Type/HealthBarTypeClass.h b/src/New/Type/HealthBarTypeClass.h deleted file mode 100644 index d6af051b43..0000000000 --- a/src/New/Type/HealthBarTypeClass.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -class HealthBarTypeClass final : public Enumerable -{ -public: - Nullable Frame_Background; - Valueable Frame_Background_ShowWhenNotSelected; - Nullable Frame_Background_Translucency; - Nullable Frame_Foreground; - Valueable Frame_Foreground_ShowWhenNotSelected; - Valueable HealthBar_XOffset; - Valueable> Sections_Pips; - Valueable Sections_Amount; - Valueable Sections_Size; - - HealthBarTypeClass(const char* pTitle = NONE_STR) : Enumerable(pTitle) - , Frame_Background { } - , Frame_Background_ShowWhenNotSelected { false } - , Frame_Background_Translucency { } - , Frame_Foreground { } - , Frame_Foreground_ShowWhenNotSelected { false } - , HealthBar_XOffset { 0 } - , Sections_Pips { { 16,17,18 } } - , Sections_Amount { 17 } - , Sections_Size { 2 } - { } - - void LoadFromINI(CCINIClass* pINI); - void LoadFromStream(PhobosStreamReader& Stm); - void SaveToStream(PhobosStreamWriter& Stm); - -private: - template - void Serialize(T& Stm); -}; diff --git a/src/Phobos.Ext.cpp b/src/Phobos.Ext.cpp index 6621d98ff7..0ebdb3e3a2 100644 --- a/src/Phobos.Ext.cpp +++ b/src/Phobos.Ext.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include @@ -231,7 +231,7 @@ using PhobosTypeRegistry = TypeRegistry< DigitalDisplayTypeClass, AttachEffectTypeClass, AttachEffectClass, - HealthBarTypeClass + BarTypeClass // other classes >; From 89c0cfbf0755550e029fe97ef092dede455a757d Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 16 Nov 2024 18:13:48 +0300 Subject: [PATCH 03/14] Update src/Ext/Techno/Body.Visuals.cpp Co-authored-by: Kerbiter --- src/Ext/Techno/Body.Visuals.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ext/Techno/Body.Visuals.cpp b/src/Ext/Techno/Body.Visuals.cpp index a017906be0..d5e7e5661f 100644 --- a/src/Ext/Techno/Body.Visuals.cpp +++ b/src/Ext/Techno/Body.Visuals.cpp @@ -499,9 +499,9 @@ void TechnoExt::DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLoca position.X += drawBackwards ? (int)round(sectionAmount * sectionOffset.X / 2) : -(int)round(sectionAmount * sectionOffset.X / 2); position.Y += drawBackwards ? (int)round(sectionAmount * sectionOffset.Y / 2) : -(int)round(sectionAmount * sectionOffset.Y / 2); - if(sectionEmptyFrame != -1) + if (sectionEmptyFrame != -1) { - for(int i = 0; i < sectionAmount; ++i) + for (int i = 0; i < sectionAmount; ++i) { position += drawBackwards ? -sectionOffset : sectionOffset; DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, FileSystem::PIPS_SHP(), From da0e53d4edee2047fc261a4f1e7220161fa25928 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 16 Nov 2024 18:14:05 +0300 Subject: [PATCH 04/14] Update src/Ext/Techno/Body.Visuals.cpp Co-authored-by: Kerbiter --- src/Ext/Techno/Body.Visuals.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Ext/Techno/Body.Visuals.cpp b/src/Ext/Techno/Body.Visuals.cpp index d5e7e5661f..44478438b9 100644 --- a/src/Ext/Techno/Body.Visuals.cpp +++ b/src/Ext/Techno/Body.Visuals.cpp @@ -513,9 +513,11 @@ void TechnoExt::DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLoca position.Y += drawBackwards ? (int)round(sectionAmount * sectionOffset.Y / 2) : -(int)round(sectionAmount * sectionOffset.Y / 2); } - if(drawBackwards) - for(int i = 0; i < (sectionAmount - sectionsToDraw); ++i) + if (drawBackwards) + { + for (int i = 0; i < (sectionAmount - sectionsToDraw); ++i) position -= sectionOffset; + } for(int i = 0; i < sectionsToDraw; ++i) { From df0c9a0867c511a2b3ecd563d0be28baa41349dc Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 16 Nov 2024 18:14:24 +0300 Subject: [PATCH 05/14] Update src/Ext/Techno/Hooks.Pips.cpp Co-authored-by: Kerbiter --- src/Ext/Techno/Hooks.Pips.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ext/Techno/Hooks.Pips.cpp b/src/Ext/Techno/Hooks.Pips.cpp index ee4d453d04..b5b4efbb0c 100644 --- a/src/Ext/Techno/Hooks.Pips.cpp +++ b/src/Ext/Techno/Hooks.Pips.cpp @@ -304,7 +304,7 @@ DEFINE_HOOK(0x6F6846, TechnoClass_DrawHealthBar_CustomHealthBar, 0x6) if(!pTypeExt->HealthBar_BarType) { R->AL(pThis->IsSelected); - if(pThisIsInf) + if (pThisIsInf) return ContinueInf; return Continue; } From 4dd8b3480529f663c5b8fb444d5c9b0e6a755b13 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 16 Nov 2024 18:14:44 +0300 Subject: [PATCH 06/14] Update src/Ext/Techno/Hooks.Pips.cpp Co-authored-by: Kerbiter --- src/Ext/Techno/Hooks.Pips.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ext/Techno/Hooks.Pips.cpp b/src/Ext/Techno/Hooks.Pips.cpp index b5b4efbb0c..991916d578 100644 --- a/src/Ext/Techno/Hooks.Pips.cpp +++ b/src/Ext/Techno/Hooks.Pips.cpp @@ -301,7 +301,7 @@ DEFINE_HOOK(0x6F6846, TechnoClass_DrawHealthBar_CustomHealthBar, 0x6) bool pThisIsInf = pThis->WhatAmI() == AbstractType::Infantry; - if(!pTypeExt->HealthBar_BarType) + if (!pTypeExt->HealthBar_BarType) { R->AL(pThis->IsSelected); if (pThisIsInf) From 39b2679538b619bfc9776ff7af1da94de5a5a427 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 16 Nov 2024 18:15:06 +0300 Subject: [PATCH 07/14] Update src/Ext/Techno/Body.Visuals.cpp Co-authored-by: Kerbiter --- src/Ext/Techno/Body.Visuals.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ext/Techno/Body.Visuals.cpp b/src/Ext/Techno/Body.Visuals.cpp index 44478438b9..16a9e3cee3 100644 --- a/src/Ext/Techno/Body.Visuals.cpp +++ b/src/Ext/Techno/Body.Visuals.cpp @@ -526,7 +526,7 @@ void TechnoExt::DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLoca frameIdxa, &position, pBounds, BlitterFlags(0x600), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); } - if(barType->BoardFG_File && (pThis->IsSelected || barType->BoardFG_ShowWhenNotSelected)) + if (barType->BoardFG_File && (pThis->IsSelected || barType->BoardFG_ShowWhenNotSelected)) DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, barType->BoardFG_File.Get(), 0, &boardPosition, pBounds, BlitterFlags(0xE00) | blitFlagsFG, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); } From 6e75804bcdd1650af7c650ffd50877ded236471c Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 16 Nov 2024 18:15:31 +0300 Subject: [PATCH 08/14] Update src/New/Type/BarTypeClass.h Co-authored-by: Kerbiter --- src/New/Type/BarTypeClass.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/New/Type/BarTypeClass.h b/src/New/Type/BarTypeClass.h index e830efdd99..731ab17f0b 100644 --- a/src/New/Type/BarTypeClass.h +++ b/src/New/Type/BarTypeClass.h @@ -29,13 +29,13 @@ class BarTypeClass final : public Enumerable , BoardFG_File { } , BoardFG_ShowWhenNotSelected { false } , BoardFG_Translucency { } - , Board_Offset { { 0,0 } } - , Bar_Offset { { 0,0 } } + , Board_Offset { { 0, 0 } } + , Bar_Offset { { 0, 0 } } , Sections_DrawBackwards { false } - , Sections_Pips { { 16,17,18 } } + , Sections_Pips { { 16, 17, 18 } } , Sections_EmptyPip { -1 } , Sections_Amount { 17 } - , Sections_PositionDelta { { 2,0 } } + , Sections_PositionDelta { { 2, 0 } } { } void LoadFromINI(CCINIClass* pINI); From 496f884276e56c9b619c8ab4efc79d261bcf7137 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 16 Nov 2024 18:15:53 +0300 Subject: [PATCH 09/14] Update src/Ext/Techno/Body.Visuals.cpp Co-authored-by: Kerbiter --- src/Ext/Techno/Body.Visuals.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ext/Techno/Body.Visuals.cpp b/src/Ext/Techno/Body.Visuals.cpp index 16a9e3cee3..6447964683 100644 --- a/src/Ext/Techno/Body.Visuals.cpp +++ b/src/Ext/Techno/Body.Visuals.cpp @@ -519,7 +519,7 @@ void TechnoExt::DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLoca position -= sectionOffset; } - for(int i = 0; i < sectionsToDraw; ++i) + for (int i = 0; i < sectionsToDraw; ++i) { position += drawBackwards ? -sectionOffset : sectionOffset; DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, FileSystem::PIPS_SHP(), From d41b3c109023667834f029d182c5dc4f5695eb5b Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 16 Nov 2024 18:16:27 +0300 Subject: [PATCH 10/14] Update src/Ext/Techno/Hooks.Pips.cpp Co-authored-by: Kerbiter --- src/Ext/Techno/Hooks.Pips.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Ext/Techno/Hooks.Pips.cpp b/src/Ext/Techno/Hooks.Pips.cpp index 991916d578..1a0b008dca 100644 --- a/src/Ext/Techno/Hooks.Pips.cpp +++ b/src/Ext/Techno/Hooks.Pips.cpp @@ -294,6 +294,7 @@ DEFINE_HOOK(0x6F64C1, TechnoClass_DrawHealthBar_BuildingHealthBar, 0xA) DEFINE_HOOK(0x6F6846, TechnoClass_DrawHealthBar_CustomHealthBar, 0x6) { enum { Continue = 0x6F68E8, ContinueInf = 0x6F6852, Skip = 0x6F6A58 }; + GET(TechnoClass*, pThis, ESI); GET_STACK(Point2D*, pLocation, STACK_OFFSET(0x4C, 0x4)); GET_STACK(RectangleStruct*, pBound, STACK_OFFSET(0x4C, 0x8)); From 1519333fe8f56b764bdb0a49ae1dd799e52139b8 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 16 Nov 2024 18:16:50 +0300 Subject: [PATCH 11/14] Update src/Ext/Techno/Hooks.Pips.cpp Co-authored-by: Kerbiter --- src/Ext/Techno/Hooks.Pips.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Ext/Techno/Hooks.Pips.cpp b/src/Ext/Techno/Hooks.Pips.cpp index 1a0b008dca..03ed63207b 100644 --- a/src/Ext/Techno/Hooks.Pips.cpp +++ b/src/Ext/Techno/Hooks.Pips.cpp @@ -279,6 +279,7 @@ DEFINE_HOOK(0x70A4FB, TechnoClass_DrawPips_SelfHealGain, 0x5) DEFINE_HOOK(0x6F64C1, TechnoClass_DrawHealthBar_BuildingHealthBar, 0xA) { enum { Continue = 0x6F64CB, Skip = 0x6F683C }; + GET(TechnoClass*, pThis, ESI); R->EAX(pThis->GetTechnoType()); From 7cd1aae9430bfc3b7a0b782609de70ceadc5fe09 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 16 Nov 2024 18:17:04 +0300 Subject: [PATCH 12/14] Update src/Ext/Techno/Hooks.Pips.cpp Co-authored-by: Kerbiter --- src/Ext/Techno/Hooks.Pips.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ext/Techno/Hooks.Pips.cpp b/src/Ext/Techno/Hooks.Pips.cpp index 03ed63207b..6c20d396b7 100644 --- a/src/Ext/Techno/Hooks.Pips.cpp +++ b/src/Ext/Techno/Hooks.Pips.cpp @@ -286,7 +286,7 @@ DEFINE_HOOK(0x6F64C1, TechnoClass_DrawHealthBar_BuildingHealthBar, 0xA) const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType()); - if(pThis->WhatAmI() == AbstractType::Building && pTypeExt->HealthBar_BarType) + if (pThis->WhatAmI() == AbstractType::Building && pTypeExt->HealthBar_BarType) return Skip; return Continue; From 35111afa1387422c06f3f21e90b899b8ff9906bf Mon Sep 17 00:00:00 2001 From: Fryone Date: Sun, 17 Nov 2024 20:59:35 +0300 Subject: [PATCH 13/14] Rework 1 - hook refactor - Healthbar.Hide moved to healthbar hook - applied some suggested changes - added ability to choose file for bar pips - added ShieldBar.BarType TO DO: - for now, ShieldBar.BarType dont work without HealthBar.BarType --- src/Ext/Techno/Body.Visuals.cpp | 35 +++++++++--------- src/Ext/Techno/Body.h | 2 +- src/Ext/Techno/Hooks.Pips.cpp | 63 +++++++++++++++++---------------- src/Ext/TechnoType/Body.cpp | 2 ++ src/Ext/TechnoType/Body.h | 6 ++-- src/Ext/TechnoType/Hooks.cpp | 10 ------ src/New/Type/BarTypeClass.cpp | 26 +++++++------- src/New/Type/BarTypeClass.h | 26 +++++++------- 8 files changed, 85 insertions(+), 85 deletions(-) diff --git a/src/Ext/Techno/Body.Visuals.cpp b/src/Ext/Techno/Body.Visuals.cpp index 6447964683..6764135f99 100644 --- a/src/Ext/Techno/Body.Visuals.cpp +++ b/src/Ext/Techno/Body.Visuals.cpp @@ -470,10 +470,10 @@ void TechnoExt::GetValuesForDisplay(TechnoClass* pThis, DisplayInfoType infoType } } -void TechnoExt::DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLocation, RectangleStruct* pBounds, double barPercentage, double yellowCond, double redCond) +void TechnoExt::DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLocation, RectangleStruct* pBounds, double barPercentage, double conditionYellow, double conditionRed) { - const BlitterFlags blitFlagsBG = barType->BoardBG_Translucency.Get(0); - const BlitterFlags blitFlagsFG = barType->BoardFG_Translucency.Get(0); + 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 sectionFrames = barType->Sections_Pips; const int sectionAmount = barType->Sections_Amount; @@ -482,35 +482,34 @@ void TechnoExt::DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLoca int sectionsToDraw = (int)round(sectionAmount * barPercentage); sectionsToDraw = sectionsToDraw == 0 ? 1 : sectionsToDraw; int frameIdxa = sectionFrames.Z; + int sign = drawBackwards ? 1 : -1; - if (barPercentage > yellowCond) + if (barPercentage > conditionYellow) frameIdxa = sectionFrames.X; - else if (barPercentage > redCond) + else if (barPercentage > conditionRed) frameIdxa = sectionFrames.Y; pLocation += barType->Bar_Offset; Point2D boardPosition = pLocation + barType->Board_Offset; - if(barType->BoardBG_File && (pThis->IsSelected || barType->BoardBG_ShowWhenNotSelected)) - DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, barType->BoardBG_File.Get(), + 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.X += drawBackwards ? (int)round(sectionAmount * sectionOffset.X / 2) : -(int)round(sectionAmount * sectionOffset.X / 2); - position.Y += drawBackwards ? (int)round(sectionAmount * sectionOffset.Y / 2) : -(int)round(sectionAmount * sectionOffset.Y / 2); + 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 += drawBackwards ? -sectionOffset : sectionOffset; - DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, FileSystem::PIPS_SHP(), + 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); } position = pLocation; - position.X += drawBackwards ? (int)round(sectionAmount * sectionOffset.X / 2) : -(int)round(sectionAmount * sectionOffset.X / 2); - position.Y += drawBackwards ? (int)round(sectionAmount * sectionOffset.Y / 2) : -(int)round(sectionAmount * sectionOffset.Y / 2); + position += {sign * (int)round(sectionAmount * sectionOffset.X / 2), sign * (int)round(sectionAmount * sectionOffset.Y / 2)}; } if (drawBackwards) @@ -521,12 +520,12 @@ void TechnoExt::DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLoca for (int i = 0; i < sectionsToDraw; ++i) { - position += drawBackwards ? -sectionOffset : sectionOffset; - DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, FileSystem::PIPS_SHP(), + 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); } - if (barType->BoardFG_File && (pThis->IsSelected || barType->BoardFG_ShowWhenNotSelected)) - DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, barType->BoardFG_File.Get(), - 0, &boardPosition, pBounds, BlitterFlags(0xE00) | blitFlagsFG, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + 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); } diff --git a/src/Ext/Techno/Body.h b/src/Ext/Techno/Body.h index f2c6f75ca5..0f1ed4985b 100644 --- a/src/Ext/Techno/Body.h +++ b/src/Ext/Techno/Body.h @@ -168,7 +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 yellowCond, double redCond); + 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); diff --git a/src/Ext/Techno/Hooks.Pips.cpp b/src/Ext/Techno/Hooks.Pips.cpp index 6c20d396b7..1fee426744 100644 --- a/src/Ext/Techno/Hooks.Pips.cpp +++ b/src/Ext/Techno/Hooks.Pips.cpp @@ -276,53 +276,56 @@ DEFINE_HOOK(0x70A4FB, TechnoClass_DrawPips_SelfHealGain, 0x5) return SkipGameDrawing; } -DEFINE_HOOK(0x6F64C1, TechnoClass_DrawHealthBar_BuildingHealthBar, 0xA) +DEFINE_HOOK(0x6F64A9, TechnoClass_DrawHealthBar_HealthAndShieldBar, 0x5) { - enum { Continue = 0x6F64CB, Skip = 0x6F683C }; + enum { Skip = 0x6F6AB6 }; - GET(TechnoClass*, pThis, ESI); - - R->EAX(pThis->GetTechnoType()); - - const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType()); - - if (pThis->WhatAmI() == AbstractType::Building && pTypeExt->HealthBar_BarType) - return Skip; - - return Continue; -} - -DEFINE_HOOK(0x6F6846, TechnoClass_DrawHealthBar_CustomHealthBar, 0x6) -{ - enum { Continue = 0x6F68E8, ContinueInf = 0x6F6852, Skip = 0x6F6A58 }; - - GET(TechnoClass*, pThis, ESI); + 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()); - bool pThisIsInf = pThis->WhatAmI() == AbstractType::Infantry; + if (pTypeExt && pTypeExt->HealthBar_Hide) + return Skip; if (!pTypeExt->HealthBar_BarType) - { - R->AL(pThis->IsSelected); - if (pThisIsInf) - return ContinueInf; - return Continue; - } + 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(pThis->WhatAmI() == AbstractType::Building) + if (pThisIsBld) + { position.Y -= (static_cast(pThis)->Type->Height + 1) * Unsorted::CellHeightInPixels / 2; + const int pThisBldTypeWidth = static_cast(pThis)->Type->GetFoundationWidth(); + length = pThisBldTypeWidth * 7 + (pThisBldTypeWidth / 2); + } else + { position.Y -= pThisIsInf ? 25 : 26; + position.Y += pThis->GetTechnoType()->PixelSelectionBracketDelta; + } - 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); - R->EDI(pLocation); return Skip; } diff --git a/src/Ext/TechnoType/Body.cpp b/src/Ext/TechnoType/Body.cpp index fd51a1f946..7d3872eba7 100644 --- a/src/Ext/TechnoType/Body.cpp +++ b/src/Ext/TechnoType/Body.cpp @@ -320,6 +320,7 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) 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"); @@ -692,6 +693,7 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm) .Process(this->Wake_Sinking) .Process(this->HealthBar_BarType) + .Process(this->ShieldBar_BarType) ; } void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm) diff --git a/src/Ext/TechnoType/Body.h b/src/Ext/TechnoType/Body.h index 35d97e1624..8c9a7d936a 100644 --- a/src/Ext/TechnoType/Body.h +++ b/src/Ext/TechnoType/Body.h @@ -234,7 +234,8 @@ class TechnoTypeExt Nullable Wake_Grapple; Nullable Wake_Sinking; - Valueable HealthBar_BarType; + Nullable HealthBar_BarType; + Nullable ShieldBar_BarType; struct LaserTrailDataEntry { @@ -465,7 +466,8 @@ class TechnoTypeExt , Wake_Grapple { } , Wake_Sinking { } - , HealthBar_BarType {} + , HealthBar_BarType { } + , ShieldBar_BarType { } { } virtual ~ExtData() = default; diff --git a/src/Ext/TechnoType/Hooks.cpp b/src/Ext/TechnoType/Hooks.cpp index 9b5f52a0b4..324ae521ea 100644 --- a/src/Ext/TechnoType/Hooks.cpp +++ b/src/Ext/TechnoType/Hooks.cpp @@ -23,16 +23,6 @@ #include #include -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)); diff --git a/src/New/Type/BarTypeClass.cpp b/src/New/Type/BarTypeClass.cpp index 5e4f35da9a..e0d27a595e 100644 --- a/src/New/Type/BarTypeClass.cpp +++ b/src/New/Type/BarTypeClass.cpp @@ -17,15 +17,16 @@ void BarTypeClass::LoadFromINI(CCINIClass* pINI) INI_EX exINI(pINI); - this->BoardBG_File.Read(exINI, section, "BoardBG.File"); - this->BoardBG_ShowWhenNotSelected.Read(exINI, section, "BoardBG.ShowWhenNotSelected"); - this->BoardBG_Translucency.Read(exINI, section, "BoardBG.Translucency"); - this->BoardFG_File.Read(exINI, section, "BoardFG.File"); - this->BoardFG_ShowWhenNotSelected.Read(exINI, section, "BoardFG.ShowWhenNotSelected"); - this->BoardFG_Translucency.Read(exINI, section, "BoardFG.Translucency"); + 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"); @@ -37,15 +38,16 @@ template void BarTypeClass::Serialize(T& Stm) { Stm - .Process(this->BoardBG_File) - .Process(this->BoardBG_ShowWhenNotSelected) - .Process(this->BoardBG_Translucency) - .Process(this->BoardFG_File) - .Process(this->BoardFG_ShowWhenNotSelected) - .Process(this->BoardFG_Translucency) + .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) diff --git a/src/New/Type/BarTypeClass.h b/src/New/Type/BarTypeClass.h index 731ab17f0b..3705305420 100644 --- a/src/New/Type/BarTypeClass.h +++ b/src/New/Type/BarTypeClass.h @@ -8,30 +8,32 @@ class BarTypeClass final : public Enumerable { public: - Nullable BoardBG_File; - Valueable BoardBG_ShowWhenNotSelected; - Nullable BoardBG_Translucency; - Nullable BoardFG_File; - Valueable BoardFG_ShowWhenNotSelected; - Nullable BoardFG_Translucency; + Nullable Board_Background_File; + Valueable Board_Background_ShowWhenNotSelected; + Nullable Board_Background_Translucency; + Nullable Board_Foreground_File; + Valueable Board_Foreground_ShowWhenNotSelected; + Nullable Board_Foreground_Translucency; Valueable> Board_Offset; Valueable> Bar_Offset; Valueable Sections_DrawBackwards; + Valueable Sections_Pips_File; Valueable> Sections_Pips; Valueable Sections_EmptyPip; Valueable Sections_Amount; Valueable> Sections_PositionDelta; BarTypeClass(const char* pTitle = NONE_STR) : Enumerable(pTitle) - , BoardBG_File { } - , BoardBG_ShowWhenNotSelected { false } - , BoardBG_Translucency { } - , BoardFG_File { } - , BoardFG_ShowWhenNotSelected { false } - , BoardFG_Translucency { } + , 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 } From f169caa74238950dd35a325416617938e7d21bd6 Mon Sep 17 00:00:00 2001 From: Fryone Date: Sat, 7 Dec 2024 19:56:58 +0300 Subject: [PATCH 14/14] rework update - changed blitterflags - updated logic with latest hook movements - shield and health bars can be used separately --- src/Ext/Techno/Body.Visuals.cpp | 8 ++-- src/Ext/Techno/Hooks.Pips.cpp | 66 ++++++++++++++++++++++++--------- src/New/Entity/ShieldClass.cpp | 8 ++-- 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/src/Ext/Techno/Body.Visuals.cpp b/src/Ext/Techno/Body.Visuals.cpp index ba0d40463b..78e5d0f4ad 100644 --- a/src/Ext/Techno/Body.Visuals.cpp +++ b/src/Ext/Techno/Body.Visuals.cpp @@ -490,7 +490,7 @@ void TechnoExt::DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLoca 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); + 0, &boardPosition, pBounds, BlitterFlags::Centered | BlitterFlags::bf_400 | BlitterFlags::Alpha | 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)}; @@ -501,7 +501,7 @@ void TechnoExt::DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLoca { 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); + sectionEmptyFrame, &position, pBounds, BlitterFlags::Centered | BlitterFlags::bf_400, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); } position = pLocation; @@ -518,10 +518,10 @@ void TechnoExt::DrawBar(TechnoClass* pThis, BarTypeClass* barType, Point2D pLoca { 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); + frameIdxa, &position, pBounds, BlitterFlags::Centered | BlitterFlags::bf_400, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); } 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); + 0, &boardPosition, pBounds, BlitterFlags::Centered | BlitterFlags::bf_400 | BlitterFlags::Alpha | blitFlagsFG, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); } diff --git a/src/Ext/Techno/Hooks.Pips.cpp b/src/Ext/Techno/Hooks.Pips.cpp index b31d2baafa..6dab0028fe 100644 --- a/src/Ext/Techno/Hooks.Pips.cpp +++ b/src/Ext/Techno/Hooks.Pips.cpp @@ -3,7 +3,7 @@ #include #include "Body.h" -DEFINE_HOOK(0x6F64A9, TechnoClass_DrawHealthBar_Hide, 0x5) +/*DEFINE_HOOK(0x6F64A9, TechnoClass_DrawHealthBar_Hide, 0x5) { GET(TechnoClass*, pThis, ECX); auto pTypeData = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType()); @@ -11,7 +11,7 @@ DEFINE_HOOK(0x6F64A9, TechnoClass_DrawHealthBar_Hide, 0x5) return 0x6F6AB6; return 0; -} +}*/ DEFINE_HOOK(0x6F65D1, TechnoClass_DrawHealthBar_Buildings, 0x6) { @@ -26,7 +26,20 @@ DEFINE_HOOK(0x6F65D1, TechnoClass_DrawHealthBar_Buildings, 0x6) if (const auto pShieldData = pExt->Shield.get()) { if (pShieldData->IsAvailable() && !pShieldData->IsBrokenAndNonRespawning()) - pShieldData->DrawShieldBar_Building(length, pBound); + { + const auto thisSBType = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType())->ShieldBar_BarType.Get(); + + if (thisSBType) + { + Point2D position = *pLocation; + position.Y -= (pThis->Type->Height + 1) * Unsorted::CellHeightInPixels / 2; + TechnoExt::DrawBar(pThis, thisSBType, position, pBound, pShieldData->GetHealthRatio(), pShieldData->GetType()->GetConditionYellow(), pShieldData->GetType()->GetConditionRed()); + } + else + { + pShieldData->DrawShieldBar_Building(length, pBound); + } + } } TechnoExt::ProcessDigitalDisplays(pThis); @@ -47,8 +60,20 @@ DEFINE_HOOK(0x6F683C, TechnoClass_DrawHealthBar_Units, 0x7) { if (pShieldData->IsAvailable() && !pShieldData->IsBrokenAndNonRespawning()) { - const int length = pThis->WhatAmI() == AbstractType::Infantry ? 8 : 17; - pShieldData->DrawShieldBar_Other(length, pBound); + const auto thisSBType = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType())->ShieldBar_BarType.Get(); + + if (thisSBType) + { + Point2D position = *pLocation; + position.Y -= pThis->WhatAmI() == AbstractType::Infantry ? 25 : 26; + position.Y += pThis->GetTechnoType()->PixelSelectionBracketDelta + pShieldData->GetType()->BracketDelta; + TechnoExt::DrawBar(pThis, thisSBType, position, pBound, pShieldData->GetHealthRatio(), pShieldData->GetType()->GetConditionYellow(), pShieldData->GetType()->GetConditionRed()); + } + else + { + const int length = pThis->WhatAmI() == AbstractType::Infantry ? 8 : 17; + pShieldData->DrawShieldBar_Other(length, pBound); + } } } @@ -370,31 +395,38 @@ DEFINE_HOOK(0x6F64A9, TechnoClass_DrawHealthBar_HealthAndShieldBar, 0x5) 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(pThis)->Type->Height + 1) * Unsorted::CellHeightInPixels / 2; - const int pThisBldTypeWidth = static_cast(pThis)->Type->GetFoundationWidth(); - length = pThisBldTypeWidth * 7 + (pThisBldTypeWidth / 2); - } else - { - position.Y -= pThisIsInf ? 25 : 26; - position.Y += pThis->GetTechnoType()->PixelSelectionBracketDelta; - } + position.Y -= (pThisIsInf ? 25 : 26) - 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 (pShieldData->IsAvailable() && !pShieldData->IsBrokenAndNonRespawning()) { - if(thisSBType) + if (thisSBType) + { + position.Y += pShieldData->GetType()->BracketDelta; TechnoExt::DrawBar(pThis, thisSBType, position, pBound, pShieldData->GetHealthRatio(), pShieldData->GetType()->GetConditionYellow(), pShieldData->GetType()->GetConditionRed()); + } else - pShieldData->DrawShieldBar(length, pLocation, pBound); + { + if (pThisIsBld) + { + const short pThisBldTypeWidth = static_cast(pThis)->Type->GetFoundationWidth(); + const int length = pThisBldTypeWidth * 7 + (pThisBldTypeWidth / 2); + pShieldData->DrawShieldBar_Building(length, pBound); + } + else + { + const int length = pThisIsInf ? 8 : 17; + pShieldData->DrawShieldBar_Other(length, pBound); + } + } } } diff --git a/src/New/Entity/ShieldClass.cpp b/src/New/Entity/ShieldClass.cpp index e440f624b4..5d3de73e49 100644 --- a/src/New/Entity/ShieldClass.cpp +++ b/src/New/Entity/ShieldClass.cpp @@ -851,7 +851,7 @@ void ShieldClass::DrawShieldBar_Building(const int length, RectangleStruct* pBou position.Y -= deltaY + 3; DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, FileSystem::PIPS_SHP, - frame, &position, pBound, BlitterFlags(0x600), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + frame, &position, pBound, BlitterFlags::Centered | BlitterFlags::bf_400, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); } } @@ -868,7 +868,7 @@ void ShieldClass::DrawShieldBar_Building(const int length, RectangleStruct* pBou const int emptyFrame = this->Type->Pips_Building_Empty.Get(RulesExt::Global()->Pips_Shield_Building_Empty.Get(0)); DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, FileSystem::PIPS_SHP, - emptyFrame, &position, pBound, BlitterFlags(0x600), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + emptyFrame, &position, pBound, BlitterFlags::Centered | BlitterFlags::bf_400, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); } } } @@ -891,7 +891,7 @@ void ShieldClass::DrawShieldBar_Other(const int length, RectangleStruct* pBound) { position.X += length + 1 + (length == 8 ? length + 1 : 0); DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, pipBoard, - frame, &position, pBound, BlitterFlags(0xE00), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + frame, &position, pBound, BlitterFlags::Centered | BlitterFlags::bf_400 | BlitterFlags::Alpha, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); position.X -= length + 1 + (length == 8 ? length + 1 : 0); } @@ -903,7 +903,7 @@ void ShieldClass::DrawShieldBar_Other(const int length, RectangleStruct* pBound) { position.X += 2; DSurface::Temp->DrawSHP(FileSystem::PALETTE_PAL, FileSystem::PIPS_SHP, - frame, &position, pBound, BlitterFlags(0x600), 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); + frame, &position, pBound, BlitterFlags::Centered | BlitterFlags::bf_400, 0, 0, ZGradient::Ground, 1000, 0, 0, 0, 0, 0); } }