mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2026-02-04 09:09:09 +00:00
feat(gameui): implement CVarGet* script methods
This commit is contained in:
parent
9d88498809
commit
fcc3be490c
8 changed files with 189 additions and 14 deletions
|
|
@ -180,11 +180,58 @@ int32_t CSimpleFrame_HasScript(lua_State* L) {
|
|||
}
|
||||
|
||||
int32_t CSimpleFrame_GetScript(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
int32_t type = CSimpleFrame::GetObjectType();
|
||||
CSimpleFrame* frame = static_cast<CSimpleFrame*>(FrameScript_GetObjectThis(L, type));
|
||||
|
||||
if (!lua_isstring(L, 2)) {
|
||||
return luaL_error(L, "Usage: %s:GetScript(\"type\")", frame->GetDisplayName());
|
||||
}
|
||||
|
||||
auto scriptName = lua_tolstring(L, 2, nullptr);
|
||||
|
||||
FrameScript_Object::ScriptData scriptData;
|
||||
auto script = frame->GetScriptByName(scriptName, scriptData);
|
||||
if (!script) {
|
||||
return luaL_error(L, "%s doesn't have a \"%s\" script", frame->GetDisplayName(), scriptName);
|
||||
}
|
||||
|
||||
// TODO: if (script->unk && lua_taintexpected && !lua_taintedclosure )
|
||||
|
||||
if (script->luaRef <= 0) {
|
||||
lua_pushnil(L);
|
||||
} else {
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, script->luaRef);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t CSimpleFrame_SetScript(lua_State* L) {
|
||||
// WARNING: This implementation breaks the client
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
|
||||
int32_t type = CSimpleFrame::GetObjectType();
|
||||
CSimpleFrame* frame = static_cast<CSimpleFrame*>(FrameScript_GetObjectThis(L, type));
|
||||
|
||||
if (!lua_isstring(L, 2) || (lua_type(L, 3) != LUA_TFUNCTION && lua_type(L, 3) != LUA_TNIL)) {
|
||||
return luaL_error(L, "Usage: %s:SetScript(\"type\", function)", frame->GetDisplayName());
|
||||
}
|
||||
|
||||
auto scriptName = lua_tolstring(L, 2, nullptr);
|
||||
|
||||
FrameScript_Object::ScriptData scriptData;
|
||||
auto script = frame->GetScriptByName(scriptName, scriptData);
|
||||
if (!script) {
|
||||
return luaL_error(L, "%s doesn't have a \"%s\" script", frame->GetDisplayName(), scriptName);
|
||||
}
|
||||
|
||||
if (script->luaRef) {
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, script->luaRef);
|
||||
}
|
||||
|
||||
auto ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
script->luaRef = ref <= 0 ? 0 : ref;
|
||||
// TODO: script->unk = lua_tainted;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t CSimpleFrame_HookScript(lua_State* L) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ class CSimpleStatusBar : public CSimpleFrame {
|
|||
virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data);
|
||||
|
||||
// Member variables
|
||||
float m_minValue = 0.0f;
|
||||
float m_maxValue = 0.0f;
|
||||
float m_value = 0.0f;
|
||||
ScriptIx m_onValueChanged;
|
||||
ScriptIx m_onMinMaxChanged;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,7 +12,11 @@ static int32_t Script_SetOrientation(lua_State* L) {
|
|||
}
|
||||
|
||||
static int32_t Script_GetMinMaxValues(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
auto type = CSimpleStatusBar::GetObjectType();
|
||||
auto statusBar = static_cast<CSimpleStatusBar*>(FrameScript_GetObjectThis(L, type));
|
||||
lua_pushnumber(L, statusBar->m_minValue);
|
||||
lua_pushnumber(L, statusBar->m_maxValue);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int32_t Script_SetMinMaxValues(lua_State* L) {
|
||||
|
|
@ -20,7 +24,10 @@ static int32_t Script_SetMinMaxValues(lua_State* L) {
|
|||
}
|
||||
|
||||
static int32_t Script_GetValue(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
auto type = CSimpleStatusBar::GetObjectType();
|
||||
auto statusBar = static_cast<CSimpleStatusBar*>(FrameScript_GetObjectThis(L, type));
|
||||
lua_pushnumber(L, statusBar->m_value);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int32_t Script_SetValue(lua_State* L) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue