Ejemplo n.º 1
0
        /// <summary>
        /// Gets inventory/equip image for specified item.
        /// Image will be cached based on material and hand for faster subsequent fetches.
        /// Animated item images do not support dyes.
        /// </summary>
        /// <param name="item">Item to fetch image for.</param>
        /// <param name="removeMask">Removes mask index (e.g. around helmets) from final image.</param>
        /// <param name="forPaperDoll">Image is for paper doll.</param>
        /// <param name="allowAnimation">Read animated textures.</param>
        /// <returns>ImageData.</returns>
        public ImageData GetItemImage(DaggerfallUnityItem item, bool removeMask = false, bool forPaperDoll = false, bool allowAnimation = false)
        {
            // Get colour
            int color = (int)item.dyeColor;

            // Get archive and record indices
            int archive = item.InventoryTextureArchive;
            int record  = item.InventoryTextureRecord;

            // Paper doll handling
            if (forPaperDoll)
            {
                // 1H Weapons in right hand need record + 1
                if (item.ItemGroup == ItemGroups.Weapons && item.EquipSlot == EquipSlots.RightHand)
                {
                    if (ItemEquipTable.GetItemHands(item) == ItemHands.Either)
                    {
                        record += 1;
                    }
                }
            }
            else
            {
                // Katanas need +1 for inventory image as they use right-hand image instead of left
                if (item.IsOfTemplate(ItemGroups.Weapons, (int)Weapons.Katana))
                {
                    record += 1;
                }
            }

            // Use world texture archive if inventory texture not set
            // Examples are gold pieces and wayrest painting
            if (archive == 0 && record == 0)
            {
                archive = item.ItemTemplate.worldTextureArchive;
                record  = item.ItemTemplate.worldTextureRecord;
            }

            // Get unique key
            int key = MakeImageKey(color, archive, record, removeMask);

            // Get existing icon if in cache
            if (itemImages.ContainsKey(key))
            {
                return(itemImages[key]);
            }

            // Load image data
            string    filename = TextureFile.IndexToFileName(archive);
            ImageData data     = ImageReader.GetImageData(filename, record, 0, true, false, allowAnimation);

            if (data.type == ImageTypes.None)
            {
                throw new Exception("GetItemImage() could not load image data.");
            }

            // Fix items with known incorrect paper doll offsets
            if (archive == 237 && (record == 52 || record == 54))
            {
                // "Short shirt" template index 202 variants 2 and 5 for human female
                data.offset = new DaggerfallConnect.Utility.DFPosition(237, 43);
            }

            Texture2D tex;

            if (!forPaperDoll && TextureReplacement.TryImportTexture(archive, record, 0, item.dyeColor, out tex))
            {
                // Assign imported texture
                // Paperdoll is disabled for now
                data.texture = tex;
            }
            else
            {
                // Remove mask if requested
                if (removeMask)
                {
                    data.dfBitmap = ImageProcessing.ChangeMask(data.dfBitmap);
                }

                // Change dye or just update texture
                ItemGroups group = item.ItemGroup;
                DyeColors  dye   = (DyeColors)color;
                if (group == ItemGroups.Weapons || group == ItemGroups.Armor)
                {
                    data = ChangeDye(data, dye, DyeTargets.WeaponsAndArmor);
                }
                else if (item.ItemGroup == ItemGroups.MensClothing || item.ItemGroup == ItemGroups.WomensClothing)
                {
                    data = ChangeDye(data, dye, DyeTargets.Clothing);
                }
                else
                {
                    ImageReader.UpdateTexture(ref data);
                }
            }

            // Add to cache
            itemImages.Add(key, data);

            return(data);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets inventory/equip image for specified item.
        /// Image will be cached based on material and hand for faster subsequent fetches.
        /// </summary>
        /// <param name="item">Item to fetch image for.</param>
        /// <param name="removeMask">Removes mask index (e.g. around helmets) from final image.</param>
        /// <param name="forPaperDoll">Image is for paper doll.</param>
        /// <returns>ImageData.</returns>
        public ImageData GetItemImage(DaggerfallUnityItem item, bool removeMask = false, bool forPaperDoll = false)
        {
            // Get colour
            int color = (int)item.dyeColor;

            // Get archive and record indices
            int archive = item.InventoryTextureArchive;
            int record  = item.InventoryTextureRecord;

            // Paper doll handling
            if (forPaperDoll)
            {
                // 1H Weapons in right hand need record + 1
                if (item.ItemGroup == ItemGroups.Weapons && item.EquipSlot == EquipSlots.RightHand)
                {
                    if (ItemEquipTable.GetItemHands(item) == ItemHands.Either)
                    {
                        record += 1;
                    }
                }
            }

            // Get unique key
            int key = MakeImageKey(color, archive, record, removeMask);

            // Get existing icon if in cache
            if (itemImages.ContainsKey(key))
            {
                return(itemImages[key]);
            }

            // Load image data
            string    filename = TextureFile.IndexToFileName(archive);
            ImageData data     = ImageReader.GetImageData(filename, record, 0, true, false);

            if (data.type == ImageTypes.None)
            {
                throw new Exception("GetItemImage() could not load image data.");
            }

            // Remove mask if requested
            if (removeMask)
            {
                data.dfBitmap = ImageProcessing.ChangeMask(data.dfBitmap);
            }

            // Change dye or just update texture
            ItemGroups group = item.ItemGroup;
            DyeColors  dye   = (DyeColors)color;

            if (group == ItemGroups.Weapons || group == ItemGroups.Armor)
            {
                data = ChangeDye(data, dye, DyeTargets.WeaponsAndArmor);
            }
            else if (item.ItemGroup == ItemGroups.MensClothing || item.ItemGroup == ItemGroups.WomensClothing)
            {
                data = ChangeDye(data, dye, DyeTargets.Clothing);
            }
            else
            {
                ImageReader.UpdateTexture(ref data);
            }

            // Add to cache
            itemImages.Add(key, data);

            return(data);
        }