From fd1962f3cfcfe29165f00ea14b78478efae3933c Mon Sep 17 00:00:00 2001 From: Explooosion-code <61145047+Explooosion-code@users.noreply.github.com> Date: Thu, 22 Oct 2020 10:12:37 +0200 Subject: [PATCH 1/2] Added default radio station when spawning a vehicle --- vMenu/CommonFunctions.cs | 5 +++++ vMenu/UserDefaults.cs | 6 ++++++ vMenu/menus/VehicleOptions.cs | 29 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/vMenu/CommonFunctions.cs b/vMenu/CommonFunctions.cs index ff3960f5..a5885f2b 100644 --- a/vMenu/CommonFunctions.cs +++ b/vMenu/CommonFunctions.cs @@ -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); } diff --git a/vMenu/UserDefaults.cs b/vMenu/UserDefaults.cs index d046bb9c..751ddef1 100644 --- a/vMenu/UserDefaults.cs +++ b/vMenu/UserDefaults.cs @@ -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 diff --git a/vMenu/menus/VehicleOptions.cs b/vMenu/menus/VehicleOptions.cs index 47fef631..c2a32d9e 100644 --- a/vMenu/menus/VehicleOptions.cs +++ b/vMenu/menus/VehicleOptions.cs @@ -134,6 +134,21 @@ private void CreateMenu() }; MenuListItem vehicleLights = new MenuListItem("Vehicle Lights", lights, 0, "Turn vehicle lights on/off."); + List stationNames = new List(); + + foreach (var radioStationName in Enum.GetNames(typeof(RadioStation))) + { + stationNames.Add(radioStationName); + } + + int radioIndex = UserDefaults.VehicleDefaultRadio; + + if (radioIndex == 255) // 255 is radio off + { + radioIndex = Enum.GetValues(typeof(RadioStation)).Length -1; // the last item is Radio off + } + + 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() { "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."); @@ -369,6 +384,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 { @@ -897,6 +915,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 From 0c4e17da51a2368b288184772ee7916ea0846132 Mon Sep 17 00:00:00 2001 From: Explooosion-code <61145047+Explooosion-code@users.noreply.github.com> Date: Mon, 26 Oct 2020 11:29:17 +0100 Subject: [PATCH 2/2] Update VehicleOptions.cs --- vMenu/menus/VehicleOptions.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vMenu/menus/VehicleOptions.cs b/vMenu/menus/VehicleOptions.cs index c2a32d9e..55169af3 100644 --- a/vMenu/menus/VehicleOptions.cs +++ b/vMenu/menus/VehicleOptions.cs @@ -143,9 +143,11 @@ private void CreateMenu() int radioIndex = UserDefaults.VehicleDefaultRadio; - if (radioIndex == 255) // 255 is radio off + if (radioIndex == (int)RadioStation.RadioOff) { - radioIndex = Enum.GetValues(typeof(RadioStation)).Length -1; // the last item is Radio off + 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");