protected override void OnSelectedItem(CommandsViewModel item) { base.OnSelectedItem(item); PaletteAnimator.ResetPalette(); PaletteAnimator.PlayAction(item?.Action?.Commands); OnPropertyChanged(nameof(DuplicateCommand)); }
public ActionsViewModel(IEnumerable <CommandsViewModel> list) : base(list) { PaletteAnimator = new PaletteAnimator(); DuplicateCommand = new RelayCommand(x => { var serializer = new XmlSerializer(SelectedItem.Action.GetType()); using (var memStream = new MemoryStream()) { serializer.Serialize(memStream, SelectedItem.Action); memStream.Position = 0; var newItem = serializer.Deserialize(memStream); Items.Add(new CommandsViewModel(newItem as PalAction)); } }, x => IsItemSelected); }
public MainViewModel() { Actions = new ActionsViewModel(); PlayActionCommand = new RelayCommand(x => { PaletteAnimator.ResetPalette(); PaletteAnimator.PlayAction(Actions?.SelectedItem.Action); }, x => true); PlayCommandCommand = new RelayCommand(x => { PaletteAnimator.ResetPalette(); PaletteAnimator.PlayCommand(Actions?.SelectedItem?.SelectedItem?.Command); }, x => true); StopCommand = new RelayCommand(x => { PaletteAnimator.ResetPalette(); PaletteAnimator.PlayAction((PalAction)null); }, x => true); LoadImageCommand = new RelayCommand(x => { var fd = FileDialog.Factory(null, FileDialog.Behavior.Open, FileDialog.Type.ImagePng); if (fd.ShowDialog() == true) { var bitmap = new BitmapImage(new System.Uri(fd.FileName)); if (bitmap.Format == PixelFormats.Indexed8) { PaletteAnimator.LoadPalette(bitmap); Spritesheet = bitmap; } else { MessageBox.Show("The selected image does not contain any palette.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } } }, x => true); }