From f9ac004aa87ce5864adf77299649eea276ea6a6d Mon Sep 17 00:00:00 2001 From: Joyce Date: Sat, 26 Sep 2020 17:32:10 +0200 Subject: [PATCH] Add the ability to set a custom mouse cursor on the client, made a generic method to avoid duplicating code for this. --- .../Configuration/ClientConfiguration.cs | 5 +++++ Intersect.Client/Core/Graphics.cs | 19 +++++++++++++++++++ Intersect.Client/Entities/Player.cs | 12 +++++------- Intersect.Client/MonoGame/IntersectGame.cs | 6 ++++++ 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Intersect (Core)/Configuration/ClientConfiguration.cs b/Intersect (Core)/Configuration/ClientConfiguration.cs index 893914d224..42f25be4b9 100644 --- a/Intersect (Core)/Configuration/ClientConfiguration.cs +++ b/Intersect (Core)/Configuration/ClientConfiguration.cs @@ -127,6 +127,11 @@ public void Validate() public string UpdateUrl { get; set; } = ""; + /// + /// Sets a custom mouse cursor. + /// + public string MouseCursor { get; set; } = ""; + #endregion #region Serialization Hooks diff --git a/Intersect.Client/Core/Graphics.cs b/Intersect.Client/Core/Graphics.cs index fa564aa17d..1342ecc505 100644 --- a/Intersect.Client/Core/Graphics.cs +++ b/Intersect.Client/Core/Graphics.cs @@ -8,6 +8,7 @@ using Intersect.Client.Framework.Graphics; using Intersect.Client.General; using Intersect.Client.Maps; +using Intersect.Client.MonoGame.Input; using Intersect.Configuration; using Intersect.Enums; using Intersect.GameObjects; @@ -488,6 +489,15 @@ public static void Render() new Color((int) Fade.GetFade(), 0, 0, 0), null, GameBlendModes.None ); + // Draw our mousecursor at the very end, but not when taking screenshots. + if (!takingScreenshot && !string.IsNullOrWhiteSpace(ClientConfiguration.Instance.MouseCursor)) + { + var renderLoc = ConvertToWorldPoint(Globals.InputManager.GetMousePosition()); + DrawGameTexture( + Globals.ContentManager.GetTexture(GameContentManager.TextureType.Misc, ClientConfiguration.Instance.MouseCursor), renderLoc.X, renderLoc.Y + ); + } + Renderer.End(); if (takingScreenshot) @@ -1118,6 +1128,15 @@ public static void UpdatePlayerLight() } //Helper Functions + /// + /// Convert a position on the screen to a position on the actual map for rendering. + /// + /// The point to convert. + /// The converted point. + public static Pointf ConvertToWorldPoint(Pointf windowPoint) + { + return new Pointf((int)Math.Floor(windowPoint.X + CurrentView.Left), (int)Math.Floor(windowPoint.Y + CurrentView.Top)); + } //Rendering Functions diff --git a/Intersect.Client/Entities/Player.cs b/Intersect.Client/Entities/Player.cs index 83d2db7a2a..5108ca69cf 100644 --- a/Intersect.Client/Entities/Player.cs +++ b/Intersect.Client/Entities/Player.cs @@ -1809,14 +1809,12 @@ public void DrawTargets() } } - var x = (int) Math.Floor(Globals.InputManager.GetMousePosition().X + Graphics.CurrentView.Left); - var y = (int) Math.Floor(Globals.InputManager.GetMousePosition().Y + Graphics.CurrentView.Top); - + var mousePos = Graphics.ConvertToWorldPoint(Globals.InputManager.GetMousePosition()); foreach (MapInstance map in MapInstance.Lookup.Values) { - if (x >= map.GetX() && x <= map.GetX() + Options.MapWidth * Options.TileWidth) + if (mousePos.X >= map.GetX() && mousePos.X <= map.GetX() + Options.MapWidth * Options.TileWidth) { - if (y >= map.GetY() && y <= map.GetY() + Options.MapHeight * Options.TileHeight) + if (mousePos.Y >= map.GetY() && mousePos.Y <= map.GetY() + Options.MapHeight * Options.TileHeight) { var mapId = map.Id; @@ -1829,7 +1827,7 @@ public void DrawTargets() if (en.Value.CurrentMap == mapId && !en.Value.IsStealthed() && - en.Value.WorldPos.Contains(x, y)) + en.Value.WorldPos.Contains(mousePos.X, mousePos.Y)) { if (en.Value.GetType() != typeof(Projectile) && en.Value.GetType() != typeof(Resource)) { @@ -1853,7 +1851,7 @@ public void DrawTargets() if (en.Value.CurrentMap == mapId && !((Event) en.Value).DisablePreview && !en.Value.IsStealthed() && - en.Value.WorldPos.Contains(x, y)) + en.Value.WorldPos.Contains(mousePos.X, mousePos.Y)) { if (TargetType != 1 || TargetIndex != en.Value.Id) { diff --git a/Intersect.Client/MonoGame/IntersectGame.cs b/Intersect.Client/MonoGame/IntersectGame.cs index 3375447499..688646f954 100644 --- a/Intersect.Client/MonoGame/IntersectGame.cs +++ b/Intersect.Client/MonoGame/IntersectGame.cs @@ -111,6 +111,12 @@ private IntersectGame([NotNull] IClientContext context, [NotNull] Action postSta Window.Position = new Microsoft.Xna.Framework.Point(-20, -2000); Window.AllowAltF4 = false; + // If we're going to be rendering a custom mouse cursor, hide the default one! + if (!string.IsNullOrWhiteSpace(ClientConfiguration.Instance.MouseCursor)) + { + IsMouseVisible = false; + } + if (!string.IsNullOrWhiteSpace(ClientConfiguration.Instance.UpdateUrl)) { mUpdater = new Updater.Updater(