From ff2a0da2544a88216b130ba970f8eaa1b595ec9d Mon Sep 17 00:00:00 2001 From: VDm Date: Tue, 12 Aug 2025 00:47:58 +0400 Subject: [PATCH] feat(ui): improve CSimpleStatusBar --- src/ui/CSimpleMessageScrollFrame.hpp | 4 ++++ src/ui/CSimpleMessageScrollFrameScript.cpp | 18 ++++++++++++++++-- src/ui/CSimpleStatusBar.cpp | 5 +++++ src/ui/CSimpleStatusBar.hpp | 4 ++++ src/ui/CSimpleStatusBarScript.cpp | 22 ++++++++++++++++++++-- src/ui/Util.cpp | 11 +++++++++++ src/ui/Util.hpp | 2 ++ src/util/StringTo.cpp | 11 +++++++++++ src/util/StringTo.hpp | 2 ++ 9 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/ui/CSimpleMessageScrollFrame.hpp b/src/ui/CSimpleMessageScrollFrame.hpp index deadef1..1e793ba 100644 --- a/src/ui/CSimpleMessageScrollFrame.hpp +++ b/src/ui/CSimpleMessageScrollFrame.hpp @@ -20,6 +20,10 @@ class CSimpleMessageScrollFrame : public CSimpleHyperlinkedFrame { // Virtual member functions virtual bool IsA(int32_t type); virtual int32_t GetScriptMetaTable(); + + // Member variables + int32_t m_atTop = 0; + int32_t m_atBottom = 1; }; #endif diff --git a/src/ui/CSimpleMessageScrollFrameScript.cpp b/src/ui/CSimpleMessageScrollFrameScript.cpp index f6791b1..f39d4e8 100644 --- a/src/ui/CSimpleMessageScrollFrameScript.cpp +++ b/src/ui/CSimpleMessageScrollFrameScript.cpp @@ -108,11 +108,25 @@ static int32_t Script_SetScrollOffset(lua_State* L) { } static int32_t Script_AtTop(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleMessageScrollFrame::GetObjectType(); + auto frame = static_cast(FrameScript_GetObjectThis(L, type)); + if (frame->m_atTop) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + return 1; } static int32_t Script_AtBottom(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleMessageScrollFrame::GetObjectType(); + auto frame = static_cast(FrameScript_GetObjectThis(L, type)); + if (frame->m_atBottom) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + return 1; } static int32_t Script_UpdateColorByID(lua_State* L) { diff --git a/src/ui/CSimpleStatusBar.cpp b/src/ui/CSimpleStatusBar.cpp index b07e28d..0e9107b 100644 --- a/src/ui/CSimpleStatusBar.cpp +++ b/src/ui/CSimpleStatusBar.cpp @@ -27,6 +27,11 @@ CSimpleStatusBar::CSimpleStatusBar(CSimpleFrame* parent) : CSimpleFrame(parent) { } +void CSimpleStatusBar::SetOrientation(uint32_t orientation) { + this->m_flags |= 1; + this->m_orientation = orientation; +} + bool CSimpleStatusBar::IsA(int32_t type) { return type == CSimpleStatusBar::s_objectType || type == CSimpleFrame::s_objectType diff --git a/src/ui/CSimpleStatusBar.hpp b/src/ui/CSimpleStatusBar.hpp index a8e1dc6..180d831 100644 --- a/src/ui/CSimpleStatusBar.hpp +++ b/src/ui/CSimpleStatusBar.hpp @@ -16,6 +16,7 @@ class CSimpleStatusBar : public CSimpleFrame { // Member functions CSimpleStatusBar(CSimpleFrame* parent); + void SetOrientation(uint32_t orientation); // Virtual member functions virtual bool IsA(int32_t type); @@ -23,9 +24,12 @@ class CSimpleStatusBar : public CSimpleFrame { virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data); // Member variables + uint32_t m_flags = 0; float m_minValue = 0.0f; float m_maxValue = 0.0f; float m_value = 0.0f; + CSimpleTexture* m_barTexture = nullptr; + uint32_t m_orientation = 0; ScriptIx m_onValueChanged; ScriptIx m_onMinMaxChanged; }; diff --git a/src/ui/CSimpleStatusBarScript.cpp b/src/ui/CSimpleStatusBarScript.cpp index 50213e9..aacd6a2 100644 --- a/src/ui/CSimpleStatusBarScript.cpp +++ b/src/ui/CSimpleStatusBarScript.cpp @@ -1,14 +1,32 @@ #include "ui/CSimpleStatusBarScript.hpp" #include "ui/CSimpleStatusBar.hpp" +#include "ui/Util.hpp" #include "util/Lua.hpp" #include "util/Unimplemented.hpp" +#include "util/StringTo.hpp" static int32_t Script_GetOrientation(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleStatusBar::GetObjectType(); + auto statusBar = static_cast(FrameScript_GetObjectThis(L, type)); + lua_pushstring(L, OrientationToString(statusBar->m_orientation)); + return 1; } static int32_t Script_SetOrientation(lua_State* L) { - WHOA_UNIMPLEMENTED(0); + auto type = CSimpleStatusBar::GetObjectType(); + auto statusBar = static_cast(FrameScript_GetObjectThis(L, type)); + if (!lua_isstring(L, 2)) { + return luaL_error(L, "Usage: %s:SetOrientation(\"orientation\")", statusBar->GetDisplayName()); + } + + auto string = lua_tolstring(L, 2, nullptr); + uint32_t orientation = 0; + if (!StringToOrientation(string, orientation)) { + return luaL_error(L, "%s:SetOrientation(): Unknown orientation: %s", statusBar->GetDisplayName(), string); + } + + statusBar->SetOrientation(orientation); + return 0; } static int32_t Script_GetMinMaxValues(lua_State* L) { diff --git a/src/ui/Util.cpp b/src/ui/Util.cpp index ecf4f0b..1b6c069 100644 --- a/src/ui/Util.cpp +++ b/src/ui/Util.cpp @@ -86,3 +86,14 @@ int32_t StringToFrameStrata(const char* string, FRAME_STRATA& strata) { return 0; } + +const char* OrientationToString(uint32_t orientation) { + switch (orientation) { + case 0: + return "HORIZONTAL"; + case 1: + return "VERTICAL"; + default: + return "UNKNOWN"; + } +} diff --git a/src/ui/Util.hpp b/src/ui/Util.hpp index c7f813b..38b5d5a 100644 --- a/src/ui/Util.hpp +++ b/src/ui/Util.hpp @@ -13,4 +13,6 @@ int32_t StringToFramePoint(const char* string, FRAMEPOINT& point); int32_t StringToFrameStrata(const char* string, FRAME_STRATA& strata); +const char* OrientationToString(uint32_t orientation); + #endif diff --git a/src/util/StringTo.cpp b/src/util/StringTo.cpp index aaf1f77..49506e6 100644 --- a/src/util/StringTo.cpp +++ b/src/util/StringTo.cpp @@ -159,3 +159,14 @@ int32_t StringToJustify(const char* string, uint32_t& justify) { return 0; } + +bool StringToOrientation(const char* string, uint32_t& orientation) { + if (!SStrCmpI(string, "HORIZONTAL", STORM_MAX_STR)) { + orientation = 0; + return true; + } else if (!SStrCmpI(string, "VERTICAL", STORM_MAX_STR)) { + orientation = 1; + return true; + } + return false; +} diff --git a/src/util/StringTo.hpp b/src/util/StringTo.hpp index 18d4825..1fb435f 100644 --- a/src/util/StringTo.hpp +++ b/src/util/StringTo.hpp @@ -17,4 +17,6 @@ int32_t StringToDrawLayer(const char*, int32_t&); int32_t StringToJustify(const char*, uint32_t&); +bool StringToOrientation(const char* string, uint32_t& orientation); + #endif