Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Mouse Cursor #334

Merged
merged 1 commit into from Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions Intersect (Core)/Configuration/ClientConfiguration.cs
Expand Up @@ -127,6 +127,11 @@ public void Validate()

public string UpdateUrl { get; set; } = "";

/// <summary>
/// Sets a custom mouse cursor.
/// </summary>
public string MouseCursor { get; set; } = "";

#endregion

#region Serialization Hooks
Expand Down
19 changes: 19 additions & 0 deletions Intersect.Client/Core/Graphics.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1118,6 +1128,15 @@ public static void UpdatePlayerLight()
}

//Helper Functions
/// <summary>
/// Convert a position on the screen to a position on the actual map for rendering.
/// </summary>
/// <param name="windowPoint">The point to convert.</param>
/// <returns>The converted point.</returns>
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

Expand Down
12 changes: 5 additions & 7 deletions Intersect.Client/Entities/Player.cs
Expand Up @@ -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;

Expand All @@ -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))
{
Expand All @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions Intersect.Client/MonoGame/IntersectGame.cs
Expand Up @@ -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(
Expand Down