Skip to content

Commit 0f2c633

Browse files
committed
Expand Search Window
1 parent 26477ed commit 0f2c633

File tree

6 files changed

+250
-84
lines changed

6 files changed

+250
-84
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.Linq;
2+
using Dalamud.Interface.Utility;
3+
using Dalamud.Interface.Utility.Raii;
4+
using ImGuiNET;
5+
using Lumina.Excel.GeneratedSheets;
6+
7+
namespace Mappy.Classes.SelectionWindowComponents;
8+
9+
public class AetheryteDrawableOption : DrawableOption {
10+
public required Aetheryte Aetheryte { get; set; }
11+
12+
public override string ExtraLineLong => GetName();
13+
14+
private Map? internalMap;
15+
16+
public override Map? Map {
17+
get => internalMap ??= GetAetheryteMap();
18+
set => internalMap = value;
19+
}
20+
21+
protected override string[] GetAdditionalFilterStrings() => [
22+
Aetheryte.PlaceName.Value?.Name ?? string.Empty,
23+
Aetheryte.AethernetName.Value?.Name ?? string.Empty,
24+
];
25+
26+
protected override void DrawIcon() {
27+
using var imageFrame = ImRaii.Child($"image_frame{Aetheryte}", ImGuiHelpers.ScaledVector2(Width * ImGuiHelpers.GlobalScale, Height), false, ImGuiWindowFlags.NoInputs);
28+
if (!imageFrame) return;
29+
30+
var xOffset = (Width - Height) / 2.0f;
31+
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + xOffset);
32+
ImGui.Image(Service.TextureProvider.GetFromGameIcon(Aetheryte.IsAetheryte ? 60453 : 60430).GetWrapOrEmpty().ImGuiHandle, ImGuiHelpers.ScaledVector2(Height, Height));
33+
}
34+
35+
private Map? GetAetheryteMap() {
36+
if (Aetheryte.Map.Row is not 0) return Aetheryte.Map.Value;
37+
38+
if (Service.DataManager.GetExcelSheet<Aetheryte>()!.FirstOrDefault(aetheryte => aetheryte.IsAetheryte && aetheryte.AethernetGroup == Aetheryte.AethernetGroup) is not { } targetAetheryte) return null;
39+
40+
return targetAetheryte.Map.Value;
41+
}
42+
43+
private string GetName() {
44+
if (Aetheryte.AethernetName.Row is not 0) return Aetheryte.AethernetName.Value?.Name.ToString() ?? string.Empty;
45+
if (Aetheryte.PlaceName.Row is not 0) return Aetheryte.PlaceName.Value?.Name.ToString() ?? string.Empty;
46+
47+
return string.Empty;
48+
}
49+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System.Drawing;
2+
using System.Linq;
3+
using System.Numerics;
4+
using Dalamud.Interface;
5+
using Dalamud.Interface.Utility;
6+
using Dalamud.Interface.Utility.Raii;
7+
using Dalamud.Utility;
8+
using ImGuiNET;
9+
using Lumina.Excel.GeneratedSheets;
10+
11+
namespace Mappy.Classes.SelectionWindowComponents;
12+
13+
public abstract class DrawableOption {
14+
protected virtual string[] GetAdditionalFilterStrings() => [];
15+
16+
public virtual Map? Map { get; set; }
17+
18+
protected static float Width => 133.5f * ImGuiHelpers.GlobalScale;
19+
20+
protected static float Height => 75.0f * ImGuiHelpers.GlobalScale;
21+
22+
protected abstract void DrawIcon();
23+
24+
public virtual string ExtraLineLong => string.Empty;
25+
26+
public virtual string ExtraLineShort => string.Empty;
27+
28+
public virtual Vector2? MarkerLocation => null;
29+
30+
public string[] GetFilterStrings() {
31+
var baseStrings = new[] {
32+
Map?.PlaceNameRegion.Value?.Name.ToString() ?? string.Empty,
33+
Map?.PlaceName.Value?.Name.ToString() ?? string.Empty,
34+
Map?.PlaceNameSub.Value?.Name.ToString() ?? string.Empty,
35+
Map?.TerritoryType.Value?.Name.ToString() ?? string.Empty,
36+
Map?.Id.ToString() ?? string.Empty,
37+
};
38+
39+
return baseStrings.Concat(GetAdditionalFilterStrings()).ToArray();
40+
}
41+
42+
public void Draw() {
43+
if (Map is null) return;
44+
45+
using var id = ImRaii.PushId(Map.RowId.ToString());
46+
47+
DrawIcon();
48+
ImGui.SameLine();
49+
50+
using var contentsFrame = ImRaii.Child("contents_frame", new Vector2(ImGui.GetContentRegionAvail().X, Height * ImGuiHelpers.GlobalScale), false, ImGuiWindowFlags.NoInputs);
51+
if (!contentsFrame) return;
52+
53+
ImGuiHelpers.ScaledDummy(1.0f);
54+
55+
using var table = ImRaii.Table("data_table", 2, ImGuiTableFlags.SizingStretchProp);
56+
if (!table) return;
57+
58+
ImGui.TableSetupColumn("##column1", ImGuiTableColumnFlags.None, 2.0f);
59+
ImGui.TableSetupColumn("##column2", ImGuiTableColumnFlags.None, 1.0f);
60+
61+
var placeName = Map.PlaceName.Value?.Name ?? "Unknown PlaceName";
62+
var zoneName = Map.PlaceNameSub.Value?.Name;
63+
var regionName = Map.PlaceNameRegion.Value?.Name;
64+
65+
ImGui.TableNextColumn();
66+
ImGui.TextUnformatted(placeName);
67+
68+
ImGui.TableNextColumn();
69+
ImGui.TextUnformatted(Map.RowId.ToString());
70+
71+
ImGui.TableNextRow();
72+
ImGui.TableNextColumn();
73+
74+
using var grayColor = ImRaii.PushColor(ImGuiCol.Text, KnownColor.DarkGray.Vector());
75+
if (zoneName is not null && !zoneName.ToString().IsNullOrEmpty() && regionName is not null && !regionName.ToString().IsNullOrEmpty()) {
76+
ImGui.TextUnformatted($"{regionName}, {zoneName}");
77+
}
78+
else if (zoneName is not null && !zoneName.ToString().IsNullOrEmpty()) {
79+
ImGui.TextUnformatted($"{zoneName}");
80+
}
81+
else if (regionName is not null && !regionName.ToString().IsNullOrEmpty()) {
82+
ImGui.TextUnformatted($"{regionName}");
83+
}
84+
85+
ImGui.TableNextColumn();
86+
ImGui.TextUnformatted($"{Map.Id}");
87+
88+
ImGui.TableNextColumn();
89+
ImGui.TextUnformatted(ExtraLineLong);
90+
91+
ImGui.TableNextColumn();
92+
ImGui.TextUnformatted(ExtraLineShort);
93+
}
94+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Numerics;
2+
using Dalamud.Interface.Utility;
3+
using Dalamud.Interface.Utility.Raii;
4+
using ImGuiNET;
5+
using Lumina.Excel.GeneratedSheets2;
6+
7+
namespace Mappy.Classes.SelectionWindowComponents;
8+
9+
public class MapDrawableOption : DrawableOption {
10+
protected override void DrawIcon() {
11+
if (Map is not { TerritoryType.Value: { } option}) return;
12+
13+
using var imageFrame = ImRaii.Child($"image_frame{option}", ImGuiHelpers.ScaledVector2(Width * ImGuiHelpers.GlobalScale, Height), false, ImGuiWindowFlags.NoInputs);
14+
if (!imageFrame) return;
15+
16+
if (Service.DataManager.GetExcelSheet<LoadingImage>()!.GetRow(option.LoadingImage) is { } loadingImageInfo) {
17+
if (Service.TextureProvider.GetFromGame($"ui/loadingimage/{loadingImageInfo.Unknown0}_hr1.tex").GetWrapOrDefault() is { } texture) {
18+
ImGui.Image(texture.ImGuiHandle, ImGuiHelpers.ScaledVector2(Width, Height), new Vector2(0.15f, 0.15f), new Vector2(0.85f, 0.85f));
19+
}
20+
else {
21+
ImGuiHelpers.ScaledDummy(Width, Height);
22+
}
23+
}
24+
}
25+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Linq;
2+
using System.Numerics;
3+
using Dalamud.Interface.Utility;
4+
using Dalamud.Interface.Utility.Raii;
5+
using ImGuiNET;
6+
using Lumina.Excel.GeneratedSheets2;
7+
using Map = Lumina.Excel.GeneratedSheets.Map;
8+
9+
namespace Mappy.Classes.SelectionWindowComponents;
10+
11+
public class PoiDrawableOption : DrawableOption {
12+
public required MapMarker MapMarker { get; set; }
13+
14+
public override Vector2? MarkerLocation => new Vector2(MapMarker.X, MapMarker.Y);
15+
16+
private Map? internalMap;
17+
18+
public override Map? Map {
19+
get => internalMap ??= Service.DataManager.GetExcelSheet<Map>()!.FirstOrDefault(map => map.MapMarkerRange == MapMarker.RowId);
20+
set => internalMap = value;
21+
}
22+
23+
public override string ExtraLineLong => MapMarker.PlaceNameSubtext.Value?.Name.ToString() ?? string.Empty;
24+
25+
protected override void DrawIcon() {
26+
using var imageFrame = ImRaii.Child($"image_frame{MapMarker}", ImGuiHelpers.ScaledVector2(Width * ImGuiHelpers.GlobalScale, Height), false, ImGuiWindowFlags.NoInputs);
27+
if (!imageFrame) return;
28+
29+
var xOffset = (Width - Height) / 2.0f;
30+
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + xOffset);
31+
ImGui.Image(Service.TextureProvider.GetFromGameIcon((uint)MapMarker.Icon).GetWrapOrEmpty().ImGuiHandle, ImGuiHelpers.ScaledVector2(Height, Height));
32+
}
33+
34+
protected override string[] GetAdditionalFilterStrings() => [
35+
MapMarker.PlaceNameSubtext.Value?.Name.ToString() ?? string.Empty
36+
];
37+
}
Lines changed: 35 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,59 @@
11
using System.Collections.Generic;
2-
using System.Drawing;
32
using System.Linq;
4-
using Dalamud.Interface;
3+
using System.Numerics;
54
using Dalamud.Interface.Utility;
6-
using Dalamud.Interface.Utility.Raii;
7-
using Dalamud.Plugin.Services;
8-
using Dalamud.Utility;
9-
using FFXIVClientStructs.FFXIV.Common.Math;
10-
using ImGuiNET;
115
using KamiLib.Window;
126
using Lumina.Excel.GeneratedSheets2;
7+
using Mappy.Classes.SelectionWindowComponents;
8+
using Aetheryte = Lumina.Excel.GeneratedSheets.Aetheryte;
139
using Map = Lumina.Excel.GeneratedSheets.Map;
14-
using TerritoryType = Lumina.Excel.GeneratedSheets.TerritoryType;
1510

1611
namespace Mappy.Windows;
1712

18-
public class MapSelectionWindow : SelectionWindowBase<Map> {
19-
20-
private const float Width = 133.5f;
21-
22-
private const float Height = 75.0f;
13+
public class MapSelectionWindow : SelectionWindowBase<DrawableOption> {
2314

2415
protected override bool AllowMultiSelect => false;
2516

2617
protected override float SelectionHeight => 75.0f * ImGuiHelpers.GlobalScale;
2718

28-
public MapSelectionWindow() : base(new Vector2(500.0f, 600.0f)) {
29-
SelectionOptions = Service.DataManager.GetExcelSheet<Map>()!
19+
public MapSelectionWindow() : base(new Vector2(500.0f, 800.0f)) {
20+
var maps = Service.DataManager.GetExcelSheet<Map>()!
3021
.Where(map => map is { PlaceName.Row: not 0, TerritoryType.Value.LoadingImage: not 0 })
3122
.Where(map => map is not { PriorityUI: 0, PriorityCategoryUI: 0 } )
23+
.Select(map => new MapDrawableOption {
24+
Map = map,
25+
})
26+
.OfType<DrawableOption>()
3227
.ToList();
33-
}
34-
35-
protected override void DrawSelection(Map option) {
36-
using var id = ImRaii.PushId(option.RowId.ToString());
37-
38-
if (option.TerritoryType.Value is null) return;
39-
40-
DrawTerritoryImage(option.TerritoryType.Value, Service.DataManager, Service.TextureProvider);
41-
ImGui.SameLine();
42-
43-
using var contentsFrame = ImRaii.Child("contents_frame", new Vector2(ImGui.GetContentRegionAvail().X, Height * ImGuiHelpers.GlobalScale), false, ImGuiWindowFlags.NoInputs);
44-
if (!contentsFrame) return;
45-
46-
ImGuiHelpers.ScaledDummy(1.0f);
47-
48-
using var table = ImRaii.Table("data_table", 2, ImGuiTableFlags.SizingStretchProp);
49-
if (!table) return;
50-
51-
ImGui.TableSetupColumn("##column1", ImGuiTableColumnFlags.None, 2.0f);
52-
ImGui.TableSetupColumn("##column2", ImGuiTableColumnFlags.None, 1.0f);
5328

54-
var placeName = option.PlaceName.Value?.Name ?? "Unknown PlaceName";
55-
var zoneName = option.PlaceNameSub.Value?.Name;
56-
var regionName = option.PlaceNameRegion.Value?.Name;
57-
58-
ImGui.TableNextColumn();
59-
ImGui.TextUnformatted(placeName);
60-
61-
ImGui.TableNextColumn();
62-
ImGui.TextUnformatted(option.RowId.ToString());
63-
64-
ImGui.TableNextRow();
65-
ImGui.TableNextColumn();
29+
var poi = Service.DataManager.GetExcelSheet<MapMarker>()!
30+
.Where(marker => marker.PlaceNameSubtext.Row is not 0)
31+
.Where(marker => marker.Icon is 60442)
32+
.Select(marker => new PoiDrawableOption {
33+
MapMarker = marker,
34+
})
35+
.OfType<DrawableOption>()
36+
.ToList();
6637

67-
using var grayColor = ImRaii.PushColor(ImGuiCol.Text, KnownColor.DarkGray.Vector());
68-
if (zoneName is not null && !zoneName.ToString().IsNullOrEmpty() && regionName is not null && !regionName.ToString().IsNullOrEmpty()) {
69-
ImGui.TextUnformatted($"{regionName}, {zoneName}");
70-
}
71-
else if (zoneName is not null && !zoneName.ToString().IsNullOrEmpty()) {
72-
ImGui.TextUnformatted($"{zoneName}");
73-
}
74-
else if (regionName is not null && !regionName.ToString().IsNullOrEmpty()) {
75-
ImGui.TextUnformatted($"{regionName}");
76-
}
38+
var aetherytes = Service.DataManager.GetExcelSheet<Aetheryte>()!
39+
.Where(aetheryte => aetheryte is not { PlaceName.Row: 0, AethernetName.Row: 0 })
40+
.Where(aetheryte => aetheryte is not { AethernetGroup: 0, Map.Row: 0 })
41+
.Select(aetheryte => new AetheryteDrawableOption {
42+
Aetheryte = aetheryte,
43+
})
44+
.OfType<DrawableOption>()
45+
.ToList();
7746

78-
ImGui.TableNextColumn();
79-
ImGui.TextUnformatted($"{option.Id}");
47+
SelectionOptions = maps
48+
.Concat(poi)
49+
.Concat(aetherytes)
50+
.ToList();
8051
}
81-
82-
protected override IEnumerable<string> GetFilterStrings(Map option)
83-
=> [
84-
option.PlaceNameRegion.Value?.Name.ToString() ?? string.Empty,
85-
option.PlaceName.Value?.Name.ToString() ?? string.Empty,
86-
option.PlaceNameSub.Value?.Name.ToString() ?? string.Empty,
87-
option.TerritoryType.Value?.Name.ToString() ?? string.Empty,
88-
option.Id.ToString(),
89-
];
9052

91-
private static void DrawTerritoryImage(TerritoryType option, IDataManager dataManager, ITextureProvider textureProvider) {
92-
using var imageFrame = ImRaii.Child($"image_frame{option}", ImGuiHelpers.ScaledVector2(Width * ImGuiHelpers.GlobalScale, Height), false, ImGuiWindowFlags.NoInputs);
93-
if (!imageFrame) return;
94-
95-
if (dataManager.GetExcelSheet<LoadingImage>()!.GetRow(option.LoadingImage) is { } loadingImageInfo) {
96-
if (textureProvider.GetFromGame($"ui/loadingimage/{loadingImageInfo.Unknown0}_hr1.tex").GetWrapOrDefault() is { } texture) {
97-
ImGui.Image(texture.ImGuiHandle, ImGuiHelpers.ScaledVector2(Width, Height), new Vector2(0.15f, 0.15f), new Vector2(0.85f, 0.85f));
98-
}
99-
else {
100-
ImGuiHelpers.ScaledDummy(Width, Height);
101-
}
102-
}
53+
protected override void DrawSelection(DrawableOption option) {
54+
option.Draw();
10355
}
56+
57+
protected override IEnumerable<string> GetFilterStrings(DrawableOption option)
58+
=> option.GetFilterStrings();
10459
}

Mappy/Windows/MapWindow.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,17 @@ private unsafe void DrawToolbar() {
264264
if (MappyGuiTweaks.IconButton(FontAwesomeIcon.Search, "search", "Search for Map")) {
265265
System.WindowManager.AddWindow(new MapSelectionWindow {
266266
SingleSelectionCallback = selection => {
267-
if (selection is not null) {
268-
System.IntegrationsController.OpenMap(selection.RowId);
269-
System.MapRenderer.DrawOffset = Vector2.Zero;
267+
if (selection?.Map != null) {
268+
if (AgentMap.Instance()->SelectedMapId != selection.Map.RowId) {
269+
System.IntegrationsController.OpenMap(selection.Map.RowId);
270+
}
271+
272+
if (selection.MarkerLocation is {} location) {
273+
System.SystemConfig.FollowPlayer = false;
274+
System.MapRenderer.DrawOffset = -location + DrawHelpers.GetMapCenterOffsetVector();
275+
}
270276
}
271-
}
277+
},
272278
}, WindowFlags.OpenImmediately | WindowFlags.RequireLoggedIn);
273279
}
274280

0 commit comments

Comments
 (0)