Files
HSMappy/Mappy/Windows/MapNoteListWindow.cs

106 lines
3.6 KiB
C#

using System.Collections.Immutable;
using System.Drawing;
using System.Linq;
using System.Numerics;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using KamiLib.Window;
using Mappy.Data;
namespace Mappy.Windows;
public class MapNoteListWindow : Window
{
private static float NoteElementHeight => 95.0f * ImGuiHelpers.GlobalScale;
public MapNoteListWindow() : base("HSMappy Note List Window", new Vector2(400.0f, 400.0f))
{
AdditionalInfoTooltip = "Shows user-placed map notes for the current map";
}
protected override unsafe void DrawContents()
{
var agent = AgentMap.Instance();
var territoryId = agent->SelectedTerritoryId;
var mapId = agent->SelectedMapId;
var notesForMap = System.MapNoteConfig.Notes
.Where(n => n.Territory == territoryId && n.Map == mapId)
.ToImmutableList();
ImGuiClip.ClippedDraw(notesForMap, DrawNote, NoteElementHeight);
}
private void DrawNote(MapNote note)
{
using var id = ImRaii.PushId(note.GetIdString());
using (ImRaii.Child("note_container", new Vector2(ImGui.GetContentRegionAvail().X, NoteElementHeight - ImGui.GetStyle().FramePadding.Y * 2.0f))) {
using (ImRaii.Child("note_image_container", new Vector2(155.0f * ImGuiHelpers.GlobalScale, ImGui.GetContentRegionAvail().Y))) {
DrawNoteImage(note);
}
ImGui.SameLine();
using (ImRaii.Child("note_contents_container", ImGui.GetContentRegionAvail())) {
var buttonHeight = 28f * ImGuiHelpers.GlobalScale;
var textHeight = ImGui.GetContentRegionAvail().Y - buttonHeight;
using (ImRaii.Child("note_text_area", new Vector2(ImGui.GetContentRegionAvail().X, textHeight))) {
DrawNoteData(note);
}
DrawButtons(note);
}
}
ImGui.Spacing();
}
private void DrawNoteImage(MapNote note)
{
var texture = note.GetMapTexture();
if (texture is not null) {
ImGui.Image(texture.Handle, ImGui.GetContentRegionAvail(), new Vector2(0.15f, 0.15f), new Vector2(0.85f, 0.85f));
}
else {
ImGuiHelpers.ScaledDummy(ImGui.GetContentRegionAvail());
}
}
private void DrawNoteData(MapNote note)
{
ImGui.TextUnformatted(note.Title ?? "");
if (!string.IsNullOrWhiteSpace(note.Description)) {
ImGui.TextColored(KnownColor.Gray.Vector().Lighten(0.20f), note.Description);
}
ImGui.TextColored(KnownColor.Gray.Vector().Lighten(0.20f), note.GetMap().PlaceName.Value.Name.ExtractText());
var coord = note.GetMapCoordinate();
var zoneName = note.GetTerritoryType().PlaceNameZone.Value.Name.ExtractText();
ImGui.TextColored(KnownColor.Gray.Vector(), $"{zoneName} • {coord.X:F1}, {coord.Y:F1}");
}
private void DrawButtons(MapNote note)
{
var buttonSize = ImGuiHelpers.ScaledVector2(80.0f, 24.0f);
ImGui.SetCursorPos(new Vector2(0.0f, ImGui.GetContentRegionMax().Y - buttonSize.Y));
if (ImGui.Button("Focus", buttonSize)) {
note.Focus();
}
ImGui.SameLine();
if (ImGui.Button("Remove", buttonSize)) {
System.MapNoteConfig.Notes.Remove(note);
System.MapNoteConfig.Save();
}
}
public override void OnClose()
{
System.WindowManager.RemoveWindow(this);
}
}