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

Commit

Permalink
fix: add a window to show cooldown.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 22, 2023
1 parent 49a5938 commit 2ef07a3
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 117 deletions.
6 changes: 3 additions & 3 deletions RotationSolver.Basic/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,19 @@ public class PluginConfiguration : IPluginConfiguration
public bool ShowControlWindow = false;
public bool IsControlWindowLock = false;
public bool ShowNextActionWindow = false;
public bool IsNextActionWindowLock = false;
public bool IsInfoWindowLock = false;
public bool UseKeyboardCommand = false;
public bool UseGamepadCommand = false;

public Vector4 ControlWindowLockBg = new Vector4(0, 0, 0, 0.6f);
public Vector4 ControlWindowUnlockBg = new Vector4(0, 0, 0, 0.9f);
public Vector4 NextActionWindowBg = new Vector4(0, 0, 0, 0.4f);
public Vector4 InfoWindowBg = new Vector4(0, 0, 0, 0.4f);

public float ControlWindowGCDSize = 40;
public float ControlWindow0GCDSize = 30;
public float ControlWindowNextSizeRatio = 1.5f;
public float ControlProgressHeight = 8;
public bool ControlShowCooldown = false;
public bool ShowCooldownWindow = false;

public Dictionary<StateCommandType, KeyRecord> KeyState { get; set; } = new Dictionary<StateCommandType, KeyRecord>();
public Dictionary<SpecialCommandType, KeyRecord> KeySpecial { get; set; } = new Dictionary<SpecialCommandType, KeyRecord>();
Expand Down
4 changes: 2 additions & 2 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ 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_ShowCooldownWindow { get; set; } = "Show Cooldown Window";
public string ConfigWindow_Control_IsWindowLock { get; set; } = "Lock";
public string ConfigWindow_Control_BackgroundColor { get; set; } = "Control Window's Background";
public string ConfigWindow_Control_NextActionWindowBg { get; set; } = "Next Action Window's Background";
public string ConfigWindow_Control_InfoWindowBg { get; set; } = "Next Action Window's Background";
public string ConfigWindow_Control_ControlWindowGCDSize { get; set; } = "GCD icon size";
public string ConfigWindow_Control_ControlWindow0GCDSize { get; set; } = "0GCD icon size";
public string ConfigWindow_Control_ControlWindowNextSizeRatio { get; set; } = "Next Action Size Ratio";
Expand Down
4 changes: 4 additions & 0 deletions RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public sealed class RotationSolverPlugin : IDalamudPlugin, IDisposable
static RotationConfigWindow _comboConfigWindow;
static ControlWindow _controlWindow;
static NextActionWindow _nextActionWindow;
static CooldownWindow _cooldownWindow;

static readonly List<IDisposable> _dis = new List<IDisposable>();
public string Name => "Rotation Solver";
Expand All @@ -40,10 +41,12 @@ public unsafe RotationSolverPlugin(DalamudPluginInterface pluginInterface)
_comboConfigWindow = new();
_controlWindow = new();
_nextActionWindow = new();
_cooldownWindow = new();
windowSystem = new WindowSystem(Name);
windowSystem.AddWindow(_comboConfigWindow);
windowSystem.AddWindow(_controlWindow);
windowSystem.AddWindow(_nextActionWindow);
windowSystem.AddWindow(_cooldownWindow);

Service.Interface.UiBuilder.OpenConfigUi += OnOpenConfigUi;
Service.Interface.UiBuilder.Draw += windowSystem.Draw;
Expand Down Expand Up @@ -114,5 +117,6 @@ internal static void UpdateDisplayWindow()

_controlWindow.IsOpen = isValid && Service.Config.ShowControlWindow;
_nextActionWindow.IsOpen = isValid && Service.Config.ShowNextActionWindow;
_cooldownWindow.IsOpen = isValid && Service.Config.ShowCooldownWindow;
}
}
79 changes: 0 additions & 79 deletions RotationSolver/UI/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,85 +75,6 @@ public override void Draw()
DrawSpecials();

ImGui.Columns(1);

if(MajorUpdater.IsValid && Service.Config.ControlShowCooldown && RotationUpdater.RightNowRotation!= null)
{
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);

uint started = 0;
foreach(var item in showItems)
{
if (started % 14 != 0)
{
ImGui.SameLine();
}
DrawActionCooldown(item);
started ++;
}
}
}
}

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)
{
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);

if (!act.EnoughLevel)
{
ImGui.GetWindowDrawList().AddRectFilled(new Vector2(pos.X, pos.Y) + winPos,
new Vector2(pos.X + width, pos.Y + width) + winPos, progressCol);
}
else 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) + 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.EnoughLevel && act is IBaseAction bAct && bAct.MaxCharges > 1)
{
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();
}

private static void DrawSpecials()
Expand Down
103 changes: 103 additions & 0 deletions RotationSolver/UI/CooldownWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using ImGuiNET;
using RotationSolver.Basic.Actions;
using RotationSolver.Basic;
using RotationSolver.Updaters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Numerics;

namespace RotationSolver.UI;

internal class CooldownWindow : InfoWindow
{
public CooldownWindow()
:base(nameof(CooldownWindow))
{

}

public override void Draw()
{
if (RotationUpdater.RightNowRotation != null)
{
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);

uint started = 0;
foreach (var item in showItems)
{
if (started % 14 != 0)
{
ImGui.SameLine();
}
DrawActionCooldown(item);
started++;
}
}
}
}

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));
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();

ControlWindow.DrawIAction(act, width);
ImGuiHelper.HoveredString(act.Name);

if (!act.EnoughLevel)
{
ImGui.GetWindowDrawList().AddRectFilled(new Vector2(pos.X, pos.Y) + winPos,
new Vector2(pos.X + width, pos.Y + width) + winPos, progressCol);
}
else 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) + 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.EnoughLevel && act is IBaseAction bAct && bAct.MaxCharges > 1)
{
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();
}

static void TextShade(Vector2 pos, string text, float width, uint fore, uint background)
{
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);
}
}
44 changes: 44 additions & 0 deletions RotationSolver/UI/InfoWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Dalamud.Interface.Windowing;
using ImGuiNET;
using RotationSolver.Basic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RotationSolver.UI;

internal abstract class InfoWindow : Window
{
const ImGuiWindowFlags BaseFlags = ControlWindow.BaseFlags
| ImGuiWindowFlags.AlwaysAutoResize
| ImGuiWindowFlags.NoResize;

public InfoWindow(string name)
: base(name, BaseFlags)
{

}

public override void PreDraw()
{
ImGui.PushStyleColor(ImGuiCol.WindowBg, Service.Config.InfoWindowBg);

Flags = BaseFlags;
if (Service.Config.IsInfoWindowLock)
{
Flags |= ImGuiWindowFlags.NoInputs;
}

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

public override void PostDraw()
{
ImGui.PopStyleColor();
ImGui.PopStyleVar();
base.PostDraw();
}
}
28 changes: 2 additions & 26 deletions RotationSolver/UI/NextActionWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,13 @@

namespace RotationSolver.UI;

internal class NextActionWindow : Window
internal class NextActionWindow : InfoWindow
{
const ImGuiWindowFlags BaseFlags = ControlWindow.BaseFlags
| ImGuiWindowFlags.AlwaysAutoResize
| ImGuiWindowFlags.NoResize;
public NextActionWindow()
: base(nameof(NextActionWindow), BaseFlags)
: base(nameof(NextActionWindow))
{
}

public override void PreDraw()
{
ImGui.PushStyleColor(ImGuiCol.WindowBg, Service.Config.NextActionWindowBg);

Flags = BaseFlags;
if (Service.Config.IsNextActionWindowLock)
{
Flags |= ImGuiWindowFlags.NoInputs;
}

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

public override void PostDraw()
{
ImGui.PopStyleColor();
ImGui.PopStyleVar();
base.PostDraw();
}

public override void Draw()
{
var width = Service.Config.ControlWindowGCDSize * Service.Config.ControlWindowNextSizeRatio;
Expand Down
14 changes: 7 additions & 7 deletions RotationSolver/UI/RotationConfigWindow_Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ private void DrawControlTab()
DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Control_ShowNextActionWindow,
ref Service.Config.ShowNextActionWindow);

if (Service.Config.ShowNextActionWindow)
DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Control_ShowCooldownWindow,
ref Service.Config.ShowCooldownWindow);

if (Service.Config.ShowNextActionWindow || Service.Config.ShowCooldownWindow)
{
DrawColor4(LocalizationManager.RightLang.ConfigWindow_Control_NextActionWindowBg,
ref Service.Config.NextActionWindowBg);
DrawColor4(LocalizationManager.RightLang.ConfigWindow_Control_InfoWindowBg,
ref Service.Config.InfoWindowBg);

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Control_IsWindowLock,
ref Service.Config.IsNextActionWindowLock);
ref Service.Config.IsInfoWindowLock);
}

ImGui.Separator();
Expand All @@ -40,9 +43,6 @@ private void DrawControlTab()
DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Control_IsWindowLock,
ref Service.Config.IsControlWindowLock);

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

if (Service.Config.IsControlWindowLock)
{
DrawColor4(LocalizationManager.RightLang.ConfigWindow_Control_BackgroundColor,
Expand Down

0 comments on commit 2ef07a3

Please sign in to comment.