LocalHuntsWindow.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using System.Linq;
  2. using System.Numerics;
  3. using Dalamud.Interface;
  4. using Dalamud.Interface.Windowing;
  5. using HuntBuddy.Utils;
  6. using ImGuiNET;
  7. namespace HuntBuddy.Windows;
  8. /// <summary>
  9. /// Local hunts window.
  10. /// </summary>
  11. public class LocalHuntsWindow: Window {
  12. public LocalHuntsWindow(): base(
  13. "Hunts in current area",
  14. ImGuiWindowFlags.NoNavInputs | ImGuiWindowFlags.NoDocking,
  15. true) {
  16. this.Size = Vector2.Zero;
  17. this.SizeCondition = ImGuiCond.Always;
  18. this.IsOpen = true;
  19. this.ShowCloseButton = false;
  20. this.RespectCloseHotkey = false;
  21. }
  22. public override void PreOpenCheck() {
  23. if (Plugin.Instance.Configuration.HideLocalHuntBackground) {
  24. if (!this.Flags.HasFlag(ImGuiWindowFlags.NoBackground)) {
  25. this.Flags |= ImGuiWindowFlags.NoBackground;
  26. }
  27. }
  28. else {
  29. this.Flags &= ~ImGuiWindowFlags.NoBackground;
  30. }
  31. if (Plugin.Instance.Configuration.LockWindowPositions) {
  32. if (!this.Flags.HasFlag(ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove)) {
  33. this.Flags |= ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove;
  34. }
  35. }
  36. else {
  37. this.Flags &= ~(ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove);
  38. }
  39. }
  40. public override unsafe bool DrawConditions() =>
  41. Plugin.Instance.Configuration.ShowLocalHunts &&
  42. !Plugin.Instance.CurrentAreaMobHuntEntries.IsEmpty &&
  43. Plugin.Instance.CurrentAreaMobHuntEntries.Count(
  44. x => Plugin.Instance.MobHuntStruct->CurrentKills[x.CurrentKillsOffset] == x.NeededKills) !=
  45. Plugin.Instance.CurrentAreaMobHuntEntries.Count;
  46. public override unsafe void Draw() {
  47. foreach (MobHuntEntry? mobHuntEntry in Plugin.Instance.CurrentAreaMobHuntEntries) {
  48. int currentKills = Plugin.Instance.MobHuntStruct->CurrentKills[mobHuntEntry.CurrentKillsOffset];
  49. if (Plugin.Instance.Configuration.HideCompletedHunts && currentKills == mobHuntEntry.NeededKills) {
  50. continue;
  51. }
  52. if (Location.Database.ContainsKey(mobHuntEntry.MobHuntId)) {
  53. if (InterfaceUtil.IconButton(FontAwesomeIcon.MapMarkerAlt, $"pin##{mobHuntEntry.MobHuntId}")) {
  54. Location.CreateMapMarker(
  55. mobHuntEntry.TerritoryType,
  56. mobHuntEntry.MapId,
  57. mobHuntEntry.MobHuntId,
  58. mobHuntEntry.Name,
  59. Location.OpenType.None);
  60. }
  61. if (ImGui.IsItemHovered()) {
  62. ImGui.BeginTooltip();
  63. ImGui.Text("Place marker on the map");
  64. ImGui.EndTooltip();
  65. }
  66. ImGui.SameLine();
  67. if (InterfaceUtil.IconButton(FontAwesomeIcon.MapMarkedAlt, $"open##{mobHuntEntry.MobHuntId}")) {
  68. bool includeArea = Plugin.Instance.Configuration.IncludeAreaOnMap;
  69. if (ImGui.IsKeyDown(ImGuiKey.ModShift)) {
  70. includeArea = !includeArea;
  71. }
  72. Location.CreateMapMarker(
  73. mobHuntEntry.TerritoryType,
  74. mobHuntEntry.MapId,
  75. mobHuntEntry.MobHuntId,
  76. mobHuntEntry.Name,
  77. includeArea ? Location.OpenType.ShowOpen : Location.OpenType.MarkerOpen);
  78. }
  79. if (ImGui.IsItemHovered()) {
  80. Vector4 color = ImGui.IsKeyDown(ImGuiKey.ModShift)
  81. ? new Vector4(0f, 0.7f, 0f, 1f)
  82. : new Vector4(0.7f, 0.7f, 0.7f, 1f);
  83. ImGui.BeginTooltip();
  84. if (Plugin.Instance.Configuration.IncludeAreaOnMap) {
  85. ImGui.Text("Show hunt area on the map");
  86. ImGui.TextColored(
  87. color,
  88. "Hold [SHIFT] to show the location only");
  89. }
  90. else {
  91. ImGui.Text("Show hunt location on the map");
  92. ImGui.TextColored(
  93. color,
  94. "Hold [SHIFT] to include the area");
  95. }
  96. ImGui.EndTooltip();
  97. }
  98. ImGui.SameLine();
  99. }
  100. ImGui.Text($"{mobHuntEntry.Name} ({currentKills}/{mobHuntEntry.NeededKills})");
  101. if (!Plugin.Instance.Configuration.ShowLocalHuntIcons) {
  102. continue;
  103. }
  104. InterfaceUtil.DrawHuntIcon(mobHuntEntry);
  105. }
  106. }
  107. }