metaforce/Runtime/GuiSys/CGuiWidget.cpp

263 lines
7.6 KiB
C++
Raw Normal View History

#include "Runtime/GuiSys/CGuiWidget.hpp"
#include "Runtime/GuiSys/CGuiFrame.hpp"
#include <logvisor/logvisor.hpp>
2016-03-10 03:47:37 +00:00
2018-12-08 05:30:43 +00:00
namespace urde {
2016-03-14 00:58:19 +00:00
static logvisor::Module Log("urde::CGuiWidget");
2016-03-10 03:47:37 +00:00
2016-03-11 22:50:15 +00:00
CGuiWidget::CGuiWidget(const CGuiWidgetParms& parms)
2018-12-08 05:30:43 +00:00
: x70_selfId(parms.x6_selfId)
, x72_parentId(parms.x8_parentId)
, m_initColor(parms.x10_color)
2018-12-08 05:30:43 +00:00
, xa4_color(parms.x10_color)
, xa8_color2(parms.x10_color)
, xac_drawFlags(parms.x14_drawFlags)
2019-07-21 08:42:52 +00:00
, xb0_frame(parms.x0_frame)
, m_name(parms.m_name) {
2018-12-08 05:30:43 +00:00
xb6_24_pg = parms.xd_g;
xb6_25_isVisible = parms.xa_defaultVisible;
xb6_26_isActive = parms.xb_defaultActive;
xb6_27_isSelectable = true;
xb6_28_eventLock = false;
xb6_29_cullFaces = parms.xc_cullFaces;
xb6_30_depthGreater = false;
xb6_31_depthTest = true;
xb7_24_depthWrite = false;
xb7_25_ = true;
2019-01-20 06:43:11 +00:00
m_mouseActive = false;
2018-12-08 05:30:43 +00:00
RecalcWidgetColor(ETraversalMode::Single);
}
CGuiWidget::CGuiWidgetParms CGuiWidget::ReadWidgetHeader(CGuiFrame* frame, CInputStream& in) {
std::string name = in.readString(-1);
s16 selfId = frame->GetWidgetIdDB().AddWidget(name);
std::string parent = in.readString(-1);
s16 parentId = frame->GetWidgetIdDB().AddWidget(parent);
bool useAnimController = in.readBool();
bool defaultVis = in.readBool();
bool defaultActive = in.readBool();
bool cullFaces = in.readBool();
zeus::CColor color;
color.readRGBABig(in);
EGuiModelDrawFlags df = EGuiModelDrawFlags(in.readUint32Big());
return CGuiWidget::CGuiWidgetParms(frame, useAnimController, selfId, parentId, defaultVis, defaultActive, cullFaces,
2019-07-21 08:42:52 +00:00
color, df, true, false, std::move(name));
2018-12-08 05:30:43 +00:00
}
std::shared_ptr<CGuiWidget> CGuiWidget::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) {
CGuiWidgetParms parms = ReadWidgetHeader(frame, in);
std::shared_ptr<CGuiWidget> ret = std::make_shared<CGuiWidget>(parms);
ret->ParseBaseInfo(frame, in, parms);
return ret;
}
void CGuiWidget::Initialize() {}
void CGuiWidget::ParseBaseInfo(CGuiFrame* frame, CInputStream& in, const CGuiWidgetParms& parms) {
CGuiWidget* parent = frame->FindWidget(parms.x8_parentId);
bool isWorker = in.readBool();
if (isWorker)
xb4_workerId = in.readInt16Big();
zeus::CVector3f trans = zeus::CVector3f::ReadBig(in);
zeus::CMatrix3f orient = zeus::CMatrix3f::ReadBig(in);
x74_transform = zeus::CTransform(orient, trans);
m_initTransform = x74_transform;
2018-12-08 05:30:43 +00:00
ReapplyXform();
2020-03-05 02:40:03 +00:00
(void)zeus::CVector3f::ReadBig(in); // Unused
2018-12-08 05:30:43 +00:00
in.readUint32Big();
in.readUint16Big();
if (isWorker) {
if (!parent->AddWorkerWidget(this)) {
2019-07-20 04:27:21 +00:00
Log.report(logvisor::Warning, fmt("Warning: Discarding useless worker id. Parent is not a compound widget."));
2018-12-08 05:30:43 +00:00
xb4_workerId = -1;
}
2018-12-08 05:30:43 +00:00
}
parent->AddChildWidget(this, false, true);
m_initLocalXF = x4_localXF;
}
void CGuiWidget::Reset(ETraversalMode mode) {
xa4_color = m_initColor;
xa8_color2 = m_initColor;
x74_transform = m_initTransform;
ReapplyXform();
x4_localXF = m_initLocalXF;
RecalculateTransforms();
switch (mode) {
case ETraversalMode::Children: {
CGuiWidget* child = static_cast<CGuiWidget*>(GetChildObject());
if (child)
child->Reset(ETraversalMode::ChildrenAndSiblings);
break;
}
case ETraversalMode::ChildrenAndSiblings: {
CGuiWidget* child = static_cast<CGuiWidget*>(GetChildObject());
if (child)
child->Reset(ETraversalMode::ChildrenAndSiblings);
CGuiWidget* nextSib = static_cast<CGuiWidget*>(GetNextSibling());
if (nextSib)
nextSib->Reset(ETraversalMode::ChildrenAndSiblings);
break;
}
default:
break;
}
2016-03-14 00:58:19 +00:00
}
2018-12-08 05:30:43 +00:00
void CGuiWidget::Update(float dt) {
CGuiWidget* ch = static_cast<CGuiWidget*>(GetChildObject());
if (ch)
ch->Update(dt);
CGuiWidget* sib = static_cast<CGuiWidget*>(GetNextSibling());
if (sib)
sib->Update(dt);
2016-03-15 23:23:45 +00:00
}
void CGuiWidget::Draw(const CGuiWidgetDrawParms&) const {}
2016-12-16 04:35:49 +00:00
void CGuiWidget::ProcessUserInput(const CFinalInput& input) {}
2016-03-15 23:23:45 +00:00
void CGuiWidget::Touch() const {}
2018-12-08 05:30:43 +00:00
bool CGuiWidget::GetIsVisible() const { return xb6_25_isVisible; }
2016-03-15 23:23:45 +00:00
2018-12-08 05:30:43 +00:00
bool CGuiWidget::GetIsActive() const { return xb6_26_isActive; }
2016-03-15 23:23:45 +00:00
2019-01-20 06:43:11 +00:00
bool CGuiWidget::GetMouseActive() const { return m_mouseActive; }
2018-12-08 05:30:43 +00:00
void CGuiWidget::InitializeRGBAFactor() {
CGuiWidget* child = static_cast<CGuiWidget*>(GetChildObject());
if (child)
child->InitializeRGBAFactor();
CGuiWidget* nextSib = static_cast<CGuiWidget*>(GetNextSibling());
if (nextSib)
nextSib->InitializeRGBAFactor();
2017-04-04 05:48:13 +00:00
}
2018-12-08 05:30:43 +00:00
bool CGuiWidget::GetIsFinishedLoadingWidgetSpecific() const { return true; }
2016-03-15 23:23:45 +00:00
2018-12-08 05:30:43 +00:00
void CGuiWidget::SetTransform(const zeus::CTransform& xf) {
x74_transform = xf;
ReapplyXform();
2016-03-15 23:23:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CGuiWidget::SetIdlePosition(const zeus::CVector3f& pos, bool reapply) {
x74_transform.origin = pos;
if (reapply)
ReapplyXform();
2016-03-15 23:23:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CGuiWidget::ReapplyXform() {
RotateReset();
SetLocalPosition(zeus::skZero3f);
2018-12-08 05:30:43 +00:00
MultiplyO2P(x74_transform);
2016-03-16 20:49:35 +00:00
}
2018-12-08 05:30:43 +00:00
void CGuiWidget::AddChildWidget(CGuiWidget* widget, bool makeWorldLocal, bool atEnd) {
AddChildObject(widget, makeWorldLocal, atEnd);
2016-03-15 23:23:45 +00:00
}
2018-12-08 05:30:43 +00:00
bool CGuiWidget::AddWorkerWidget(CGuiWidget* worker) { return false; }
2016-03-15 23:23:45 +00:00
2018-12-08 05:30:43 +00:00
void CGuiWidget::SetVisibility(bool vis, ETraversalMode mode) {
switch (mode) {
case ETraversalMode::Children: {
2016-03-15 23:23:45 +00:00
CGuiWidget* child = static_cast<CGuiWidget*>(GetChildObject());
if (child)
2018-12-08 05:30:43 +00:00
child->SetVisibility(vis, ETraversalMode::ChildrenAndSiblings);
break;
}
case ETraversalMode::ChildrenAndSiblings: {
CGuiWidget* child = static_cast<CGuiWidget*>(GetChildObject());
if (child)
child->SetVisibility(vis, ETraversalMode::ChildrenAndSiblings);
2016-03-15 23:23:45 +00:00
CGuiWidget* nextSib = static_cast<CGuiWidget*>(GetNextSibling());
if (nextSib)
2018-12-08 05:30:43 +00:00
nextSib->SetVisibility(vis, ETraversalMode::ChildrenAndSiblings);
break;
}
default:
break;
}
SetIsVisible(vis);
}
void CGuiWidget::RecalcWidgetColor(ETraversalMode mode) {
CGuiWidget* parent = static_cast<CGuiWidget*>(GetParent());
if (parent)
xa8_color2 = xa4_color * parent->xa8_color2;
else
xa8_color2 = xa4_color;
switch (mode) {
case ETraversalMode::ChildrenAndSiblings: {
CGuiWidget* nextSib = static_cast<CGuiWidget*>(GetNextSibling());
if (nextSib)
nextSib->RecalcWidgetColor(ETraversalMode::ChildrenAndSiblings);
2019-02-18 05:47:46 +00:00
[[fallthrough]];
2018-12-08 05:30:43 +00:00
}
case ETraversalMode::Children: {
CGuiWidget* child = static_cast<CGuiWidget*>(GetChildObject());
if (child)
child->RecalcWidgetColor(ETraversalMode::ChildrenAndSiblings);
2019-02-18 05:47:46 +00:00
break;
2018-12-08 05:30:43 +00:00
}
default:
break;
}
}
CGuiWidget* CGuiWidget::FindWidget(s16 id) {
if (x70_selfId == id)
return this;
CGuiWidget* child = static_cast<CGuiWidget*>(GetChildObject());
if (child) {
CGuiWidget* found = child->FindWidget(id);
if (found)
return found;
}
CGuiWidget* nextSib = static_cast<CGuiWidget*>(GetNextSibling());
if (nextSib) {
CGuiWidget* found = nextSib->FindWidget(id);
if (found)
return found;
}
return nullptr;
}
bool CGuiWidget::GetIsFinishedLoading() const { return GetIsFinishedLoadingWidgetSpecific(); }
void CGuiWidget::DispatchInitialize() {
Initialize();
CGuiWidget* ch = static_cast<CGuiWidget*>(GetChildObject());
if (ch)
ch->DispatchInitialize();
CGuiWidget* sib = static_cast<CGuiWidget*>(GetNextSibling());
if (sib)
sib->DispatchInitialize();
}
void CGuiWidget::SetColor(const zeus::CColor& color) {
xa4_color = color;
RecalcWidgetColor(ETraversalMode::Children);
2016-03-14 00:58:19 +00:00
}
void CGuiWidget::OnActiveChange() {}
void CGuiWidget::OnVisibleChange() {}
2016-03-14 00:58:19 +00:00
2018-12-08 05:30:43 +00:00
void CGuiWidget::SetIsVisible(bool vis) {
xb6_25_isVisible = vis;
OnVisibleChange();
2016-03-15 23:23:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CGuiWidget::SetIsActive(bool a) {
if (a != xb6_26_isActive) {
xb6_26_isActive = a;
OnActiveChange();
}
2016-03-11 22:50:15 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde