コード例 #1
0
        protected void UniqueCopyCard(object parameter)
        {
            if (ActiveCard != null)
            {
                //create new card and move it to a place right after the one that was copied
                ICardViewItem card = ActiveCard.CloneCard(ActiveCard.OwningSet);
                ICardSetModel set  = card.Parent as ICardSetModel;
                set.SwitchCardOrder(card, ActiveCard, false);

                //change name of the cloned card so that the
                //user can easily identify that it is the cloned card
                foreach (ITemplateElement <string> element in card.Template.Children.OfType <ITemplateElement <string> >())
                {
                    if (element.Name.Equals(Card.ElementNameCardBinding))
                    {
                        element.Content = ActiveCard.Name + " (copy)";
                    }
                }

                NotifyPropertyChanged("ObservableSets");
                double x = (canvasWorkspace.ActualWidth / 2) - (card.Template.Width / 2);
                double y = (canvasWorkspace.ActualHeight / 2) - (card.Template.Height / 2);
                card.Template.XPos = x;
                card.Template.YPos = y;
            }
            NotifyPropertyChanged("ObservableSets");
        }
コード例 #2
0
        /// <summary>
        /// Creates an exact copy of this card but for two differences.
        /// It has a newly generated Guid and can be assigned to a new owning set.
        /// This clone is effectively a whole new card with the same template
        /// and element values as the source it was cloned from. There are no links
        /// shared between this card the new clone.
        /// </summary>
        /// <param name="owningSet"></param>
        /// <returns></returns>
        public ICardViewItem CloneCard(ICardSetModel owningSet)
        {
            ICardViewItem card = new CardViewItem(this.Template);

            owningSet.RegisterCard(card);
            return(card);
        }
コード例 #3
0
        private void NewSet(object parameter)
        {
            ICardSetModel set = Workspace.Game.AddSet(Workspace.Game.GetDefaultSetName());

            if (set != null)
            {
                NotifyPropertyChanged("ObservableSets");
            }
        }
コード例 #4
0
        private void CardDropAction(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(ITreeViewItem).Name))
            {
                TreeViewItem  targetItem = sender as TreeViewItem;
                ITreeViewItem target     = targetItem.DataContext as ITreeViewItem;
                ITreeViewItem card       = e.Data.GetData(typeof(ITreeViewItem).Name) as ITreeViewItem;

                //did we drop onto a card or a deck
                ICardModel dropTarget = target as ICardModel;

                ICardSetViewItem setModel = TreeHelper.InferSet(targetItem);
                if (setModel != null && card != null)
                {
                    ICardSetModel set = setModel as ICardSetModel;
                    if (setModel == card.Parent)
                    {
                        //moving within the same set
                        //did we drop on a deck or a card
                        if (dropTarget != null)
                        {
                            if (dropTarget != card as ICardModel)
                            {
                                set.SwitchCardOrder(card as ICardModel, dropTarget, true);
                            }
                        }
                    }
                    else
                    {
                        //moving to a new set - first, move to the set
                        ICardSetModel owner = card.Parent as ICardSetModel;
                        owner.UnregisterCard(card as ICardModel);
                        owner = set as ICardSetModel;
                        owner.RegisterCard(card as ICardModel);

                        //did we drop on a deck or a card - move card within the set
                        if (dropTarget != null)
                        {
                            if (dropTarget != card as ICardModel)
                            {
                                set.SwitchCardOrder(card as ICardModel, dropTarget, true);
                            }
                        }
                    }

                    NotifyPropertyChanged("ObservableSets");
                }
                else
                {
                    MessageBox.Show("There was an error attempting to determine the card or deck during the drag operation.\n " +
                                    "Hell! I don't even know if it was a card or a deck!");
                    return;
                }
            }
        }
コード例 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="deck"></param>
 public void UnregisterWithDeck(ICardSetModel deck)
 {
     if (_Decks == null)
     {
         _Decks = new List <ICardSetModel>();
     }
     if (!_Decks.Contains(deck))
     {
         _Decks.Remove(deck);
     }
 }
コード例 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="deck"></param>
 public void RegisterWithDeck(ICardSetModel deck)
 {
     if (deck == null)
     {
         return;
     }
     if (_Decks == null)
     {
         _Decks = new List <ICardSetModel>();
     }
     if (!_Decks.Contains(deck))
     {
         _Decks.Add(deck);
     }
 }
コード例 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="set"></param>
 public void UnregisterWithSet(ICardSetModel set)
 {
     if (set == _Set)
     {
         //remove this card from all decks
         if (_Decks.Count > 1)
         {
             for (int i = _Decks.Count - 1; i >= 0; i--)
             {
                 _Decks[i].UnregisterCard(this);
             }
         }
         _Set = null;
     }
 }
コード例 #8
0
ファイル: Game.cs プロジェクト: jamClark/Card-Tricks
        public bool RenameSet(ICardSetModel set, string newName)
        {
            ValidateSets();
            if (set == null)
            {
                return(false);
            }
            if (!_Sets.Contains(set))
            {
                throw new InvalidOperationException("The set '" + set.Name + "' does not exist within this game project.");
            }

            //first, make sure the new name isn't invalid
            foreach (ICardSetModel s in _Sets)
            {
                if (s.Name.Equals(newName))
                {
                    throw new InvalidOperationException("A set with the name '" + newName + "' already exists.");
                }
            }

            return(true);
        }
コード例 #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="set"></param>
 public void RegisterWithSet(ICardSetModel set)
 {
     _Set = set;
 }