Exemple #1
0
        public override void onUpdate()
        {
            if (WhiskeyControl.InputManager.isNewMouseDown(Whiskey2D.Core.Inputs.MouseButtons.Left))
            {
                Vector mousePos = WhiskeyControl.InputManager.MousePosition;
                mousePos = WhiskeyControl.ActiveCamera.getGameCoordinate(mousePos);

                //check if selection already exists. If so, check for controlPoints

                {
                    Gob.Selected     = null;
                    Gob.Sprite.Color = Color.Transparent;
                    //GameManager.Controller.SelectedGob = null;
                    List <InstanceDescriptor> objs = Gob.CurrentLevel.getInstances();//GameManager.Objects.getAllObjectsNotOfType<EditorGameObject>();


                    float highestDepth = 0;

                    foreach (InstanceDescriptor obj in objs)
                    {
                        if (!obj.Layer.Locked && obj.Layer.Visible)
                        {
                            if (obj.Sprite != null && obj.Bounds.vectorWithin(mousePos) ||
                                new Bounds(obj.Position - Vector.One * 8, Vector.One * 16, 0).vectorWithin(mousePos)


                                || obj == Gob.ControlPointObject && (
                                    Gob.isSelectingControlPoint(mousePos))

                                )
                            {
                                if (obj.Sprite.Depth > highestDepth)
                                {
                                    Gob.Selected           = obj;
                                    highestDepth           = obj.Sprite.Depth;
                                    Gob.ControlPointObject = Gob.Selected;
                                    SelectionManager.Instance.SelectedInstance = obj;
                                }

                                //break;
                            }
                        }
                    }

                    if (Gob.Selected == null)
                    {
                        SelectionManager.Instance.SelectedInstance = null;
                    }
                }
            }



            if (Gob.Selected != null)
            {
                //Sprite clone = new Sprite(Gob.Selected.Sprite);
                // Gob.Sprite = clone;
                Gob.Sprite.Color    = Gob.CurrentLevel.BackgroundColorCompliment;
                Gob.Sprite.Rotation = Gob.Selected.Sprite.Rotation;
                //Color c = Gob.Sprite.Color;
                //c.A = 128;
                //Gob.Sprite.Color = c;

                Gob.Sprite.Depth = Gob.Selected.Sprite.Depth / 2;
                Gob.Position     = Gob.Selected.Position;


                Gob.Sprite.Scale = Gob.Selected.Bounds.Size + new Vector(12);
            }


            else if (Gob.Unselect)
            {
                Gob.Unselect     = false;
                Gob.Sprite.Color = Color.Transparent;
            }
        }
        public override void onUpdate()
        {
            Vector mousePos = WhiskeyControl.InputManager.MousePosition;

            mousePos = WhiskeyControl.ActiveCamera.getGameCoordinate(mousePos);

            mousePos = new Vector((int)mousePos.X, (int)mousePos.Y);

            if (WhiskeyControl.InputManager.isNewMouseDown(Whiskey2D.Core.Inputs.MouseButtons.Left))
            {
                //make sure no control points are being selected
                if (!Gob.isSelectingControlPoint(mousePos))
                {
                    List <InstanceDescriptor> objs = Gob.CurrentLevel.getInstances();

                    float highestDepth = 0f;

                    foreach (InstanceDescriptor obj in objs)
                    {
                        if (!obj.Layer.Locked && obj.Layer.Visible)
                        {
                            if (obj.Sprite != null && obj.Bounds.vectorWithin(mousePos) || new Bounds(obj.Position - Vector.One * 8, Vector.One * 16, 0).vectorWithin(mousePos))
                            {
                                if (obj.Sprite.Depth > highestDepth)
                                {
                                    highestDepth = obj.Sprite.Depth;
                                    Gob.Dragging = obj;
                                    grabOffset   = Gob.Dragging.Position - mousePos;
                                    //break;
                                }
                            }
                        }
                    }
                }
            }



            if (Gob.Dragging != null)
            {
                //WhiskeyControl.Controller.SelectedGob = Gob.Dragging;
                SelectionManager.Instance.SelectedInstance = Gob.Dragging;

                Gob.Dragging.Position = mousePos + grabOffset;

                if (WhiskeyControl.InputManager.isKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift))
                {
                    Vector topLeft = Gob.Dragging.Bounds.TopLeft;
                    topLeft = GridManager.Instance.snap(topLeft);
                    Gob.Dragging.Position = topLeft + Gob.Dragging.Sprite.ScaledOffset;
                }

                Gob.Dragging.X = Gob.Dragging.Position.X;
                Gob.Dragging.Y = Gob.Dragging.Position.Y;

                if (!WhiskeyControl.InputManager.isMouseDown(Whiskey2D.Core.Inputs.MouseButtons.Left))
                {
                    Gob.Dragging = null;
                }
            }
        }