Beispiel #1
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 = $"Cursor @\n screen: {(int) Math.Round(mousePosition.X)}, {(int) Math.Round(mousePosition.Y)}";

            if (Engine.Scene is Level)
            {
                Level  level = (Level)Engine.Scene;
                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);
                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();
        }
Beispiel #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);

            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((Engine.Instance.Window.ClientBounds.Height - 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();
        }