Compare commits

...

6 Commits

Author SHA1 Message Date
fallenoak
856bb72e1a
chore(ui): improve CSimpleStatusBar ctor
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-04 21:53:51 -06:00
fallenoak
3713a7ee89
feat(ui): implement CSimpleStatusBar_GetMinMaxValues 2026-02-04 21:40:42 -06:00
fallenoak
98103db5ee
feat(ui): implement CSimpleStatusBar_SetStatusBarColor 2026-02-04 21:15:32 -06:00
fallenoak
d0621df975
feat(ui): implement CSimpleStatusBar::SetStatusBarColor 2026-02-04 21:10:42 -06:00
fallenoak
fd31a10eaf
feat(ui): implement CSimpleStatusBar::SetBarTexture 2026-02-04 21:06:53 -06:00
fallenoak
78f2afb891
feat(ui): add CSimpleStatusBar::LoadXML 2026-02-04 17:08:31 -06:00
3 changed files with 139 additions and 7 deletions

View File

@ -1,6 +1,11 @@
#include "ui/simple/CSimpleStatusBar.hpp"
#include "ui/LoadXML.hpp"
#include "ui/simple/CSimpleStatusBarScript.hpp"
#include "ui/simple/CSimpleTexture.hpp"
#include "util/CStatus.hpp"
#include "util/Lua.hpp"
#include "util/StringTo.hpp"
#include <common/XML.hpp>
int32_t CSimpleStatusBar::s_metatable;
int32_t CSimpleStatusBar::s_objectType;
@ -23,10 +28,6 @@ void CSimpleStatusBar::RegisterScriptMethods(lua_State* L) {
FrameScript_Object::FillScriptMethodTable(L, SimpleStatusBarMethods, NUM_SIMPLE_STATUS_BAR_SCRIPT_METHODS);
}
CSimpleStatusBar::CSimpleStatusBar(CSimpleFrame* parent) : CSimpleFrame(parent) {
// TODO
}
FrameScript_Object::ScriptIx* CSimpleStatusBar::GetScriptByName(const char* name, ScriptData& data) {
auto script = this->CSimpleFrame::GetScriptByName(name, data);
@ -49,6 +50,14 @@ int32_t CSimpleStatusBar::GetScriptMetaTable() {
return CSimpleStatusBar::s_metatable;
}
float CSimpleStatusBar::GetMaxValue() const {
return this->m_maxValue;
}
float CSimpleStatusBar::GetMinValue() const {
return this->m_minValue;
}
float CSimpleStatusBar::GetValue() const {
return this->m_value;
}
@ -60,6 +69,66 @@ bool CSimpleStatusBar::IsA(int32_t type) {
|| type == CScriptObject::s_objectType;
}
void CSimpleStatusBar::LoadXML(const XMLNode* node, CStatus* status) {
this->CSimpleFrame::LoadXML(node, status);
int32_t drawlayer = DRAWLAYER_ARTWORK;
auto drawlayerAttr = node->GetAttributeByName("drawLayer");
if (drawlayerAttr && *drawlayerAttr) {
StringToDrawLayer(drawlayerAttr, drawlayer);
}
for (auto child = node->GetChild(); child; child = child->GetSibling()) {
if (!SStrCmpI(child->GetName(), "BarTexture")) {
auto texture = LoadXML_Texture(child, this, status);
this->SetBarTexture(texture, drawlayer);
} else if (!SStrCmpI(child->GetName(), "BarColor")) {
CImVector color = {};
LoadXML_Color(child, color);
this->SetStatusBarColor(color);
}
}
auto minValueAttr = node->GetAttributeByName("minValue");
if (minValueAttr && *minValueAttr) {
auto maxValueAttr = node->GetAttributeByName("maxValue");
if (maxValueAttr && *maxValueAttr) {
auto minValue = SStrToFloat(minValueAttr);
auto maxValue = SStrToFloat(maxValueAttr);
if (minValue < -1.0e12 || minValue > 1.0e12 || maxValue < -1.0e12 || maxValue > 1.0e12) {
status->Add(STATUS_ERROR, "Frame %s: Min or Max out of range", this->GetDisplayName());
} else if (maxValue - minValue > 1.0e12) {
status->Add(STATUS_ERROR, "Frame %s: Min and Max too far apart", this->GetDisplayName());
} else {
this->SetMinMaxValues(minValue, maxValue);
}
auto defaultValueAttr = node->GetAttributeByName("defaultValue");
if (defaultValueAttr && *defaultValueAttr) {
auto defaultValue = SStrToFloat(defaultValueAttr);
this->SetValue(defaultValue);
}
}
}
auto orientationAttr = node->GetAttributeByName("orientation");
if (orientationAttr && *orientationAttr) {
ORIENTATION orientation;
if (StringToOrientation(orientationAttr, orientation)) {
this->SetOrientation(orientation);
} else {
status->Add(STATUS_WARNING, "Frame %s: Unknown orientation %s in element %s", this->GetDisplayName(), orientationAttr, node->GetName());
}
}
auto rotatesTextureAttr = node->GetAttributeByName("rotatesTexture");
if (rotatesTextureAttr && *rotatesTextureAttr) {
auto rotatesTexture = StringToBOOL(rotatesTextureAttr);
this->SetRotatesTexture(rotatesTexture);
}
}
void CSimpleStatusBar::RunOnMinMaxChangedScript() {
if (!this->m_onMinMaxChanged.luaRef) {
return;
@ -85,6 +154,30 @@ void CSimpleStatusBar::RunOnValueChangedScript() {
this->RunScript(this->m_onValueChanged, 1, nullptr);
}
void CSimpleStatusBar::SetBarTexture(CSimpleTexture* texture, int32_t drawlayer) {
// No change
if (this->m_barTexture == texture) {
return;
}
if (this->m_barTexture) {
delete this->m_barTexture;
}
if (texture) {
texture->SetFrame(this, drawlayer, true);
texture->SetPoint(FRAMEPOINT_BOTTOMLEFT, this, FRAMEPOINT_BOTTOMLEFT, 0.0f, 0.0f, true);
texture->SetPoint(FRAMEPOINT_BOTTOMRIGHT, this, FRAMEPOINT_BOTTOMRIGHT, 0.0f, 0.0f, true);
texture->SetPoint(FRAMEPOINT_TOPLEFT, this, FRAMEPOINT_TOPLEFT, 0.0f, 0.0f, true);
texture->SetPoint(FRAMEPOINT_TOPRIGHT, this, FRAMEPOINT_TOPRIGHT, 0.0f, 0.0f, true);
}
this->m_barTexture = texture;
this->m_changed = true;
}
void CSimpleStatusBar::SetMinMaxValues(float min, float max) {
if (min > max) {
min = max;
@ -108,6 +201,20 @@ void CSimpleStatusBar::SetMinMaxValues(float min, float max) {
}
}
void CSimpleStatusBar::SetOrientation(ORIENTATION orientation) {
// TODO
}
void CSimpleStatusBar::SetRotatesTexture(int32_t enabled) {
// TODO
}
void CSimpleStatusBar::SetStatusBarColor(const CImVector& color) {
if (this->m_barTexture) {
this->m_barTexture->SetVertexColor(color);
}
}
void CSimpleStatusBar::SetValue(float value) {
if (!this->m_rangeSet) {
return;

View File

@ -20,13 +20,24 @@ class CSimpleStatusBar : public CSimpleFrame {
virtual bool IsA(int32_t type);
// TODO
virtual void SetValue(float value);
virtual void LoadXML(const XMLNode* node, CStatus* status);
// Public member functions
CSimpleStatusBar(CSimpleFrame* parent);
CSimpleStatusBar(CSimpleFrame* parent)
: CSimpleFrame(parent)
, m_changed(false)
, m_rangeSet(false)
, m_valueSet(false) {};
float GetMaxValue() const;
float GetMinValue() const;
float GetValue() const;
void RunOnMinMaxChangedScript();
void RunOnValueChangedScript();
void SetBarTexture(CSimpleTexture* texture, int32_t drawlayer);
void SetMinMaxValues(float min, float max);
void SetOrientation(ORIENTATION orientation);
void SetRotatesTexture(int32_t enabled);
void SetStatusBarColor(const CImVector& color);
protected:
// Protected member variables

View File

@ -15,7 +15,13 @@ int32_t CSimpleStatusBar_SetOrientation(lua_State* L) {
}
int32_t CSimpleStatusBar_GetMinMaxValues(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
auto type = CSimpleStatusBar::GetObjectType();
auto statusBar = static_cast<CSimpleStatusBar*>(FrameScript_GetObjectThis(L, type));
lua_pushnumber(L, statusBar->GetMinValue());
lua_pushnumber(L, statusBar->GetMaxValue());
return 2;
}
int32_t CSimpleStatusBar_SetMinMaxValues(lua_State* L) {
@ -83,7 +89,15 @@ int32_t CSimpleStatusBar_GetStatusBarColor(lua_State* L) {
}
int32_t CSimpleStatusBar_SetStatusBarColor(lua_State* L) {
WHOA_UNIMPLEMENTED(0);
auto type = CSimpleStatusBar::GetObjectType();
auto statusBar = static_cast<CSimpleStatusBar*>(FrameScript_GetObjectThis(L, type));
CImVector color = {};
FrameScript_GetColor(L, 2, color);
statusBar->SetStatusBarColor(color);
return 0;
}
int32_t CSimpleStatusBar_GetRotatesTexture(lua_State* L) {