diff --git a/src/gameui/CGTooltip.hpp b/src/gameui/CGTooltip.hpp index 4c175da..dd64fca 100644 --- a/src/gameui/CGTooltip.hpp +++ b/src/gameui/CGTooltip.hpp @@ -24,7 +24,7 @@ class CGTooltip : public CSimpleFrame { virtual int32_t GetScriptMetaTable(); virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data); - // Members + // Member variables ScriptIx m_onTooltipSetDefaultAnchor; ScriptIx m_onTooltipCleared; ScriptIx m_onTooltipAddMoney; diff --git a/src/gameui/GameScriptFunctions.cpp b/src/gameui/GameScriptFunctions.cpp index c674e1a..2480b7f 100644 --- a/src/gameui/GameScriptFunctions.cpp +++ b/src/gameui/GameScriptFunctions.cpp @@ -8,6 +8,7 @@ #include "gameui/CGTabardModelFrame.hpp" #include "gameui/CGQuestPOIFrame.hpp" #include "console/Console.hpp" +#include "gx/CGVideoOptions.hpp" #include "ui/FrameXML.hpp" #include "ui/FrameScript.hpp" #include "util/Lua.hpp" @@ -1690,6 +1691,7 @@ void LoadScriptFunctions() { GlyphInfoRegisterScriptFunctions(); AchievementInfoRegisterScriptFunctions(); CurrencyTypesRegisterScriptFunctions(); + CGVideoOptions::RegisterScriptFunctions(); EquipmentManagerRegisterScriptFunctions(); GMTicketInfoRegisterScriptFunctions(); BattlenetUIRegisterScriptFunctions(); diff --git a/src/gameui/scripts/GameScriptFunctionsActionBar.cpp b/src/gameui/scripts/GameScriptFunctionsActionBar.cpp index bc3edef..8a398b2 100644 --- a/src/gameui/scripts/GameScriptFunctionsActionBar.cpp +++ b/src/gameui/scripts/GameScriptFunctionsActionBar.cpp @@ -13,7 +13,9 @@ static int32_t Script_GetActionTexture(lua_State* L) { } static int32_t Script_GetActionCount(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_GetActionCooldown(lua_State* L) { @@ -29,7 +31,9 @@ static int32_t Script_GetActionText(lua_State* L) { } static int32_t Script_HasAction(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnil(L); + return 1; } static int32_t Script_UseAction(lua_State* L) { @@ -81,11 +85,14 @@ static int32_t Script_IsActionInRange(lua_State* L) { } static int32_t Script_GetBonusBarOffset(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_GetMultiCastBarOffset(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + lua_pushnumber(L, 6.0); + return 1; } static int32_t Script_ChangeActionBarPage(lua_State* L) { diff --git a/src/gameui/scripts/GameScriptFunctionsCharacterInfo.cpp b/src/gameui/scripts/GameScriptFunctionsCharacterInfo.cpp index 9ff1b34..5110dd3 100644 --- a/src/gameui/scripts/GameScriptFunctionsCharacterInfo.cpp +++ b/src/gameui/scripts/GameScriptFunctionsCharacterInfo.cpp @@ -1,11 +1,43 @@ #include "gameui/GameScriptFunctions.hpp" #include "ui/FrameScript.hpp" +#include "db/Db.hpp" #include "util/Lua.hpp" #include "util/Unimplemented.hpp" static int32_t Script_GetInventorySlotInfo(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + const char* buttonName = nullptr; + + if (lua_isstring(L, 1)) { + buttonName = lua_tolstring(L, 1, nullptr); + } + + if (!buttonName || g_paperDollItemFrameDB.GetNumRecords() < 1) { + return luaL_error(L, "Invalid inventory slot in GetInventorySlotInfo"); + } + + PaperDollItemFrameRec* record = nullptr; + bool found = false; + for (int32_t i = 0; i < g_paperDollItemFrameDB.GetNumRecords(); ++i) { + record = g_paperDollItemFrameDB.GetRecordByIndex(i); + if (!SStrCmpI(record->m_itemButtonName, buttonName, STORM_MAX_STR)) { + found = true; + break; + } + } + + if (!found) { + return luaL_error(L, "Invalid inventory slot in GetInventorySlotInfo"); + } + + lua_pushnumber(L, record->m_slotNumber); + lua_pushstring(L, record->m_slotIcon); + if (record->m_slotNumber == 18) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + return 3; } static int32_t Script_GetInventoryItemsForSlot(lua_State* L) { diff --git a/src/gameui/scripts/GameScriptFunctionsPartyInfo.cpp b/src/gameui/scripts/GameScriptFunctionsPartyInfo.cpp index 1a7f8fe..0c33c4f 100644 --- a/src/gameui/scripts/GameScriptFunctionsPartyInfo.cpp +++ b/src/gameui/scripts/GameScriptFunctionsPartyInfo.cpp @@ -5,11 +5,15 @@ static int32_t Script_GetNumPartyMembers(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_GetRealNumPartyMembers(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_GetPartyMember(lua_State* L) { diff --git a/src/gameui/scripts/GameScriptFunctionsRaidInfo.cpp b/src/gameui/scripts/GameScriptFunctionsRaidInfo.cpp index d69ebda..ff27784 100644 --- a/src/gameui/scripts/GameScriptFunctionsRaidInfo.cpp +++ b/src/gameui/scripts/GameScriptFunctionsRaidInfo.cpp @@ -5,11 +5,15 @@ static int32_t Script_GetNumRaidMembers(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_GetRealNumRaidMembers(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_GetRaidRosterInfo(lua_State* L) { diff --git a/src/gameui/scripts/GameScriptFunctionsScriptEvents.cpp b/src/gameui/scripts/GameScriptFunctionsScriptEvents.cpp index e92432e..7174dd2 100644 --- a/src/gameui/scripts/GameScriptFunctionsScriptEvents.cpp +++ b/src/gameui/scripts/GameScriptFunctionsScriptEvents.cpp @@ -52,7 +52,6 @@ static int32_t Script_UnitIsUnit(lua_State* L) { static int32_t Script_UnitIsPlayer(lua_State* L) { // TODO - __debugbreak(); lua_pushnil(L); return 1; } @@ -178,39 +177,57 @@ static int32_t Script_UnitPVPName(lua_State* L) { } static int32_t Script_UnitXP(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 50.0); + return 1; } static int32_t Script_UnitXPMax(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 100.0); + return 1; } static int32_t Script_UnitHealth(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 50.0); + return 1; } static int32_t Script_UnitHealthMax(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 100.0); + return 1; } static int32_t Script_UnitMana(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 50.0); + return 1; } static int32_t Script_UnitManaMax(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 100.0); + return 1; } static int32_t Script_UnitPower(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 50.0); + return 1; } static int32_t Script_UnitPowerMax(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 100.0); + return 1; } static int32_t Script_UnitPowerType(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_UnitOnTaxi(lua_State* L) { @@ -222,15 +239,21 @@ static int32_t Script_UnitIsFeignDeath(lua_State* L) { } static int32_t Script_UnitIsDead(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushboolean(L, 0); + return 1; } static int32_t Script_UnitIsGhost(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushboolean(L, 0); + return 1; } static int32_t Script_UnitIsDeadOrGhost(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushboolean(L, 0); + return 1; } static int32_t Script_UnitIsConnected(lua_State* L) { diff --git a/src/gameui/scripts/GameScriptFunctionsSound.cpp b/src/gameui/scripts/GameScriptFunctionsSound.cpp index 7c16fea..6ce97e0 100644 --- a/src/gameui/scripts/GameScriptFunctionsSound.cpp +++ b/src/gameui/scripts/GameScriptFunctionsSound.cpp @@ -21,7 +21,9 @@ static int32_t Script_StopMusic(lua_State* L) { } static int32_t Script_Sound_GameSystem_GetNumInputDrivers(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_Sound_GameSystem_GetInputDriverNameByIndex(lua_State* L) { @@ -29,7 +31,9 @@ static int32_t Script_Sound_GameSystem_GetInputDriverNameByIndex(lua_State* L) { } static int32_t Script_Sound_GameSystem_GetNumOutputDrivers(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_Sound_GameSystem_GetOutputDriverNameByIndex(lua_State* L) { @@ -41,7 +45,9 @@ static int32_t Script_Sound_GameSystem_RestartSoundSystem(lua_State* L) { } static int32_t Script_Sound_ChatSystem_GetNumInputDrivers(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_Sound_ChatSystem_GetInputDriverNameByIndex(lua_State* L) { @@ -49,7 +55,9 @@ static int32_t Script_Sound_ChatSystem_GetInputDriverNameByIndex(lua_State* L) { } static int32_t Script_Sound_ChatSystem_GetNumOutputDrivers(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + // TODO + lua_pushnumber(L, 0.0); + return 1; } static int32_t Script_Sound_ChatSystem_GetOutputDriverNameByIndex(lua_State* L) { diff --git a/src/ui/CSimpleButtonScript.cpp b/src/ui/CSimpleButtonScript.cpp index 46a2420..8010475 100644 --- a/src/ui/CSimpleButtonScript.cpp +++ b/src/ui/CSimpleButtonScript.cpp @@ -128,7 +128,18 @@ int32_t CSimpleButton_SetFontString(lua_State* L) { } int32_t CSimpleButton_GetFontString(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleButton::GetObjectType(); + auto button = static_cast(FrameScript_GetObjectThis(L, type)); + auto fontString = button->m_text; + if (fontString) { + if (!fontString->lua_registered) { + fontString->RegisterScriptObject(nullptr); + } + lua_rawgeti(L, LUA_REGISTRYINDEX, fontString->lua_objectRef); + } else { + lua_pushnil(L); + } + return 1; } int32_t CSimpleButton_SetText(lua_State* L) { diff --git a/src/ui/CSimpleFrame.cpp b/src/ui/CSimpleFrame.cpp index e610bca..6859567 100644 --- a/src/ui/CSimpleFrame.cpp +++ b/src/ui/CSimpleFrame.cpp @@ -450,6 +450,19 @@ void CSimpleFrame::RunOnUpdateScript(float elapsedSec) { } } +void CSimpleFrame::RunOnAttributeChangedScript(const char* name, int32_t luaRef) { + if (this->m_onAttributeChange.luaRef) { + auto L = FrameScript_GetContext(); + // TODO: LUA Tainted + auto loweredName = static_cast(alloca(SStrLen(name) + 1)); + SStrCopy(loweredName, name, STORM_MAX_STR); + SStrLower(loweredName); + lua_pushstring(L, loweredName); + lua_rawgeti(L, LUA_REGISTRYINDEX, luaRef); + this->RunScript(this->m_onAttributeChange, 2, nullptr); + } +} + void CSimpleFrame::PreLoadXML(XMLNode* node, CStatus* status) { const char* name = node->GetAttributeByName("name"); @@ -700,7 +713,58 @@ int32_t CSimpleFrame::HideThis() { } void CSimpleFrame::LoadXML_Attributes(XMLNode* node, CStatus* status) { - // TODO + auto L = FrameScript_GetContext(); + + auto child = node->m_child; + while (child) { + auto childName = child->m_name.GetString(); + if (SStrCmpI(childName, "Attribute", STORM_MAX_STR)) { + status->Add(STATUS_WARNING, "Frame %s: Unknown attributes element %s", this->GetDisplayName(), childName); + child = child->m_next; + continue; + } + + auto name = child->GetAttributeByName("name"); + if (!name) { + status->Add(STATUS_WARNING, "Frame %s: unnamed attribute element", this->GetDisplayName()); + child = child->m_next; + continue; + } + + auto type = child->GetAttributeByName("type"); + if (!type) { + type = "string"; + } + + auto value = child->GetAttributeByName("value"); + if (!value || !SStrCmpI(value, "nil", STORM_MAX_STR)) { + status->Add(STATUS_WARNING, "Frame %s: attribute element named %s missing value", this->GetDisplayName(), name); + child = child->m_next; + continue; + } + + if (!SStrCmpI(type, "nil", STORM_MAX_STR)) { + lua_pushnil(L); + } else if (!SStrCmpI(type, "boolean", STORM_MAX_STR)) { + lua_pushboolean(L, StringToBOOL(value)); + } else if (!SStrCmpI(type, "number", STORM_MAX_STR)) { + lua_pushnumber(L, SStrToFloat(value)); + } else { + lua_pushstring(L, value); + } + + auto attribute = this->m_attributes.Ptr(name); + if (attribute) { + luaL_unref(L, LUA_REGISTRYINDEX, attribute->luaRef); + } else { + attribute = this->m_attributes.New(name, 0, 0); + } + + // TODO: LUA Tainted Logic + attribute->luaRef = luaL_ref(L, LUA_REGISTRYINDEX); + + child = child->m_next; + } } void CSimpleFrame::LoadXML_Backdrop(XMLNode* node, CStatus* status) { @@ -1588,3 +1652,26 @@ void CSimpleFrame::UnregisterRegion(CSimpleRegion* 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; +} + +void CSimpleFrame::SetAttribute(const char* name, int32_t luaRef) { + auto attribute = this->m_attributes.Ptr(name); + if (!attribute) { + attribute = this->m_attributes.New(name, 0, 0); + } + attribute->luaRef = luaRef; + this->RunOnAttributeChangedScript(name, luaRef); +} + +bool CSimpleFrame::AttributeChangesAllowed() const { + // TODO + return true; +} diff --git a/src/ui/CSimpleFrame.hpp b/src/ui/CSimpleFrame.hpp index 40abe7d..fcc9d55 100644 --- a/src/ui/CSimpleFrame.hpp +++ b/src/ui/CSimpleFrame.hpp @@ -7,6 +7,7 @@ #include "ui/Types.hpp" #include #include +#include class CBackdropGenerator; class CCharEvent; @@ -16,6 +17,11 @@ class CSimpleTitleRegion; class CSimpleTop; struct lua_State; +class FRAMEATTR : public TSHashObject { + public: + int32_t luaRef = -1; +}; + class CSimpleFrame : public CScriptRegion { public: // Static members @@ -79,6 +85,7 @@ class CSimpleFrame : public CScriptRegion { TSLink m_framesLink; TSLink m_destroyedLink; TSLink m_strataLink; + TSHashTable m_attributes; // Virtual member functions virtual ~CSimpleFrame(); @@ -146,6 +153,7 @@ class CSimpleFrame : public CScriptRegion { void RunOnShowScript(); void RunOnSizeChangedScript(float width, float height); void RunOnUpdateScript(float elapsedSec); + void RunOnAttributeChangedScript(const char* name, int32_t luaRef); void SetBackdrop(CBackdropGenerator* backdrop); void SetBeingScrolled(int32_t a2, int32_t a3); void SetFrameAlpha(uint8_t alpha); @@ -158,6 +166,9 @@ class CSimpleFrame : public CScriptRegion { void Show(); int32_t TestHitRect(const C2Vector& pt); void UnregisterForEvents(int32_t a2); + bool GetAttribute(const char* name, int32_t& luaRef); + void SetAttribute(const char* name, int32_t luaRef); + bool AttributeChangesAllowed() const; }; #endif diff --git a/src/ui/CSimpleFrameScript.cpp b/src/ui/CSimpleFrameScript.cpp index 739e317..2b68e78 100644 --- a/src/ui/CSimpleFrameScript.cpp +++ b/src/ui/CSimpleFrameScript.cpp @@ -231,11 +231,95 @@ int32_t CSimpleFrame_CanChangeAttributes(lua_State* L) { } int32_t CSimpleFrame_GetAttribute(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleFrame::GetObjectType(); + auto frame = static_cast(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) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleFrame::GetObjectType(); + auto frame = static_cast(FrameScript_GetObjectThis(L, type)); + + if (!frame->ProtectedFunctionsAllowed() && !frame->AttributeChangesAllowed()) { + // TODO: CSimpleTop::s_instance->dword1254(); // fptr call + return 0; + } + + lua_settop(L, 3); + if (!lua_isstring(L, 2) || lua_type(L, 3) == LUA_TNONE) { + return luaL_error(L, "Usage: %s:SetAttribute(\"name\", value)", frame->GetDisplayName()); + } + + int32_t luaRef = -1; + + auto name = lua_tolstring(L, 2, nullptr); + if (frame->GetAttribute(name, luaRef)) { + luaL_unref(L, LUA_REGISTRYINDEX, luaRef); + } + + // TODO: LUA Tainted + luaRef = luaL_ref(L, LUA_REGISTRYINDEX); + frame->SetAttribute(name, luaRef); + + return 0; } int32_t CSimpleFrame_GetEffectiveScale(lua_State* L) { diff --git a/src/ui/CSimpleMessageFrame.cpp b/src/ui/CSimpleMessageFrame.cpp new file mode 100644 index 0000000..ea4e0a3 --- /dev/null +++ b/src/ui/CSimpleMessageFrame.cpp @@ -0,0 +1,39 @@ +#include "ui/CSimpleMessageFrame.hpp" +#include "ui/CSimpleMessageFrameScript.hpp" + +int32_t CSimpleMessageFrame::s_metatable = 0; +int32_t CSimpleMessageFrame::s_objectType = 0; + +void CSimpleMessageFrame::CreateScriptMetaTable() { + lua_State* L = FrameScript_GetContext(); + int32_t ref = FrameScript_Object::CreateScriptMetaTable(L, &CSimpleMessageFrame::RegisterScriptMethods); + CSimpleMessageFrame::s_metatable = ref; +} + +int32_t CSimpleMessageFrame::GetObjectType() { + if (!CSimpleMessageFrame::s_objectType) { + CSimpleMessageFrame::s_objectType = ++FrameScript_Object::s_objectTypes; + } + + return CSimpleMessageFrame::s_objectType; +} + +void CSimpleMessageFrame::RegisterScriptMethods(lua_State* L) { + CSimpleFrame::RegisterScriptMethods(L); + FrameScript_Object::FillScriptMethodTable(L, SimpleMessageFrameMethods, NUM_SIMPLE_MESSAGE_FRAME_SCRIPT_METHODS); +} + +CSimpleMessageFrame::CSimpleMessageFrame(CSimpleFrame* parent) + : CSimpleFrame(parent) { +} + +bool CSimpleMessageFrame::IsA(int32_t type) { + return type == CSimpleMessageFrame::s_objectType + || type == CSimpleFrame::s_objectType + || type == CScriptRegion::s_objectType + || type == CScriptObject::s_objectType; +} + +int32_t CSimpleMessageFrame::GetScriptMetaTable() { + return CSimpleMessageFrame::s_metatable; +} diff --git a/src/ui/CSimpleMessageFrame.hpp b/src/ui/CSimpleMessageFrame.hpp new file mode 100644 index 0000000..2029db0 --- /dev/null +++ b/src/ui/CSimpleMessageFrame.hpp @@ -0,0 +1,25 @@ +#ifndef UI_C_SIMPLE_MESSAGE_FRAME_HPP +#define UI_C_SIMPLE_MESSAGE_FRAME_HPP + +#include "ui/CSimpleFrame.hpp" + +class CSimpleMessageFrame : public CSimpleFrame { + public: + // Static variables + static int32_t s_metatable; + static int32_t s_objectType; + + // Static functions + static void CreateScriptMetaTable(); + static int32_t GetObjectType(); + static void RegisterScriptMethods(lua_State* L); + + // Member functions + CSimpleMessageFrame(CSimpleFrame* parent); + + // Virtual member functions + virtual bool IsA(int32_t type); + virtual int32_t GetScriptMetaTable(); +}; + +#endif diff --git a/src/ui/CSimpleMessageFrameScript.cpp b/src/ui/CSimpleMessageFrameScript.cpp new file mode 100644 index 0000000..8ca78d7 --- /dev/null +++ b/src/ui/CSimpleMessageFrameScript.cpp @@ -0,0 +1,68 @@ +#include "ui/CSimpleMessageFrameScript.hpp" +#include "ui/CSimpleMessageFrame.hpp" +#include "util/Lua.hpp" +#include "util/Unimplemented.hpp" + +static int32_t Script_GetOrientation(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_SetOrientation(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_GetMinMaxValues(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_SetMinMaxValues(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_GetValue(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_SetValue(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_GetStatusBarTexture(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_SetStatusBarTexture(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_GetStatusBarColor(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_SetStatusBarColor(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_GetRotatesTexture(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_SetRotatesTexture(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + + +FrameScript_Method SimpleMessageFrameMethods[NUM_SIMPLE_MESSAGE_FRAME_SCRIPT_METHODS] = { + { "GetOrientation", &Script_GetOrientation }, + { "SetOrientation", &Script_SetOrientation }, + { "GetMinMaxValues", &Script_GetMinMaxValues }, + { "SetMinMaxValues", &Script_SetMinMaxValues }, + { "GetValue", &Script_GetValue }, + { "SetValue", &Script_SetValue }, + { "GetStatusBarTexture", &Script_GetStatusBarTexture }, + { "SetStatusBarTexture", &Script_SetStatusBarTexture }, + { "GetStatusBarColor", &Script_GetStatusBarColor }, + { "SetStatusBarColor", &Script_SetStatusBarColor }, + { "GetRotatesTexture", &Script_GetRotatesTexture }, + { "SetRotatesTexture", &Script_SetRotatesTexture } +}; diff --git a/src/ui/CSimpleMessageFrameScript.hpp b/src/ui/CSimpleMessageFrameScript.hpp new file mode 100644 index 0000000..bf01acd --- /dev/null +++ b/src/ui/CSimpleMessageFrameScript.hpp @@ -0,0 +1,10 @@ +#ifndef UI_C_SIMPLE_MESSAGE_FRAME_SCRIPT_HPP +#define UI_C_SIMPLE_MESSAGE_FRAME_SCRIPT_HPP + +#include "ui/FrameScript.hpp" + +#define NUM_SIMPLE_MESSAGE_FRAME_SCRIPT_METHODS 12 + +extern FrameScript_Method SimpleMessageFrameMethods[NUM_SIMPLE_MESSAGE_FRAME_SCRIPT_METHODS]; + +#endif diff --git a/src/ui/CSimpleStatusBar.cpp b/src/ui/CSimpleStatusBar.cpp new file mode 100644 index 0000000..b07e28d --- /dev/null +++ b/src/ui/CSimpleStatusBar.cpp @@ -0,0 +1,59 @@ +#include "ui/CSimpleStatusBar.hpp" +#include "ui/CSimpleStatusBarScript.hpp" + +int32_t CSimpleStatusBar::s_metatable = 0; +int32_t CSimpleStatusBar::s_objectType = 0; + +void CSimpleStatusBar::CreateScriptMetaTable() { + lua_State* L = FrameScript_GetContext(); + int32_t ref = FrameScript_Object::CreateScriptMetaTable(L, &CSimpleStatusBar::RegisterScriptMethods); + CSimpleStatusBar::s_metatable = ref; +} + +int32_t CSimpleStatusBar::GetObjectType() { + if (!CSimpleStatusBar::s_objectType) { + CSimpleStatusBar::s_objectType = ++FrameScript_Object::s_objectTypes; + } + + return CSimpleStatusBar::s_objectType; +} + +void CSimpleStatusBar::RegisterScriptMethods(lua_State* L) { + CSimpleFrame::RegisterScriptMethods(L); + FrameScript_Object::FillScriptMethodTable(L, SimpleStatusBarMethods, NUM_SIMPLE_STATUS_BAR_SCRIPT_METHODS); +} + +CSimpleStatusBar::CSimpleStatusBar(CSimpleFrame* parent) + : CSimpleFrame(parent) { +} + +bool CSimpleStatusBar::IsA(int32_t type) { + return type == CSimpleStatusBar::s_objectType + || type == CSimpleFrame::s_objectType + || type == CScriptRegion::s_objectType + || type == CScriptObject::s_objectType; +} + +int32_t CSimpleStatusBar::GetScriptMetaTable() { + return CSimpleStatusBar::s_metatable; +} + +FrameScript_Object::ScriptIx* CSimpleStatusBar::GetScriptByName(const char* name, ScriptData& data) { + auto parentScript = CSimpleFrame::GetScriptByName(name, data); + + if (parentScript) { + return parentScript; + } + + if (!SStrCmpI(name, "OnValueChanged", STORM_MAX_STR)) { + data.wrapper = "return function(self,value) %s end"; + return &this->m_onValueChanged; + } + + if (!SStrCmpI(name, "OnMinMaxChanged", STORM_MAX_STR)) { + data.wrapper = "return function(self,min,max) %s end"; + return &this->m_onMinMaxChanged; + } + + return nullptr; +} diff --git a/src/ui/CSimpleStatusBar.hpp b/src/ui/CSimpleStatusBar.hpp new file mode 100644 index 0000000..e7973b3 --- /dev/null +++ b/src/ui/CSimpleStatusBar.hpp @@ -0,0 +1,30 @@ +#ifndef UI_C_SIMPLE_STATUS_BAR_HPP +#define UI_C_SIMPLE_STATUS_BAR_HPP + +#include "ui/CSimpleFrame.hpp" + +class CSimpleStatusBar : public CSimpleFrame { + public: + // Static variables + static int32_t s_metatable; + static int32_t s_objectType; + + // Static functions + static void CreateScriptMetaTable(); + static int32_t GetObjectType(); + static void RegisterScriptMethods(lua_State* L); + + // Member functions + CSimpleStatusBar(CSimpleFrame* parent); + + // Virtual member functions + virtual bool IsA(int32_t type); + virtual int32_t GetScriptMetaTable(); + virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data); + + // Member variables + ScriptIx m_onValueChanged; + ScriptIx m_onMinMaxChanged; +}; + +#endif diff --git a/src/ui/CSimpleStatusBarScript.cpp b/src/ui/CSimpleStatusBarScript.cpp new file mode 100644 index 0000000..1172af4 --- /dev/null +++ b/src/ui/CSimpleStatusBarScript.cpp @@ -0,0 +1,68 @@ +#include "ui/CSimpleStatusBarScript.hpp" +#include "ui/CSimpleStatusBar.hpp" +#include "util/Lua.hpp" +#include "util/Unimplemented.hpp" + +static int32_t Script_GetOrientation(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_SetOrientation(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_GetMinMaxValues(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_SetMinMaxValues(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_GetValue(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_SetValue(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_GetStatusBarTexture(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_SetStatusBarTexture(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_GetStatusBarColor(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_SetStatusBarColor(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_GetRotatesTexture(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + +static int32_t Script_SetRotatesTexture(lua_State* L) { + WHOA_UNIMPLEMENTED(0); +} + + +FrameScript_Method SimpleStatusBarMethods[NUM_SIMPLE_STATUS_BAR_SCRIPT_METHODS] = { + { "GetOrientation", &Script_GetOrientation }, + { "SetOrientation", &Script_SetOrientation }, + { "GetMinMaxValues", &Script_GetMinMaxValues }, + { "SetMinMaxValues", &Script_SetMinMaxValues }, + { "GetValue", &Script_GetValue }, + { "SetValue", &Script_SetValue }, + { "GetStatusBarTexture", &Script_GetStatusBarTexture }, + { "SetStatusBarTexture", &Script_SetStatusBarTexture }, + { "GetStatusBarColor", &Script_GetStatusBarColor }, + { "SetStatusBarColor", &Script_SetStatusBarColor }, + { "GetRotatesTexture", &Script_GetRotatesTexture }, + { "SetRotatesTexture", &Script_SetRotatesTexture } +}; diff --git a/src/ui/CSimpleStatusBarScript.hpp b/src/ui/CSimpleStatusBarScript.hpp new file mode 100644 index 0000000..f440cc2 --- /dev/null +++ b/src/ui/CSimpleStatusBarScript.hpp @@ -0,0 +1,10 @@ +#ifndef UI_C_SIMPLE_STATUS_BAR_SCRIPT_HPP +#define UI_C_SIMPLE_STATUS_BAR_SCRIPT_HPP + +#include "ui/FrameScript.hpp" + +#define NUM_SIMPLE_STATUS_BAR_SCRIPT_METHODS 12 + +extern FrameScript_Method SimpleStatusBarMethods[NUM_SIMPLE_STATUS_BAR_SCRIPT_METHODS]; + +#endif diff --git a/src/ui/FrameXML.cpp b/src/ui/FrameXML.cpp index 30b6d54..763e60a 100644 --- a/src/ui/FrameXML.cpp +++ b/src/ui/FrameXML.cpp @@ -8,8 +8,10 @@ #include "ui/CSimpleModel.hpp" #include "ui/CSimpleMovieFrame.hpp" #include "ui/CSimpleScrollFrame.hpp" +#include "ui/CSimpleMessageFrame.hpp" #include "ui/CSimpleMessageScrollFrame.hpp" #include "ui/CSimpleSlider.hpp" +#include "ui/CSimpleStatusBar.hpp" #include "util/CStatus.hpp" #include "util/SFile.hpp" #include @@ -56,7 +58,8 @@ CSimpleFrame* Create_SimpleFrame(CSimpleFrame* parent) { CSimpleFrame* Create_SimpleMessageFrame(CSimpleFrame* parent) { // TODO - return nullptr; + auto m = SMemAlloc(sizeof(CSimpleMessageFrame), __FILE__, __LINE__, 0x0); + return new (m) CSimpleMessageFrame(parent); } CSimpleFrame* Create_SimpleModel(CSimpleFrame* parent) { @@ -101,7 +104,8 @@ CSimpleFrame* Create_SimpleHTML(CSimpleFrame* parent) { CSimpleFrame* Create_SimpleStatusBar(CSimpleFrame* parent) { // TODO - return nullptr; + auto m = SMemAlloc(sizeof(CSimpleStatusBar), __FILE__, __LINE__, 0x0); + return new (m) CSimpleStatusBar(parent); } CSimpleFrame* Create_SimpleColorSelect(CSimpleFrame* parent) { diff --git a/src/ui/ScriptFunctions.cpp b/src/ui/ScriptFunctions.cpp index 56fda65..466d271 100644 --- a/src/ui/ScriptFunctions.cpp +++ b/src/ui/ScriptFunctions.cpp @@ -12,7 +12,9 @@ #include "ui/CSimpleScrollFrame.hpp" #include "ui/CSimpleSlider.hpp" #include "ui/CSimpleTexture.hpp" +#include "ui/CSimpleMessageFrame.hpp" #include "ui/CSimpleMessageScrollFrame.hpp" +#include "ui/CSimpleStatusBar.hpp" #include "ui/FrameScript.hpp" void CharacterCreateRegisterScriptFunctions() { @@ -78,8 +80,7 @@ void RegisterSimpleFrameScriptMethods() { CSimpleEditBox::CreateScriptMetaTable(); CSimpleHTML::CreateScriptMetaTable(); - // TODO - // CSimpleMessageFrame::CreateScriptMetaTable(); + CSimpleMessageFrame::CreateScriptMetaTable(); CSimpleMessageScrollFrame::CreateScriptMetaTable(); CSimpleModel::CreateScriptMetaTable(); @@ -88,7 +89,7 @@ void RegisterSimpleFrameScriptMethods() { CSimpleSlider::CreateScriptMetaTable(); // TODO - // CSimpleStatusBar::CreateScriptMetaTable(); + CSimpleStatusBar::CreateScriptMetaTable(); // CSimpleColorSelect::CreateScriptMetaTable(); CSimpleMovieFrame::CreateScriptMetaTable(); }