Ejemplo n.º 1
0
    /// <summary>
    /// Handles when the user selects a new value in the level collection dropdown.
    /// </summary>
    /// <param name="selectedLevel">The index of the level which should be selected by default in the level select menu.</param>
    /// <param name="mode">The LevelManagerMode which should be selected.</param>
    /// <param name="numCars">The number of cars which should be selected.</param>
    public void HandleLevelCollectionDropdownChange(int selectedLevel, LevelManagerMode mode, int numCars)
    {
        Dropdown levelSelect = this.dropdowns[(int)Dropdowns.LevelSelect];

        levelSelect.ClearOptions();
        levelSelect.AddOptions(this.SelectedLevelCollection.LevelNames);
        levelSelect.value = selectedLevel;

        this.HandleLevelDropdownChange(mode, numCars);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Handles when the user selects a new value in the level dropdown.
    /// </summary>
    /// <param name="mode">The LevelManagerMode which should be selected.</param>
    /// <param name="numCars">The number of cars which should be selected.</param>
    public void HandleLevelDropdownChange(LevelManagerMode mode, int numCars)
    {
        // Adjust mode dropdown to show/hide "Race" option based on level
        Dropdown modeDropdown = this.dropdowns[(int)Dropdowns.Mode];
        List <Dropdown.OptionData> modeOptions =
            SelectedLevel.IsRaceable ? MainMenu.ModeOptionsWithRace
            :  SelectedLevel.AutograderLevels != null ? MainMenu.ModeOptionsWithoutRace : MainMenu.ModeOptionsWithoutAutograder;

        if (modeDropdown.options.Count != modeOptions.Count)
        {
            modeDropdown.options      = modeOptions;
            modeDropdown.interactable = modeOptions.Count > 1;
        }

        modeDropdown.value = (int)mode;

        // Show and populate the numCars dropdown if the level supports multiple cars
        Dropdown numCarDropdown = this.dropdowns[(int)Dropdowns.NumCars];

        if (this.SelectedLevel.MaxCars > 1)
        {
            if (this.SelectedLevel.MaxCars != numCarDropdown.options.Count)
            {
                List <string> options = new List <string>(this.SelectedLevel.MaxCars);
                for (int i = 1; i <= this.SelectedLevel.MaxCars; i++)
                {
                    options.Add(i.ToString());
                }
                numCarDropdown.ClearOptions();
                numCarDropdown.AddOptions(options);
            }
            this.numCars.SetActive(true);
        }
        else
        {
            this.numCars.SetActive(false);
        }

        // Regardless of whether it is shown, we always set the dropdown value since it determines NumPlayers when the level is loaded
        numCarDropdown.value = numCars - 1;
    }