Exemple #1
0
        public void Draw(DevicePanel d)
        {
            if (!d.IsObjectOnScreen(entity.Position.X.High, entity.Position.Y.High, NAME_BOX_WIDTH, NAME_BOX_HEIGHT))
            {
                return;
            }
            Color color        = Selected ? Color.MediumPurple : Color.MediumTurquoise;
            Color color2       = Color.DarkBlue;
            int   Transparency = (Editor.Instance.EditLayer == null) ? 0xff : 0x32;

            int x = entity.Position.X.High;
            int y = entity.Position.Y.High;

            d.DrawRectangle(x, y, x + NAME_BOX_WIDTH, y + NAME_BOX_HEIGHT, Color.FromArgb(Transparency, color));
            d.DrawLine(x, y, x + NAME_BOX_WIDTH, y, Color.FromArgb(Transparency, color2));
            d.DrawLine(x, y, x, y + NAME_BOX_HEIGHT, Color.FromArgb(Transparency, color2));
            d.DrawLine(x, y + NAME_BOX_HEIGHT, x + NAME_BOX_WIDTH, y + NAME_BOX_HEIGHT, Color.FromArgb(Transparency, color2));
            d.DrawLine(x + NAME_BOX_WIDTH, y, x + NAME_BOX_WIDTH, y + NAME_BOX_HEIGHT, Color.FromArgb(Transparency, color2));

            if (Editor.Instance.GetZoom() >= 1)
            {
                d.DrawTextSmall(String.Format("{0} (ID: {1})", entity.Object.Name, entity.SlotID), x + 2, y + 2, NAME_BOX_WIDTH - 4, Color.FromArgb(Transparency, Color.Black), true);
            }
        }
Exemple #2
0
        // allow derived types to override the draw
        public virtual void Draw(DevicePanel d)
        {
            List <string> entityRenderList     = entityRenderingObjects;
            List <string> onScreenExlusionList = renderOnScreenExlusions;

            if (Properties.Settings.Default.DisableRenderExlusions)
            {
                onScreenExlusionList = new List <string>();
            }


            if (filteredOut)
            {
                return;
            }


            if (Properties.Settings.Default.AlwaysRenderObjects == false && !onScreenExlusionList.Contains(entity.Object.Name.Name))
            {
                //This causes some objects not to load ever, which is problamatic, so I made a toggle(and a list as of recently). It can also have some performance benifits
                if (!d.IsObjectOnScreen(entity.Position.X.High, entity.Position.Y.High, NAME_BOX_WIDTH, NAME_BOX_HEIGHT))
                {
                    return;
                }
            }
            System.Drawing.Color color  = Selected ? System.Drawing.Color.MediumPurple : System.Drawing.Color.MediumTurquoise;
            System.Drawing.Color color2 = System.Drawing.Color.DarkBlue;
            if (HasFilter(1) || HasFilter(5))
            {
                color2 = System.Drawing.Color.DarkBlue;
            }
            else if (HasFilter(2))
            {
                color2 = System.Drawing.Color.DarkRed;
            }
            else if (HasFilter(4))
            {
                color2 = System.Drawing.Color.DarkGreen;
            }
            else if (HasFilterOther())
            {
                color2 = System.Drawing.Color.Yellow;
            }

            int Transparency = (Editor.Instance.EditLayer == null) ? 0xff : 0x32;

            if (!Properties.Settings.Default.NeverLoadEntityTextures)
            {
                LoadNextAnimation();
            }
            int    x          = entity.Position.X.High;
            int    y          = entity.Position.Y.High;
            bool   fliph      = false;
            bool   flipv      = false;
            bool   rotate     = false;
            var    offset     = GetRotationFromAttributes(ref fliph, ref flipv, ref rotate);
            string name       = entity.Object.Name.Name;
            var    editorAnim = LoadAnimation2(name, d, -1, -1, fliph, flipv, rotate);

            if (entityRenderList.Contains(name))
            {
                if (!Properties.Settings.Default.NeverLoadEntityTextures)
                {
                    if (d.IsObjectOnScreen(entity.Position.X.High, entity.Position.Y.High, NAME_BOX_WIDTH, NAME_BOX_HEIGHT) || onScreenExlusionList.Contains(entity.Object.Name.Name))
                    {
                        DrawOthers(d);
                    }
                }
            }
            else if (editorAnim != null && editorAnim.Frames.Count > 0)
            {
                // Special cases that always display a set frame(?)
                if (Editor.Instance.ShowAnimations.Enabled == true)
                {
                    if (entity.Object.Name.Name == "StarPost")
                    {
                        index = 1;
                    }
                    //else if (entity.Object.Name.Name == "SpecialRing")
                    //    index = 9;
                }



                // Just incase
                if (index >= editorAnim.Frames.Count)
                {
                    index = 0;
                }
                var frame = editorAnim.Frames[index];

                if (entity.attributesMap.ContainsKey("frameID"))
                {
                    frame = GetFrameFromAttribute(editorAnim, entity.attributesMap["frameID"]);
                }

                if (frame != null)
                {
                    ProcessAnimation(frame.Entry.FrameSpeed, frame.Entry.Frames.Count, frame.Frame.Duration);
                    // Draw the normal filled Rectangle but Its visible if you have the entity selected
                    d.DrawBitmap(frame.Texture, x + frame.Frame.CenterX + ((int)offset.X * frame.Frame.Width), y + frame.Frame.CenterY + ((int)offset.Y * frame.Frame.Height),
                                 frame.Frame.Width, frame.Frame.Height, false, Transparency);
                }
                else
                { // No frame to render
                    d.DrawRectangle(x, y, x + NAME_BOX_WIDTH, y + NAME_BOX_HEIGHT, System.Drawing.Color.FromArgb(Transparency, color));
                }
                // Draws the Special Objects
            }
            else
            {
                if (d.IsObjectOnScreen(entity.Position.X.High, entity.Position.Y.High, NAME_BOX_WIDTH, NAME_BOX_HEIGHT))
                {
                    d.DrawRectangle(x, y, x + NAME_BOX_WIDTH, y + NAME_BOX_HEIGHT, System.Drawing.Color.FromArgb(Transparency, color));
                }
            }

            if (d.IsObjectOnScreen(entity.Position.X.High, entity.Position.Y.High, NAME_BOX_WIDTH, NAME_BOX_HEIGHT))
            {
                d.DrawRectangle(x, y, x + NAME_BOX_WIDTH, y + NAME_BOX_HEIGHT, System.Drawing.Color.FromArgb(Selected ? 0x60 : 0x00, System.Drawing.Color.MediumPurple));
                d.DrawLine(x, y, x + NAME_BOX_WIDTH, y, System.Drawing.Color.FromArgb(Transparency, color2));
                d.DrawLine(x, y, x, y + NAME_BOX_HEIGHT, System.Drawing.Color.FromArgb(Transparency, color2));
                d.DrawLine(x, y + NAME_BOX_HEIGHT, x + NAME_BOX_WIDTH, y + NAME_BOX_HEIGHT, System.Drawing.Color.FromArgb(Transparency, color2));
                d.DrawLine(x + NAME_BOX_WIDTH, y, x + NAME_BOX_WIDTH, y + NAME_BOX_HEIGHT, System.Drawing.Color.FromArgb(Transparency, color2));
                if (Properties.Settings.Default.UseObjectRenderingImprovements == false && entity.Object.Name.Name != "TransportTube")
                {
                    if (Editor.Instance.GetZoom() >= 1)
                    {
                        d.DrawTextSmall(String.Format("{0} (ID: {1})", entity.Object.Name, entity.SlotID), x + 2, y + 2, NAME_BOX_WIDTH - 4, System.Drawing.Color.FromArgb(Transparency, System.Drawing.Color.Black), true);
                    }
                }
                if (entity.Object.Name.Name == "TransportTube")
                {
                    if (Editor.Instance.GetZoom() >= 1)
                    {
                        d.DrawText(String.Format(entity.attributesMap["dirMask"].ValueUInt8.ToString()), x + 2, y + 2, NAME_BOX_WIDTH - 4, System.Drawing.Color.FromArgb(Transparency, System.Drawing.Color.Red), true);
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Loads / Gets the Sprite Animation
        /// NOTE:
        /// </summary>
        /// <param name="name">The Name of the object</param>
        /// <param name="d">The DevicePanel</param>
        /// <param name="AnimId">The Animation ID (-1 to Load Normal)</param>
        /// <param name="frameId">The Frame ID for the specified Animation (-1 to load all frames)</param>
        /// <param name="fliph">Flip the Texture Horizontally</param>
        /// <param name="flipv">Flip the Texture Vertically</param>
        /// <returns>The fully loaded Animation</returns>
        public EditorAnimation LoadAnimation(string name, DevicePanel d, int AnimId, int frameId, bool fliph, bool flipv, bool rotate, bool loadImageToDX = true)
        {
            string key  = $"{name}-{AnimId}-{frameId}-{fliph}-{flipv}-{rotate}";
            var    anim = new EditorAnimation();

            if (Animations.ContainsKey(key))
            {
                if (Animations[key].Ready)
                {
                    // Use the already loaded Amination
                    return(Animations[key]);
                }
                else
                {
                    return(null);
                }
            }

            Animations.Add(key, anim);


            string path, path2;

            if (name == "EditorAssets" || name == "SuperSpecialRing" || name == "EditorIcons2" || name == "TransportTubes")
            {
                if (name == "EditorAssets")
                {
                    path2 = Path.Combine(Environment.CurrentDirectory, "EditorAssets.bin");
                    if (!File.Exists(path2))
                    {
                        return(null);
                    }
                }
                else if (name == "EditorIcons2")
                {
                    path2 = Path.Combine(Environment.CurrentDirectory, "EditorIcons2.bin");
                    if (!File.Exists(path2))
                    {
                        return(null);
                    }
                }
                else if (name == "TransportTubes")
                {
                    path2 = Path.Combine(Environment.CurrentDirectory, "Global\\", "TransportTubes.bin");
                    if (!File.Exists(path2))
                    {
                        return(null);
                    }
                }
                else
                {
                    path2 = Path.Combine(Environment.CurrentDirectory, "Global\\", "SuperSpecialRing.bin");
                    Debug.Print(path2);
                    if (!File.Exists(path2))
                    {
                        return(null);
                    }
                }
            }
            else
            {
                if (DataDirectoryList == null)
                {
                    DataDirectoryList = Directory.GetFiles(Path.Combine(Editor.DataDirectory, "Sprites"), $"*.bin", SearchOption.AllDirectories);
                }


                // Checks Global frist
                path  = Editor.Instance.SelectedZone + "\\" + name + ".bin";
                path2 = Path.Combine(Editor.DataDirectory, "sprites") + '\\' + path;
                if (!File.Exists(path2))
                {
                    // Checks without last character
                    path  = path = Editor.Instance.SelectedZone.Substring(0, Editor.Instance.SelectedZone.Length - 1) + "\\" + name + ".bin";
                    path2 = Path.Combine(Editor.DataDirectory, "sprites") + '\\' + path;
                }

                /*if (!File.Exists(path2))
                 * {
                 *  // Checks Editor Global
                 *  path2 = Environment.CurrentDirectory + "\\Global\\" + name + ".bin";
                 * }*/
                if (!File.Exists(path2))
                {
                    // Checks Global
                    path  = "Global\\" + name + ".bin";
                    path2 = Path.Combine(Editor.DataDirectory, "sprites") + '\\' + path;
                }
                if (!File.Exists(path2))
                {
                    // Checks the Stage folder
                    foreach (string dir in Directory.GetDirectories(Path.Combine(Editor.DataDirectory, "Sprites"), $"*", SearchOption.TopDirectoryOnly))
                    {
                        path  = Path.GetFileName(dir) + "\\" + name + ".bin";
                        path2 = Path.Combine(Editor.DataDirectory, "sprites") + '\\' + path;
                        if (File.Exists(path2))
                        {
                            break;
                        }
                    }
                }
                if (!File.Exists(path2))
                {
                    // Seaches all around the Data directory
                    var list = DataDirectoryList;
                    if (list.Any(t => Path.GetFileName(t.ToLower()).Contains(name.ToLower())))
                    {
                        list = list.Where(t => Path.GetFileName(t.ToLower()).Contains(name.ToLower())).ToArray();
                        if (list.Any(t => t.ToLower().Contains(Editor.Instance.SelectedZone)))
                        {
                            path2 = list.Where(t => t.ToLower().Contains(Editor.Instance.SelectedZone)).First();
                        }
                        else
                        {
                            path2 = list.First();
                        }
                    }
                }
                if (!File.Exists(path2))
                {
                    // No animation found
                    return(null);
                }
            }

            using (var stream = File.OpenRead(path2))
            {
                rsdkAnim = new Animation();
                rsdkAnim.Load(new BinaryReader(stream));
            }
            if (AnimId == -1)
            {
                if (rsdkAnim.Animations.Any(t => t.AnimName.Contains("Normal")))
                {
                    AnimId = rsdkAnim.Animations.FindIndex(t => t.AnimName.Contains("Normal"));
                }
                else
                {
                    AnimId = 0;
                }
                // Use Vertical Amination if one exists
                if (rotate && rsdkAnim.Animations.Any(t => t.AnimName.EndsWith(" V")))
                {
                    AnimId = rsdkAnim.Animations.FindIndex(t => t.AnimName.EndsWith(" V"));
                }
            }
            if (AnimId >= rsdkAnim.Animations.Count)
            {
                AnimId = rsdkAnim.Animations.Count - 1;
            }
            for (int i = 0; i < rsdkAnim.Animations[AnimId].Frames.Count; ++i)
            {
                // check we don't stray outside our loaded animations/frames
                // if user enters a value that would take us there, just show
                // a valid frame instead
                var animiation = rsdkAnim.Animations[AnimId];
                var frame      = animiation.Frames[i];
                if (frameId >= 0 && frameId < animiation.Frames.Count)
                {
                    frame = animiation.Frames[frameId];
                }
                Bitmap map;

                if (!Sheets.ContainsKey(rsdkAnim.SpriteSheets[frame.SpriteSheet]))
                {
                    string targetFile;
                    if (name == "EditorAssets" || name == "SuperSpecialRing" || name == "EditorIcons2" || name == "TransportTubes")
                    {
                        if (name == "EditorAssets")
                        {
                            targetFile = Path.Combine(Environment.CurrentDirectory, "EditorAssets.gif");
                        }
                        else if (name == "EditorIcons2")
                        {
                            targetFile = Path.Combine(Environment.CurrentDirectory, "EditorIcons2.gif");
                        }
                        else if (name == "TransportTubes")
                        {
                            targetFile = Path.Combine(Environment.CurrentDirectory, "Global\\", "TransportTubes.gif");
                        }
                        else
                        {
                            targetFile = Path.Combine(Environment.CurrentDirectory, "Global\\", "SuperSpecialRing.gif");
                        }
                    }
                    else
                    {
                        targetFile = Path.Combine(Editor.DataDirectory, "sprites", rsdkAnim.SpriteSheets[frame.SpriteSheet].Replace('/', '\\'));
                    }
                    if (!File.Exists(targetFile))
                    {
                        map = null;

                        // add a Null to our lookup, so we can avoid looking again in the future
                        Sheets.Add(rsdkAnim.SpriteSheets[frame.SpriteSheet], map);
                    }
                    else
                    {
                        map = new Bitmap(targetFile);
                        Sheets.Add(rsdkAnim.SpriteSheets[frame.SpriteSheet], map);
                    }
                }
                else
                {
                    map = Sheets[rsdkAnim.SpriteSheets[frame.SpriteSheet]];
                }


                if (frame.Width == 0 || frame.Height == 0)
                {
                    continue;
                }

                // can't load the animation, it probably doesn't exist in the User's Sprites folder
                if (map == null)
                {
                    return(null);
                }

                // We are storing the first colour from the palette so we can use it to make sprites transparent
                var colour = map.Palette.Entries[0];
                // Slow
                map = CropImage(map, new Rectangle(frame.X, frame.Y, frame.Width, frame.Height), fliph, flipv);
                RemoveColourImage(map, colour, frame.Width, frame.Height);

                Texture texture = null;
                if (loadImageToDX)
                {
                    texture = TextureCreator.FromBitmap(d._device, map);
                }
                var editorFrame = new EditorAnimation.EditorFrame()
                {
                    Texture = texture,
                    Frame   = frame,
                    Entry   = rsdkAnim.Animations[AnimId]
                };
                if (!loadImageToDX)
                {
                    editorFrame._Bitmap = map;
                }
                anim.Frames.Add(editorFrame);
                if (frameId != -1)
                {
                    break;
                }
            }
            anim.ImageLoaded = true;
            if (loadImageToDX)
            {
                anim.Ready = true;
            }
            Working = false;
            return(anim);
        }