mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-10-26 22:06:06 +03:00
feat(ui): improve CSimpleStatusBar
This commit is contained in:
parent
fcc3be490c
commit
ff2a0da254
@ -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
|
||||
|
||||
@ -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<CSimpleMessageScrollFrame*>(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<CSimpleMessageScrollFrame*>(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) {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
@ -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<CSimpleStatusBar*>(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<CSimpleStatusBar*>(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) {
|
||||
|
||||
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user