mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-12-12 03:02:30 +00:00
feat(ui): implement type-related CSimpleFontString script methods
This commit is contained in:
parent
a50ca69e8c
commit
f0634dded2
8 changed files with 99 additions and 5 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
#include "ui/CSimpleFontScript.hpp"
|
#include "ui/CSimpleFontScript.hpp"
|
||||||
|
#include "ui/CSimpleFontString.hpp"
|
||||||
#include "util/Unimplemented.hpp"
|
#include "util/Unimplemented.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
int32_t CSimpleFontString::s_count;
|
int32_t CSimpleFontString::s_count;
|
||||||
int32_t CSimpleFontString::s_metatable;
|
int32_t CSimpleFontString::s_metatable;
|
||||||
int32_t CSimpleFontString::s_objectType;
|
int32_t CSimpleFontString::s_objectType;
|
||||||
|
const char* CSimpleFontString::s_objectTypeName = "FontString";
|
||||||
|
|
||||||
void CSimpleFontString::CreateScriptMetaTable() {
|
void CSimpleFontString::CreateScriptMetaTable() {
|
||||||
lua_State* L = FrameScript_GetContext();
|
lua_State* L = FrameScript_GetContext();
|
||||||
|
|
@ -127,6 +128,16 @@ bool CSimpleFontString::IsA(int32_t type) {
|
||||||
|| type == CScriptObject::s_objectType;
|
|| type == CScriptObject::s_objectType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSimpleFontString::IsA(const char* typeName) {
|
||||||
|
return !SStrCmpI(typeName, CSimpleFontString::s_objectTypeName, STORM_MAX_STR)
|
||||||
|
|| !SStrCmpI(typeName, CScriptRegion::s_objectTypeName, STORM_MAX_STR)
|
||||||
|
|| !SStrCmpI(typeName, CScriptObject::s_objectTypeName, STORM_MAX_STR);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* CSimpleFontString::GetObjectTypeName() {
|
||||||
|
return CSimpleFontString::s_objectTypeName;
|
||||||
|
}
|
||||||
|
|
||||||
void CSimpleFontString::FontObjectUpdated(CSimpleFontStringAttributes& attributes) {
|
void CSimpleFontString::FontObjectUpdated(CSimpleFontStringAttributes& attributes) {
|
||||||
attributes.Update(this, this->m_fontableFlags);
|
attributes.Update(this, this->m_fontableFlags);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ class CSimpleFontString : public CSimpleRegion, public CSimpleFontable {
|
||||||
static int32_t s_count;
|
static int32_t s_count;
|
||||||
static int32_t s_metatable;
|
static int32_t s_metatable;
|
||||||
static int32_t s_objectType;
|
static int32_t s_objectType;
|
||||||
|
static const char* s_objectTypeName;
|
||||||
|
|
||||||
// Static functions
|
// Static functions
|
||||||
static void CreateScriptMetaTable();
|
static void CreateScriptMetaTable();
|
||||||
|
|
@ -43,6 +44,8 @@ class CSimpleFontString : public CSimpleRegion, public CSimpleFontable {
|
||||||
// Virtual member functions
|
// Virtual member functions
|
||||||
virtual ~CSimpleFontString();
|
virtual ~CSimpleFontString();
|
||||||
virtual bool IsA(int32_t type);
|
virtual bool IsA(int32_t type);
|
||||||
|
virtual bool IsA(const char* typeName);
|
||||||
|
virtual const char* GetObjectTypeName();
|
||||||
virtual int32_t GetScriptMetaTable();
|
virtual int32_t GetScriptMetaTable();
|
||||||
virtual void LoadXML(XMLNode* node, CStatus* status);
|
virtual void LoadXML(XMLNode* node, CStatus* status);
|
||||||
virtual void OnColorChanged(bool a2);
|
virtual void OnColorChanged(bool a2);
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,74 @@
|
||||||
#include "ui/CSimpleFontStringScript.hpp"
|
#include "ui/CSimpleFontStringScript.hpp"
|
||||||
#include "ui/CSimpleFont.hpp"
|
#include "ui/CSimpleFont.hpp"
|
||||||
#include "ui/CSimpleFontString.hpp"
|
#include "ui/CSimpleFontString.hpp"
|
||||||
|
#include "ui/Util.hpp"
|
||||||
#include "util/Lua.hpp"
|
#include "util/Lua.hpp"
|
||||||
#include "util/Unimplemented.hpp"
|
#include "util/Unimplemented.hpp"
|
||||||
|
#include "util/StringTo.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
int32_t CSimpleFontString_IsObjectType(lua_State* L) {
|
int32_t CSimpleFontString_IsObjectType(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CSimpleFontString::GetObjectType();
|
||||||
|
auto string = static_cast<CSimpleFontString*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
|
||||||
|
if (!lua_isstring(L, 2)) {
|
||||||
|
return luaL_error(L, "Usage: %s:IsObjectType(\"TYPE\")", string->GetDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string->IsA(lua_tolstring(L, 2, nullptr))) {
|
||||||
|
lua_pushnumber(L, 1.0);
|
||||||
|
} else {
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CSimpleFontString_GetObjectType(lua_State* L) {
|
int32_t CSimpleFontString_GetObjectType(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CSimpleFontString::GetObjectType();
|
||||||
|
auto string = static_cast<CSimpleFontString*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
lua_pushstring(L, string->GetObjectTypeName());
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CSimpleFontString_GetDrawLayer(lua_State* L) {
|
int32_t CSimpleFontString_GetDrawLayer(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CSimpleFontString::GetObjectType();
|
||||||
|
auto string = static_cast<CSimpleFontString*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
auto layer = DrawLayerToString(string->m_drawlayer);
|
||||||
|
lua_pushstring(L, layer);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CSimpleFontString_SetDrawLayer(lua_State* L) {
|
int32_t CSimpleFontString_SetDrawLayer(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CSimpleFontString::GetObjectType();
|
||||||
|
auto string = static_cast<CSimpleFontString*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
|
||||||
|
const char* strlayer = lua_isstring(L, 2) ? lua_tostring(L, 2) : nullptr;
|
||||||
|
|
||||||
|
int32_t layer = 0;
|
||||||
|
if (!strlayer || !StringToDrawLayer(strlayer, layer)) {
|
||||||
|
return luaL_error(L, "Usage: %s:SetDrawLayer(\"layer\")", string->GetDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
string->SetFrame(string->m_parent, layer, string->m_shown);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CSimpleFontString_SetVertexColor(lua_State* L) {
|
int32_t CSimpleFontString_SetVertexColor(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CSimpleFontString::GetObjectType();
|
||||||
|
auto string = static_cast<CSimpleFontString*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
|
||||||
|
CImVector color;
|
||||||
|
string->GetVertexColor(color);
|
||||||
|
|
||||||
|
CImVector newColor;
|
||||||
|
FrameScript_GetColor(L, 2, newColor);
|
||||||
|
if (!lua_isnumber(L, 5)) {
|
||||||
|
newColor.a = color.a;
|
||||||
|
}
|
||||||
|
|
||||||
|
string->SetVertexColor(color);
|
||||||
|
// TODO: Some flag should be set
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CSimpleFontString_GetAlpha(lua_State* L) {
|
int32_t CSimpleFontString_GetAlpha(lua_State* L) {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
int32_t CSimpleFrame::s_metatable;
|
int32_t CSimpleFrame::s_metatable;
|
||||||
int32_t CSimpleFrame::s_objectType;
|
int32_t CSimpleFrame::s_objectType;
|
||||||
|
const char* CSimpleFrame::s_objectTypeName = "Frame";
|
||||||
|
|
||||||
int32_t CSimpleFrame::GetObjectType() {
|
int32_t CSimpleFrame::GetObjectType() {
|
||||||
if (!CSimpleFrame::s_objectType) {
|
if (!CSimpleFrame::s_objectType) {
|
||||||
|
|
@ -654,6 +655,16 @@ bool CSimpleFrame::IsA(int32_t type) {
|
||||||
|| type == CScriptObject::s_objectType;
|
|| type == CScriptObject::s_objectType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSimpleFrame::IsA(const char* typeName) {
|
||||||
|
return !SStrCmpI(typeName, CSimpleFrame::s_objectTypeName, STORM_MAX_STR)
|
||||||
|
|| !SStrCmpI(typeName, CScriptRegion::s_objectTypeName, STORM_MAX_STR)
|
||||||
|
|| !SStrCmpI(typeName, CScriptObject::s_objectTypeName, STORM_MAX_STR);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* CSimpleFrame::GetObjectTypeName() {
|
||||||
|
return CSimpleFrame::s_objectTypeName;
|
||||||
|
}
|
||||||
|
|
||||||
void CSimpleFrame::EnableEvent(CSimpleEventType eventType, int32_t priority) {
|
void CSimpleFrame::EnableEvent(CSimpleEventType eventType, int32_t priority) {
|
||||||
if ((1 << eventType) & this->m_eventmask) {
|
if ((1 << eventType) & this->m_eventmask) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ class CSimpleFrame : public CScriptRegion {
|
||||||
// Static members
|
// Static members
|
||||||
static int32_t s_metatable;
|
static int32_t s_metatable;
|
||||||
static int32_t s_objectType;
|
static int32_t s_objectType;
|
||||||
|
static const char* s_objectTypeName;
|
||||||
|
|
||||||
// Static functions
|
// Static functions
|
||||||
static void CreateScriptMetaTable();
|
static void CreateScriptMetaTable();
|
||||||
|
|
@ -91,6 +92,8 @@ class CSimpleFrame : public CScriptRegion {
|
||||||
virtual ~CSimpleFrame();
|
virtual ~CSimpleFrame();
|
||||||
virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data);
|
virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data);
|
||||||
virtual bool IsA(int32_t type);
|
virtual bool IsA(int32_t type);
|
||||||
|
virtual bool IsA(const char* typeName);
|
||||||
|
virtual const char* GetObjectTypeName();
|
||||||
virtual int32_t GetScriptMetaTable();
|
virtual int32_t GetScriptMetaTable();
|
||||||
virtual void LoadXML(XMLNode* node, CStatus* status);
|
virtual void LoadXML(XMLNode* node, CStatus* status);
|
||||||
virtual void PreOnAnimUpdate();
|
virtual void PreOnAnimUpdate();
|
||||||
|
|
|
||||||
|
|
@ -126,3 +126,20 @@ const char* AnchorPointToString(int32_t point) {
|
||||||
return "ANCHOR_NONE";
|
return "ANCHOR_NONE";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* DrawLayerToString(int32_t layer) {
|
||||||
|
switch (layer) {
|
||||||
|
case 0:
|
||||||
|
return "BACKGROUND";
|
||||||
|
case 1:
|
||||||
|
return "BORDER";
|
||||||
|
case 2:
|
||||||
|
return "ARTWORK";
|
||||||
|
case 3:
|
||||||
|
return "OVERLAY";
|
||||||
|
case 4:
|
||||||
|
return "HIGHLIGHT";
|
||||||
|
default:
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,4 +17,6 @@ const char* OrientationToString(uint32_t orientation);
|
||||||
|
|
||||||
const char* AnchorPointToString(int32_t point);
|
const char* AnchorPointToString(int32_t point);
|
||||||
|
|
||||||
|
const char* DrawLayerToString(int32_t layer);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue