Skip to content

Commit

Permalink
Add Region Links to Layers Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
MidoriKami committed Aug 16, 2024
1 parent 32dfc91 commit befa906
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions Mappy/Windows/MapWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Dalamud.Interface;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Memory;
using Dalamud.Utility;
using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
Expand Down Expand Up @@ -410,22 +411,41 @@ private unsafe void DrawLayersContextMenu() {
if (!contextMenu) return;

var currentMap = Service.DataManager.GetExcelSheet<Map>()!.GetRow(AgentMap.Instance()->SelectedMapId);
if (currentMap is null) return;

var layers = Service.DataManager.GetExcelSheet<Map>()!
.Where(eachMap => eachMap.PlaceName.Row == currentMap!.PlaceName.Row)
.Where(eachMap => eachMap.MapIndex != 0)
.OrderBy(eachMap => eachMap.MapIndex)
.ToList();
// If this is a region map
if (currentMap.Hierarchy is 3) {
foreach (var marker in AgentMap.Instance()->MapMarkers) {
if (!DrawHelpers.IsRegionIcon(marker.MapMarker.IconId)) continue;

if (layers.Count is 0) {
ImGui.Text("No layers for this map");
var label = MemoryHelper.ReadStringNullTerminated((nint)marker.MapMarker.Subtext);

if (ImGui.MenuItem(label)) {
System.IntegrationsController.OpenMap(marker.DataKey);
System.SystemConfig.FollowPlayer = false;
System.MapRenderer.DrawOffset = Vector2.Zero;
}
}
}

foreach (var layer in layers) {
if (ImGui.MenuItem(layer.PlaceNameSub.Value?.Name ?? "Unable to Parse Name", "", AgentMap.Instance()->SelectedMapId == layer.RowId)) {
System.IntegrationsController.OpenMap(layer.RowId);
System.SystemConfig.FollowPlayer = false;
System.MapRenderer.DrawOffset = Vector2.Zero;
// Any other map
else {
var layers = Service.DataManager.GetExcelSheet<Map>()!
.Where(eachMap => eachMap.PlaceName.Row == currentMap.PlaceName.Row)
.Where(eachMap => eachMap.MapIndex != 0)
.OrderBy(eachMap => eachMap.MapIndex)
.ToList();

if (layers.Count is 0) {
ImGui.Text("No layers for this map");
}

foreach (var layer in layers) {
if (ImGui.MenuItem(layer.PlaceNameSub.Value?.Name ?? "Unable to Parse Name", "", AgentMap.Instance()->SelectedMapId == layer.RowId)) {
System.IntegrationsController.OpenMap(layer.RowId);
System.SystemConfig.FollowPlayer = false;
System.MapRenderer.DrawOffset = Vector2.Zero;
}
}
}
}
Expand Down

0 comments on commit befa906

Please sign in to comment.