Exemplo n.º 1
0
 public EditActor(Actor actor)
 {
     InitializeComponent();
     this.DataContext = actor;
     this.Loaded += EditActor_Loaded;
 }
 private void SetActorInitiativeToCurrent(Actor actor)
 {
     if (CurrentInitiative.HasValue)
     {
         actor.Initiative = CurrentInitiative.Value;
         RefreshActor(actor);
     }
 }
        private void RefreshActor(Actor actor)
        {
            if (actor.IsDelayed || !actor.IsEnabled)
                actor.HasInitiative = false;
            else if (actor.Initiative == CurrentInitiative)
                actor.HasInitiative = true;

            ActorsView.Refresh();
        }
 private void EditActor(Actor actor)
 {
     if (actor != null)
     {
         var editActorWindow = new EditActor(actor);
         editActorWindow.ShowDialog();
         if (actor.Initiative == CurrentInitiative)
             actor.HasInitiative = true;
         ActorsView.Refresh();
     }
 }
        private void DeleteActor(Actor actor)
        {
            if (actor != null
                && MessageBox.Show(string.Format("Are you sure you want to delete {0}", actor.Name),
                                   string.Format("Delete {0}?", actor.Name),
                                   MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                Actors.Remove(actor);
                ActorsView.Refresh();

                if (ActorObservableDisposables.ContainsKey(actor))
                {
                    foreach (var disposable in ActorObservableDisposables[actor])
                        disposable.Dispose();
                    ActorObservableDisposables.Remove(actor);
                }
            }
        }
        private void AddActor()
        {
            var actor = new Actor { Name = string.Format("Actor {0}", ++_ActorNum), Initiative = 0, HasInitiative = false, IsEnabled = true, IsDelayed = false, Notes = string.Empty };
            var editActorWindow = new EditActor(actor);
            editActorWindow.ShowDialog();
            if (!string.IsNullOrWhiteSpace(actor.Name))
            {
                Actors.Add(actor);
                if (actor.Initiative == CurrentInitiative)
                    actor.HasInitiative = true;

                var enabledDisposable = actor.ObservableForProperty(x => x.IsEnabled).Subscribe(x => RefreshActor(x.Sender));
                var delayedDisposable = actor.ObservableForProperty(x => x.IsDelayed).Where(x => !x.Value).Subscribe(x => SetActorInitiativeToCurrent(x.Sender));

                if (!ActorObservableDisposables.ContainsKey(actor))
                    ActorObservableDisposables.Add(actor, new List<IDisposable> { enabledDisposable, delayedDisposable });
                else if (ActorObservableDisposables[actor] == null)
                    ActorObservableDisposables[actor] = new List<IDisposable> { enabledDisposable, delayedDisposable };
                else
                {
                    ActorObservableDisposables[actor].Add(enabledDisposable);
                    ActorObservableDisposables[actor].Add(delayedDisposable);
                }

                ActorsView.Refresh();
            }
        }