public void DeleteSelectedSlot()
        {
            if (this.SelectedSlot == null)
            {
                return;
            }

            this.Slots.Remove(this.SelectedSlot);
            this.SelectedSlot = this.Slots.FirstOrDefault();
        }
 public void NewWeapon()
 {
     var weapon = new BackpackWeapon()
     {
         UniqueId = new Random().Next(int.MinValue, int.MaxValue),
         // TODO: check other item unique IDs to prevent rare collisions
         AssetLibrarySetId = 0,
     };
     var viewModel = new BackpackWeaponViewModel(weapon);
     this.Slots.Add(viewModel);
     this.SelectedSlot = viewModel;
 }
        public void NewItem()
        {
            var item = new BackpackItem()
            {
                UniqueId = new Random().Next(int.MinValue, int.MaxValue),
                // TODO: check other item unique IDs to prevent rare collisions
                AssetLibrarySetId = 0,
            };
            var viewModel = new BackpackItemViewModel(item);

            this.Slots.Add(viewModel);
            this.SelectedSlot = viewModel;
        }
        public void DuplicateSelectedSlot()
        {
            if (this.SelectedSlot == null)
            {
                return;
            }

            var copy = (IBackpackSlot)this.SelectedSlot.BackpackSlot.Clone();

            copy.UniqueId = new Random().Next(int.MinValue, int.MaxValue);
            // TODO: check other item unique IDs to prevent rare collisions

            if (copy is BackpackWeapon)
            {
                var weapon = (BackpackWeapon)copy;
                weapon.QuickSlot = QuickWeaponSlot.None;
                weapon.Mark      = PlayerMark.Standard;

                var viewModel = new BackpackWeaponViewModel(weapon);
                this.Slots.Add(viewModel);
                this.SelectedSlot = viewModel;
            }
            else if (copy is BackpackItem)
            {
                var item = (BackpackItem)copy;
                item.Equipped = false;
                item.Mark     = PlayerMark.Standard;

                var viewModel = new BackpackItemViewModel(item);
                this.Slots.Add(viewModel);
                this.SelectedSlot = viewModel;
            }
            else
            {
                throw new NotSupportedException();
            }
        }
        public IEnumerable <IResult> PasteCode()
        {
            bool containsText;
            bool containsUnicodeText = false;

            if (MyClipboard.ContainsText(TextDataFormat.Text, out containsText) != MyClipboard.Result.Success ||
                MyClipboard.ContainsText(TextDataFormat.UnicodeText, out containsUnicodeText) !=
                MyClipboard.Result.Success)
            {
                yield return(new MyMessageBox("Clipboard failure.", "Error")
                             .WithIcon(MessageBoxImage.Error));
            }

            if (containsText == false &&
                containsUnicodeText == false)
            {
                yield break;
            }

            var errors     = 0;
            var viewModels = new List <IBackpackSlotViewModel>();

            yield return(new DelegateResult(() =>
            {
                string codes;
                if (MyClipboard.GetText(out codes) != MyClipboard.Result.Success)
                {
                    MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                // strip whitespace
                codes = Regex.Replace(codes, @"\s+", "");

                foreach (var match in _CodeSignature.Matches(codes).Cast <Match>()
                         .Where(m => m.Success == true))
                {
                    var code = match.Groups["data"].Value;

                    IPackable packable;

                    try
                    {
                        var data = Convert.FromBase64String(code);
                        packable = BackpackDataHelper.Decode(data);
                    }
                    catch (Exception)
                    {
                        errors++;
                        continue;
                    }

                    // TODO: check other item unique IDs to prevent rare collisions
                    packable.UniqueId = new Random().Next(int.MinValue, int.MaxValue);

                    if (packable is BackpackWeapon)
                    {
                        var weapon = (BackpackWeapon)packable;
                        weapon.QuickSlot = QuickWeaponSlot.None;
                        weapon.Mark = PlayerMark.Standard;
                        var viewModel = new BackpackWeaponViewModel(weapon);
                        viewModels.Add(viewModel);
                    }
                    else if (packable is BackpackItem)
                    {
                        var item = (BackpackItem)packable;
                        item.Quantity = 1;
                        item.Equipped = false;
                        item.Mark = PlayerMark.Standard;
                        var viewModel = new BackpackItemViewModel(item);
                        viewModels.Add(viewModel);
                    }
                }
            }));

            if (viewModels.Count > 0)
            {
                viewModels.ForEach(vm => this.Slots.Add(vm));
                this.SelectedSlot = viewModels.First();
            }

            if (errors > 0)
            {
                yield return
                    (new MyMessageBox("Failed to load " + errors.ToString(CultureInfo.InvariantCulture) + " codes.",
                                      "Warning")
                     .WithIcon(MessageBoxImage.Warning));
            }
            else if (viewModels.Count == 0)
            {
                yield return
                    (new MyMessageBox("Did not find any codes in clipboard.",
                                      "Warning")
                     .WithIcon(MessageBoxImage.Warning));
            }
        }
        public void DeleteSelectedSlot()
        {
            if (this.SelectedSlot == null)
            {
                return;
            }

            this.Slots.Remove(this.SelectedSlot);
            this.SelectedSlot = this.Slots.FirstOrDefault();
        }
        public void DuplicateSelectedSlot()
        {
            if (this.SelectedSlot == null)
            {
                return;
            }

            var copy = (IBackpackSlot)this.SelectedSlot.BackpackSlot.Clone();
            copy.UniqueId = new Random().Next(int.MinValue, int.MaxValue);
            // TODO: check other item unique IDs to prevent rare collisions

            if (copy is BackpackWeapon)
            {
                var weapon = (BackpackWeapon)copy;
                weapon.QuickSlot = QuickWeaponSlot.None;
                weapon.Mark = PlayerMark.Standard;

                var viewModel = new BackpackWeaponViewModel(weapon);
                this.Slots.Add(viewModel);
                this.SelectedSlot = viewModel;
            }
            else if (copy is BackpackItem)
            {
                var item = (BackpackItem)copy;
                item.Equipped = false;
                item.Mark = PlayerMark.Standard;

                var viewModel = new BackpackItemViewModel(item);
                this.Slots.Add(viewModel);
                this.SelectedSlot = viewModel;
            }
            else
            {
                throw new NotSupportedException();
            }
        }
        public IEnumerable<IResult> PasteCode()
        {
            bool containsText;
            bool containsUnicodeText = false;
            if (MyClipboard.ContainsText(TextDataFormat.Text, out containsText) != MyClipboard.Result.Success ||
                MyClipboard.ContainsText(TextDataFormat.UnicodeText, out containsUnicodeText) !=
                MyClipboard.Result.Success)
            {
                yield return new MyMessageBox("Clipboard failure.", "Error")
                    .WithIcon(MessageBoxImage.Error);
            }

            if (containsText == false &&
                containsUnicodeText == false)
            {
                yield break;
            }

            var errors = 0;
            var viewModels = new List<IBackpackSlotViewModel>();
            yield return new DelegateResult(() =>
            {
                string codes;
                if (MyClipboard.GetText(out codes) != MyClipboard.Result.Success)
                {
                    MessageBox.Show("Clipboard failure.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                // strip whitespace
                codes = Regex.Replace(codes, @"\s+", "");

                foreach (var match in _CodeSignature.Matches(codes).Cast<Match>()
                    .Where(m => m.Success == true))
                {
                    var code = match.Groups["data"].Value;

                    IPackable packable;

                    try
                    {
                        var data = Convert.FromBase64String(code);
                        packable = BackpackDataHelper.Decode(data);
                    }
                    catch (Exception)
                    {
                        errors++;
                        continue;
                    }

                    // TODO: check other item unique IDs to prevent rare collisions
                    packable.UniqueId = new Random().Next(int.MinValue, int.MaxValue);

                    if (packable is BackpackWeapon)
                    {
                        var weapon = (BackpackWeapon)packable;
                        weapon.QuickSlot = QuickWeaponSlot.None;
                        weapon.Mark = PlayerMark.Standard;
                        var viewModel = new BackpackWeaponViewModel(weapon);
                        viewModels.Add(viewModel);
                    }
                    else if (packable is BackpackItem)
                    {
                        var item = (BackpackItem)packable;
                        item.Quantity = 1;
                        item.Equipped = false;
                        item.Mark = PlayerMark.Standard;
                        var viewModel = new BackpackItemViewModel(item);
                        viewModels.Add(viewModel);
                    }
                }
            });

            if (viewModels.Count > 0)
            {
                viewModels.ForEach(vm => this.Slots.Add(vm));
                this.SelectedSlot = viewModels.First();
            }

            if (errors > 0)
            {
                yield return
                    new MyMessageBox("Failed to load " + errors.ToString(CultureInfo.InvariantCulture) + " codes.",
                                     "Warning")
                        .WithIcon(MessageBoxImage.Warning);
            }
            else if (viewModels.Count == 0)
            {
                yield return
                    new MyMessageBox("Did not find any codes in clipboard.",
                                     "Warning")
                        .WithIcon(MessageBoxImage.Warning);
            }
        }