diff --git a/src/paint.cpp b/src/paint.cpp index ee652da..0fc60bc 100644 --- a/src/paint.cpp +++ b/src/paint.cpp @@ -150,17 +150,30 @@ void Paint::NodeWrapperRecursive(RwFrame* frame, CVehicle* pVeh, std::function& names_vec) +void Paint::GenerateNodeList(CVehicle* pVeh, std::vector& names_vec, std::string& selected) { + static int vehModel = 0; + if (vehModel == pVeh->m_nModelIndex) + { + return; + } + + // reset to default + names_vec.clear(); + names_vec.push_back("Default"); + selected = "Default"; + RwFrame* frame = (RwFrame*)pVeh->m_pRwClump->object.parent; NodeWrapperRecursive(frame, pVeh, [&](RwFrame* frame) { const std::string name = GetFrameNodeName(frame); - if (!(std::find(names_vec.begin(), names_vec.end(), name) != names_vec.end())) + { names_vec.push_back(name); + } }); + vehModel = pVeh->m_nModelIndex; } void Paint::SetNodeColor(CVehicle* pVeh, std::string node_name, CRGBA color, bool filter_mat) diff --git a/src/paint.h b/src/paint.h index df8b9a9..8a1888b 100644 --- a/src/paint.h +++ b/src/paint.h @@ -77,7 +77,7 @@ public: static inline ResourceStore m_TextureData { "textures", eResourceType::TYPE_IMAGE, ImVec2(100, 80) }; static void InjectHooks(); - static void GenerateNodeList(CVehicle* pVeh, std::vector& names_vec); + static void GenerateNodeList(CVehicle* pVeh, std::vector& names_vec, std::string& selected); static void SetNodeColor(CVehicle* pVeh, std::string node_name, CRGBA color, bool filter_mat = false); static void SetNodeTexture(CVehicle* pVeh, std::string node_name, std::string texturename, bool filter_mat = false); static void ResetNodeColor(CVehicle* veh, std::string node_name); diff --git a/src/util.cpp b/src/util.cpp index d2c7575..845ef69 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,6 +1,12 @@ #include "pch.h" #include "util.h" #include "psapi.h" +#include + +float Util::RoundFloat(float val) +{ + return roundf(val * 100) / 100; +} bool Util::IsInVehicle(CPed *pPed) { diff --git a/src/util.h b/src/util.h index 82fd452..cd73807 100644 --- a/src/util.h +++ b/src/util.h @@ -35,4 +35,5 @@ public: static bool IsInVehicle(CPed *pPed = FindPlayerPed()); static void RainbowValues(int& r, int& g, int& b, float speed); static void SetCarForwardSpeed(CVehicle *pVeh, float speed); + static float RoundFloat(float val); }; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 591f5cf..cfc31c0 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1043,7 +1043,7 @@ void Vehicle::ShowPage() if (ImGui::BeginTabItem(TEXT("Vehicle.Color"))) { #ifdef GTASA - Paint::GenerateNodeList(veh, m_Paint::m_vecNames); + Paint::GenerateNodeList(veh, m_Paint::m_vecNames, m_Paint::m_Selected); ImGui::Spacing(); if (ImGui::Button(TEXT("Vehicle.ResetColor"), ImVec2(Ui::GetSize()))) @@ -1115,6 +1115,7 @@ void Vehicle::ShowPage() { if (ImGui::BeginTabItem(TEXT("Vehicle.NeonsTab"))) { + int model = veh->m_nModelIndex; ImGui::Spacing(); if (ImGui::Button(TEXT("Vehicle.RemoveNeon"), ImVec2(Ui::GetSize()))) { @@ -1140,8 +1141,11 @@ void Vehicle::ShowPage() if (ImGui::ColorEdit3(TEXT("Vehicle.ColorPicker"), m_Neon::m_fColorPicker)) { - Neon::Install(veh, m_Neon::m_fColorPicker[0] * 255, m_Neon::m_fColorPicker[1] * 255, - m_Neon::m_fColorPicker[2] * 255); + int r = static_cast(m_Neon::m_fColorPicker[0] * 255); + int g = static_cast(m_Neon::m_fColorPicker[1] * 255); + int b = static_cast(m_Neon::m_fColorPicker[2] * 255); + + Neon::Install(veh, r, g, b); } @@ -1158,10 +1162,14 @@ void Vehicle::ShowPage() for (int color_id = 0; color_id < count; ++color_id) { - if (Ui::ColorButton(color_id, m_CarcolsColorData[color_id], ImVec2(btnSize, btnSize))) + auto& color = m_CarcolsColorData[color_id]; + if (Ui::ColorButton(color_id, color, ImVec2(btnSize, btnSize))) { - std::vector& color = m_CarcolsColorData[color_id]; - Neon::Install(veh, color[0] * 255, color[1] * 255, color[2] * 255); + int r = static_cast(color[0] * 255); + int g = static_cast(color[1] * 255); + int b = static_cast(color[2] * 255); + + Neon::Install(veh, r, g, b); } if ((color_id + 1) % btnsInRow != 0) @@ -1175,7 +1183,7 @@ void Vehicle::ShowPage() } if (ImGui::BeginTabItem(TEXT("Vehicle.TextureTab"))) { - Paint::GenerateNodeList(veh, m_Paint::m_vecNames); + Paint::GenerateNodeList(veh, m_Paint::m_vecNames, m_Paint::m_Selected); ImGui::Spacing(); if (ImGui::Button(TEXT("Vehicle.ResetTexture"), ImVec2(Ui::GetSize()))) @@ -1188,29 +1196,41 @@ void Vehicle::ShowPage() Ui::ListBoxStr(TEXT("Vehicle.Component"), m_Paint::m_vecNames, m_Paint::m_Selected); ImGui::Spacing(); + ImGui::Columns(2, NULL, false); + ImGui::Checkbox(TEXT("Vehicle.MatFilter"), &m_Paint::m_bMatFilter); + ImGui::NextColumn(); int maxpjob, curpjob; Command(hveh, &maxpjob); if (maxpjob > 0) { Command(hveh, &curpjob); - - if (ImGui::InputInt(TEXT("Vehicle.Paintjob"), &curpjob)) + + if (ImGui::ArrowButton("Left", ImGuiDir_Left)) { - if (curpjob > maxpjob) - curpjob = -1; + curpjob -= 1; if (curpjob < -1) - curpjob = maxpjob - 1; - + { + curpjob = maxpjob - 1; + } + Command(hveh, curpjob); + } + ImGui::SameLine(); + ImGui::Text("%s: %d",TEXT("Vehicle.Paintjob"), curpjob+2); + ImGui::SameLine(); + if (ImGui::ArrowButton("Right", ImGuiDir_Right)) + { + curpjob += 1; + if (curpjob > maxpjob) + { + curpjob = -1; + } Command(hveh, curpjob); } ImGui::Spacing(); } - - ImGui::Spacing(); - ImGui::SameLine(); - ImGui::Checkbox(TEXT("Vehicle.MatFilter"), &m_Paint::m_bMatFilter); + ImGui::Columns(1); ImGui::Spacing(); Ui::DrawImages(Paint::m_TextureData, [](std::string& str)