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

Commit

Permalink
fix: add cooldown show.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 19, 2023
1 parent 3b7d169 commit 2f5c111
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public bool IsEnabled

public uint IconID => _action.Icon;

private bool IsGeneralGCD { get; }
public bool IsGeneralGCD { get; }

public bool IsRealGCD { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public bool ElapsedAfter(float time)

public bool WillHaveOneChargeGCD(uint gcdCount = 0, uint abilityCount = 0)
{
if (HaveOneCharge) return true;
if (HasOneCharge) return true;
var recast = RecastTimeRemainOneCharge;
return CooldownHelper.RecastAfterGCD(recast, gcdCount, abilityCount);
}
Expand All @@ -31,7 +31,7 @@ public bool WillHaveOneChargeGCD(uint gcdCount = 0, uint abilityCount = 0)

private bool WillHaveOneCharge(float remain, bool addWeaponRemain)
{
if (HaveOneCharge) return true;
if (HasOneCharge) return true;
var recast = RecastTimeRemainOneCharge;
return CooldownHelper.RecastAfter(recast, remain, addWeaponRemain);
}
Expand Down Expand Up @@ -65,7 +65,7 @@ private bool WillHaveOneCharge(float remain, bool addWeaponRemain)
/// <summary>
/// 是否起码有一层技能
/// </summary>
public bool HaveOneCharge => IsCoolingDown ? RecastTimeElapsed >= RecastTimeOneCharge : true;
public bool HasOneCharge => IsCoolingDown ? RecastTimeElapsed >= RecastTimeOneCharge : true;
/// <summary>
/// 当前技能层数
/// </summary>
Expand Down
8 changes: 7 additions & 1 deletion RotationSolver.Basic/Actions/BaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public bool IsEnabled

public string Description => string.Empty;

public unsafe float RecastTimeOneCharge => ActionManager.Instance()->GetRecastTime(ActionType.Item, ID);

public unsafe float RecastTimeElapsed => ActionManager.Instance()->GetRecastTimeElapsed(ActionType.Item, ID);

public bool EnoughLevel => true;

public BaseItem(uint row, uint a4 = 65535)
{
_item = Service.GetSheet<Item>().GetRow(row);
Expand All @@ -56,7 +62,7 @@ public unsafe bool CanUse(out IAction item)

if (ConfigurationHelper.BadStatus.Contains(ActionManager.Instance()->GetActionStatus(ActionType.Item, ID))) return false;

var remain = ActionManager.Instance()->GetRecastTime(ActionType.Item, ID) - ActionManager.Instance()->GetRecastTimeElapsed(ActionType.Item, ID);
var remain = RecastTimeOneCharge - RecastTimeElapsed;

if (!CooldownHelper.RecastAfter(DataCenter.AbilityRemain, remain, false)) return false;

Expand Down
7 changes: 7 additions & 0 deletions RotationSolver.Basic/Actions/IAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ public interface IAction : ITexture
bool Use();
uint ID { get; }
uint AdjustedID { get; }
float RecastTimeOneCharge { get; }
float RecastTimeElapsed { get; }

/// <summary>
/// Player's level is enough for this action's usage.
/// </summary>
bool EnoughLevel { get; }
}
17 changes: 13 additions & 4 deletions RotationSolver.Basic/Actions/IBaseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public interface IBaseAction : IAction
Func<BattleChara, bool> ActionCheck { get; set; }

/// <summary>
/// Player's level is enough for this action's usage.
/// Is a GCD action.
/// </summary>
bool EnoughLevel { get; }
bool IsRealGCD { get; }

/// <summary>
/// Is a GCD action.
/// Is a simple gcd action, without other cooldown.
/// </summary>
bool IsRealGCD { get; }
bool IsGeneralGCD { get; }

/// <summary>
/// Can I use this action at this time. It will check a lot of things.
Expand Down Expand Up @@ -90,6 +90,15 @@ public interface IBaseAction : IAction
/// </summary>
ushort MaxCharges { get; }

/// <summary>
/// At least has one Charge
/// </summary>
bool HasOneCharge { get; }

/// <summary>
/// recast time remain total.
/// </summary>
float RecastTimeRemain { get; }
/// <summary>
/// Has it been in cooldown for <paramref name="gcdCount"/> gcds and <paramref name="abilityCount"/> abilities?
/// </summary>
Expand Down
5 changes: 3 additions & 2 deletions RotationSolver/Localization/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@
"ConfigWindow_Param_TeachingModeColor": "Prompt box color of teaching mode",
"ConfigWindow_Param_MovingTargetColor": "Prompt box color of moving target",
"ConfigWindow_Param_TargetColor": "Target color",
"ConfigWindow_Params_SubTargetColor": "Sub-target color",
"ConfigWindow_Param_SubTargetColor": "Sub-target color",
"ConfigWindow_Param_KeyBoardNoise": "Simulate the effect of pressing",
"ConfigWindow_Params_VoiceVolume": "Voice volume",
"ConfigWindow_Param_VoiceVolume": "Voice volume",
"ConfigWindow_Param_VoiceName": "Voice Name",
"ConfigWindow_Param_FlytextPositional": "Hint positional anticipation by flytext",
"ConfigWindow_Param_SayPositional": "Hint positional anticipation by shouting",
"ConfigWindow_Param_PositionalFeedback": "Positional error feedback",
Expand Down
77 changes: 71 additions & 6 deletions RotationSolver/UI/ControlWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dalamud.Interface.Colors;
using Dalamud.Interface;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing;
using FFXIVClientStructs.FFXIV.Client.Game;
using ImGuiNET;
Expand All @@ -10,6 +11,8 @@
using RotationSolver.Commands;
using RotationSolver.Localization;
using RotationSolver.Updaters;
using System;
using System.Buffers.Text;
using System.Numerics;

namespace RotationSolver.UI;
Expand Down Expand Up @@ -53,7 +56,7 @@ public override void PostDraw()
base.PostDraw();
}

public override void Draw()
public override void Draw()
{
ImGui.Columns(2, "Control Bolder", false);
ImGui.SetColumnWidth(0, DrawNextAction() + ImGui.GetStyle().ColumnsMinSpacing * 2);
Expand All @@ -72,8 +75,67 @@ public override void Draw()
ref Service.Config.IsControlWindowLock);

ImGui.NextColumn();

DrawSpecials();

ImGui.Columns(1);
ImGui.Separator();

if(RotationUpdater.RightNowRotation!= null)
{
foreach (var pair in RotationUpdater.AllGroupedActions)
{
ImGui.Text(pair.Key);
bool started = false;
foreach(var item in pair)
{
if (started)
{
ImGui.SameLine();
}
DrawActionCooldown(item);
started = true;
}
}
}
}

private static void DrawActionCooldown(IAction act)
{
if (act is IBaseAction a && a.IsGeneralGCD) return;

var width = Service.Config.ControlWindow0GCDSize;
var recast = act.RecastTimeOneCharge;
var elapsed = act.RecastTimeElapsed;

ImGui.BeginGroup();
var pos = ImGui.GetCursorPos();
DrawIAction(act, width);
ImGuiHelper.HoveredString(act.Name);

var ratio = recast == 0 ? 0 : elapsed % recast / recast;
ImGui.SetCursorPos(new Vector2(pos.X + width * ratio, pos.Y));
ImGui.PushStyleColor(ImGuiCol.FrameBg, new Vector4(0, 0, 0, 0.7f));
ImGui.ProgressBar(0, new Vector2(width * (1 - ratio), width), string.Empty);
ImGui.PopStyleColor();

string time = recast == 0 || !act.EnoughLevel ? "0" : ((int)(recast - elapsed % recast)).ToString();
var strSize = ImGui.CalcTextSize(time);
ImGui.SetCursorPos(new Vector2(pos.X + width / 2 - strSize.X / 2, pos.Y + width / 2 - strSize.Y / 2));
ImGui.Text(time);

if(act is IBaseAction bAct && bAct.MaxCharges > 1)
{
//Draw charges here.
}

ImGui.EndGroup();
}

private static void DrawSpecials()
{
var rotation = RotationUpdater.RightNowRotation;
DrawCommandAction(rotation?.ActionHealAreaGCD, rotation?.ActionHealAreaAbility,
DrawCommandAction(rotation?.ActionHealAreaGCD, rotation?.ActionHealAreaAbility,
SpecialCommandType.HealArea, ImGuiColors.HealerGreen);

ImGui.SameLine();
Expand Down Expand Up @@ -119,8 +181,6 @@ public override void Draw()

DrawCommandAction(rotation?.AntiKnockbackAbility,
SpecialCommandType.AntiKnockback, ImGuiColors.DalamudWhite2);

ImGui.SetCursorPosY(ImGui.GetCursorPosY() + 5);
}

static void DrawCommandAction(IAction gcd, IAction ability, SpecialCommandType command, Vector4 color)
Expand Down Expand Up @@ -325,7 +385,12 @@ static void DrawIAction(nint handle, string id, float width, StateCommandType co

static void DrawIAction(IAction action, float width)
{
ImGui.Image(GetTexture(action).ImGuiHandle, new Vector2(width, width));
DrawIAction(GetTexture(action).ImGuiHandle, width);
}

static void DrawIAction(nint handle, float width)
{
ImGui.Image(handle, new Vector2(width, width));
}

static unsafe float DrawNextAction()
Expand Down
5 changes: 2 additions & 3 deletions RotationSolver/UI/ImGuiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public static void Display(this IAction action, bool IsActive)
item.Display(IsActive);
}
}
private unsafe static void Display(this BaseAction action, bool IsActive) => action.DrawEnableTexture(IsActive, () =>
private unsafe static void Display(this IBaseAction action, bool IsActive) => action.DrawEnableTexture(IsActive, () =>
{
if (action.IsTimeline) RotationConfigWindow.ActiveAction = action;
}, otherThing: () =>
Expand All @@ -532,8 +532,7 @@ private unsafe static void Display(this BaseAction action, bool IsActive) => act
{
try
{
ImGui.Text("Can Target: " + action.CanUseTo(action.Target));
ImGui.Text("Have One:" + action.HaveOneCharge.ToString());
ImGui.Text("Have One:" + action.HasOneCharge.ToString());
ImGui.Text("Is Real GCD: " + action.IsRealGCD.ToString());
ImGui.Text("Recast One: " + action.RecastTimeOneCharge.ToString());
ImGui.Text("Recast Elapsed: " + action.RecastTimeElapsed.ToString());
Expand Down
34 changes: 1 addition & 33 deletions RotationSolver/UI/RotationConfigWindow_Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,7 @@ private void DrawActionList()
if (ImGui.BeginChild("Action List", new Vector2(0f, -1f), true))
{
if (RotationUpdater.RightNowRotation != null)
foreach (var pair in RotationUpdater.RightNowRotation.AllActions.GroupBy(a =>
{
if (a is IBaseAction act)
{
string result;

if (act.IsFriendly)
{
result = LocalizationManager.RightLang.Action_Friendly;
if (act.IsEot)
{
result += "Hot";
}
}
else
{
result = LocalizationManager.RightLang.Action_Attack;

if (act.IsEot)
{
result += "Dot";
}
}
result += "-" + (act.IsRealGCD ? "GCD" : LocalizationManager.RightLang.Timeline_Ability);
return result;
}
else if (a is IBaseItem)
{
return "Item";
}
return string.Empty;

}).OrderBy(g => g.Key))
foreach (var pair in RotationUpdater.AllGroupedActions)
{
if (ImGui.CollapsingHeader(pair.Key))
{
Expand Down
4 changes: 2 additions & 2 deletions RotationSolver/UI/RotationConfigWindow_Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ private void DrawControlTab()
}

DrawFloatNumber(LocalizationManager.RightLang.ConfigWindow_Control_ControlWindowGCDSize,
ref Service.Config.ControlWindowGCDSize);
ref Service.Config.ControlWindowGCDSize, speed: 0.2f , max: 80);

DrawFloatNumber(LocalizationManager.RightLang.ConfigWindow_Control_ControlWindow0GCDSize,
ref Service.Config.ControlWindow0GCDSize);
ref Service.Config.ControlWindow0GCDSize, speed: 0.2f, max: 80);


DrawFloatNumber(LocalizationManager.RightLang.ConfigWindow_Control_ControlWindowNextSizeRatio,
Expand Down
15 changes: 14 additions & 1 deletion RotationSolver/Updaters/InputUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,27 @@ internal static class InputUpdater
public static StateCommandType RecordingStateType { get ; set; }
public static DateTime RecordingTime { get; set; } = DateTime.MinValue;

internal static void UpdateCommand()
internal static unsafe void UpdateCommand()
{
if(DateTime.Now - RecordingTime > TimeSpan.FromSeconds(10))
{
RecordingSpecialType = SpecialCommandType.None;
RecordingStateType = StateCommandType.None;
}

#if DEBUG
Service.KeyState[VirtualKey.W] =
Service.KeyState[VirtualKey.A] =
Service.KeyState[VirtualKey.S] =
Service.KeyState[VirtualKey.D] =
Service.KeyState[VirtualKey.UP] =
Service.KeyState[VirtualKey.DOWN] =
Service.KeyState[VirtualKey.LEFT] =
Service.KeyState[VirtualKey.RIGHT] = false;

var input = (GamepadInput*)Service.GamepadState.GamepadInputAddress;
input->LeftStickX = input->LeftStickY = 0;
#endif
foreach (var key in Service.KeyState.GetValidVirtualKeys())
{
if (key is VirtualKey.CONTROL) continue;
Expand Down
36 changes: 36 additions & 0 deletions RotationSolver/Updaters/RotationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using RotationSolver.Basic.Attributes;
using RotationSolver.Basic.Data;
using RotationSolver.Basic.Rotations;
using RotationSolver.Localization;
using System.Reflection;
using System.Runtime.Loader;

Expand Down Expand Up @@ -84,6 +85,41 @@ private static ICustomRotation[] CreateRotationSet(ICustomRotation[] combos)

public static ICustomRotation RightNowRotation { get; private set; }

public static IEnumerable<IGrouping<string, IAction>> AllGroupedActions
=> RightNowRotation?.AllActions.GroupBy(a =>
{
if (a is IBaseAction act)
{
string result;

if (act.IsFriendly)
{
result = LocalizationManager.RightLang.Action_Friendly;
if (act.IsEot)
{
result += "Hot";
}
}
else
{
result = LocalizationManager.RightLang.Action_Attack;

if (act.IsEot)
{
result += "Dot";
}
}
result += "-" + (act.IsRealGCD ? "GCD" : LocalizationManager.RightLang.Timeline_Ability);
return result;
}
else if (a is IBaseItem)
{
return "Item";
}
return string.Empty;

}).OrderBy(g => g.Key);

public static IBaseAction[] RightRotationBaseActions { get; private set; } = new IBaseAction[0];

static ClassJobID _job;
Expand Down

0 comments on commit 2f5c111

Please sign in to comment.