Ejemplo n.º 1
0
        /// <summary>
        /// Returns the item as CardSetModelView if it represents a deck. If it represents
        /// a card it returns that card's visual parent which should be a deck.
        /// </summary>
        /// <param name="item"></param>
        public static ICardSetViewItem InferSet(TreeViewItem item, DragEventArgs e = null)
        {
            ITreeViewItem itemData = item.DataContext as ITreeViewItem;

            if (itemData != null && itemData.IsLeaf)
            {
                //this is a child, get its parent
                TreeViewItem parent = GetParentTreeViewItem(item as DependencyObject);

                if (parent == null)
                {
                    return(null);
                }
                ICardSetViewItem set = parent.DataContext as ICardSetViewItem;
                if (set != null && !set.IsLeaf)
                {
                    return(set as ICardSetViewItem);
                }
            }
            else
            {
                //this is a parent, return it
                return(item.DataContext as ICardSetViewItem);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public void SwitchSetOrder(ICardSetViewItem moving, ICardSetViewItem location, bool before = true)
        {
            ValidateSets();
            if (moving == null || location == null)
            {
                return;
            }

            _Sets.Remove(moving as SetViewItem);
            for (int index = 0; index < _Sets.Count; index++)
            {
                if (_Sets[index] == location)
                {
                    if (before)
                    {
                        _Sets.Insert(index, moving as SetViewItem);
                    }
                    else
                    {
                        _Sets.Insert(index + 1, moving as SetViewItem);
                    }
                    return;
                }
            }

            return;
        }
Ejemplo n.º 3
0
        protected void NewCard(object parameter)
        {
            string    templateName = parameter as string;
            ITemplate template     = _Workspace.Game.GetTemplateByName(templateName);

            if (template == null)
            {
                MessageBox.Show("There was an error trying to obtain the template '" + templateName + "'.");
                return;
            }
            ICardSetViewItem cardSet = treeviewSets.SelectedItem as ICardSetViewItem;

            if (cardSet != null)
            {
                ICardViewItem card = new CardViewItem(template);
                cardSet.RegisterCard(card);
                NotifyPropertyChanged("ObservableSets");
                ActiveCard = card; //this will redraw the canvas.
                double x = (canvasWorkspace.ActualWidth / 2) - (ActiveCard.Template.Width / 2);
                double y = (canvasWorkspace.ActualHeight / 2) - (ActiveCard.Template.Height / 2);
                ActiveCard.Template.XPos = x;
                ActiveCard.Template.YPos = y;
                cardSet.IsExpanded       = true;
            }
            else
            {
                MessageBox.Show("You must select a set before you can add a card to it.");
            }
        }
Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 5
0
        public void RemoveSet(ICardSetViewItem set)
        {
            ValidateSets();
            if (set == null)
            {
                return;
            }

            //TODO: All cards in this set must be removed from _Decks as well
            _Sets.Remove(set as SetViewItem);
        }
Ejemplo n.º 6
0
        protected void ReconcileSet(object parameter)
        {
            if (Xceed.Wpf.Toolkit.MessageBox.Show(this,
                                                  "The operation you are about to perform is irreversable.\n" +
                                                  "Any elements that have been removed from their master templates\n" +
                                                  "will likewise be removed from the applicable cards within this set.\n\n" +
                                                  "Click cancel if you do not want this action to be taken.", "WARNING",
                                                  MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.Cancel)
            {
                return;
            }

            //first, we have to determine the set being clicked
            ICardSetViewItem cardSet = treeviewSets.SelectedItem as ICardSetViewItem;

            if (cardSet != null)
            {
                foreach (ICardModel card in cardSet.Cards)
                {
                    //Yucky inner loop
                    foreach (ITemplate template in _Workspace.Game.Templates)
                    {
                        //BUG ALERT: This should match Guids, not names!!!
                        //UPDATE: In fact it should probably fallback to names if Guid can't be found
                        //But a warning message should be provided to the user before hand.
                        //TODO: Make fallback method here
                        if (template.Guid.Equals(card.Template.Guid))
                        {
                            template.ReconcileElementProperties(card.Template as BaseElement);
                        }
                    }

                    //not the most efficient, but certainly the easiest
                    RestoreLayoutView(card);
                }
                NotifyPropertyChanged("ObservableSets");
            }
        }