Ejemplo n.º 1
0
        /// <summary>
        /// A new subclass has been selected. Update the relevant fields from the model.
        /// </summary>
        private void SelectNewSubClass()
        {
            if (this.SubClassListIndex < 0 ||
                this.SubClassListIndex >= this.SubClassNumbers.Count)
            {
                return;
            }

            // Clear down
            this.NumbersList.Clear();

            foreach (IClassConfigImageSelectorViewModel image in this.Images)
            {
                image.SelectionMadeEvent -= this.UpdateImagesInModel;
            }

            this.Images.Clear();
            this.RaisePropertyChangedEvent(nameof(this.NumbersList));
            this.RaisePropertyChangedEvent(nameof(this.Images));

            // Refresh
            foreach (Number number in this.classFileConfiguration.Subclasses[this.SubClassListIndex].Numbers)
            {
                this.NumbersList.Add(number.CurrentNumber);
            }

            for (int imageIndex = 0; imageIndex < MaxImages; ++imageIndex)
            {
                string imageName =
                    imageIndex < this.classFileConfiguration.Subclasses[this.SubClassListIndex].Images.Count
                    ? this.classFileConfiguration.Subclasses[this.SubClassListIndex].Images[imageIndex].Name
                    : string.Empty;

                IClassConfigImageSelectorViewModel selector =
                    new ClassConfigImageSelectorViewModel(
                        this.unitsIoController,
                        imageName);
                selector.SelectionMadeEvent += this.UpdateImagesInModel;
                this.Images.Add(selector);
            }

            this.RaisePropertyChangedEvent(nameof(this.NumbersList));
            this.RaisePropertyChangedEvent(nameof(this.Images));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialises a new instance of the <see cref="ClassConfigViewModel"/> class.
        /// </summary>
        /// <param name="unitsIoController">units IO controller</param>
        /// <param name="unitsXmlIoController">units XML IO controller</param>
        /// <param name=")">individual units XML IO controller</param>
        /// <param name="classId">class id</param>
        public ClassConfigViewModel(
            UnitsIOController unitsIoController,
            UnitsXmlIOController unitsXmlIoController,
            string classId)
        {
            this.unitsIoController    = unitsIoController;
            this.unitsXmlIoController = unitsXmlIoController;

            this.unsavedChanges = false;

            this.SubClassNumbers = new ObservableCollection <string>();
            this.NumbersList     = new ObservableCollection <int>();
            this.Images          = new ObservableCollection <IClassConfigImageSelectorViewModel>();

            this.classId = classId;

            // If the file doesn't exist then leave m_classData, as initialised.
            if (this.unitsXmlIoController.DoesFileExist(this.classId))
            {
                this.classFileConfiguration =
                    this.unitsXmlIoController.Read(
                        this.classId);

                this.formation       = this.classFileConfiguration.Formation;
                this.alphaIdentifier = this.classFileConfiguration.AlphaId;
                this.year            = this.classFileConfiguration.Year;

                foreach (Subclass subclass in this.classFileConfiguration.Subclasses)
                {
                    this.SubClassNumbers.Add(subclass.Type);
                }

                if (this.SubClassNumbers.Count > 0)
                {
                    this.subClassListIndex = 0;

                    foreach (Number number in this.classFileConfiguration.Subclasses[this.SubClassListIndex].Numbers)
                    {
                        this.NumbersList.Add(number.CurrentNumber);
                    }

                    for (int imageIndex = 0; imageIndex < MaxImages; ++imageIndex)
                    {
                        string imageName =
                            imageIndex < this.classFileConfiguration.Subclasses[this.SubClassListIndex].Images.Count
                            ? this.classFileConfiguration.Subclasses[this.SubClassListIndex].Images[imageIndex].Name
                            : string.Empty;

                        IClassConfigImageSelectorViewModel selector =
                            new ClassConfigImageSelectorViewModel(
                                this.unitsIoController,
                                imageName);
                        selector.SelectionMadeEvent += this.UpdateImagesInModel;
                        this.Images.Add(selector);
                    }
                }
                else
                {
                    this.subClassListIndex = -1;

                    for (int imageIndex = 0; imageIndex < MaxImages; ++imageIndex)
                    {
                        IClassConfigImageSelectorViewModel selector =
                            new ClassConfigImageSelectorViewModel(
                                this.unitsIoController,
                                string.Empty);
                        selector.SelectionMadeEvent += this.UpdateImagesInModel;
                        this.Images.Add(selector);
                    }
                }
            }
            else
            {
                this.classFileConfiguration = new ClassDetails();
            }

            this.CanSave = false;

            this.SaveCmd               = new CommonCommand(this.SaveModel, () => true);
            this.CloseCmd              = new CommonCommand(this.CloseWindow);
            this.AddNewSubClassCmd     = new CommonCommand(this.AddNewSubClass, this.CanPerformAction);
            this.AddNewNumberCmd       = new CommonCommand(this.AddNewNumber, this.CanPerformAction);
            this.AddNewNumberSeriesCmd = new CommonCommand(this.AddNewNumberSeries, this.CanPerformAction);
            this.RenumberCmd           = new CommonCommand(this.Renumber, this.CanPerformAction);
        }