Esempio n. 1
0
        internal void Render()
        {
            int viewWidth  = Engine.ViewWidth;
            int viewHeight = Engine.ViewHeight;

            // Vector2 mousePosition = MInput.Mouse.Position;
            // When the console is opening, MInput.Mouse.UpdateNull is called so MInput.Mouse.Position keeps returning 0, 0
            // Let's just use the XNA / FNA MouseState instead.
            MouseState mouseState       = Mouse.GetState();
            int        mouseScrollDelta = mouseState.ScrollWheelValue - mouseScroll;

            mouseScroll = mouseState.ScrollWheelValue;
            Vector2 mousePosition     = new Vector2(mouseState.X, mouseState.Y);
            Vector2?mouseSnapPosition = null;

            int maxCursorScale = 1;

            string mouseText = "";

            Level level = Engine.Scene as Level;

            if (level != null)
            {
                mouseText += $"Area: {level.Session.Level} @ {level.Session.Area}\n";
            }

            mouseText += $"Cursor @\n screen: {(int) Math.Round(mousePosition.X)}, {(int) Math.Round(mousePosition.Y)}";

            if (level != null)
            {
                Camera cam       = level.Camera;
                float  viewScale = (float)Engine.ViewWidth / Engine.Width;
                // Convert screen to world position. The method assumes screen is in full size (1920x1080) so we need to scale the position.
                Vector2 mouseWorldPosition = Calc.Floor(((patch_Level)level).ScreenToWorld(mousePosition / viewScale));
                // CelesteTAS already displays world coordinates. If it is installed, leave that up to it.
                if (!celesteTASInstalled.Value)
                {
                    mouseText += $"\n world:       {(int) Math.Round(mouseWorldPosition.X)}, {(int) Math.Round(mouseWorldPosition.Y)}";
                }
                mouseWorldPosition -= level.LevelOffset;
                mouseText          += $"\n level:       {(int) Math.Round(mouseWorldPosition.X)}, {(int) Math.Round(mouseWorldPosition.Y)}";
                // Convert world to world-snap position.
                mouseSnapPosition = Calc.Floor(mouseWorldPosition / 8f);
                mouseText        += $"\n level, /8:   {(int) Math.Round(mouseSnapPosition.Value.X)}, {(int) Math.Round(mouseSnapPosition.Value.Y)}";
                mouseSnapPosition = 8f * mouseSnapPosition;
                mouseText        += $"\n level, snap: {(int) Math.Round(mouseSnapPosition.Value.X)}, {(int) Math.Round(mouseSnapPosition.Value.Y)}";
                // Convert world-snap to screen-snap position.
                mouseSnapPosition += new Vector2(4f, 4f); // Center the cursor on the tile.
                mouseSnapPosition += level.LevelOffset;
                mouseSnapPosition  = Calc.Floor(((patch_Level)level).WorldToScreen(mouseSnapPosition.Value) * viewScale);
                // Cursor shouldn't be larger than an unzoomed tile (level.Zoom and cam.Zoom are both 1)
                maxCursorScale = Engine.ViewWidth / cam.Viewport.Width;
            }

            Draw.SpriteBatch.Begin();

            // Draw cursor below all other UI.
            if (mouseScrollDelta < 0)
            {
                cursorScale--;
            }
            else if (mouseScrollDelta > 0)
            {
                cursorScale++;
            }
            cursorScale = Calc.Clamp(cursorScale, 1, maxCursorScale);
            if (mouseSnapPosition != null)
            {
                DrawCursor(mouseSnapPosition.Value, cursorScale, Color.Red);
            }
            DrawCursor(mousePosition, cursorScale, Color.Yellow);

            // Draw cursor world position.
            Vector2 mouseTextSize = Draw.DefaultFont.MeasureString(mouseText);

            Draw.Rect(10f, 10f, mouseTextSize.X + 20f, mouseTextSize.Y + 20f, Color.Black * 0.8f);
            Draw.SpriteBatch.DrawString(
                Draw.DefaultFont,
                mouseText,
                new Vector2(20f, 20f),
                Color.White
                );

            // Draw standard console.

            Draw.Rect(10f, viewHeight - 50f, viewWidth - 20f, 40f, Color.Black * 0.8f);

            var drawPoint = new Vector2(20f, viewHeight - 42f);

            Draw.SpriteBatch.DrawString(Draw.DefaultFont, ">" + currentText, drawPoint, Color.White);
            if (underscore)
            {
                var size = Draw.DefaultFont.MeasureString(">" + currentText.Substring(0, charIndex));
                size.X++;
                Draw.Line(drawPoint + new Vector2(size.X, 0), drawPoint + size, Color.White);
            }

            if (drawCommands.Count > 0)
            {
                int   drawCount = Math.Min((viewHeight - 100) / 30, drawCommands.Count - firstLineIndexToDraw);
                float height    = 10f + 30f * drawCount;
                Draw.Rect(10f, viewHeight - height - 60f, viewWidth - 20f, height, Color.Black * 0.8f);
                for (int i = 0; i < drawCount && firstLineIndexToDraw + i < drawCommands.Count; i++)
                {
                    Draw.SpriteBatch.DrawString(
                        Draw.DefaultFont,
                        drawCommands[firstLineIndexToDraw + i].Text,
                        new Vector2(20f, viewHeight - 92f - 30f * i),
                        drawCommands[firstLineIndexToDraw + i].Color
                        );
                }
            }

            Draw.SpriteBatch.End();
        }
Esempio n. 2
0
        internal void Render()
        {
            int viewWidth  = Engine.ViewWidth;
            int viewHeight = Engine.ViewHeight;

            // Vector2 mousePosition = MInput.Mouse.Position;
            // For whatever reason, MInput.Mouse.Position keeps returning 0, 0
            // Let's just use the XNA / FNA MouseState instead.
            MouseState mouseState       = Mouse.GetState();
            int        mouseScrollDelta = mouseState.ScrollWheelValue - mouseScroll;

            mouseScroll = mouseState.ScrollWheelValue;
            Vector2 mousePosition     = new Vector2(mouseState.X, mouseState.Y);
            Vector2?mouseSnapPosition = null;

            int viewScale = 1;

            string mouseText = "";

            Level level = Engine.Scene as Level;

            if (level != null)
            {
                mouseText += $"Area: {level.Session.Level} @ {level.Session.Area}\n";
            }

            mouseText += $"Cursor @\n screen: {(int) Math.Round(mousePosition.X)}, {(int) Math.Round(mousePosition.Y)}";

            if (level != null)
            {
                Camera cam = level.Camera;
                viewScale = (int)Math.Round(Engine.Instance.GraphicsDevice.PresentationParameters.BackBufferWidth / (float)cam.Viewport.Width);
                Vector2 mouseWorldPosition = mousePosition;
                // Convert screen to world position.
                mouseWorldPosition = Calc.Floor(mouseWorldPosition / viewScale);
                mouseWorldPosition = cam.ScreenToCamera(mouseWorldPosition);
                // CelesteTAS already displays world coordinates. If it is installed, leave that up to it.
                if (!celesteTASInstalled.Value)
                {
                    mouseText += $"\n world:       {(int) Math.Round(mouseWorldPosition.X)}, {(int) Math.Round(mouseWorldPosition.Y)}";
                }
                mouseWorldPosition -= level.LevelOffset;
                mouseText          += $"\n level:       {(int) Math.Round(mouseWorldPosition.X)}, {(int) Math.Round(mouseWorldPosition.Y)}";
                // Convert world to world-snap position.
                mouseSnapPosition = mouseWorldPosition;
                mouseSnapPosition = Calc.Floor(mouseSnapPosition.Value / 8f);
                mouseText        += $"\n level, /8:   {(int) Math.Round(mouseSnapPosition.Value.X)}, {(int) Math.Round(mouseSnapPosition.Value.Y)}";
                mouseSnapPosition = 8f * mouseSnapPosition;
                mouseText        += $"\n level, snap: {(int) Math.Round(mouseSnapPosition.Value.X)}, {(int) Math.Round(mouseSnapPosition.Value.Y)}";
                // Convert world-snap to screen-snap position.
                mouseSnapPosition += new Vector2(4f, 4f); // Center the cursor on the tile.
                mouseSnapPosition += level.LevelOffset;
                mouseSnapPosition  = cam.CameraToScreen(mouseSnapPosition.Value);
                mouseSnapPosition *= viewScale;
            }

            Draw.SpriteBatch.Begin();

            // Draw cursor below all other UI.
            if (mouseScrollDelta < 0)
            {
                cursorScale--;
            }
            else if (mouseScrollDelta > 0)
            {
                cursorScale++;
            }
            cursorScale = Calc.Clamp(cursorScale, 1, viewScale);
            if (mouseSnapPosition != null)
            {
                DrawCursor(mouseSnapPosition.Value, cursorScale, Color.Red);
            }
            DrawCursor(mousePosition, cursorScale, Color.Yellow);

            // Draw cursor world position.
            Vector2 mouseTextSize = Draw.DefaultFont.MeasureString(mouseText);

            Draw.Rect(10f, 10f, mouseTextSize.X + 20f, mouseTextSize.Y + 20f, Color.Black * 0.8f);
            Draw.SpriteBatch.DrawString(
                Draw.DefaultFont,
                mouseText,
                new Vector2(20f, 20f),
                Color.White
                );

            // Draw standard console.

            Draw.Rect(10f, viewHeight - 50f, viewWidth - 20f, 40f, Color.Black * 0.8f);

            if (underscore)
            {
                Draw.SpriteBatch.DrawString(
                    Draw.DefaultFont,
                    ">" + currentText + "_",
                    new Vector2(20f, viewHeight - 42f),
                    Color.White
                    );
            }
            else
            {
                Draw.SpriteBatch.DrawString(
                    Draw.DefaultFont,
                    ">" + currentText,
                    new Vector2(20f, viewHeight - 42f),
                    Color.White
                    );
            }

            if (drawCommands.Count > 0)
            {
                float height = 10f + 30f * drawCommands.Count;
                Draw.Rect(10f, viewHeight - height - 60f, viewWidth - 20f, height, Color.Black * 0.8f);
                for (int i = 0; i < drawCommands.Count; i++)
                {
                    Draw.SpriteBatch.DrawString(
                        Draw.DefaultFont,
                        drawCommands[i].Text,
                        new Vector2(20f, viewHeight - 92f - 30f * i),
                        drawCommands[i].Color
                        );
                }
            }

            Draw.SpriteBatch.End();
        }
Esempio n. 3
0
 public void EndTiling()
 {
     Draw.SpriteBatch.End();
     Draw.ResetTarget();
 }
Esempio n. 4
0
 public void BeginTiling(BlendState blendState, int offsetX, int offsetY)
 {
     Draw.SetTarget(Canvas);
     Engine.Instance.GraphicsDevice.Clear(Color.Transparent);
     Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, blendState, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, null, Matrix.CreateTranslation(offsetX, offsetY, 0));
 }
Esempio n. 5
0
 public void BeginTiling(BlendState blendState)
 {
     Draw.SetTarget(Canvas);
     Engine.Instance.GraphicsDevice.Clear(Color.Transparent);
     Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, blendState, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone);
 }
Esempio n. 6
0
 public override void Render(Camera camera, Color color)
 {
     Draw.HollowRect(AbsoluteX, AbsoluteY, Width, Height, color);
 }
Esempio n. 7
0
 public override void Render(Camera camera, Color color)
 {
     Draw.Circle(AbsolutePosition, Radius, color, 4);
 }