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

Commit

Permalink
fix: finished the cooldown show.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 19, 2023
1 parent b363364 commit 4769cf4
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 63 deletions.
2 changes: 2 additions & 0 deletions RotationSolver.Basic/Actions/BaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public bool IsEnabled

public bool EnoughLevel => true;

public unsafe bool IsCoolingDown => ActionManager.Instance()->IsRecastTimerActive(ActionType.Item, ID);

public BaseItem(uint row, uint a4 = 65535)
{
_item = Service.GetSheet<Item>().GetRow(row);
Expand Down
1 change: 1 addition & 0 deletions RotationSolver.Basic/Actions/IAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface IAction : ITexture
uint AdjustedID { get; }
float RecastTimeOneCharge { get; }
float RecastTimeElapsed { get; }
bool IsCoolingDown { get; }

/// <summary>
/// Player's level is enough for this action's usage.
Expand Down
5 changes: 1 addition & 4 deletions RotationSolver/Commands/RSCommands_StateSpecialCommand.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Basic;
using RotationSolver.Basic;
using RotationSolver.Basic.Data;
using RotationSolver.Basic.Helpers;
using RotationSolver.Localization;
using RotationSolver.SigReplacers;
using System;

namespace RotationSolver.Commands
{
Expand Down
1 change: 1 addition & 0 deletions RotationSolver/Localization/Localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
"ConfigWindow_Control_ShowControlWindow": "Show Control Window",
"ConfigWindow_Control_UseKeyboardCommand": "Use Keyboard Command",
"ConfigWindow_Control_UseGamepadCommand": "Use GamePad Command",
"ConfigWindow_Control_ControlShowCooldown": "Show action's cooldown",
"ConfigWindow_Control_IsControlWindowLock": "Lock",
"ConfigWindow_Control_BackgroundColor": "Control Window's Background",
"ConfigWindow_Control_ControlWindowGCDSize": "GCD icon size",
Expand Down
1 change: 1 addition & 0 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ internal partial class Strings
public string ConfigWindow_Control_ShowControlWindow { get; set; } = "Show Control Window";
public string ConfigWindow_Control_UseKeyboardCommand { get; set; } = "Use Keyboard Command";
public string ConfigWindow_Control_UseGamepadCommand { get; set; } = "Use GamePad Command";
public string ConfigWindow_Control_ControlShowCooldown { get; set; } = "Show action's cooldown";
public string ConfigWindow_Control_IsControlWindowLock { get; set; } = "Lock";
public string ConfigWindow_Control_BackgroundColor { get; set; } = "Control Window's Background";
public string ConfigWindow_Control_ControlWindowGCDSize { get; set; } = "GCD icon size";
Expand Down
4 changes: 0 additions & 4 deletions RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Dalamud.Utility;
using ImGuiScene;
using Newtonsoft.Json;
using RotationSolver.Basic;
using RotationSolver.Basic.Configuration;
using RotationSolver.Basic.Data;
using RotationSolver.Commands;
using RotationSolver.Localization;
using RotationSolver.SigReplacers;
using RotationSolver.UI;
using RotationSolver.Updaters;
using System.Net;

namespace RotationSolver;

Expand Down
58 changes: 41 additions & 17 deletions RotationSolver/UI/ControlWindow.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Interface;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing;
using Dalamud.Logging;
using FFXIVClientStructs.FFXIV.Client.Game;
using ImGuiNET;
using ImGuiScene;
Expand Down Expand Up @@ -29,7 +30,7 @@ public ControlWindow()
: base(nameof(ControlWindow), _baseFlags)
{
Size = new Vector2(540f, 490f);
//SizeCondition = ImGuiCond.FirstUseEver;
SizeCondition = ImGuiCond.FirstUseEver;
}

public override void PreDraw()
Expand Down Expand Up @@ -86,9 +87,14 @@ public override void Draw()
ImGui.Separator();
foreach (var pair in RotationUpdater.AllGroupedActions)
{
var showItems = pair.Where(i => !(i is IBaseAction a && a.IsGeneralGCD)).OrderBy(a => a.ID);

if (!showItems.Any()) continue;

ImGui.Text(pair.Key);

bool started = false;
foreach(var item in pair)
foreach(var item in showItems)
{
if (started)
{
Expand All @@ -101,34 +107,51 @@ public override void Draw()
}
}

private static void DrawActionCooldown(IAction act)
static readonly uint black = ImGui.ColorConvertFloat4ToU32(new Vector4(0, 0, 0, 1));
static readonly uint white = ImGui.ColorConvertFloat4ToU32(new Vector4(1, 1, 1, 1));
static readonly uint progressCol = ImGui.ColorConvertFloat4ToU32(new Vector4(0.6f, 0.6f, 0.6f, 0.6f));

static void TextShade(Vector2 pos, string text, float width, uint fore, uint background)
{
if (act is IBaseAction a && a.IsGeneralGCD) return;
ImGui.GetWindowDrawList().AddText(pos - new Vector2(0, width), background, text);
ImGui.GetWindowDrawList().AddText(pos - new Vector2(0, -width), background, text);
ImGui.GetWindowDrawList().AddText(pos - new Vector2(width, 0), background, text);
ImGui.GetWindowDrawList().AddText(pos - new Vector2(-width, 0), background, text);
ImGui.GetWindowDrawList().AddText(pos, fore, text);
}

private static void DrawActionCooldown(IAction act)
{
var width = Service.Config.ControlWindow0GCDSize;
var recast = act.RecastTimeOneCharge;
var elapsed = act.RecastTimeElapsed;

ImGui.BeginGroup();
var pos = ImGui.GetCursorPos();
var winPos = ImGui.GetWindowPos();

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();
if (act.IsCoolingDown)
{
var ratio = recast == 0 ? 0 : elapsed % recast / recast;
ImGui.GetWindowDrawList().AddRectFilled(new Vector2(pos.X + width * ratio, pos.Y) + winPos,
new Vector2(pos.X + width, pos.Y + width) + winPos, progressCol);

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);
string time = recast == 0 || !act.EnoughLevel ? "0" : ((int)(recast - elapsed % recast) + 1).ToString();
var strSize = ImGui.CalcTextSize(time);
var fontPos = new Vector2(pos.X + width / 2 - strSize.X / 2, pos.Y + width / 2 - strSize.Y / 2) + winPos;

TextShade(fontPos, time, 1.5f, white, black);
}

if(act is IBaseAction bAct && bAct.MaxCharges > 1)
{
ImGui.SetCursorPos(pos);
ImGui.TextDisabled(bAct.CurrentCharges.ToString());
for (int i = 0; i < bAct.CurrentCharges; i++)
{
ImGui.GetWindowDrawList().AddCircleFilled(winPos + pos + (i + 0.5f) * new Vector2(6, 0), 2.5f, white);
}
}

ImGui.EndGroup();
Expand Down Expand Up @@ -297,8 +320,9 @@ static TextureWrap GetTexture(IAction action)
uint iconId = 0;
if(action != null && !_actionIcons.TryGetValue(action.AdjustedID, out iconId))
{
_actionIcons[action.AdjustedID] = iconId =
Service.GetSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(action.AdjustedID).Icon;
iconId = action is IBaseAction ? Service.GetSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(action.AdjustedID).Icon
: Service.GetSheet<Lumina.Excel.GeneratedSheets.Item>().GetRow(action.AdjustedID).Icon;
_actionIcons[action.AdjustedID] = iconId;
}
return IconSet.GetTexture(iconId);
}
Expand Down
3 changes: 3 additions & 0 deletions RotationSolver/UI/RotationConfigWindow_Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ private void DrawControlTab()
DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Control_UseGamepadCommand,
ref Service.Config.UseGamepadCommand);

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Control_ControlShowCooldown,
ref Service.Config.ControlShowCooldown);

if (Service.Config.IsControlWindowLock)
{
DrawColor4(LocalizationManager.RightLang.ConfigWindow_Control_BackgroundColor,
Expand Down
3 changes: 1 addition & 2 deletions RotationSolver/UI/RotationConfigWindow_Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
using RotationSolver.Basic.Data;
using RotationSolver.Basic.Helpers;
using RotationSolver.Commands;
using RotationSolver.SigReplacers;
using RotationSolver.UI;
using RotationSolver.Updaters;
using System.Numerics;

namespace RotationSolver.UI;
namespace RotationSolver.UI;

internal partial class RotationConfigWindow
{
Expand Down
3 changes: 0 additions & 3 deletions RotationSolver/UI/RotationConfigWindow_Rotation.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using Dalamud.Interface.Colors;
using Dalamud.Utility;
using ImGuiNET;
using RotationSolver.Basic;
using RotationSolver.Basic.Data;
using RotationSolver.Basic.Helpers;
using RotationSolver.Basic.Rotations;
using RotationSolver.Localization;
using RotationSolver.SigReplacers;
using RotationSolver.UI;
using RotationSolver.Updaters;
using System.Numerics;

Expand Down
3 changes: 0 additions & 3 deletions RotationSolver/Updaters/ActionUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
using RotationSolver.Basic.Helpers;
using RotationSolver.Commands;
using RotationSolver.Localization;
using RotationSolver.SigReplacers;
using System;

namespace RotationSolver.Updaters;

internal static class ActionUpdater
{

static DateTime _startCombatTime = DateTime.MinValue;

static RandomDelay _GCDDelay = new RandomDelay(() => (Service.Config.WeaponDelayMin, Service.Config.WeaponDelayMax));
Expand Down
13 changes: 0 additions & 13 deletions RotationSolver/Updaters/InputUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@ internal static unsafe void UpdateCommand()
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using RotationSolver.Basic;
using RotationSolver.Basic.Helpers;

namespace RotationSolver.SigReplacers;
namespace RotationSolver.Updaters;

internal class MovingController : IDisposable
{
Expand All @@ -21,7 +21,6 @@ public MovingController()
{
SignatureHelper.Initialise(this);
movingHook?.Enable();

}
public void Dispose()
{
Expand Down
1 change: 0 additions & 1 deletion RotationSolver/Updaters/PreviewUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using RotationSolver.Basic.Data;
using RotationSolver.Basic.Helpers;
using RotationSolver.Commands;
using RotationSolver.SigReplacers;
using System;
using System.Runtime.InteropServices;

Expand Down
6 changes: 0 additions & 6 deletions RotationSolver/Updaters/TargetUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
using RotationSolver.Basic;
using RotationSolver.Basic.Data;
using RotationSolver.Basic.Helpers;
using RotationSolver.SigReplacers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using Action = Lumina.Excel.GeneratedSheets.Action;

namespace RotationSolver.Updaters;
Expand Down
7 changes: 0 additions & 7 deletions RotationSolver/Updaters/TimeLineUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
using ImGuiNET;
using Newtonsoft.Json;
using RotationSolver.Actions;
using RotationSolver.Basic;
using RotationSolver.Basic.Data;
using RotationSolver.SigReplacers;
using RotationSolver.Timeline;
using RotationSolver.UI;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace RotationSolver.Updaters
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using System.Text.RegularExpressions;
using Action = Lumina.Excel.GeneratedSheets.Action;

namespace RotationSolver.SigReplacers;
namespace RotationSolver;

public class Watcher : IDisposable
{
Expand Down

0 comments on commit 4769cf4

Please sign in to comment.