feat(gameui): update CGTooltip script methods

This commit is contained in:
VDm 2025-08-14 00:32:18 +04:00
parent 5e54cca3fa
commit 55bcd21c1f
7 changed files with 162 additions and 6 deletions

View File

@ -5,6 +5,7 @@
int32_t CGTooltip::s_metatable;
int32_t CGTooltip::s_objectType;
CImVector CGTooltip::s_defaultColor{ 0, 210, 255, 255 };
CSimpleFrame* CGTooltip::Create(CSimpleFrame* parent) {
// TODO: Data = CDataAllocator__GetData(0, ".?AVCGTooltip@@", -2);
@ -40,6 +41,15 @@ void CGTooltip::ClearTooltip() {
void CGTooltip::ResetPosition(int32_t a1) {
}
void CGTooltip::SetAnchorType(TOOLTIP_ANCHORPOINT anchorpoint, float xoffset, float yoffset) {
this->m_offsetX = xoffset;
this->m_offsetY = yoffset;
if (this->m_owner) {
this->m_anchorPoint = anchorpoint;
}
this->ResetPosition(1);
}
void CGTooltip::SetOwner(CSimpleFrame* owner, TOOLTIP_ANCHORPOINT anchorpoint, float xoffset, float yoffset) {
this->ClearTooltip();
this->SetFrameAlpha(255);
@ -60,6 +70,15 @@ void CGTooltip::SetOwner(CSimpleFrame* owner, TOOLTIP_ANCHORPOINT anchorpoint, f
void CGTooltip::AddFontStrings(CSimpleFontString* leftstring, CSimpleFontString* rightstring) {
}
void CGTooltip::AddLine(
const char* leftText,
const char* rightText,
const CImVector& leftColor,
const CImVector& rightColor,
int32_t wrapped) {
}
bool CGTooltip::IsA(int32_t type) {
return type == CGTooltip::s_objectType
|| type == CSimpleFrame::s_objectType

View File

@ -26,6 +26,7 @@ class CGTooltip : public CSimpleFrame {
// Static variables
static int32_t s_metatable;
static int32_t s_objectType;
static CImVector s_defaultColor;
// Static functions
static CSimpleFrame* Create(CSimpleFrame* parent);
@ -37,8 +38,15 @@ class CGTooltip : public CSimpleFrame {
CGTooltip(CSimpleFrame* parent);
void ClearTooltip();
void ResetPosition(int32_t a1);
void SetAnchorType(TOOLTIP_ANCHORPOINT anchorpoint, float xoffset, float yoffset);
void SetOwner(CSimpleFrame* owner, TOOLTIP_ANCHORPOINT anchorpoint, float xoffset, float yoffset);
void AddFontStrings(CSimpleFontString* leftstring, CSimpleFontString* rightstring);
void AddLine(
const char* leftText,
const char* rightText,
const CImVector& leftColor,
const CImVector& rightColor,
int32_t wrapped);
// Virtual member functions
virtual bool IsA(int32_t type);

View File

@ -1,6 +1,8 @@
#include "gameui/CGTooltipScript.hpp"
#include "gameui/CGTooltip.hpp"
#include "ui/FrameScript.hpp"
#include "ui/CSimpleFontString.hpp"
#include "ui/Util.hpp"
#include "gx/Coordinate.hpp"
#include "util/Lua.hpp"
#include "util/Unimplemented.hpp"
@ -171,23 +173,86 @@ static int32_t Script_SetOwner(lua_State* L) {
}
static int32_t Script_GetAnchorType(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
auto type = CGTooltip::GetObjectType();
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
lua_pushstring(L, AnchorPointToString(tooltip->m_anchorPoint));
return 1;
}
static int32_t Script_SetAnchorType(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
auto type = CGTooltip::GetObjectType();
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
int32_t anchorPoint = 0;
if (lua_isstring(L, 2)) {
StringToAnchorPoint(lua_tolstring(L, 3, nullptr), anchorPoint);
} else {
return luaL_error(L, "Usage: %s:SetAnchorType( anchorType [,Xoffset] [,Yoffset] )", tooltip->GetDisplayName());
}
float xoffset = 0.0f;
if (lua_isnumber(L, 3)) {
float value = lua_tonumber(L, 3);
value /= CoordinateGetAspectCompensation() * 1024.0f;
xoffset = NDCToDDCWidth(value);
}
float yoffset = 0.0f;
if (lua_isnumber(L, 4)) {
float value = lua_tonumber(L, 4);
value /= CoordinateGetAspectCompensation() * 1024.0f;
yoffset = NDCToDDCWidth(value);
}
tooltip->SetAnchorType(static_cast<TOOLTIP_ANCHORPOINT>(anchorPoint), xoffset, yoffset);
return 0;
}
static int32_t Script_ClearLines(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
auto type = CGTooltip::GetObjectType();
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
tooltip->ClearTooltip();
return 0;
}
static int32_t Script_AddLine(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
auto type = CGTooltip::GetObjectType();
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
const char* line = lua_isstring(L, 2) ? lua_tolstring(L, 2, nullptr) : nullptr;
CImVector color = CGTooltip::s_defaultColor;
if (lua_isnumber(L, 3)) {
FrameScript_GetColorNoAlpha(L, 3, color);
}
bool wrapped = StringToBOOL(L, 6, 0);
tooltip->AddLine(line, nullptr, color, color, wrapped);
return 0;
}
static int32_t Script_AddDoubleLine(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
auto type = CGTooltip::GetObjectType();
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
const char* leftLine = lua_isstring(L, 2) ? lua_tolstring(L, 2, nullptr) : nullptr;
const char* rightLine = lua_isstring(L, 3) ? lua_tolstring(L, 3, nullptr) : nullptr;
CImVector leftColor = CGTooltip::s_defaultColor;
if (lua_isnumber(L, 4)) {
FrameScript_GetColorNoAlpha(L, 4, leftColor);
}
CImVector rightColor = CGTooltip::s_defaultColor;
if (lua_isnumber(L, 7)) {
FrameScript_GetColorNoAlpha(L, 7, rightColor);
}
bool wrapped = StringToBOOL(L, 10, 0);
tooltip->AddLine(leftLine, rightLine, leftColor, rightColor, wrapped);
return 0;
}
static int32_t Script_AddTexture(lua_State* L) {
@ -195,7 +260,25 @@ static int32_t Script_AddTexture(lua_State* L) {
}
static int32_t Script_SetText(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
auto type = CGTooltip::GetObjectType();
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
const char* line = lua_isstring(L, 2) ? lua_tolstring(L, 2, nullptr) : nullptr;
if (!line) {
return luaL_error(L, "Usage: %s:SetText(\"text\" [, color])", tooltip->GetDisplayName());
}
CImVector color = CGTooltip::s_defaultColor;
if (lua_isnumber(L, 3)) {
FrameScript_GetColor(L, 3, color);
}
bool wrapped = StringToBOOL(L, 7, 0);
tooltip->ClearTooltip();
tooltip->AddLine(line, nullptr, color, color, wrapped);
tooltip->Show();
return 0;
}
static int32_t Script_AppendText(lua_State* L) {

View File

@ -447,6 +447,19 @@ void FrameScript_Flush() {
}
}
void FrameScript_GetColorNoAlpha(lua_State* L, int32_t idx, CImVector& color) {
float r = lua_tonumber(L, idx + 0);
r = std::max(0.0f, std::min(r, 1.0f));
float g = lua_tonumber(L, idx + 1);
g = std::max(0.0f, std::min(g, 1.0f));
float b = lua_tonumber(L, idx + 2);
b = std::max(0.0f, std::min(b, 1.0f));
color.Set(1.0f, r, g, b);
}
void FrameScript_GetColor(lua_State* L, int32_t idx, CImVector& color) {
float r = lua_tonumber(L, idx + 0);
r = std::max(0.0f, std::min(r, 1.0f));

View File

@ -77,6 +77,8 @@ int32_t FrameScript_ExecuteFile(const char* filePath, const char* a2, MD5_CTX* m
void FrameScript_Flush();
void FrameScript_GetColorNoAlpha(lua_State* L, int32_t idx, CImVector& color);
void FrameScript_GetColor(lua_State* L, int32_t idx, CImVector& color);
int32_t SetDecimalConversion(int32_t enabled);

View File

@ -97,3 +97,32 @@ const char* OrientationToString(uint32_t orientation) {
return "UNKNOWN";
}
}
const char* AnchorPointToString(int32_t point) {
switch (point) {
case 0:
return "ANCHOR_LEFT";
case 1:
return "ANCHOR_RIGHT";
case 2:
return "ANCHOR_BOTTOMLEFT";
case 3:
return "ANCHOR_BOTTOM";
case 4:
return "ANCHOR_BOTTOMRIGHT";
case 5:
return "ANCHOR_TOPLEFT";
case 6:
return "ANCHOR_TOP";
case 7:
return "ANCHOR_TOPRIGHT";
case 8:
return "ANCHOR_CURSOR";
case 10:
return "ANCHOR_PRESERVE";
case 11:
return "ANCHOR_CURSOR_RIGHT";
default:
return "ANCHOR_NONE";
}
}

View File

@ -15,4 +15,6 @@ int32_t StringToFrameStrata(const char* string, FRAME_STRATA& strata);
const char* OrientationToString(uint32_t orientation);
const char* AnchorPointToString(int32_t point);
#endif