diff --git a/Client/game_sa/CHudSA.cpp b/Client/game_sa/CHudSA.cpp index b30eb03589..ba9358e254 100644 --- a/Client/game_sa/CHudSA.cpp +++ b/Client/game_sa/CHudSA.cpp @@ -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) @@ -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; @@ -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; diff --git a/Client/game_sa/CHudSA.h b/Client/game_sa/CHudSA.h index a26dcba6e7..81dd6c3546 100644 --- a/Client/game_sa/CHudSA.h +++ b/Client/game_sa/CHudSA.h @@ -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}; @@ -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; diff --git a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp index f10330fbc9..ba9b0e1b60 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp @@ -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") diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp index 3bf98beb0e..3dd45e8ffd 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp @@ -1040,6 +1040,11 @@ std::variant, CLuaMultiR } case eHudComponentProperty::CUSTOM_ALPHA: return hud->GetComponentUseCustomAlpha(component); + case eHudComponentProperty::TEXT_SIZE: + { + CVector2D& size = hud->GetComponentTextSize(component); + return CLuaMultiReturn{size.fX, size.fY}; + } } return false; diff --git a/Client/sdk/game/CHud.h b/Client/sdk/game/CHud.h index 6dd2cc5ee1..56acc80cb5 100644 --- a/Client/sdk/game/CHud.h +++ b/Client/sdk/game/CHud.h @@ -49,6 +49,7 @@ enum class eHudComponentProperty TEXT_ALIGNMENT, TEXT_PROPORTIONAL, CUSTOM_ALPHA, + TEXT_SIZE, ALL_PROPERTIES, }; @@ -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; };