Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add tooltip for every actions and status.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 19, 2023
1 parent 0814d35 commit b698f18
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 31 deletions.
10 changes: 7 additions & 3 deletions ActionTimelineEx/Helpers/DrawHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
12 changes: 8 additions & 4 deletions ActionTimelineEx/Timeline/StatusLineItem.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using ActionTimeline;
using ActionTimeline.Helpers;
using ActionTimeline.Helpers;
using ActionTimelineEx.Configurations;
using ImGuiNET;
using ImGuiScene;
using System.Drawing;
using System.Numerics;

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; }

Expand Down Expand Up @@ -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);

}
}
35 changes: 24 additions & 11 deletions ActionTimelineEx/Timeline/TimelineItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Dalamud.Interface;
using ImGuiNET;
using ImGuiScene;
using RotationSolver.Basic.Data;
using System.Drawing;
using System.Numerics;

namespace ActionTimelineEx.Timeline;
Expand Down Expand Up @@ -30,8 +32,8 @@ public class TimelineItem : ITimelineItem

public DateTime EndTime => StartTime + TimeSpan.FromSeconds(TimeDuration);

public HashSet<uint> StatusGainIcon { get; } = new(4);
public HashSet<uint> 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)
{
Expand Down Expand Up @@ -70,14 +72,14 @@ public void DrawItemWithCenter(Vector2 centerPos, TimelineLayer icon, DrawingSet
}
}

private static TextureWrap[] GetTextures(HashSet<uint> iconIds)
private static (TextureWrap texture, string? name)[] GetTextures(HashSet<(uint icon, string? name)> iconIds)
{
var result = new List<TextureWrap>(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();
}
Expand All @@ -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:
Expand All @@ -109,17 +114,25 @@ 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());

center += setting.TimeDirection * statusStep;
}
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());

Expand Down
27 changes: 15 additions & 12 deletions ActionTimelineEx/Timeline/TimelineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Status>()?.GetRow(id);
if (status == null) return 0;
name = status.Name;

ShowedStatusId.Add(id);
var icon = status.Icon;
Expand Down Expand Up @@ -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<uint> statusGain = new (), statusLose = new ();
SortedSet<(uint, string?)> statusGain = new (), statusLose = new ();

for (int i = 0; i < set.Header.TargetCount; i++)
{
Expand All @@ -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;
}
});
Expand Down Expand Up @@ -338,11 +340,12 @@ private async void AddStatusLine(TimelineItem? effectItem, ulong targetId)
List<StatusLineItem> list = new List<StatusLineItem>(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,
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand Down
6 changes: 5 additions & 1 deletion ActionTimelineEx/Windows/TimelineWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b698f18

Please sign in to comment.