mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-10-25 21:36:05 +03:00
feat(ui): implement CSimpleStatusBar::LoadXML
This commit is contained in:
parent
fa55a29a93
commit
dbc140d1e4
@ -1,7 +1,10 @@
|
||||
#include "ui/CSimpleStatusBar.hpp"
|
||||
#include "ui/CSimpleStatusBarScript.hpp"
|
||||
#include "ui/CSimpleTexture.hpp"
|
||||
#include "ui/LoadXML.hpp"
|
||||
#include "util/Lua.hpp"
|
||||
#include "util/StringTo.hpp"
|
||||
#include <common/XML.hpp>
|
||||
|
||||
int32_t CSimpleStatusBar::s_metatable = 0;
|
||||
int32_t CSimpleStatusBar::s_objectType = 0;
|
||||
@ -87,6 +90,24 @@ void CSimpleStatusBar::SetBarTexture(CSimpleTexture* texture, int32_t layer) {
|
||||
this->m_barTexture = texture;
|
||||
}
|
||||
|
||||
void CSimpleStatusBar::SetRotatesTexture(bool rotates) {
|
||||
if (rotates) {
|
||||
C2Vector v[4] = {
|
||||
{ 0.0f, 1.0f },
|
||||
{ 1.0f, 1.0f },
|
||||
{ 0.0f, 0.0f },
|
||||
{ 1.0f, 0.0f }
|
||||
};
|
||||
|
||||
this->m_barTexture->SetTexCoord(v);
|
||||
this->m_flags = this->m_flags ^ (this->m_flags ^ 8) & 8 | 1;
|
||||
} else {
|
||||
CRect r(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
this->m_barTexture->SetTexCoord(r);
|
||||
this->m_flags = this->m_flags ^ (this->m_flags ^ 0) & 8 | 1;
|
||||
}
|
||||
}
|
||||
|
||||
void CSimpleStatusBar::RunOnMinMaxChanged() {
|
||||
if (this->m_onMinMaxChanged.luaRef) {
|
||||
auto L = FrameScript_GetContext();
|
||||
@ -118,6 +139,12 @@ void CSimpleStatusBar::SetValue(float value) {
|
||||
}
|
||||
}
|
||||
|
||||
void CSimpleStatusBar::SetStatusBarColor(CImVector& color) {
|
||||
if (this->m_barTexture) {
|
||||
this->m_barTexture->SetVertexColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
bool CSimpleStatusBar::IsA(int32_t type) {
|
||||
return type == CSimpleStatusBar::s_objectType
|
||||
|| type == CSimpleFrame::s_objectType
|
||||
@ -148,3 +175,60 @@ FrameScript_Object::ScriptIx* CSimpleStatusBar::GetScriptByName(const char* name
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CSimpleStatusBar::LoadXML(XMLNode* node, CStatus* status) {
|
||||
CSimpleFrame::LoadXML(node, status);
|
||||
|
||||
int32_t layer = 2;
|
||||
|
||||
auto drawLayer = node->GetAttributeByName("drawLayer");
|
||||
if (drawLayer && *drawLayer) {
|
||||
StringToDrawLayer(drawLayer, layer);
|
||||
}
|
||||
|
||||
for (auto child = node->m_child; child; child = child->m_next) {
|
||||
if (!SStrCmpI(child->GetName(), "BarTexture", STORM_MAX_STR)) {
|
||||
auto texture = LoadXML_Texture(child, this, status);
|
||||
this->SetBarTexture(texture, layer);
|
||||
} else if (!SStrCmpI(child->GetName(), "BarColor", STORM_MAX_STR)) {
|
||||
CImVector color;
|
||||
if (LoadXML_Color(child, color)) {
|
||||
this->SetStatusBarColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto sminValue = node->GetAttributeByName("minValue");
|
||||
auto smaxValue = node->GetAttributeByName("maxValue");
|
||||
if (sminValue && *sminValue && smaxValue && *smaxValue) {
|
||||
auto minValue = SStrToFloat(sminValue);
|
||||
auto maxValue = SStrToFloat(smaxValue);
|
||||
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 sdefValue = node->GetAttributeByName("defaultValue");
|
||||
if (sdefValue && *sdefValue) {
|
||||
this->SetValue(SStrToFloat(sdefValue));
|
||||
}
|
||||
}
|
||||
|
||||
auto sorientation = node->GetAttributeByName("orientation");
|
||||
if (sorientation && *sorientation) {
|
||||
uint32_t orientation;
|
||||
if (StringToOrientation(sorientation, orientation)) {
|
||||
this->SetOrientation(orientation);
|
||||
} else {
|
||||
status->Add(STATUS_WARNING, "Frame %s: Unknown orientation %s in element %s", this->GetDisplayName(), sorientation, node->GetName());
|
||||
}
|
||||
}
|
||||
|
||||
auto rotatesTexture = node->GetAttributeByName("rotatesTexture");
|
||||
if (rotatesTexture && *rotatesTexture) {
|
||||
this->SetRotatesTexture(StringToBOOL(rotatesTexture));
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,14 +20,17 @@ class CSimpleStatusBar : public CSimpleFrame {
|
||||
void SetMinMaxValues(float minValue, float maxValue);
|
||||
void SetBarTexture(const char* texFile, int32_t layer);
|
||||
void SetBarTexture(CSimpleTexture* texture, int32_t layer);
|
||||
void SetRotatesTexture(bool rotates);
|
||||
void RunOnMinMaxChanged();
|
||||
void RunOnValueChanged();
|
||||
|
||||
// Virtual member functions
|
||||
virtual void SetValue(float value);
|
||||
virtual void SetStatusBarColor(CImVector& color);
|
||||
virtual bool IsA(int32_t type);
|
||||
virtual int32_t GetScriptMetaTable();
|
||||
virtual ScriptIx* GetScriptByName(const char* name, ScriptData& data);
|
||||
virtual void LoadXML(XMLNode* node, CStatus* status);
|
||||
|
||||
// Member variables
|
||||
uint32_t m_flags = 0;
|
||||
|
||||
@ -134,19 +134,51 @@ static int32_t Script_SetStatusBarTexture(lua_State* L) {
|
||||
}
|
||||
|
||||
static int32_t Script_GetStatusBarColor(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
auto type = CSimpleStatusBar::GetObjectType();
|
||||
auto statusBar = static_cast<CSimpleStatusBar*>(FrameScript_GetObjectThis(L, type));
|
||||
auto texture = statusBar->m_barTexture;
|
||||
|
||||
CImVector color;
|
||||
|
||||
if (texture) {
|
||||
texture->GetVertexColor(color);
|
||||
} else {
|
||||
color.Set(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
lua_pushnumber(L, color.r * 0.00392156);
|
||||
lua_pushnumber(L, color.g * 0.00392156);
|
||||
lua_pushnumber(L, color.b * 0.00392156);
|
||||
lua_pushnumber(L, color.a * 0.00392156);
|
||||
return 4;
|
||||
}
|
||||
|
||||
static int32_t Script_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;
|
||||
}
|
||||
|
||||
static int32_t Script_GetRotatesTexture(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
auto type = CSimpleStatusBar::GetObjectType();
|
||||
auto statusBar = static_cast<CSimpleStatusBar*>(FrameScript_GetObjectThis(L, type));
|
||||
if (statusBar->m_flags & 8) {
|
||||
lua_pushnumber(L, 1.0);
|
||||
} else {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int32_t Script_SetRotatesTexture(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
auto type = CSimpleStatusBar::GetObjectType();
|
||||
auto statusBar = static_cast<CSimpleStatusBar*>(FrameScript_GetObjectThis(L, type));
|
||||
statusBar->SetRotatesTexture(StringToBOOL(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user