Beispiel #1
0
 public static void NotifySingle(ViewModelBase viewModel, params String[] properties)
 {
     ViewModelMessenger.NotifySingle(viewModel, properties);
 }
Beispiel #2
0
 public static void Unregister(ViewModelBase viewModel)
 {
     ViewModelMessenger.Unregister(viewModel);
 }
Beispiel #3
0
 public static void NotifyAll(params String[] properties)
 {
     ViewModelMessenger.NotifyAll(properties);
 }
Beispiel #4
0
        public InventoryCreatorViewModel(Character createdCharacter) : base(createdCharacter)
        {
            ShowAddItemDialog    = new Interaction <AddItemViewModel, ItemDataViewModel?>();
            ShowRemoveItemDialog = new Interaction <ConfirmationViewModel, ResultViewModel?>();
            ShowMessageBox       = new Interaction <MessageBoxViewModel, ResultViewModel?>();
            _equipmentItems      = new ObservableCollection <ItemCategory>(createdCharacter.GetInventoryCategories());

            AddItemCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                AddItemViewModel aivm = new AddItemViewModel(CharacterIsClosed);

                ViewModelMessenger.Register(aivm);

                ItemDataViewModel?result = await ShowAddItemDialog.Handle(aivm);

                if (result != null && result.Item != null)
                {
                    IItem itemInstance = result.Item.NewPriceInstance(result.BuyingPrice, result.Count);
                    if (createdCharacter.AddItem(itemInstance, result.IsBuying ? result.BuyingPrice : 0))
                    {
                        AddItemToDisplay(itemInstance);
                        SelectedItem = itemInstance;
                        NotifyEverything();
                        //NotifySingle(this, nameof(DisplayMoney));
                        NotifyOthers(this, "WeaponCombinations");
                    }
                    else
                    {
                        //Window mainWindow = ((IVisual)this).FindAncestorOfType<Window>();
                        //await MessageBox.Show(null, "Postava nemá dostatek peněz na koupi. Chybí " + (result.BuyingPrice - createdCharacter.Money) + ".", "Nedostatek peněz", MessageBox.MessageBoxButtons.Ok);
                        string message = "Postava nemá dostatek peněz na koupi předmětu\"" + result.Item.Name + "\". Chybí " + RuleTables.GetPresentableMoney(result.BuyingPrice - createdCharacter.Money) + ".";
                        var messageBoxStandardWindow = MessageBox.Avalonia.MessageBoxManager.GetMessageBoxStandardWindow("Nedostatek peněz", message);
                        await messageBoxStandardWindow.Show();
                    }
                }

                ViewModelMessenger.Unregister(aivm);
            });

            RemoveItemCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                if (SelectedItem != null)
                {
                    ConfirmationViewModel cnf_vm = new ConfirmationViewModel("Smazat předmět?", "smazat předmět " + SelectedItem.Name);

                    ViewModelMessenger.Register(cnf_vm);

                    ResultViewModel?result = await ShowRemoveItemDialog.Handle(cnf_vm);

                    if (result != null && result.Value)
                    {
                        int sellPrice = createdCharacter.CharacterIsClosed ? 0 : (SelectedItem.Price == null ? 0 : (int)SelectedItem.Price);
                        createdCharacter.RemoveItem(SelectedItem, sellPrice);
                        RemoveItemFromDisplay(SelectedItem);
                        SelectedItem = null;
                        //NotifySingle(this, nameof(DisplayMoney));
                        NotifyEverything();
                        NotifyOthers(this, "WeaponCombinations");
                    }

                    ViewModelMessenger.Unregister(cnf_vm);
                }
            });
        }