Exemplo n.º 1
0
        private void DeckCardMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (sender == null)
            {
                return;
            }
            var ansc = FindAncestor <Expander>((FrameworkElement)sender);

            if (ansc == null)
            {
                return;
            }

            activeRow   = FindAncestor <DataGridRow>((DependencyObject)e.OriginalSource);
            dragSection = (ObservableSection)ansc.DataContext;
            if (activeRow == null)
            {
                return;
            }
            var getCard = (ICard)activeRow.Item;

            CardSelected(sender, new SearchCardImageEventArgs {
                SetId = getCard.SetId, Image = getCard.ImageUri, CardId = getCard.Id, Alternate = ""
            });
        }
Exemplo n.º 2
0
 private void DeckDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent("Card"))
     {
         _unsaved = true;
         var dragCard = e.Data.GetData("Card") as IMultiCard;
         ObservableSection dropSection = (ObservableSection)((FrameworkElement)sender).DataContext;
         var element = dropSection.Cards.FirstOrDefault(c => c.Id == dragCard.Id);
         if (e.Effects == DragDropEffects.Copy)
         {
             dragCard.Quantity = 1;
         }
         if (element != null)
         {
             element.Quantity = (byte)(element.Quantity + dragCard.Quantity);
         }
         else
         {
             dropSection.Cards.AddCard(dragCard);
             DataGridRow row = FindAncestor <DataGridRow>(e.OriginalSource as FrameworkElement);
             if (row != null && FindAncestor <DataGrid>(row).Items.SortDescriptions.Count == 0) // do not move if no valid target or deck is sorted when dropped
             {
                 dropSection.Cards.Move(dragCard, row.GetIndex());
             }
         }
         removeAdorner();
     }
     e.Handled = true;
 }
Exemplo n.º 3
0
 private void DeckCardMouseDown(object sender, MouseButtonEventArgs e)
 {
     try
     {
         //Hack try catch, this stems from concurrency issues I believe.
         activeCard = FindAncestor <DataGridRow>((DependencyObject)e.OriginalSource);
         if (sender == null)
         {
             return;                 //(from above) Somehow we get a null here
         }
         var ansc = FindAncestor <Expander>((FrameworkElement)sender);
         if (ansc == null)
         {
             return;
         }
         dragSection = (ObservableSection)ansc.DataContext;
         if (activeCard != null)
         {
             int cardIndex = activeCard.GetIndex();
             var getCard   = dragSection.Cards.ElementAt(cardIndex);
             CardSelected(sender, new SearchCardImageEventArgs {
                 SetId = getCard.SetId, Image = getCard.ImageUri, CardId = getCard.Id
             });
         }
     }
     catch (Exception ex)
     {
         Log.Warn("DeckCardMouseDown", ex);
     }
 }
Exemplo n.º 4
0
        public static ObservableSection AsObservable(this ISection section)
        {
            if (section == null)
            {
                return(null);
            }
            var ret = new ObservableSection();

            ret.Name  = section.Name;
            ret.Cards = section.Cards;
            return(ret);
        }
Exemplo n.º 5
0
        public static ObservableSection AsObservable(this ISection section)
        {
            if (section == null)
            {
                return(null);
            }
            var ret = new ObservableSection();

            ret.Name   = section.Name.Clone() as string;
            ret.Cards  = section.Cards.ToArray();
            ret.Shared = section.Shared;
            return(ret);
        }
Exemplo n.º 6
0
 private void DeckCardMouseDown(object sender, MouseButtonEventArgs e)
 {
     activeCard  = FindAncestor <DataGridRow>((DependencyObject)e.OriginalSource);
     dragSection = (ObservableSection)FindAncestor <Expander>((FrameworkElement)sender).DataContext;
     if (activeCard != null)
     {
         int cardIndex = activeCard.GetIndex();
         var getCard   = dragSection.Cards.ElementAt(cardIndex);
         CardSelected(sender, new SearchCardImageEventArgs {
             SetId = getCard.SetId, Image = getCard.ImageUri, CardId = getCard.Id
         });
     }
 }
Exemplo n.º 7
0
 private void DeckDragEnter(object sender, DragEventArgs e)
 {
     if (!e.Data.GetDataPresent("Card"))
     {
         e.Effects = DragDropEffects.None;
     }
     else
     {
         if (e.Effects == DragDropEffects.Copy)
         {
             Expander          exp         = FindAncestor <Expander>(sender as FrameworkElement);
             ObservableSection dropSection = (ObservableSection)((FrameworkElement)exp).DataContext;
             var dragCard = e.Data.GetData("Card") as IMultiCard;
             var element  = dropSection.Cards.FirstOrDefault(c => c.Id == dragCard.Id);
             if (element == null) //i.e. card is not found
             {
                 e.Effects = DragDropEffects.All;
             }
         }
         if (e.Effects == DragDropEffects.All)
         {
             DataGridRow row  = FindAncestor <DataGridRow>(e.OriginalSource as FrameworkElement);
             DataGrid    grid = (DataGrid)FindAncestor <Expander>(e.OriginalSource as FrameworkElement).Content;
             if (row != null)
             {
                 AdornerLayer aLayer = AdornerLayer.GetAdornerLayer(row);
                 removeAdorner();
                 adorner = new DropAdorner(row);
                 adorner.IsHitTestVisible = false;
                 aLayer.Add(adorner);
             }
             else
             {
                 removeAdorner();
                 if (grid != null)
                 {
                     AdornerLayer aLayer = AdornerLayer.GetAdornerLayer(grid);
                     adorner = new DropAdorner(grid, true);
                     adorner.IsHitTestVisible = false;
                     aLayer.Add(adorner);
                 }
             }
         }
     }
 }
Exemplo n.º 8
0
        private void DeckDragEnter(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent("Card"))
            {
                e.Effects = DragDropEffects.None;
            }
            else
            {
                DataGridRow adornedRow = FindAncestor <DataGridRow>(e.OriginalSource as FrameworkElement); // used to place drop adorner
                DataGrid    grid       = (DataGrid)FindAncestor <Expander>(e.OriginalSource as FrameworkElement).Content;

                if (e.Effects == DragDropEffects.Copy)
                {
                    Expander          exp         = FindAncestor <Expander>(sender as FrameworkElement);
                    ObservableSection dropSection = (ObservableSection)((FrameworkElement)exp).DataContext;
                    var dragCard = e.Data.GetData("Card") as IMultiCard;
                    var element  = dropSection.Cards.FirstOrDefault(c => c.Id == dragCard.Id);
                    if (element != null) //i.e. card already in section
                    {
                        // Highlight the existing card
                        adornedRow = grid.ItemContainerGenerator.ContainerFromIndex(grid.Items.IndexOf(element)) as DataGridRow; // Move adorner to existing card
                        adornedRow.BringIntoView();
                        ShowAdorner(adornedRow, true);
                    }
                    else
                    {
                        e.Effects = DragDropEffects.All;
                    }
                }
                if (e.Effects == DragDropEffects.All)
                {
                    if (adornedRow != null && grid.Items.SortDescriptions.Count == 0)
                    {
                        ShowAdorner(adornedRow, false);
                    }
                    else if (grid != null)
                    {
                        ShowAdorner(grid, true);
                    }
                }
            }
        }
Exemplo n.º 9
0
        public override Task <string> LoadAsync(NavigationContext context)
        {
            string sample = context.Parameters.GetValueOrDefault <string>("sample");

            Model = new ListBoxSampleModel()
            {
                Title = Resources.Strings.ResourceManager.GetString(sample)
            };
            switch (sample)
            {
            case ListBoxAddRemoveSampleView.Perspective:
                Model.Description = Resources.Strings.ListBoxAddRemoveSampleDescription;
                Model.Items       = new[]
                {
                    Resources.Strings.Item + " 1",
                    Resources.Strings.Item + " 2"
                };
                break;

            case ListBoxSectioningSampleView.Perspective:
                Model.Description = Resources.Strings.ListBoxSectioningSampleDescription;
                Model.Items       = new ObservableSection <string> [10];
                for (int i = 0; i < Model.Items.Length;)
                {
                    // ObservableSection is a convenience class.  Any class that implements the IList interface will work.
                    var section = new ObservableSection <string>();
                    Model.Items[i] = section;

                    section.HeaderTitle = Resources.Strings.Section + " " + (++i).ToString();
                    for (int j = 0; j < 10;)
                    {
                        section.Items.Add(Resources.Strings.Item + " " + (++j).ToString());
                    }
                }
                ;
                break;
            }

            return(Task.FromResult(sample));
        }
Exemplo n.º 10
0
        public static ObservableDeck AsObservable(this IDeck deck)
        {
            if (deck == null)
            {
                return(null);
            }
            var ret = new ObservableDeck();

            ret.GameId   = deck.GameId;
            ret.IsShared = deck.IsShared;
            ret.Sleeve   = (ISleeve)deck.Sleeve?.Clone();
            if (deck.Sections == null)
            {
                ret.Sections = new List <ObservableSection>();
            }
            else
            {
                ret.Sections = deck.Sections
                               .Where(x => x != null)
                               .Select(
                    x =>
                {
                    var sret  = new ObservableSection();
                    sret.Name = (x.Name ?? "").Clone() as string;
                    if (x.Cards == null)
                    {
                        sret.Cards = new List <ObservableMultiCard>();
                    }
                    else
                    {
                        sret.Cards = x.Cards.Where(y => y != null).Select(y => y.AsObservable()).ToArray();
                    }
                    sret.Shared = x.Shared;
                    return(sret);
                });
            }
            ret.Notes = (deck.Notes ?? "").Clone() as string;
            return(ret);
        }
Exemplo n.º 11
0
 private void DeckDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent("Card"))
     {
         _unsaved = true;
         var dragCard = e.Data.GetData("Card") as IMultiCard;
         ObservableSection dropSection = (ObservableSection)((FrameworkElement)sender).DataContext;
         var element = dropSection.Cards.FirstOrDefault(c => c.Id == dragCard.Id);
         if (e.Effects == DragDropEffects.Copy)
         {
             if (element != null)
             {
                 element.Quantity += 1;
             }
             else
             {
                 dropSection.Cards.AddCard(dragCard);
                 //var card = CardManager.Get().GetCardById(dragCard.Id);
                 //dropSection.Cards.AddCard(card.ToMultiCard());
             }
         }
         else
         {
             if (element != null)
             {
                 element.Quantity = (byte)(element.Quantity + dragCard.Quantity);
             }
             else
             {
                 dropSection.Cards.AddCard(dragCard);
                 //var card = CardManager.Get().GetCardById(dragCard.Id);
                 //dropSection.Cards.AddCard(card.ToMultiCard(dragCard.Quantity));
                 //dropSection.Cards.Add(new Deck.Element { Card = Game.GetCardById(dragCard.Card.Id), Quantity = dragCard.Quantity });
             }
         }
     }
     e.Handled = true;
 }
Exemplo n.º 12
0
        private bool dragging; // stole this unused varriable

        private void DeckCardMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (sender == null)
            {
                return;
            }
            var ansc = FindAncestor <Expander>((FrameworkElement)sender);

            if (ansc == null)
            {
                return;
            }

            activeRow   = FindAncestor <DataGridRow>((DependencyObject)e.OriginalSource);
            dragSection = (ObservableSection)ansc.DataContext;
            //as far as I can tell, the card changes from the ElementSelected 100% of the time already
            //if (activeRow != null)
            //{
            //    int cardIndex = activeRow.GetIndex();
            //    var getCard = dragSection.Cards.ElementAt(cardIndex);
            //    CardSelected(sender, new SearchCardImageEventArgs { SetId = getCard.SetId, Image = getCard.ImageUri, CardId = getCard.Id });
            //}
        }
Exemplo n.º 13
0
 private void DeckCardMouseDown(object sender, MouseButtonEventArgs e)
 {
     activeCard  = FindAncestor <DataGridRow>((DependencyObject)e.OriginalSource);
     dragSection = (ObservableSection)FindAncestor <Expander>((FrameworkElement)sender).DataContext;
 }