Compare commits

..

No commits in common. "d9b6647c42e6715f60e4de9d1fa0dbc1666072a5" and "7d911e453d34c71d2d818008aa5469d248dc1670" have entirely different histories.

6 changed files with 12 additions and 264 deletions

View File

@ -35,33 +35,6 @@ const char* FrameScript_Object::GetDisplayName() {
return name ? name : "<unnamed>";
}
int32_t FrameScript_Object::GetScript(lua_State* L) {
if (!lua_isstring(L, 2)) {
luaL_error(L, "Usage: %s:GetScript(\"type\")", this->GetDisplayName());
return 0;
}
auto name = lua_tostring(L, 2);
ScriptData data;
auto script = this->GetScriptByName(name, data);
if (!script) {
luaL_error(L, "%s doesn't have a \"%s\" script", this->GetDisplayName(), lua_tostring(L, 2));
return 0;
}
// TODO taint management
if (script->luaRef > 0) {
lua_rawgeti(L, LUA_REGISTRYINDEX, script->luaRef);
} else {
lua_pushnil(L);
}
return 1;
}
FrameScript_Object::ScriptIx* FrameScript_Object::GetScriptByName(const char* name, FrameScript_Object::ScriptData& data) {
if (!SStrCmpI(name, "OnEvent", STORM_MAX_STR)) {
data.wrapper = "return function(self,event,...) %s end";

View File

@ -43,7 +43,6 @@ class FrameScript_Object {
// Member functions
const char* GetDisplayName();
int32_t GetScript(lua_State* L);
int32_t RegisterScriptEvent(const char* name);
void RegisterScriptObject(const char* name);
void RunScript(ScriptIx const& script, int32_t argCount, const char* a4);

View File

@ -2,13 +2,10 @@
#include "gx/Coordinate.hpp"
#include "ui/CBackdropGenerator.hpp"
#include "ui/FrameScript.hpp"
#include "ui/FrameXML.hpp"
#include "ui/simple/CSimpleFrame.hpp"
#include "ui/simple/CSimpleTexture.hpp"
#include "util/Lua.hpp"
#include "util/StringTo.hpp"
#include "util/Unimplemented.hpp"
#include <storm/Memory.hpp>
#include <algorithm>
#include <cstdint>
#include <limits>
@ -22,66 +19,7 @@ int32_t CSimpleFrame_CreateTitleRegion(lua_State* L) {
}
int32_t CSimpleFrame_CreateTexture(lua_State* L) {
auto type = CSimpleFrame::GetObjectType();
auto frame = static_cast<CSimpleFrame*>(FrameScript_GetObjectThis(L, type));
const char* name = nullptr;
if (lua_isstring(L, 2)) {
name = lua_tostring(L, 2);
}
int32_t drawlayer = DRAWLAYER_ARTWORK;
if (lua_isstring(L, 3)) {
auto drawlayerStr = lua_tostring(L, 3);
StringToDrawLayer(drawlayerStr, drawlayer);
}
XMLNode* inheritNode = nullptr;
if (lua_type(L, 4) == LUA_TSTRING) {
auto inheritName = lua_tostring(L, 4);
const char* tainted;
bool locked;
inheritNode = FrameXML_AcquireHashNode(inheritName, tainted, locked);
if (!inheritNode) {
luaL_error(L, "%s:CreateTexture(): Couldn't find inherited node \"%s\"", frame->GetDisplayName(), inheritName);
return 0;
}
if (locked) {
luaL_error(L, "%s:CreateTexture(): Recursively inherited node \"%s\"", frame->GetDisplayName(), inheritName);
return 0;
}
}
// TODO CDataAllocator::GetData
auto texture = STORM_NEW(CSimpleTexture)(frame, drawlayer, true);
if (name && *name) {
texture->SetName(name);
}
if (inheritNode) {
CStatus status;
texture->LoadXML(inheritNode, &status);
texture->PostLoadXML(inheritNode, &status);
auto inheritName = lua_tostring(L, 4);
FrameXML_ReleaseHashNode(inheritName);
}
// TODO anim related logic?
if (!texture->lua_registered) {
texture->RegisterScriptObject(nullptr);
}
lua_rawgeti(L, LUA_REGISTRYINDEX, texture->lua_objectRef);
return 1;
WHOA_UNIMPLEMENTED(0);
}
int32_t CSimpleFrame_CreateFontString(lua_State* L) {
@ -188,10 +126,7 @@ int32_t CSimpleFrame_HasScript(lua_State* L) {
}
int32_t CSimpleFrame_GetScript(lua_State* L) {
auto type = CSimpleFrame::GetObjectType();
auto frame = static_cast<CSimpleFrame*>(FrameScript_GetObjectThis(L, type));
return frame->GetScript(L);
WHOA_UNIMPLEMENTED(0);
}
int32_t CSimpleFrame_SetScript(lua_State* L) {

View File

@ -1,6 +1,5 @@
#include "ui/simple/CSimpleStatusBar.hpp"
#include "ui/simple/CSimpleStatusBarScript.hpp"
#include "util/Lua.hpp"
int32_t CSimpleStatusBar::s_metatable;
int32_t CSimpleStatusBar::s_objectType;
@ -27,104 +26,6 @@ CSimpleStatusBar::CSimpleStatusBar(CSimpleFrame* parent) : CSimpleFrame(parent)
// TODO
}
FrameScript_Object::ScriptIx* CSimpleStatusBar::GetScriptByName(const char* name, ScriptData& data) {
auto script = this->CSimpleFrame::GetScriptByName(name, data);
if (script) {
return script;
}
if (!SStrCmpI(name, "OnValueChanged")) {
script = &this->m_onValueChanged;
data.wrapper = "return function(self,value) %s end";
} else if (!SStrCmpI(name, "OnMinMaxChanged")) {
script = &this->m_onMinMaxChanged;
data.wrapper = "return function(self,min,max) %s end";
}
return script;
}
int32_t CSimpleStatusBar::GetScriptMetaTable() {
return CSimpleStatusBar::s_metatable;
}
float CSimpleStatusBar::GetValue() const {
return this->m_value;
}
bool CSimpleStatusBar::IsA(int32_t type) {
return type == CSimpleStatusBar::s_objectType
|| type == CSimpleFrame::s_objectType
|| type == CScriptRegion::s_objectType
|| type == CScriptObject::s_objectType;
}
void CSimpleStatusBar::RunOnMinMaxChangedScript() {
if (!this->m_onMinMaxChanged.luaRef) {
return;
}
auto L = FrameScript_GetContext();
lua_pushnumber(L, this->m_minValue);
lua_pushnumber(L, this->m_maxValue);
this->RunScript(this->m_onMinMaxChanged, 2, nullptr);
}
void CSimpleStatusBar::RunOnValueChangedScript() {
if (!this->m_onValueChanged.luaRef) {
return;
}
auto L = FrameScript_GetContext();
lua_pushnumber(L, this->m_value);
this->RunScript(this->m_onValueChanged, 1, nullptr);
}
void CSimpleStatusBar::SetMinMaxValues(float min, float max) {
if (min > max) {
min = max;
}
// No change
if (this->m_rangeSet && this->m_minValue == min && this->m_maxValue == max) {
return;
}
this->m_minValue = min;
this->m_maxValue = max;
this->m_changed = true;
this->m_rangeSet = true;
this->RunOnMinMaxChangedScript();
if (this->m_valueSet) {
this->SetValue(this->m_value);
}
}
void CSimpleStatusBar::SetValue(float value) {
if (!this->m_rangeSet) {
return;
}
// Clamp value
value = std::min(std::max(value, this->m_minValue), this->m_maxValue);
// No change
if (this->m_valueSet && this->m_value == value) {
return;
}
this->m_value = value;
this->m_changed = true;
this->m_valueSet = true;
this->RunOnValueChangedScript();
}

View File

@ -5,41 +5,23 @@
class CSimpleStatusBar : public CSimpleFrame {
public:
// Public static variables
// Static variables
static int32_t s_metatable;
static int32_t s_objectType;
// Public static functions
// Static functions
static void CreateScriptMetaTable();
static int32_t GetObjectType();
static void RegisterScriptMethods(lua_State* L);
// Public virtual member functions
virtual int32_t GetScriptMetaTable();
virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data);
virtual bool IsA(int32_t type);
// Member variables
// TODO
virtual void SetValue(float value);
// Public member functions
// Virtual member functions
virtual int32_t GetScriptMetaTable();
// Member functions
CSimpleStatusBar(CSimpleFrame* parent);
float GetValue() const;
void RunOnMinMaxChangedScript();
void RunOnValueChangedScript();
void SetMinMaxValues(float min, float max);
protected:
// Protected member variables
uint32_t m_changed : 1;
uint32_t m_rangeSet : 1;
uint32_t m_valueSet : 1;
float m_minValue = 0.0f;
float m_maxValue = 0.0f;
float m_value = 0.0f;
CSimpleTexture* m_barTexture = nullptr;
ORIENTATION m_orientation = ORIENTATION_HORIZONTAL;
ScriptIx m_onValueChanged;
ScriptIx m_onMinMaxChanged;
};
#endif

View File

@ -1,7 +1,5 @@
#include "ui/simple/CSimpleStatusBarScript.hpp"
#include "ui/simple/CSimpleStatusBar.hpp"
#include "ui/FrameScript.hpp"
#include "util/Lua.hpp"
#include "util/Unimplemented.hpp"
namespace {
@ -19,55 +17,15 @@ int32_t CSimpleStatusBar_GetMinMaxValues(lua_State* L) {
}
int32_t CSimpleStatusBar_SetMinMaxValues(lua_State* L) {
auto type = CSimpleStatusBar::GetObjectType();
auto statusBar = static_cast<CSimpleStatusBar*>(FrameScript_GetObjectThis(L, type));
if (!lua_isnumber(L, 2) || !lua_isnumber(L, 3)) {
luaL_error(L, "Usage: %s:SetMinMaxValues(min, max)", statusBar->GetDisplayName());
return 0;
}
auto min = lua_tonumber(L, 2);
auto max = lua_tonumber(L, 3);
if (min < -1.0e12 || min > 1.0e12 || max < -1.0e12 || max > 1.0e12) {
luaL_error(L, "Min or Max out of range");
return 0;
}
if (max - min > 1.0e12) {
luaL_error(L, "Min and Max too far apart");
return 0;
}
statusBar->SetMinMaxValues(static_cast<float>(min), static_cast<float>(max));
return 0;
WHOA_UNIMPLEMENTED(0);
}
int32_t CSimpleStatusBar_GetValue(lua_State* L) {
auto type = CSimpleStatusBar::GetObjectType();
auto statusBar = static_cast<CSimpleStatusBar*>(FrameScript_GetObjectThis(L, type));
lua_pushnumber(L, statusBar->GetValue());
return 1;
WHOA_UNIMPLEMENTED(0);
}
int32_t CSimpleStatusBar_SetValue(lua_State* L) {
auto type = CSimpleStatusBar::GetObjectType();
auto statusBar = static_cast<CSimpleStatusBar*>(FrameScript_GetObjectThis(L, type));
if (!lua_isnumber(L, 2)) {
luaL_error(L, "Usage: %s:SetValue(value)", statusBar->GetDisplayName());
return 0;
}
auto value = static_cast<float>(lua_tonumber(L, 2));
statusBar->SetValue(value);
return 0;
WHOA_UNIMPLEMENTED(0);
}
int32_t CSimpleStatusBar_GetStatusBarTexture(lua_State* L) {