Esempio n. 1
0
        private void SelectPrevious()
        {
            if (_classes.Any())
            {
                ClassListItemViewModel selected = _classes.FirstOrDefault(x => x.IsSelected);

                foreach (ClassListItemViewModel c in _classes)
                {
                    c.IsSelected = false;
                }

                if (selected == null)
                {
                    _classes[_classes.Count - 1].IsSelected = true;
                    _selectedClass = new ClassViewModel(_classes[_classes.Count - 1].ClassModel);
                }
                else
                {
                    int index = Math.Max(_classes.IndexOf(selected) - 1, 0);
                    _classes[index].IsSelected = true;
                    _selectedClass             = new ClassViewModel(_classes[index].ClassModel);
                }

                OnPropertyChanged(nameof(SelectedClass));
            }
        }
Esempio n. 2
0
        private void Delete()
        {
            if (_selectedClass != null)
            {
                bool canDelete = true;

                foreach (CharacterModel character in _compendium.Characters)
                {
                    foreach (LevelModel level in character.Levels)
                    {
                        if (level.Class != null && level.Class.Id == _selectedClass.ClassModel.Id)
                        {
                            canDelete = false;
                            break;
                        }
                    }

                    if (!canDelete)
                    {
                        break;
                    }
                }

                if (canDelete)
                {
                    string message = String.Format("Are you sure you want to delete {0}?",
                                                   _selectedClass.Name);

                    bool?result = _dialogService.ShowConfirmationDialog("Delete Class", message, "Yes", "No", null);

                    if (result == true)
                    {
                        _compendium.DeleteClass(_selectedClass.ClassModel.Id);

                        ClassListItemViewModel listItem = _classes.FirstOrDefault(x => x.ClassModel.Id == _selectedClass.ClassModel.Id);
                        if (listItem != null)
                        {
                            _classes.Remove(listItem);
                        }

                        _selectedClass = null;

                        _compendium.SaveClasses();

                        OnPropertyChanged(nameof(SelectedClass));

                        if (_editClassXML != null)
                        {
                            CancelEditClass();
                        }
                    }
                }
                else
                {
                    _dialogService.ShowConfirmationDialog("Unable Delete Class", "Class is in use by a character.", "OK", null, null);
                }
            }
        }
Esempio n. 3
0
 private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == nameof(ClassesViewModel.SelectedClass))
     {
         ClassListItemViewModel selected = _viewModel.Classes.FirstOrDefault(x => x.IsSelected);
         if (selected != null)
         {
             if (_tree.ItemContainerGenerator.ContainerFromItem(selected) is TreeViewItem item)
             {
                 item.BringIntoView();
             }
         }
     }
 }
Esempio n. 4
0
        private void SelectClass(ClassListItemViewModel classItem)
        {
            bool selectClass = true;

            if (_editClassXML != null)
            {
                if (_editHasUnsavedChanges)
                {
                    string body = String.Format("{0} has unsaved changes.{1}What would you like to do?",
                                                _selectedClass.Name, Environment.NewLine + Environment.NewLine);
                    string accept = "Save and Continue";
                    string reject = "Discard Changes";
                    string cancel = "Cancel Navigation";
                    bool?  result = _dialogService.ShowConfirmationDialog("Unsaved Changes", body, accept, reject, cancel);

                    if (result == true)
                    {
                        if (!SaveEditClass())
                        {
                            selectClass = false;
                        }
                    }
                    else if (result == false)
                    {
                        CancelEditClass();
                    }
                    else
                    {
                        selectClass = false;
                    }
                }
                else
                {
                    CancelEditClass();
                }
            }

            if (selectClass)
            {
                foreach (ClassListItemViewModel item in _classes)
                {
                    item.IsSelected = false;
                }
                classItem.IsSelected = true;

                _selectedClass = new ClassViewModel(classItem.ClassModel);
                OnPropertyChanged(nameof(SelectedClass));
            }
        }
Esempio n. 5
0
 private void SortClasses()
 {
     if (_classes != null && _classes.Count > 0)
     {
         List <ClassModel> classes = _classSearchService.Sort(_classes.Select(x => x.ClassModel), _classSearchInput.SortOption.Key);
         for (int i = 0; i < classes.Count; ++i)
         {
             if (classes[i].Id != _classes[i].ClassModel.Id)
             {
                 ClassListItemViewModel classListItem = _classes.FirstOrDefault(x => x.ClassModel.Id == classes[i].Id);
                 if (classListItem != null)
                 {
                     _classes.Move(_classes.IndexOf(classListItem), i);
                 }
             }
         }
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Searches, applying current sorting and filtering
        /// </summary>
        public void Search()
        {
            _classes.Clear();
            foreach (ClassModel classModel in _classSearchService.Search(_classSearchInput))
            {
                _classes.Add(new ClassListItemViewModel(classModel, _stringService));
            }

            if (_selectedClass != null)
            {
                ClassListItemViewModel classItem = _classes.FirstOrDefault(x => x.ClassModel.Id == _selectedClass.ClassModel.Id);
                if (classItem != null)
                {
                    classItem.IsSelected = true;
                }
            }

            OnPropertyChanged(nameof(SortAndFilterHeader));
        }
Esempio n. 7
0
        private void Copy()
        {
            if (_selectedClass != null)
            {
                bool copyClass = true;

                if (_editClassXML != null)
                {
                    if (_editHasUnsavedChanges)
                    {
                        string body = String.Format("{0} has unsaved changes.{1}What would you like to do?",
                                                    _selectedClass.Name, Environment.NewLine + Environment.NewLine);
                        string accept = "Save and Continue";
                        string reject = "Discard Changes";
                        string cancel = "Cancel Navigation";
                        bool?  result = _dialogService.ShowConfirmationDialog("Unsaved Changes", body, accept, reject, cancel);

                        if (result == true)
                        {
                            if (!SaveEditClass())
                            {
                                copyClass = false;
                            }
                        }
                        else if (result == false)
                        {
                            CancelEditClass();
                        }
                        else
                        {
                            copyClass = false;
                        }
                    }
                    else
                    {
                        CancelEditClass();
                    }
                }

                if (copyClass)
                {
                    ClassModel newClass = new ClassModel(_selectedClass.ClassModel);
                    newClass.Name += " (copy)";
                    newClass.Id    = Guid.NewGuid();
                    newClass.XML   = newClass.XML.Replace("<name>" + _selectedClass.ClassModel.Name + "</name>",
                                                          "<name>" + newClass.Name + "</name>");

                    _compendium.AddClass(newClass);

                    if (_classSearchService.SearchInputApplies(_classSearchInput, newClass))
                    {
                        ClassListItemViewModel listItem = new ClassListItemViewModel(newClass, _stringService);
                        _classes.Add(listItem);
                        foreach (ClassListItemViewModel item in _classes)
                        {
                            item.IsSelected = false;
                        }
                        listItem.IsSelected = true;
                    }

                    _selectedClass = new ClassViewModel(newClass);

                    SortClasses();

                    _compendium.SaveClasses();

                    OnPropertyChanged(nameof(SelectedClass));
                }
            }
        }
Esempio n. 8
0
        private void Add()
        {
            bool addClass = true;

            if (_editClassXML != null)
            {
                if (_editHasUnsavedChanges)
                {
                    string body = String.Format("{0} has unsaved changes.{1}What would you like to do?",
                                                _selectedClass.Name, Environment.NewLine + Environment.NewLine);
                    string accept = "Save and Continue";
                    string reject = "Discard Changes";
                    string cancel = "Cancel Navigation";
                    bool?  result = _dialogService.ShowConfirmationDialog("Unsaved Changes", body, accept, reject, cancel);

                    if (result == true)
                    {
                        if (!SaveEditClass())
                        {
                            addClass = false;
                        }
                    }
                    else if (result == false)
                    {
                        CancelEditClass();
                    }
                    else
                    {
                        addClass = false;
                    }
                }
                else
                {
                    CancelEditClass();
                }
            }

            if (addClass)
            {
                string xml = "<name>New Class</name><hd>0</hd><proficiency></proficiency><spellAbility></spellAbility><autolevel level=\"1\"><feature optional=\"YES\"><name>Starting</name><text></text></feature></autolevel>";

                ClassModel classModel = _xmlImporter.GetClass(xml);

                _compendium.AddClass(classModel);

                if (_classSearchService.SearchInputApplies(_classSearchInput, classModel))
                {
                    ClassListItemViewModel listItem = new ClassListItemViewModel(classModel, _stringService);
                    _classes.Add(listItem);
                    foreach (ClassListItemViewModel item in _classes)
                    {
                        item.IsSelected = false;
                    }
                    listItem.IsSelected = true;
                }

                _selectedClass = new ClassViewModel(classModel);

                _editClassXML = classModel.XML;

                SortClasses();

                _compendium.SaveClasses();

                OnPropertyChanged(nameof(EditingClassXML));
                OnPropertyChanged(nameof(IsEditingClass));
                OnPropertyChanged(nameof(SelectedClass));
            }
        }
Esempio n. 9
0
        private bool SaveEditClass()
        {
            bool saved = false;

            try
            {
                ClassModel model = _xmlImporter.GetClass(_editClassXML);

                if (model != null)
                {
                    model.Id = _selectedClass.ClassModel.Id;
                    _compendium.UpdateClass(model);
                    _selectedClass = new ClassViewModel(model);

                    ClassListItemViewModel oldListItem = _classes.FirstOrDefault(x => x.ClassModel.Id == model.Id);
                    if (oldListItem != null)
                    {
                        if (_classSearchService.SearchInputApplies(_classSearchInput, model))
                        {
                            oldListItem.UpdateModel(model);
                        }
                        else
                        {
                            _classes.Remove(oldListItem);
                        }
                    }

                    _editClassXML          = null;
                    _editHasUnsavedChanges = false;

                    SortClasses();

                    _compendium.SaveClasses();

                    OnPropertyChanged(nameof(SelectedClass));
                    OnPropertyChanged(nameof(EditingClassXML));
                    OnPropertyChanged(nameof(IsEditingClass));
                    OnPropertyChanged(nameof(HasUnsavedChanges));

                    saved = true;
                }
                else
                {
                    string message = String.Format("Something went wrong...{0}{1}{2}{3}",
                                                   Environment.NewLine + Environment.NewLine,
                                                   "The following are required:",
                                                   Environment.NewLine,
                                                   "-name");
                    _dialogService.ShowConfirmationDialog("Unable To Save", message, "OK", null, null);
                }
            }
            catch (Exception ex)
            {
                string message = String.Format("Something went wrong...{0}{1}",
                                               Environment.NewLine + Environment.NewLine,
                                               ex.Message);
                _dialogService.ShowConfirmationDialog("Unable To Save", message, "OK", null, null);
            }

            return(saved);
        }