Compare commits

...

10 Commits

Author SHA1 Message Date
Tristan 'Natrist' Cormier
8fe68e4643
Merge b902b5484e into 3d8073cf75 2026-02-03 10:52:47 -05:00
fallenoak
3d8073cf75
feat(ui): implement CSimpleFrame::LoadXML_Attributes 2026-02-03 09:00:27 -06:00
fallenoak
bdce266205
feat(ui): add CSimpleFrame::SetAttribute 2026-02-03 08:36:04 -06:00
fallenoak
c099226cd2
feat(ui): add CSimpleFrame::GetAttribute
Some checks are pending
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:cl compiler_name:MSVC cxx:cl os:windows-latest system_name:Windows test_path:WhoaTest]) (push) Waiting to run
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:clang compiler_name:Clang cxx:clang++ os:macos-latest system_name:macOS test_path:WhoaTest]) (push) Waiting to run
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:gcc compiler_name:GCC cxx:g++ os:ubuntu-latest system_name:Linux test_path:WhoaTest]) (push) Waiting to run
2026-02-02 22:29:26 -06:00
fallenoak
ae64833a5c
feat(ui): add CSimpleFrame::m_attributes 2026-02-02 22:19:15 -06:00
fallenoak
728d13b216
fix(object): link to ui lib 2026-02-02 22:13:40 -06:00
fallenoak
f42416bd0b
feat(ui): implement CSimpleButton_GetTextHeight 2026-02-02 21:09:56 -06:00
fallenoak
b076c2c573
feat(ui): implement CSimpleFontString_GetText 2026-02-02 21:02:29 -06:00
fallenoak
0962e5952e
feat(ui): implement Script_FillLocalizedClassList 2026-02-02 20:30:52 -06:00
Tristan Cormier
b902b5484e feat(glue): implement Script_AcceptedScanning 2026-01-11 17:00:18 -05:00
9 changed files with 179 additions and 6 deletions

View File

@ -39,6 +39,7 @@
#include <cstdio>
int32_t CGlueMgr::m_acceptedEULA = 1; // TODO
int32_t CGlueMgr::m_acceptedScanning = 1; // TODO
int32_t CGlueMgr::m_acceptedTerminationWithoutNotice;
int32_t CGlueMgr::m_acceptedTOS = 1; // TODO
int32_t CGlueMgr::m_accountMsgAvailable;

View File

@ -33,6 +33,7 @@ class CGlueMgr {
// Static variables
static int32_t m_acceptedEULA;
static int32_t m_acceptedScanning;
static int32_t m_acceptedTerminationWithoutNotice;
static int32_t m_acceptedTOS;
static int32_t m_accountMsgAvailable;

View File

@ -210,7 +210,14 @@ int32_t Script_ShowScanningNotice(lua_State* L) {
}
int32_t Script_ScanningAccepted(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
if (CGlueMgr::m_acceptedScanning) {
lua_pushnumber(L, 1.0);
}
else {
lua_pushnil(L);
}
return 1;
}
int32_t Script_AcceptScanning(lua_State* L) {

View File

@ -16,4 +16,5 @@ target_include_directories(object
target_link_libraries(object
PRIVATE
db
ui
)

View File

@ -1,11 +1,13 @@
#include "ui/game/ScriptEvents.hpp"
#include "object/client/ObjMgr.hpp"
#include "db/Db.hpp"
#include "object/Client.hpp"
#include "ui/FrameScript.hpp"
#include "ui/ScriptFunctionsSystem.hpp"
#include "ui/game/CGGameUI.hpp"
#include "ui/game/ScriptUtil.hpp"
#include "util/GUID.hpp"
#include "util/Lua.hpp"
#include "util/StringTo.hpp"
#include "util/Unimplemented.hpp"
namespace {
@ -707,7 +709,29 @@ int32_t Script_IsXPUserDisabled(lua_State* L) {
}
int32_t Script_FillLocalizedClassList(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
if (lua_type(L, 1) != LUA_TTABLE) {
luaL_error(L, "Usage: FillLocalizedClassList(classTable[, isFemale])");
return 0;
}
auto isFemale = StringToBOOL(L, 2, 0);
auto sex = isFemale ? UNITSEX_FEMALE : UNITSEX_MALE;
lua_settop(L, 1);
for (int32_t i = 0; i < g_chrClassesDB.GetNumRecords(); ++i) {
auto classRec = g_chrClassesDB.GetRecordByIndex(i);
if (classRec) {
auto displayName = CGUnit_C::GetDisplayClassNameFromRecord(classRec, sex, 0);
lua_pushstring(L, classRec->m_filename);
lua_pushstring(L, displayName);
lua_settable(L, -3);
}
}
return 1;
}
}

View File

@ -372,7 +372,18 @@ int32_t CSimpleButton_GetTextWidth(lua_State* L) {
}
int32_t CSimpleButton_GetTextHeight(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
auto type = CSimpleButton::GetObjectType();
auto button = static_cast<CSimpleButton*>(FrameScript_GetObjectThis(L, type));
auto text = button->m_text;
float height = text ? text->GetHeight() : 0.0f;
float ddcHeight = CoordinateGetAspectCompensation() * 1024.0f * height;
float ndcHeight = DDCToNDCWidth(ddcHeight);
lua_pushnumber(L, ndcHeight);
return 1;
}
int32_t CSimpleButton_RegisterForClicks(lua_State* L) {

View File

@ -162,7 +162,17 @@ int32_t CSimpleFontString_SetFont(lua_State* L) {
}
int32_t CSimpleFontString_GetText(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
auto type = CSimpleFontString::GetObjectType();
auto string = static_cast<CSimpleFontString*>(FrameScript_GetObjectThis(L, type));
auto text = string->GetText();
if (!text || !*text) {
text = nullptr;
}
lua_pushstring(L, text);
return 1;
}
int32_t CSimpleFontString_GetFieldSize(lua_State* L) {

View File

@ -376,6 +376,29 @@ void CSimpleFrame::RegisterForEvents(int32_t a2) {
}
}
void CSimpleFrame::RunOnAttributeChangedScript(const char* name, int32_t luaRef) {
if (!this->m_onAttributeChange.luaRef) {
return;
}
auto L = FrameScript_GetContext();
// TODO taint management
// Attribute name
auto nameLower = static_cast<char*>(alloca(SStrLen(name) + 1));
SStrCopy(nameLower, name);
SStrLower(nameLower);
lua_pushstring(L, nameLower);
// Attribute ref
lua_rawgeti(L, LUA_REGISTRYINDEX, luaRef);
this->RunScript(this->m_onAttributeChange, 2, nullptr);
// TODO taint management
}
void CSimpleFrame::RunOnCharScript(const char* chr) {
if (this->m_onChar.luaRef) {
auto L = FrameScript_GetContext();
@ -522,6 +545,18 @@ void CSimpleFrame::PreLoadXML(XMLNode* node, CStatus* status) {
}
}
bool CSimpleFrame::GetAttribute(const char* name, int32_t& luaRef) {
auto attr = this->m_attributes.Ptr(name);
if (!attr || attr->luaRef == -1) {
return false;
}
luaRef = attr->luaRef;
return true;
}
int32_t CSimpleFrame::GetBoundsRect(CRect& bounds) {
if (this->IsResizePending()) {
this->Resize(1);
@ -737,7 +772,69 @@ int32_t CSimpleFrame::HideThis() {
}
void CSimpleFrame::LoadXML_Attributes(const XMLNode* node, CStatus* status) {
// TODO
auto L = FrameScript_GetContext();
auto child = node->GetChild();
while (child) {
// Unexpected child node
if (SStrCmpI(child->GetName(), "Attribute")) {
status->Add(STATUS_WARNING, "Frame %s: Unknown attributes element %s", this->GetDisplayName(), child->GetName());
child = child->GetSibling();
continue;
}
auto attrName = child->GetAttributeByName("name");
// No attribute name
if (!attrName) {
status->Add(STATUS_WARNING, "Frame %s: unnamed attribute element", this->GetDisplayName());
child = child->GetSibling();
continue;
}
auto attrType = child->GetAttributeByName("type");
if (!attrType) {
attrType = "string";
}
auto attrValue = child->GetAttributeByName("value");
// Missing attribute value for non-nil type
if (SStrCmpI(attrType, "nil") && !attrValue) {
status->Add(STATUS_WARNING, "Frame %s: attribute element named %s missing value", this->GetDisplayName(), attrName);
child = child->GetSibling();
continue;
}
// Push attribute value to stack
if (!SStrCmpI(attrType, "nil")) {
lua_pushnil(L);
} else if (!SStrCmpI(attrType, "boolean")) {
lua_pushboolean(L, StringToBOOL(attrValue));
} else if (!SStrCmpI(attrType, "number")) {
lua_pushnumber(L, SStrToFloat(attrValue));
} else {
lua_pushstring(L, attrValue);
}
auto attr = this->m_attributes.Ptr(attrName);
if (attr) {
luaL_unref(L, LUA_REGISTRYINDEX, attr->luaRef);
} else {
attr = this->m_attributes.New(attrName, 0, 0x0);
}
// TODO taint management
attr->luaRef = luaL_ref(L, LUA_REGISTRYINDEX);
// TODO taint management
child = child->GetSibling();
}
}
void CSimpleFrame::LoadXML_Backdrop(const XMLNode* node, CStatus* status) {
@ -1317,6 +1414,18 @@ void CSimpleFrame::RemoveFrameRegion(CSimpleRegion* region, uint32_t drawlayer)
this->NotifyDrawLayerChanged(drawlayer);
}
void CSimpleFrame::SetAttribute(const char* name, int32_t luaRef) {
auto attr = this->m_attributes.Ptr(name);
if (!attr) {
attr = this->m_attributes.New(name, 0, 0x0);
}
attr->luaRef = luaRef;
this->RunOnAttributeChangedScript(name, luaRef);
}
void CSimpleFrame::SetBackdrop(CBackdropGenerator* backdrop) {
if (this->m_backdrop) {
delete this->m_backdrop;

View File

@ -6,6 +6,7 @@
#include "ui/CScriptRegion.hpp"
#include "ui/Types.hpp"
#include "ui/simple/CSimpleRegion.hpp"
#include <storm/Hash.hpp>
#include <storm/List.hpp>
#include <cstdint>
@ -17,6 +18,10 @@ class CSimpleTitleRegion;
class CSimpleTop;
struct lua_State;
struct FRAMEATTR : TSHashObject<FRAMEATTR, HASHKEY_STRI> {
int32_t luaRef;
};
class CSimpleFrame : public CScriptRegion {
public:
// Static members
@ -71,6 +76,7 @@ class CSimpleFrame : public CScriptRegion {
ScriptIx m_onAttributeChange;
ScriptIx m_onEnable;
ScriptIx m_onDisable;
TSHashTable<FRAMEATTR, HASHKEY_STRI> m_attributes;
int32_t m_drawenabled[NUM_SIMPLEFRAME_DRAWLAYERS];
CBackdropGenerator* m_backdrop = nullptr;
STORM_EXPLICIT_LIST(CSimpleRegion, m_regionLink) m_regions;
@ -126,6 +132,7 @@ class CSimpleFrame : public CScriptRegion {
void DisableEvent(CSimpleEventType eventType);
void EnableDrawLayer(uint32_t drawlayer);
void EnableEvent(CSimpleEventType eventType, int32_t priority);
bool GetAttribute(const char* name, int32_t& luaRef);
int32_t GetHitRect(CRect& rect);
void Hide();
void LoadXML_Attributes(const XMLNode* node, CStatus* status);
@ -139,6 +146,7 @@ class CSimpleFrame : public CScriptRegion {
void RegisterForEvents(int32_t a2);
void RegisterRegion(CSimpleRegion* region);
void RemoveFrameRegion(CSimpleRegion* region, uint32_t drawlayer);
void RunOnAttributeChangedScript(const char* name, int32_t luaRef);
void RunOnCharScript(const char* chr);
void RunOnEnableScript();
void RunOnEnterScript(int32_t a2);
@ -152,6 +160,7 @@ class CSimpleFrame : public CScriptRegion {
void RunOnShowScript();
void RunOnSizeChangedScript(float width, float height);
void RunOnUpdateScript(float elapsedSec);
void SetAttribute(const char* name, int32_t luaRef);
void SetBackdrop(CBackdropGenerator* backdrop);
void SetBeingScrolled(int32_t a2, int32_t a3);
void SetFrameAlpha(uint8_t alpha);