CheatMenuSA/CheatMenu/Neon.cpp

96 lines
2.1 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-02-25 17:45:41 -05:00
void Neon::RenderEvent(CVehicle *pVeh)
{
NeonData* data = &VehNeon.Get(pVeh);
if (data->neon_installed && !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));
CVector up = pVeh->TransformFromObjectSpace(CVector(0.0f, -Pos.y - data->val, 0.0f)) - center;
CVector right = pVeh->TransformFromObjectSpace(CVector(Pos.x + data->val, 0.0f, 0.0f)) - center;
CShadows::StoreShadowToBeRendered(5, neon_texture, &center, up.x, up.y, right.x, right.y, 180, data->color.r, data->color.g, data->color.b, 2.0f, false, 1.0f, 0, true);
if (CTimer::m_snTimeInMilliseconds - data->timer > 150)
2020-12-02 16:19:16 -05:00
{
2021-02-25 17:45:41 -05:00
data->timer = CTimer::m_snTimeInMilliseconds;
2020-12-02 16:19:16 -05:00
2021-02-25 17:45:41 -05:00
if (data->pulsing)
{
2021-02-25 17:45:41 -05:00
if (data->val < 0.0f)
data->increment = true;
2021-02-25 17:45:41 -05:00
if (data->val > 0.3f)
data->increment = false;
2021-02-25 17:45:41 -05:00
if (data->increment)
data->val += 0.1f;
else
data->val -= 0.1f;
}
2020-12-02 16:19:16 -05:00
}
2021-02-25 17:45:41 -05:00
}
}
Neon::Neon()
{
Events::processScriptsEvent += [this]
{
if (!mask_loaded)
{
neon_texture = Util::LoadTextureFromPngFile(PLUGIN_PATH((char*)"CheatMenu\\vehicles\\neon_mask.png"));
if (!neon_texture)
flog << "Failed to load neon mask" << std::endl;
2021-02-25 17:45:41 -05:00
mask_loaded = true;
}
};
2021-02-25 17:45:41 -05:00
Events::vehicleRenderEvent += RenderEvent;
2020-12-02 16:19:16 -05:00
}
Neon::~Neon()
2021-02-27 15:40:51 -05:00
{
2021-02-25 17:45:41 -05:00
Events::vehicleRenderEvent -= RenderEvent;
2021-03-16 03:12:59 -04:00
if (neon_texture)
{
RwTextureDestroy(neon_texture);
neon_texture = nullptr;
}
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
{
return VehNeon.Get(pVeh).neon_installed;
2020-12-02 16:19:16 -05:00
}
2021-02-24 16:54:45 -05:00
bool Neon::IsPulsingEnabled(CVehicle* pVeh)
{
return VehNeon.Get(pVeh).pulsing;
}
2021-02-24 16:54:45 -05:00
void Neon::SetPulsing(CVehicle* pVeh, bool state)
{
VehNeon.Get(pVeh).pulsing = 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-02-24 16:54:45 -05:00
CRGBA& color = VehNeon.Get(pVeh).color;
color.r = red;
color.g = green;
color.b = blue;
color.a = 255;
2020-12-02 16:19:16 -05:00
VehNeon.Get(pVeh).neon_installed = 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
{
VehNeon.Get(pVeh).neon_installed = false;
2020-12-02 16:19:16 -05:00
}