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

Commit

Permalink
feat: add multi window option.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jul 19, 2023
1 parent 18fc442 commit e47e09a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 76 deletions.
4 changes: 2 additions & 2 deletions ActionTimelineEx/Configurations/DrawingSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DrawingSettings
public float CenterOffset = 0;

public int TimeOffsetSetting = 2;
public int TimeOffset => IsRotation ? 0 : TimeOffsetSetting;
public int TimeOffset => IsRotation ? -TimeOffsetSetting : TimeOffsetSetting;
public int GCDIconSize = 40;

public bool ShowOGCD = true;
Expand Down Expand Up @@ -64,7 +64,7 @@ public class DrawingSettings
public bool GridSubdivideSeconds = true;
public int GridSubdivisionCount = 2;
public float GridLineWidth = 1;
public float GridCenterLineWidth = 0.1f;
public float GridCenterLineWidth = 1f;
public float GridStartLineWidth = 3;
public float GridSubdivisionLineWidth = 1;
public Vector4 GridLineColor = new Vector4(0.3f, 0.3f, 0.3f, 1f);
Expand Down
2 changes: 1 addition & 1 deletion ActionTimelineEx/Configurations/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Settings : IPluginConfiguration
public bool ShowTimelineOnlyInDuty = false;
public bool ShowTimelineOnlyInCombat = false;
//public float StatusCheckDelay = 0.1f;
public List<DrawingSettings> TimelineSettings = new() { new DrawingSettings() };
public List<DrawingSettings> TimelineSettings = new();
public HashSet<ushort> HideStatusIds = new HashSet<ushort>();
public bool PrintClipping = false;
public int PrintClippingMin = 150;
Expand Down
15 changes: 3 additions & 12 deletions ActionTimelineEx/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ActionTimeline.Windows;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Interface.Windowing;
using Dalamud.Logging;
using Dalamud.Plugin;
using ECommons;
using ECommons.Commands;
Expand Down Expand Up @@ -138,21 +139,11 @@ private void Draw()

if (!ShowTimeline()) return;

ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0, 0));
ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0);

HashSet<string> showedName = new HashSet<string>();
int index = 0;
foreach (var setting in Settings.TimelineSettings)
{
if (showedName.Contains(setting.Name)) continue;

TimelineWindow.Draw(setting);

showedName.Add(setting.Name);
TimelineWindow.Draw(setting, index++);
}

ImGui.PopStyleColor();
ImGui.PopStyleVar(2);
}

private bool ShowTimeline()
Expand Down
57 changes: 8 additions & 49 deletions ActionTimelineEx/Timeline/TimelineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected void Dispose(bool disposing)
public static SortedSet<ushort> ShowedStatusId { get; } = new SortedSet<ushort>();

public DateTime EndTime { get; private set; } = DateTime.Now;
private static int kMaxItemCount = 128;
private static int kMaxItemCount = 2048;
private readonly Queue<TimelineItem> _items = new Queue<TimelineItem>(kMaxItemCount);
private TimelineItem? _lastItem = null;

Expand Down Expand Up @@ -109,7 +109,7 @@ public List<TimelineItem> GetItems(DateTime time, out DateTime lastEndTime)
return GetItems(_items, time, out lastEndTime);
}

private static int kMaxStatusCount = 16;
private static int kMaxStatusCount = 256;
private readonly Queue<StatusLineItem> _statusItems = new Queue<StatusLineItem>(kMaxStatusCount);
private void AddItem(StatusLineItem item)
{
Expand Down Expand Up @@ -156,7 +156,6 @@ public unsafe float GCD

private static TimelineItemType GetActionType(uint actionId, ActionType type)
{

switch (type)
{
case ActionType.Spell:
Expand Down Expand Up @@ -316,46 +315,6 @@ private void ActionFromSelf(ActionEffectSet set)

UpdateEndTime(effectItem.EndTime);


//int statusDelay = 0;
//if (Plugin.Settings.StatusCheckDelay is > 0 and < 0.5f)
//{
// statusDelay = (int)(Plugin.Settings.StatusCheckDelay * 1000);
// var previousStatus = Player.Object.StatusList
// .Where(s => s.SourceId == Player.Object.ObjectId && (s.RemainingTime > Plugin.Settings.StatusCheckDelay || s.RemainingTime <= 0))
// .Select(s => (s.StatusId, s.StackCount))
// .ToArray();

// await Task.Delay(statusDelay);

// var nowStatus = Player.Object.StatusList
// .Where(s => s.SourceId == Player.Object.ObjectId)
// .Select(s => (s.StatusId, s.StackCount))
// .ToArray();

// foreach (var pre in previousStatus)
// {
// var status = Svc.Data.GetExcelSheet<Status>()?.GetRow(pre.StatusId);
// if (status == null) continue;
// var now = nowStatus.FirstOrDefault(i => i.StatusId == pre.StatusId);
// if (now.StatusId == 0 || now.StackCount < pre.StackCount)
// {
// effectItem?.StatusLoseIcon.Add(status.Icon + (uint)Math.Max(0, pre.StackCount - 1));
// }
// }

// foreach (var now in nowStatus)
// {
// var status = Svc.Data.GetExcelSheet<Status>()?.GetRow(now.StatusId);
// if (status == null) continue;
// var pre = previousStatus.FirstOrDefault(i => i.StatusId == now.StatusId);
// if (pre.StatusId == 0)
// {
// effectItem?.StatusGainIcon.Add(status.Icon + (uint)Math.Max(0, now.StackCount - 1));
// }
// }
//}

AddStatusLine(effectItem, set.TargetEffects[0].TargetID);
}

Expand Down Expand Up @@ -413,12 +372,12 @@ private async void OnActorControl(uint entityId, ActorControlCategory type, uint

_onActorControlHook?.Original(entityId, type, buffID, direct, actionId, sourceId, arg4, arg5, targetId, a10);

//#if DEBUG
// if (buffID == 122)
// {
// Svc.Chat.Print($"Type: {type}, Buff: {buffID}, Direct: {direct}, Action: {actionId}, Source: {sourceId}, Arg4: {arg4}, Arg5: {arg5}, Target: {targetId}, a10: {a10}");
// }
//#endif
//#if DEBUG
// if (buffID == 122)
// {
// Svc.Chat.Print($"Type: {type}, Buff: {buffID}, Direct: {direct}, Action: {actionId}, Source: {sourceId}, Arg4: {arg4}, Arg5: {arg5}, Target: {targetId}, a10: {a10}");
// }
//#endif

if (entityId != Player.Object?.ObjectId) return;

Expand Down
14 changes: 9 additions & 5 deletions ActionTimelineEx/Windows/SettingsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ public override void Draw()
int index = 0;
DrawingSettings? removingSetting = null;

if (!Settings.TimelineSettings.Any()) Settings.TimelineSettings.Add(new DrawingSettings());

foreach (var setting in Settings.TimelineSettings)
{
var duplicated = showedName.Contains(setting.Name);
if (duplicated) ImGui.PushStyleColor(ImGuiCol.Text, ImGui.ColorConvertFloat4ToU32(ImGuiColors.DalamudRed));
if (duplicated) ImGui.PushStyleColor(ImGuiCol.Text, ImGui.ColorConvertFloat4ToU32(ImGuiColors.DPSRed));

var showTab = ImGui.BeginTabItem($"TL:{index}");
if (duplicated) ImGui.PopStyleColor();

if (ImGui.BeginTabItem($"TL:{setting.Name}"))
if (showTab)
{
if(duplicated) ImGui.PopStyleColor();
if (DrawTimelineSetting(setting))
{
removingSetting = setting;
Expand Down Expand Up @@ -114,7 +118,7 @@ private void DrawHelp()
private ushort _aboutAdd = 0;
private void DrawGeneralSetting()
{
if(ImGui.Button("Add One Timeline"))
if (ImGui.Button("Add One Timeline"))
{
Settings.TimelineSettings.Add(new DrawingSettings()
{
Expand Down Expand Up @@ -284,7 +288,7 @@ private bool RemoveValue(string name)
if (isLast) ImGui.PushStyleColor(ImGuiCol.Text, isTime ? ImGuiColors.HealerGreen : ImGuiColors.DPSRed);

ImGui.PushFont(UiBuilder.IconFont);
if (ImGui.Button($"{(isLast ? FontAwesomeIcon.Check : FontAwesomeIcon.Undo).ToIconString()}##Remove{name}"))
if (ImGui.Button($"{(isLast ? FontAwesomeIcon.Check : FontAwesomeIcon.Ban).ToIconString()}##Remove{name}"))
{
if (isLast && isTime)
{
Expand Down
24 changes: 17 additions & 7 deletions ActionTimelineEx/Windows/TimelineWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal static class TimelineWindow
| ImGuiWindowFlags.NoNav
| ImGuiWindowFlags.NoScrollWithMouse;

public static void Draw(DrawingSettings setting)
public static void Draw(DrawingSettings setting, int index)
{
if (!setting.Enable || string.IsNullOrEmpty(setting.Name)) return;

Expand All @@ -31,12 +31,17 @@ public static void Draw(DrawingSettings setting)
ImGui.SetNextWindowSize(new Vector2(560, 100) * ImGuiHelpers.GlobalScale, ImGuiCond.FirstUseEver);
ImGui.SetNextWindowPos(new Vector2(200, 200) * ImGuiHelpers.GlobalScale, ImGuiCond.FirstUseEver);

if (ImGui.Begin($"Timeline: {setting.Name}", flag))
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0, 0));
ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0);

if (ImGui.Begin($"Timeline: {index}", flag))
{
DrawContent(setting);
ImGui.End();
}

ImGui.PopStyleVar(2);

ImGui.PopStyleColor();
}

Expand All @@ -52,7 +57,7 @@ private static void DrawContent(DrawingSettings setting)
var pos = ImGui.GetWindowPos();
var size = ImGui.GetWindowSize();

var now = setting.IsRotation ? (TimelineManager.Instance?.EndTime ?? DateTime.Now - TimeSpan.FromSeconds(setting.TimeOffsetSetting)) : DateTime.Now;
var now = setting.IsRotation ? (TimelineManager.Instance?.EndTime ?? DateTime.Now - TimeSpan.FromSeconds(setting.TimeOffset)) : DateTime.Now;

var endTime = now - TimeSpan.FromSeconds(size.X / setting.SizePerSecond - setting.TimeOffset);

Expand Down Expand Up @@ -115,10 +120,14 @@ private static void DrawContent(DrawingSettings setting)
}
}

uint lineColor = ImGui.ColorConvertFloat4ToU32(setting.GridStartLineColor);
if (!setting.IsRotation)
{
uint lineColor = ImGui.ColorConvertFloat4ToU32(setting.GridStartLineColor);

var x = pos.X + size.X - setting.TimeOffset * setting.SizePerSecond;
ImGui.GetWindowDrawList().AddLine(new Vector2(x, pos.Y), new Vector2(x, pos.Y + size.Y), lineColor, setting.GridStartLineWidth);
var x = pos.X + size.X - setting.TimeOffset * setting.SizePerSecond;

ImGui.GetWindowDrawList().AddLine(new Vector2(x, pos.Y), new Vector2(x, pos.Y + size.Y), lineColor, setting.GridStartLineWidth);
}

if (!setting.Locked) ImGui.Text(setting.Name);
}
Expand Down Expand Up @@ -153,11 +162,12 @@ private static void DrawGrid(Vector2 pos, Vector2 size, DrawingSettings setting)
}
var time = -i + setting.TimeOffset;

if (time != 0)
if (time != 0 || setting.IsRotation)
{
drawList.AddLine(new Vector2(start, pos.Y), new Vector2(start, pos.Y + height), lineColor, setting.GridLineWidth);
}

if (setting.IsRotation) time -= setting.TimeOffsetSetting;
if (setting.GridShowSecondsText)
{
drawList.AddText(new Vector2(start + 2, pos.Y), lineColor, $" {time}s");
Expand Down

0 comments on commit e47e09a

Please sign in to comment.