Ejemplo n.º 1
0
 private void _compendium_EncounterChanged(object sender, CompendiumChangeEventArgs e)
 {
     if (_selectedEncounter != null && e.IDs.Contains(_selectedEncounter.EncounterModel.Id))
     {
         _selectedEncounter = new EncounterViewModel(_selectedEncounter.EncounterModel);
     }
 }
        private async void NewEncounter(object sender, EventArgs e)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            var encounter = new EncounterViewModel()
            {
                CampaignId = campaign.Id
            };

            var name = await DisplayPromptAsync("New Encounter", "Name: ");

            if (!string.IsNullOrEmpty(name))
            {
                encounter.Name = name;
                await encounter.Save();

                await Navigation.PushAsync(new EncounterEditPage()
                {
                    BindingContext = encounter
                });
            }

            IsBusy = false;
        }
Ejemplo n.º 3
0
        private void Delete()
        {
            if (_selectedEncounter != null)
            {
                string message = String.Format("Are you sure you want to delete {0}?",
                                               _selectedEncounter.Name);

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

                if (result == true)
                {
                    _compendium.DeleteEncounter(_selectedEncounter.EncounterModel.Id);

                    EncounterListItemViewModel listItem = _encounters.FirstOrDefault(x => x.EncounterModel.Id == _selectedEncounter.EncounterModel.Id);
                    if (listItem != null)
                    {
                        _encounters.Remove(listItem);
                    }

                    _selectedEncounter = null;

                    _compendium.SaveEncounters();

                    OnPropertyChanged(nameof(SelectedEncounter));

                    if (_encounterEditViewModel != null)
                    {
                        CancelEditEncounter();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void ExportEncounter(EncounterViewModel encounterViewModel)
        {
            Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();
            saveFileDialog.Filter   = "Encounter Archive|*.ccea";
            saveFileDialog.Title    = "Save Encounter";
            saveFileDialog.FileName = encounterViewModel.Name;

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

                    if (ext == ".ccea")
                    {
                        byte[] bytes = _dataManager.CreateEncounterArchive(encounterViewModel.EncounterModel);
                        File.WriteAllBytes(saveFileDialog.FileName, bytes);
                    }
                    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 encounter.", "OK", null, null);
                }
            }
        }
Ejemplo n.º 5
0
        public async Task <PartialViewResult> MonstersDetail(int id, bool value)
        {
            var encounter = new EncounterViewModel();

            SetEncounterCreatures(encounter);

            if (value == true)
            {
                var client       = new HttpClient();
                var urlExtension = $"api/monsters/" + id;

                client.BaseAddress = new Uri("http://dnd5eapi.co/");
                var result = await client.GetAsync(urlExtension);

                var monster = await result.Content.ReadAsAsync <Monsters>();

                encounter.Monsters = monster;

                //return PartialView("_MonstersDetail", encounter);
            }

            else if (value == false)
            {
                Characters character = db.Characters.Find(id);
                encounter.Characters = character;

                //return PartialView("_MonstersDetail", encounter);
            }

            return(PartialView("MonstersDetail", encounter));
        }
Ejemplo n.º 6
0
        private void SelectPrevious()
        {
            if (_encounters.Any())
            {
                EncounterListItemViewModel selected = _encounters.FirstOrDefault(x => x.IsSelected);

                foreach (EncounterListItemViewModel encounter in _encounters)
                {
                    encounter.IsSelected = false;
                }

                if (selected == null)
                {
                    _encounters[_encounters.Count - 1].IsSelected = true;
                    _selectedEncounter = new EncounterViewModel(_encounters[_encounters.Count - 1].EncounterModel);
                }
                else
                {
                    int index = Math.Max(_encounters.IndexOf(selected) - 1, 0);
                    _encounters[index].IsSelected = true;
                    _selectedEncounter            = new EncounterViewModel(_encounters[index].EncounterModel);
                }

                OnPropertyChanged(nameof(SelectedEncounter));
            }
        }
Ejemplo n.º 7
0
        public virtual EncounterViewModel EncounterViewModel()
        {
            var encounterViewModel = new EncounterViewModel();

            encounterViewModel.EditCommand = new RelayCommand <TurningPoint>(x => { encounterViewModel.TurningPoint = x; });

            return(encounterViewModel);
        }
Ejemplo n.º 8
0
        private void CancelEditEncounter()
        {
            _editHasUnsavedChanges  = false;
            _encounterEditViewModel = null;

            OnPropertyChanged(nameof(EditingEncounter));
            OnPropertyChanged(nameof(IsEditingEncounter));
            OnPropertyChanged(nameof(HasUnsavedChanges));
        }
Ejemplo n.º 9
0
        private void CommitAddElement()
        {
            EncounterViewModel vm = (EncounterViewModel)DataContext;

            vm.AddElements(this.elementSearchList.SelectedItems.Cast <EnvironmentElementViewModel> ());

            this.addElementSearch.Text = String.Empty;
            this.addElementFlyout.Hide();
        }
Ejemplo n.º 10
0
        private void EditEncounter(EncounterViewModel encounterModel)
        {
            if (encounterModel != null)
            {
                _encounterEditViewModel = new EncounterViewModel(encounterModel.EncounterModel);
                _encounterEditViewModel.PropertyChanged += _encounterEditViewModel_PropertyChanged;

                OnPropertyChanged(nameof(EditingEncounter));
                OnPropertyChanged(nameof(IsEditingEncounter));
            }
        }
Ejemplo n.º 11
0
        protected override void OnAppearing()
        {
            base.OnAppearing();
            encounter = BindingContext as EncounterViewModel;
            encounter.AddPlayers();
            creatureList.ItemsSource = encounter.Creatures;

            if (!rolled)
            {
                RollInitiative();
            }
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> Create(EncounterViewModel encounterView)
        {
            try
            {
                var user = await getcurrentuserasync();

                var encounterinstance = new Encounter


                {
                    Name                = encounterView.Encounter.Name,
                    Description         = encounterView.Encounter.Description,
                    Location            = encounterView.Encounter.Location,
                    CharacterEncounters = new List <CharacterEncounter>(),
                    MonsterEncounters   = new List <MonsterEncounter>(),
                    ApplicationUserId   = user.Id
                };

                _context.Add(encounterinstance);
                await _context.SaveChangesAsync();

                foreach (var characterId in encounterView.CharacterIds)
                {
                    var createdCharacterEncounter = new CharacterEncounter
                    {
                        CharacterId = characterId,
                        EncounterId = encounterinstance.Id
                    };
                    _context.Add(createdCharacterEncounter);
                }

                foreach (var monsterId in encounterView.MonsterIds)
                {
                    var createdMonsterEncounter = new MonsterEncounter
                    {
                        MonsterId   = monsterId,
                        EncounterId = encounterinstance.Id
                    };
                    _context.Add(createdMonsterEncounter);
                }


                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 13
0
 private void _compendium_CharacterChanged(object sender, CompendiumChangeEventArgs e)
 {
     if (_selectedEncounter != null)
     {
         foreach (EncounterCharacterViewModel encounterCharacter in _selectedEncounter.Characters)
         {
             if (encounterCharacter.EncounterCharacterModel.CharacterModel != null && e.IDs.Contains(encounterCharacter.EncounterCharacterModel.CharacterModel.Id))
             {
                 _selectedEncounter = new EncounterViewModel(_selectedEncounter.EncounterModel);
                 break;
             }
         }
     }
 }
Ejemplo n.º 14
0
        private void SelectEncounter(EncounterListItemViewModel encounterItem)
        {
            bool selectEncounter = true;

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

            if (selectEncounter)
            {
                foreach (EncounterListItemViewModel item in _encounters)
                {
                    item.IsSelected = false;
                }
                encounterItem.IsSelected = true;

                _selectedEncounter = new EncounterViewModel(encounterItem.EncounterModel);
                OnPropertyChanged(nameof(SelectedEncounter));
            }
        }
Ejemplo n.º 15
0
        protected async override void OnAppearing()
        {
            base.OnAppearing();
            encounter = BindingContext as EncounterViewModel;
            Title     = "New Encounter";
            if (encounter.Id != 0)
            {
                await encounter.ReloadData();

                Title = $"Edit: {encounter.Name}";
            }

            encounter.Creatures.CollectionChanged += Creatures_CollectionChanged;
            creatureList.ItemsSource = encounter.Creatures;
        }
Ejemplo n.º 16
0
        public void SetEncounterCreatures(EncounterViewModel encounterView)
        {
            encounterView.EncounterCreatures = EncounterViewModel.creaturesQueue;
            List <EncounterCreature> encounter = EncounterViewModel.encounterCreatures;

            if (encounter.Count > 1)
            {
                encounter.Sort((x, y) => y.Initiative.CompareTo(x.Initiative));
            }
            EncounterViewModel.creaturesQueue.Clear();
            foreach (var x in encounter)
            {
                EncounterViewModel.creaturesQueue.Enqueue(x);
            }
        }
        protected async override void OnAppearing()
        {
            base.OnAppearing();
            encounter = BindingContext as EncounterViewModel;
            await encounter.ReloadData();

            creatureList.ItemsSource = encounter.Creatures;
            Title = encounter.Name;

            prevEncounterExists = App.ResourceManager.EncounterExists(encounter.Id);

            if (!prevEncounterExists)
            {
                continueButton.IsEnabled = false;
                continueButton.IsVisible = false;
            }
        }
Ejemplo n.º 18
0
        // GET: Encounter
        public ActionResult Index()
        {
            EncounterViewModel encounterView = new EncounterViewModel();

            SetEncounterCreatures(encounterView);

            //encounterView.EncounterCreatures = creaturesQueue;
            //List<EncounterCreature> encounter = encounterCreatures;

            //if (encounter.Count > 1)
            //    encounter.Sort((x, y) => y.Initiative.CompareTo(x.Initiative));
            //creaturesQueue.Clear();
            //foreach (var x in encounter)
            //{
            //    creaturesQueue.Enqueue(x);
            //}

            return(View(encounterView));
        }
Ejemplo n.º 19
0
        public bool RemoveEncounter(EncounterViewModel encounter)
        {
            var filePath = Path.Combine(path, encounterDirectory, GetEncounterFileName(encounter.Id));

            if (File.Exists(filePath))
            {
                try
                {
                    File.Delete(filePath);
                }
                catch (IOException e)
                {
                    Crashes.TrackError(e);
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 20
0
        // GET: Encounter/Create
        public async Task <ActionResult> Create()
        {
            var viewModel        = new EncounterViewModel();
            var characterOptions = await _context.Character.Select(ch => new SelectListItem()

            {
                Text  = ch.CharacterName,
                Value = ch.Id.ToString()
            }).ToListAsync();

            var monsterOptions = await _context.Monster.Select(m => new SelectListItem()
            {
                Text  = m.Name,
                Value = m.Id.ToString()
            }).ToListAsync();

            viewModel.CharacterOptions = characterOptions;
            viewModel.MonsterOptions   = monsterOptions;
            return(View(viewModel));
        }
Ejemplo n.º 21
0
        protected override void OnAppearing()
        {
            base.OnAppearing();
            encounter = BindingContext as EncounterViewModel;
            creatureList.ItemsSource = encounter.Creatures;

            // check if a creature has a turn
            var turn = encounter.Creatures.FirstOrDefault((c) => c.HasTurn);

            if (turn == null)
            {
                encounter.Creatures[turnIndex].HasTurn = true;
            }
            else
            {
                turnIndex = encounter.Creatures.IndexOf(turn);
            }

            App.OnSleeping += App_OnSleeping;
        }
Ejemplo n.º 22
0
        private bool SaveEditEncounter()
        {
            bool saved = false;

            if (_encounterEditViewModel.EncounterModel != null)
            {
                _encounterEditViewModel.EncounterModel.Id = _selectedEncounter.EncounterModel.Id;
                _compendium.UpdateEncounter(_encounterEditViewModel.EncounterModel);

                _selectedEncounter = new EncounterViewModel(_encounterEditViewModel.EncounterModel);

                EncounterListItemViewModel oldListItem = _encounters.FirstOrDefault(x => x.EncounterModel.Id == _encounterEditViewModel.EncounterModel.Id);
                if (oldListItem != null)
                {
                    if (_encounterSearchService.SearchInputApplies(_encounterSearchInput, _encounterEditViewModel.EncounterModel))
                    {
                        oldListItem.UpdateModel(_encounterEditViewModel.EncounterModel);
                    }
                    else
                    {
                        _encounters.Remove(oldListItem);
                    }
                }

                _encounterEditViewModel = null;
                _editHasUnsavedChanges  = false;

                SortEncounters();

                _compendium.SaveEncounters();

                OnPropertyChanged(nameof(SelectedEncounter));
                OnPropertyChanged(nameof(EditingEncounter));
                OnPropertyChanged(nameof(IsEditingEncounter));
                OnPropertyChanged(nameof(HasUnsavedChanges));

                saved = true;
            }

            return(saved);
        }
Ejemplo n.º 23
0
        public bool SaveEncounter(EncounterViewModel encounter)
        {
            string json = encounter.ToJson();

            var fileName = GetEncounterFileName(encounter.Id);
            var filePath = Path.Combine(path, encounterDirectory, fileName);

            using (StreamWriter writer = new StreamWriter(filePath, false))
            {
                try
                {
                    writer.Write(json);
                }
                catch (IOException e)
                {
                    Crashes.TrackError(e);
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 24
0
        //[HttpPost]
        public ActionResult SaveCreature(EncounterCreature encounterCreature)
        {
            var encounterView = new EncounterViewModel();

            EncounterViewModel.encounterCreatures.Add(encounterCreature);

            if (EncounterViewModel.creaturesQueue.Count != 0)
            {
                int i = EncounterViewModel.creaturesQueue.Count;
                while (EncounterViewModel.creaturesQueue.Peek().Initiative > encounterCreature.Initiative && i > 0)
                {
                    EncounterViewModel.creaturesQueue.Enqueue(EncounterViewModel.creaturesQueue.Dequeue());
                    i--;
                }
                for (int j = EncounterViewModel.encounterCreatures.Count - i; j > 0; j--)
                {
                    EncounterViewModel.creaturesQueue.Enqueue(EncounterViewModel.creaturesQueue.Dequeue());
                }
            }

            return(RedirectToAction("_EncounterLayout", "Encounter", encounterView));
        }
Ejemplo n.º 25
0
 public ActionResult _EncounterLayout(EncounterViewModel encounterView)
 {
     SetEncounterCreatures(encounterView);
     encounterView.EncounterCreatures = EncounterViewModel.creaturesQueue;
     return(PartialView(encounterView));
 }
Ejemplo n.º 26
0
 public CreatureAddPopup(EncounterViewModel encounter)
 {
     this.encounter = encounter;
     InitializeComponent();
 }
Ejemplo n.º 27
0
 public Encounters()
 {
     InitializeComponent();
     DataContext = new EncounterViewModel();
 }
Ejemplo n.º 28
0
        private void Copy()
        {
            if (_selectedEncounter != null)
            {
                bool copyEncounter = true;

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

                if (copyEncounter)
                {
                    EncounterModel encounterModel = new EncounterModel(_selectedEncounter.EncounterModel);
                    encounterModel.Name += " (copy)";
                    encounterModel.Id    = Guid.NewGuid();

                    _compendium.AddEncounter(encounterModel);

                    if (_encounterSearchService.SearchInputApplies(_encounterSearchInput, encounterModel))
                    {
                        EncounterListItemViewModel listItem = new EncounterListItemViewModel(encounterModel);
                        _encounters.Add(listItem);
                        foreach (EncounterListItemViewModel item in _encounters)
                        {
                            item.IsSelected = false;
                        }
                        listItem.IsSelected = true;
                    }

                    _selectedEncounter = new EncounterViewModel(encounterModel);

                    SortEncounters();

                    _compendium.SaveEncounters();

                    OnPropertyChanged(nameof(SelectedEncounter));
                }
            }
        }