MainWindow.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Numerics;
  4. using System.Threading.Tasks;
  5. using Dalamud.Interface;
  6. using Dalamud.Interface.Utility;
  7. using Dalamud.Interface.Windowing;
  8. using FFXIVClientStructs.FFXIV.Client.Game.UI;
  9. using HuntBuddy.Utils;
  10. using ImGuiNET;
  11. namespace HuntBuddy.Windows;
  12. /// <summary>
  13. /// Main plugin window.
  14. /// </summary>
  15. public class MainWindow: Window {
  16. public MainWindow() : base(
  17. $"{Plugin.Instance.Name}",
  18. ImGuiWindowFlags.NoDocking,
  19. true) {
  20. this.Size = new Vector2(400 * ImGui.GetIO().FontGlobalScale, 500);
  21. this.SizeCondition = ImGuiCond.FirstUseEver;
  22. this.RespectCloseHotkey = !Plugin.Instance.Configuration.IgnoreCloseHotkey;
  23. }
  24. public override void PreOpenCheck() {
  25. if (Plugin.Instance.Configuration.LockWindowPositions) {
  26. this.Flags |= ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove;
  27. }
  28. else {
  29. this.Flags &= ~(ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove);
  30. }
  31. }
  32. public override unsafe void Draw() {
  33. if (!Plugin.Instance.MobHuntEntriesReady) {
  34. ImGui.Text("Reloading data ...");
  35. return;
  36. }
  37. ImGui.BeginGroup();
  38. ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.8f, 0.2f, 0.2f, 1));
  39. InterfaceUtil.DrawCenteredText("B-RANK AND ARR HUNT MARK");
  40. InterfaceUtil.DrawCenteredText("LOCATIONS ARE NOT SUPPORTED");
  41. ImGui.PopStyleColor();
  42. ImGui.EndGroup();
  43. if (ImGui.IsItemHovered()) {
  44. InterfaceUtil.DrawWrappedTooltip(ImGuiHelpers.GlobalScale * 400,
  45. "B-rank marks have a varying number of potential spawn locations, and will only ever exist in one of them at a time."
  46. + $" {Plugin.Instance.Name} has no way to know which location a given mob is in, and as such cannot direct you to it."
  47. + " You can look up spawn maps online to find the possible spots for your target.\n"
  48. + "\n"
  49. + "Several ARR hunt marks are FATE mobs, which means they aren't always available."
  50. + $" Since {Plugin.Instance.Name} has no way to know if the FATE is up or not, ARR marks are not part of the plugin.");
  51. }
  52. if (InterfaceUtil.IconButton(FontAwesomeIcon.Redo, "Reload")) {
  53. Plugin.Instance.MobHuntEntriesReady = false;
  54. Task.Run(Plugin.Instance.ReloadData);
  55. return;
  56. }
  57. if (ImGui.IsItemHovered()) {
  58. ImGui.BeginTooltip();
  59. ImGui.Text("Click this button to reload daily hunt data");
  60. ImGui.EndTooltip();
  61. }
  62. ImGui.SameLine();
  63. if (InterfaceUtil.IconButton(FontAwesomeIcon.Cog, "Config")) {
  64. Plugin.Instance.OpenConfigUi();
  65. }
  66. IEnumerable<KeyValuePair<string, Dictionary<KeyValuePair<uint, string>, List<MobHuntEntry>>>> expansionEntriesWithTreeNodes = Plugin.Instance
  67. .MobHuntEntries
  68. .Where(expansionEntry => ImGui.TreeNode(expansionEntry.Key));
  69. foreach (KeyValuePair<string, Dictionary<KeyValuePair<uint, string>, List<MobHuntEntry>>> expansionEntry in expansionEntriesWithTreeNodes) {
  70. IEnumerable<KeyValuePair<KeyValuePair<uint, string>, List<MobHuntEntry>>> mobEntriesWithTreeNodes = expansionEntry.Value
  71. .Where(entry => {
  72. bool treeOpen = ImGui.TreeNodeEx(entry.Key.Value, ImGuiTreeNodeFlags.AllowItemOverlap);
  73. ImGui.SameLine();
  74. int killedCount = entry.Value.Count(x => MobHunt.Instance()->GetKillCount(x.BillNumber, x.MobIndex) == x.NeededKills);
  75. if (killedCount != entry.Value.Count) {
  76. ImGui.Text($"({killedCount}/{entry.Value.Count})");
  77. }
  78. else {
  79. ImGui.TextColored(
  80. new Vector4(0f, 1f, 0f, 1f),
  81. $"({killedCount}/{entry.Value.Count})");
  82. }
  83. return treeOpen;
  84. });
  85. foreach (KeyValuePair<KeyValuePair<uint, string>, List<MobHuntEntry>> entry in mobEntriesWithTreeNodes) {
  86. foreach (MobHuntEntry? mobHuntEntry in entry.Value) {
  87. if (Location.Database.ContainsKey(mobHuntEntry.MobHuntId)) {
  88. if (InterfaceUtil.IconButton(FontAwesomeIcon.MapMarkerAlt, $"pin##{mobHuntEntry.MobHuntId}")) {
  89. Location.CreateMapMarker(
  90. mobHuntEntry.TerritoryType,
  91. mobHuntEntry.MapId,
  92. mobHuntEntry.MobHuntId,
  93. mobHuntEntry.Name,
  94. Location.OpenType.None);
  95. }
  96. if (ImGui.IsItemHovered()) {
  97. ImGui.BeginTooltip();
  98. ImGui.Text("Place marker on the map");
  99. ImGui.EndTooltip();
  100. }
  101. ImGui.SameLine();
  102. if (InterfaceUtil.IconButton(FontAwesomeIcon.MapMarkedAlt, $"open##{mobHuntEntry.MobHuntId}")) {
  103. bool includeArea = Plugin.Instance.Configuration.IncludeAreaOnMap;
  104. if (ImGui.IsKeyDown(ImGuiKey.ModShift)) {
  105. includeArea = !includeArea;
  106. }
  107. Location.CreateMapMarker(
  108. mobHuntEntry.TerritoryType,
  109. mobHuntEntry.MapId,
  110. mobHuntEntry.MobHuntId,
  111. mobHuntEntry.Name,
  112. includeArea ? Location.OpenType.ShowOpen : Location.OpenType.MarkerOpen);
  113. }
  114. if (ImGui.IsItemHovered()) {
  115. Vector4 color = ImGui.IsKeyDown(ImGuiKey.ModShift)
  116. ? new Vector4(0f, 0.7f, 0f, 1f)
  117. : new Vector4(0.7f, 0.7f, 0.7f, 1f);
  118. ImGui.BeginTooltip();
  119. if (Plugin.Instance.Configuration.IncludeAreaOnMap) {
  120. ImGui.Text("Show hunt area on the map");
  121. ImGui.TextColored(
  122. color,
  123. "Hold [SHIFT] to show the location only");
  124. }
  125. else {
  126. ImGui.Text("Show hunt location on the map");
  127. ImGui.TextColored(
  128. color,
  129. "Hold [SHIFT] to include the area");
  130. }
  131. ImGui.EndTooltip();
  132. }
  133. ImGui.SameLine();
  134. if (Plugin.TeleportConsumer?.IsAvailable == true) {
  135. if (InterfaceUtil.IconButton(FontAwesomeIcon.StreetView, $"teleport##{mobHuntEntry.MobHuntId}")) {
  136. Location.TeleportToNearestAetheryte(
  137. mobHuntEntry.TerritoryType,
  138. mobHuntEntry.MapId,
  139. mobHuntEntry.MobHuntId);
  140. }
  141. if (ImGui.IsItemHovered()) {
  142. ImGui.BeginTooltip();
  143. ImGui.Text("Teleport to nearest aetheryte");
  144. ImGui.EndTooltip();
  145. }
  146. ImGui.SameLine();
  147. }
  148. if (Plugin.Instance.Configuration.EnableXivEspIntegration && Plugin.EspConsumer?.IsAvailable == true) {
  149. if (InterfaceUtil.IconButton(FontAwesomeIcon.Search, $"esp##{mobHuntEntry.MobHuntId}")) {
  150. Plugin.EspConsumer.SearchFor(mobHuntEntry.Name!);
  151. }
  152. if (ImGui.IsItemHovered()) {
  153. ImGui.BeginTooltip();
  154. ImGui.Text("Set XivEsp search to this target");
  155. ImGui.EndTooltip();
  156. }
  157. ImGui.SameLine();
  158. }
  159. }
  160. int currentKills = MobHunt.Instance()->GetKillCount(mobHuntEntry.BillNumber, mobHuntEntry.MobIndex);
  161. ImGui.Text(mobHuntEntry.Name);
  162. if (ImGui.IsItemHovered()) {
  163. ImGui.PushStyleColor(ImGuiCol.PopupBg, Vector4.Zero);
  164. ImGui.BeginTooltip();
  165. InterfaceUtil.DrawHuntIcon(mobHuntEntry);
  166. ImGui.PopStyleColor();
  167. ImGui.EndTooltip();
  168. }
  169. ImGui.SameLine();
  170. if (currentKills != mobHuntEntry.NeededKills) {
  171. ImGui.Text($"({currentKills}/{mobHuntEntry.NeededKills})");
  172. }
  173. else {
  174. ImGui.TextColored(
  175. new Vector4(0f, 1f, 0f, 1f),
  176. $"({currentKills}/{mobHuntEntry.NeededKills})");
  177. }
  178. }
  179. ImGui.TreePop();
  180. }
  181. ImGui.TreePop();
  182. }
  183. }
  184. }