Skip to content

Commit

Permalink
Merge pull request #395 from JayPaulinCodes/feature/customRgbColours
Browse files Browse the repository at this point in the history
[VehicleOptions] Added ability to select custom vehicle colours using RGB values
  • Loading branch information
XdGoldenTigerOfficial authored Aug 29, 2024
2 parents e7ce553 + 11e6420 commit 3310944
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 13 deletions.
35 changes: 34 additions & 1 deletion vMenu/CommonFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,26 @@ 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"]);
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)
{
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"];
}

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)
{
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"];
}

SetVehicleInteriorColour(vehicle.Handle, vehicleInfo.colors["trim"]);
SetVehicleDashboardColour(vehicle.Handle, vehicleInfo.colors["dash"]);

Expand Down Expand Up @@ -1549,6 +1568,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<int, bool>();
Expand Down
63 changes: 51 additions & 12 deletions vMenu/menus/VehicleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in

if (sender == primaryColorsMenu)
{
if (itemIndex == 1)
if (itemIndex == 2)
{
pearlColor = VehicleData.ClassicColors[newIndex].id;
}
Expand All @@ -1144,26 +1144,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;
Expand All @@ -1172,32 +1173,36 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in
}
}

ClearVehicleCustomPrimaryColour(veh.Handle);
SetVehicleColours(veh.Handle, primaryColor, secondaryColor);
}
else if (sender == secondaryColorsMenu)
{
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;
}

ClearVehicleCustomSecondaryColour(veh.Handle);
SetVehicleColours(veh.Handle, primaryColor, secondaryColor);
}
else if (sender == VehicleColorsMenu)
Expand Down Expand Up @@ -1237,8 +1242,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);
Expand All @@ -1249,6 +1284,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);
Expand All @@ -1264,9 +1300,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);
Expand All @@ -1276,6 +1314,7 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in
secondaryColorsMenu.AddMenuItem(wornList);

secondaryColorsMenu.OnListIndexChange += HandleListIndexChanges;
secondaryColorsMenu.OnItemSelect += HandleItemSelect;
}
}
#endregion
Expand Down

0 comments on commit 3310944

Please sign in to comment.