MainWindow.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using System.Linq;
  2. using System.Numerics;
  3. using System.Threading.Tasks;
  4. using Dalamud.Interface;
  5. using Dalamud.Interface.Windowing;
  6. using ImGuiNET;
  7. using HuntBuddy.Utils;
  8. namespace HuntBuddy.Windows;
  9. /// <summary>
  10. /// Main plugin window.
  11. /// </summary>
  12. public class MainWindow : Window
  13. {
  14. public MainWindow() : base(
  15. $"{Plugin.Instance.Name}",
  16. ImGuiWindowFlags.NoDocking,
  17. true)
  18. {
  19. this.Size = new Vector2(400 * ImGui.GetIO().FontGlobalScale, 500);
  20. this.SizeCondition = ImGuiCond.Once;
  21. }
  22. public override void PreOpenCheck()
  23. {
  24. if (Plugin.Instance.Configuration.LockWindowPositions)
  25. {
  26. if (!this.Flags.HasFlag(ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove))
  27. {
  28. this.Flags |= ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove;
  29. }
  30. }
  31. else
  32. {
  33. this.Flags &= ~(ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove);
  34. }
  35. }
  36. public override unsafe void Draw()
  37. {
  38. if (!Plugin.Instance.MobHuntEntriesReady)
  39. {
  40. ImGui.Text("Reloading data ...");
  41. return;
  42. }
  43. if (InterfaceUtil.IconButton(FontAwesomeIcon.Redo, "Reload"))
  44. {
  45. Plugin.Instance.MobHuntEntriesReady = false;
  46. Task.Run(Plugin.Instance.ReloadData);
  47. return;
  48. }
  49. if (ImGui.IsItemHovered())
  50. {
  51. ImGui.BeginTooltip();
  52. ImGui.Text("Click this button to reload daily hunt data");
  53. ImGui.EndTooltip();
  54. }
  55. ImGui.SameLine();
  56. if (InterfaceUtil.IconButton(FontAwesomeIcon.Cog, "Config"))
  57. {
  58. Plugin.Instance.OpenConfigUi();
  59. }
  60. foreach (var expansionEntry in Plugin.Instance.MobHuntEntries.Where(
  61. expansionEntry =>
  62. ImGui.TreeNode(expansionEntry.Key)))
  63. {
  64. foreach (var entry in expansionEntry.Value.Where(
  65. entry =>
  66. {
  67. var treeOpen = ImGui.TreeNodeEx(entry.Key.Value, ImGuiTreeNodeFlags.AllowItemOverlap);
  68. ImGui.SameLine();
  69. var killedCount = entry.Value.Count(
  70. x =>
  71. Plugin.Instance.MobHuntStruct->CurrentKills[x.CurrentKillsOffset] ==
  72. x.NeededKills);
  73. if (killedCount != entry.Value.Count)
  74. {
  75. ImGui.Text($"({killedCount}/{entry.Value.Count})");
  76. }
  77. else
  78. {
  79. ImGui.TextColored(
  80. new Vector4(0f, 1f, 0f, 1f),
  81. $"({killedCount}/{entry.Value.Count})");
  82. }
  83. return treeOpen;
  84. }))
  85. {
  86. foreach (var mobHuntEntry in entry.Value)
  87. {
  88. if (Location.Database.ContainsKey(mobHuntEntry.MobHuntId))
  89. {
  90. if (InterfaceUtil.IconButton(FontAwesomeIcon.MapMarkerAlt, $"pin##{mobHuntEntry.MobHuntId}"))
  91. {
  92. Location.CreateMapMarker(
  93. mobHuntEntry.TerritoryType,
  94. mobHuntEntry.MapId,
  95. mobHuntEntry.MobHuntId,
  96. mobHuntEntry.Name,
  97. Location.OpenType.None);
  98. }
  99. if (ImGui.IsItemHovered())
  100. {
  101. ImGui.BeginTooltip();
  102. ImGui.Text("Place marker on the map");
  103. ImGui.EndTooltip();
  104. }
  105. ImGui.SameLine();
  106. if (InterfaceUtil.IconButton(FontAwesomeIcon.MapMarkedAlt, $"open##{mobHuntEntry.MobHuntId}"))
  107. {
  108. var includeArea = Plugin.Instance.Configuration.IncludeAreaOnMap;
  109. if (ImGui.IsKeyDown(ImGuiKey.ModShift))
  110. {
  111. includeArea = !includeArea;
  112. }
  113. Location.CreateMapMarker(
  114. mobHuntEntry.TerritoryType,
  115. mobHuntEntry.MapId,
  116. mobHuntEntry.MobHuntId,
  117. mobHuntEntry.Name,
  118. includeArea ? Location.OpenType.ShowOpen : Location.OpenType.MarkerOpen);
  119. }
  120. if (ImGui.IsItemHovered())
  121. {
  122. var color = ImGui.IsKeyDown(ImGuiKey.ModShift)
  123. ? new Vector4(0f, 0.7f, 0f, 1f)
  124. : new Vector4(0.7f, 0.7f, 0.7f, 1f);
  125. ImGui.BeginTooltip();
  126. if (Plugin.Instance.Configuration.IncludeAreaOnMap)
  127. {
  128. ImGui.Text("Show hunt area on the map");
  129. ImGui.TextColored(
  130. color,
  131. "Hold [SHIFT] to show the location only");
  132. }
  133. else
  134. {
  135. ImGui.Text("Show hunt location on the map");
  136. ImGui.TextColored(
  137. color,
  138. "Hold [SHIFT] to include the area");
  139. }
  140. ImGui.EndTooltip();
  141. }
  142. ImGui.SameLine();
  143. if (Plugin.TeleportConsumer?.IsAvailable == true)
  144. {
  145. if (InterfaceUtil.IconButton(FontAwesomeIcon.StreetView, $"t##{mobHuntEntry.MobHuntId}"))
  146. {
  147. Location.TeleportToNearestAetheryte(
  148. mobHuntEntry.TerritoryType,
  149. mobHuntEntry.MapId,
  150. mobHuntEntry.MobHuntId);
  151. }
  152. if (ImGui.IsItemHovered())
  153. {
  154. ImGui.BeginTooltip();
  155. ImGui.Text("Teleport to nearest aetheryte");
  156. ImGui.EndTooltip();
  157. }
  158. ImGui.SameLine();
  159. }
  160. }
  161. var currentKills = Plugin.Instance.MobHuntStruct->CurrentKills[mobHuntEntry.CurrentKillsOffset];
  162. ImGui.Text(mobHuntEntry.Name);
  163. if (ImGui.IsItemHovered())
  164. {
  165. ImGui.PushStyleColor(ImGuiCol.PopupBg, Vector4.Zero);
  166. ImGui.BeginTooltip();
  167. InterfaceUtil.DrawHuntIcon(mobHuntEntry);
  168. ImGui.PopStyleColor();
  169. ImGui.EndTooltip();
  170. }
  171. ImGui.SameLine();
  172. if (currentKills != mobHuntEntry.NeededKills)
  173. {
  174. ImGui.Text($"({currentKills}/{mobHuntEntry.NeededKills})");
  175. }
  176. else
  177. {
  178. ImGui.TextColored(
  179. new Vector4(0f, 1f, 0f, 1f),
  180. $"({currentKills}/{mobHuntEntry.NeededKills})");
  181. }
  182. }
  183. ImGui.TreePop();
  184. }
  185. ImGui.TreePop();
  186. }
  187. }
  188. }