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

Added default radio station when spawning a vehicle #232

Merged
merged 2 commits into from
Oct 28, 2020
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
5 changes: 5 additions & 0 deletions vMenu/CommonFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,11 @@ public static async void SpawnVehicle(uint vehicleHash, bool spawnInside, bool r
}
vehicle.CurrentRPM = rpm;

await Delay(1); // Mandatory delay - without it radio station will not set properly

// Set the radio station to default set by player in Vehicle Menu
vehicle.RadioStation = (RadioStation)UserDefaults.VehicleDefaultRadio;

// Discard the model.
SetModelAsNoLongerNeeded(vehicleHash);
}
Expand Down
6 changes: 6 additions & 0 deletions vMenu/UserDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ public static bool VehicleBikeSeatbelt
get { return GetSettingsBool("vehicleBikeSeatbelt"); }
set { SetSavedSettingsBool("vehicleBikeSeatbelt", value); }
}

public static int VehicleDefaultRadio
{
get { return GetSettingsInt("vehicleDefaultRadio"); }
set { SetSavedSettingsInt("vehicleDefaultRadio", value); }
}
#endregion

#region Vehicle Spawner Options
Expand Down
31 changes: 31 additions & 0 deletions vMenu/menus/VehicleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ private void CreateMenu()
};
MenuListItem vehicleLights = new MenuListItem("Vehicle Lights", lights, 0, "Turn vehicle lights on/off.");

List<string> stationNames = new List<string>();

foreach (var radioStationName in Enum.GetNames(typeof(RadioStation)))
{
stationNames.Add(radioStationName);
}

int radioIndex = UserDefaults.VehicleDefaultRadio;

if (radioIndex == (int)RadioStation.RadioOff)
{
RadioStation[] stations = (RadioStation[])Enum.GetValues(typeof(RadioStation));
int index = Array.IndexOf(stations, RadioStation.RadioOff);
radioIndex = index;
}

MenuListItem radioStations = new MenuListItem("Default radio station", stationNames, radioIndex, "Select a defalut radio station to be set when spawning new car");

var tiresList = new List<string>() { "All Tires", "Tire #1", "Tire #2", "Tire #3", "Tire #4", "Tire #5", "Tire #6", "Tire #7", "Tire #8" };
MenuListItem vehicleTiresList = new MenuListItem("Fix / Destroy Tires", tiresList, 0, "Fix or destroy a specific vehicle tire, or all of them at once. Note, not all indexes are valid for all vehicles, some might not do anything on certain vehicles.");
Expand Down Expand Up @@ -369,6 +386,9 @@ private void CreateMenu()
}
// always allowed
menu.AddMenuItem(showHealth); // SHOW VEHICLE HEALTH

// I don't really see why would you want to disable this so I will not add useless permissions
TomGrobbe marked this conversation as resolved.
Show resolved Hide resolved
menu.AddMenuItem(radioStations);

if (IsAllowed(Permission.VONoSiren) && !vMenuShared.ConfigManager.GetSettingsBool(vMenuShared.ConfigManager.Setting.vmenu_use_els_compatibility_mode)) // DISABLE SIREN
{
Expand Down Expand Up @@ -897,6 +917,17 @@ private void CreateMenu()
{
Notify.Error(CommonErrors.NoVehicle);
}
} else if (item == radioStations)
{
RadioStation newStation = (RadioStation)Enum.GetValues(typeof(RadioStation)).GetValue(listIndex);
TomGrobbe marked this conversation as resolved.
Show resolved Hide resolved

var veh = GetVehicle();
if (veh != null && veh.Exists())
{
veh.RadioStation = newStation;
}

UserDefaults.VehicleDefaultRadio = (int) newStation;
TomGrobbe marked this conversation as resolved.
Show resolved Hide resolved
}
};
#endregion
Expand Down