From c5c66ac9df021c330260a98165236b9c945f0653 Mon Sep 17 00:00:00 2001 From: Jacob Paulin Date: Fri, 12 Apr 2024 00:27:06 -0400 Subject: [PATCH 1/3] feat(vehicleOptions): Add custom RGB colours for primary and secondary veh colours --- vMenu/CommonFunctions.cs | 50 ++++++++++++++++++++++++++++++++++- vMenu/menus/VehicleOptions.cs | 37 ++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/vMenu/CommonFunctions.cs b/vMenu/CommonFunctions.cs index d6b0a9c4..177ed1a0 100644 --- a/vMenu/CommonFunctions.cs +++ b/vMenu/CommonFunctions.cs @@ -1414,7 +1414,41 @@ private static async void ApplyVehicleModsDelayed(Vehicle vehicle, VehicleInfo v ToggleVehicleMod(vehicle.Handle, 22, vehicleInfo.xenonHeadlights); SetVehicleLivery(vehicle.Handle, vehicleInfo.livery); - SetVehicleColours(vehicle.Handle, vehicleInfo.colors["primary"], vehicleInfo.colors["secondary"]); + if (vehicleInfo.colors.ContainsKey("customPrimaryR") && vehicleInfo.colors.ContainsKey("customPrimaryG") && vehicleInfo.colors.ContainsKey("customPrimaryB")) + { + bool useCustomRgbPrimary = vehicleInfo.colors["customPrimaryR"] > 0 && vehicleInfo.colors["customPrimaryG"] > 0 && vehicleInfo.colors["customPrimaryB"] > 0; + + if (useCustomRgbPrimary) + { + vehicle.Mods.CustomPrimaryColor = System.Drawing.Color.FromArgb(255, vehicleInfo.colors["customPrimaryR"], vehicleInfo.colors["customPrimaryG"], vehicleInfo.colors["customPrimaryB"]); + } + else + { + vehicle.Mods.PrimaryColor = (VehicleColor)vehicleInfo.colors["primary"]; + } + } + else + { + vehicle.Mods.PrimaryColor = (VehicleColor)vehicleInfo.colors["primary"]; + } + + if (vehicleInfo.colors.ContainsKey("customSecondaryR") && vehicleInfo.colors.ContainsKey("customSecondaryG") && vehicleInfo.colors.ContainsKey("customSecondaryB")) + { + bool useCustomRgbSecondary = vehicleInfo.colors["customSecondaryR"] > 0 && vehicleInfo.colors["customSecondaryG"] > 0 && vehicleInfo.colors["customSecondaryB"] > 0; + if (useCustomRgbSecondary) + { + vehicle.Mods.CustomSecondaryColor = System.Drawing.Color.FromArgb(255, vehicleInfo.colors["customSecondaryR"], vehicleInfo.colors["customSecondaryR"], vehicleInfo.colors["customSecondaryB"]); + } + else + { + vehicle.Mods.SecondaryColor = (VehicleColor)vehicleInfo.colors["secondary"]; + } + } + else + { + vehicle.Mods.SecondaryColor = (VehicleColor)vehicleInfo.colors["secondary"]; + } + SetVehicleInteriorColour(vehicle.Handle, vehicleInfo.colors["trim"]); SetVehicleDashboardColour(vehicle.Handle, vehicleInfo.colors["dash"]); @@ -1549,6 +1583,20 @@ public static async void SaveVehicle(string updateExistingSavedVehicleName = nul colors.Add("tyresmokeR", tyresmokeR); colors.Add("tyresmokeG", tyresmokeG); colors.Add("tyresmokeB", tyresmokeB); + int customPrimaryR = -1; + int customPrimaryG = -1; + int customPrimaryB = -1; + GetVehicleCustomPrimaryColour(veh.Handle, ref customPrimaryR, ref customPrimaryG, ref customPrimaryB); + colors.Add("customPrimaryR", customPrimaryR); + colors.Add("customPrimaryG", customPrimaryG); + colors.Add("customPrimaryB", customPrimaryB); + int customSecondaryR = -1; + int customSecondaryG = -1; + int customSecondaryB = -1; + GetVehicleCustomSecondaryColour(veh.Handle, ref customSecondaryR, ref customSecondaryG, ref customSecondaryB); + colors.Add("customSecondaryR", customSecondaryR); + colors.Add("customSecondaryG", customSecondaryG); + colors.Add("customSecondaryB", customSecondaryB); #endregion var extras = new Dictionary(); diff --git a/vMenu/menus/VehicleOptions.cs b/vMenu/menus/VehicleOptions.cs index ba08b98f..98662589 100644 --- a/vMenu/menus/VehicleOptions.cs +++ b/vMenu/menus/VehicleOptions.cs @@ -1147,6 +1147,7 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in } } + ClearVehicleCustomPrimaryColour(veh.Handle); SetVehicleColours(veh.Handle, primaryColor, secondaryColor); } else if (sender == secondaryColorsMenu) @@ -1173,6 +1174,8 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in secondaryColor = VehicleData.WornColors[newIndex].id; break; } + + ClearVehicleCustomSecondaryColour(veh.Handle); SetVehicleColours(veh.Handle, primaryColor, secondaryColor); } else if (sender == VehicleColorsMenu) @@ -1212,8 +1215,38 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in } } + async void HandleItemSelect(Menu menu, MenuItem menuItem, int itemIndex) + { + Vehicle veh = GetVehicle(); + if (veh != null && veh.Exists() && !veh.IsDead && veh.Driver == Game.PlayerPed) + { + string rawRValue = await GetUserInput("Custom RGB - R Value (number from 0-255)", "0", 3); + string rawGValue = await GetUserInput("Custom RGB - G Value (number from 0-255)", "0", 3); + string rawBValue = await GetUserInput("Custom RGB - B Value (number from 0-255)", "0", 3); + int rValue; + int gValue; + int bValue; + + if (!int.TryParse(rawRValue, out rValue) || !int.TryParse(rawGValue, out gValue) || !int.TryParse(rawBValue, out bValue)) + { + Notify.Error("An invalid RGB value was entered, ensure you enter numbers between 0 and 255"); + return; + } + + if (menu == primaryColorsMenu) + { + SetVehicleCustomPrimaryColour(veh.Handle, rValue, gValue, bValue); + } + else if (menu == secondaryColorsMenu) + { + SetVehicleCustomSecondaryColour(veh.Handle, rValue, gValue, bValue); + } + } + } + for (var i = 0; i < 2; i++) { + var customColour = new MenuItem("Custom RGB") { Label = ">>>" }; var pearlescentList = new MenuListItem("Pearlescent", classic, 0); var classicList = new MenuListItem("Classic", classic, 0); var metallicList = new MenuListItem("Metallic", classic, 0); @@ -1224,6 +1257,7 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in if (i == 0) { + primaryColorsMenu.AddMenuItem(customColour); primaryColorsMenu.AddMenuItem(classicList); primaryColorsMenu.AddMenuItem(metallicList); primaryColorsMenu.AddMenuItem(matteList); @@ -1239,9 +1273,11 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in } primaryColorsMenu.OnListIndexChange += HandleListIndexChanges; + primaryColorsMenu.OnItemSelect += HandleItemSelect; } else { + secondaryColorsMenu.AddMenuItem(customColour); secondaryColorsMenu.AddMenuItem(pearlescentList); secondaryColorsMenu.AddMenuItem(classicList); secondaryColorsMenu.AddMenuItem(metallicList); @@ -1251,6 +1287,7 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in secondaryColorsMenu.AddMenuItem(wornList); secondaryColorsMenu.OnListIndexChange += HandleListIndexChanges; + secondaryColorsMenu.OnItemSelect += HandleItemSelect; } } #endregion From 16fa3c63fba55b3cdc62efe307d54b71e8da9cac Mon Sep 17 00:00:00 2001 From: Jacob Paulin Date: Fri, 12 Apr 2024 00:52:03 -0400 Subject: [PATCH 2/3] chore(commonFunctions/applyVehicleModsDelayed): Reduced the complexity level --- vMenu/CommonFunctions.cs | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/vMenu/CommonFunctions.cs b/vMenu/CommonFunctions.cs index 177ed1a0..4ec365e2 100644 --- a/vMenu/CommonFunctions.cs +++ b/vMenu/CommonFunctions.cs @@ -1414,35 +1414,20 @@ private static async void ApplyVehicleModsDelayed(Vehicle vehicle, VehicleInfo v ToggleVehicleMod(vehicle.Handle, 22, vehicleInfo.xenonHeadlights); SetVehicleLivery(vehicle.Handle, vehicleInfo.livery); - if (vehicleInfo.colors.ContainsKey("customPrimaryR") && vehicleInfo.colors.ContainsKey("customPrimaryG") && vehicleInfo.colors.ContainsKey("customPrimaryB")) + bool useCustomRgbPrimary = vehicleInfo.colors.ContainsKey("customPrimaryR") && vehicleInfo.colors.ContainsKey("customPrimaryG") && vehicleInfo.colors.ContainsKey("customPrimaryB"); + if (useCustomRgbPrimary && vehicleInfo.colors["customPrimaryR"] > 0 && vehicleInfo.colors["customPrimaryG"] > 0 && vehicleInfo.colors["customPrimaryB"] > 0) { - bool useCustomRgbPrimary = vehicleInfo.colors["customPrimaryR"] > 0 && vehicleInfo.colors["customPrimaryG"] > 0 && vehicleInfo.colors["customPrimaryB"] > 0; - - if (useCustomRgbPrimary) - { - vehicle.Mods.CustomPrimaryColor = System.Drawing.Color.FromArgb(255, vehicleInfo.colors["customPrimaryR"], vehicleInfo.colors["customPrimaryG"], vehicleInfo.colors["customPrimaryB"]); - } - else - { - vehicle.Mods.PrimaryColor = (VehicleColor)vehicleInfo.colors["primary"]; - } + vehicle.Mods.CustomPrimaryColor = System.Drawing.Color.FromArgb(255, vehicleInfo.colors["customPrimaryR"], vehicleInfo.colors["customPrimaryG"], vehicleInfo.colors["customPrimaryB"]); } else { vehicle.Mods.PrimaryColor = (VehicleColor)vehicleInfo.colors["primary"]; } - if (vehicleInfo.colors.ContainsKey("customSecondaryR") && vehicleInfo.colors.ContainsKey("customSecondaryG") && vehicleInfo.colors.ContainsKey("customSecondaryB")) + bool useCustomRgbSecondary = vehicleInfo.colors.ContainsKey("customSecondaryR") && vehicleInfo.colors.ContainsKey("customSecondaryG") && vehicleInfo.colors.ContainsKey("customSecondaryB"); + if (useCustomRgbSecondary && vehicleInfo.colors["customSecondaryR"] > 0 && vehicleInfo.colors["customSecondaryG"] > 0 && vehicleInfo.colors["customSecondaryB"] > 0) { - bool useCustomRgbSecondary = vehicleInfo.colors["customSecondaryR"] > 0 && vehicleInfo.colors["customSecondaryG"] > 0 && vehicleInfo.colors["customSecondaryB"] > 0; - if (useCustomRgbSecondary) - { - vehicle.Mods.CustomSecondaryColor = System.Drawing.Color.FromArgb(255, vehicleInfo.colors["customSecondaryR"], vehicleInfo.colors["customSecondaryR"], vehicleInfo.colors["customSecondaryB"]); - } - else - { - vehicle.Mods.SecondaryColor = (VehicleColor)vehicleInfo.colors["secondary"]; - } + vehicle.Mods.CustomSecondaryColor = System.Drawing.Color.FromArgb(255, vehicleInfo.colors["customSecondaryR"], vehicleInfo.colors["customSecondaryR"], vehicleInfo.colors["customSecondaryB"]); } else { From ea6a21f7c3c25cace358f57ec0ae94bef94d85ae Mon Sep 17 00:00:00 2001 From: blackfirefly000 <50463948+blackfirefly000@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:24:53 -0700 Subject: [PATCH 3/3] Update VehicleOptions.cs Fixes vehicle color menu not working correctly --- vMenu/menus/VehicleOptions.cs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/vMenu/menus/VehicleOptions.cs b/vMenu/menus/VehicleOptions.cs index 98662589..9eb6cc74 100644 --- a/vMenu/menus/VehicleOptions.cs +++ b/vMenu/menus/VehicleOptions.cs @@ -1107,7 +1107,7 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in if (sender == primaryColorsMenu) { - if (itemIndex == 1) + if (itemIndex == 2) { pearlColor = VehicleData.ClassicColors[newIndex].id; } @@ -1119,26 +1119,27 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in switch (itemIndex) { case 0: - case 1: + case 1: + case 2: primaryColor = VehicleData.ClassicColors[newIndex].id; break; - case 2: + case 3: primaryColor = VehicleData.MatteColors[newIndex].id; break; - case 3: + case 4: primaryColor = VehicleData.MetalColors[newIndex].id; break; - case 4: + case 5: primaryColor = VehicleData.UtilColors[newIndex].id; break; - case 5: + case 6: primaryColor = VehicleData.WornColors[newIndex].id; break; } if (GetSettingsBool(Setting.vmenu_using_chameleon_colours)) { - if (itemIndex == 6) + if (itemIndex == 7) { primaryColor = VehicleData.ChameleonColors[newIndex].id; secondaryColor = VehicleData.ChameleonColors[newIndex].id; @@ -1155,22 +1156,23 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in switch (itemIndex) { case 0: + case 1: pearlColor = VehicleData.ClassicColors[newIndex].id; break; - case 1: case 2: + case 3: secondaryColor = VehicleData.ClassicColors[newIndex].id; break; - case 3: + case 4: secondaryColor = VehicleData.MatteColors[newIndex].id; break; - case 4: + case 5: secondaryColor = VehicleData.MetalColors[newIndex].id; break; - case 5: + case 6: secondaryColor = VehicleData.UtilColors[newIndex].id; break; - case 6: + case 7: secondaryColor = VehicleData.WornColors[newIndex].id; break; }