Skip to content

Commit

Permalink
textSize property
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX committed Dec 26, 2024
1 parent e38e5c6 commit 5546c04
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
27 changes: 18 additions & 9 deletions Client/game_sa/CHudSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ bool CHudSA::IsComponentText(const eHudComponent& component) const noexcept
return false;
}

CVector2D CHudSA::GetComponentTextSize(const eHudComponent& component) const
{
const auto& ref = GetHudComponentRef(component);
return CVector2D(ref.placement.stringWidth, ref.placement.stringHeight);
}

RwColor CHudSA::GetHUDColour(const eHudColour& colour) noexcept
{
switch (colour)
Expand Down Expand Up @@ -710,14 +716,6 @@ void CHudSA::RenderText(float x, float y, const char* text, SHudComponentData& p
bool useCustomPosition = properties.placement.useCustomPosition;
bool useCustomSize = properties.placement.useCustomSize;

// Save default position once
if (!properties.placement.setDefaultXY)
{
properties.placement.x = x;
properties.placement.y = y;
properties.placement.setDefaultXY = true;
}

float scaleX = useCustomSize ? properties.placement.customWidth : properties.placement.width;
float scaleY = useCustomSize ? properties.placement.customHeight : properties.placement.height;

Expand Down Expand Up @@ -750,7 +748,18 @@ void CHudSA::RenderText(float x, float y, const char* text, SHudComponentData& p
CFontSA::SetDropColor(properties.dropColor);
CFontSA::SetColor(useSecondColor ? properties.fillColor_Second : properties.fillColor);
}


// Save default position once
if (!properties.placement.setDefaultXY)
{
properties.placement.x = x;
properties.placement.y = y;
properties.placement.stringWidth = CFontSA::GetStringWidth(text, true);
properties.placement.stringHeight = CFontSA::GetFontHeight(CFontSA::GetScale().fY);

properties.placement.setDefaultXY = true;
}

// Draw text
float posX = useCustomPosition ? properties.placement.customX : x;
float posY = useCustomPosition ? properties.placement.customY : y;
Expand Down
3 changes: 3 additions & 0 deletions Client/game_sa/CHudSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ struct SComponentPlacement
// Original position & size
float x{0.0f}, y{0.0f}; // for getter function only
float width{0.0f}, height{0.0f};
float stringWidth{0.0f}, stringHeight{0.0f}; // for getter function only

// Custom position & size
float customX{0.0f}, customY{0.0f};
Expand Down Expand Up @@ -237,6 +238,8 @@ class CHudSA : public CHud

bool GetComponentUseCustomAlpha(const eHudComponent& component) const noexcept override { return GetHudComponentRef(component).useCustomAlpha; }

CVector2D GetComponentTextSize(const eHudComponent& component) const override;

static RsGlobal* GetRSGlobal() noexcept { return rsGlobal; }
static RwColor GetHUDColour(const eHudColour& colour) noexcept;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ ADD_ENUM(eHudComponentProperty::TEXT_STYLE, "fontStyle")
ADD_ENUM(eHudComponentProperty::TEXT_ALIGNMENT, "fontAlignment")
ADD_ENUM(eHudComponentProperty::TEXT_PROPORTIONAL, "proportional")
ADD_ENUM(eHudComponentProperty::CUSTOM_ALPHA, "useCustomAlpha")
ADD_ENUM(eHudComponentProperty::TEXT_SIZE, "textSize")
ADD_ENUM(eHudComponentProperty::ALL_PROPERTIES, "all")
IMPLEMENT_ENUM_CLASS_END("hud-component-property")

Expand Down
5 changes: 5 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,11 @@ std::variant<float, bool, std::string, CLuaMultiReturn<float, float>, CLuaMultiR
}
case eHudComponentProperty::CUSTOM_ALPHA:
return hud->GetComponentUseCustomAlpha(component);
case eHudComponentProperty::TEXT_SIZE:
{
CVector2D& size = hud->GetComponentTextSize(component);
return CLuaMultiReturn<float, float>{size.fX, size.fY};
}
}

return false;
Expand Down
3 changes: 3 additions & 0 deletions Client/sdk/game/CHud.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ enum class eHudComponentProperty
TEXT_ALIGNMENT,
TEXT_PROPORTIONAL,
CUSTOM_ALPHA,
TEXT_SIZE,

ALL_PROPERTIES,
};
Expand Down Expand Up @@ -127,4 +128,6 @@ class CHud
virtual bool GetComponentFontProportional(const eHudComponent& component) const = 0;

virtual bool GetComponentUseCustomAlpha(const eHudComponent& component) const noexcept = 0;

virtual CVector2D GetComponentTextSize(const eHudComponent& component) const = 0;
};

0 comments on commit 5546c04

Please sign in to comment.