Ejemplo n.º 1
0
    public void OnClick_TimetableItemForModification(TimetableItemUIObject timetableUIObject)
    {
        //get the timetable item [Model] for this particular timetable UI object and store in the activeTimetable ref. NOTE: this is required so that Confirm Modified Item can use this ref. later
        if (timetableUITracker.TryGetValueByFirst(timetableUIObject, out activeTimetableItem))
        {
            defaultOptionsMenu.SetActive(false);
            activeTimetableItem.modificationFlag = true;
            timetableItemsParent.GetComponent <CanvasGroup> ().interactable = false;                    //set all timetable UI items so they cannot be modified
            //populate the 4 modification menu items with the values from this timetable item that is being modified
            modification_schedDepartureTimeText.text = ConvertGameTimeToHHMM(activeTimetableItem.scheduledDepartureTime);
            modification_DestinationText.text        = activeTimetableItem.destination.name;

            int indexOfPreviouslySelected = -1;
            if (activeTimetableItem.train != null)                      //if the item selected for mods had a train already chosen previously then restore it to available options
            {
                GameManager.instance.trainPool.RestoreItem(activeTimetableItem.train.trainSerialID, activeTimetableItem.train);
            }
            modification_trainDropdown.ClearOptions();
            List <Dropdown.OptionData> dropdownOptions = new List <Dropdown.OptionData> ();
            dropdownOptions.Add(emptyTrainOption);              //an empty option at start
            foreach (Train train in GameManager.instance.trainPool.AvailableOptions)
            {
                dropdownOptions.Add(new Dropdown.OptionData(train.trainSerialID, trainUISprite));
                if (activeTimetableItem.train != null && activeTimetableItem.train.trainSerialID == train.trainSerialID)
                {
                    indexOfPreviouslySelected = dropdownOptions.Count - 1;
                }
            }
            modification_trainDropdown.AddOptions(dropdownOptions);
            modification_trainDropdown.value = (activeTimetableItem.train == null)? 0 : indexOfPreviouslySelected;              //if the item selected for mods had a train already chosen previously then select it as the dropdown option, otherwise the empty option

            indexOfPreviouslySelected = -1;
            if (activeTimetableItem.platform != null)                   //if the item selected for mods had a platform already chosen previously then restore it to available options and select it in the dropdown
            {
                GameManager.instance.platforms.RestoreItem(activeTimetableItem.platform.platformNumber.ToString(), activeTimetableItem.platform);
            }
            modification_platformDropdown.ClearOptions();
            dropdownOptions.Clear();                  //used for trains prior to this
            dropdownOptions.Add(emptyPlatformOption); //an empty option at start
            foreach (Platform platform in GameManager.instance.platforms.AvailableOptions)
            {
                dropdownOptions.Add(new Dropdown.OptionData("Platform " + platform.platformNumber.ToString()));
                if (activeTimetableItem.platform != null && activeTimetableItem.platform.platformNumber == platform.platformNumber)
                {
                    indexOfPreviouslySelected = dropdownOptions.Count - 1;
                }
            }
            modification_platformDropdown.AddOptions(dropdownOptions);
            modification_platformDropdown.value = (activeTimetableItem.platform == null)? 0 : indexOfPreviouslySelected;                //if the item selected for mods had a platform already chosen previously then select it in the dropdown, otherwise the empty option
            itemModificationMenu.SetActive(true);
        }
        else
        {
            Debug.LogWarning("Player clicked a Timetable UI Item for modification but it was not found in the timetableUITracker dictionary of such items. Modification will not occur.");
        }
    }