diff --git a/vMenu/CommonFunctions.cs b/vMenu/CommonFunctions.cs index e762c97e..3dc95ebd 100644 --- a/vMenu/CommonFunctions.cs +++ b/vMenu/CommonFunctions.cs @@ -1445,6 +1445,14 @@ private static async void ApplyVehicleModsDelayed(Vehicle vehicle, VehicleInfo v { vehicle.Mods.PrimaryColor = (VehicleColor)vehicleInfo.colors["primary"]; } + if (vehicleInfo.colors.ContainsKey("PrimaryPaintFinish")) + { + var pearlColorReset = 0; + var wheelColorReset = 0; + GetVehicleExtraColours(vehicle.Handle, ref pearlColorReset, ref wheelColorReset); + SetVehicleModColor_1(vehicle.Handle, vehicleInfo.colors["PrimaryPaintFinish"], 0, 0); + SetVehicleExtraColours(vehicle.Handle, pearlColorReset, wheelColorReset); + } 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) @@ -1455,7 +1463,14 @@ private static async void ApplyVehicleModsDelayed(Vehicle vehicle, VehicleInfo v { vehicle.Mods.SecondaryColor = (VehicleColor)vehicleInfo.colors["secondary"]; } - + if (vehicleInfo.colors.ContainsKey("SecondaryPaintFinish")) + { + var pearlColorReset = 0; + var wheelColorReset = 0; + GetVehicleExtraColours(vehicle.Handle, ref pearlColorReset, ref wheelColorReset); + SetVehicleModColor_2(vehicle.Handle, vehicleInfo.colors["SecondaryPaintFinish"], 0); + SetVehicleExtraColours(vehicle.Handle, pearlColorReset, wheelColorReset); + } SetVehicleInteriorColour(vehicle.Handle, vehicleInfo.colors["trim"]); SetVehicleDashboardColour(vehicle.Handle, vehicleInfo.colors["dash"]); @@ -1472,6 +1487,11 @@ private static async void ApplyVehicleModsDelayed(Vehicle vehicle, VehicleInfo v VehicleOptions.SetHeadlightsColorForVehicle(vehicle, vehicleInfo.headlightColor); + bool useCustomRgbHeadlight = vehicleInfo.colors.ContainsKey("customheadlightR") && vehicleInfo.colors.ContainsKey("customheadlightG") && vehicleInfo.colors.ContainsKey("customheadlightB"); + if (useCustomRgbHeadlight) + { + SetVehicleXenonLightsCustomColor(vehicle.Handle, vehicleInfo.colors["customheadlightR"], vehicleInfo.colors["customheadlightG"], vehicleInfo.colors["customheadlightB"]); + } vehicle.Mods.NeonLightsColor = System.Drawing.Color.FromArgb(red: vehicleInfo.colors["neonR"], green: vehicleInfo.colors["neonG"], blue: vehicleInfo.colors["neonB"]); vehicle.Mods.SetNeonLightsOn(VehicleNeonLight.Left, vehicleInfo.neonLeft); vehicle.Mods.SetNeonLightsOn(VehicleNeonLight.Right, vehicleInfo.neonRight); @@ -1601,6 +1621,11 @@ public static async void SaveVehicle(string updateExistingSavedVehicleName = nul GetVehicleCustomPrimaryColour(veh.Handle, ref customPrimaryR, ref customPrimaryG, ref customPrimaryB); } + if (veh.State.Get("vMenu:PrimaryPaintFinish") is int primaryPaintFinish) + { + colors.Add("PrimaryPaintFinish", primaryPaintFinish); + } + colors.Add("customPrimaryR", customPrimaryR); colors.Add("customPrimaryG", customPrimaryG); colors.Add("customPrimaryB", customPrimaryB); @@ -1616,9 +1641,24 @@ public static async void SaveVehicle(string updateExistingSavedVehicleName = nul GetVehicleCustomSecondaryColour(veh.Handle, ref customSecondaryR, ref customSecondaryG, ref customSecondaryB); } + if (veh.State.Get("vMenu:SecondaryPaintFinish") is int secondaryPaintFinish) + { + colors.Add("SecondaryPaintFinish", secondaryPaintFinish); + } + colors.Add("customSecondaryR", customSecondaryR); colors.Add("customSecondaryG", customSecondaryG); colors.Add("customSecondaryB", customSecondaryB); + + int customheadlightR = -1; + int customheadlightG = -1; + int customheadlightB = -1; + if (GetVehicleXenonLightsCustomColor(veh.Handle, ref customheadlightR, ref customheadlightG, ref customheadlightB)) + { + colors.Add("customheadlightR", customheadlightR); + colors.Add("customheadlightG", customheadlightG); + colors.Add("customheadlightB", customheadlightB); + } #endregion var extras = new Dictionary(); diff --git a/vMenu/data/VehicleData.cs b/vMenu/data/VehicleData.cs index f9f7cb3a..65fcc62f 100644 --- a/vMenu/data/VehicleData.cs +++ b/vMenu/data/VehicleData.cs @@ -322,7 +322,6 @@ public VehicleColor(int id, string label) new VehicleColor(133, "OLIVE_GREEN"), }; - // Chameleon Colour List // public static readonly List ChameleonColors = new() { new VehicleColor(223, "G9_PAINT01"), @@ -343,6 +342,23 @@ public VehicleColor(int id, string label) new VehicleColor(238, "G9_PAINT16"), }; + public static readonly List NeonLightColors = new() + { + { new int[3] { 255, 255, 255 } }, // White + { new int[3] { 2, 21, 255 } }, // Blue + { new int[3] { 3, 83, 255 } }, // Electric blue + { new int[3] { 0, 255, 140 } }, // Mint Green + { new int[3] { 94, 255, 1 } }, // Lime Green + { new int[3] { 255, 255, 0 } }, // Yellow + { new int[3] { 255, 150, 5 } }, // Golden Shower + { new int[3] { 255, 62, 0 } }, // Orange + { new int[3] { 255, 0, 0 } }, // Red + { new int[3] { 255, 50, 100 } }, // Pony Pink + { new int[3] { 255, 5, 190 } }, // Hot Pink + { new int[3] { 35, 1, 255 } }, // Purple + { new int[3] { 15, 3, 255 } }, // Blacklight + }; + public static class Vehicles { #region Vehicle List Per Class diff --git a/vMenu/menus/MpPedCustomization.cs b/vMenu/menus/MpPedCustomization.cs index d132152b..610804f6 100644 --- a/vMenu/menus/MpPedCustomization.cs +++ b/vMenu/menus/MpPedCustomization.cs @@ -1099,35 +1099,6 @@ private void CreateMenu() inheritanceMenu.AddMenuItem(inheritanceShapeMix); inheritanceMenu.AddMenuItem(inheritanceSkinMix); - // formula from maintransition.#sc - float GetMinimum() - { - return currentCharacter.IsMale ? 0.05f : 0.3f; - } - - float GetMaximum() - { - return currentCharacter.IsMale ? 0.7f : 0.95f; - } - - float ClampMix(int value) - { - var sliderFraction = mixValues[value]; - var min = GetMinimum(); - var max = GetMaximum(); - - return min + (sliderFraction * (max - min)); - } - - int UnclampMix(float value) - { - var min = GetMinimum(); - var max = GetMaximum(); - - var origFraction = (value - min) / (max - min); - return Math.Max(Math.Min((int)(origFraction * 10), 10), 0); - } - inheritanceMenu.OnListIndexChange += (_menu, listItem, oldSelectionIndex, newSelectionIndex, itemIndex) => { _parentOne = inheritanceParentOne.ListIndex; diff --git a/vMenu/menus/VehicleOptions.cs b/vMenu/menus/VehicleOptions.cs index 165613bf..17da329b 100644 --- a/vMenu/menus/VehicleOptions.cs +++ b/vMenu/menus/VehicleOptions.cs @@ -1231,6 +1231,7 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in } ClearVehicleCustomPrimaryColour(veh.Handle); + veh.State.Set("vMenu:PrimaryPaintFinish", null, true); SetVehicleColours(veh.Handle, primaryColor, secondaryColor); } else if (sender == secondaryColorsMenu) @@ -1260,6 +1261,7 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in } ClearVehicleCustomSecondaryColour(veh.Handle); + veh.State.Set("vMenu:SecondaryPaintFinish", null, true); SetVehicleColours(veh.Handle, primaryColor, secondaryColor); } else if (sender == VehicleColorsMenu) @@ -1299,35 +1301,6 @@ 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 = "→→→" }; @@ -1341,6 +1314,7 @@ async void HandleItemSelect(Menu menu, MenuItem menuItem, int itemIndex) if (i == 0) { + var customColourMenuPrimary = new Menu("Custom Colour", "Custom Vehicle Colour"); primaryColorsMenu.AddMenuItem(customColour); primaryColorsMenu.AddMenuItem(classicList); primaryColorsMenu.AddMenuItem(metallicList); @@ -1348,6 +1322,9 @@ async void HandleItemSelect(Menu menu, MenuItem menuItem, int itemIndex) primaryColorsMenu.AddMenuItem(metalList); primaryColorsMenu.AddMenuItem(utilList); primaryColorsMenu.AddMenuItem(wornList); + MenuController.AddSubmenu(primaryColorsMenu, customColourMenuPrimary); + MenuController.BindMenuItem(primaryColorsMenu, customColourMenuPrimary, customColour); + if (GetSettingsBool(Setting.vmenu_using_chameleon_colours)) { @@ -1355,12 +1332,13 @@ async void HandleItemSelect(Menu menu, MenuItem menuItem, int itemIndex) primaryColorsMenu.AddMenuItem(chameleonList); } - + + CreateCustomColourMenu(customColourMenuPrimary, RGBType.primaryPaint); primaryColorsMenu.OnListIndexChange += HandleListIndexChanges; - primaryColorsMenu.OnItemSelect += HandleItemSelect; } else { + var customColourMenuSecondary = new Menu("Custom Colour", "Custom Vehicle Colour"); secondaryColorsMenu.AddMenuItem(customColour); secondaryColorsMenu.AddMenuItem(pearlescentList); secondaryColorsMenu.AddMenuItem(classicList); @@ -1369,9 +1347,11 @@ async void HandleItemSelect(Menu menu, MenuItem menuItem, int itemIndex) secondaryColorsMenu.AddMenuItem(metalList); secondaryColorsMenu.AddMenuItem(utilList); secondaryColorsMenu.AddMenuItem(wornList); + MenuController.AddSubmenu(secondaryColorsMenu, customColourMenuSecondary); + MenuController.BindMenuItem(secondaryColorsMenu, customColourMenuSecondary, customColour); + CreateCustomColourMenu(customColourMenuSecondary, RGBType.secondaryPaint); secondaryColorsMenu.OnListIndexChange += HandleListIndexChanges; - secondaryColorsMenu.OnItemSelect += HandleItemSelect; } } @@ -1877,6 +1857,7 @@ void ChangeVehiclePresetColor(int index) VehicleUnderglowMenu.AddMenuItem(underglowColor); + CreateCustomColourMenu(VehicleUnderglowMenu, RGBType.underglow); menu.OnItemSelect += (sender, item, index) => { #region reset checkboxes state when opening the menu. @@ -2170,22 +2151,58 @@ public void UpdateMods(int selectedIndex = 0) VehicleModMenu.AddMenuItem(vehicleWheelType); } - // Create the checkboxes for some options. - var toggleCustomWheels = new MenuCheckboxItem("Toggle Custom Wheels", "Press this to add or remove ~y~custom~s~ wheels.", GetVehicleModVariation(veh.Handle, 23)); + var headlightsButton = new MenuItem("Headlights"); + var headlightsMenu = new Menu("Headlights"); var xenonHeadlights = new MenuCheckboxItem("Xenon Headlights", "Enable or disable ~b~xenon ~s~headlights.", IsToggleModOn(veh.Handle, 22)); - var turbo = new MenuCheckboxItem("Turbo", "Enable or disable the ~y~turbo~s~ for this vehicle.", IsToggleModOn(veh.Handle, 18)); - var bulletProofTires = new MenuCheckboxItem("Bullet Proof Tires", "Enable or disable ~y~bullet proof tires~s~ for this vehicle.", !GetVehicleTyresCanBurst(veh.Handle)); - - // Add the checkboxes to the menu. - VehicleModMenu.AddMenuItem(toggleCustomWheels); - VehicleModMenu.AddMenuItem(xenonHeadlights); + headlightsMenu.AddMenuItem(xenonHeadlights); var currentHeadlightColor = GetHeadlightsColorForVehicle(veh); if (currentHeadlightColor is < 0 or > 12) { currentHeadlightColor = 13; } var headlightColor = new MenuListItem("Headlight Color", new List() { "White", "Blue", "Electric Blue", "Mint Green", "Lime Green", "Yellow", "Golden Shower", "Orange", "Red", "Pony Pink", "Hot Pink", "Purple", "Blacklight", "Default Xenon" }, currentHeadlightColor, "New in the Arena Wars GTA V update: Colored headlights. Note you must enable Xenon Headlights first."); - VehicleModMenu.AddMenuItem(headlightColor); + headlightsMenu.AddMenuItem(headlightColor); + headlightsMenu.OnCheckboxChange += (sender2, item2, index2, _checked) => + { + veh = GetVehicle(); + + // Xenon Headlights + if (item2 == xenonHeadlights) + { + ToggleVehicleMod(veh.Handle, 22, _checked); + } + }; + headlightsMenu.OnListIndexChange += (sender2, item2, oldIndex, newIndex, itemIndex) => + { + veh = GetVehicle(); + if (item2 == headlightColor) + { + if (newIndex == 13) // default + { + SetHeadlightsColorForVehicle(veh, 255); + } + else if (newIndex is > (-1) and < 13) + { + ClearVehicleXenonLightsCustomColor(veh.Handle); + SetHeadlightsColorForVehicle(veh, newIndex); + } + } + }; + MenuController.AddSubmenu(VehicleModMenu, headlightsMenu); + MenuController.BindMenuItem(VehicleModMenu, headlightsMenu, headlightsButton); + VehicleModMenu.AddMenuItem(headlightsButton); + CreateCustomColourMenu(headlightsMenu, RGBType.headlight); + + + // Create the checkboxes for some options. + var toggleCustomWheels = new MenuCheckboxItem("Toggle Custom Wheels", "Press this to add or remove ~y~custom~s~ wheels.", GetVehicleModVariation(veh.Handle, 23)); + var turbo = new MenuCheckboxItem("Turbo", "Enable or disable the ~y~turbo~s~ for this vehicle.", IsToggleModOn(veh.Handle, 18)); + var bulletProofTires = new MenuCheckboxItem("Bullet Proof Tires", "Enable or disable ~y~bullet proof tires~s~ for this vehicle.", !GetVehicleTyresCanBurst(veh.Handle)); + + + + // Add the checkboxes to the menu. + VehicleModMenu.AddMenuItem(toggleCustomWheels); VehicleModMenu.AddMenuItem(turbo); VehicleModMenu.AddMenuItem(bulletProofTires); @@ -2196,6 +2213,8 @@ public void UpdateMods(int selectedIndex = 0) VehicleModMenu.AddMenuItem(lowGripTires); } + var tireSmokeButton = new MenuItem("Tire Smoke"); + var tireSmokeMenu = new Menu("Tire Smoke"); // Create a list of tire smoke options. var tireSmokes = new List() { "Red", "Orange", "Yellow", "Gold", "Light Green", "Dark Green", "Light Blue", "Dark Blue", "Purple", "Pink", "Black" }; var tireSmokeColors = new Dictionary() @@ -2222,11 +2241,67 @@ public void UpdateMods(int selectedIndex = 0) } var tireSmoke = new MenuListItem("Tire Smoke Color", tireSmokes, index, $"Choose a ~y~tire smoke color~s~ for your vehicle."); - VehicleModMenu.AddMenuItem(tireSmoke); + tireSmokeMenu.AddMenuItem(tireSmoke); // Create the checkbox to enable/disable the tiresmoke. var tireSmokeEnabled = new MenuCheckboxItem("Tire Smoke", "Enable or disable ~y~tire smoke~s~ for your vehicle. ~h~~r~Important:~s~ When disabling tire smoke, you'll need to drive around before it takes affect.", IsToggleModOn(veh.Handle, 20)); - VehicleModMenu.AddMenuItem(tireSmokeEnabled); + tireSmokeMenu.AddMenuItem(tireSmokeEnabled); + + + tireSmokeMenu.OnCheckboxChange += (sender2, item2, index2, _checked) => + { + veh = GetVehicle(); + + // Toggle Tire Smoke + if (item2 == tireSmokeEnabled) + { + // If it should be enabled: + if (_checked) + { + // Enable it. + ToggleVehicleMod(veh.Handle, 20, true); + // Get the selected color values. + var r = tireSmokeColors[tireSmokes[tireSmoke.ListIndex]][0]; + var g = tireSmokeColors[tireSmokes[tireSmoke.ListIndex]][1]; + var b = tireSmokeColors[tireSmokes[tireSmoke.ListIndex]][2]; + // Set the color. + SetVehicleTyreSmokeColor(veh.Handle, r, g, b); + } + // If it should be disabled: + else + { + // Set the smoke to white. + SetVehicleTyreSmokeColor(veh.Handle, 255, 255, 255); + // Disable it. + ToggleVehicleMod(veh.Handle, 20, false); + // Remove the mod. + RemoveVehicleMod(veh.Handle, 20); + } + } + }; + tireSmokeMenu.OnListIndexChange += (sender2, item2, oldIndex, newIndex, itemIndex) => + { + // Get the vehicle and set the mod kit. + veh = GetVehicle(); + SetVehicleModKit(veh.Handle, 0); + + // Tire smoke + if (item2 == tireSmoke) + { + // Get the selected color values. + var r = tireSmokeColors[tireSmokes[newIndex]][0]; + var g = tireSmokeColors[tireSmokes[newIndex]][1]; + var b = tireSmokeColors[tireSmokes[newIndex]][2]; + + // Set the color. + SetVehicleTyreSmokeColor(veh.Handle, r, g, b); + } + }; + + MenuController.AddSubmenu(VehicleModMenu, tireSmokeMenu); + MenuController.BindMenuItem(VehicleModMenu, tireSmokeMenu, tireSmokeButton); + VehicleModMenu.AddMenuItem(tireSmokeButton); + CreateCustomColourMenu(tireSmokeMenu, RGBType.tiresmoke); // Create list for window tint var windowTints = new List() { "Stock [1/7]", "None [2/7]", "Limo [3/7]", "Light Smoke [4/7]", "Dark Smoke [5/7]", "Pure Black [6/7]", "Green [7/7]" }; @@ -2275,13 +2350,8 @@ public void UpdateMods(int selectedIndex = 0) { veh = GetVehicle(); - // Xenon Headlights - if (item2 == xenonHeadlights) - { - ToggleVehicleMod(veh.Handle, 22, _checked); - } // Turbo - else if (item2 == turbo) + if (item2 == turbo) { ToggleVehicleMod(veh.Handle, 18, _checked); } @@ -2306,32 +2376,6 @@ public void UpdateMods(int selectedIndex = 0) SetVehicleMod(veh.Handle, 24, GetVehicleMod(veh.Handle, 24), GetVehicleModVariation(veh.Handle, 23)); } } - // Toggle Tire Smoke - else if (item2 == tireSmokeEnabled) - { - // If it should be enabled: - if (_checked) - { - // Enable it. - ToggleVehicleMod(veh.Handle, 20, true); - // Get the selected color values. - var r = tireSmokeColors[tireSmokes[tireSmoke.ListIndex]][0]; - var g = tireSmokeColors[tireSmokes[tireSmoke.ListIndex]][1]; - var b = tireSmokeColors[tireSmokes[tireSmoke.ListIndex]][2]; - // Set the color. - SetVehicleTyreSmokeColor(veh.Handle, r, g, b); - } - // If it should be disabled: - else - { - // Set the smoke to white. - SetVehicleTyreSmokeColor(veh.Handle, 255, 255, 255); - // Disable it. - ToggleVehicleMod(veh.Handle, 20, false); - // Remove the mod. - RemoveVehicleMod(veh.Handle, 20); - } - } }; #endregion @@ -2354,7 +2398,7 @@ public void UpdateMods(int selectedIndex = 0) } #endregion // If it was not one of the lists above, then it was one of the manual lists/options selected, - // either: vehicle Wheel Type, tire smoke color, or window tint: + // either: vehicle Wheel Type, or window tint: #region Handle the items available on all vehicles. // Wheel types else if (item2 == vehicleWheelType) @@ -2400,17 +2444,6 @@ public void UpdateMods(int selectedIndex = 0) // Refresh the menu with the item index so that the view doesn't change UpdateMods(selectedIndex: itemIndex); } - // Tire smoke - else if (item2 == tireSmoke) - { - // Get the selected color values. - var r = tireSmokeColors[tireSmokes[newIndex]][0]; - var g = tireSmokeColors[tireSmokes[newIndex]][1]; - var b = tireSmokeColors[tireSmokes[newIndex]][2]; - - // Set the color. - SetVehicleTyreSmokeColor(veh.Handle, r, g, b); - } // Window Tint else if (item2 == windowTint) { @@ -2448,17 +2481,6 @@ public void UpdateMods(int selectedIndex = 0) break; } } - else if (item2 == headlightColor) - { - if (newIndex == 13) // default - { - SetHeadlightsColorForVehicle(veh, 255); - } - else if (newIndex is > (-1) and < 13) - { - SetHeadlightsColorForVehicle(veh, newIndex); - } - } #endregion }; @@ -2514,24 +2536,6 @@ internal static int GetHeadlightsColorForVehicle(Vehicle vehicle) #endregion #region GetColorFromIndex function (underglow) - - private readonly List _VehicleNeonLightColors = new() - { - { new int[3] { 255, 255, 255 } }, // White - { new int[3] { 2, 21, 255 } }, // Blue - { new int[3] { 3, 83, 255 } }, // Electric blue - { new int[3] { 0, 255, 140 } }, // Mint Green - { new int[3] { 94, 255, 1 } }, // Lime Green - { new int[3] { 255, 255, 0 } }, // Yellow - { new int[3] { 255, 150, 5 } }, // Golden Shower - { new int[3] { 255, 62, 0 } }, // Orange - { new int[3] { 255, 0, 0 } }, // Red - { new int[3] { 255, 50, 100 } }, // Pony Pink - { new int[3] { 255, 5, 190 } }, // Hot Pink - { new int[3] { 35, 1, 255 } }, // Purple - { new int[3] { 15, 3, 255 } }, // Blacklight - }; - /// /// Converts a list index to a struct. /// @@ -2541,10 +2545,328 @@ private System.Drawing.Color GetColorFromIndex(int index) { if (index is >= 0 and < 13) { - return System.Drawing.Color.FromArgb(_VehicleNeonLightColors[index][0], _VehicleNeonLightColors[index][1], _VehicleNeonLightColors[index][2]); + return System.Drawing.Color.FromArgb(VehicleData.NeonLightColors[index][0], VehicleData.NeonLightColors[index][1], VehicleData.NeonLightColors[index][2]); } return System.Drawing.Color.FromArgb(255, 255, 255); } + public enum Colour_Types + { + Metallic = 0, + Classic, + Pearlescent, + Matte, + Metals, + Chrome, + Chameleon + } + private static bool IsHex(IEnumerable chars) + { + bool isHex; + foreach (var c in chars) + { + isHex = ((c >= '0' && c <= '9') || + (c >= 'a' && c <= 'f') || + (c >= 'A' && c <= 'F')); + + if (!isHex) + return false; + } + return true; + } + public enum RGBType + { + primaryPaint, + secondaryPaint, + underglow, + headlight, + tiresmoke, + + } + + public static void CreateCustomColourMenu(Menu menu, RGBType type = RGBType.primaryPaint) + { + + var hexColour = new MenuItem("Hex Colour Code"); + var typeList = new MenuListItem("Paint Finish", Enum.GetNames(typeof(Colour_Types)).ToList(), 0); + + int r = 0, g = 0, b = 0; + + var redColour = new MenuSliderItem("Red Colour", 0, 255, 128, true) + { + BarColor = System.Drawing.Color.FromArgb(155, 0, 0, 0), + BackgroundColor = System.Drawing.Color.FromArgb(200, 79, 79, 79), + }; + var greenColour = new MenuSliderItem("Green Colour", 0, 255, 128, true) + { + BarColor = System.Drawing.Color.FromArgb(155, 0, 0, 0), + BackgroundColor = System.Drawing.Color.FromArgb(200, 79, 79, 79), + }; + var blueColour = new MenuSliderItem("Blue Colour", 0, 255, 128, true) + { + BarColor = System.Drawing.Color.FromArgb(155, 0, 0, 0), + BackgroundColor = System.Drawing.Color.FromArgb(200, 79, 79, 79), + }; + + menu.AddMenuItem(hexColour); + menu.AddMenuItem(redColour); + menu.AddMenuItem(greenColour); + menu.AddMenuItem(blueColour); + if (type == RGBType.primaryPaint || type == RGBType.secondaryPaint) + menu.AddMenuItem(typeList); + + menu.OnMenuOpen += (menu) => + { + Vehicle vehicle = GetVehicle(); + + if (type == RGBType.primaryPaint) + GetVehicleCustomPrimaryColour(vehicle.Handle, ref r, ref g, ref b); + else if (type == RGBType.secondaryPaint) + GetVehicleCustomSecondaryColour(vehicle.Handle, ref r, ref g, ref b); + else if (type == RGBType.underglow) + { + r = vehicle.Mods.NeonLightsColor.R; + g = vehicle.Mods.NeonLightsColor.G; + b = vehicle.Mods.NeonLightsColor.B; + } + else if (type == RGBType.headlight) + { + if (!GetVehicleXenonLightsCustomColor(vehicle.Handle, ref r, ref g, ref b)) + { + if (IsToggleModOn(vehicle.Handle, 22)) + { + r = VehicleData.NeonLightColors[GetHeadlightsColorForVehicle(vehicle)][0]; + g = VehicleData.NeonLightColors[GetHeadlightsColorForVehicle(vehicle)][1]; + b = VehicleData.NeonLightColors[GetHeadlightsColorForVehicle(vehicle)][2]; + } + } + + } + else if (type == RGBType.tiresmoke) + GetVehicleTyreSmokeColor(vehicle.Handle, ref r, ref g, ref b); + + + redColour.Text = $"Red Colour ({r})"; + redColour.Position = r; + + greenColour.Text = $"Green Colour ({g})"; + greenColour.Position = g; + + blueColour.Text = $"Blue Colour ({b})"; + blueColour.Position = b; + + redColour.BarColor = System.Drawing.Color.FromArgb(255, redColour.Position, greenColour.Position, blueColour.Position); + greenColour.BarColor = System.Drawing.Color.FromArgb(255, redColour.Position, greenColour.Position, blueColour.Position); + blueColour.BarColor = System.Drawing.Color.FromArgb(255, redColour.Position, greenColour.Position, blueColour.Position); + }; + + menu.OnItemSelect += async (sender, item, index) => + { + Vehicle vehicle = GetVehicle(); + if (item == hexColour) + { + string hexValue = redColour.Position.ToString("X2") + greenColour.Position.ToString("X2") + blueColour.Position.ToString("X2"); + var result = await GetUserInput(windowTitle: "Enter Colour Hex", defaultText: (hexValue).Replace("#", ""), maxInputLength: 6); + if (!string.IsNullOrEmpty(result)) + { + if (IsHex(result)) + { + int RGBint = Convert.ToInt32(result, 16); + byte red = (byte)((RGBint >> 16) & 255); + byte green = (byte)((RGBint >> 8) & 255); + byte blue = (byte)(RGBint & 255); + + if (type == RGBType.primaryPaint) + SetVehicleCustomPrimaryColour(vehicle.Handle, red, green, blue); + else if (type == RGBType.secondaryPaint) + SetVehicleCustomSecondaryColour(vehicle.Handle, red, green, blue); + else if (type == RGBType.underglow) + vehicle.Mods.NeonLightsColor = System.Drawing.Color.FromArgb(255, red, green, blue); + else if (type == RGBType.headlight) + SetVehicleXenonLightsCustomColor(vehicle.Handle, red, green, blue); + else if (type == RGBType.tiresmoke) + SetVehicleTyreSmokeColor(vehicle.Handle, red, green, blue); + + redColour.BarColor = System.Drawing.Color.FromArgb(255, red, green, blue); + greenColour.BarColor = System.Drawing.Color.FromArgb(255, red, green, blue); + blueColour.BarColor = System.Drawing.Color.FromArgb(255, red, green, blue); + + redColour.Text = $"Red Colour ({red})"; + redColour.Position = red; + + greenColour.Text = $"Green Colour ({green})"; + greenColour.Position = green; + + blueColour.Text = $"Blue Colour ({blue})"; + blueColour.Position = blue; + } + } + } + }; + menu.OnSliderPositionChange += (m, sliderItem, oldPosition, newPosition, itemIndex) => + { + Vehicle vehicle = GetVehicle(); + + if (type == RGBType.primaryPaint) + GetVehicleCustomPrimaryColour(vehicle.Handle, ref r, ref g, ref b); + else if (type == RGBType.secondaryPaint) + GetVehicleCustomSecondaryColour(vehicle.Handle, ref r, ref g, ref b); + else if (type == RGBType.underglow) + { + r = vehicle.Mods.NeonLightsColor.R; + g = vehicle.Mods.NeonLightsColor.G; + b = vehicle.Mods.NeonLightsColor.B; + } + else if (type == RGBType.headlight) + { + if (!GetVehicleXenonLightsCustomColor(vehicle.Handle, ref r, ref g, ref b)) + { + if (IsToggleModOn(vehicle.Handle, 22)) + { + r = VehicleData.NeonLightColors[GetHeadlightsColorForVehicle(vehicle)][0]; + g = VehicleData.NeonLightColors[GetHeadlightsColorForVehicle(vehicle)][1]; + b = VehicleData.NeonLightColors[GetHeadlightsColorForVehicle(vehicle)][2]; + } + } + + } + else if (type == RGBType.tiresmoke) + GetVehicleTyreSmokeColor(vehicle.Handle, ref r, ref g, ref b); + + + if (sliderItem == redColour) + { + if (type == RGBType.primaryPaint) + SetVehicleCustomPrimaryColour(vehicle.Handle, newPosition, g, b); + else if (type == RGBType.secondaryPaint) + SetVehicleCustomSecondaryColour(vehicle.Handle, newPosition, g, b); + else if (type == RGBType.underglow) + vehicle.Mods.NeonLightsColor = System.Drawing.Color.FromArgb(255, newPosition, g, b); + else if (type == RGBType.headlight) + SetVehicleXenonLightsCustomColor(vehicle.Handle, newPosition, g, b); + else if (type == RGBType.tiresmoke) + vehicle.Mods.TireSmokeColor = System.Drawing.Color.FromArgb(255, newPosition, g, b); + + redColour.Text = $"Red Colour ({newPosition})"; + } + if (sliderItem == greenColour) + { + if (type == RGBType.primaryPaint) + SetVehicleCustomPrimaryColour(vehicle.Handle, r, newPosition, b); + else if (type == RGBType.secondaryPaint) + SetVehicleCustomSecondaryColour(vehicle.Handle, r, newPosition, b); + else if (type == RGBType.underglow) + vehicle.Mods.NeonLightsColor = System.Drawing.Color.FromArgb(255, r, newPosition, b); + else if (type == RGBType.headlight) + SetVehicleXenonLightsCustomColor(vehicle.Handle, r, newPosition, b); + else if (type == RGBType.tiresmoke) + vehicle.Mods.TireSmokeColor = System.Drawing.Color.FromArgb(255, r, newPosition, b); + + greenColour.Text = $"Green Colour ({newPosition})"; + } + if (sliderItem == blueColour) + { + if (type == RGBType.primaryPaint) + SetVehicleCustomPrimaryColour(vehicle.Handle, r, g, newPosition); + else if (type == RGBType.secondaryPaint) + SetVehicleCustomSecondaryColour(vehicle.Handle, r, g, newPosition); + else if (type == RGBType.underglow) + vehicle.Mods.NeonLightsColor = System.Drawing.Color.FromArgb(255, r, g, newPosition); + else if (type == RGBType.headlight) + SetVehicleXenonLightsCustomColor(vehicle.Handle, r, g, newPosition); + else if (type == RGBType.tiresmoke) + vehicle.Mods.TireSmokeColor = System.Drawing.Color.FromArgb(255, r, g, newPosition); + + blueColour.Text = $"Blue Colour ({newPosition})"; + } + redColour.BarColor = System.Drawing.Color.FromArgb(255, redColour.Position, greenColour.Position, blueColour.Position); + greenColour.BarColor = System.Drawing.Color.FromArgb(255, redColour.Position, greenColour.Position, blueColour.Position); + blueColour.BarColor = System.Drawing.Color.FromArgb(255, redColour.Position, greenColour.Position, blueColour.Position); + }; + + menu.OnListIndexChange += (sender, item, oldIndex, newIndex, itemIndex) => + { + Vehicle vehicle = GetVehicle(); + + if (type == RGBType.primaryPaint) + { + var pearlColorReset = 0; + var wheelColorReset = 0; + GetVehicleExtraColours(vehicle.Handle, ref pearlColorReset, ref wheelColorReset); + SetVehicleModColor_1(vehicle.Handle, newIndex, 0, 0); + vehicle.State.Set("vMenu:PrimaryPaintFinish", newIndex, true); + SetVehicleExtraColours(vehicle.Handle, pearlColorReset, wheelColorReset); + } + else if (type == RGBType.secondaryPaint) + { + var pearlColorReset = 0; + var wheelColorReset = 0; + GetVehicleExtraColours(vehicle.Handle, ref pearlColorReset, ref wheelColorReset); + SetVehicleModColor_2(vehicle.Handle, newIndex, 0); + vehicle.State.Set("vMenu:SecondaryPaintFinish", newIndex, true); + SetVehicleExtraColours(vehicle.Handle, pearlColorReset, wheelColorReset); + } + else if (type == RGBType.underglow) + { + int red = vehicle.Mods.TireSmokeColor.R; + int green = vehicle.Mods.NeonLightsColor.G; + int blue = vehicle.Mods.NeonLightsColor.B; + + redColour.BarColor = System.Drawing.Color.FromArgb(255, red, green, blue); + greenColour.BarColor = System.Drawing.Color.FromArgb(255, red, green, blue); + blueColour.BarColor = System.Drawing.Color.FromArgb(255, red, green, blue); + + redColour.Text = $"Red Colour ({red})"; + redColour.Position = red; + + greenColour.Text = $"Green Colour ({green})"; + greenColour.Position = green; + + blueColour.Text = $"Blue Colour ({blue})"; + blueColour.Position = blue; + } + else if (type == RGBType.headlight) + { + + int red = VehicleData.NeonLightColors[GetHeadlightsColorForVehicle(vehicle)][0]; + int green = VehicleData.NeonLightColors[GetHeadlightsColorForVehicle(vehicle)][1]; + int blue = VehicleData.NeonLightColors[GetHeadlightsColorForVehicle(vehicle)][2]; + + + redColour.BarColor = System.Drawing.Color.FromArgb(255, red, green, blue); + greenColour.BarColor = System.Drawing.Color.FromArgb(255, red, green, blue); + blueColour.BarColor = System.Drawing.Color.FromArgb(255, red, green, blue); + + redColour.Text = $"Red Colour ({red})"; + redColour.Position = red; + + greenColour.Text = $"Green Colour ({green})"; + greenColour.Position = green; + + blueColour.Text = $"Blue Colour ({blue})"; + blueColour.Position = blue; + } + else if (type == RGBType.tiresmoke) + { + int red = vehicle.Mods.TireSmokeColor.R; + int green = vehicle.Mods.TireSmokeColor.G; + int blue = vehicle.Mods.TireSmokeColor.B; + + redColour.BarColor = System.Drawing.Color.FromArgb(255, red, green, blue); + greenColour.BarColor = System.Drawing.Color.FromArgb(255, red, green, blue); + blueColour.BarColor = System.Drawing.Color.FromArgb(255, red, green, blue); + + redColour.Text = $"Red Colour ({red})"; + redColour.Position = red; + + greenColour.Text = $"Green Colour ({green})"; + greenColour.Position = green; + + blueColour.Text = $"Blue Colour ({blue})"; + blueColour.Position = blue; + } + + }; + } /// /// Returns the color index that is applied on the current vehicle. @@ -2569,9 +2891,9 @@ private int GetIndexFromColor() return 0; } - if (_VehicleNeonLightColors.Any(a => { return a[0] == r && a[1] == g && a[2] == b; })) + if (VehicleData.NeonLightColors.Any(a => { return a[0] == r && a[1] == g && a[2] == b; })) { - return _VehicleNeonLightColors.FindIndex(a => { return a[0] == r && a[1] == g && a[2] == b; }); + return VehicleData.NeonLightColors.FindIndex(a => { return a[0] == r && a[1] == g && a[2] == b; }); } return 0;