public PickCardsDialog()
 {
     CardPool = new ObservableCollection<CardModel>();
       CardPoolView = new ListCollectionView(CardPool) { Filter = FilterCard };
       UnlimitedPool = new ObservableCollection<CardModel>();
       UnlimitedPoolView = new ListCollectionView(UnlimitedPool);
       UnlimitedPoolView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
       LimitedDeck = new Deck(Database.OpenedGame);
       CreateFilters();
       InitializeComponent();
 }
 public DeckBuilderWindow()
 {
     Searches = new ObservableCollection<SearchControl>();
     InitializeComponent();
     // If there's only one game in the repository, create a deck of the correct kind
     if (Program.GamesRepository.Games.Count == 1)
     {
         Game = Program.GamesRepository.Games[0];
         Deck = new Deck(Game);
         deckFilename = null;
     }
 }
 public DeckBuilderWindow()
 {
     Searches = new ObservableCollection<SearchControl>();
     InitializeComponent();
     // If there's only one game in the repository, create a deck of the correct kind
     if (Program.GamesRepository.Games.Count == 1)
     {
         Game = Program.GamesRepository.Games[0];
         Deck = new Deck(Game);
         deckFilename = null;
     }
     Version Oversion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
     this.Title = "OCTGN Deck Editor  version " + Oversion;
 }
Example #4
0
 public DeckBuilderWindow()
 {
     Searches = new ObservableCollection<SearchControl>();
     InitializeComponent();
     // If there's only one game in the repository, create a deck of the correct kind
     if (Program.GamesRepository.Games.Count == 1)
     {
         Game = Program.GamesRepository.Games[0];
         Deck = new Deck(Game);
         _deckFilename = null;
     }
     Version oversion = Assembly.GetExecutingAssembly().GetName().Version;
     newSubMenu.ItemsSource = Program.GamesRepository.Games;
     loadSubMenu.ItemsSource = Program.GamesRepository.Games;
     Title = "Octgn Deck Editor  version " + oversion;
 }
Example #5
0
        public DeckBuilderWindow()
        {
            Searches = new ObservableCollection<SearchControl>();
            InitializeComponent();
            // If there's only one game in the repository, create a deck of the correct kind
            if (Program.GamesRepository.Games.Count == 1)
            {
                Game = Program.GamesRepository.Games[0];
                Deck = new Deck(Game);
                _deckFilename = null;
            }
            Version oversion = Assembly.GetExecutingAssembly().GetName().Version;
            newSubMenu.ItemsSource = Program.GamesRepository.Games;
            loadSubMenu.ItemsSource = Program.GamesRepository.Games;
            Title = "Octgn Deck Editor  version " + oversion;

            var deplugins = PluginManager.GetPlugins<IDeckBuilderPlugin>();
            foreach (var p in deplugins)
            {
                try
                {
                    p.OnLoad(Program.GamesRepository);
                    foreach (var m in p.MenuItems)
                    {
                        var mi = new MenuItem() { Header = m.Name };
                        var m1 = m;
                        mi.Click += (sender, args) =>
                            {
                                try
                                {
                                    m1.OnClick(this);
                                }
                                catch (Exception e)
                                {
                                    new ErrorWindow(e).Show();
                                }
                            };
                        MenuPlugins.Items.Add(mi);
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.Message);
                }

            }
        }
 public void LoadDeck(Deck deck)
 {
     LoadedDeck = deck;
 }
Example #7
0
 private void NewDeckCommand(object sender, ExecutedRoutedEventArgs e)
 {
     e.Handled = true;
     if (Game == null)
     {
         if (Program.GamesRepository.Games.Count == 1)
             Game = Program.GamesRepository.Games[0];
         else
         {
             MessageBox.Show("You have to select a game before you can use this command.", "Error",
                             MessageBoxButton.OK);
             return;
         }
     }
     Deck = new Deck(Game);
     _deckFilename = null;
 }
Example #8
0
 private void NewClicked(object sender, RoutedEventArgs e)
 {
     if (_unsaved)
     {
         MessageBoxResult result = MessageBox.Show("This deck contains unsaved modifications. Save?", "Warning",
                                                   MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
         switch (result)
         {
             case MessageBoxResult.Yes:
                 Save();
                 break;
             case MessageBoxResult.No:
                 break;
             default:
                 return;
         }
     }
     Game = (Data.Game) ((MenuItem) e.OriginalSource).DataContext;
     CommandManager.InvalidateRequerySuggested();
     Deck = new Deck(Game);
     _deckFilename = null;
 }
        /// <summary>
        /// This happens when the menu item is clicked.
        /// </summary>
        /// <param name="con"></param>
        public void OnClick(IDeckBuilderPluginController con)
        {
            // Find the first game with cards in it.
            var game = con.Games.Games.FirstOrDefault(x => x.SelectCards(null).Rows.Count > 0);
            if (game == null)
            {
                MessageBox.Show("No Games Installed?!?!?");
                return;
            }
            // Before we make a deck, we need to make sure we load the correct game for the deck.
            con.SetLoadedGame(game);

            // Select a random card from the games card list.
            var cm = game.SelectRandomCardModels(1).FirstOrDefault();
            var d = new Deck(game);

            // It's weird, but this is how you add a card.
            d.Sections[0].Cards.Add(new Deck.Element()
                                        {
                                            Card = cm,
                                            Quantity = (byte)1
                                        });

            // Load that mother.
            con.LoadDeck(d);
        }
 private void NewClicked(object sender, RoutedEventArgs e)
 {
     Game = (Data.Game)((MenuItem)e.OriginalSource).DataContext;
     CommandManager.InvalidateRequerySuggested();
     Deck = new Deck(Game);
     deckFilename = null;
 }
        /// <summary>
        /// Saves the deck.
        /// </summary>
        public void SaveDeck()
        {
            var deck = new Deck(SelectedGame);

            // It's weird, but this is how you add a card.
            var sectionIndex = 0;

            if (IsWarhammerInvasion)
            {
                // Warhammer invasion: Cards are stored in section 1
                sectionIndex = 1;

                // Add selected capital here
                if (_selectedWarhammerInvasionCapital != null)
                {
                    deck.Sections[0].Cards.Add(new Deck.Element()
                        {
                            Quantity = 1,
                            Card = _selectedWarhammerInvasionCapital,
                        });
                }
            }

            foreach (var matched in MatchedCards)
            {
                deck.Sections[sectionIndex].Cards.Add(matched);
            }

            // Load that mother.
            PluginController.LoadDeck(deck);
        }
Example #12
0
        private static Deck LoadCore(XDocument doc, Game game)
        {
            Deck deck;
            try
            {
                var isShared = doc.Root.Attr<bool>("shared");
                IEnumerable<string> defSections = isShared ? game.SharedDeckSections : game.DeckSections;

                deck = new Deck {GameId = game.Id, IsShared = isShared};
                if (doc.Root != null)
                {
                    IEnumerable<Section> sections = from section in doc.Root.Elements("section")
                                                    let xAttribute = section.Attribute("name")
                                                    where xAttribute != null
                                                    select new Section(false)
                                                               {
                                                                   Name = xAttribute.Value,
                                                                   Cards = new ObservableCollection<Element>
                                                                       (from card in section.Elements("card")
                                                                        select new Element
                                                                                   {
                                                                                       LoadedId =
                                                                                           card.Attr<string>("id"),
                                                                                       LoadedName = card.Value,
                                                                                       Quantity =
                                                                                           card.Attr<byte>("qty", 1)
                                                                                   })
                                                               };
                    var allSections = new Section[defSections.Count()];
                    int i = 0;
                    foreach (string sectionName in defSections)
                    {
                        allSections[i] = sections.FirstOrDefault(x => x.Name == sectionName);
                        if (allSections[i] == null) allSections[i] = new Section {Name = sectionName};
                        ++i;
                    }
                    deck.Sections = allSections;
                }
            }
            catch
            {
                throw new InvalidFileFormatException();
            }

            // Matches with actual cards in database
            foreach (Element e in deck.Sections.SelectMany(s => s.Cards))
                try
                {
                    //TODO: This can be done better or in batch. Future implementation idea!
                    // First try by id, if one is provided
                    if (e.LoadedId != null) e.Card = game.GetCardById(new Guid(e.LoadedId));
                    // If there's no id, or if it doesn't match a card in the database, try to fallback on the name
                    if (e.Card == null) e.Card = game.GetCardByName(e.LoadedName);
                    // If we still can't find the card, report an error
                    if (e.Card == null)
                        throw new UnknownCardException(e.LoadedId, e.LoadedName);
                }
                catch (FormatException)
                {
                    throw new InvalidFileFormatException(string.Format("Could not parse card id {0}.",
                                                                       e.LoadedId));
                }
            return deck;
        }
Example #13
0
        private void ConvertMWS()
        {
            GamesRepository mygame = new Octgn.Data.GamesRepository();
            Game game = mygame.Games[gameindex];
            Deck newDeck = new Deck(mygame.Games[gameindex]);
            int i = 0; // Decks have 4 sections. Main = 0, Sideboard = 1, Command Zone = 2, and Plains/Schemes = 3

            TextReader reader = new StreamReader(textBox2.Text);
            string line = "";
            while ((line = reader.ReadLine()) != null)
            {
                i = 0;
                if (line != "")
                {
                    if (!line.Contains("//"))
                    {
                        if (line.Remove(3) == "SB:")
                        {
                            i = 1;
                            line = line.Remove(0, 3);
                        }

                        if ((line.Contains('[')) && (line.Contains(']')))
                        {
                            int count = line.IndexOf('[');
                            line = line.Remove(count, line.IndexOf(']') - count + 1);
                        }

                        line = line.Trim();
                        var quantity = line.Remove(line.IndexOf(' ')).Trim();
                        var name = line.Remove(0, line.IndexOf(' ') + 1).Trim();
                        newDeck.Sections[i].Cards.Add(new Deck.Element { Card = game.GetCardByName(name) ?? game.GetCardByName("Swamp"), Quantity = Convert.ToByte(quantity) });
                    }
                }
            }
            deck = newDeck;
        }
Example #14
0
        private static Deck LoadCore(XDocument doc, Game game)
        {
            Deck deck;
            try
            {
            var isShared = doc.Root.Attr<bool>("shared");
            var defSections = isShared ? game.SharedDeckSections : game.DeckSections;

            deck = new Deck { GameId = game.Id, IsShared = isShared };
                var sections = from section in doc.Root.Elements("section")
                                             select new Section(false)
                                             {
                                                 Name = section.Attribute("name").Value,
                                                 Cards = new ObservableCollection<Element>
                                                                 (from card in section.Elements("card")
                                                                    select new Element
                                                                    {
                                                                        loadedId = card.Attr<string>("id"),
                                                                        loadedName = card.Value,
                                                                        Quantity = card.Attr<byte>("qty", 1)
                                                                    })
                                             };
                Section[] allSections = new Section[defSections.Count()];
                int i = 0;
                foreach (string sectionName in defSections)
                {
                    allSections[i] = sections.FirstOrDefault(x => x.Name == sectionName);
                    if (allSections[i] == null) allSections[i] = new Section { Name = sectionName };
                    ++i;
                }
                deck.Sections = allSections;
            }
            catch
            { throw new InvalidFileFormatException(); }

            bool isDbClosed = !game.IsDatabaseOpen;
            try
            {
                if (isDbClosed)
                    game.OpenDatabase(true);
                // Matches with actual cards in database
                foreach (Section s in deck.Sections)
                    foreach (Element e in s.Cards)
                        try
                        {
                            // First try by id, if one is provided
                            if (e.loadedId != null) e.Card = game.GetCardById(new Guid(e.loadedId));
                            // If there's no id, or if it doesn't match a card in the database, try to fallback on the name
                            if (e.Card == null) e.Card = game.GetCardByName(e.loadedName);
                            // If we still can't find the card, report an error
                            if (e.Card == null)
                                throw new UnknownCardException(e.loadedId, e.loadedName);
                        }
                        catch (FormatException)
                        { throw new InvalidFileFormatException(string.Format("Could not parse card id {0}.", e.loadedId)); }
            }
            finally
            {
                if (isDbClosed)
                    game.CloseDatabase();
            }

            return deck;
        }