CheatMenuSA/CheatMenu/Neon.cpp

97 lines
2.2 KiB
C++
Raw Normal View History

2020-12-02 16:19:16 -05:00
#include "pch.h"
#include "Neon.h"
#include "Util.h"
2020-12-02 16:19:16 -05:00
2021-06-18 12:49:11 -04:00
void Neon::RenderEvent(CVehicle* pVeh)
2021-02-25 17:45:41 -05:00
{
2021-06-18 12:49:11 -04:00
NeonData* data = &m_VehNeon.Get(pVeh);
if (data->m_bNeonInstalled && !pVeh->IsUpsideDown())
{
2021-02-25 17:45:41 -05:00
CVector Pos = CModelInfo::GetModelInfo(pVeh->m_nModelIndex)->m_pColModel->m_boundBox.m_vecMin;
CVector center = pVeh->TransformFromObjectSpace(CVector(0.0f, 0.0f, 0.0f));
2021-06-18 12:49:11 -04:00
CVector up = pVeh->TransformFromObjectSpace(CVector(0.0f, -Pos.y - data->m_fVal, 0.0f)) - center;
CVector right = pVeh->TransformFromObjectSpace(CVector(Pos.x + data->m_fVal, 0.0f, 0.0f)) - center;
CShadows::StoreShadowToBeRendered(5, m_pNeonTexture, &center, up.x, up.y, right.x, right.y, 180, data->m_Color.r,
data->m_Color.g, data->m_Color.b, 2.0f, false, 1.0f, 0, true);
2021-02-25 17:45:41 -05:00
2021-06-18 12:49:11 -04:00
if (CTimer::m_snTimeInMilliseconds - data->m_nTimer > 150)
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
data->m_nTimer = CTimer::m_snTimeInMilliseconds;
2020-12-02 16:19:16 -05:00
2021-06-18 12:49:11 -04:00
if (data->m_bPulsing)
{
2021-06-18 12:49:11 -04:00
if (data->m_fVal < 0.0f)
data->m_bIncrement = true;
2021-06-18 12:49:11 -04:00
if (data->m_fVal > 0.3f)
data->m_bIncrement = false;
2021-06-18 12:49:11 -04:00
if (data->m_bIncrement)
data->m_fVal += 0.1f;
2021-02-25 17:45:41 -05:00
else
2021-06-18 12:49:11 -04:00
data->m_fVal -= 0.1f;
}
2020-12-02 16:19:16 -05:00
}
2021-02-25 17:45:41 -05:00
}
}
Neon::Neon()
{
Events::processScriptsEvent += [this]
{
2021-06-18 12:49:11 -04:00
if (!m_bMaskLoaded)
{
2021-06-18 12:49:11 -04:00
m_pNeonTexture = Util::LoadTextureFromPngFile(PLUGIN_PATH((char*)"CheatMenu\\vehicles\\neon_mask.png"));
if (!m_pNeonTexture)
flog << "Failed to load neon mask" << std::endl;
2021-02-25 17:45:41 -05:00
2021-06-18 12:49:11 -04:00
m_bMaskLoaded = true;
}
};
2021-06-18 12:49:11 -04:00
2021-02-25 17:45:41 -05:00
Events::vehicleRenderEvent += RenderEvent;
2020-12-02 16:19:16 -05:00
}
Neon::~Neon()
2021-06-18 12:49:11 -04:00
{
2021-02-25 17:45:41 -05:00
Events::vehicleRenderEvent -= RenderEvent;
2021-03-16 03:12:59 -04:00
2021-06-18 12:49:11 -04:00
if (m_pNeonTexture)
2021-03-16 03:12:59 -04:00
{
2021-06-18 12:49:11 -04:00
RwTextureDestroy(m_pNeonTexture);
m_pNeonTexture = nullptr;
2021-03-16 03:12:59 -04:00
}
2020-12-02 16:19:16 -05:00
}
2021-02-24 16:54:45 -05:00
bool Neon::IsNeonInstalled(CVehicle* pVeh)
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
return m_VehNeon.Get(pVeh).m_bNeonInstalled;
2020-12-02 16:19:16 -05:00
}
2021-02-24 16:54:45 -05:00
bool Neon::IsPulsingEnabled(CVehicle* pVeh)
{
2021-06-18 12:49:11 -04:00
return m_VehNeon.Get(pVeh).m_bPulsing;
}
2021-02-24 16:54:45 -05:00
void Neon::SetPulsing(CVehicle* pVeh, bool state)
{
2021-06-18 12:49:11 -04:00
m_VehNeon.Get(pVeh).m_bPulsing = state;
}
2021-02-24 16:54:45 -05:00
void Neon::InstallNeon(CVehicle* pVeh, int red, int green, int blue)
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
CRGBA& color = m_VehNeon.Get(pVeh).m_Color;
color.r = red;
color.g = green;
color.b = blue;
color.a = 255;
2020-12-02 16:19:16 -05:00
2021-06-18 12:49:11 -04:00
m_VehNeon.Get(pVeh).m_bNeonInstalled = true;
2020-12-02 16:19:16 -05:00
}
2021-02-24 16:54:45 -05:00
void Neon::RemoveNeon(CVehicle* pVeh)
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
m_VehNeon.Get(pVeh).m_bNeonInstalled = false;
2020-12-02 16:19:16 -05:00
}