示例#1
0
 public void Pick(Part part, Cel cel)
 {
     if (part != null)
     {
         if (parts.SelectedItem == part)
         {
             parts_SelectedItemChanged(null, null);
         }
         else
         {
             parts.SelectedItem = part;
         }
     }
     if (cel != null)
     {
         if (cels.SelectedItem == cel)
         {
             cels_SelectedItemChanged(null, null);
         }
         else
         {
             cels.SelectedItem = cel;
         }
         ((Viewer)this.ParentForm).HilightedCel = cel;
     }
     else
     {
         ((Viewer)this.ParentForm).HilightedCel = null;
     }
 }
示例#2
0
        public void Catch(Part held, Cel cel)
        {
            //FIXCATCH: applies to FIXED
            //CATCH: applies to all with a LESS THAN MAX FIX
            //PRESS: always applies
            var fix = held.Fix > 0 ? "fixcatch" : "catch";

            if (RunEvent("{0}|{1}", fix, cel.ID))
            {
                Viewer.DrawScene();
                return;
            }
            else
            {
                if (RunEvent("{0}|{1}", fix, held.ID))
                {
                    Viewer.DrawScene();
                    return;
                }
            }
            if (RunEvent("press|{0}", cel.ID))
            {
                Viewer.DrawScene();
            }
            else
            {
                if (RunEvent("press|{0}", held.ID))
                {
                    Viewer.DrawScene();
                }
            }
        }
示例#3
0
        public Part GetPartFromPoint(Point point, out Cel backCel)
        {
            Part ret = null;

            backCel = null;
            for (var i = Cels.Count; i > 0; i--)
            {
                var cel  = Cels[i - 1];
                var part = cel.Part;

                if (cel.Ghost)
                {
                    continue;
                }
                if (!cel.OnSet)
                {
                    continue;
                }
                if (!cel.Visible)
                {
                    continue;
                }

                var x = point.X - part.Position.X - cel.Offset.X;
                var y = point.Y - part.Position.Y - cel.Offset.Y;
                if (x <= 0 || y <= 0 || x >= cel.Image.Width || y >= cel.Image.Height)
                {
                    continue;
                }
                var color = cel.Image.GetPixel(x, y);
                if (color.A != 0)
                {
                    ret     = part;
                    backCel = cel;
                }
            }
            return(ret);
        }
示例#4
0
        private void Screen_MouseMove(object sender, MouseEventArgs e)
        {
            if (Scene == null)
            {
                return;
            }

            var eX           = e.X / Scene.Zoom;
            var eY           = e.Y / Scene.Zoom;
            var realLocation = new Point(eX, eY);

            if (gridToolStripButton.Checked)
            {
                eX = (eX / 8) * 8;
                eY = (eY / 8) * 8;
            }
            var eLocation = new Point(eX, eY);

            if (held != null)
            {
                held.Position = new Point(eX - heldOffset.X, eY - heldOffset.Y);

                if (held.Position.X < 0)
                {
                    held.Position = new Point(0, held.Position.Y);
                }
                if (held.Position.Y < 0)
                {
                    held.Position = new Point(held.Position.X, 0);
                }
                if (held.Position.X + held.Bounds.Width > Scene.Bitmap.Width)
                {
                    held.Position = new Point(Scene.Bitmap.Width - held.Bounds.Width, held.Position.Y);
                }
                if (held.Position.Y + held.Bounds.Height > Scene.Bitmap.Height)
                {
                    held.Position = new Point(held.Position.X, Scene.Bitmap.Height - held.Bounds.Height);
                }

                if (held.Fix > 0)
                {
                    if (Tools.Distance(fix, held.Position) > FixSnap)
                    {
                        held.Fix--;
                        if (held.Fix == 0)
                        {
                            if (!Scene.RunEvent(string.Format("unfix|{0}", HilightedCel)))
                            {
                                Scene.RunEvent(string.Format("unfix|{0}", held));
                            }
                        }
                        held.Position = new Point(fix.X, fix.Y);
                        held          = null;
                    }
                }
                DrawScene();
                return;
            }

            var cel        = default(Cel);
            var part       = Scene.GetPartFromPoint(realLocation, out cel);
            var statusPart = part;

            if (statusPart == null && HilightedCel != null)
            {
                statusPart = HilightedCel.Part;
            }
            if (statusPart != null && cel != null)
            {
                mainStatusStrip.Items[0].Text  = string.Format("{0} » {1}", statusPart.ID, cel.ID);
                mainStatusStrip.Items[1].Text  = string.Format("{0} by {1}", statusPart.Position.X, statusPart.Position.Y);
                mainStatusStrip.Items[2].Image = (statusPart.Locked || statusPart.Fix > 0) ? refixToolStripMenuItem.Image : unfixToolStripMenuItem.Image;
                mainStatusStrip.Items[3].Text  = statusPart.Fix.ToString();
            }
            else
            {
                mainStatusStrip.Items[0].Text  = mainStatusStrip.Items[1].Text = mainStatusStrip.Items[3].Text = string.Empty;
                mainStatusStrip.Items[2].Image = null;
            }

            if (lastCelPointed != cel)
            {
                if (lastCelPointed != null)
                {
                    if (Scene.RunEvent("mouseout|{0}", lastCelPointed.ID))
                    {
                        DrawScene();
                    }
                    else
                    {
                        if (Scene.RunEvent("mouseout|{0}", lastCelPointed.Part.ID))
                        {
                            DrawScene();
                        }
                    }
                }
                if (cel != null)
                {
                    if (Scene.RunEvent("mousein|{0}", cel.ID))
                    {
                        DrawScene();
                    }
                    else
                    {
                        if (Scene.RunEvent("mousein|{0}", part.ID))
                        {
                            DrawScene();
                        }
                    }
                }
                lastCelPointed = cel;
            }

            if (cel != null && cel is ButtonCel)
            {
                if (lastButton != null && lastButton != cel)
                {
                    lastButton.State = 0;
                }
                if (lastButton != cel)
                {
                    lastButton = (ButtonCel)cel;
                    if (lastButton.State == 0)
                    {
                        lastButton.State = 2;
                        DrawScene();
                    }
                }
            }
            else if (lastButton != null)
            {
                lastButton.State = 0;
                lastButton       = null;
                DrawScene();
            }

            if (part == null)
            {
                if (dragStart == null)
                {
                    activeScreen.Cursor = Cursors.Default;
                }
                else
                {
                    activeScreen.Cursor = Cursors.SizeAll;
                    var dragPoint = screenContainerPanel.PointToClient(screenPictureBox.PointToScreen(realLocation));
                    if (screenContainerPanel.HorizontalScroll.Visible)
                    {
                        var x = -startScroll.X + (dragStart.Value.X - dragPoint.X);
                        var y = -startScroll.Y + (dragStart.Value.Y - dragPoint.Y);
                        screenContainerPanel.AutoScrollPosition = new Point(x, y);
                    }
                }
            }
            else if (part.Locked)
            {
                activeScreen.Cursor = Cursors.Default;
            }
            else
            {
                activeScreen.Cursor = Cursors.Hand;
            }
        }
示例#5
0
        public void Release(Part held, Cel cel)
        {
            //var somethingHappened = false;
            var somethingCollided = false;

            if (held == null)
            {
                if (cel == null)
                {
                    return;
                }
                held = cel.Part;
                if (held == null)
                {
                    return;
                }
            }

            //FIXDROP: applies to FIXED
            //DROP: applies to all with a LESS THAN MAX FIX
            //RELEASE: always applies
            var fix = held.Fix > 0 ? "fixdrop" : "drop";

            if (RunEvent("{0}|{1}", fix, cel.ID))
            {
                Viewer.DrawScene();
                return;
            }
            else
            {
                if (RunEvent("{0}|{1}", fix, held.ID))
                {
                    Viewer.DrawScene();
                    return;
                }
            }
            if (RunEvent("release|{0}", cel.ID))
            {
                Viewer.DrawScene();
                return;
            }
            else
            {
                if (RunEvent("release|{0}", held.ID))
                {
                    Viewer.DrawScene();
                    return;
                }
            }

            foreach (var other in Parts)
            {
                if (other == held)
                {
                    continue;
                }
                if (Tools.Overlap(held.Position, other.Position, held.Bounds, other.Bounds))
                {
                    scriptVariables["#a"] = held.ID;
                    scriptVariables["#b"] = other.ID;
                    var maybe = string.Format("collide|{0}|{1}", held.ID, other.ID);

                    if (!string.IsNullOrWhiteSpace(Viewer.Config.AutoCollide) && other.ID == Viewer.Config.AutoCollide)
                    {
                        Clipboard.SetText(string.Format("((collide \"{0}\" \"{1}\") (moverel {2} {3}))", held.ID, other.ID, held.Position.X - other.Position.X, held.Position.Y - other.Position.Y));
                    }

                    if (Events.ContainsKey(maybe))
                    {
                        if (!Tools.PixelOverlap(held, other))
                        {
                            continue;
                        }

                        if (other == held.LastCollidedWith)
                        {
                            somethingCollided = true;
                            continue;
                        }

                        held.LastCollidedWith = other;
                        somethingCollided     = true;
                        //somethingHappened = true;
                        if (RunEvent(Events[maybe]))
                        {
                            break;
                        }
                    }
                    maybe = string.Format("in|{0}|{1}", held.ID, other.ID);
                    if (Events.ContainsKey(maybe))
                    {
                        if (other == held.LastCollidedWith)
                        {
                            somethingCollided = true;
                            continue;
                        }

                        held.LastCollidedWith = other;
                        somethingCollided     = true;
                        //somethingHappened = true;
                        if (RunEvent(Events[maybe]))
                        {
                            break;
                        }
                    }
                }
            }
            if (!somethingCollided)
            {
                held.LastCollidedWith = null;
            }
            //if (somethingHappened)
            //Viewer.DrawScene();
        }
示例#6
0
        public static bool PixelOverlap(Part oA, Part oB, Cel cA, Cel cB)
        {
            var pA = new Point(oA.Position.X + cA.Offset.X, oA.Position.Y + cA.Offset.Y);
            var pB = new Point(oB.Position.X + cB.Offset.X, oB.Position.Y + cB.Offset.Y);

            try
            {
                if (!Overlap(pA, pB, cA.Image.Size, cB.Image.Size))
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }

            var hitbox1 = new Rectangle(pA, cA.Image.Size);
            var hitbox2 = new Rectangle(pB, cB.Image.Size);

            int top    = Math.Max(hitbox1.Top, hitbox2.Top);
            int bottom = Math.Min(hitbox1.Bottom, hitbox2.Bottom);
            int right  = Math.Max(hitbox1.Right, hitbox2.Right);
            int left   = Math.Min(hitbox1.Left, hitbox2.Left);

            for (var y = top; y < bottom; y++)
            {
                for (var x = left; x < right; x++)
                {
                    var xA = x - hitbox1.Left;
                    var yA = y - hitbox1.Top;
                    var xB = x - hitbox2.Left;
                    var yB = y - hitbox2.Top;

                    if (xA < 0)
                    {
                        continue;
                    }
                    if (xB < 0)
                    {
                        continue;
                    }
                    if (xA >= cA.Image.Width)
                    {
                        continue;
                    }
                    if (xB >= cB.Image.Width)
                    {
                        continue;
                    }

                    var color1 = cA.Image.GetPixel(xA, yA);
                    var color2 = cB.Image.GetPixel(xB, yB);

                    if (color1.A != 0 && color2.A != 0)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#7
0
 public ButtonCel(Scene scene, Cel original) : base(scene)
 {
     glyph = original.Image;
     Image = new Bitmap(glyph.Width + 8, glyph.Height + 8);
 }
示例#8
0
        public Cel ParseCelForm(List <object> celItem)
        {
            Bitmap image     = null;
            var    file      = "";
            var    id        = "";
            var    partof    = "";
            var    alpha     = 255;
            var    positions = new List <object>()
            {
                0, 0
            };
            var offset = new List <object>()
            {
                0, 0
            };
            var on          = defaultOn;    //"0123456789";
            var fix         = 0;
            var newPos      = false;
            var newFix      = false;
            var mapped      = true;
            var ghosted     = false;
            var labelText   = "";
            var labelWidth  = 0;
            var labelFont   = new Font("Tahoma", 8);
            var labelColor  = Color.Black;
            var labelCenter = false;

            var celType = "";

            for (var i = 0; i < celItem.Count; i++)
            {
                var form = celItem[i] as Symbol;
                switch (form)
                {
                case null:
                    break;

                case "file":
                {
                    i++;
                    file = celItem[i] as string;
                    if (id == "")
                    {
                        id = file;
                    }
                    if (partof == "")
                    {
                        partof = id;
                    }
                    celType = "pic";
                }
                break;

                case "label":
                {
                    celType = "label";
                }
                break;

                case "button":
                {
                    i++;
                    file    = celItem[i] as string;
                    celType = "button";
                }
                break;

                case "id":
                {
                    i++;
                    if (partof == id)
                    {
                        partof = "";
                    }
                    id = celItem[i] as string;
                    if (partof == "")
                    {
                        partof = id;
                    }
                }
                break;

                case "partof":
                {
                    i++;
                    partof = celItem[i] as string;
                }
                break;

                case "alpha":
                {
                    i++;
                    alpha = (int)celItem[i];
                }
                break;

                case "pos":
                {
                    i++;
                    positions = celItem[i] as List <object>;
                    newPos    = true;
                }
                break;

                case "offset":
                {
                    i++;
                    offset = celItem[i] as List <object>;
                }
                break;

                case "fix":
                {
                    i++;
                    fix    = (int)celItem[i];
                    newFix = true;
                }
                break;

                case "locked":
                {
                    fix    = MaxFix;
                    newFix = true;
                }
                break;

                case "on":
                {
                    i++;
                    on = celItem[i] as string;
                }
                break;

                case "unmapped":
                {
                    mapped = false;
                }
                break;

                case "ghost":
                {
                    ghosted = true;
                }
                break;

                case "group":
                    break;

                case "text":
                {
                    i++;
                    labelText = celItem[i] as string;
                }
                break;

                case "width":
                {
                    i++;
                    labelWidth = (int)celItem[i];
                }
                break;

                case "color":
                {
                    i++;
                    var bgi = celItem[i] as List <object>;
                    if (bgi.Count == 3 && bgi[0] is int && bgi[1] is int && bgi[2] is int)
                    {
                        labelColor = Color.FromArgb((int)bgi[0], (int)bgi[1], (int)bgi[2]);
                    }
                }
                break;

                case "font":
                {
                    i++;
                    var f = labelFont.Name;
                    var p = labelFont.Size;
                    var s = FontStyle.Regular;
                    if (celItem[i] is string)
                    {
                        f = celItem[i] as string;
                    }
                    else if (celItem[i] is List <object> )
                    {
                        var bgi = celItem[i] as List <object>;
                        f = bgi[0] as string;
                        if (bgi.Count > 1)
                        {
                            p = (int)bgi[1];
                        }
                        if (bgi.Count > 2)
                        {
                            for (var j = 2; j < bgi.Count; j++)
                            {
                                if (bgi[j] is Symbol && (Symbol)bgi[j] == "bold")
                                {
                                    s |= FontStyle.Bold;
                                }
                                if (bgi[j] is Symbol && (Symbol)bgi[j] == "italic")
                                {
                                    s |= FontStyle.Italic;
                                }
                                if (bgi[j] is Symbol && (Symbol)bgi[j] == "center")
                                {
                                    labelCenter = true;
                                }
                            }
                        }
                    }
                    labelFont = new Font(f, p, s);
                }
                break;
                }
            }

            //try to preload the image
            if (celType == "pic" || celType == "button")
            {
                try
                {
                    image = Tools.GrabClonedBitmap(file + ".png", Mix);
                }
                catch (System.IO.FileNotFoundException ex)
                {
                    DarkUI.Forms.DarkMessageBox.ShowWarning(ex.Message, Application.ProductName);
                    return(null);
                }
            }

            //find the partof object
            var part = Parts.FirstOrDefault(o => o.ID == partof);

            if (part == null)
            {
                part = new Part(this)
                {
                    ID   = partof,
                    Cels = new List <Cel>(),
                };
                Parts.Add(part);
            }

            if (newPos)
            {
                if (positions[0] is int)
                {
                    //pos (12 34) --> pos ((12 34))
                    positions = new List <object>()
                    {
                        positions
                    };
                }

                while (positions.Count < 10)
                {
                    positions.Add(positions[0]);
                }

                for (var i = 0; i < 10; i++)
                {
                    if (positions[i] is Symbol && positions[i].ToString() == "*")
                    {
                        if (i == 0)
                        {
                            positions[i] = new List <object>()
                            {
                                0, 0
                            }
                        }
                        ;
                        else
                        {
                            positions[i] = positions[0];
                        }
                    }
                    var pos = positions[i] as List <object>;
                    part.Positions[i] = new Point((int)pos[0], (int)pos[1]);
                    if (pos.Count > 2 && pos[2].ToString() == ">")
                    {
                        pos.RemoveAt(2);
                        for (var j = i + 1; j < 10; j++)
                        {
                            positions[j] = positions[i];
                        }
                    }
                }

                for (var i = 0; i < 10; i++)
                {
                    part.InitialPositions[i] = part.Positions[i];
                }
            }
            if (newFix)
            {
                part.Fix = part.InitialFix = fix;
            }

            var c = new Cel(this)
            {
                Image         = image,
                ImageFilename = file + ".png",
                Visible       = mapped,
                ID            = id,
                Opacity       = alpha,
                Ghost         = ghosted,
            };

            if (celType == "label")
            {
                c = new TextCel(this)
                {
                    Width    = labelWidth,
                    Color    = labelColor,
                    Font     = labelFont,
                    Centered = labelCenter,
                    Visible  = mapped,
                    ID       = id,
                    Opacity  = alpha,
                    Ghost    = ghosted,
                };
                ((TextCel)c).Text = labelText;
                ((TextCel)c).Draw();
            }
            if (celType == "button")
            {
                c = new ButtonCel(this, c)
                {
                    Visible = mapped,
                    ID      = id,
                    Opacity = alpha,
                    Ghost   = ghosted,
                };
                ((ButtonCel)c).Draw();
            }

            foreach (var s in on)
            {
                if (!char.IsDigit(s))
                {
                    continue;
                }
                var i = (int)(s - '0');
                c.OnSets[i] = true;
            }
            c.Offset = new Point((int)offset[0], (int)offset[1]);
            c.Part   = part;
            part.Cels.Add(c);
            part.UpdateBounds();

            Cels.Add(c);
            return(c);
        }