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

Commit

Permalink
feat: add rotation helper feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jul 12, 2024
1 parent e66bbda commit 187c65d
Show file tree
Hide file tree
Showing 22 changed files with 682 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "XIVConfigUI"]
path = XIVConfigUI
url = https://github.com/ArchiDog1998/XIVConfigUI
[submodule "XIVDrawer"]
path = XIVDrawer
url = https://github.com/ArchiDog1998/XIVDrawer
10 changes: 10 additions & 0 deletions ActionTimelineEx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ActionTimelineEx", "ActionT
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XIVConfigUI", "XIVConfigUI\XIVConfigUI\XIVConfigUI.csproj", "{E3AA7E1F-8B6C-4B5C-BE87-1B54BC5003CC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XIVDrawer", "XIVDrawer\XIVDrawer\XIVDrawer.csproj", "{A269BD49-DF07-445F-AF13-3BAC46D4F2CD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -46,6 +48,14 @@ Global
{E3AA7E1F-8B6C-4B5C-BE87-1B54BC5003CC}.Release|Any CPU.Build.0 = Release|Any CPU
{E3AA7E1F-8B6C-4B5C-BE87-1B54BC5003CC}.Release|x64.ActiveCfg = Release|Any CPU
{E3AA7E1F-8B6C-4B5C-BE87-1B54BC5003CC}.Release|x64.Build.0 = Release|Any CPU
{A269BD49-DF07-445F-AF13-3BAC46D4F2CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A269BD49-DF07-445F-AF13-3BAC46D4F2CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A269BD49-DF07-445F-AF13-3BAC46D4F2CD}.Debug|x64.ActiveCfg = Debug|Any CPU
{A269BD49-DF07-445F-AF13-3BAC46D4F2CD}.Debug|x64.Build.0 = Debug|Any CPU
{A269BD49-DF07-445F-AF13-3BAC46D4F2CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A269BD49-DF07-445F-AF13-3BAC46D4F2CD}.Release|Any CPU.Build.0 = Release|Any CPU
{A269BD49-DF07-445F-AF13-3BAC46D4F2CD}.Release|x64.ActiveCfg = Release|Any CPU
{A269BD49-DF07-445F-AF13-3BAC46D4F2CD}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 2 additions & 1 deletion ActionTimelineEx/ActionTimelineEx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<PackageReference Include="DalamudPackager" Version="2.1.12" />
<ProjectReference Include="..\ECommons\ECommons\ECommons.csproj" />
<ProjectReference Include="..\XIVConfigUI\XIVConfigUI\XIVConfigUI.csproj" />

<ProjectReference Include="..\XIVDrawer\XIVDrawer\XIVDrawer.csproj" />

<Reference Include="Dalamud">
<HintPath>$(DalamudLibPath)Dalamud.dll</HintPath>
<Private>False</Private>
Expand Down
124 changes: 124 additions & 0 deletions ActionTimelineEx/Configurations/ActionSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using ActionTimeline.Helpers;
using Dalamud.Plugin.Services;
using ECommons.DalamudServices;
using FFXIVClientStructs.FFXIV.Common.Lua;
using ImGuiNET;
using System.Drawing;
using System.Numerics;
using System.Xml.Linq;
using XIVConfigUI.Attributes;

namespace ActionTimelineEx.Configurations;

internal class ActionSettingAttribute() : ListUIAttribute(0)
{
public override uint GetIcon(object obj)
{
if (obj is not ActionSetting setting)
return base.GetIcon(obj);
return setting.IconId;
}

public override void OnClick(object obj)
{
base.OnClick(obj);
if (obj is not ActionSetting setting) return;

//TODO: Change the acion ID...
}
}

public enum ActionSettingType : byte
{
Action,
Item,
}

[ActionSetting]
public class ActionSetting
{
internal uint IconId { get; private set; } = 0;
internal bool IsGCD { get; private set; } = false;

[UI("Name")]
internal string DisplayName { get; private set; } = "";

private uint _actionId;

[UI("Id")]
public uint ActionId
{
get => _actionId;
set
{
if (value == _actionId) return;
_actionId = value;

Update();
}
}

private ActionSettingType _type;

[UI("Type")]
public ActionSettingType Type
{
get => _type;
set
{
if (value == _type) return;
_type = value;

Update();
}
}

private void Update()
{
ClearData();

switch (Type)
{
case ActionSettingType.Action:
UpdateAction();
return;

case ActionSettingType.Item:
UpdateItem();
return;
}

void UpdateItem()
{
var item = Svc.Data.GetExcelSheet<Lumina.Excel.GeneratedSheets.Item>()?.GetRow(ActionId);
if (item == null) return;

IconId = item.Icon;
DisplayName = item.Name;
}

void UpdateAction()
{
var action = Svc.Data.GetExcelSheet<Lumina.Excel.GeneratedSheets.Action>()?.GetRow(ActionId);
if (action == null) return;

IsGCD = action.CooldownGroup == 58 || action.AdditionalCooldownGroup == 58;

IconId = action.Icon;
DisplayName = $"{action.Name} ({(IsGCD ? "GCD" : "Ability")})";
}

void ClearData()
{
IconId = 0;
DisplayName = string.Empty;
IsGCD = false;
}
}

public void Draw(ImDrawListPtr drawList, Vector2 point, float size)
{
drawList.DrawActionIcon(IconId, Type is ActionSettingType.Item, point, size);
if (!string.IsNullOrEmpty(DisplayName) && DrawHelper.IsInRect(point, new Vector2(size))) ImGui.SetTooltip(DisplayName);
}
}
10 changes: 10 additions & 0 deletions ActionTimelineEx/Configurations/RotationSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using XIVConfigUI.Attributes;

namespace ActionTimelineEx.Configurations;
public class RotationSetting
{
[UI("Rotation Name")]
public string Name { get; set; } = "Default";

public List<ActionSetting> Actions { get; set; } = [];
}
29 changes: 29 additions & 0 deletions ActionTimelineEx/Configurations/RotationsSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Text.Json.Serialization;

namespace ActionTimelineEx.Configurations;

public class RotationsSetting
{
public string Choice { get; set; } = "Default";
public List<RotationSetting> RotationSettings { get; set; } = [];

[JsonIgnore]
public RotationSetting RotationSetting
{
get
{
var result = RotationSettings.FirstOrDefault(r => r.Name == Choice);
if (result != null) return result;

result = RotationSettings.FirstOrDefault();
if (result == null)
{
result = new();
RotationSettings.Add(result);
}

Choice = result.Name;
return result;
}
}
}
81 changes: 80 additions & 1 deletion ActionTimelineEx/Configurations/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
using ActionTimelineEx.Configurations;
using Dalamud.Configuration;
using ECommons.DalamudServices;
using ECommons.ExcelServices;
using ECommons.GameHelpers;
using Newtonsoft.Json;
using System.Numerics;
using XIVConfigUI.Attributes;

namespace ActionTimeline;

internal class TimelineChoicesAttribute : ChoicesAttribute
{
protected override Pair[] GetChoices()
{
return [..Plugin.Settings.EditSetting?.RotationSettings.Select(i => i.Name)];
}
}

public class Settings : IPluginConfiguration
{
[UI("Record Data")]
Expand Down Expand Up @@ -35,9 +46,77 @@ public class Settings : IPluginConfiguration
[UI("Show the donate link.")]
public bool ShowDonate { get; set; } = true;

public List<DrawingSettings> TimelineSettings = [];
public List<DrawingSettings> TimelineSettings { get; set; } = [];
public HashSet<ushort> HideStatusIds { get; set; } = [];

[UI("Draw Rotation", 1)]
public bool DrawRotation { get; set; } = false;

[JsonIgnore]
[TimelineChoices]
[UI("Rotation Choice", Parent = nameof(DrawRotation))]
public string RotationChoice
{
get => EditSetting?.Choice ?? "Default";
set
{
if (EditSetting == null) return;
EditSetting.Choice = value;
}
}

[JsonIgnore]
[UI("Rotation Name", Parent = nameof(DrawRotation))]
public string RotationName
{
get => EditSetting?.RotationSetting.Name ?? "Default";
set
{
if (EditSetting == null) return;
EditSetting.RotationSetting.Name = value;
}
}

[UI("Locked", Parent = nameof(DrawRotation))]
public bool RotationLocked { get; set; } = false;

[UI("Locked Background Color", Parent = nameof(DrawRotation))]
public Vector4 RotationLockedBackgroundColor { get; set; } = new(0f, 0f, 0f, 0.5f);

[UI("Unlocked Background Color", Parent = nameof(DrawRotation))]
public Vector4 RotationUnlockedBackgroundColor { get; set; } = new(0f, 0f, 0f, 0.75f);

[UI("Rotation Highlight Color", Parent = nameof(DrawRotation))]
public Vector4 RotationHighlightColor { get; set; } = new Vector4(1, 1, 1, 1);

[Range(1, 100, ConfigUnitType.Pixels, 0.2f)]
[UI("GCD Icon Size", Parent = nameof(DrawRotation))]
public int GCDIconSize { get; set; } = 40;

[Range(1, 100, ConfigUnitType.Pixels, 0.2f)]
[UI("Off GCD Icon Size", Parent = nameof(DrawRotation))]
public int OGCDIconSize { get; set; } = 30;

[Range(1, 100, ConfigUnitType.Pixels, 0.2f)]
[UI("Icon Spacing", Parent = nameof(DrawRotation))]
public int IconSpacing { get; set; } = 5;

[JsonProperty]
private Dictionary<uint, Dictionary<Job, RotationsSetting>> _rotationHelpers = [];

[JsonIgnore]
internal RotationsSetting? EditSetting { get; set; } = null;

public RotationsSetting GetSetting(uint territoryId)
{
if (!_rotationHelpers.TryGetValue(territoryId, out var dict)) _rotationHelpers[territoryId] = dict = [];

var job = Player.Job;
if (!dict.TryGetValue(job, out var result)) dict[job] = result = new();

return result;
}

public int Version { get; set; } = 6;

public void Save()
Expand Down
6 changes: 6 additions & 0 deletions ActionTimelineEx/Configurations/UiString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ internal enum UiString

[Description("Remove this Item:")]
RemoveDesc,

[Description("Rotation Setting")]
RotationSetting,

[Description("Rotation")]
Rotation,
}
9 changes: 2 additions & 7 deletions ActionTimelineEx/Helpers/DrawHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dalamud.Interface.Textures;
using ActionTimelineEx.Configurations;
using Dalamud.Interface.Textures;
using Dalamud.Interface.Textures.TextureWraps;
using ECommons.DalamudServices;
using ImGuiNET;
Expand Down Expand Up @@ -27,12 +28,6 @@ public static void DrawActionIcon(this ImDrawListPtr drawList, uint iconId, bool
}
}

public static Vector4 ChangeAlpha(this Vector4 color, float alpha)
{
color.Z = alpha;
return color;
}

public static IDalamudTextureWrap? GetTextureFromIconId(uint iconId, bool highQuality = true)
=> ImageLoader.GetTexture(new GameIconLookup( iconId, false, highQuality), out var texture) ? texture
: ImageLoader.GetTexture(new GameIconLookup(0, false, highQuality), out texture) ? texture : null;
Expand Down
Loading

0 comments on commit 187c65d

Please sign in to comment.