feat(gameui): update CGTooltip class

This commit is contained in:
VDm 2025-08-15 00:17:21 +04:00
parent 1c65263c61
commit a50ca69e8c
6 changed files with 78 additions and 7 deletions

View File

@ -41,6 +41,28 @@ CGTooltip::CGTooltip(CSimpleFrame* parent)
}
void CGTooltip::ClearTooltip() {
// TODO
for (uint32_t line = 0; line < this->m_lines; ++line) {
auto leftString = this->m_leftStrings[line];
leftString->SetWidth(0.0f);
leftString->SetText("", 1);
leftString->Hide();
auto rightString = this->m_rightStrings[line];
rightString->SetWidth(0.0f);
rightString->SetText("", 1);
rightString->Hide();
this->m_wrapLine[line] = 0;
}
if (!this->m_minWidthForced) {
this->m_minWidth = 0.0f;
}
if (this->m_lines && this->m_onTooltipCleared.luaRef) {
this->RunScript(this->m_onTooltipCleared, 0, nullptr);
}
}
void CGTooltip::ResetPosition(int32_t a1) {
@ -144,6 +166,16 @@ void CGTooltip::AddLine(
this->m_wrapLine[this->m_lines++] = wrapped;
}
void CGTooltip::FadeOut() {
if (this->m_anchorPoint == ANCHOR_LEFT || this->m_anchorPoint == ANCHOR_CURSOR_RIGHT) {
this->HideThis();
this->m_fading = 0;
} else {
this->m_fading = 1;
this->m_fadeTime = TOOLTIP_FADE_TIME;
}
}
bool CGTooltip::IsA(int32_t type) {
return type == CGTooltip::s_objectType
|| type == CSimpleFrame::s_objectType

View File

@ -24,6 +24,8 @@ enum TOOLTIP_ANCHORPOINT {
class CGTooltip : public CSimpleFrame {
public:
const float TOOLTIP_FADE_TIME = 2.0f;
// Static variables
static int32_t s_metatable;
static int32_t s_objectType;
@ -48,6 +50,7 @@ class CGTooltip : public CSimpleFrame {
const CImVector& leftColor,
const CImVector& rightColor,
int32_t wrapped);
void FadeOut();
// Virtual member functions
virtual bool IsA(int32_t type);
@ -65,6 +68,8 @@ class CGTooltip : public CSimpleFrame {
TSFixedArray<int32_t> m_wrapLine;
CSimpleStatusBar* m_statusBar = nullptr;
CSimpleTexture* m_textures[10] = {};
uint32_t m_fading = 0;
float m_fadeTime = 0.0f;
float m_padding = 0.0f;
float m_minWidth = 0.0f;
uint32_t m_minWidthForced = 0;

View File

@ -286,7 +286,10 @@ static int32_t Script_AppendText(lua_State* L) {
}
static int32_t Script_FadeOut(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
auto type = CGTooltip::GetObjectType();
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
tooltip->FadeOut();
return 0;
}
static int32_t Script_SetHyperlink(lua_State* L) {
@ -406,7 +409,10 @@ static int32_t Script_SetAuctionItem(lua_State* L) {
}
static int32_t Script_NumLines(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
auto type = CGTooltip::GetObjectType();
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
lua_pushnumber(L, tooltip->m_lines);
return 1;
}
static int32_t Script_SetQuestRewardSpell(lua_State* L) {

View File

@ -844,11 +844,17 @@ static int32_t Script_NotWhileDeadError(lua_State* L) {
}
static int32_t Script_GetRestState(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
// TODO
lua_pushnil(L);
lua_pushnil(L);
lua_pushnil(L);
return 3;
}
static int32_t Script_GetXPExhaustion(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
// TODO
lua_pushnil(L);
return 1;
}
static int32_t Script_GetTimeToWellRested(lua_State* L) {

View File

@ -234,7 +234,9 @@ static int32_t Script_BNIsFriend(lua_State* L) {
}
static int32_t Script_BNGetMaxPlayersInConversation(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
// TODO: LoginConnection
lua_pushnumber(L, 12.0);
return 1;
}
void BattlenetUIRegisterScriptFunctions() {

View File

@ -3,6 +3,7 @@
#include "ui/FrameScriptInternal.hpp"
#include "util/Lua.hpp"
#include "util/Unimplemented.hpp"
#include "os/Debug.hpp"
#include <cstdint>
@ -120,7 +121,26 @@ int32_t forceinsecure(lua_State* L) {
}
int32_t securecall(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
// TODO: tainted
if (lua_isstring(L, 1)) {
lua_pushstring(L, lua_tolstring(L, 1, nullptr));
lua_rawget(L, LUA_GLOBALSINDEX);
lua_remove(L, 1);
lua_insert(L, 1);
}
if (!lua_gettop(L)) {
lua_pushnil(L);
}
lua_rawgeti(L, LUA_REGISTRYINDEX, FrameScript::s_errorHandlerRef);
lua_insert(L, 1);
if (lua_pcall(L, lua_gettop(L) - 2, -1, 1)) {
lua_settop(L, -3);
} else {
lua_remove(L, 1);
}
// TODO: tainted
return lua_gettop(L);
}
int32_t hooksecurefunc(lua_State* L) {
@ -132,7 +152,7 @@ int32_t debugload(lua_State* L) {
}
int32_t debuginfo(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
return 0;
}
int32_t debugprint(lua_State* L) {