| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- using System.Linq;
- using System.Numerics;
- using System.Threading.Tasks;
- using Dalamud.Interface;
- using ImGuiNET;
- namespace HuntBuddy
- {
- public class Interface
- {
- private readonly Plugin plugin;
- public bool DrawInterface;
- private bool drawConfigurationInterface;
- public Interface(Plugin plugin)
- {
- this.plugin = plugin;
- }
- public unsafe bool Draw()
- {
- var draw = true;
- ImGui.SetNextWindowSize(new Vector2(400 * ImGui.GetIO().FontGlobalScale, 500), ImGuiCond.Once);
- if (!ImGui.Begin($"{this.plugin.Name}", ref draw, ImGuiWindowFlags.NoDocking))
- {
- return draw;
- }
- if (!this.plugin.MobHuntEntriesReady)
- {
- ImGui.Text("Reloading data ...");
- ImGui.End();
- return draw;
- }
- if (Interface.IconButton(FontAwesomeIcon.Redo, "Reload"))
- {
- ImGui.End();
- this.plugin.MobHuntEntriesReady = false;
- Task.Run(() => this.plugin.ReloadData());
- return draw;
- }
- if (ImGui.IsItemHovered())
- {
- ImGui.BeginTooltip();
- ImGui.Text("Click this button to reload daily hunt data");
- ImGui.EndTooltip();
- }
- ImGui.SameLine();
- if (Interface.IconButton(FontAwesomeIcon.Cog, "Config"))
- {
- this.drawConfigurationInterface = !this.drawConfigurationInterface;
- }
- foreach (var expansionEntry in this.plugin.MobHuntEntries.Where(
- expansionEntry =>
- ImGui.TreeNode(expansionEntry.Key)))
- {
- foreach (var entry in expansionEntry.Value.Where(
- entry =>
- {
- var treeOpen = ImGui.TreeNodeEx(entry.Key.Value, ImGuiTreeNodeFlags.AllowItemOverlap);
- ImGui.SameLine();
- var killedCount = entry.Value.Count(
- x =>
- this.plugin.MobHuntStruct->CurrentKills[x.CurrentKillsOffset] ==
- x.NeededKills);
- if (killedCount != entry.Value.Count)
- {
- ImGui.Text($"({killedCount}/{entry.Value.Count})");
- }
- else
- {
- ImGui.TextColored(
- new Vector4(0f, 1f, 0f, 1f),
- $"({killedCount}/{entry.Value.Count})");
- }
- return treeOpen;
- }))
- {
- ImGui.Indent();
- foreach (var mobHuntEntry in entry.Value)
- {
- if (Location.Database.ContainsKey(mobHuntEntry.MobHuntId))
- {
- if (Interface.IconButton(FontAwesomeIcon.MapMarkerAlt, $"pin##{mobHuntEntry.MobHuntId}"))
- {
- Location.CreateMapMarker(
- mobHuntEntry.TerritoryType,
- mobHuntEntry.MapId,
- mobHuntEntry.MobHuntId,
- mobHuntEntry.Name,
- Location.OpenType.None);
- }
- if (ImGui.IsItemHovered())
- {
- ImGui.BeginTooltip();
- ImGui.Text("Place marker on the map");
- ImGui.EndTooltip();
- }
- ImGui.SameLine();
- if (Interface.IconButton(FontAwesomeIcon.Compass, $"openRadius##{mobHuntEntry.MobHuntId}"))
- {
- Location.CreateMapMarker(
- mobHuntEntry.TerritoryType,
- mobHuntEntry.MapId,
- mobHuntEntry.MobHuntId,
- mobHuntEntry.Name,
- Location.OpenType.ShowOpen);
- }
- if (ImGui.IsItemHovered())
- {
- ImGui.BeginTooltip();
- ImGui.Text("Show hunt location on the map");
- ImGui.EndTooltip();
- }
- ImGui.SameLine();
- if (Interface.IconButton(FontAwesomeIcon.MapMarkedAlt, $"open##{mobHuntEntry.MobHuntId}"))
- {
- Location.CreateMapMarker(
- mobHuntEntry.TerritoryType,
- mobHuntEntry.MapId,
- mobHuntEntry.MobHuntId,
- mobHuntEntry.Name);
- }
- if (ImGui.IsItemHovered())
- {
- ImGui.BeginTooltip();
- ImGui.Text("Show hunt location on the map");
- ImGui.EndTooltip();
- }
- ImGui.SameLine();
- if (Plugin.TeleportConsumer?.Subscribed == true)
- {
- if (Interface.IconButton(FontAwesomeIcon.StreetView, $"t##{mobHuntEntry.MobHuntId}"))
- {
- Location.TeleportToNearestAetheryte(
- mobHuntEntry.TerritoryType,
- mobHuntEntry.MapId,
- mobHuntEntry.MobHuntId);
- }
- if (ImGui.IsItemHovered())
- {
- ImGui.BeginTooltip();
- ImGui.Text("Teleport to nearest aetheryte");
- ImGui.EndTooltip();
- }
- ImGui.SameLine();
- }
- }
- var currentKills = this.plugin.MobHuntStruct->CurrentKills[mobHuntEntry.CurrentKillsOffset];
- ImGui.Text(mobHuntEntry.Name);
- if (ImGui.IsItemHovered())
- {
- ImGui.PushStyleColor(ImGuiCol.PopupBg, Vector4.Zero);
- ImGui.BeginTooltip();
- this.DrawHuntIcon(mobHuntEntry);
- ImGui.PopStyleColor();
- ImGui.EndTooltip();
- }
- ImGui.SameLine();
- if (currentKills != mobHuntEntry.NeededKills)
- {
- ImGui.Text($"({currentKills}/{mobHuntEntry.NeededKills})");
- }
- else
- {
- ImGui.TextColored(
- new Vector4(0f, 1f, 0f, 1f),
- $"({currentKills}/{mobHuntEntry.NeededKills})");
- }
- }
- ImGui.Unindent();
- ImGui.TreePop();
- }
- ImGui.TreePop();
- }
- ImGui.End();
- if (this.drawConfigurationInterface)
- {
- this.DrawConfiguration();
- }
- return draw;
- }
- public unsafe void DrawLocalHunts()
- {
- if (!this.plugin.Configuration.ShowLocalHunts ||
- this.plugin.CurrentAreaMobHuntEntries.IsEmpty ||
- this.plugin.CurrentAreaMobHuntEntries.Count(
- x =>
- this.plugin.MobHuntStruct->CurrentKills[x.CurrentKillsOffset] == x.NeededKills) ==
- this.plugin.CurrentAreaMobHuntEntries.Count)
- {
- return;
- }
- ImGui.SetNextWindowSize(Vector2.Zero, ImGuiCond.Always);
- var windowFlags = ImGuiWindowFlags.NoNavInputs | ImGuiWindowFlags.NoDocking;
- if (this.plugin.Configuration.HideLocalHuntBackground)
- {
- windowFlags |= ImGuiWindowFlags.NoBackground;
- }
- if (!ImGui.Begin("Hunts in current area", windowFlags))
- {
- return;
- }
- foreach (var mobHuntEntry in this.plugin.CurrentAreaMobHuntEntries)
- {
- var currentKills = this.plugin.MobHuntStruct->CurrentKills[mobHuntEntry.CurrentKillsOffset];
- if (this.plugin.Configuration.HideCompletedHunts && currentKills == mobHuntEntry.NeededKills)
- {
- continue;
- }
- if (Location.Database.ContainsKey(mobHuntEntry.MobHuntId))
- {
- if (Interface.IconButton(FontAwesomeIcon.MapMarkerAlt, $"pin##{mobHuntEntry.MobHuntId}"))
- {
- Location.CreateMapMarker(
- mobHuntEntry.TerritoryType,
- mobHuntEntry.MapId,
- mobHuntEntry.MobHuntId,
- mobHuntEntry.Name,
- Location.OpenType.None);
- }
- if (ImGui.IsItemHovered())
- {
- ImGui.BeginTooltip();
- ImGui.Text("Place marker on the map");
- ImGui.EndTooltip();
- }
- ImGui.SameLine();
- if (Interface.IconButton(FontAwesomeIcon.Compass, $"openRadius##{mobHuntEntry.MobHuntId}"))
- {
- Location.CreateMapMarker(
- mobHuntEntry.TerritoryType,
- mobHuntEntry.MapId,
- mobHuntEntry.MobHuntId,
- mobHuntEntry.Name,
- Location.OpenType.ShowOpen);
- }
- if (ImGui.IsItemHovered())
- {
- ImGui.BeginTooltip();
- ImGui.Text("Show hunt location on the map");
- ImGui.EndTooltip();
- }
- ImGui.SameLine();
- if (Interface.IconButton(FontAwesomeIcon.MapMarkedAlt, $"open##{mobHuntEntry.MobHuntId}"))
- {
- Location.CreateMapMarker(
- mobHuntEntry.TerritoryType,
- mobHuntEntry.MapId,
- mobHuntEntry.MobHuntId,
- mobHuntEntry.Name);
- }
- if (ImGui.IsItemHovered())
- {
- ImGui.BeginTooltip();
- ImGui.Text("Show hunt location on the map");
- ImGui.EndTooltip();
- }
- ImGui.SameLine();
- }
- ImGui.Text($"{mobHuntEntry.Name} ({currentKills}/{mobHuntEntry.NeededKills})");
- if (!this.plugin.Configuration.ShowLocalHuntIcons)
- {
- continue;
- }
- this.DrawHuntIcon(mobHuntEntry);
- }
- ImGui.End();
- }
- private void DrawConfiguration()
- {
- ImGui.SetNextWindowSize(Vector2.Zero, ImGuiCond.Always);
- if (!ImGui.Begin($"{this.plugin.Name} settings", ImGuiWindowFlags.NoDocking))
- {
- return;
- }
- var save = false;
- save |= ImGui.Checkbox("Show hunts in local area", ref this.plugin.Configuration.ShowLocalHunts);
- save |= ImGui.Checkbox(
- "Show icons of hunts in local area",
- ref this.plugin.Configuration.ShowLocalHuntIcons);
- save |= ImGui.Checkbox(
- "Hide background of local hunts window",
- ref this.plugin.Configuration.HideLocalHuntBackground);
- save |= ImGui.Checkbox(
- "Hide completed targets in local hunts window",
- ref this.plugin.Configuration.HideCompletedHunts);
- save |= ImGui.SliderFloat("Hunt icon scale", ref this.plugin.Configuration.IconScale, 0.2f, 2f, "%.2f");
- if (ImGui.ColorEdit4("Hunt icon background colour", ref this.plugin.Configuration.IconBackgroundColour))
- {
- this.plugin.Configuration.IconBackgroundColourU32 =
- ImGui.ColorConvertFloat4ToU32(this.plugin.Configuration.IconBackgroundColour);
- save = true;
- }
- if (save)
- {
- this.plugin.Configuration.Save();
- }
- ImGui.End();
- }
- private static bool IconButton(FontAwesomeIcon icon, string? id = null)
- {
- ImGui.PushFont(UiBuilder.IconFont);
- var text = icon.ToIconString();
- if (id != null)
- {
- text += $"##{id}";
- }
- var result = ImGui.Button(text);
- ImGui.PopFont();
- return result;
- }
- private void DrawHuntIcon(MobHuntEntry mobHuntEntry)
- {
- var cursorPos = ImGui.GetCursorScreenPos();
- var imageSize = mobHuntEntry.ExpansionId < 3 ? new Vector2(192f, 128f) : new Vector2(210f);
- imageSize *= ImGui.GetIO().FontGlobalScale * this.plugin.Configuration.IconScale;
- ImGui.InvisibleButton("canvas", imageSize);
- var drawList = ImGui.GetWindowDrawList();
- if (mobHuntEntry is { ExpansionId: 4, IsEliteMark: false }) // Endwalker uses circle for non elite mobs
- {
- drawList.AddCircleFilled(
- cursorPos + (imageSize / 2f),
- imageSize.X / 2f,
- this.plugin.Configuration.IconBackgroundColourU32);
- }
- else
- {
- drawList.AddRectFilled(
- cursorPos,
- cursorPos + imageSize,
- this.plugin.Configuration.IconBackgroundColourU32);
- }
- drawList.AddImage(mobHuntEntry.Icon.ImGuiHandle, cursorPos, cursorPos + imageSize);
- }
- }
- }
|