MainWindow.cs 5.9 KB

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