Compare commits

..

No commits in common. "3d8cd8b87f833de75b9365bc3c5abb9e3767a22b" and "9d2b94b0cdc5e5638a579419f65fb601401a511f" have entirely different histories.

9 changed files with 16 additions and 383 deletions

View File

@ -1,12 +1,10 @@
#include "gameui/CGTooltip.hpp"
#include "gameui/CGTooltipScript.hpp"
#include "ui/CSimpleFontString.hpp"
#include "util/Lua.hpp"
#include <bc/Memory.hpp>
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);
@ -36,64 +34,6 @@ CGTooltip::CGTooltip(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) {
return type == CGTooltip::s_objectType
|| type == CSimpleFrame::s_objectType

View File

@ -4,29 +4,11 @@
#include "ui/CSimpleFrame.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 {
public:
// Static variables
static int32_t s_metatable;
static int32_t s_objectType;
static CImVector s_defaultColor;
// Static functions
static CSimpleFrame* Create(CSimpleFrame* parent);
@ -36,17 +18,6 @@ class CGTooltip : public CSimpleFrame {
// Member functions
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);
@ -54,18 +25,6 @@ class CGTooltip : public CSimpleFrame {
virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data);
// 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_onTooltipCleared;
ScriptIx m_onTooltipAddMoney;

View File

@ -1,83 +1,26 @@
#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"
#include "util/StringTo.hpp"
static int32_t Script_AddFontStrings(lua_State* L) {
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;
WHOA_UNIMPLEMENTED(0);
}
static int32_t Script_SetMinimumWidth(lua_State* L) {
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;
WHOA_UNIMPLEMENTED(0);
}
static int32_t Script_GetMinimumWidth(lua_State* L) {
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;
WHOA_UNIMPLEMENTED(0);
}
static int32_t Script_SetPadding(lua_State* L) {
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;
WHOA_UNIMPLEMENTED(0);
}
static int32_t Script_GetPadding(lua_State* L) {
auto type = CGTooltip::GetObjectType();
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
lua_pushnumber(L, tooltip->m_padding);
return 1;
WHOA_UNIMPLEMENTED(0);
}
static int32_t Script_IsOwned(lua_State* L) {
@ -89,7 +32,7 @@ static int32_t Script_IsOwned(lua_State* L) {
}
lua_rawgeti(L, 2, 0);
auto frame = static_cast<CSimpleFrame*>(lua_touserdata(L, -1));
auto frame = static_cast<CScriptObject*>(lua_touserdata(L, -1));
lua_settop(L, -2);
if (!frame) {
@ -100,7 +43,7 @@ static int32_t Script_IsOwned(lua_State* L) {
return luaL_error(L, "%s:IsOwned(): Wrong object type, expected frame", tooltip->GetDisplayName());
}
if (tooltip->m_owner == frame) {
if (tooltip->m_parent == frame) {
lua_pushnumber(L, 1.0);
} else {
lua_pushnil(L);
@ -112,147 +55,33 @@ static int32_t Script_GetOwner(lua_State* L) {
auto type = CGTooltip::GetObjectType();
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
if (tooltip->m_owner) {
if (!tooltip->m_owner->lua_registered) {
tooltip->m_owner->RegisterScriptObject(nullptr);
}
lua_rawgeti(L, LUA_REGISTRYINDEX, tooltip->m_owner->lua_objectRef);
} else {
// TODO
lua_pushnil(L);
}
return 1;
}
static int32_t Script_SetOwner(lua_State* L) {
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);
WHOA_UNIMPLEMENTED(0);
}
static int32_t Script_GetAnchorType(lua_State* L) {
auto type = CGTooltip::GetObjectType();
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
lua_pushstring(L, AnchorPointToString(tooltip->m_anchorPoint));
return 1;
WHOA_UNIMPLEMENTED(0);
}
static int32_t Script_SetAnchorType(lua_State* L) {
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;
WHOA_UNIMPLEMENTED(0);
}
static int32_t Script_ClearLines(lua_State* L) {
auto type = CGTooltip::GetObjectType();
auto tooltip = static_cast<CGTooltip*>(FrameScript_GetObjectThis(L, type));
tooltip->ClearTooltip();
return 0;
WHOA_UNIMPLEMENTED(0);
}
static int32_t Script_AddLine(lua_State* L) {
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;
WHOA_UNIMPLEMENTED(0);
}
static int32_t Script_AddDoubleLine(lua_State* L) {
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;
WHOA_UNIMPLEMENTED(0);
}
static int32_t Script_AddTexture(lua_State* L) {
@ -260,25 +89,7 @@ static int32_t Script_AddTexture(lua_State* L) {
}
static int32_t Script_SetText(lua_State* L) {
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;
WHOA_UNIMPLEMENTED(0);
}
static int32_t Script_AppendText(lua_State* L) {

View File

@ -447,19 +447,6 @@ 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,8 +77,6 @@ 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,32 +97,3 @@ 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,6 +15,4 @@ int32_t StringToFrameStrata(const char* string, FRAME_STRATA& strata);
const char* OrientationToString(uint32_t orientation);
const char* AnchorPointToString(int32_t point);
#endif

View File

@ -1,7 +1,6 @@
#include "util/StringTo.hpp"
#include "util/Lua.hpp"
#include <storm/String.hpp>
#include <utility>
uint64_t StringToClickAction(const char* actionStr) {
if (!actionStr || !*actionStr) {
@ -171,31 +170,3 @@ bool StringToOrientation(const char* string, uint32_t& orientation) {
}
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;
}

View File

@ -19,6 +19,4 @@ int32_t StringToJustify(const char*, uint32_t&);
bool StringToOrientation(const char* string, uint32_t& orientation);
bool StringToAnchorPoint(const char* string, int32_t& point);
#endif