Exemplo n.º 1
0
        public static Inventory <T> CreateGenericInventory()
        {
            // One non-specific pouch
            var pouch = new InventoryPouch <T>(ItemPouchType.FreeSpace);

            return(new Inventory <T>(pouch));
        }
Exemplo n.º 2
0
        private DataGridView GetDGV(InventoryPouch pouch)
        {
            // Add DataGrid
            var dgv = GetBaseDataGrid(pouch);

            // Get Columns
            var item = GetItemColumn(ColumnItem = dgv.Columns.Count);

            dgv.Columns.Add(item);
            dgv.Columns.Add(GetCountColumn(pouch, Main.HaX, ColumnCount = dgv.Columns.Count));
            if (HasFreeSpace)
            {
                dgv.Columns.Add(GetFreeSpaceColumn(ColumnFreeSpace = dgv.Columns.Count));
            }
            if (HasNew)
            {
                dgv.Columns.Add(GetNewColumn(ColumnNEW = dgv.Columns.Count));
            }

            // Populate with rows
            var itemarr = Main.HaX ? itemlist : GetStringsForPouch(pouch.LegalItems);

            item.Items.AddRange(itemarr);

            dgv.Rows.Add(pouch.Items.Length);
            dgv.CancelEdit();

            return(dgv);
        }
Exemplo n.º 3
0
        private static EncounterCount ReadCounts(InventoryPouch pouch)
        {
            var counts = new EncounterCount();

            foreach (var ball in pouch.Items)
            {
                counts.SetCount(ball.Index, ball.Count);
            }
            return(counts);
        }
Exemplo n.º 4
0
        private BallPouchUtil ReadCounts(InventoryPouch pouch)
        {
            var counts = new BallPouchUtil();

            foreach (var ball in pouch.Items)
            {
                counts.SetCount(ball.Index, ball.Count);
            }
            return(counts);
        }
Exemplo n.º 5
0
        private static FossilCount ReadCounts(InventoryPouch pouch)
        {
            var counts = new FossilCount();

            foreach (var item in pouch.Items)
            {
                counts.SetCount(item.Index, item.Count);
            }
            return(counts);
        }
Exemplo n.º 6
0
 private void getBag(DataGridView dgv, InventoryPouch pouch)
 {
     for (int i = 0; i < dgv.Rows.Count; i++)
     {
         int c = 0;
         dgv.Rows[i].Cells[c++].Value = itemlist[pouch.Items[i].Index];
         dgv.Rows[i].Cells[c++].Value = pouch.Items[i].Count;
         if (HasFreeSpace)
             dgv.Rows[i].Cells[c++].Value = pouch.Items[i].FreeSpace;
         if (HasNew)
             dgv.Rows[i].Cells[c].Value = pouch.Items[i].New;
     }
 }
Exemplo n.º 7
0
        private void setBag(DataGridView dgv, InventoryPouch pouch)
        {
            int ctr = 0;

            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                int    c         = 0;
                string item      = dgv.Rows[i].Cells[c++].Value.ToString();
                int    itemindex = Array.IndexOf(itemlist, item);
                if (itemindex <= 0) // Compression of Empty Slots
                {
                    continue;
                }

                int itemcnt;
                int.TryParse(dgv.Rows[i].Cells[c++].Value?.ToString(), out itemcnt);

                if (itemcnt > pouch.MaxCount)
                {
                    if (itemindex == 797 && itemcnt >= 2) // Edge case when for some reason the item count for Z-Ring was 2 in an unedited save and set 1 after using PKHeX
                    {
                        itemcnt = 2;
                    }
                    else
                    {
                        itemcnt = pouch.MaxCount; // Cap at pouch maximum
                    }
                }
                else if (itemcnt <= 0)
                {
                    continue; // ignore item
                }
                pouch.Items[ctr] = new InventoryItem {
                    Index = itemindex, Count = itemcnt
                };
                if (HasFreeSpace)
                {
                    pouch.Items[ctr].FreeSpace = (bool)dgv.Rows[i].Cells[c++].Value;
                }
                if (HasNew)
                {
                    pouch.Items[ctr].New = (bool)dgv.Rows[i].Cells[c].Value;
                }
                ctr++;
            }
            for (int i = ctr; i < pouch.Items.Length; i++)
            {
                pouch.Items[i] = new InventoryItem(); // Empty Slots at the end
            }
        }
Exemplo n.º 8
0
        private static DataGridViewColumn GetCountColumn(InventoryPouch pouch, bool HaX, int c)
        {
            var dgvIndex = new DataGridViewTextBoxColumn
            {
                HeaderText       = "Count",
                DisplayIndex     = c,
                Width            = 45,
                DefaultCellStyle = { Alignment = DataGridViewContentAlignment.MiddleCenter },
            };

            if (!HaX)
            {
                dgvIndex.MaxInputLength = (int)(Math.Log10(Math.Max(1, pouch.MaxCount)) + 1);
            }
            return(dgvIndex);
        }
Exemplo n.º 9
0
 private void GetBag(DataGridView dgv, InventoryPouch pouch)
 {
     for (int i = 0; i < dgv.Rows.Count; i++)
     {
         var cells = dgv.Rows[i].Cells;
         cells[ColumnItem].Value  = itemlist[pouch.Items[i].Index];
         cells[ColumnCount].Value = pouch.Items[i].Count;
         if (HasFreeSpace)
         {
             cells[ColumnFreeSpace].Value = pouch.Items[i].FreeSpace;
         }
         if (HasNew)
         {
             cells[ColumnNEW].Value = pouch.Items[i].New;
         }
     }
 }
Exemplo n.º 10
0
        private void SetBag(DataGridView dgv, InventoryPouch pouch)
        {
            int ctr = 0;

            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                var cells     = dgv.Rows[i].Cells;
                var str       = cells[ColumnItem].Value.ToString();
                var itemindex = Array.IndexOf(itemlist, str);

                if (itemindex <= 0 && !HasNew) // Compression of Empty Slots
                {
                    continue;
                }

                bool result = int.TryParse(cells[ColumnCount].Value?.ToString(), out int itemcnt);
                if (!result)
                {
                    continue;
                }
                if (!pouch.IsValidItemAndCount(SAV, itemindex, HasNew, Main.HaX, ref itemcnt))
                {
                    continue; // ignore item
                }
                // create clean item data when saving
                var obj = new InventoryItem {
                    Index = itemindex, Count = itemcnt
                };
                if (HasFreeSpace)
                {
                    obj.FreeSpace = (bool)cells[ColumnFreeSpace].Value;
                }
                if (HasNew)
                {
                    obj.New = (bool)cells[ColumnNEW].Value;
                }
                pouch.Items[ctr] = obj;
                ctr++;
            }
            for (int i = ctr; i < pouch.Items.Length; i++)
            {
                pouch.Items[i] = new InventoryItem(); // Empty Slots at the end
            }
        }
Exemplo n.º 11
0
        private static int GetMax(ITrainerInfo sav, InventoryPouch pouch, bool haX)
        {
            if (haX)
            {
                return(pouch.MaxCount);
            }

            // Cap at absolute maximum
            if (sav.Generation <= 2)
            {
                return(byte.MaxValue);
            }
            if (sav.Generation >= 7)
            {
                return(pouch.MaxCount);
            }
            // if (SAV.Generation >= 3)
            return(ushort.MaxValue);
        }
Exemplo n.º 12
0
        private void setBag(DataGridView dgv, InventoryPouch pouch)
        {
            int ctr = 0;
            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                int c = 0;
                string item = dgv.Rows[i].Cells[c++].Value.ToString();
                int itemindex = Array.IndexOf(itemlist, item);
                if (itemindex <= 0) // Compression of Empty Slots
                    continue;

                int itemcnt;
                int.TryParse(dgv.Rows[i].Cells[c++].Value?.ToString(), out itemcnt);

                if (Main.HaX && SAV.Generation != 7) // Gen7 has true cap at 1023, keep 999 cap.
                {
                    // Cap at absolute maximum
                    if (SAV.Generation <= 2 && itemcnt > byte.MaxValue)
                        itemcnt = byte.MaxValue;
                    else if (SAV.Generation >= 3 && itemcnt > ushort.MaxValue)
                        itemcnt = ushort.MaxValue;
                }
                else if (itemcnt > pouch.MaxCount)
                {
                    if (itemindex == 797 && itemcnt >= 2) // Edge case when for some reason the item count for Z-Ring was 2 in an unedited save and set 1 after using PKHeX
                        itemcnt = 2;
                    else
                        itemcnt = pouch.MaxCount; // Cap at pouch maximum
                }   
                else if (itemcnt <= 0)
                    continue; // ignore item

                pouch.Items[ctr] = new InventoryItem { Index = itemindex, Count = itemcnt };
                if (HasFreeSpace)
                    pouch.Items[ctr].FreeSpace = (bool)dgv.Rows[i].Cells[c++].Value;
                if (HasNew)
                    pouch.Items[ctr].New = (bool)dgv.Rows[i].Cells[c].Value;
                ctr++;
            }
            for (int i = ctr; i < pouch.Items.Length; i++)
                pouch.Items[i] = new InventoryItem(); // Empty Slots at the end
        }
Exemplo n.º 13
0
        private static DataGridView GetBaseDataGrid(InventoryPouch pouch)
        {
            return(new DataGridView
            {
                Dock = DockStyle.Fill,
                Text = pouch.Type.ToString(),
                Name = "DGV_" + pouch.Type,

                AllowUserToAddRows = false,
                AllowUserToDeleteRows = false,
                AllowUserToResizeRows = false,
                AllowUserToResizeColumns = false,
                RowHeadersVisible = false,
                MultiSelect = false,
                ShowEditingIcon = false,

                EditMode = DataGridViewEditMode.EditOnEnter,
                ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single,
                ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize,
                SelectionMode = DataGridViewSelectionMode.CellSelect,
                CellBorderStyle = DataGridViewCellBorderStyle.None,
            });
        }
Exemplo n.º 14
0
        private static bool GetModifySettings(InventoryPouch pouch, out bool truncate, out bool shuffle)
        {
            truncate = false;
            shuffle  = false;
            if (!pouch.IsCramped)
            {
                return(true);
            }

            var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgItemPouchSizeSmall,
                                         string.Format(MsgItemPouchRandom, Environment.NewLine));

            if (dr == DialogResult.Cancel)
            {
                return(false);
            }
            truncate = true;
            if (dr == DialogResult.No)
            {
                shuffle = true;
            }

            return(true);
        }
Exemplo n.º 15
0
        private DataGridView GetDGV(InventoryPouch pouch)
        {
            // Add DataGrid
            DataGridView dgv = new DataGridView
            {
                Dock = DockStyle.Fill,
                Text = pouch.Type.ToString(),
                Name = DGVPrefix + pouch.Type,

                AllowUserToAddRows       = false,
                AllowUserToDeleteRows    = false,
                AllowUserToResizeRows    = false,
                AllowUserToResizeColumns = false,
                RowHeadersVisible        = false,
                //ColumnHeadersVisible = false,
                MultiSelect     = false,
                ShowEditingIcon = false,

                EditMode = DataGridViewEditMode.EditOnEnter,
                ColumnHeadersBorderStyle    = DataGridViewHeaderBorderStyle.Single,
                ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize,
                SelectionMode   = DataGridViewSelectionMode.CellSelect,
                CellBorderStyle = DataGridViewCellBorderStyle.None,
            };

            int c = 0;
            DataGridViewComboBoxColumn dgvItemVal = new DataGridViewComboBoxColumn
            {
                HeaderText   = "Item",
                DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
                DisplayIndex = c++,
                Width        = 135,
                FlatStyle    = FlatStyle.Flat
            };
            DataGridViewColumn dgvIndex = new DataGridViewTextBoxColumn();

            {
                dgvIndex.HeaderText   = "Count";
                dgvIndex.DisplayIndex = c++;
                dgvIndex.Width        = 45;
                dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                if (!Main.HaX)
                {
                    ((DataGridViewTextBoxColumn)dgvIndex).MaxInputLength = (int)(Math.Log10(Math.Max(1, pouch.MaxCount)) + 1);
                }
            }

            dgv.Columns.Add(dgvItemVal);
            dgv.Columns.Add(dgvIndex);

            if (HasFreeSpace)
            {
                DataGridViewCheckBoxColumn dgvFree = new DataGridViewCheckBoxColumn
                {
                    HeaderText   = "Free",
                    DisplayIndex = c++,
                    Width        = 40,
                    FlatStyle    = FlatStyle.Flat
                };
                dgv.Columns.Add(dgvFree);
            }
            if (HasNew)
            {
                DataGridViewCheckBoxColumn dgvNew = new DataGridViewCheckBoxColumn
                {
                    HeaderText   = "NEW",
                    DisplayIndex = c++,
                    Width        = 40,
                    FlatStyle    = FlatStyle.Flat
                };
                dgv.Columns.Add(dgvNew);
            }

            var itemcount = pouch.Items.Length;

            string[] itemarr = Main.HaX ? (string[])itemlist.Clone() : GetItems(pouch.LegalItems);

            var combo = dgv.Columns[0] as DataGridViewComboBoxColumn;

            foreach (string t in itemarr)
            {
                combo.Items.Add(t); // add only the Item Names
            }
            dgv.Rows.Add(itemcount > 0 ? itemcount : itemarr.Length);
            dgv.CancelEdit();

            return(dgv);
        }
Exemplo n.º 16
0
        public bool TryGetPouch(ItemType item, out InventoryPouch <T> pouch)
        {
            ItemPouchType pt = ItemData.GetPouchType(item);

            return(_pouches.TryGetValue(pt, out pouch));
        }
Exemplo n.º 17
0
 public bool TryGetValue(ItemPouchType key, out InventoryPouch <T> value)
 {
     return(_pouches.TryGetValue(key, out value));
 }