metaforce/Runtime/GuiSys/CGuiModel.cpp

121 lines
3.4 KiB
C++
Raw Permalink Normal View History

#include "Runtime/GuiSys/CGuiModel.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
#include "Runtime/GuiSys/CGuiFrame.hpp"
#include "Runtime/GuiSys/CGuiSys.hpp"
#include "Runtime/GuiSys/CGuiWidgetDrawParms.hpp"
2021-04-10 08:42:06 +00:00
namespace metaforce {
2017-08-13 05:26:14 +00:00
CGuiModel::CGuiModel(const CGuiWidgetParms& parms, CSimplePool* sp, CAssetId modelId, u32 lightMask, bool flag)
2018-12-08 05:30:43 +00:00
: CGuiWidget(parms), xc8_modelId(modelId), xcc_lightMask(lightMask) {
if (!flag || !modelId.IsValid() || parms.x0_frame->GetGuiSys().GetUsageMode() == CGuiSys::EUsageMode::Two) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
xb8_model = sp->GetObj({SBIG('CMDL'), modelId});
}
bool CGuiModel::GetIsFinishedLoadingWidgetSpecific() {
if (!xb8_model) {
2018-12-08 05:30:43 +00:00
return true;
}
if (!xb8_model.IsLoaded()) {
2018-12-08 05:30:43 +00:00
return false;
}
xb8_model->Touch(0);
return xb8_model->IsLoaded(0);
2016-03-17 02:18:01 +00:00
}
void CGuiModel::Touch() {
if (CModel* const model = xb8_model.GetObj()) {
model->Touch(0);
}
2016-03-17 02:18:01 +00:00
}
void CGuiModel::Draw(const CGuiWidgetDrawParms& parms) {
2018-12-08 05:30:43 +00:00
CGraphics::SetModelMatrix(x34_worldXF);
if (!xb8_model) {
2018-12-08 05:30:43 +00:00
return;
}
if (!GetIsFinishedLoading()) {
2018-12-08 05:30:43 +00:00
return;
}
CModel* const model = xb8_model.GetObj();
if (model == nullptr) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
if (GetIsVisible()) {
2020-04-11 22:51:39 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CGuiModel::Draw {}"), m_name).c_str(), zeus::skCyan);
2018-12-08 05:30:43 +00:00
zeus::CColor moduCol = xa8_color2;
moduCol.a() *= parms.x0_alphaMod;
xb0_frame->EnableLights(xcc_lightMask);
if (xb6_29_cullFaces) {
CGraphics::SetCullMode(ERglCullMode::Front);
}
2018-12-08 05:30:43 +00:00
switch (xac_drawFlags) {
case EGuiModelDrawFlags::Shadeless: {
constexpr CModelFlags flags(0, 0, 3, zeus::skWhite);
2018-12-08 05:30:43 +00:00
model->Draw(flags);
break;
}
case EGuiModelDrawFlags::Opaque: {
CModelFlags flags(1, 0, 3, moduCol);
model->Draw(flags);
break;
}
case EGuiModelDrawFlags::Alpha: {
CModelFlags flags(5, 0, (u32(xb7_24_depthWrite) << 1) | u32(xb6_31_depthTest), moduCol);
model->Draw(flags);
break;
}
case EGuiModelDrawFlags::Additive: {
CModelFlags flags(7, 0, (u32(xb7_24_depthWrite) << 1) | u32(xb6_31_depthTest), moduCol);
model->Draw(flags);
break;
}
case EGuiModelDrawFlags::AlphaAdditiveOverdraw: {
const CModelFlags flags(5, 0, (u32(xb6_30_depthGreater) << 4) | u32(xb6_31_depthTest), moduCol);
2018-12-08 05:30:43 +00:00
model->Draw(flags);
const CModelFlags overdrawFlags(
8, 0, (u32(xb6_30_depthGreater) << 4) | (u32(xb7_24_depthWrite) << 1) | u32(xb6_31_depthTest), moduCol);
model->Draw(overdrawFlags);
2018-12-08 05:30:43 +00:00
break;
}
default:
break;
2016-03-17 02:18:01 +00:00
}
if (xb6_29_cullFaces) {
CGraphics::SetCullMode(ERglCullMode::None);
}
2018-12-08 05:30:43 +00:00
xb0_frame->DisableLights();
}
CGuiWidget::Draw(parms);
2016-03-17 02:18:01 +00:00
}
2019-01-20 06:43:11 +00:00
bool CGuiModel::TestCursorHit(const zeus::CMatrix4f& vp, const zeus::CVector2f& point) const {
if (!xb8_model || !xb8_model.IsLoaded()) {
2019-01-20 06:43:11 +00:00
return false;
}
2019-01-20 06:43:11 +00:00
return xb8_model->GetAABB().projectedPointTest(vp * x34_worldXF.toMatrix4f(), point);
}
2018-12-08 05:30:43 +00:00
std::shared_ptr<CGuiWidget> CGuiModel::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) {
CGuiWidgetParms parms = ReadWidgetHeader(frame, in);
auto model = in.Get<CAssetId>();
in.ReadLong();
u32 lightMask = in.ReadLong();
2018-12-08 05:30:43 +00:00
std::shared_ptr<CGuiWidget> ret = std::make_shared<CGuiModel>(parms, sp, model, lightMask, true);
ret->ParseBaseInfo(frame, in, parms);
return ret;
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce