Ejemplo n.º 1
0
        private static void AddVehicle(Vehicle vehicle, StationWheelPair pair)
        {
            if (Vehicles.Count == 20)
            {
                Vehicles.RemoveAt(0);
            }

            Vehicles.Add(new UsedVehicle(vehicle, pair));
        }
Ejemplo n.º 2
0
        public static void SetLastStationNow(Vehicle vehicle)
        {
            if (IsUsedVehicle(vehicle))
            {
                var item = GetFromList(vehicle);

                if (item.radioInfo == null)
                {
                    return;
                }

                //StationWheelPair pair = StationWheelPair.List.Find(x => x.Station == item.radioInfo.Station);
                StationWheelPair pair = StationWheelPair.List.Find(x => x.Equals(item.radioInfo));

                WheelVars.CurrentRadioWheel = pair.Wheel;
                WheelVars.CurrentRadioWheel.SelectedCategory = pair.Category;
                RadioStation.NextQueuedStation = pair.Station;
            }
        }
Ejemplo n.º 3
0
        public static void UpdateVehicleWithStationInfo(Vehicle vehicle, StationWheelPair pair)
        {
            if (IsUsedVehicle(vehicle))
            {
                var item = GetFromList(vehicle);

                if (pair == null)
                {
                    //Vehicles.Remove(item);
                    item.radioInfo = null;
                }
                else
                {
                    item.radioInfo = pair;
                }
            }
            else
            {
                AddVehicle(vehicle, pair);
            }
        }
        public void SetupRadio()
        {
            // Get folders in script's main folder "Custom Radio Stations"
            string[] wheelDirectories = Directory.GetDirectories(mainPath, "*", SearchOption.TopDirectoryOnly);

            foreach (var wheelDir in wheelDirectories)
            {
                Logger.Log("Loading " + wheelDir);

                Logger.Log("Checking if " + wheelDir + "\\settings.ini exists");

                var wheelIni = Config.LoadWheelINI(wheelDir);

                // Create wheel obj
                Wheel radioWheel = new Wheel("Radio Wheel", wheelDir, 0, 0, new System.Drawing.Size(wheelIni.iconX, wheelIni.iconY), 200, wheelIni.wheelRadius);

                // Get folders in script's main folder "Custom Radio Stations"
                string[] stationDirectories = Directory.GetDirectories(wheelDir, "*", SearchOption.TopDirectoryOnly);

                Logger.Log("Number of stations: " + stationDirectories.Count());

                // Specify file extensions to search for in the next step
                var extensions = new List <string> {
                    ".mp3", ".wav", ".flac", ".lnk"
                };

                // Keep count of the number of station folders with actual music files
                int populatedStationCount = 0;

                // Generate wheel categories for each folder, which will be our individual stations on the wheel
                foreach (var stationDir in stationDirectories)
                {
                    Logger.Log("Loading " + stationDir);

                    // Get all files that have the above-mentioned extensions.
                    var musicFilePaths = Directory.GetFiles(stationDir, "*.*", SearchOption.TopDirectoryOnly)
                                         .Where(x => extensions.Contains(Path.GetExtension(x)));

                    // Don't make a station out of an empty folder
                    if (musicFilePaths.Count() == 0)
                    {
                        Logger.Log("Skipping " + Path.GetFileName(stationDir) + " as there are no music files.");
                        continue;
                    }

                    // Increase count
                    populatedStationCount++;

                    WheelCategory stationCat = new WheelCategory(Path.GetFileName(stationDir));
                    radioWheel.AddCategory(stationCat);
                    WheelCategoryItem stationItem = new WheelCategoryItem(stationCat.Name);
                    stationCat.AddItem(stationItem);

                    RadioStation station = new RadioStation(stationCat, musicFilePaths);

                    // Add wheel category-station combo to a station list
                    StationWheelPair pair = new StationWheelPair(radioWheel, stationCat, station);
                    StationWheelPair.List.Add(pair);

                    // Get description
                    pair.LoadStationINI(Path.Combine(stationDir, "station.ini"));

                    radioWheel.OnCategoryChange += (sender, selectedCategory, selectedItem, wheelJustOpened) =>
                    {
                        // HandleRadioWheelToggle() handles what happens when the wheel is opened.
                        // So we will only use this anonymous method for when the station is actually changed.
                        //if (wheelJustOpened) return;

                        if (selectedCategory == stationCat)
                        {
                            // If there is no input for a short amount of time, set the selected station as next to play
                            ActionQueued = ActionOptions.PlayQueued;

                            RadioStation.NextQueuedStation = station;

                            // If radio is still being decided, add delay before station changes
                            SetActionDelay(Config.WheelActionDelay);

                            lastRadioWasCustom = true;
                        }
                    };

                    radioWheel.OnItemChange += (sender, selectedCategory, selectedItem, wheelJustOpened, goTo) =>
                    {
                        if (wheelJustOpened)
                        {
                            return;
                        }

                        if (radioWheel.Visible && radioWheel == WheelVars.CurrentRadioWheel && WheelVars.NextQueuedWheel == null)
                        {
                            if (goTo == GoTo.Next)
                            {
                                radioWheel.Visible        = false;
                                WheelVars.NextQueuedWheel = WheelVars.RadioWheels.GetNext(radioWheel);
                            }
                            else if (goTo == GoTo.Prev)
                            {
                                radioWheel.Visible        = false;
                                WheelVars.NextQueuedWheel = WheelVars.RadioWheels.GetPrevious(radioWheel);
                            }
                        }
                    };
                }

                if (populatedStationCount > 0)
                {
                    WheelVars.RadioWheels.Add(radioWheel);
                    radioWheel.Origin = new Vector2(0.5f, 0.45f);
                    radioWheel.SetCategoryBackgroundIcons(iconBgPath, Config.IconBG, Config.IconBgSizeMultiple, iconhighlightPath, Config.IconHL, Config.IconHlSizeMultiple);
                    radioWheel.CalculateCategoryPlacement();
                }

                Logger.Log(@"/\/\/\/\/\/\/\/\/\/\/\/\/\/\");
            }

            if (WheelVars.RadioWheels.Count > 0)
            {
                WheelVars.CurrentRadioWheel = WheelVars.RadioWheels[0];
            }
            else
            {
                UI.ShowSubtitle("No music found in Custom Radio Stations. " +
                                "Please add music and reload script with the INS key.");
                Logger.Log("ERROR: No music found in any station directory. Aborting script...");
                Tick -= OnTick;
            }
        }
Ejemplo n.º 5
0
 public UsedVehicle(Vehicle vehicle, StationWheelPair pair)
 {
     Handle    = vehicle.Handle;
     radioInfo = pair;
 }