Esempio n. 1
0
        private void ExportNPC(NPCViewModel npcViewModel)
        {
            Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
            saveFileDialog.Filter   = "NPC Archive|*.ccea|Word Document|*.docx";
            saveFileDialog.Title    = "Save NPC";
            saveFileDialog.FileName = npcViewModel.Name;

            if (saveFileDialog.ShowDialog() == true)
            {
                try
                {
                    string ext = Path.GetExtension(saveFileDialog.FileName);

                    if (ext == ".ccaa")
                    {
                        byte[] bytes = _dataManager.CreateNPCArchive(npcViewModel.NPCModel);
                        File.WriteAllBytes(saveFileDialog.FileName, bytes);
                    }
                    else if (ext == "*.docx")
                    {
                        //_documentService.CreateWordDoc(saveFileDialog.FileName, npcViewModel);
                    }
                    else
                    {
                        _dialogService.ShowConfirmationDialog("Unable To Export", "Invalid file extension.", "OK", null, null);
                    }
                }
                catch (Exception)
                {
                    _dialogService.ShowConfirmationDialog("Unable To Export", "An error occurred when attempting to export the npc.", "OK", null, null);
                }
            }
        }
Esempio n. 2
0
        private void SelectPrevious()
        {
            if (_npcs.Any())
            {
                ListItemViewModel <NPCModel> selected = _npcs.FirstOrDefault(x => x.IsSelected);

                foreach (ListItemViewModel <NPCModel> npc in _npcs)
                {
                    npc.IsSelected = false;
                }

                if (selected == null)
                {
                    _npcs[_npcs.Count - 1].IsSelected = true;
                    _selectedNPC = new NPCViewModel(_npcs[_npcs.Count - 1].Model);
                }
                else
                {
                    int index = Math.Max(_npcs.IndexOf(selected) - 1, 0);
                    _npcs[index].IsSelected = true;
                    _selectedNPC            = new NPCViewModel(_npcs[index].Model);
                }

                OnPropertyChanged(nameof(SelectedNPC));
            }
        }
Esempio n. 3
0
        private void Delete()
        {
            if (_selectedNPC != null)
            {
                string message = String.Format("Are you sure you want to delete {0}?",
                                               _selectedNPC.Name);

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

                if (result == true)
                {
                    _compendium.DeleteNPC(_selectedNPC.NPCModel.Id);

                    ListItemViewModel <NPCModel> listItem = _npcs.FirstOrDefault(x => x.Model.Id == _selectedNPC.NPCModel.Id);
                    if (listItem != null)
                    {
                        _npcs.Remove(listItem);
                    }

                    _selectedNPC = null;

                    _compendium.SaveNPCs();

                    OnPropertyChanged(nameof(SelectedNPC));

                    if (_npcEditViewModel != null)
                    {
                        CancelEditNPC();
                    }
                }
            }
        }
Esempio n. 4
0
        private void EditNPC(NPCViewModel npcModel)
        {
            if (npcModel != null)
            {
                _npcEditViewModel = new NPCEditViewModel(npcModel.NPCModel);
                _npcEditViewModel.PropertyChanged += _npcEditViewModel_PropertyChanged;

                OnPropertyChanged(nameof(EditingNPC));
                OnPropertyChanged(nameof(IsEditingNPC));
            }
        }
Esempio n. 5
0
        private void SelectNPC(ListItemViewModel <NPCModel> npcItem)
        {
            bool selectNPC = true;

            if (_npcEditViewModel != null)
            {
                if (_editHasUnsavedChanges)
                {
                    string body = String.Format("{0} has unsaved changes.{1}What would you like to do?",
                                                _selectedNPC.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 (!SaveEditNPC())
                        {
                            selectNPC = false;
                        }
                    }
                    else if (result == false)
                    {
                        CancelEditNPC();
                    }
                    else
                    {
                        selectNPC = false;
                    }
                }
                else
                {
                    CancelEditNPC();
                }
            }

            if (selectNPC)
            {
                foreach (ListItemViewModel <NPCModel> item in _npcs)
                {
                    item.IsSelected = false;
                }
                npcItem.IsSelected = true;

                _selectedNPC = new NPCViewModel(npcItem.Model);
                OnPropertyChanged(nameof(SelectedNPC));
            }
        }
Esempio n. 6
0
        private bool SaveEditNPC()
        {
            bool saved = false;

            if (_npcEditViewModel.NPCModel != null)
            {
                _npcEditViewModel.NPCModel.Id = _selectedNPC.NPCModel.Id;
                _compendium.UpdateNPC(_npcEditViewModel.NPCModel);

                _selectedNPC = new NPCViewModel(_npcEditViewModel.NPCModel);

                ListItemViewModel <NPCModel> oldListItem = _npcs.FirstOrDefault(x => x.Model.Id == _npcEditViewModel.NPCModel.Id);
                if (oldListItem != null)
                {
                    if (_npcSearchService.SearchInputApplies(_npcSearchInput, _npcEditViewModel.NPCModel))
                    {
                        InitializeListItemDetails(oldListItem, _npcEditViewModel.NPCModel);
                    }
                    else
                    {
                        _npcs.Remove(oldListItem);
                    }
                }

                _npcEditViewModel      = null;
                _editHasUnsavedChanges = false;

                SortNPCs();

                _compendium.SaveNPCs();

                OnPropertyChanged(nameof(SelectedNPC));
                OnPropertyChanged(nameof(EditingNPC));
                OnPropertyChanged(nameof(IsEditingNPC));
                OnPropertyChanged(nameof(HasUnsavedChanges));

                saved = true;
            }

            return(saved);
        }
Esempio n. 7
0
        private void Copy()
        {
            if (_selectedNPC != null)
            {
                bool copyNPC = true;

                if (_npcEditViewModel != null)
                {
                    if (_editHasUnsavedChanges)
                    {
                        string body = String.Format("{0} has unsaved changes.{1}What would you like to do?",
                                                    _selectedNPC.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 (!SaveEditNPC())
                            {
                                copyNPC = false;
                            }
                        }
                        else if (result == false)
                        {
                            CancelEditNPC();
                        }
                        else
                        {
                            copyNPC = false;
                        }
                    }
                    else
                    {
                        CancelEditNPC();
                    }
                }

                if (copyNPC)
                {
                    NPCModel npcModel = new NPCModel(_selectedNPC.NPCModel);
                    npcModel.Name += " (copy)";
                    npcModel.Id    = Guid.NewGuid();

                    _compendium.AddNPC(npcModel);

                    if (_npcSearchService.SearchInputApplies(_npcSearchInput, npcModel))
                    {
                        ListItemViewModel <NPCModel> listItem = new ListItemViewModel <NPCModel>(npcModel);
                        InitializeListItemDetails(listItem, npcModel);
                        _npcs.Add(listItem);
                        foreach (ListItemViewModel <NPCModel> item in _npcs)
                        {
                            item.IsSelected = false;
                        }
                        listItem.IsSelected = true;
                    }

                    _selectedNPC = new NPCViewModel(npcModel);

                    SortNPCs();

                    _compendium.SaveNPCs();

                    OnPropertyChanged(nameof(SelectedNPC));
                }
            }
        }