2016-03-12 04:58:56 +00:00
|
|
|
#include "CGuiModel.hpp"
|
|
|
|
#include "CGuiFrame.hpp"
|
|
|
|
#include "CGuiSys.hpp"
|
|
|
|
#include "CSimplePool.hpp"
|
2016-03-17 02:18:01 +00:00
|
|
|
#include "CGuiWidgetDrawParms.hpp"
|
|
|
|
#include "Graphics/CGraphics.hpp"
|
2016-03-12 04:58:56 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CGuiModel::CGuiModel(const CGuiWidgetParms& parms, CSimplePool* sp, CAssetId modelId, u32 lightMask, bool flag)
|
2017-12-21 03:19:54 +00:00
|
|
|
: CGuiWidget(parms), xc8_modelId(modelId), xcc_lightMask(lightMask)
|
2016-03-12 04:58:56 +00:00
|
|
|
{
|
2017-11-13 13:13:34 +00:00
|
|
|
if (!flag || !modelId.IsValid() ||
|
2016-03-12 04:58:56 +00:00
|
|
|
parms.x0_frame->GetGuiSys().GetUsageMode() == CGuiSys::EUsageMode::Two)
|
|
|
|
return;
|
|
|
|
|
2017-12-21 03:19:54 +00:00
|
|
|
xb8_model = sp->GetObj({SBIG('CMDL'), modelId});
|
2016-03-12 04:58:56 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
std::vector<CAssetId> CGuiModel::GetModelAssets() const
|
2016-03-17 02:18:01 +00:00
|
|
|
{
|
2017-12-21 03:19:54 +00:00
|
|
|
return {xc8_modelId};
|
2016-03-17 02:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGuiModel::GetIsFinishedLoadingWidgetSpecific() const
|
|
|
|
{
|
2017-12-21 03:19:54 +00:00
|
|
|
if (!xb8_model)
|
2016-03-17 02:18:01 +00:00
|
|
|
return true;
|
2017-12-21 03:19:54 +00:00
|
|
|
const CModel* model = xb8_model.GetObj();
|
2016-03-17 02:18:01 +00:00
|
|
|
if (!model)
|
|
|
|
return false;
|
2016-09-02 19:32:57 +00:00
|
|
|
model->GetInstance().Touch(0);
|
2016-03-17 02:18:01 +00:00
|
|
|
return model->IsLoaded(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiModel::Touch() const
|
|
|
|
{
|
2017-12-21 03:19:54 +00:00
|
|
|
const CModel* model = xb8_model.GetObj();
|
2016-03-17 02:18:01 +00:00
|
|
|
if (model)
|
2016-09-02 19:32:57 +00:00
|
|
|
model->GetInstance().Touch(0);
|
2016-03-17 02:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiModel::Draw(const CGuiWidgetDrawParms& parms) const
|
|
|
|
{
|
|
|
|
CGraphics::SetModelMatrix(x34_worldXF);
|
2017-12-21 03:19:54 +00:00
|
|
|
if (!xb8_model)
|
2016-03-17 02:18:01 +00:00
|
|
|
return;
|
|
|
|
if (!GetIsFinishedLoading())
|
|
|
|
return;
|
2017-12-21 03:19:54 +00:00
|
|
|
const CModel* model = xb8_model.GetObj();
|
2016-03-17 02:18:01 +00:00
|
|
|
if (!model)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (GetIsVisible())
|
|
|
|
{
|
2016-12-15 22:37:34 +00:00
|
|
|
zeus::CColor moduCol = xa8_color2;
|
2016-03-17 02:18:01 +00:00
|
|
|
moduCol.a *= parms.x0_alphaMod;
|
2017-12-21 03:19:54 +00:00
|
|
|
xb0_frame->EnableLights(xcc_lightMask, const_cast<CBooModel&>(model->GetInstance()));
|
2017-12-10 05:30:01 +00:00
|
|
|
//if (xb6_29_cullFaces)
|
|
|
|
// CGraphics::SetCullMode(ERglCullMode::Front);
|
2016-03-17 02:18:01 +00:00
|
|
|
|
2016-12-15 22:37:34 +00:00
|
|
|
switch (xac_drawFlags)
|
2016-03-17 02:18:01 +00:00
|
|
|
{
|
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);
|
2017-03-10 20:52:53 +00:00
|
|
|
flags.m_extendedShader = EExtendedShader::Flat;
|
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);
|
2017-03-10 20:52:53 +00:00
|
|
|
flags.m_extendedShader = EExtendedShader::Lighting;
|
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
|
|
|
{
|
2017-12-21 03:19:54 +00:00
|
|
|
CModelFlags flags(5, 0, (u32(xb7_24_depthWrite) << 1) | u32(xb6_31_depthTest), moduCol);
|
|
|
|
flags.m_noCull = !xb6_29_cullFaces;
|
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
|
|
|
{
|
2017-12-21 03:19:54 +00:00
|
|
|
CModelFlags flags(7, 0, (u32(xb7_24_depthWrite) << 1) | u32(xb6_31_depthTest), moduCol);
|
|
|
|
flags.m_noCull = !xb6_29_cullFaces;
|
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
|
|
|
{
|
2017-12-21 03:19:54 +00:00
|
|
|
CModelFlags flags(5, 0, xb6_31_depthTest, moduCol);
|
|
|
|
flags.m_noCull = !xb6_29_cullFaces;
|
2016-03-17 02:18:01 +00:00
|
|
|
model->Draw(flags);
|
|
|
|
|
2017-12-21 03:19:54 +00:00
|
|
|
flags.x0_blendMode = 7;
|
2017-03-20 05:09:53 +00:00
|
|
|
flags.x1_matSetIdx = 0;
|
|
|
|
flags.x2_flags = (u32(xb7_24_depthWrite) << 1) | u32(xb6_31_depthTest);
|
|
|
|
flags.x4_color = moduCol;
|
2017-12-21 03:19:54 +00:00
|
|
|
flags.m_noCull = !xb6_29_cullFaces;
|
2016-03-17 02:18:01 +00:00
|
|
|
model->Draw(flags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2017-12-10 05:30:01 +00:00
|
|
|
//if (xb6_29_cullFaces)
|
|
|
|
// CGraphics::SetCullMode(ERglCullMode::None);
|
2016-12-15 22:37:34 +00:00
|
|
|
xb0_frame->DisableLights();
|
2016-03-17 02:18:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CGuiWidget::Draw(parms);
|
|
|
|
}
|
|
|
|
|
2017-01-22 01:40:12 +00:00
|
|
|
std::shared_ptr<CGuiWidget> CGuiModel::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp)
|
2016-03-12 04:58:56 +00:00
|
|
|
{
|
2017-01-22 01:40:12 +00:00
|
|
|
CGuiWidgetParms parms = ReadWidgetHeader(frame, in);
|
2016-03-12 04:58:56 +00:00
|
|
|
|
2017-08-13 05:26:14 +00:00
|
|
|
CAssetId model = in.readUint32Big();
|
2016-03-12 04:58:56 +00:00
|
|
|
in.readUint32Big();
|
2016-03-17 02:18:01 +00:00
|
|
|
u32 lightMask = in.readUint32Big();
|
2016-03-12 04:58:56 +00:00
|
|
|
|
2017-01-22 01:40:12 +00:00
|
|
|
std::shared_ptr<CGuiWidget> ret = std::make_shared<CGuiModel>(parms, sp, model, lightMask, true);
|
2016-03-12 04:58:56 +00:00
|
|
|
ret->ParseBaseInfo(frame, in, parms);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|