Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VehicleOptions] Added ability to select custom vehicle colours using RGB values #395

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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;
}
Expand All @@ -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;
Expand All @@ -1147,32 +1148,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 @@ -1212,8 +1217,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 @@ -1224,6 +1259,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 @@ -1239,9 +1275,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 @@ -1251,6 +1289,7 @@ void HandleListIndexChanges(Menu sender, MenuListItem listItem, int oldIndex, in
secondaryColorsMenu.AddMenuItem(wornList);

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