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

Commit

Permalink
feat: add better rotatoin helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jul 12, 2024
1 parent befc390 commit fded3cd
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 41 deletions.
4 changes: 4 additions & 0 deletions ActionTimelineEx/ActionTimelineEx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@
<ItemGroup>
<Folder Include="Localization\" />
</ItemGroup>

<ItemGroup>
<Using Include="Newtonsoft.Json" />
</ItemGroup>
</Project>
28 changes: 20 additions & 8 deletions ActionTimelineEx/Configurations/ActionSetting.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
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;
Expand All @@ -26,6 +22,12 @@ public override void OnClick(object obj)

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

public override string GetDescription(object obj)
{
if (obj is not ActionSetting setting) return base.GetDescription(obj);
return setting.DisplayName;
}
}

public enum ActionSettingType : byte
Expand All @@ -40,12 +42,10 @@ 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;
Expand All @@ -57,7 +57,8 @@ public uint ActionId
Update();
}
}

[JsonIgnore, UI("Id")]
public int Id { get => (int)ActionId; set => ActionId = (uint) value; }
private ActionSettingType _type;

[UI("Type")]
Expand Down Expand Up @@ -104,7 +105,7 @@ void UpdateAction()

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

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

Expand All @@ -121,4 +122,15 @@ 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);
}

private static uint GetActionIcon(Lumina.Excel.GeneratedSheets.Action action)
{
var isGAction = action.ActionCategory.Row is 10 or 11;
if (!isGAction) return action.Icon;

var gAct = Svc.Data.GetExcelSheet<Lumina.Excel.GeneratedSheets.GeneralAction>()?.FirstOrDefault(g => g.Action.Row == action.RowId);

if (gAct == null) return action.Icon;
return (uint)gAct.Icon;
}
}
4 changes: 1 addition & 3 deletions ActionTimelineEx/Configurations/RotationsSetting.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text.Json.Serialization;

namespace ActionTimelineEx.Configurations;
namespace ActionTimelineEx.Configurations;

public class RotationsSetting
{
Expand Down
3 changes: 3 additions & 0 deletions ActionTimelineEx/Configurations/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public string RotationName
[UI("Icon Spacing", Parent = nameof(DrawRotation))]
public int IconSpacing { get; set; } = 5;

[UI("Show the wrong clicking", Parent = nameof(DrawRotation))]
public bool ShowWrongClick { get; set; } = true;

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

Expand Down
3 changes: 3 additions & 0 deletions ActionTimelineEx/Configurations/UiString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ internal enum UiString

[Description("Rotation")]
Rotation,

[Description("Reset Count")]
RotationReset,
}
61 changes: 39 additions & 22 deletions ActionTimelineEx/Helpers/RotationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,57 @@ private set
if (_count == value) return;
_count = value;

if (_highLight == null) return;
_highLight.Color = Plugin.Settings.RotationHighlightColor;
_highLight.HotbarIDs.Clear();

var action = ActiveActon;
if (action == null) return;
UpdateHighlight();
}
}
public static uint SuccessCount { get; private set; } = 0;

HotbarID? hotbar = null;
private static void UpdateHighlight()
{
if (_highLight == null) return;
_highLight.Color = Plugin.Settings.RotationHighlightColor;
_highLight.HotbarIDs.Clear();

switch (action.Type)
{
case ActionSettingType.Action:
hotbar = new HotbarID(FFXIVClientStructs.FFXIV.Client.UI.Misc.RaptureHotbarModule.HotbarSlotType.Action, action.ActionId);
break;
var action = ActiveActon;
if (action == null) return;

case ActionSettingType.Item:
hotbar = new HotbarID(FFXIVClientStructs.FFXIV.Client.UI.Misc.RaptureHotbarModule.HotbarSlotType.Item, action.ActionId);
break;
}
HotbarID? hotbar = null;

if (hotbar == null) return;
_highLight.HotbarIDs.Add(hotbar.Value);
switch (action.Type)
{
case ActionSettingType.Action:
var isGAction = Svc.Data.GetExcelSheet<Lumina.Excel.GeneratedSheets.Action>()?.GetRow(action.ActionId)?.ActionCategory.Row is 10 or 11;
if (isGAction)
{
var gAct = Svc.Data.GetExcelSheet<GeneralAction>()?.FirstOrDefault(g => g.Action.Row == action.ActionId);
if (gAct != null)
{
hotbar = new HotbarID(FFXIVClientStructs.FFXIV.Client.UI.Misc.RaptureHotbarModule.HotbarSlotType.GeneralAction, gAct.RowId);
break;
}
}

hotbar = new HotbarID(FFXIVClientStructs.FFXIV.Client.UI.Misc.RaptureHotbarModule.HotbarSlotType.Action, action.ActionId);
break;

case ActionSettingType.Item:
hotbar = new HotbarID(FFXIVClientStructs.FFXIV.Client.UI.Misc.RaptureHotbarModule.HotbarSlotType.Item, action.ActionId);
break;
}

if (hotbar == null) return;
_highLight.HotbarIDs.Add(hotbar.Value);
}
public static uint SuccessCount { get; private set; } = 0;

public static void Init()
{
ActionEffect.ActionEffectEvent += ActionFromSelf;
Svc.DutyState.DutyWiped += DutyState_DutyWiped;
Svc.DutyState.DutyCompleted += DutyState_DutyWiped;
Svc.ClientState.TerritoryChanged += ClientState_TerritoryChanged;

ClientState_TerritoryChanged(Svc.ClientState.TerritoryType);
_highLight = new();
UpdateHighlight();
}

public static void Dispose()
Expand Down Expand Up @@ -102,9 +119,9 @@ private static void ActionFromSelf(ActionEffectSet set)
{
SuccessCount++;
}
else
else if(Plugin.Settings.ShowWrongClick)
{
Svc.Chat.Print("Failed to click the action!");
Svc.Chat.PrintError($"Clicked the wrong action {set.Name}! You should Click {action.DisplayName}!");
}
Count++;
}
Expand Down
18 changes: 17 additions & 1 deletion ActionTimelineEx/Localization/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,21 @@
"ActionTimeline.SettingsName.RotationName": "Rotation Name",
"ActionTimeline.SettingsName.RotationCount": "Rotation Count",
"ActionTimeline.SettingsName.RotationHighlightColor": "Rotation Highlight Color",
"ActionTimeline.SettingsName.Position": "Rotation Position"
"ActionTimeline.SettingsName.Position": "Rotation Position",
"ActionTimeline.SettingsName.RotationLocked": "Locked",
"ActionTimeline.SettingsName.RotationLockedBackgroundColor": "Locked Background Color",
"ActionTimeline.SettingsName.RotationUnlockedBackgroundColor": "Unlocked Background Color",
"ActionTimeline.SettingsName.GCDIconSize": "GCD Icon Size",
"ActionTimeline.SettingsName.OGCDIconSize": "Off GCD Icon Size",
"ActionTimeline.SettingsName.IconSpacing": "Icon Spacing",
"ActionTimelineEx.Configurations.UiString.RotationSetting": "Rotation Setting",
"ActionTimelineEx.Configurations.UiString.Rotation": "Rotation",
"ActionTimelineEx.Windows.RotationHelperItem": "Rotation Helper",
"ActionTimelineEx.Configurations.ActionSetting": "ActionSetting",
"ActionTimelineEx.Configurations.ActionSettingType.Action": "Action",
"ActionTimelineEx.Configurations.ActionSettingType.Item": "Item",
"ActionTimelineEx.Configurations.ActionSettingName.Type": "Type",
"ActionTimelineEx.Configurations.ActionSettingName.Id": "Id",
"ActionTimelineEx.Configurations.ActionSettingDescription": "Maim (GCD)",
"ActionTimelineEx.Configurations.UiString.RotationReset": "Reset Count"
}
2 changes: 1 addition & 1 deletion ActionTimelineEx/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public Plugin(IDalamudPluginInterface pluginInterface)
Svc.PluginInterface.UiBuilder.OpenMainUi += OpenConfigUi;

TimelineManager.Initialize();
RotationHelper.Init();

try
{
Expand All @@ -87,6 +86,7 @@ public Plugin(IDalamudPluginInterface pluginInterface)
Settings = new Settings();
}

RotationHelper.Init();
CreateWindows();
}

Expand Down
30 changes: 27 additions & 3 deletions ActionTimelineEx/Windows/RotationHelperItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Dalamud.Interface.Textures.TextureWraps;
using Dalamud.Interface.Utility.Raii;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using ImGuiNET;
using Lumina.Excel.GeneratedSheets;
using System.ComponentModel;
Expand Down Expand Up @@ -38,14 +39,23 @@ public override void Draw(ConfigWindow window)

_group ??= new CollapsingHeaderGroup(new()
{
{ () => UiString.RotationSetting.Local(), () => window.Collection.DrawItems(1) },
{ () => UiString.RotationSetting.Local(), () => DrawSetting(window) },
{ () => UiString.Rotation.Local(), () => ConditionDrawer.Draw(setting.RotationSetting.Actions) },
});

_group.Draw();
base.Draw(window);
}

private static void DrawSetting(ConfigWindow window)
{
if (ImGui.Button(UiString.RotationReset.Local()))
{
RotationHelper.Clear();
}
window.Collection.DrawItems(1);
}

private static void DrawTerritoryHeader()
{
_territories ??= Svc.Data.GetExcelSheet<TerritoryType>()?
Expand All @@ -56,14 +66,28 @@ private static void DrawTerritoryHeader()
var name = GetName(rightTerritory);

var imFont = DrawingExtensions.GetFont(21);
float width = 0;
float width = 0, height = 0;
using (var font = ImRaii.PushFont(imFont))
{
width = ImGui.CalcTextSize(name).X + (ImGui.GetStyle().ItemSpacing.X * 2);
height = ImGui.CalcTextSize(name).Y + (ImGui.GetStyle().ItemSpacing.Y * 2);
}

var HasJob = ImageLoader.GetTexture(62100 + Player.Object.ClassJob.Id, out var jobTexture);

if (HasJob)
{
width += height + ImGui.GetStyle().ItemSpacing.X;
}

ImGuiHelper.DrawItemMiddle(() =>
{
if (HasJob)
{
ImGui.Image(jobTexture.ImGuiHandle, Vector2.One * height);
ImGui.SameLine();
}

var territories = _territories ?? [];
var index = Array.IndexOf(territories, rightTerritory);
if (ImGuiHelper.SelectableCombo("##Choice the specific dungeon", [.. territories.Select(GetName)], ref index, imFont, ImGuiColors.DalamudYellow))
Expand All @@ -77,7 +101,7 @@ private static void DrawTerritoryHeader()
static string GetName(TerritoryType? territory)
{
var str = territory?.ContentFinderCondition?.Value?.Name?.RawString;
if (string.IsNullOrEmpty(str)) str = territory?.Name?.RawString;
if (string.IsNullOrEmpty(str)) str = territory?.PlaceName?.Value?.Name?.RawString;
if (string.IsNullOrEmpty(str)) return "Unnamed Territory";
return str;
}
Expand Down
2 changes: 1 addition & 1 deletion ActionTimelineEx/Windows/RotationHelperWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static void DrawContent()
var spacing = Plugin.Settings.IconSpacing;
var drawList = ImGui.GetWindowDrawList();

var pos = ImGui.GetWindowPos() + new Vector2(0, ImGui.GetWindowSize().Y / 2 - gcdHeight / 2);
var pos = ImGui.GetWindowPos() + new Vector2(gcdHeight * 0.2f, ImGui.GetWindowSize().Y / 2 - gcdHeight / 2);
var maxX = pos.X + ImGui.GetWindowSize().X;

bool isFirst = true;
Expand Down

0 comments on commit fded3cd

Please sign in to comment.