mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-12-08 18:36:00 +03:00
Compare commits
3 Commits
9d2b94b0cd
...
3d8cd8b87f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d8cd8b87f | ||
|
|
55bcd21c1f | ||
|
|
5e54cca3fa |
@ -1,10 +1,12 @@
|
|||||||
#include "gameui/CGTooltip.hpp"
|
#include "gameui/CGTooltip.hpp"
|
||||||
#include "gameui/CGTooltipScript.hpp"
|
#include "gameui/CGTooltipScript.hpp"
|
||||||
|
#include "ui/CSimpleFontString.hpp"
|
||||||
#include "util/Lua.hpp"
|
#include "util/Lua.hpp"
|
||||||
#include <bc/Memory.hpp>
|
#include <bc/Memory.hpp>
|
||||||
|
|
||||||
int32_t CGTooltip::s_metatable;
|
int32_t CGTooltip::s_metatable;
|
||||||
int32_t CGTooltip::s_objectType;
|
int32_t CGTooltip::s_objectType;
|
||||||
|
CImVector CGTooltip::s_defaultColor{ 0, 210, 255, 255 };
|
||||||
|
|
||||||
CSimpleFrame* CGTooltip::Create(CSimpleFrame* parent) {
|
CSimpleFrame* CGTooltip::Create(CSimpleFrame* parent) {
|
||||||
// TODO: Data = CDataAllocator__GetData(0, ".?AVCGTooltip@@", -2);
|
// TODO: Data = CDataAllocator__GetData(0, ".?AVCGTooltip@@", -2);
|
||||||
@ -34,6 +36,64 @@ CGTooltip::CGTooltip(CSimpleFrame* parent)
|
|||||||
: CSimpleFrame(parent) {
|
: CSimpleFrame(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
// TODO: this->unk77 = 0;
|
||||||
|
|
||||||
|
if (this->m_owner != owner
|
||||||
|
|| this->m_anchorPoint != anchorpoint
|
||||||
|
|| this->m_offsetX != xoffset
|
||||||
|
|| this->m_offsetY != yoffset) {
|
||||||
|
this->m_offsetX = xoffset;
|
||||||
|
this->m_offsetY = yoffset;
|
||||||
|
this->m_owner = owner;
|
||||||
|
this->m_anchorPoint = owner ? anchorpoint : ANCHOR_NONE;
|
||||||
|
this->ResetPosition(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
if ((!leftText || !*leftText) && (!rightText || !*rightText)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this->m_linesMax) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->m_lines == this->m_linesMax - 1) {
|
||||||
|
char name[256];
|
||||||
|
SStrPrintf(name, sizeof(name), "%sTextLeft%d", this->GetDisplayName(), this->m_linesMax + 1);
|
||||||
|
// TODO: CDataAllocator
|
||||||
|
auto leftFontString = NEW(CSimpleFontString, this, 2, 1);
|
||||||
|
leftFontString->SetName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool CGTooltip::IsA(int32_t type) {
|
bool CGTooltip::IsA(int32_t type) {
|
||||||
return type == CGTooltip::s_objectType
|
return type == CGTooltip::s_objectType
|
||||||
|| type == CSimpleFrame::s_objectType
|
|| type == CSimpleFrame::s_objectType
|
||||||
|
|||||||
@ -4,11 +4,29 @@
|
|||||||
#include "ui/CSimpleFrame.hpp"
|
#include "ui/CSimpleFrame.hpp"
|
||||||
#include "ui/CSimpleTop.hpp"
|
#include "ui/CSimpleTop.hpp"
|
||||||
|
|
||||||
|
class CSimpleFontString;
|
||||||
|
|
||||||
|
enum TOOLTIP_ANCHORPOINT {
|
||||||
|
ANCHOR_LEFT = 0,
|
||||||
|
ANCHOR_RIGHT,
|
||||||
|
ANCHOR_BOTTOMLEFT,
|
||||||
|
ANCHOR_BOTTOM,
|
||||||
|
ANCHOR_BOTTOMRIGHT,
|
||||||
|
ANCHOR_TOPLEFT,
|
||||||
|
ANCHOR_TOP,
|
||||||
|
ANCHOR_TOPRIGHT,
|
||||||
|
ANCHOR_CURSOR,
|
||||||
|
ANCHOR_NONE,
|
||||||
|
ANCHOR_PRESERVE,
|
||||||
|
ANCHOR_CURSOR_RIGHT,
|
||||||
|
};
|
||||||
|
|
||||||
class CGTooltip : public CSimpleFrame {
|
class CGTooltip : public CSimpleFrame {
|
||||||
public:
|
public:
|
||||||
// Static variables
|
// Static variables
|
||||||
static int32_t s_metatable;
|
static int32_t s_metatable;
|
||||||
static int32_t s_objectType;
|
static int32_t s_objectType;
|
||||||
|
static CImVector s_defaultColor;
|
||||||
|
|
||||||
// Static functions
|
// Static functions
|
||||||
static CSimpleFrame* Create(CSimpleFrame* parent);
|
static CSimpleFrame* Create(CSimpleFrame* parent);
|
||||||
@ -18,6 +36,17 @@ class CGTooltip : public CSimpleFrame {
|
|||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
CGTooltip(CSimpleFrame* parent);
|
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 member functions
|
||||||
virtual bool IsA(int32_t type);
|
virtual bool IsA(int32_t type);
|
||||||
@ -25,6 +54,18 @@ class CGTooltip : public CSimpleFrame {
|
|||||||
virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data);
|
virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data);
|
||||||
|
|
||||||
// Member variables
|
// Member variables
|
||||||
|
CSimpleFrame* m_owner = nullptr;
|
||||||
|
TOOLTIP_ANCHORPOINT m_anchorPoint = ANCHOR_NONE;
|
||||||
|
uint32_t m_lines = 0;
|
||||||
|
uint32_t m_linesMax = 0;
|
||||||
|
TSFixedArray<CSimpleFontString*> m_leftStrings;
|
||||||
|
TSFixedArray<CSimpleFontString*> m_rightStrings;
|
||||||
|
TSFixedArray<int32_t> m_wrapLine;
|
||||||
|
float m_padding = 0.0f;
|
||||||
|
float m_minWidth = 0.0f;
|
||||||
|
uint32_t m_minWidthForced = 0;
|
||||||
|
float m_offsetX = 0.0f;
|
||||||
|
float m_offsetY = 0.0f;
|
||||||
ScriptIx m_onTooltipSetDefaultAnchor;
|
ScriptIx m_onTooltipSetDefaultAnchor;
|
||||||
ScriptIx m_onTooltipCleared;
|
ScriptIx m_onTooltipCleared;
|
||||||
ScriptIx m_onTooltipAddMoney;
|
ScriptIx m_onTooltipAddMoney;
|
||||||
|
|||||||
@ -1,26 +1,83 @@
|
|||||||
#include "gameui/CGTooltipScript.hpp"
|
#include "gameui/CGTooltipScript.hpp"
|
||||||
#include "gameui/CGTooltip.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/Lua.hpp"
|
||||||
#include "util/Unimplemented.hpp"
|
#include "util/Unimplemented.hpp"
|
||||||
|
#include "util/StringTo.hpp"
|
||||||
|
|
||||||
static int32_t Script_AddFontStrings(lua_State* L) {
|
static int32_t Script_AddFontStrings(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CGTooltip::GetObjectType();
|
||||||
|
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
|
||||||
|
CSimpleFontString* arguments[2] = {};
|
||||||
|
|
||||||
|
for (int32_t i = 2; i < 4; ++i) {
|
||||||
|
if (lua_type(L, i) != LUA_TTABLE) {
|
||||||
|
return luaL_error(L, "Usage: %s:AddFontStrings(leftstring, rightstring)", tooltip->GetDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_rawgeti(L, i, 0);
|
||||||
|
auto fontString = static_cast<CSimpleFontString*>(lua_touserdata(L, -1));
|
||||||
|
lua_settop(L, -2);
|
||||||
|
|
||||||
|
if (!fontString) {
|
||||||
|
return luaL_error(L, "%s:AddFontStrings(): Couldn't find 'this' in fontstring", tooltip->GetDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fontString->IsA(CSimpleFontString::GetObjectType())) {
|
||||||
|
return luaL_error(L, "%s:AddFontStrings(): Wrong object type, expected fontstring", tooltip->GetDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
arguments[i - 2] = fontString;
|
||||||
|
}
|
||||||
|
|
||||||
|
tooltip->AddFontStrings(arguments[0], arguments[1]);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Script_SetMinimumWidth(lua_State* L) {
|
static int32_t Script_SetMinimumWidth(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CGTooltip::GetObjectType();
|
||||||
|
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
|
||||||
|
if (!lua_isnumber(L, 2)) {
|
||||||
|
return luaL_error(L, "Usage: %s:SetMinimumWidth(width [,force])", tooltip->GetDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
tooltip->m_minWidth = lua_tonumber(L, 2);
|
||||||
|
tooltip->m_minWidthForced = StringToBOOL(L, 3, 0);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Script_GetMinimumWidth(lua_State* L) {
|
static int32_t Script_GetMinimumWidth(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CGTooltip::GetObjectType();
|
||||||
|
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
lua_pushnumber(L, tooltip->m_minWidth);
|
||||||
|
if (tooltip->m_minWidthForced) {
|
||||||
|
lua_pushnumber(L, 1.0);
|
||||||
|
} else {
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Script_SetPadding(lua_State* L) {
|
static int32_t Script_SetPadding(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CGTooltip::GetObjectType();
|
||||||
|
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
|
||||||
|
float value = lua_tonumber(L, 2);
|
||||||
|
value /= CoordinateGetAspectCompensation() * 1024.0f;
|
||||||
|
tooltip->m_padding = NDCToDDCWidth(value);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Script_GetPadding(lua_State* L) {
|
static int32_t Script_GetPadding(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CGTooltip::GetObjectType();
|
||||||
|
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
lua_pushnumber(L, tooltip->m_padding);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Script_IsOwned(lua_State* L) {
|
static int32_t Script_IsOwned(lua_State* L) {
|
||||||
@ -32,7 +89,7 @@ static int32_t Script_IsOwned(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lua_rawgeti(L, 2, 0);
|
lua_rawgeti(L, 2, 0);
|
||||||
auto frame = static_cast<CScriptObject*>(lua_touserdata(L, -1));
|
auto frame = static_cast<CSimpleFrame*>(lua_touserdata(L, -1));
|
||||||
lua_settop(L, -2);
|
lua_settop(L, -2);
|
||||||
|
|
||||||
if (!frame) {
|
if (!frame) {
|
||||||
@ -43,7 +100,7 @@ static int32_t Script_IsOwned(lua_State* L) {
|
|||||||
return luaL_error(L, "%s:IsOwned(): Wrong object type, expected frame", tooltip->GetDisplayName());
|
return luaL_error(L, "%s:IsOwned(): Wrong object type, expected frame", tooltip->GetDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tooltip->m_parent == frame) {
|
if (tooltip->m_owner == frame) {
|
||||||
lua_pushnumber(L, 1.0);
|
lua_pushnumber(L, 1.0);
|
||||||
} else {
|
} else {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
@ -55,33 +112,147 @@ static int32_t Script_GetOwner(lua_State* L) {
|
|||||||
auto type = CGTooltip::GetObjectType();
|
auto type = CGTooltip::GetObjectType();
|
||||||
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
|
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
|
||||||
// TODO
|
if (tooltip->m_owner) {
|
||||||
lua_pushnil(L);
|
if (!tooltip->m_owner->lua_registered) {
|
||||||
|
tooltip->m_owner->RegisterScriptObject(nullptr);
|
||||||
|
}
|
||||||
|
lua_rawgeti(L, LUA_REGISTRYINDEX, tooltip->m_owner->lua_objectRef);
|
||||||
|
} else {
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Script_SetOwner(lua_State* L) {
|
static int32_t Script_SetOwner(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CGTooltip::GetObjectType();
|
||||||
|
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
|
||||||
|
tooltip->Hide();
|
||||||
|
|
||||||
|
if (lua_type(L, 2) != LUA_TTABLE) {
|
||||||
|
return luaL_error(L, "Usage: %s:SetOwner(frame)", tooltip->GetDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_rawgeti(L, 2, 0);
|
||||||
|
auto frame = static_cast<CSimpleFrame*>(lua_touserdata(L, -1));
|
||||||
|
lua_settop(L, -2);
|
||||||
|
|
||||||
|
if (!frame) {
|
||||||
|
return luaL_error(L, "%s:SetOwner(): Couldn't find 'this' in frame object", tooltip->GetDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!frame->IsA(CSimpleFrame::GetObjectType())) {
|
||||||
|
return luaL_error(L, "%s:SetOwner(): Wrong object type, expected frame", tooltip->GetDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame == tooltip) {
|
||||||
|
return luaL_error(L, "%s:SetOwner(): Can't set owner to self", tooltip->GetDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t anchorPoint = 0;
|
||||||
|
if (lua_isstring(L, 3)) {
|
||||||
|
StringToAnchorPoint(lua_tolstring(L, 3, nullptr), anchorPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
float xoffset = 0.0f;
|
||||||
|
if (lua_isnumber(L, 4)) {
|
||||||
|
float value = lua_tonumber(L, 4);
|
||||||
|
value /= CoordinateGetAspectCompensation() * 1024.0f;
|
||||||
|
xoffset = NDCToDDCWidth(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
float yoffset = 0.0f;
|
||||||
|
if (lua_isnumber(L, 5)) {
|
||||||
|
float value = lua_tonumber(L, 5);
|
||||||
|
value /= CoordinateGetAspectCompensation() * 1024.0f;
|
||||||
|
yoffset = NDCToDDCWidth(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
tooltip->SetOwner(frame, static_cast<TOOLTIP_ANCHORPOINT>(anchorPoint), xoffset, yoffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Script_GetAnchorType(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) {
|
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) {
|
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) {
|
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) {
|
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) {
|
static int32_t Script_AddTexture(lua_State* L) {
|
||||||
@ -89,7 +260,25 @@ static int32_t Script_AddTexture(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int32_t Script_SetText(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) {
|
static int32_t Script_AppendText(lua_State* L) {
|
||||||
|
|||||||
@ -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) {
|
void FrameScript_GetColor(lua_State* L, int32_t idx, CImVector& color) {
|
||||||
float r = lua_tonumber(L, idx + 0);
|
float r = lua_tonumber(L, idx + 0);
|
||||||
r = std::max(0.0f, std::min(r, 1.0f));
|
r = std::max(0.0f, std::min(r, 1.0f));
|
||||||
|
|||||||
@ -77,6 +77,8 @@ int32_t FrameScript_ExecuteFile(const char* filePath, const char* a2, MD5_CTX* m
|
|||||||
|
|
||||||
void FrameScript_Flush();
|
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);
|
void FrameScript_GetColor(lua_State* L, int32_t idx, CImVector& color);
|
||||||
|
|
||||||
int32_t SetDecimalConversion(int32_t enabled);
|
int32_t SetDecimalConversion(int32_t enabled);
|
||||||
|
|||||||
@ -97,3 +97,32 @@ const char* OrientationToString(uint32_t orientation) {
|
|||||||
return "UNKNOWN";
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -15,4 +15,6 @@ int32_t StringToFrameStrata(const char* string, FRAME_STRATA& strata);
|
|||||||
|
|
||||||
const char* OrientationToString(uint32_t orientation);
|
const char* OrientationToString(uint32_t orientation);
|
||||||
|
|
||||||
|
const char* AnchorPointToString(int32_t point);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "util/StringTo.hpp"
|
#include "util/StringTo.hpp"
|
||||||
#include "util/Lua.hpp"
|
#include "util/Lua.hpp"
|
||||||
#include <storm/String.hpp>
|
#include <storm/String.hpp>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
uint64_t StringToClickAction(const char* actionStr) {
|
uint64_t StringToClickAction(const char* actionStr) {
|
||||||
if (!actionStr || !*actionStr) {
|
if (!actionStr || !*actionStr) {
|
||||||
@ -170,3 +171,31 @@ bool StringToOrientation(const char* string, uint32_t& orientation) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StringToAnchorPoint(const char* string, int32_t& point) {
|
||||||
|
static std::pair<int32_t, const char*> table[12] = {
|
||||||
|
{ 0, "ANCHOR_LEFT" },
|
||||||
|
{ 1, "ANCHOR_RIGHT" },
|
||||||
|
{ 2, "ANCHOR_BOTTOMLEFT" },
|
||||||
|
{ 3, "ANCHOR_BOTTOM" },
|
||||||
|
{ 4, "ANCHOR_BOTTOMRIGHT" },
|
||||||
|
{ 5, "ANCHOR_TOPLEFT" },
|
||||||
|
{ 6, "ANCHOR_TOP" },
|
||||||
|
{ 7, "ANCHOR_TOPRIGHT" },
|
||||||
|
{ 8, "ANCHOR_CURSOR" },
|
||||||
|
{ 9, "ANCHOR_NONE" },
|
||||||
|
{ 10, "ANCHOR_PRESERVE" },
|
||||||
|
{ 11, "ANCHOR_CURSOR_RIGHT" },
|
||||||
|
};
|
||||||
|
|
||||||
|
point = 0;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < 12; ++i) {
|
||||||
|
if (!SStrCmpI(string, table[i].second, STORM_MAX_STR)) {
|
||||||
|
point = table[i].first;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@ -19,4 +19,6 @@ int32_t StringToJustify(const char*, uint32_t&);
|
|||||||
|
|
||||||
bool StringToOrientation(const char* string, uint32_t& orientation);
|
bool StringToOrientation(const char* string, uint32_t& orientation);
|
||||||
|
|
||||||
|
bool StringToAnchorPoint(const char* string, int32_t& point);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user