-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: map editor cursor sprites (#1797)
* feat: map editor cursor sprites * Feature can be toggled within the editor -> File -> Options -> General - Cursor sprite changes when the user switches between tools. - Moving the cursor out of the map editor sets the cursor back to normal. - Editor tool's custom sprites are modifiable. - Editor tool's cursor click-points are configurable. * Fixed issues when switching from selection tool to other tools. * March 14th, 2023: Updated to NET7 Branch and reviews: - ToolCursor doesn't needs IConfigurable. - ToolCursor uses a dictionary for improved performance. - Better performance and structure as overall. - Code clean up according to previous reviews. * review: defer ToolCursor initialization in Load() method
- Loading branch information
Showing
18 changed files
with
387 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Newtonsoft.Json; | ||
using Intersect.Editor.General; | ||
|
||
namespace Intersect.Editor.Configuration | ||
{ | ||
public sealed class ToolCursor | ||
{ | ||
public Point CursorClickPoint { get; set; } | ||
|
||
private static readonly Dictionary<EditingTool, ToolCursor> _toolCursorDict; | ||
|
||
public static IReadOnlyDictionary<EditingTool, ToolCursor> ToolCursorDict => _toolCursorDict; | ||
|
||
static ToolCursor() | ||
{ | ||
_toolCursorDict = new Dictionary<EditingTool, ToolCursor> | ||
{ | ||
{ EditingTool.Brush, new ToolCursor() }, | ||
{ EditingTool.Dropper, new ToolCursor() }, | ||
{ EditingTool.Erase, new ToolCursor() }, | ||
{ EditingTool.Fill, new ToolCursor() }, | ||
{ EditingTool.Rectangle, new ToolCursor() }, | ||
{ EditingTool.Selection, new ToolCursor() } | ||
}; | ||
} | ||
|
||
public static void Load() | ||
{ | ||
foreach (EditingTool tool in Enum.GetValues(typeof(EditingTool))) | ||
{ | ||
var fileName = $"resources/cursors/editor_{tool.ToString().ToLowerInvariant()}.json"; | ||
ToolCursor toolCursor; | ||
|
||
if (File.Exists(fileName)) | ||
{ | ||
if (!_toolCursorDict.TryGetValue(tool, out toolCursor)) | ||
{ | ||
continue; | ||
} | ||
|
||
var json = File.ReadAllText(fileName); | ||
toolCursor = JsonConvert.DeserializeObject<ToolCursor>(json); | ||
} | ||
else | ||
{ | ||
toolCursor = new ToolCursor(); | ||
var json = JsonConvert.SerializeObject(toolCursor); | ||
File.WriteAllText(fileName, json); | ||
} | ||
|
||
_toolCursorDict[tool] = toolCursor; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Intersect.Editor/Forms/DockingElements/frmMapEditor.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.