// --------------------------------------------------------------
        #region PUBLIC FUNCTIONS
        // --------------------------------------------------------------

        /// <summary>
        /// Set the images on the picturebox
        /// </summary>
        /// <param name="item">Item to show</param>
        public void SetImages(string GamePath, ItemData item)
        {
            // get the CC image
            Bitmap imageCC = item.GetItemImage(GamePath, false);

            // get the old KR image
            Bitmap imageKR = item.GetItemImage(GamePath, true);

            // draw the images
            imgCC.Image = DirectBitmap.CropImage(imageCC, 10);
            imgKR.Image = DirectBitmap.CropImage(imageKR, 10);

            // re-position the KR image properly
            imgKR.Location = new Point(imgCC.Width, imgKR.Location.Y);

            // get the item flags
            string flags = item.GetAllFlags();

            // set the item data text
            lblItemData.Text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(item.Name.Replace("_", " ")) + "\nID: " + item.ID.ToString() + (item.Properties.ContainsKey(ItemData.TileArtProperties.Animation) ? "\nAnimation: " + item.Properties[ItemData.TileArtProperties.Animation] + "\n(DOUBLE CLICK TO VIEW)\n" + (item.Properties.ContainsKey(ItemData.TileArtProperties.Layer) ? "\nLayer: " + (ItemData.Layers)item.Properties[ItemData.TileArtProperties.Layer] : "") : "") + (flags != string.Empty ? "\nFlags: " + item.GetAllFlags() : "");

            // resize the form
            Size = new Size(Math.Max((imgCC.Image != null ? imgCC.Image.Width : 0) + (imgKR.Image != null ? imgKR.Image.Width : 0) + 1, pnlItemData.Width + 1) + 1, Math.Max(imgCC.Image != null ? imgCC.Image.Height : 0, imgKR.Image != null ? imgKR.Image.Height : 0) + pnlItemData.Height + 4);

            // move the item data at the bottom of the tooltip
            pnlItemData.Location = new Point(0, Size.Height - 2 - pnlItemData.Height + 1);

            // show the tooltip
            Show();
        }
示例#2
0
        // --------------------------------------------------------------
        #region PUBLIC FUNCTIONS
        // --------------------------------------------------------------

        /// <summary>
        /// Create the image for the multi item
        /// </summary>
        /// <param name="gamePath">Game path (used to load the images)</param>
        /// <param name="itemsCache">Reference to the list with all the items</param>
        /// <param name="minZ">Minimum Z to show</param>
        /// <param name="maxZ">Maximum Z to show</param>
        /// <returns>Multi item image</returns>
        public Bitmap GetImage(string gamePath, List <ItemData> itemsCache, Hue h, int minZ = -1, int maxZ = -1)
        {
            // check if a minZ has been specified
            if (minZ == -1 || minZ < MinZ)
            {
                minZ = MinZ;
            }

            // check if a maxZ has been specified
            if (maxZ == -1 || maxZ > MaxZ)
            {
                maxZ = MaxZ;
            }

            // default tile size width
            int tileSize = defaultTileSize.Width;

            // tile size to use to calculate the width
            int widthTileSize = Settings.Default.useOldKRItems ? defaultTileSize.Height : tileSize;

            // calculate the image width
            int width = Math.Max(MaxX * widthTileSize + MaxY * widthTileSize - MinX * widthTileSize - MinY * widthTileSize + 200, 600);

            // calculate the image height
            int height = width * 2;

            // calculate the middle of the canvas
            int halfWidth  = width / 2;
            int halfHeight = height / 2;

            // original maxZ
            int orgMaxZ = MaxZ;

            // too big?
            if (width > 10000 || height > 10000)
            {
                return(null);
            }

            // initialize the final image
            Bitmap final = new Bitmap(width, height);

            // initialize the drawing tool
            using (Graphics g = Graphics.FromImage(final))
            {
                // set the background transparent
                g.Clear(Color.Transparent);

                // get the parts list
                List <MultiItemPart> PartsList = new List <MultiItemPart>(Parts);

                // scan all the parts in the list
                foreach (MultiItemPart p in PartsList)
                {
                    // get the item data
                    ItemData itm = itemsCache.Where(it => it.ID == p.ItemID).FirstOrDefault();

                    // item missing?
                    if (itm == null)
                    {
                        continue;
                    }

                    // the floors with the old KR art tiles are not isometric, so we need to recalculate the positon
                    if (Settings.Default.useOldKRItems && Type == MultiType.House && itm.Flags.HasFlag(ItemData.TileFlag.Surface) && !itm.Flags.HasFlag(ItemData.TileFlag.Bridge) && !itm.Flags.HasFlag(ItemData.TileFlag.StairRight))
                    {
                        p.X -= 1;
                        p.Y -= 1;
                    }

                    // ship mast are drawn incorrectly with the old KR art
                    if (Settings.Default.useOldKRItems && Type == MultiType.Boat && itm.Flags.HasFlag(ItemData.TileFlag.Foliage))
                    {
                        // set the position (based on the mast ID)
                        switch (itm.ID)
                        {
                        case 16093:
                        case 15962:
                        {
                            p.X += 1;
                            p.Y += 1;

                            break;
                        }

                        case 15980:
                        case 16098:
                        {
                            p.X += 2;
                            p.Y += 2;

                            break;
                        }
                        }
                    }

                    // signs need to be drawn higher
                    if (Type == MultiType.House && itm.Flags.HasFlag(ItemData.TileFlag.Transparent) && !itm.Flags.HasFlag(ItemData.TileFlag.Foliage))
                    {
                        p.Z += 5;
                    }

                    // fix the SA ship mast location
                    if (Type == MultiType.Boat && IsSAMast(itm.Flags, itm.Name))
                    {
                        // move the mast higher
                        p.Z = orgMaxZ + (orgMaxZ - p.Z);

                        // make sure the max Z is still correct
                        MaxZ = Math.Max(MaxZ, p.Z);
                    }
                }

                // we draw the image from bottom to top
                for (int z = MinZ; z <= MaxZ; z++)
                {
                    // and from back to front
                    for (int y = MinY; y <= MaxY; y++)
                    {
                        for (int x = MinX; x <= MaxX; x++)
                        {
                            // get the part at the current location
                            List <MultiItemPart> currParts = Parts.Where(pt => pt.X == x && pt.Y == y && pt.Z == z).Where(pt => pt.OriginalZ >= minZ && pt.OriginalZ <= maxZ).ToList();

                            // nothing in this position?
                            if (currParts == null || currParts.Count == 0)
                            {
                                continue;
                            }

                            // put the floors first then the rest
                            currParts = currParts.OrderBy(pt => itemsCache.Where(it => it.ID == pt.ItemID).FirstOrDefault() != null && (!(itemsCache.Where(it => it.ID == pt.ItemID).FirstOrDefault()).Flags.HasFlag(ItemData.TileFlag.Surface) || (itemsCache.Where(it => it.ID == pt.ItemID).FirstOrDefault()).Flags.HasFlag(ItemData.TileFlag.Bridge))).ToList();

                            // draw all the items in this tile
                            foreach (MultiItemPart p in currParts)
                            {
                                // get the item data
                                ItemData itm = itemsCache.Where(it => it.ID == p.ItemID).FirstOrDefault();

                                // missing item?
                                if (itm == null)
                                {
                                    continue;
                                }

                                // calculate where to draw the item
                                Point drawPoint = GetDrawingPosition(p, itm, width, height);

                                // get the cached tile image
                                Bitmap img = itemsImageCache.ContainsKey((int)itm.ID) ? itemsImageCache[(int)itm.ID] : null;

                                // no image in the cache?
                                if (img == null && !itemsImageCache.ContainsKey((int)itm.ID))
                                {
                                    // load the image in the cache
                                    itemsImageCache.Add((int)itm.ID, itm.GetItemImage(gamePath, Settings.Default.useOldKRItems));

                                    // get the image
                                    img = itemsImageCache[(int)itm.ID];
                                }

                                // draw the item image
                                if (img != null)
                                {
                                    // is there a hue selected?
                                    if (h.ID != 0)
                                    {
                                        // for boats we apply the color only to the dyeable parts
                                        if ((Type == MultiType.Boat && itm.Flags.HasFlag(ItemData.TileFlag.PartialHue) && !IsSAMast(itm.Flags, itm.Name)) || Type != MultiType.Boat)
                                        {
                                            // create a temporary image to apply the hue
                                            using (DirectBitmap db = new DirectBitmap(img))
                                            {
                                                // apply the hue
                                                img = db.ApplyHue(h.HueDiagram, itm.Flags.HasFlag(ItemData.TileFlag.PartialHue));
                                            }
                                        }
                                    }

                                    // are we using the old KR items and this is a floor item?
                                    if (Settings.Default.useOldKRItems && itm.Flags.HasFlag(ItemData.TileFlag.Surface) && !itm.Flags.HasFlag(ItemData.TileFlag.Bridge) && !itm.Flags.HasFlag(ItemData.TileFlag.StairRight) && !itm.Flags.HasFlag(ItemData.TileFlag.Container))
                                    {
                                        // kr floors need to be rotated 45°
                                        g.DrawImage(DirectBitmap.RotateImage(img, 45), drawPoint);
                                    }

                                    else // draw the item
                                    {
                                        g.DrawImage(img, drawPoint);
                                    }
                                }

                                // update the form
                                Application.DoEvents();
                            }
                        }
                    }
                }
            }

            return(DirectBitmap.CropImage(final, 50));
        }