Beispiel #1
0
 public void Reset()
 {
     SelectedPlatform = null;
     SelectedPlatforms.Clear();
     SelectedSegue = null;
     SelectedSegues.Clear();
     MapOffset = new Point();
     Degree = 0;
 }
Beispiel #2
0
 private bool segueContains(PlatformSegue segue, Vector2 pos)
 {
     return (segue.Destination - pos).Length() < MapRenderer.SEGUE_DRAW_RADIUS;
 }
Beispiel #3
0
        //Ugly method that handles all mouse down events. Needs to be cleaned
        public void MouseDown(MouseEventArgs e)
        {
            Vector2 pos = editorState.MousePosOnMap(e.Location);
            MapData map = editorState.Map;
            shiftDrag = false;

            if (CurrentActionType == Actions.Move)
            {
                startMapDrag(e);
            }
            else if (CurrentActionType == Actions.Platform)
            {
                draggingPlatform = new PlatformData(pos, Degree);
                draggingItemOffset = new Vector2();
                map.Platforms.Add(draggingPlatform);
            }
            else if (CurrentActionType == Actions.Select)
            {

                if (Control.ModifierKeys != Keys.Control)
                {
                    //set selections to null
                    SelectedPlatform = null;
                    SelectedSegue = null;
                    SelectedPlatforms.Clear();
                    SelectedSegues.Clear();
                }
                draggingPlatform = null;
                draggingSegue = null;

                if (SelectedPlatform == null)
                {
                    foreach (PlatformData platform in map.Platforms)
                    {
                        //check the start "segue" which is really just
                        //the start position of the platform
                        //but you can move that, so it's selectable
                        if (segueContains(platform.StartSegue, pos))
                        {
                            SelectedSegue = platform.StartSegue;
                            draggingSegue = SelectedSegue;
                            break;
                        }
                        //and check all the rest
                        foreach (PlatformSegue segue in platform.segues)
                        {
                            if (segueContains(segue, pos))
                            {
                                SelectedSegue = segue;
                                draggingSegue = SelectedSegue;
                                break;
                            }
                        }
                    }
                }

                //drag the selected segue
                if (draggingSegue != null)
                {
                    draggingItemOffset = SelectedSegue.Destination - pos;
                }
                if (SelectedSegue != null && !SelectedSegues.Contains(SelectedSegue))
                {
                    SelectedSegues.Add(SelectedSegue);
                }

                if (SelectedSegue == null)
                {
                    //look for a platform first
                    foreach (PlatformData platform in map.Platforms)
                    {
                        if (platform.contains(pos, Degree))
                        {
                            SelectedPlatform = platform;
                            draggingPlatform = platform;
                        }
                    }
                    if (SelectedPlatform != null)
                    {
                        SelectedPlatforms.Add(SelectedPlatform);
                        shiftDrag = Control.ModifierKeys == Keys.Shift;
                    }
                }

                //drag the selected platform
                draggingPlatform = SelectedPlatform;
                if (draggingPlatform != null)
                {
                    draggingItemOffset = SelectedPlatform.GetPosition(Degree) - pos;
                }

                //if we're not selecting anything, just drag the map
                if (SelectedPlatform == null && SelectedSegue == null)
                {
                    startMapDrag(e);
                }

                if (SelectedPlatform != null && e.Clicks == 2)
                {
                    draggingPlatform = null;
                    platformDialog.EditorState = editorState;
                    platformDialog.ShowDialog();
                }
            }
            else if (CurrentActionType == Actions.Segue)
            {
                //add a new segue and start dragging it
                if (SelectedPlatform == null) return;
                PlatformSegue segue = null;

                if (CurrentSegueType == Segues.Linear)
                {
                    segue = new PlatformSegueLinear(pos);
                }
                else if (CurrentSegueType == Segues.Curved)
                {
                    segue = new PlatformSegueCurved(pos);
                }

                if (segue == null) return;

                SelectedPlatform.segues.Add(segue);
                draggingSegue = segue;
                draggingItemOffset = new Vector2();
            }
        }
Beispiel #4
0
 public void MouseUp(MouseEventArgs e)
 {
     //just clear dragging variables
     draggingMap = false;
     draggingPlatform = null;
     draggingSegue = null;
 }
Beispiel #5
0
 private void DrawSegue(Graphics g, PlatformSegue segue, Pen pen)
 {
     Point sPos = MapPointOnCanvas(segue.Destination);
     if (editorState.SelectedSegues.Contains(segue))
     {
         if (editorState.SelectedSegue == segue)
         {
             pen = Pens.Red;
         }
         else
         {
             pen = Pens.DarkRed;
         }
     }
     g.DrawEllipse(pen, new Rectangle(sPos.X - SEGUE_DRAW_RADIUS,
         sPos.Y - SEGUE_DRAW_RADIUS,
         SEGUE_DRAW_RADIUS * 2, SEGUE_DRAW_RADIUS * 2));
 }