Implement CHudEnergyInterface

This commit is contained in:
Jack Andersen 2017-04-02 19:37:54 -10:00
parent a2b9bfb1a2
commit 67ed82bc52
10 changed files with 313 additions and 26 deletions

View File

@ -28,6 +28,10 @@ struct ITweakGui : ITweak
};
virtual float GetMapAlphaInterpolant() const=0;
virtual float GetEnergyBarFilledSpeed() const=0;
virtual float GetEnergyBarShadowSpeed() const=0;
virtual float GetEnergyBarDrainDelay() const=0;
virtual bool GetEnergyBarAlwaysResetDelay() const=0;
virtual atUint32 GetHudCamFovTweak() const=0;
virtual atUint32 GetHudCamYTweak() const=0;
virtual atUint32 GetHudCamZTweak() const=0;

View File

@ -7,16 +7,39 @@ namespace DataSpec
{
struct ITweakGuiColors : BigYAML
{
struct VisorEnergyInitColors
{
zeus::CColor tankFilled;
zeus::CColor tankEmpty;
zeus::CColor digitsFont;
zeus::CColor digitsOutline;
};
struct VisorEnergyBarColors
{
zeus::CColor filled;
zeus::CColor empty;
zeus::CColor shadow;
};
virtual zeus::CColor GetHudMessageFill() const=0;
virtual zeus::CColor GetHudMessageOutline() const=0;
virtual zeus::CColor GetHudFrameColor() const=0;
virtual zeus::CColor GetEnergyBarFilledLowEnergy() const=0;
virtual zeus::CColor GetEnergyBarShadowLowEnergy() const=0;
virtual zeus::CColor GetEnergyBarEmptyLowEnergy() const=0;
virtual zeus::CColor GetEnergyWarningFont() const=0;
virtual zeus::CColor GetTickDecoColor() const=0;
virtual zeus::CColor GetEnergyWarningOutline() const=0;
virtual zeus::CColor GetEnergyBarFlashColor() const=0;
virtual zeus::CColor GetXRayEnergyDecoColor() const=0;
virtual zeus::CColor GetHudCounterFill() const=0;
virtual zeus::CColor GetHudCounterOutline() const=0;
virtual zeus::CColor GetThermalDecoColor() const=0;
virtual zeus::CColor GetThermalOutlinesColor() const=0;
virtual zeus::CColor GetThermalLockColor() const=0;
virtual VisorEnergyInitColors GetVisorEnergyInitColors(int idx) const=0;
virtual VisorEnergyBarColors GetVisorEnergyBarColors(int idx) const=0;
};
}

View File

@ -22,10 +22,10 @@ struct CTweakGui : ITweakGui
Value<float> x28_;
atUint32 x2c_ = 0;
Value<float> x30_;
Value<float> x34_;
Value<float> x38_;
Value<float> x3c_;
Value<bool> x40_;
Value<float> x34_energyBarFilledSpeed;
Value<float> x38_energyBarShadowSpeed;
Value<float> x3c_energyBarDrainDelay;
Value<bool> x40_energyBarAlwaysResetDelay;
Value<float> x44_;
Value<float> x48_;
Value<float> x4c_;
@ -196,6 +196,10 @@ struct CTweakGui : ITweakGui
CTweakGui(athena::io::IStreamReader& r) { this->read(r); }
float GetMapAlphaInterpolant() const { return x8_mapAlphaInterp; }
float GetEnergyBarFilledSpeed() const { return x34_energyBarFilledSpeed; }
float GetEnergyBarShadowSpeed() const { return x38_energyBarShadowSpeed; }
float GetEnergyBarDrainDelay() const { return x3c_energyBarDrainDelay; }
bool GetEnergyBarAlwaysResetDelay() const { return x40_energyBarAlwaysResetDelay; }
atUint32 GetHudCamFovTweak() const { return xa8_hudCamFovTweak; }
atUint32 GetHudCamYTweak() const { return xac_hudCamYTweak; }
atUint32 GetHudCamZTweak() const { return xb0_hudCamZTweak; }

View File

@ -22,9 +22,9 @@ struct CTweakGuiColors : public ITweakGuiColors
DNAColor x28_;
DNAColor x2c_;
DNAColor x30_;
DNAColor x34_;
DNAColor x38_;
DNAColor x3c_;
DNAColor x34_energyBarFilledLowEnergy;
DNAColor x38_energyBarShadowLowEnergy;
DNAColor x3c_energyBarEmptyLowEnergy;
DNAColor x40_;
DNAColor x44_;
DNAColor x48_;
@ -32,7 +32,7 @@ struct CTweakGuiColors : public ITweakGuiColors
DNAColor x50_;
DNAColor x54_;
DNAColor x58_;
DNAColor x5c_;
DNAColor x5c_energyWarningFont;
DNAColor x60_;
DNAColor x64_;
DNAColor x68_;
@ -54,7 +54,7 @@ struct CTweakGuiColors : public ITweakGuiColors
DNAColor xa8_;
DNAColor xac_;
DNAColor xb0_;
DNAColor xb4_;
DNAColor xb4_energyWarningOutline;
DNAColor xb8_;
DNAColor xbc_;
DNAColor xc0_;
@ -67,7 +67,7 @@ struct CTweakGuiColors : public ITweakGuiColors
DNAColor xdc_;
DNAColor xe0_;
DNAColor xe4_;
DNAColor xe8_;
DNAColor xe8_energyBarFlashColor;
DNAColor xec_;
DNAColor xf0_;
DNAColor xf4_;
@ -122,19 +122,20 @@ struct CTweakGuiColors : public ITweakGuiColors
DNAColor x1b8_thermalLockColor;
DNAColor x1bc_;
DNAColor x1c0_;
struct UnkColors : BigYAML
struct PerVisorColors : BigYAML
{
DECL_YAML
DNAColor x0_;
DNAColor x4_;
DNAColor x8_;
DNAColor xc_;
DNAColor x10_;
DNAColor x14_;
DNAColor x18_;
DNAColor x0_energyBarFilled;
DNAColor x4_energyBarEmpty;
DNAColor x8_energyBarShadow;
DNAColor xc_energyTankFilled;
DNAColor x10_energyTankEmpty;
DNAColor x14_energyDigitsFont;
DNAColor x18_energyDigitsOutline;
};
Value<atUint32> x1c4_count;
Vector<UnkColors, DNA_COUNT(x1c4_count)> x1c4_;
Value<atUint32> x1c4_perVisorCount;
/* Combat, Scan, XRay, Thermal, Ball */
Vector<PerVisorColors, DNA_COUNT(x1c4_perVisorCount)> x1c4_perVisorColors;
CTweakGuiColors() = default;
CTweakGuiColors(athena::io::IStreamReader& r) { this->read(r); }
@ -142,13 +143,30 @@ struct CTweakGuiColors : public ITweakGuiColors
zeus::CColor GetHudMessageFill() const { return x14_hudMessageFill; }
zeus::CColor GetHudMessageOutline() const { return x18_hudMessageOutline; }
zeus::CColor GetHudFrameColor() const { return x1c_hudFrameColor; }
zeus::CColor GetEnergyBarFilledLowEnergy() const { return x34_energyBarFilledLowEnergy; }
zeus::CColor GetEnergyBarShadowLowEnergy() const { return x38_energyBarShadowLowEnergy; }
zeus::CColor GetEnergyBarEmptyLowEnergy() const { return x3c_energyBarEmptyLowEnergy; }
zeus::CColor GetEnergyWarningFont() const { return x5c_energyWarningFont; }
zeus::CColor GetTickDecoColor() const { return x88_tickDecoColor; }
zeus::CColor GetEnergyWarningOutline() const { return xb4_energyWarningOutline; }
zeus::CColor GetEnergyBarFlashColor() const { return xe8_energyBarFlashColor; }
zeus::CColor GetXRayEnergyDecoColor() const { return x100_xrayEnergyDecoColor; }
zeus::CColor GetHudCounterFill() const { return x180_hudCounterFill; }
zeus::CColor GetHudCounterOutline() const { return x184_hudCounterOutline; }
zeus::CColor GetThermalDecoColor() const { return x1ac_thermalDecoColor; }
zeus::CColor GetThermalOutlinesColor() const { return x1b0_thermalOutlinesColor; }
zeus::CColor GetThermalLockColor() const { return x1b8_thermalLockColor; }
VisorEnergyInitColors GetVisorEnergyInitColors(int idx) const
{
const PerVisorColors& colors = x1c4_perVisorColors[idx];
return {colors.xc_energyTankFilled, colors.x10_energyTankEmpty,
colors.x14_energyDigitsFont, colors.x18_energyDigitsOutline};
}
VisorEnergyBarColors GetVisorEnergyBarColors(int idx) const
{
const PerVisorColors& colors = x1c4_perVisorColors[idx];
return {colors.x0_energyBarFilled, colors.x4_energyBarEmpty, colors.x8_energyBarShadow};
}
};
}
}

View File

@ -163,8 +163,8 @@ public:
void DecrPickup(EItemType type, s32 amount);
void IncrPickup(EItemType type, s32 amount);
void ResetAndIncrPickUp(EItemType type, s32 amount);
float GetEnergyTankCapacity() const { return 100.f; }
float GetBaseHealthCapacity() const { return 99.f; }
static float GetEnergyTankCapacity() { return 100.f; }
static float GetBaseHealthCapacity() { return 99.f; }
float CalculateHealth(u32 health);
void ReInitalizePowerUp(EItemType type, u32 capacity);
void InitializePowerUp(EItemType type, u32 capacity);

View File

@ -47,6 +47,7 @@ public:
void Update(float dt);
void Draw(const CGuiWidgetDrawParms& drawParms) const;
float GetActualFraction() const { return xe0_maxEnergy == 0.f ? 0.f : xf4_setEnergy / xe0_maxEnergy; }
float GetFilledEnergy() const { return xf8_filledEnergy; }
void SetCurrEnergy(float e, ESetMode mode);
void SetCoordFunc(FCoordFunc func) { xd8_coordFunc = func; }
void SetEmptyColor(const zeus::CColor& c) { xcc_emptyColor = c; }

View File

@ -113,6 +113,7 @@ public:
const zeus::CTransform& GetTransform() const {return x74_transform;}
zeus::CTransform& GetTransform() {return x74_transform;}
const zeus::CVector3f& GetIdlePosition() const {return x74_transform.origin;}
const zeus::CColor& GetGeometryColor() const { return xa8_color2; }
void SetIdlePosition(const zeus::CVector3f& pos, bool reapply);
void ReapplyXform();
void SetIsVisible(bool);

View File

@ -1,11 +1,197 @@
#include "CHudEnergyInterface.hpp"
#include "CAuiEnergyBarT01.hpp"
#include "CAuiMeter.hpp"
#include "GameGlobalObjects.hpp"
#include "CStringTable.hpp"
#include "CGuiTextPane.hpp"
#include "Audio/CSfxManager.hpp"
#include "CGuiFrame.hpp"
namespace urde
{
void CHudEnergyInterfaceBall::Update(float dt, float energyLowPulse)
static const CAuiEnergyBarT01::FCoordFunc CoordFuncs[] =
{
CHudEnergyInterface::CombatEnergyCoordFunc,
CHudEnergyInterface::CombatEnergyCoordFunc,
CHudEnergyInterface::XRayEnergyCoordFunc,
CHudEnergyInterface::ThermalEnergyCoordFunc,
CHudEnergyInterface::BallEnergyCoordFunc
};
static const float Tesselations[] =
{
0.2f, 0.2f, 0.1f, 0.2f, 0.1f
};
CHudEnergyInterface::CHudEnergyInterface(CGuiFrame& selHud, float tankEnergy, int totalEnergyTanks,
int numTanksFilled, bool energyLow, EBarType barType)
: x0_barType(barType), xc_tankEnergy(tankEnergy), x10_totalEnergyTanks(totalEnergyTanks),
x14_numTanksFilled(numTanksFilled)
{
x1c_24_ = true;
x1c_25_ = true;
x1c_26_barDirty = true;
x1c_27_energyLow = energyLow;
x20_textpane_energydigits = static_cast<CGuiTextPane*>(selHud.FindWidget("textpane_energydigits"));
x24_meter_energytanks = static_cast<CAuiMeter*>(selHud.FindWidget("meter_energytanks"));
x28_textpane_energywarning = static_cast<CGuiTextPane*>(selHud.FindWidget("textpane_energywarning"));
x2c_energybart01_energybar = static_cast<CAuiEnergyBarT01*>(selHud.FindWidget("energybart01_energybar"));
x2c_energybart01_energybar->SetCoordFunc(CoordFuncs[int(barType)]);
x2c_energybart01_energybar->SetTesselation(Tesselations[int(barType)]);
ITweakGuiColors::VisorEnergyBarColors barColors = g_tweakGuiColors->GetVisorEnergyBarColors(int(barType));
ITweakGuiColors::VisorEnergyInitColors initColors = g_tweakGuiColors->GetVisorEnergyInitColors(int(barType));
x20_textpane_energydigits->TextSupport()->SetFontColor(initColors.digitsFont);
x20_textpane_energydigits->TextSupport()->SetOutlineColor(initColors.digitsOutline);
x2c_energybart01_energybar->SetMaxEnergy(CPlayerState::GetBaseHealthCapacity());
x2c_energybart01_energybar->SetFilledColor(barColors.filled);
x2c_energybart01_energybar->SetShadowColor(barColors.shadow);
x2c_energybart01_energybar->SetEmptyColor(barColors.empty);
x2c_energybart01_energybar->SetFilledDrainSpeed(g_tweakGui->GetEnergyBarFilledSpeed());
x2c_energybart01_energybar->SetShadowDrainSpeed(g_tweakGui->GetEnergyBarShadowSpeed());
x2c_energybart01_energybar->SetShadowDrainDelay(g_tweakGui->GetEnergyBarDrainDelay());
x2c_energybart01_energybar->SetIsAlwaysResetTimer(g_tweakGui->GetEnergyBarAlwaysResetDelay());
x24_meter_energytanks->SetMaxCapacity(14);
if (x28_textpane_energywarning)
{
x28_textpane_energywarning->TextSupport()->SetFontColor(g_tweakGuiColors->GetEnergyWarningFont());
x28_textpane_energywarning->TextSupport()->SetOutlineColor(g_tweakGuiColors->GetEnergyWarningOutline());
if (x1c_27_energyLow)
x28_textpane_energywarning->TextSupport()->SetText(g_MainStringTable->GetString(9));
else
x28_textpane_energywarning->TextSupport()->SetText(u"");
}
for (int i=0 ; i<14 ; ++i)
{
CGuiGroup* g = static_cast<CGuiGroup*>(x24_meter_energytanks->GetWorkerWidget(i));
if (CGuiWidget* w = g->GetWorkerWidget(0))
w->SetColor(initColors.tankFilled);
if (CGuiWidget* w = g->GetWorkerWidget(1))
w->SetColor(initColors.tankEmpty);
}
}
void CHudEnergyInterface::Update(float dt, float energyLowPulse)
{
if (x28_textpane_energywarning)
{
if (x1c_27_energyLow)
{
x4_energyLowFader = std::min(x4_energyLowFader + 2.f * dt, 1.f);
zeus::CColor color = zeus::CColor::skWhite;
color.a = x4_energyLowFader * energyLowPulse;
x28_textpane_energywarning->SetColor(color);
}
else
{
x4_energyLowFader = std::max(0.f, x4_energyLowFader - 2.f * dt);
zeus::CColor color = zeus::CColor::skWhite;
color.a = x4_energyLowFader * energyLowPulse;
x28_textpane_energywarning->SetColor(color);
}
if (x28_textpane_energywarning->GetGeometryColor().a)
x28_textpane_energywarning->SetIsVisible(true);
else
x28_textpane_energywarning->SetIsVisible(false);
}
if (x2c_energybart01_energybar->GetFilledEnergy() != x18_cachedBarEnergy || x1c_26_barDirty)
{
x1c_26_barDirty = false;
x18_cachedBarEnergy = x2c_energybart01_energybar->GetFilledEnergy();
std::u16string string = hecl::UTF8ToChar16(hecl::Format("%02d",
int(std::fmod(x18_cachedBarEnergy, CPlayerState::GetEnergyTankCapacity()))));
x20_textpane_energydigits->TextSupport()->SetText(string);
}
ITweakGuiColors::VisorEnergyBarColors barColors = g_tweakGuiColors->GetVisorEnergyBarColors(int(x0_barType));
zeus::CColor emptyColor = x1c_27_energyLow ? g_tweakGuiColors->GetEnergyBarEmptyLowEnergy() : barColors.empty;
zeus::CColor filledColor = x1c_27_energyLow ? g_tweakGuiColors->GetEnergyBarFilledLowEnergy() : barColors.filled;
zeus::CColor shadowColor = x1c_27_energyLow ? g_tweakGuiColors->GetEnergyBarShadowLowEnergy() : barColors.shadow;
x2c_energybart01_energybar->SetFilledColor(zeus::CColor::lerp(
zeus::CColor::lerp(filledColor, g_tweakGuiColors->GetEnergyBarFlashColor(), x8_flashMag),
zeus::CColor(1.f, 0.8f, 0.4f, 1.f), energyLowPulse));
x2c_energybart01_energybar->SetShadowColor(shadowColor);
x2c_energybart01_energybar->SetEmptyColor(emptyColor);
}
void CHudEnergyInterface::SetEnergyLow(bool energyLow)
{
if (x1c_27_energyLow == energyLow)
return;
std::u16string string;
if (energyLow)
string = g_MainStringTable->GetString(9);
if (x28_textpane_energywarning)
x28_textpane_energywarning->TextSupport()->SetText(string);
if (energyLow)
CSfxManager::SfxStart(1405, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
x1c_27_energyLow = energyLow;
}
void CHudEnergyInterface::SetFlashMagnitude(float mag)
{
x8_flashMag = zeus::clamp(0.f, mag, 1.f);
}
void CHudEnergyInterface::SetNumFilledEnergyTanks(int numTanksFilled)
{
x14_numTanksFilled = numTanksFilled;
x24_meter_energytanks->SetCurrValue(numTanksFilled);
}
void CHudEnergyInterface::SetNumTotalEnergyTanks(int totalEnergyTanks)
{
x10_totalEnergyTanks = totalEnergyTanks;
x24_meter_energytanks->SetCapacity(totalEnergyTanks);
}
void CHudEnergyInterface::SetCurrEnergy(float tankEnergy, bool wrapped)
{
xc_tankEnergy = tankEnergy;
x2c_energybart01_energybar->SetCurrEnergy(tankEnergy,
tankEnergy == 0.f ? CAuiEnergyBarT01::ESetMode::Insta : CAuiEnergyBarT01::ESetMode(wrapped));
}
std::pair<zeus::CVector3f, zeus::CVector3f> CHudEnergyInterface::CombatEnergyCoordFunc(float t)
{
float theta = 0.46764705f * t - 0.15882353f;
float x = 17.f * std::sin(theta);
float y = 17.f * std::cos(theta) - 17.f;
return {zeus::CVector3f(x, y, 0.4f), zeus::CVector3f(x, y, 0.f)};
}
std::pair<zeus::CVector3f, zeus::CVector3f> CHudEnergyInterface::XRayEnergyCoordFunc(float t)
{
float theta = 1.8207964f - 0.69f * t;
float x = std::cos(theta);
float z = std::sin(theta);
return {zeus::CVector3f(9.4f * x, 0.f, 9.4f * z), zeus::CVector3f(9.f * x, 0.f, 9.f * z)};
}
std::pair<zeus::CVector3f, zeus::CVector3f> CHudEnergyInterface::ThermalEnergyCoordFunc(float t)
{
float x = 8.1663399f * t;
return {zeus::CVector3f(x, 0.f, 0.f), zeus::CVector3f(x, 0.f, 0.4355512f)};
}
std::pair<zeus::CVector3f, zeus::CVector3f> CHudEnergyInterface::BallEnergyCoordFunc(float t)
{
float x = 1.6666f * t;
return {zeus::CVector3f(x, 0.f, 0.f), zeus::CVector3f(x, 0.f, 0.088887997f)};
}
}

View File

@ -1,13 +1,63 @@
#ifndef __URDE_CHUDENERGYINTERFACE_HPP__
#define __URDE_CHUDENERGYINTERFACE_HPP__
#include "RetroTypes.hpp"
namespace urde
{
class CGuiFrame;
class CGuiWidget;
class CGuiTextPane;
class CAuiMeter;
class CAuiEnergyBarT01;
class CHudEnergyInterfaceBall
class CHudEnergyInterface
{
public:
enum class EBarType
{
Combat,
Scan,
XRay,
Thermal,
Ball
};
private:
EBarType x0_barType;
float x4_energyLowFader = 0.f;
float x8_flashMag = 0.f;
float xc_tankEnergy;
int x10_totalEnergyTanks;
int x14_numTanksFilled;
float x18_cachedBarEnergy = 0.f;
union
{
struct
{
bool x1c_24_ : 1;
bool x1c_25_ : 1;
bool x1c_26_barDirty : 1;
bool x1c_27_energyLow : 1;
};
u16 _dummy = 0;
};
CGuiTextPane* x20_textpane_energydigits;
CAuiMeter* x24_meter_energytanks;
CGuiTextPane* x28_textpane_energywarning;
CAuiEnergyBarT01* x2c_energybart01_energybar;
public:
CHudEnergyInterface(CGuiFrame& selHud, float tankEnergy, int totalEnergyTanks,
int numTanksFilled, bool energyLow, EBarType barType);
void Update(float dt, float energyLowPulse);
void SetEnergyLow(bool energyLow);
void SetFlashMagnitude(float mag);
void SetNumFilledEnergyTanks(int numTanksFilled);
void SetNumTotalEnergyTanks(int totalEnergyTanks);
void SetCurrEnergy(float tankEnergy, bool wrapped);
static std::pair<zeus::CVector3f, zeus::CVector3f> CombatEnergyCoordFunc(float t);
static std::pair<zeus::CVector3f, zeus::CVector3f> XRayEnergyCoordFunc(float t);
static std::pair<zeus::CVector3f, zeus::CVector3f> ThermalEnergyCoordFunc(float t);
static std::pair<zeus::CVector3f, zeus::CVector3f> BallEnergyCoordFunc(float t);
};
}

View File

@ -104,7 +104,7 @@ class CSamusHud
CGuiFrame* x274_loadedFrmeBaseHud = nullptr;
TLockedToken<CGuiFrame> x278_selectedHud; // used to be optional
CGuiFrame* x288_loadedSelectedHud = nullptr;
std::unique_ptr<CHudEnergyInterfaceBall> x28c_ballEnergyIntf;
std::unique_ptr<CHudEnergyInterface> x28c_ballEnergyIntf;
std::unique_ptr<IHudThreatInterface> x290_threatIntf;
std::unique_ptr<CHudMissileInterfaceCombat> x294_missileIntf;
std::unique_ptr<IFreeLookInterface> x298_freeLookIntf;
@ -121,7 +121,7 @@ class CSamusHud
ETransitionState x2c4_activeTransState = ETransitionState::NotTransitioning;
float x2c8_transT = 1.f;
u32 x2cc_preLoadCountdown = 0;
float x2d0_ = 0.f;
float x2d0_playerHealth = 0.f;
u32 x2d4_totalEnergyTanks = 0;
u32 x2d8_missileAmount = 0;
u32 x2dc_missileCapacity = 0;