diff --git a/src/ui/CSimpleFontString.cpp b/src/ui/CSimpleFontString.cpp index 969e17f..8fea6f6 100644 --- a/src/ui/CSimpleFontString.cpp +++ b/src/ui/CSimpleFontString.cpp @@ -947,3 +947,12 @@ void CSimpleFontString::UpdateString() { this->OnRegionChanged(); } + +bool CSimpleFontString::SetAlphaGradient(int32_t startChar, int32_t length) { + this->m_alphaGradientStart = startChar; + this->m_alphaGradientLength = length; + if (this->m_string) { + // TODO: return TextBlockSetGradient() + } + return false; +} diff --git a/src/ui/CSimpleFontString.hpp b/src/ui/CSimpleFontString.hpp index 030346e..4f08fc7 100644 --- a/src/ui/CSimpleFontString.hpp +++ b/src/ui/CSimpleFontString.hpp @@ -87,6 +87,7 @@ class CSimpleFontString : public CSimpleRegion, public CSimpleFontable { void SetTextLength(uint32_t a2); int32_t Sub482AC0(); void UpdateString(); + bool SetAlphaGradient(int32_t startChar, int32_t length); }; #endif diff --git a/src/ui/CSimpleFontStringScript.cpp b/src/ui/CSimpleFontStringScript.cpp index 0618946..21b8a66 100644 --- a/src/ui/CSimpleFontStringScript.cpp +++ b/src/ui/CSimpleFontStringScript.cpp @@ -5,6 +5,7 @@ #include "util/Lua.hpp" #include "util/Unimplemented.hpp" #include "util/StringTo.hpp" +#include "gx/Coordinate.hpp" #include int32_t CSimpleFontString_IsObjectType(lua_State* L) { @@ -72,15 +73,47 @@ int32_t CSimpleFontString_SetVertexColor(lua_State* L) { } int32_t CSimpleFontString_GetAlpha(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleFontString::GetObjectType(); + auto string = static_cast(FrameScript_GetObjectThis(L, type)); + + CImVector color; + string->GetVertexColor(color); + lua_pushnumber(L, color.a / 255.0); + return 1; } int32_t CSimpleFontString_SetAlpha(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleFontString::GetObjectType(); + auto string = static_cast(FrameScript_GetObjectThis(L, type)); + + if (!lua_isnumber(L, 2)) { + return luaL_error(L, "Usage: %s:SetAlpha(alpha)", string->GetDisplayName()); + } + + CImVector color; + string->GetVertexColor(color); + + color.a = lua_tonumber(L, 2) * 255.0; + string->SetVertexColor(color); + return 0; } int32_t CSimpleFontString_SetAlphaGradient(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleFontString::GetObjectType(); + auto string = static_cast(FrameScript_GetObjectThis(L, type)); + + if (!lua_isnumber(L, 2) || !lua_isnumber(L, 3)) { + return luaL_error(L, "Usage: %s:SetAlphaGradient(start, length)", string->GetDisplayName()); + } + + auto start = lua_tonumber(L, 2); + auto length = lua_tonumber(L, 3); + if (string->SetAlphaGradient(start, length)) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + return 1; } int32_t CSimpleFontString_Show(lua_State* L) { @@ -124,7 +157,17 @@ int32_t CSimpleFontString_IsShown(lua_State* L) { } int32_t CSimpleFontString_GetFontObject(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleFontString::GetObjectType(); + auto string = static_cast(FrameScript_GetObjectThis(L, type)); + if (string->m_fontObject) { + if (!string->m_fontObject->lua_registered) { + string->m_fontObject->RegisterScriptObject(nullptr); + } + lua_rawgeti(L, LUA_REGISTRYINDEX, string->m_fontObject->lua_objectRef); + } else { + lua_pushnil(L); + } + return 1; } int32_t CSimpleFontString_SetFontObject(lua_State* L) { @@ -162,7 +205,20 @@ int32_t CSimpleFontString_SetFontObject(lua_State* L) { } int32_t CSimpleFontString_GetFont(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleFontString::GetObjectType(); + auto string = static_cast(FrameScript_GetObjectThis(L, type)); + + lua_pushstring(L, string->GetFontName()); + + auto height = string->GetFontHeight(false); + height *= CoordinateGetAspectCompensation() * 1024.0f; + height = DDCToNDCWidth(height); + lua_pushnumber(L, height); + + auto flags = FontFlagsToString(string->GetFontFlags()); + lua_pushstring(L, flags); + + return 3; } int32_t CSimpleFontString_SetFont(lua_State* L) { diff --git a/src/ui/Util.cpp b/src/ui/Util.cpp index a941d0f..6e57f2a 100644 --- a/src/ui/Util.cpp +++ b/src/ui/Util.cpp @@ -143,3 +143,28 @@ const char* DrawLayerToString(int32_t layer) { return "UNKNOWN"; } } + +const char* FontFlagsToString(uint32_t flags) { + struct FlagEntry { + uint32_t flag; + const char* string; + }; + + static FlagEntry table[3] = { + { 1, "OUTLINE" }, + { 4, "THICKOUTLINE" }, + { 2, "MONOCHROME" }, + }; + + static char result[64] = {}; + result[0] = '\0'; + for (size_t i = 0; i < 3; ++i) { + if (flags & table[i].flag) { + if (result[0]) { + SStrPack(result, ", ", sizeof(result)); + } + SStrPack(result, table[i].string, sizeof(result)); + } + } + return result; +} diff --git a/src/ui/Util.hpp b/src/ui/Util.hpp index 5c973ff..341e6b4 100644 --- a/src/ui/Util.hpp +++ b/src/ui/Util.hpp @@ -19,4 +19,6 @@ const char* AnchorPointToString(int32_t point); const char* DrawLayerToString(int32_t layer); +const char* FontFlagsToString(uint32_t flags); + #endif