Exemplo n.º 1
0
        public override void Render()
        {
            UpdateMouse();
            Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, null, Camera.Matrix * Engine.ScreenMatrix);
            float num  = 1920f / Camera.Zoom;
            float num2 = 1080f / Camera.Zoom;
            int   num3 = 5;
            float num4 = (float)Math.Floor(Camera.Left / num3 - 1f) * num3;
            float num5 = (float)Math.Floor(Camera.Top / num3 - 1f) * num3;

            for (float num6 = num4; num6 <= num4 + num + 10f; num6 += 5f)
            {
                Draw.Line(num6, Camera.Top, num6, Camera.Top + num2, gridColor);
            }
            for (float num7 = num5; num7 <= num5 + num2 + 10f; num7 += 5f)
            {
                Draw.Line(Camera.Left, num7, Camera.Left + num, num7, gridColor);
            }
            Draw.Line(0f, Camera.Top, 0f, Camera.Top + num2, Color.DarkSlateBlue, 1f / Camera.Zoom);
            Draw.Line(Camera.Left, 0f, Camera.Left + num, 0f, Color.DarkSlateBlue, 1f / Camera.Zoom);

            foreach (BoardSpaceTemplate src in connections.Keys)
            {
                foreach (BoardSpaceTemplate dest in connections[src])
                {
                    DrawArrow(src.Position, dest.Position);
                }
            }

            // Draw line for current path being built
            if (MInput.Keyboard.Check(Keys.P))
            {
                BoardSpaceTemplate pathDest = TestCheck(mousePosition);
                BoardSpaceTemplate pathSrc;
                if (selection.Count == 1 && (pathSrc = selection.First()) != pathDest)
                {
                    DrawArrow(pathSrc.Position, pathDest?.Position ?? mousePosition);
                }
            }

            foreach (BoardSpaceTemplate space in spaces)
            {
                space.Render(Camera);
            }
            if (mouseMode == MouseModes.Hover)
            {
                Draw.Line(mousePosition.X - 12f / Camera.Zoom, mousePosition.Y, mousePosition.X + 12f / Camera.Zoom, mousePosition.Y, Color.Yellow, 3f / Camera.Zoom);
                Draw.Line(mousePosition.X, mousePosition.Y - 12f / Camera.Zoom, mousePosition.X, mousePosition.Y + 12f / Camera.Zoom, Color.Yellow, 3f / Camera.Zoom);
            }
            else if (mouseMode == MouseModes.Select)
            {
                Draw.Rect(GetMouseRect(mouseDragStart, mousePosition), Color.Lime * 0.25f);
            }
            if (saveFlash > 0f)
            {
                Draw.Rect(Camera.Left, Camera.Top, num, num2, Color.White * Ease.CubeInOut(saveFlash));
            }
            if (fade > 0f)
            {
                Draw.Rect(0f, 0f, 320f, 180f, Color.Black * fade);
            }
            Draw.SpriteBatch.End();
            Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullNone, null, Engine.ScreenMatrix);
            Draw.Rect(0f, 0f, 1920f, 72f, Color.Black);
            Vector2 position  = new Vector2(16f, 4f);
            Vector2 position2 = new Vector2(1904f, 4f);

            if (hovered.Count == 0)
            {
                if (selection.Count > 0)
                {
                    ActiveFont.Draw(selection.Count + " spaces selected", position, Color.Red);
                }
                else
                {
                    ActiveFont.Draw("Hello", position, Color.Aqua);
                }
            }
            else if (hovered.Count == 1)
            {
                BoardSpaceTemplate levelTemplate = null;
                using (HashSet <BoardSpaceTemplate> .Enumerator enumerator2 = hovered.GetEnumerator()) {
                    if (enumerator2.MoveNext())
                    {
                        levelTemplate = enumerator2.Current;
                    }
                }
                string text = levelTemplate.X + "," + levelTemplate.Y + "   " + levelTemplate.Type + "   " + levelTemplate.HeartSpace;
                if (selection.Count > 0)
                {
                    ActiveFont.Draw(selection.Count + " spaces selected", position, Color.Red);
                }
                else
                {
                    ActiveFont.Draw("Hello", position, Color.Aqua);
                }
                ActiveFont.Draw(text, position2, Vector2.UnitX, Vector2.One, Color.Green);
            }
            else
            {
                ActiveFont.Draw(hovered.Count + " spaces", position, Color.Yellow);
            }
            Draw.SpriteBatch.End();
            RenderManualText();
        }
Exemplo n.º 2
0
        public override void Update()
        {
            MakeMapEditorBetter();
            Vector2 vector = default(Vector2);

            vector.X = (lastMouseScreenPosition.X - MInput.Mouse.Position.X) / Camera.Zoom;
            vector.Y = (lastMouseScreenPosition.Y - MInput.Mouse.Position.Y) / Camera.Zoom;
            if (MInput.Keyboard.Pressed(Keys.Space) && MInput.Keyboard.Check(Keys.LeftControl))
            {
                Camera.Zoom     = 6f;
                Camera.Position = Vector2.Zero;
            }
            int zoomDir = Math.Sign(MInput.Mouse.WheelDelta);

            if ((zoomDir > 0 && Camera.Zoom >= 1f) || Camera.Zoom > 1f)
            {
                Camera.Zoom += zoomDir;
            }
            else
            {
                Camera.Zoom += zoomDir * 0.25f;
            }
            Camera.Zoom      = Math.Max(0.25f, Math.Min(24f, Camera.Zoom));
            Camera.Position += new Vector2(Input.MoveX.Value, Input.MoveY.Value) * 300f * Engine.DeltaTime;
            UpdateMouse();
            hovered.Clear();
            if (mouseMode == MouseModes.Hover)
            {
                mouseDragStart = mousePosition;
                if (MInput.Mouse.PressedLeftButton)
                {
                    bool flag = LevelCheck(mousePosition);
                    if (MInput.Keyboard.Check(Keys.Space))
                    {
                        mouseMode = MouseModes.Pan;
                    }
                    else if (MInput.Keyboard.Check(Keys.P))
                    {
                        BoardSpaceTemplate pathDest = TestCheck(mousePosition);
                        BoardSpaceTemplate pathSrc;
                        if (pathDest != null && selection.Count == 1 && (pathSrc = selection.First()) != pathDest)
                        {
                            if (!connections.ContainsKey(pathSrc))
                            {
                                connections[pathSrc] = new HashSet <BoardSpaceTemplate>();
                            }
                            if (connections[pathSrc].Contains(pathDest))
                            {
                                connections[pathSrc].Remove(pathDest);
                            }
                            else
                            {
                                connections[pathSrc].Add(pathDest);
                            }
                            selection.Clear();
                            selection.Add(pathDest);
                        }
                    }
                    else if (MInput.Keyboard.Check(Keys.LeftControl))
                    {
                        if (flag)
                        {
                            ToggleSelection(mousePosition);
                        }
                        else
                        {
                            mouseMode = MouseModes.Select;
                        }
                    }
                    else if (MInput.Keyboard.Check(Keys.N))
                    {
                        spaces.Add(new BoardSpaceTemplate(new BoardSpace {
                            x = (int)mousePosition.X / 2, y = (int)mousePosition.Y / 2, type = 'b'
                        }));
                    }
                    else if (flag)
                    {
                        if (!SelectionCheck(mousePosition))
                        {
                            SetSelection(mousePosition);
                        }

                        StoreUndo();
                        foreach (BoardSpaceTemplate item3 in selection)
                        {
                            item3.StartMoving();
                        }
                        mouseMode = MouseModes.Move;
                    }
                    else
                    {
                        mouseMode = MouseModes.Select;
                    }
                }
                else if (MInput.Mouse.PressedRightButton)
                {
                    BoardSpaceTemplate space = TestCheck(mousePosition);
                    if (space != null)
                    {
                        if (MInput.Keyboard.Check(Keys.N))
                        {
                            spaces.Remove(space);
                        }
                        return;
                    }
                }
                else if (MInput.Mouse.PressedMiddleButton)
                {
                    mouseMode = MouseModes.Pan;
                }
                else if (!MInput.Keyboard.Check(Keys.Space))
                {
                    foreach (BoardSpaceTemplate space in spaces)
                    {
                        if (space.Check(mousePosition))
                        {
                            hovered.Add(space);
                        }
                    }
                    if (MInput.Keyboard.Check(Keys.LeftControl))
                    {
                        if (MInput.Keyboard.Pressed(Keys.Z))
                        {
                            Undo();
                        }
                        else if (MInput.Keyboard.Pressed(Keys.Y) || (MInput.Keyboard.Check(Keys.LeftShift) && MInput.Keyboard.Pressed(Keys.Z)))
                        {
                            Redo();
                        }
                        else if (MInput.Keyboard.Pressed(Keys.A))
                        {
                            SelectAll();
                        }
                    }

                    if (MInput.Keyboard.Check(Keys.Delete))
                    {
                        DeleteSelected();
                    }
                }
            }
            else if (mouseMode == MouseModes.Pan)
            {
                Camera.Position += vector;
                if (!MInput.Mouse.CheckLeftButton && !MInput.Mouse.CheckMiddleButton)
                {
                    mouseMode = MouseModes.Hover;
                }
            }
            else if (mouseMode == MouseModes.Select)
            {
                Rectangle mouseRect = GetMouseRect(mouseDragStart, mousePosition);
                foreach (BoardSpaceTemplate space in spaces)
                {
                    if (space.Check(mouseRect))
                    {
                        hovered.Add(space);
                    }
                }
                if (!MInput.Mouse.CheckLeftButton)
                {
                    if (MInput.Keyboard.Check(Keys.LeftControl))
                    {
                        ToggleSelection(mouseRect);
                    }
                    else
                    {
                        SetSelection(mouseRect);
                    }
                    mouseMode = MouseModes.Hover;
                }
            }
            else if (mouseMode == MouseModes.Move)
            {
                Vector2 relativeMove = coordScale * ((mousePosition - mouseDragStart) / coordScale).Round();
                bool    snap         = selection.Count == 1 && !MInput.Keyboard.Check(Keys.LeftAlt);
                foreach (BoardSpaceTemplate space in selection)
                {
                    space.Move(relativeMove);
                }
                if (!MInput.Mouse.CheckLeftButton)
                {
                    mouseMode = MouseModes.Hover;
                }
            }
            if (MInput.Keyboard.Pressed(Keys.D1))
            {
                SetType('b');
            }
            else if (MInput.Keyboard.Pressed(Keys.D2))
            {
                SetType('r');
            }
            else if (MInput.Keyboard.Pressed(Keys.D3))
            {
                SetType('i');
            }
            else if (MInput.Keyboard.Pressed(Keys.D4))
            {
                SetType('s');
            }
            else if (MInput.Keyboard.Pressed(Keys.D5))
            {
                SetType('g');
                SetGreenSpaceEvent(DebugCommands.greenSpaceEvent);
            }
            if (MInput.Keyboard.Pressed(Keys.H))
            {
                ToggleHeartSpace();
            }
            if (MInput.Keyboard.Pressed(Keys.F1) || (MInput.Keyboard.Check(Keys.LeftControl) && MInput.Keyboard.Pressed(Keys.S)))
            {
                SaveAndReload();
                return;
            }
            if (saveFlash > 0f)
            {
                saveFlash -= Engine.DeltaTime * 4f;
            }
            lastMouseScreenPosition = MInput.Mouse.Position;
            base.Update();
        }