diff --git a/Source/UI/Gauges/UIPcGage.h b/Source/UI/Gauges/UIPcGage.h index cc3dba9e..ce39aca0 100644 --- a/Source/UI/Gauges/UIPcGage.h +++ b/Source/UI/Gauges/UIPcGage.h @@ -44,6 +44,7 @@ class UIPlayerGage : public UIGage { public: UIPlayerGage(); bool Slot03() override; + void Paint() override; void SetFirstValues(std::function current, std::function maximum); void SetSecondValues(std::function current, std::function maximum); void SetThirdValues(std::function current, std::function maximum); diff --git a/Source/UI/Gauges/UIPlayerGage.cpp b/Source/UI/Gauges/UIPlayerGage.cpp index f3b01839..caab5942 100644 --- a/Source/UI/Gauges/UIPlayerGage.cpp +++ b/Source/UI/Gauges/UIPlayerGage.cpp @@ -85,3 +85,64 @@ void UIPlayerGage::SetSecondValues(std::function current, std::f this->m_secondCurrent = current; this->m_secondMaximum = maximum; } + +// OFFSET: 0x0088CB50 +// FUNCTION: fn_45488 +void UIPlayerGage::Paint() { + this->ClearSurface(this->colors[0]); + + const auto drawBar = [this](int y, std::function& current, std::function& maximum, + std::uint32_t color, std::uint32_t alternateColor, bool thresholdColor, + bool wideDenominator) { + const std::int64_t maximumValue = (std::max)(std::int64_t(1), maximum()); + const std::int64_t denominator = (std::max)(current(), maximumValue); + const std::int64_t numerator = current(); + const double divisor = + wideDenominator ? static_cast(denominator) : static_cast(static_cast(denominator)); + const float ratio = static_cast(static_cast(numerator) / divisor); + + this->FillRegion(1, y, this->geometry.width - 2, 3, this->colors[1]); + if (thresholdColor && ratio < 0.25f) { + color = alternateColor; + } + this->FillRegion(1, y, static_cast(static_cast(this->geometry.width - 2) * ratio), 3, color); + }; + + switch (this->unknown_009C) { + case 7: + if (this->m_thirdCurrent && this->m_thirdMaximum) { + drawBar(1, this->m_thirdCurrent, this->m_thirdMaximum, this->colors[5], this->colors[6], true, true); + } + break; + case 9: + case 10: + if (this->m_firstCurrent && this->m_firstMaximum && this->m_secondCurrent && this->m_secondMaximum) { + drawBar(1, this->m_firstCurrent, this->m_firstMaximum, this->colors[2], this->colors[4], true, true); + drawBar(5, this->m_secondCurrent, this->m_secondMaximum, this->colors[3], this->colors[3], false, false); + } + break; + case 13: + case 14: + if (this->m_firstCurrent && this->m_firstMaximum) { + drawBar(1, this->m_firstCurrent, this->m_firstMaximum, this->colors[2], this->colors[4], true, true); + } + break; + case 8: + if (this->m_firstCurrent && this->m_firstMaximum && this->m_secondCurrent && this->m_secondMaximum && + this->m_thirdCurrent && this->m_thirdMaximum) { + drawBar(1, this->m_firstCurrent, this->m_firstMaximum, this->colors[2], this->colors[4], true, true); + drawBar(5, this->m_secondCurrent, this->m_secondMaximum, this->colors[3], this->colors[3], false, true); + drawBar(9, this->m_thirdCurrent, this->m_thirdMaximum, this->colors[5], this->colors[6], true, true); + } + break; + default: + if (this->m_firstCurrent && this->m_firstMaximum && this->m_secondCurrent && this->m_secondMaximum) { + drawBar(1, this->m_firstCurrent, this->m_firstMaximum, this->colors[2], this->colors[4], true, false); + drawBar(5, this->m_secondCurrent, this->m_secondMaximum, this->colors[3], this->colors[3], false, false); + if (this->m_fourthCurrent && this->m_fourthMaximum) { + drawBar(9, this->m_fourthCurrent, this->m_fourthMaximum, this->colors[7], this->colors[7], false, false); + } + } + break; + } +}