Initial CGuiCursor implementation

This commit is contained in:
Luke Street 2020-03-04 13:55:48 -05:00
parent 12c9a2459f
commit d95064c7dd
5 changed files with 235 additions and 1 deletions

View File

@ -0,0 +1,124 @@
#include "Runtime/GuiSys/CGuiCursor.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/IMain.hpp"
namespace urde {
namespace {
constexpr char skGuiCursorPanName[] = "CMDL_GuiCursorPan";
constexpr char skGuiCursorReticleName[] = "CMDL_GuiCursorReticle";
} // Anonymous namespace
CGuiCursorTransfer::CGuiCursorTransfer(const CGuiCursorTransfer& other)
: x0_(other.x0_)
, x4_(other.x4_)
, x8_(other.x8_)
, x14_(other.x14_)
, x18_(other.x18_)
, x1c_(other.x1c_)
, x20_(other.x20_)
, x24_(other.x24_)
, x28_(other.x28_)
, x2c_(other.x2c_)
, x30_(other.x30_)
, x34_(other.x34_)
, x38_(other.x38_)
, x3c_(other.x3c_) {}
CGuiCursorTransfer::CGuiCursorTransfer(float f1, float f2, float f3, float f4) {
// TODO
}
CGuiCursor::CGuiCursor(const CGuiCursorTransfer& t1, const CGuiCursorTransfer& t2, ECursorState cursorState)
: x0_cursorReticle(g_SimplePool->GetObj(GetCursorName(cursorState)))
, xc_cursorPan(g_SimplePool->GetObj(skGuiCursorPanName))
, x2c_(t1)
, x6c_(t2)
, xe0_cursorColor(GetCursorColor(cursorState)) {
const zeus::CAABox& box = x0_cursorReticle.GetObj()->GetInstance().GetAABB();
float x = 30.f / (box.max.x() - box.min.x());
x20_ = zeus::CVector3f(x, 1.f, -1.f * x);
}
void FUN_800d7eec() {
const boo::SWindowRect& rect = CGraphics::GetViewport();
CGraphics::SetOrtho(rect.location[0], rect.location[0] + rect.size[0],
rect.location[1] + rect.size[1], rect.location[1], -1.f, 1.f);
CGraphics::SetViewPointMatrix(zeus::CTransform::Translate(-0.5f * rect.size[0], 0.f, -0.5f * rect.size[1]));
}
zeus::CVector3f CGuiCursor::ProjectCursorPosition() {
const SClipScreenRect& rect = CGraphics::g_CroppedViewport;
float w = 0.5f * rect.xc_width, h = 0.5f * rect.x10_height;
if (-h <= 0.f) {
h = h * x18_.y();
}
if (-w <= 0.f) {
w = w * x18_.x();
}
if (-h - h <= 0.f) {
h = -h;
}
if (-w - w <= 0.f) {
w = -w;
}
return zeus::CVector3f(std::floor(0.5f + w), 0.f, std::floor(0.5f + h));
}
void CGuiCursor::Draw() {
float alpha = xb4_ * xc8_;
if (xe8_ && 0.f < alpha) { // && DAT_805c2580 == '\0' ?
FUN_800d7eec();
const zeus::CVector3f pos = ProjectCursorPosition();
const zeus::CTransform scale = zeus::CTransform::Scale(x20_);
const zeus::CTransform translate = zeus::CTransform::Translate(pos);
zeus::CTransform t = translate * scale;
if (xb0_ < 0.5f) {
const zeus::CTransform rotX = zeus::CTransform::RotateX(zeus::degToRad(xd8_));
const zeus::CTransform rotY = zeus::CTransform::RotateY(zeus::degToRad(xdc_));
const zeus::CTransform rot = rotY * rotX;
t = t * rot;
}
CGraphics::SetModelMatrix(t);
CGraphics::SetCullMode(ERglCullMode::None);
zeus::CColor x1a4 = xe0_cursorColor;
x1a4.a() = alpha;
if (0.5f <= xb0_) {
zeus::CColor color = xe0_cursorColor;
color.a() = 2.f * (xb0_ - 0.5f);
if (xe4_ == ECursorState::x1) {
CModelFlags flags(5, 0, 2, color);
xc_cursorPan->Draw(flags);
} else {
CModelFlags flags(7, 0, 2, color);
xc_cursorPan->Draw(flags);
}
} else {
zeus::CColor color = xe0_cursorColor;
color.a() = 1.f - (2.f * xb0_);
if (xe4_ == ECursorState::x1) {
CModelFlags flags(5, 0, 2, color);
x0_cursorReticle->Draw(flags);
} else {
CModelFlags flags(7, 0, 2, color);
x0_cursorReticle->Draw(flags);
}
}
}
}
void CGuiCursor::Update(double dt) {
}
const char* CGuiCursor::GetCursorName(ECursorState state) {
return state < ECursorState::x2 ? skGuiCursorReticleName : nullptr;
}
const zeus::CColor CGuiCursor::GetCursorColor(ECursorState state) {
return zeus::Comp32(state == ECursorState::x1 ? 0x83c1ff7e : 0x6e72fbb5);
}
} // namespace urde

View File

@ -0,0 +1,97 @@
#pragma once
#include <array>
#include <vector>
#include <zeus/CColor.hpp>
#include "Runtime/CToken.hpp"
#include "Runtime/Graphics/CModel.hpp"
namespace urde {
enum class ECursorState {
x0,
x1,
x2,
};
struct SGuiCursorTransferInner {
int x0_; // unk type
int x4_; // unk type
int x8_; // unk type
int xc_; // unk type
int x10_; // unk type
int x14_; // unk type
int x18_; // unk type
};
class CGuiCursorTransfer {
private:
public:
int x0_; // unk type
int x4_; // unk type
std::vector<SGuiCursorTransferInner> x8_;
int x14_; // unk type
int x18_; // unk type
int x1c_; // unk type
int x20_; // unk type
int x24_; // unk type
union {
struct {
bool x28_ : 1;
};
u32 _dummy = 0;
};
int x2c_; // unk type
int x30_; // unk type
int x34_; // unk type
int x38_; // unk type
int x3c_; // unk type
CGuiCursorTransfer(const CGuiCursorTransfer& other);
CGuiCursorTransfer(float f1, float f2, float f3, float f4);
double GetSomeDouble();
};
class CGuiCursor {
private:
static const char* GetCursorName(ECursorState state);
static const zeus::CColor GetCursorColor(ECursorState state);
public:
TLockedToken<CModel> x0_cursorReticle;
TLockedToken<CModel> xc_cursorPan;
zeus::CVector2f x18_ = zeus::skZero2f;
zeus::CVector3f x20_ = zeus::skOne3f;
CGuiCursorTransfer x2c_;
CGuiCursorTransfer x6c_;
int xac_; // unk type
float xb0_ = 0.f;
float xb4_ = 1.f;
float xb8_ = 1.f;
float xbc_ = 1.f;
float xc0_ = 0.f;
float xc4_ = 0.f;
float xc8_ = 0.f;
int xcc_; // unk type
int xd0_; // unk type
float xd4_ = 0.f;
float xd8_ = 0.f;
float xdc_ = 67.5f;
zeus::CColor xe0_cursorColor;
ECursorState xe4_;
union {
struct {
bool xe8_ : 1;
};
u32 _dummy = 0;
};
CGuiCursor(const CGuiCursorTransfer& t1, const CGuiCursorTransfer& t2, ECursorState cursorState);
void Draw();
void Update(double dt);
zeus::CVector3f ProjectCursorPosition();
};
} // namespace urde

View File

@ -49,6 +49,7 @@ set(GUISYS_SOURCES
CHudRadarInterface.hpp CHudRadarInterface.cpp
CHudBallInterface.hpp CHudBallInterface.cpp
CHudInterface.hpp
CScanDisplay.hpp CScanDisplay.cpp)
CScanDisplay.hpp CScanDisplay.cpp
CGuiCursor.hpp CGuiCursor.cpp)
runtime_add_list(GuiSys GUISYS_SOURCES)

View File

@ -172,6 +172,10 @@ CInGameGuiManager::CInGameGuiManager(CStateManager& stateMgr, CArchitectureQueue
: x0_iggmPreLoad(g_SimplePool->GetObj("PreLoadIGGM_DGRP"))
, x1c_rand(1234)
, x20_faceplateDecor(stateMgr)
, x40_rs5_cursor(CGuiCursor(
CGuiCursorTransfer(0.f, 0.f, 1.f, 1.f),
CGuiCursorTransfer(0.f, 0.f, 1.f, 1.f),
ECursorState::x0))
, x50_deathDot(g_SimplePool->GetObj("TXTR_DeathDot"))
, x5c_pauseScreenDGRPs(LockPauseScreenDependencies()) {
x1e0_helmetVisMode = g_tweakGui->GetHelmetVisMode();
@ -551,6 +555,12 @@ void CInGameGuiManager::Draw(CStateManager& stateMgr) {
x148_model_automapper->SetIsVisible(false);
}
if (stateMgr.GetPlayer().GetUnknownPlayerState1().x184_ == 1 &&
stateMgr.GetPlayer().GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Unmorphed &&
!stateMgr.GetCameraManager()->IsInCinematicCamera()) {
x40_rs5_cursor.Draw();
}
if (!preDrawBlur)
x3c_pauseScreenBlur->Draw(stateMgr);

View File

@ -12,6 +12,7 @@
#include "Runtime/CStateManager.hpp"
#include "Runtime/Camera/CCameraFilter.hpp"
#include "Runtime/Graphics/Shaders/CRandomStaticFilter.hpp"
#include "Runtime/GuiSys/CGuiCursor.hpp"
#include "Runtime/MP1/CFaceplateDecoration.hpp"
#include "Runtime/MP1/CInGameGuiManagerCommon.hpp"
#include "Runtime/MP1/CInventoryScreen.hpp"
@ -61,6 +62,7 @@ private:
std::unique_ptr<CAutoMapper> x38_autoMapper;
std::unique_ptr<CPauseScreenBlur> x3c_pauseScreenBlur;
std::unique_ptr<CSamusFaceReflection> x40_samusReflection;
CGuiCursor x40_rs5_cursor;
std::unique_ptr<CMessageScreen> x44_messageScreen;
std::unique_ptr<CPauseScreen> x48_pauseScreen;
std::unique_ptr<CSaveGameScreen> x4c_saveUI;