2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/GuiSys/CHudRadarInterface.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CGameState.hpp"
|
|
|
|
#include "Runtime/CSimplePool.hpp"
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/Camera/CGameCamera.hpp"
|
2022-02-25 07:45:25 +00:00
|
|
|
#include "Runtime/Graphics/CCubeRenderer.hpp"
|
2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/GuiSys/CGuiCamera.hpp"
|
|
|
|
#include "Runtime/GuiSys/CGuiFrame.hpp"
|
|
|
|
#include "Runtime/GuiSys/CGuiWidgetDrawParms.hpp"
|
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
|
|
|
#include "Runtime/World/CWallCrawlerSwarm.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2017-04-02 03:03:37 +00:00
|
|
|
|
2019-12-22 20:04:07 +00:00
|
|
|
#include <zeus/CEulerAngles.hpp>
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
CHudRadarInterface::CHudRadarInterface(CGuiFrame& baseHud, CStateManager& stateMgr) {
|
|
|
|
x0_txtrRadarPaint = g_SimplePool->GetObj("TXTR_RadarPaint");
|
|
|
|
x40_BaseWidget_RadarStuff = baseHud.FindWidget("BaseWidget_RadarStuff");
|
|
|
|
x44_camera = baseHud.GetFrameCamera();
|
|
|
|
xc_radarStuffXf = x40_BaseWidget_RadarStuff->GetLocalTransform();
|
|
|
|
x40_BaseWidget_RadarStuff->SetColor(g_tweakGuiColors->GetRadarStuffColor());
|
2017-04-07 05:35:09 +00:00
|
|
|
}
|
2017-04-02 03:03:37 +00:00
|
|
|
|
2022-03-27 00:24:23 +00:00
|
|
|
void CHudRadarInterface::DoDrawRadarPaint(float radius) {
|
2018-12-08 05:30:43 +00:00
|
|
|
radius *= 4.f;
|
2020-03-13 20:32:24 +00:00
|
|
|
|
2022-03-27 00:24:23 +00:00
|
|
|
CGraphics::StreamBegin(GX::TRIANGLESTRIP);
|
|
|
|
CGraphics::StreamTexcoord(0.f, 1.f);
|
|
|
|
CGraphics::StreamVertex(-radius, 0.f, radius);
|
|
|
|
CGraphics::StreamTexcoord(0.f, 0.f);
|
|
|
|
CGraphics::StreamVertex(-radius, 0.f, -radius);
|
|
|
|
CGraphics::StreamTexcoord(1.f, 1.f);
|
|
|
|
CGraphics::StreamVertex(radius, 0.f, radius);
|
|
|
|
CGraphics::StreamTexcoord(1.f, 0.f);
|
|
|
|
CGraphics::StreamVertex(radius, 0.f, -radius);
|
|
|
|
CGraphics::StreamEnd();
|
2017-04-07 05:35:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CHudRadarInterface::DrawRadarPaint(const zeus::CVector3f& enemyPos, float radius, float alpha,
|
2020-04-10 01:23:47 +00:00
|
|
|
const SRadarPaintDrawParms& parms) {
|
2020-04-13 18:25:54 +00:00
|
|
|
const zeus::CVector2f playerToEnemy = enemyPos.toVec2f() - parms.x0_playerPos.toVec2f();
|
|
|
|
const float zDelta = std::fabs(enemyPos.z() - parms.x0_playerPos.z());
|
|
|
|
|
|
|
|
if (playerToEnemy.magnitude() > parms.x78_xyRadius || zDelta > parms.x7c_zRadius) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zDelta > parms.x80_ZCloseRadius) {
|
|
|
|
alpha *= 1.f - (zDelta - parms.x80_ZCloseRadius) / (parms.x7c_zRadius - parms.x80_ZCloseRadius);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-13 18:25:54 +00:00
|
|
|
|
|
|
|
const zeus::CVector2f scopeScaled = playerToEnemy * parms.x70_scopeScalar;
|
2022-03-27 00:24:23 +00:00
|
|
|
g_Renderer->SetModelMatrix(
|
|
|
|
parms.x3c_postTranslate *
|
|
|
|
zeus::CTransform::Translate(parms.xc_preTranslate * zeus::CVector3f(scopeScaled.x(), 0.f, scopeScaled.y())));
|
|
|
|
|
2020-04-13 18:25:54 +00:00
|
|
|
zeus::CColor color = g_tweakGuiColors->GetRadarEnemyPaintColor();
|
|
|
|
color.a() *= alpha;
|
|
|
|
color.a() *= parms.x74_alpha;
|
2022-03-27 00:24:23 +00:00
|
|
|
CGraphics::StreamColor(color);
|
|
|
|
DoDrawRadarPaint(radius);
|
2017-04-07 05:35:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CHudRadarInterface::SetIsVisibleGame(bool v) {
|
|
|
|
x3c_24_visibleGame = v;
|
|
|
|
x40_BaseWidget_RadarStuff->SetVisibility(x3c_25_visibleDebug && x3c_24_visibleGame, ETraversalMode::Children);
|
2017-04-02 03:03:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CHudRadarInterface::Update(float dt, const CStateManager& mgr) {
|
2020-04-13 18:25:54 +00:00
|
|
|
const CPlayerState& playerState = *mgr.GetPlayerState();
|
|
|
|
const float visorTransFactor = (playerState.GetCurrentVisor() == CPlayerState::EPlayerVisor::Combat)
|
|
|
|
? playerState.GetVisorTransitionFactor()
|
|
|
|
: 0.f;
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CColor color = g_tweakGuiColors->GetRadarStuffColor();
|
|
|
|
color.a() *= g_GameState->GameOptions().GetHUDAlpha() / 255.f * visorTransFactor;
|
|
|
|
x40_BaseWidget_RadarStuff->SetColor(color);
|
2020-04-13 18:25:54 +00:00
|
|
|
const bool tweakVis = g_tweakGui->GetHudVisMode() >= ITweakGui::EHudVisMode::Three;
|
|
|
|
|
|
|
|
if (tweakVis == x3c_25_visibleDebug) {
|
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-13 18:25:54 +00:00
|
|
|
|
|
|
|
x3c_25_visibleDebug = tweakVis;
|
|
|
|
x40_BaseWidget_RadarStuff->SetVisibility(x3c_25_visibleDebug && x3c_24_visibleGame, ETraversalMode::Children);
|
2017-04-07 05:35:09 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 01:23:47 +00:00
|
|
|
void CHudRadarInterface::Draw(const CStateManager& mgr, float alpha) {
|
2018-12-08 05:30:43 +00:00
|
|
|
alpha *= g_GameState->GameOptions().GetHUDAlpha() / 255.f;
|
|
|
|
if (g_tweakGui->GetHudVisMode() == ITweakGui::EHudVisMode::Zero || !x3c_24_visibleGame || !x0_txtrRadarPaint ||
|
2020-04-13 18:25:54 +00:00
|
|
|
!x0_txtrRadarPaint.IsLoaded()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-04-13 18:25:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
SRadarPaintDrawParms drawParms;
|
|
|
|
|
2020-04-13 18:25:54 +00:00
|
|
|
const CPlayer& player = mgr.GetPlayer();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (player.IsOverrideRadarRadius()) {
|
|
|
|
drawParms.x78_xyRadius = player.GetRadarXYRadiusOverride();
|
|
|
|
drawParms.x7c_zRadius = player.GetRadarZRadiusOverride();
|
|
|
|
drawParms.x80_ZCloseRadius = 0.667f * drawParms.x7c_zRadius;
|
|
|
|
} else {
|
|
|
|
drawParms.x78_xyRadius = g_tweakGui->GetRadarXYRadius();
|
|
|
|
drawParms.x7c_zRadius = g_tweakGui->GetRadarZRadius();
|
|
|
|
drawParms.x80_ZCloseRadius = g_tweakGui->GetRadarZCloseRadius();
|
|
|
|
}
|
|
|
|
|
|
|
|
drawParms.x6c_scopeRadius = g_tweakGui->GetRadarScopeCoordRadius();
|
|
|
|
drawParms.x70_scopeScalar = drawParms.x6c_scopeRadius / drawParms.x78_xyRadius;
|
|
|
|
|
2020-04-13 18:25:54 +00:00
|
|
|
const float camZ =
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CEulerAngles(zeus::CQuaternion(mgr.GetCameraManager()->GetCurrentCamera(mgr)->GetTransform().basis)).z();
|
|
|
|
zeus::CRelAngle angleZ(camZ);
|
2018-12-17 03:52:51 +00:00
|
|
|
angleZ.makeRel();
|
2018-12-08 05:30:43 +00:00
|
|
|
drawParms.xc_preTranslate = zeus::CTransform::RotateY(angleZ);
|
|
|
|
drawParms.x3c_postTranslate = x40_BaseWidget_RadarStuff->GetWorldTransform();
|
2020-04-13 18:25:54 +00:00
|
|
|
const float enemyRadius = g_tweakGui->GetRadarEnemyPaintRadius();
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
x44_camera->Draw(CGuiWidgetDrawParms{0.f, zeus::CVector3f{}});
|
|
|
|
|
2022-03-27 00:24:23 +00:00
|
|
|
g_Renderer->SetModelMatrix(drawParms.x3c_postTranslate);
|
|
|
|
g_Renderer->SetBlendMode_AdditiveAlpha();
|
|
|
|
x0_txtrRadarPaint->Load(GX::TEXMAP0, EClampMode::Repeat);
|
|
|
|
CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::sTevPass805a5ebc);
|
|
|
|
g_Renderer->SetDepthReadWrite(false, false);
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CColor playerColor = g_tweakGuiColors->GetRadarPlayerPaintColor();
|
|
|
|
playerColor.a() *= alpha;
|
2022-03-27 00:24:23 +00:00
|
|
|
CGraphics::StreamColor(playerColor);
|
|
|
|
DoDrawRadarPaint(g_tweakGui->GetRadarPlayerPaintRadius());
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-04-13 18:25:54 +00:00
|
|
|
const zeus::CAABox radarBounds(
|
2018-12-08 05:30:43 +00:00
|
|
|
player.GetTranslation().x() - drawParms.x78_xyRadius, player.GetTranslation().y() - drawParms.x78_xyRadius,
|
|
|
|
player.GetTranslation().z() - drawParms.x7c_zRadius, player.GetTranslation().x() + drawParms.x78_xyRadius,
|
|
|
|
player.GetTranslation().y() + drawParms.x78_xyRadius, player.GetTranslation().z() + drawParms.x7c_zRadius);
|
|
|
|
|
2021-06-07 00:07:45 +00:00
|
|
|
EntityList nearList;
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.BuildNearList(nearList, radarBounds,
|
|
|
|
CMaterialFilter(CMaterialList(EMaterialTypes::Target, EMaterialTypes::RadarObject),
|
|
|
|
CMaterialList(EMaterialTypes::ExcludeFromRadar),
|
|
|
|
CMaterialFilter::EFilterType::IncludeExclude),
|
|
|
|
nullptr);
|
2019-01-20 06:43:11 +00:00
|
|
|
drawParms.x0_playerPos = mgr.GetPlayer().GetTranslation();
|
2019-02-24 07:15:54 +00:00
|
|
|
drawParms.x74_alpha = alpha;
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-09-18 21:04:50 +00:00
|
|
|
for (const auto& id : nearList) {
|
2020-04-13 18:25:54 +00:00
|
|
|
if (const TCastToConstPtr<CActor> act = mgr.GetObjectById(id)) {
|
|
|
|
if (!act->GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-04-13 18:25:54 +00:00
|
|
|
}
|
|
|
|
if (const TCastToConstPtr<CWallCrawlerSwarm> swarm = act.GetPtr()) {
|
|
|
|
const float radius = enemyRadius * 0.5f;
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const CWallCrawlerSwarm::CBoid& boid : swarm->GetBoids()) {
|
2020-04-13 18:25:54 +00:00
|
|
|
if (!boid.GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-04-13 18:25:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
DrawRadarPaint(boid.GetTranslation(), radius, 0.5f, drawParms);
|
2017-04-07 05:35:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
DrawRadarPaint(act->GetTranslation(), enemyRadius, 1.f, drawParms);
|
|
|
|
}
|
2017-04-07 05:35:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-04-03 01:39:23 +00:00
|
|
|
|
2022-03-27 00:24:23 +00:00
|
|
|
g_Renderer->SetDepthReadWrite(true, true);
|
2017-04-03 01:39:23 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|