metaforce/Runtime/GuiSys/CGuiModel.cpp

127 lines
3.3 KiB
C++
Raw Normal View History

#include "CGuiModel.hpp"
#include "CGuiFrame.hpp"
#include "CGuiSys.hpp"
#include "CSimplePool.hpp"
2016-03-14 00:58:19 +00:00
#include "CGuiAnimController.hpp"
2016-03-17 02:18:01 +00:00
#include "CGuiWidgetDrawParms.hpp"
#include "Graphics/CGraphics.hpp"
namespace urde
{
2016-04-14 21:42:47 +00:00
CGuiModel::CGuiModel(const CGuiWidgetParms& parms, ResId modelId, u32 lightMask, bool flag)
2016-03-17 02:18:01 +00:00
: CGuiWidget(parms), x108_modelId(modelId), x10c_lightMask(lightMask)
{
if (!flag || (modelId & 0xffff) == 0xffff ||
parms.x0_frame->GetGuiSys().GetUsageMode() == CGuiSys::EUsageMode::Two)
return;
xf8_model = parms.x0_frame->GetGuiSys().GetResStore().GetObj({SBIG('CMDL'), modelId});
}
2016-04-14 21:42:47 +00:00
std::vector<ResId> CGuiModel::GetModelAssets() const
2016-03-17 02:18:01 +00:00
{
return {x108_modelId};
}
bool CGuiModel::GetIsFinishedLoadingWidgetSpecific() const
{
if (!xf8_model)
return true;
2016-03-31 02:44:43 +00:00
const CModel* model = xf8_model.GetObj();
2016-03-17 02:18:01 +00:00
if (!model)
return false;
model->Touch(0);
return model->IsLoaded(0);
}
void CGuiModel::Touch() const
{
2016-03-31 02:44:43 +00:00
const CModel* model = xf8_model.GetObj();
2016-03-17 02:18:01 +00:00
if (model)
model->Touch(0);
}
void CGuiModel::Draw(const CGuiWidgetDrawParms& parms) const
{
CGraphics::SetModelMatrix(x34_worldXF);
if (!xf8_model)
return;
if (!GetIsFinishedLoading())
return;
2016-03-31 02:44:43 +00:00
const CModel* model = xf8_model.GetObj();
2016-03-17 02:18:01 +00:00
if (!model)
return;
if (GetIsVisible())
{
zeus::CColor moduCol = xb4_;
moduCol.a *= parms.x0_alphaMod;
xc8_frame->EnableLights(x10c_lightMask);
if (xf6_29_cullFaces)
CGraphics::SetCullMode(ERglCullMode::Front);
switch (xc4_drawFlags)
{
2016-03-17 22:19:25 +00:00
case EGuiModelDrawFlags::Shadeless:
2016-03-17 02:18:01 +00:00
{
2016-04-03 05:25:34 +00:00
CModelFlags flags(0, 0, 3, zeus::CColor::skWhite);
2016-03-17 02:18:01 +00:00
model->Draw(flags);
break;
}
2016-03-17 22:19:25 +00:00
case EGuiModelDrawFlags::Opaque:
2016-03-17 02:18:01 +00:00
{
2016-04-03 05:25:34 +00:00
CModelFlags flags(1, 0, 3, moduCol);
2016-03-17 02:18:01 +00:00
model->Draw(flags);
break;
}
2016-03-17 22:19:25 +00:00
case EGuiModelDrawFlags::Alpha:
2016-03-17 02:18:01 +00:00
{
2016-04-03 05:25:34 +00:00
CModelFlags flags(4, 0, (xf7_24_depthWrite << 1) | xf6_31_depthTest, moduCol);
2016-03-17 02:18:01 +00:00
model->Draw(flags);
break;
}
2016-03-17 22:19:25 +00:00
case EGuiModelDrawFlags::Additive:
2016-03-17 02:18:01 +00:00
{
2016-04-03 05:25:34 +00:00
CModelFlags flags(3, 0, (xf7_24_depthWrite << 1) | xf6_31_depthTest, moduCol);
2016-03-17 02:18:01 +00:00
model->Draw(flags);
break;
}
2016-03-17 22:19:25 +00:00
case EGuiModelDrawFlags::AlphaAdditiveOverdraw:
2016-03-17 02:18:01 +00:00
{
2016-04-03 05:25:34 +00:00
CModelFlags flags(4, 0, xf6_31_depthTest, moduCol);
2016-03-17 02:18:01 +00:00
model->Draw(flags);
2016-03-31 06:18:56 +00:00
flags.m_blendMode = 5;
flags.m_matSetIdx = 0;
flags.m_flags = (xf7_24_depthWrite << 1) | xf6_31_depthTest;
2016-03-17 02:18:01 +00:00
flags.color = moduCol;
model->Draw(flags);
break;
}
default: break;
}
if (xf6_29_cullFaces)
CGraphics::SetCullMode(ERglCullMode::None);
2016-03-17 22:19:25 +00:00
xc8_frame->DisableLights();
2016-03-17 02:18:01 +00:00
}
CGuiWidget::Draw(parms);
}
CGuiModel* CGuiModel::Create(CGuiFrame* frame, CInputStream& in, bool flag)
{
CGuiWidgetParms parms = ReadWidgetHeader(frame, in, flag);
2016-04-14 21:42:47 +00:00
ResId model = in.readUint32Big();
in.readUint32Big();
2016-03-17 02:18:01 +00:00
u32 lightMask = in.readUint32Big();
2016-03-17 02:18:01 +00:00
CGuiModel* ret = new CGuiModel(parms, model, lightMask, flag);
ret->ParseBaseInfo(frame, in, parms);
return ret;
}
}