Skip to content

Commit

Permalink
Merge pull request #232 from Explooosion-code/radiostation
Browse files Browse the repository at this point in the history
Added default radio station when spawning a vehicle
  • Loading branch information
TomGrobbe authored Oct 28, 2020
2 parents 54aaa0f + 0c4e17d commit 7942210
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
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
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);
var veh = GetVehicle();
if (veh != null && veh.Exists())
{
veh.RadioStation = newStation;
}
UserDefaults.VehicleDefaultRadio = (int) newStation;
}
};
#endregion
Expand Down

0 comments on commit 7942210

Please sign in to comment.