LocalHuntsWindow.cs 4.2 KB

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