コード例 #1
0
        /// <param name="Autofill">If true, then when the player picks up an item that can be stored in this bag, it will automatically be stored if there is space for it.</param>
        public BoundedBag(BagType TypeInfo, ContainerSize Size, bool Autofill)
            : base(BagType.GetTranslatedName(TypeInfo), "", Size, TypeInfo.GetIconTexture(), TypeInfo.IconSourceRect, new Vector2(16, 16), 0.5f, 1f)
        {
            this.TypeInfo = TypeInfo;
            this.SizeInfo = TypeInfo.SizeSettings.FirstOrDefault(x => x.Size == Size);
            if (SizeInfo == null) // This should never happen but just in case...
            {
                SizeInfo = TypeInfo.SizeSettings.First();
            }
            this.Autofill = Autofill;

            _MaxStackSize = ItemBagsMod.UserConfig.GetStandardBagCapacity(Size, TypeInfo);

            DescriptionAlias = string.Format("{0}\n({1})",
                                             BagType.GetTranslatedDescription(TypeInfo),
                                             ItemBagsMod.Translate("CapacityDescription", new Dictionary <string, string>()
            {
                { "count", MaxStackSize.ToString() }
            }));

            if (SizeInfo.Size != Size)
            {
                this.AllowedObjects = new ReadOnlyCollection <AllowedObject>(new List <AllowedObject>());
            }
            else
            {
                this.AllowedObjects = new ReadOnlyCollection <AllowedObject>(SizeInfo.Items.Select(x => new AllowedObject(x)).ToList());
            }
            this.ExcludedAutofillItems = new Dictionary <string, HashSet <ObjectQuality> >();
        }
コード例 #2
0
 /// <param name="Autofill">If true, then when the player picks up an item that can be stored in this bag, it will automatically be stored if there is space for it.</param>
 public BoundedBag(BagType TypeInfo, ContainerSize Size, bool Autofill)
     : base(BagType.GetTranslatedName(TypeInfo), "", Size, TypeInfo.GetIconTexture(), TypeInfo.IconSourceRect, new Vector2(16, 16), 0.5f, 1f)
 {
     this.TypeInfo = TypeInfo;
     this.Autofill = Autofill;
     this.ExcludedAutofillItems = new Dictionary <string, HashSet <ObjectQuality> >();
     OnSizeChanged += BoundedBag_OnSizeChanged;
 }
コード例 #3
0
        protected override void LoadSettings(BagInstance Data)
        {
            if (Data != null)
            {
                this.Size     = Data.Size;
                this.Autofill = Data.Autofill;
                this.ExcludedAutofillItems = new Dictionary <string, HashSet <ObjectQuality> >();
                foreach (var KVP in Data.ExcludedAutofillItems)
                {
                    this.ExcludedAutofillItems.Add(KVP.Key, KVP.Value);
                }

                //  Load the type
                this.TypeInfo = ItemBagsMod.BagConfig.BagTypes.FirstOrDefault(x => x.Id == Data.TypeId);
                if (TypeInfo == null)
                {
                    string Warning = string.Format("Warning - no BagType with Id = {0} was found. Did you manually edit your {1} json file or delete a .json file from 'Modded Bags' folder? The saved bag cannot be properly loaded without a corresponding type!"
                                                   + " To prevent crashes, this bag will be automatically converted to a default BagType.", Data.TypeId, ItemBagsMod.BagConfigDataKey);
                    ItemBagsMod.ModInstance.Monitor.Log(Warning, LogLevel.Warn);

                    //  To prevent crashes, convert this bag into a different bag type that exists
                    this.TypeInfo = ItemBagsMod.BagConfig.GetDefaultBoundedBagType();
                }

                //  Load the size configuration
                this.SizeInfo = TypeInfo.SizeSettings.FirstOrDefault(x => x.Size == Size);
                if (SizeInfo == null)
                {
                    string Warning = string.Format("Warning - BagType with Id = {0} does not contain any settings for Size={1}. Did you manually edit your {2} json file?"
                                                   + " The saved bag cannot be properly loaded without the corresponding settings for this size! To prevent crashes, this bag will be automatically converted to a default size for this BagType.",
                                                   this.TypeInfo.Id, this.Size.ToString(), ItemBagsMod.BagConfigDataKey);
                    ItemBagsMod.ModInstance.Monitor.Log(Warning, LogLevel.Warn);

                    this.SizeInfo = TypeInfo.SizeSettings.First();
                }

                _MaxStackSize = ItemBagsMod.UserConfig.GetStandardBagCapacity(Size, TypeInfo);

                this.BaseName    = BagType.GetTranslatedName(TypeInfo);
                DescriptionAlias = string.Format("{0}\n({1})",
                                                 BagType.GetTranslatedDescription(TypeInfo),
                                                 ItemBagsMod.Translate("CapacityDescription", new Dictionary <string, string>()
                {
                    { "count", MaxStackSize.ToString() }
                }));

                if (SizeInfo.Size != Size)
                {
                    this.AllowedObjects = new ReadOnlyCollection <AllowedObject>(new List <AllowedObject>());
                }
                else
                {
                    this.AllowedObjects = new ReadOnlyCollection <AllowedObject>(SizeInfo.Items.Select(x => new AllowedObject(x)).ToList());
                }

                this.Contents.Clear();
                foreach (BagItem Item in Data.Contents)
                {
                    this.Contents.Add(Item.ToObject());
                }

                if (Data.IsCustomIcon)
                {
                    this.Icon = Game1.objectSpriteSheet;
                    this.IconTexturePosition = Data.OverriddenIcon;
                }
                else
                {
                    ResetIcon();
                }
            }
        }