diff --git a/ActionTimelineEx/Helpers/DrawHelper.cs b/ActionTimelineEx/Helpers/DrawHelper.cs index b3cf16f..257a6b1 100644 --- a/ActionTimelineEx/Helpers/DrawHelper.cs +++ b/ActionTimelineEx/Helpers/DrawHelper.cs @@ -92,9 +92,6 @@ private static void CalculateColor() { var tex = Svc.Data.GetIcon(icon, false); - - Svc.Data.GetImGuiTexture(tex); - if(tex == null) { textureColorCache[icon] = uint.MaxValue; @@ -126,4 +123,11 @@ public static void SetTooltip(string message) ImGui.SetTooltip(message); } } + + public static bool IsInRect(Vector2 leftTop, Vector2 size) + { + var pos = ImGui.GetMousePos() - leftTop; + if (pos.X < 0 || pos.Y < 0 || pos.X > size.X || pos.Y > size.Y) return false; + return true; + } } diff --git a/ActionTimelineEx/Timeline/StatusLineItem.cs b/ActionTimelineEx/Timeline/StatusLineItem.cs index 63e97fc..df28947 100644 --- a/ActionTimelineEx/Timeline/StatusLineItem.cs +++ b/ActionTimelineEx/Timeline/StatusLineItem.cs @@ -1,9 +1,7 @@ -using ActionTimeline; -using ActionTimeline.Helpers; +using ActionTimeline.Helpers; using ActionTimelineEx.Configurations; using ImGuiNET; using ImGuiScene; -using System.Drawing; using System.Numerics; namespace ActionTimelineEx.Timeline; @@ -11,6 +9,7 @@ namespace ActionTimelineEx.Timeline; public class StatusLineItem : ITimelineItem { public uint Icon { get; set; } + public string? Name { get; set; } public float TimeDuration { get; set; } public DateTime StartTime { get; init; } @@ -53,13 +52,18 @@ public void DrawItemWithCenter(Vector2 centerPos, Vector2 windowPos, DrawingSett var rightBottom = leftTop + setting.TimeDirectionPerSecond * TimeDuration + setting.RealDownDirection * statusWidth - shrink; drawList.AddRectFilled(leftTop + shrink, rightBottom,col, rounding, flag); + if (!string.IsNullOrEmpty(Name) && DrawHelper.IsInRect(leftTop + shrink, rightBottom - leftTop - shrink)) ImGui.SetTooltip(Name); + if (rightBottom.X <= windowPos.X) return; leftTop.X = Math.Max(leftTop.X, windowPos.X); leftTop.Y = Math.Max(leftTop.Y, windowPos.Y); + var size = new Vector2(statusHeight / TimelineItem.HeightRatio, statusHeight); drawList.AddImage(texture.ImGuiHandle, leftTop, - leftTop + new Vector2(statusHeight / TimelineItem.HeightRatio, statusHeight), Vector2.Zero, Vector2.One); + leftTop + size , Vector2.Zero, Vector2.One); + if (!string.IsNullOrEmpty(Name) && DrawHelper.IsInRect(leftTop, size)) ImGui.SetTooltip(Name); + } } diff --git a/ActionTimelineEx/Timeline/TimelineItem.cs b/ActionTimelineEx/Timeline/TimelineItem.cs index 095ccf0..1e64579 100644 --- a/ActionTimelineEx/Timeline/TimelineItem.cs +++ b/ActionTimelineEx/Timeline/TimelineItem.cs @@ -3,6 +3,8 @@ using Dalamud.Interface; using ImGuiNET; using ImGuiScene; +using RotationSolver.Basic.Data; +using System.Drawing; using System.Numerics; namespace ActionTimelineEx.Timeline; @@ -30,8 +32,8 @@ public class TimelineItem : ITimelineItem public DateTime EndTime => StartTime + TimeSpan.FromSeconds(TimeDuration); - public HashSet StatusGainIcon { get; } = new(4); - public HashSet StatusLoseIcon { get; } = new(4); + public HashSet<(uint icon, string? name)> StatusGainIcon { get; } = new(4); + public HashSet<(uint icon, string? name)> StatusLoseIcon { get; } = new(4); public void Draw(DateTime time, Vector2 windowPos, Vector2 windowSize, TimelineLayer icon, DrawingSettings setting) { @@ -70,14 +72,14 @@ public void DrawItemWithCenter(Vector2 centerPos, TimelineLayer icon, DrawingSet } } - private static TextureWrap[] GetTextures(HashSet iconIds) + private static (TextureWrap texture, string? name)[] GetTextures(HashSet<(uint icon, string? name)> iconIds) { - var result = new List(iconIds.Count); + var result = new List<(TextureWrap texture, string? name)>(iconIds.Count); foreach (var item in iconIds) { - TextureWrap? texture = DrawHelper.GetTextureFromIconId(item); + TextureWrap? texture = DrawHelper.GetTextureFromIconId(item.icon); if (texture == null) continue; - result.Add(texture); + result.Add((texture, item.name)); } return result.ToArray(); } @@ -88,7 +90,10 @@ private void DrawItemWithCenter(ImDrawListPtr drawList, Vector2 centerPos, Vecto switch (icon) { case TimelineLayer.Icon: - drawList.DrawActionIcon(Icon, IsHq, centerPos - iconSize / 2 * setting.RealDownDirection, iconSize); + var pos = centerPos - iconSize / 2 * setting.RealDownDirection; + drawList.DrawActionIcon(Icon, IsHq, pos, iconSize); + if (!string.IsNullOrEmpty(Name) && DrawHelper.IsInRect(pos, new Vector2( iconSize))) ImGui.SetTooltip(Name); + return; case TimelineLayer.Status when setting.ShowStatus: @@ -109,8 +114,12 @@ private void DrawItemWithCenter(ImDrawListPtr drawList, Vector2 centerPos, Vecto } for (int i = 0; i < gains.Length; i++) { - drawList.AddImage(gains[i].ImGuiHandle, center, - center + new Vector2(statusSize, statusSize * HeightRatio), Vector2.Zero, Vector2.One, color); + var size = new Vector2(statusSize, statusSize * HeightRatio); + drawList.AddImage(gains[i].texture.ImGuiHandle, center, + center + size, Vector2.Zero, Vector2.One, color); + + var name = gains[i].name; + if (!string.IsNullOrEmpty(name) && DrawHelper.IsInRect(center, size)) ImGui.SetTooltip(name); drawList.AddText(UiBuilder.IconFont, statusSize / 2f, center, gainColor, FontAwesomeIcon.Plus.ToIconString()); @@ -118,8 +127,12 @@ private void DrawItemWithCenter(ImDrawListPtr drawList, Vector2 centerPos, Vecto } for (int i = 0; i < lose.Length; i++) { - drawList.AddImage(lose[i].ImGuiHandle, center, - center + new Vector2(statusSize, statusSize * HeightRatio), Vector2.Zero, Vector2.One, color); + var size = new Vector2(statusSize, statusSize * HeightRatio); + drawList.AddImage(lose[i].texture.ImGuiHandle, center, + center + size, Vector2.Zero, Vector2.One, color); + + var name = lose[i].name; + if (!string.IsNullOrEmpty(name) && DrawHelper.IsInRect(center, size)) ImGui.SetTooltip(name); drawList.AddText(UiBuilder.IconFont, statusSize / 2f, center, loseColor, FontAwesomeIcon.Ban.ToIconString()); diff --git a/ActionTimelineEx/Timeline/TimelineManager.cs b/ActionTimelineEx/Timeline/TimelineManager.cs index f435a77..033ae7e 100644 --- a/ActionTimelineEx/Timeline/TimelineManager.cs +++ b/ActionTimelineEx/Timeline/TimelineManager.cs @@ -193,11 +193,13 @@ private void CancelCasting() _lastItem.CastingTime = MathF.Min(maxTime, _lastItem.CastingTime); } - private uint GetStatusIcon(ushort id, bool isGain, byte stack = byte.MaxValue) + private uint GetStatusIcon(ushort id, bool isGain, out string? name, byte stack = byte.MaxValue) { + name = null; if (Plugin.Settings.HideStatusIds.Contains(id)) return 0; var status = Svc.Data.GetExcelSheet()?.GetRow(id); if (status == null) return 0; + name = status.Name; ShowedStatusId.Add(id); var icon = status.Icon; @@ -227,7 +229,7 @@ private void ActionFromSelf(ActionEffectSet set) if (set.Source.ObjectId != Player.Object.ObjectId || !Plugin.Settings.Record) return; DamageType damage = DamageType.None; - SortedSet statusGain = new (), statusLose = new (); + SortedSet<(uint, string?)> statusGain = new (), statusLose = new (); for (int i = 0; i < set.Header.TargetCount; i++) { @@ -250,14 +252,14 @@ private void ActionFromSelf(ActionEffectSet set) { case ActionEffectType.ApplyStatusEffectTarget when recordTarget: case ActionEffectType.ApplyStatusEffectSource: - var icon = GetStatusIcon(x.value, true); - if (icon != 0) statusGain.Add(icon); + var icon = GetStatusIcon(x.value, true, out var name); + if (icon != 0) statusGain.Add((icon, name)); break; case ActionEffectType.LoseStatusEffectTarget when recordTarget: case ActionEffectType.LoseStatusEffectSource: - icon = GetStatusIcon(x.value, false); - if (icon != 0) statusLose.Add(icon); + icon = GetStatusIcon(x.value, false, out name); + if (icon != 0) statusLose.Add((icon, name)); break; } }); @@ -338,11 +340,12 @@ private async void AddStatusLine(TimelineItem? effectItem, ulong targetId) List list = new List(4); foreach (var icon in effectItem.StatusGainIcon) { - if (Plugin.IconStack.TryGetValue(icon, out var stack)) + if (Plugin.IconStack.TryGetValue(icon.icon, out var stack)) { var item = new StatusLineItem() { - Icon = icon, + Icon = icon.icon, + Name = icon.name, TimeDuration = 6, Stack = stack, StartTime = effectItem.StartTime, @@ -401,7 +404,7 @@ private async void OnActorControl(uint entityId, ActorControlCategory type, uint case ActorControlCategory.LoseEffect when record: var stack = Player.Object?.StatusList.FirstOrDefault(s => s.StatusId == buffID && s.SourceId == Player.Object.ObjectId)?.StackCount ?? 0; - var icon = GetStatusIcon((ushort)buffID, false, ++stack); + var icon = GetStatusIcon((ushort)buffID, false, out var name, ++stack); if (icon == 0) break; var now = DateTime.Now; @@ -416,7 +419,7 @@ private async void OnActorControl(uint entityId, ActorControlCategory type, uint if (_lastItem != null && now < _lastTime) { - _lastItem.StatusLoseIcon.Add(icon); + _lastItem.StatusLoseIcon.Add((icon, name)); } break; @@ -428,14 +431,14 @@ private async void OnActorControl(uint entityId, ActorControlCategory type, uint // break; case ActorControlCategory.GainEffect when record: - icon = GetStatusIcon((ushort)buffID, true); + icon = GetStatusIcon((ushort)buffID, true, out name); if (icon == 0) break; now = DateTime.Now; await Task.Delay(10); if (_lastItem != null && now < _lastTime + TimeSpan.FromSeconds(0.01)) { - _lastItem?.StatusGainIcon.Add(icon); + _lastItem?.StatusGainIcon.Add((icon, name)); } break; diff --git a/ActionTimelineEx/Windows/TimelineWindow.cs b/ActionTimelineEx/Windows/TimelineWindow.cs index c781b47..8090f38 100644 --- a/ActionTimelineEx/Windows/TimelineWindow.cs +++ b/ActionTimelineEx/Windows/TimelineWindow.cs @@ -135,7 +135,11 @@ private static void DrawContent(DrawingSettings setting) ImGui.GetWindowDrawList().AddLine(pt, pt + downDirWhole, lineColor, setting.GridStartLineWidth); } - if (!setting.Locked) ImGui.Text(setting.Name); + if (!setting.Locked) + { + ImGui.SetCursorPos(Vector2.Zero); + ImGui.Text(setting.Name); + } } private static void DrawGrid(Vector2 pos, Vector2 timeDirWhole, Vector2 downDirWhole, DrawingSettings setting)