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

Commit

Permalink
feat: Multi Timeline!
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jul 19, 2023
1 parent 11b8cf1 commit 1fdaa80
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 107 deletions.
2 changes: 2 additions & 0 deletions ActionTimelineEx/Configurations/DrawingSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace ActionTimelineEx.Configurations;

public class DrawingSettings
{
public string Name = "Major";

public bool Enable = true;
public bool IsRotation = false;

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 DrawingSettings TimelineSetting = new DrawingSettings();
public List<DrawingSettings> TimelineSettings = new() { new DrawingSettings() };
public HashSet<ushort> HideStatusIds = new HashSet<ushort>();
public bool PrintClipping = false;
public int PrintClippingMin = 150;
Expand Down
70 changes: 34 additions & 36 deletions ActionTimelineEx/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using ECommons.Commands;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using ImGuiNET;
using System.Numerics;

namespace ActionTimeline;

Expand Down Expand Up @@ -102,20 +104,16 @@ private void PluginCommand(string command, string arguments)
var sub = arguments.Split(' ').FirstOrDefault();
if(string.Equals("unlock", sub, StringComparison.OrdinalIgnoreCase))
{
foreach (var window in _windowSystem.Windows)
foreach (var setting in Settings.TimelineSettings)
{
if (window is not TimelineWindow tWindow) continue;

tWindow.Setting.Locked = false;
setting.Locked = false;
}
}
else if (string.Equals("lock", sub, StringComparison.OrdinalIgnoreCase))
{
foreach (var window in _windowSystem.Windows)
foreach (var setting in Settings.TimelineSettings)
{
if (window is not TimelineWindow tWindow) continue;

tWindow.Setting.Locked = true;
setting.Locked = true;
}
}
else
Expand All @@ -130,43 +128,46 @@ private void CreateWindows()

_windowSystem = new WindowSystem("ActionTimeline_Windows");
_windowSystem.AddWindow(_settingsWindow);
_windowSystem.AddWindow(new TimelineWindow("Timeline1")
{
Setting = Settings.TimelineSetting,
});
}

private void Draw()
{
if (Settings == null || !Player.Available) return;

UpdateTimeline();

_windowSystem?.Draw();

if (!ShowTimeline()) return;

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

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

TimelineWindow.Draw(setting);

showedName.Add(setting.Name);
}

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

private void UpdateTimeline()
private bool ShowTimeline()
{
foreach (var window in _windowSystem.Windows)
if (Settings.ShowTimelineOnlyInCombat && !Svc.Condition[ConditionFlag.InCombat])
{
if (window is not TimelineWindow tWindow) continue;

bool show = tWindow.Setting.Enable;
if (show)
{
if (Settings.ShowTimelineOnlyInCombat && !Svc.Condition[ConditionFlag.InCombat])
{
show = false;
}

if (Settings.ShowTimelineOnlyInDuty && !Svc.Condition[ConditionFlag.BoundByDuty])
{
show = false;
}
}
return false;
}

tWindow.IsOpen = show;
if (Settings.ShowTimelineOnlyInDuty && !Svc.Condition[ConditionFlag.BoundByDuty])
{
return false;
}

return true;
}

public static void OpenConfigUi()
Expand All @@ -176,10 +177,7 @@ public static void OpenConfigUi()

protected virtual void Dispose(bool disposing)
{
if (!disposing)
{
return;
}
if (!disposing) return;

Settings.Save();

Expand Down
95 changes: 88 additions & 7 deletions ActionTimelineEx/Windows/SettingsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ActionTimeline.Timeline;
using ActionTimelineEx.Configurations;
using Dalamud.Interface;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing;
using Dalamud.Utility;
using ECommons.Commands;
Expand Down Expand Up @@ -39,11 +40,35 @@ public override void Draw()
DrawGeneralSetting();
ImGui.EndTabItem();
}
if (ImGui.BeginTabItem("Timeline"))

HashSet<string> showedName = new HashSet<string>();
int index = 0;
DrawingSettings? removingSetting = null;

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

if (ImGui.BeginTabItem($"TL:{setting.Name}"))
{
if(duplicated) ImGui.PopStyleColor();
if (DrawTimelineSetting(setting))
{
removingSetting = setting;
}
ImGui.EndTabItem();
}

showedName.Add(setting.Name);
index++;
}

if(removingSetting != null)
{
Settings.TimelineSettings.Remove(removingSetting);
}

if (ImGui.BeginTabItem("Help"))
{
DrawHelp();
Expand Down Expand Up @@ -89,6 +114,13 @@ private void DrawHelp()
private ushort _aboutAdd = 0;
private void DrawGeneralSetting()
{
if(ImGui.Button("Add One Timeline"))
{
Settings.TimelineSettings.Add(new DrawingSettings()
{
Name = (Settings.TimelineSettings.Count + 1).ToString(),
});
}
ImGui.Checkbox("Show Only In Duty", ref Settings.ShowTimelineOnlyInDuty);
ImGui.Checkbox("Show Only In Combat", ref Settings.ShowTimelineOnlyInCombat);
ImGui.Checkbox("Print Clipping Time On Chat", ref Settings.PrintClipping);
Expand Down Expand Up @@ -188,19 +220,20 @@ private void DrawGeneralSetting()
}

#region Timeline
private void DrawTimelineSetting(DrawingSettings settings)
private bool DrawTimelineSetting(DrawingSettings settings)
{
var result = false;
if (!ImGui.BeginTabBar("##Timeline_Settings_TabBar"))
{
return;
return result;
}

ImGui.PushItemWidth(80 * _scale);

// general
if (ImGui.BeginTabItem("General##Timeline_General"))
{
DrawGeneralTab(settings);
result = DrawGeneralTab(settings);
ImGui.EndTabItem();
}

Expand Down Expand Up @@ -233,10 +266,56 @@ private void DrawTimelineSetting(DrawingSettings settings)
}

ImGui.EndTabBar();

return result;
}

private string _undoName = string.Empty;
private DateTime _lastTime = DateTime.MinValue;
private bool RemoveValue(string name)
{
ImGui.SameLine();

bool isLast = name == _undoName && DateTime.Now - _lastTime < TimeSpan.FromSeconds(2);
bool isTime = DateTime.Now - _lastTime > TimeSpan.FromSeconds(0.5);

bool result = false;

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 (isLast && isTime)
{
result = true;
_lastTime = DateTime.MinValue;
}
else
{
_lastTime = DateTime.Now;
_undoName = name;
}
}

ImGui.PopFont();

if (ImGui.IsItemHovered())
{
ImGui.SetTooltip(!isTime ? "Please wait for a second." :
isLast ? "Are you sure to remove this timeline?"
: "Click to remove this timeline.");
}

if (isLast) ImGui.PopStyleColor();
return result;
}

private void DrawGeneralTab(DrawingSettings settings)
private bool DrawGeneralTab(DrawingSettings settings)
{
ImGui.InputText("Name: ", ref settings.Name, 32);
var result = RemoveValue(settings.Name);

ImGui.Checkbox("Enable", ref settings.Enable);
ImGui.Checkbox("Is Rotation", ref settings.IsRotation);

Expand All @@ -257,6 +336,8 @@ private void DrawGeneralTab(DrawingSettings settings)
DrawHelper.SetTooltip("This is the advanced time about action using");
}
ImGui.DragFloat("Drawing Center offset", ref settings.CenterOffset, 0.3f, -500, 500);

return result;
}

private void DrawIconsTab(DrawingSettings settings)
Expand Down
Loading

0 comments on commit 1fdaa80

Please sign in to comment.