mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-12-12 03:02:30 +00:00
feat(ui): implement CSimpleFrame_GetAttribute script method
This commit is contained in:
parent
88f2cb7e5f
commit
19feaf57d3
3 changed files with 75 additions and 17 deletions
|
|
@ -706,22 +706,14 @@ void CSimpleFrame::LoadXML_Attributes(XMLNode* node, CStatus* status) {
|
||||||
while (child) {
|
while (child) {
|
||||||
auto childName = child->m_name.GetString();
|
auto childName = child->m_name.GetString();
|
||||||
if (SStrCmpI(childName, "Attribute", STORM_MAX_STR)) {
|
if (SStrCmpI(childName, "Attribute", STORM_MAX_STR)) {
|
||||||
const char* frameName = this->GetName();
|
status->Add(STATUS_WARNING, "Frame %s: Unknown attributes element %s", this->GetDisplayName(), childName);
|
||||||
if (!frameName) {
|
|
||||||
frameName = "<unnamed>";
|
|
||||||
}
|
|
||||||
status->Add(STATUS_WARNING, "Frame %s: Unknown attributes element %s", frameName, childName);
|
|
||||||
child = child->m_next;
|
child = child->m_next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto name = child->GetAttributeByName("name");
|
auto name = child->GetAttributeByName("name");
|
||||||
if (!name) {
|
if (!name) {
|
||||||
const char* frameName = this->GetName();
|
status->Add(STATUS_WARNING, "Frame %s: unnamed attribute element", this->GetDisplayName());
|
||||||
if (!frameName) {
|
|
||||||
frameName = "<unnamed>";
|
|
||||||
}
|
|
||||||
status->Add(STATUS_WARNING, "Frame %s: unnamed attribute element", frameName);
|
|
||||||
child = child->m_next;
|
child = child->m_next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -733,11 +725,7 @@ void CSimpleFrame::LoadXML_Attributes(XMLNode* node, CStatus* status) {
|
||||||
|
|
||||||
auto value = child->GetAttributeByName("value");
|
auto value = child->GetAttributeByName("value");
|
||||||
if (!value || !SStrCmpI(value, "nil", STORM_MAX_STR)) {
|
if (!value || !SStrCmpI(value, "nil", STORM_MAX_STR)) {
|
||||||
const char* frameName = this->GetName();
|
status->Add(STATUS_WARNING, "Frame %s: attribute element named %s missing value", this->GetDisplayName(), name);
|
||||||
if (!frameName) {
|
|
||||||
frameName = "<unnamed>";
|
|
||||||
}
|
|
||||||
status->Add(STATUS_WARNING, "Frame %s: attribute element named %s missing value", frameName, name);
|
|
||||||
child = child->m_next;
|
child = child->m_next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -1651,3 +1639,12 @@ void CSimpleFrame::UnregisterRegion(CSimpleRegion* region) {
|
||||||
|
|
||||||
this->m_regions.UnlinkNode(region);
|
this->m_regions.UnlinkNode(region);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSimpleFrame::GetAttribute(const char* name, int32_t& luaRef) {
|
||||||
|
auto attribute = this->m_attributes.Ptr(name);
|
||||||
|
if (!attribute || attribute->luaRef == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
luaRef = attribute->luaRef;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ struct lua_State;
|
||||||
|
|
||||||
class FRAMEATTR : public TSHashObject<FRAMEATTR, HASHKEY_STRI> {
|
class FRAMEATTR : public TSHashObject<FRAMEATTR, HASHKEY_STRI> {
|
||||||
public:
|
public:
|
||||||
int32_t luaRef;
|
int32_t luaRef = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CSimpleFrame : public CScriptRegion {
|
class CSimpleFrame : public CScriptRegion {
|
||||||
|
|
@ -165,6 +165,7 @@ class CSimpleFrame : public CScriptRegion {
|
||||||
void Show();
|
void Show();
|
||||||
int32_t TestHitRect(const C2Vector& pt);
|
int32_t TestHitRect(const C2Vector& pt);
|
||||||
void UnregisterForEvents(int32_t a2);
|
void UnregisterForEvents(int32_t a2);
|
||||||
|
bool GetAttribute(const char* name, int32_t& luaRef);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,67 @@ int32_t CSimpleFrame_CanChangeAttributes(lua_State* L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CSimpleFrame_GetAttribute(lua_State* L) {
|
int32_t CSimpleFrame_GetAttribute(lua_State* L) {
|
||||||
WHOA_UNIMPLEMENTED(0);
|
auto type = CSimpleFrame::GetObjectType();
|
||||||
|
auto frame = static_cast<CSimpleFrame*>(FrameScript_GetObjectThis(L, type));
|
||||||
|
|
||||||
|
if (lua_gettop(L) == 4 && lua_isstring(L, 3)) {
|
||||||
|
size_t prefixLength;
|
||||||
|
size_t nameLength;
|
||||||
|
size_t suffixLength;
|
||||||
|
auto prefix = lua_tolstring(L, 2, &prefixLength);
|
||||||
|
auto name = lua_tolstring(L, 3, &nameLength);
|
||||||
|
auto suffix = lua_tolstring(L, 4, &suffixLength);
|
||||||
|
|
||||||
|
int32_t luaRef = -1;
|
||||||
|
char fullName[256];
|
||||||
|
|
||||||
|
size_t offset = 0;
|
||||||
|
offset += SStrNCopy(&fullName[offset], prefix, prefixLength, sizeof(fullName) - offset);
|
||||||
|
offset += SStrNCopy(&fullName[offset], name, nameLength, sizeof(fullName) - offset);
|
||||||
|
offset += SStrNCopy(&fullName[offset], suffix, suffixLength, sizeof(fullName) - offset);
|
||||||
|
|
||||||
|
if (frame->GetAttribute(fullName, luaRef)) {
|
||||||
|
lua_rawgeti(L, LUA_REGISTRYINDEX, luaRef);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset = 0;
|
||||||
|
offset += SStrNCopy(&fullName[offset], prefix, prefixLength, sizeof(fullName) - offset - 1);
|
||||||
|
offset += SStrNCopy(&fullName[offset], name, nameLength, sizeof(fullName) - offset - 1);
|
||||||
|
fullName[offset++] = '*';
|
||||||
|
fullName[offset++] = '\0';
|
||||||
|
|
||||||
|
if (frame->GetAttribute(fullName, luaRef)) {
|
||||||
|
lua_rawgeti(L, LUA_REGISTRYINDEX, luaRef);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset = 0;
|
||||||
|
fullName[offset++] = '*';
|
||||||
|
offset += SStrNCopy(&fullName[offset], name, nameLength, sizeof(fullName) - offset - 1);
|
||||||
|
fullName[offset++] = '*';
|
||||||
|
fullName[offset++] = '\0';
|
||||||
|
|
||||||
|
if (frame->GetAttribute(fullName, luaRef) || frame->GetAttribute(name, luaRef)) {
|
||||||
|
lua_rawgeti(L, LUA_REGISTRYINDEX, luaRef);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pushnil(L);
|
||||||
|
} else {
|
||||||
|
if (!lua_isstring(L, 2)) {
|
||||||
|
return luaL_error(L, "Usage: %s:GetAttribute(\"name\")", frame->GetDisplayName());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto name = lua_tolstring(L, 2, nullptr);
|
||||||
|
int32_t luaRef = -1;
|
||||||
|
if (frame->GetAttribute(name, luaRef)) {
|
||||||
|
lua_rawgeti(L, LUA_REGISTRYINDEX, luaRef);
|
||||||
|
} else {
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CSimpleFrame_SetAttribute(lua_State* L) {
|
int32_t CSimpleFrame_SetAttribute(lua_State* L) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue