Skip to content

Commit 4938ec9

Browse files
authored
feature: ability to highlight selected NPC with declared spawn (AscensionGameDev#2223)
* feature: ability to highlight selected NPC with declared spawn (Editor feature and QoL update) - Adds the ability to highlight selected NPC with declared spawn within the map grid - Adds configurable pulsating color for selected NPC spawns - QoL enhancements and fixes for declared/random spawns: - Differently colored text as visual aid - Pressing the random checkbox for spawn location updates the grid preview - QoL enhancements on forms organization within the NPCs map layers tab - Adds a spawn counter under the NPC list (day's review) - Cached repeated global calls - Simplified code, less nesting - Adjusted Color Pulse calculation to use Intersect's Timing system - HotPink is easier to read with dark background for random location label (chore: UI changes and fixes) - prevents an ArgumentOutOfRangeException at Graphics.cs L:1007 with a check to ensure that selectedNpcIndex is less than the size of tmpMap.Spawns before using it to access an element in the list. - Reorganizes things a bit, added border style to the spawn counter.
1 parent 8b9cecf commit 4938ec9

File tree

5 files changed

+202
-74
lines changed

5 files changed

+202
-74
lines changed

Intersect.Editor/Core/Graphics.cs

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Intersect.Editor.Content;
88
using Intersect.Editor.Entities;
99
using Intersect.Editor.Forms.DockingElements;
10+
using Intersect.Editor.Forms.Helpers;
1011
using Intersect.Editor.General;
1112
using Intersect.Editor.Maps;
1213
using Intersect.Enums;
@@ -100,6 +101,10 @@ public static partial class Graphics
100101

101102
public static bool TilePreviewUpdated;
102103

104+
private static long _lastNpcPulseColorUpdate;
105+
106+
private static float _npcColorPulseRatio;
107+
103108
//Setup and Loading
104109
public static void InitMonogame()
105110
{
@@ -982,29 +987,51 @@ private static void DrawSelectionRect()
982987
{
983988
for (var i = 0; i < tmpMap.Spawns.Count; i++)
984989
{
985-
if (tmpMap.Spawns[i].X >= 0 && tmpMap.Spawns[i].Y >= 0)
990+
if (tmpMap.Spawns[i].X < 0 || tmpMap.Spawns[i].Y < 0)
986991
{
987-
var spawnTex = GameContentManager.GetTexture(
988-
GameContentManager.TextureType.Misc, "spawnicon.png"
989-
);
992+
continue;
993+
}
994+
995+
var spawnTex = GameContentManager.GetTexture(
996+
GameContentManager.TextureType.Misc, "spawnicon.png"
997+
);
990998

991-
if (spawnTex != null)
999+
if (spawnTex == null)
1000+
{
1001+
continue;
1002+
}
1003+
1004+
// Check if the current spawn is selected
1005+
var spawnColor = System.Drawing.Color.White;
1006+
var selectedNpcIndex = Globals.MapLayersWindow.lstMapNpcs.SelectedIndex;
1007+
if (selectedNpcIndex > -1 && selectedNpcIndex < tmpMap.Spawns.Count &&
1008+
tmpMap.Spawns[i] == tmpMap.Spawns[selectedNpcIndex])
1009+
{
1010+
// Calculate pulsating color: adjusts denominator to change speed of pulsation.
1011+
var currentTime = Timing.Global.MillisecondsUtc;
1012+
if ((currentTime - _lastNpcPulseColorUpdate) >= 50) // Update every 50ms.
9921013
{
993-
DrawTexture(
994-
spawnTex, new RectangleF(0, 0, spawnTex.Width, spawnTex.Height),
995-
new RectangleF(
996-
CurrentView.Left + tmpMap.Spawns[i].X * Options.TileWidth,
997-
CurrentView.Top + tmpMap.Spawns[i].Y * Options.TileHeight, Options.TileWidth,
998-
Options.TileHeight
999-
), System.Drawing.Color.White, null
1000-
);
1014+
_npcColorPulseRatio = (float)(Math.Sin(2 * Math.PI * (currentTime / 1000.0)) + 1) / 2;
1015+
_lastNpcPulseColorUpdate = currentTime;
1016+
}
1017+
if (FrmMapLayers.NpcPulseColor == default)
1018+
{
1019+
FrmMapLayers.NpcPulseColor = System.Drawing.Color.Red;
10011020
}
1021+
1022+
spawnColor = GridHelper.ColorInterpolate(spawnColor, FrmMapLayers.NpcPulseColor, _npcColorPulseRatio);
10021023
}
1024+
1025+
DrawTexture(
1026+
spawnTex, new RectangleF(0, 0, spawnTex.Width, spawnTex.Height),
1027+
new RectangleF(
1028+
CurrentView.Left + tmpMap.Spawns[i].X * Options.TileWidth,
1029+
CurrentView.Top + tmpMap.Spawns[i].Y * Options.TileHeight, Options.TileWidth,
1030+
Options.TileHeight
1031+
), spawnColor
1032+
);
10031033
}
10041034
}
1005-
else
1006-
{
1007-
}
10081035
}
10091036

10101037
if (Globals.CurrentTool == EditingTool.Selection && Globals.Dragging)

Intersect.Editor/Forms/DockingElements/frmMapLayers.Designer.cs

Lines changed: 77 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)