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 next action window.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 21, 2023
1 parent ffc816f commit 2f3de8f
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 194 deletions.
1 change: 1 addition & 0 deletions RotationSolver.Basic/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public class PluginConfiguration : IPluginConfiguration
public MacroInfo DutyEnd { get; set; } = new MacroInfo();

public bool ShowControlWindow = false;
public bool ShowNextActionWindow = false;
public bool IsControlWindowLock = false;
public bool UseKeyboardCommand = false;
public bool UseGamepadCommand = false;
Expand Down
138 changes: 0 additions & 138 deletions RotationSolver.Old/Full Rotation1.cs

This file was deleted.

27 changes: 0 additions & 27 deletions RotationSolver.Old/Simple Rotation1.cs

This file was deleted.

2 changes: 2 additions & 0 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ internal partial class Strings
public string ConfigWindow_Param_ConditionDown { get; set; } = "Down";
public string ConfigWindow_Param_ConditionDelete { get; set; } = "Delete";

public string ConfigWindow_Control_ShowNextActionWindow { get; set; } = "Show Next Action Window";

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";
Expand Down
6 changes: 5 additions & 1 deletion RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public sealed class RotationSolverPlugin : IDalamudPlugin, IDisposable

static RotationConfigWindow _comboConfigWindow;
static ControlWindow _controlWindow;
static NextActionWindow _nextActionWindow;

static readonly List<IDisposable> _dis = new List<IDisposable>();
public string Name => "Rotation Solver";
Expand All @@ -37,9 +38,11 @@ public unsafe RotationSolverPlugin(DalamudPluginInterface pluginInterface)

_comboConfigWindow = new();
_controlWindow = new();
_nextActionWindow = new();
windowSystem = new WindowSystem(Name);
windowSystem.AddWindow(_comboConfigWindow);
windowSystem.AddWindow(_controlWindow);
windowSystem.AddWindow(_nextActionWindow);

Service.Interface.UiBuilder.OpenConfigUi += OnOpenConfigUi;
Service.Interface.UiBuilder.Draw += windowSystem.Draw;
Expand Down Expand Up @@ -101,8 +104,9 @@ internal static void OpenConfigWindow()
_comboConfigWindow.Toggle();
}

internal static void UpdateControlWindow()
internal static void UpdateDisplayWindow()
{
_controlWindow.IsOpen = MajorUpdater.IsValid && Service.Config.ShowControlWindow;
_nextActionWindow.IsOpen = MajorUpdater.IsValid && Service.Config.ShowNextActionWindow;
}
}
20 changes: 4 additions & 16 deletions RotationSolver/UI/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@ namespace RotationSolver.UI;

internal class ControlWindow : Window
{
const ImGuiWindowFlags _baseFlags = ImGuiWindowFlags.NoScrollbar
| ImGuiWindowFlags.NoCollapse
| ImGuiWindowFlags.NoTitleBar
| ImGuiWindowFlags.NoNav
| ImGuiWindowFlags.NoScrollWithMouse;

public ControlWindow()
: base(nameof(ControlWindow), _baseFlags)
: base(nameof(ControlWindow), NextActionWindow.BaseFlags)
{
Size = new Vector2(540f, 490f);
SizeCondition = ImGuiCond.FirstUseEver;
Expand All @@ -40,7 +34,7 @@ public override void PreDraw()
: Service.Config.ControlWindowUnlockBg;
ImGui.PushStyleColor(ImGuiCol.WindowBg, bgColor);

Flags = _baseFlags;
Flags = NextActionWindow.BaseFlags;

if (Service.Config.IsControlWindowLock)
{
Expand Down Expand Up @@ -414,7 +408,7 @@ static void DrawIAction(nint handle, string id, float width, StateCommandType co
}
}

static void DrawIAction(IAction action, float width)
internal static void DrawIAction(IAction action, float width)
{
DrawIAction(GetTexture(action).ImGuiHandle, width);
}
Expand All @@ -426,21 +420,15 @@ static void DrawIAction(nint handle, float width)

static unsafe float DrawNextAction()
{
var group = ActionManager.Instance()->GetRecastGroupDetail(ActionHelper.GCDCooldownGroup - 1);
var remain = group->Total - group->Elapsed;

var gcd = Service.Config.ControlWindowGCDSize * Service.Config.ControlWindowNextSizeRatio;
var ability = Service.Config.ControlWindow0GCDSize * Service.Config.ControlWindowNextSizeRatio;
var width = gcd + ability + ImGui.GetStyle().ItemSpacing.X;

var str = "Next Action";
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + width / 2 - ImGui.CalcTextSize(str).X / 2);
ImGui.TextColored(ImGuiColors.DalamudYellow, str);
str = remain.ToString("F2") + "s";

ImGui.SetCursorPosX(ImGui.GetCursorPosX() + width / 2 - ImGui.CalcTextSize(str).X / 2);
ImGui.Text(str);
ImGui.ProgressBar(group->Elapsed / group->Total, new Vector2(width, Service.Config.ControlProgressHeight), string.Empty);
NextActionWindow.DrawGcdCooldown(width, true);

DrawIAction(ActionUpdater.NextGCDAction, gcd);

Expand Down
87 changes: 87 additions & 0 deletions RotationSolver/UI/NextActionWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing;
using FFXIVClientStructs.FFXIV.Client.Game;
using ImGuiNET;
using RotationSolver.Basic;
using RotationSolver.Basic.Helpers;
using RotationSolver.Updaters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace RotationSolver.UI;

internal class NextActionWindow : Window
{
public const ImGuiWindowFlags BaseFlags = ImGuiWindowFlags.NoScrollbar
| ImGuiWindowFlags.NoCollapse
| ImGuiWindowFlags.NoTitleBar
| ImGuiWindowFlags.NoNav
| ImGuiWindowFlags.NoScrollWithMouse;

public NextActionWindow()
: base(nameof(NextActionWindow), BaseFlags
| ImGuiWindowFlags.AlwaysAutoResize
| ImGuiWindowFlags.NoResize
| ImGuiWindowFlags.NoInputs)
{
}

public override void Draw()
{
var width = Service.Config.ControlWindowGCDSize * Service.Config.ControlWindowNextSizeRatio;
DrawGcdCooldown(width, false);
ControlWindow.DrawIAction(ActionUpdater.NextAction, width);
}

public static unsafe void DrawGcdCooldown(float width, bool drawTittle)
{
var group = ActionManager.Instance()->GetRecastGroupDetail(ActionHelper.GCDCooldownGroup - 1);
var remain = group->Total - group->Elapsed;

if(drawTittle)
{
var str = remain.ToString("F2") + "s";
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + width / 2 - ImGui.CalcTextSize(str).X / 2);
ImGui.Text(str);
}

var cursor = ImGui.GetCursorPos() + ImGui.GetWindowPos();
var height = Service.Config.ControlProgressHeight;
var total = DataCenter.WeaponTotal;
var interval = Service.Config.AbilitiesInterval;

ImGui.ProgressBar(group->Elapsed / group->Total, new Vector2(width, height), string.Empty);

foreach (var value in CalculateValue(total, interval))
{
if (value < DataCenter.CastingTotal) continue;
var pt = cursor + new Vector2(total, 0) * value / total;

ImGui.GetWindowDrawList().AddLine(pt, pt + new Vector2(0, height),
ImGui.ColorConvertFloat4ToU32(ImGuiColors.DalamudRed));
}
}

static float[] CalculateValue(float total, float interval)
{
if(interval <= 0 || total <= 0 || interval <= total) return new float[0];

var count = (int)(total / interval);
var result = new List<float>(count);

if(count > 1)
{
for (int i = 1; i < count; i++)
{
result.Add(i * interval);
}
}

result.Add(total - interval);
return result.ToArray();
}
}
3 changes: 3 additions & 0 deletions RotationSolver/UI/RotationConfigWindow_Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ private void DrawControlTab()

ImGui.Separator();

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Control_ShowNextActionWindow,
ref Service.Config.ShowNextActionWindow);

DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Control_ShowControlWindow,
ref Service.Config.ShowControlWindow);

Expand Down
Loading

0 comments on commit 2f3de8f

Please sign in to comment.