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

Commit

Permalink
fix: ctrl window and cd window.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 17, 2023
1 parent 33e9a31 commit 1a7717a
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 269 deletions.
6 changes: 1 addition & 5 deletions RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,6 @@ public enum PluginConfigInt : byte

[Default(0)] TargetingIndex,
[Default(0)] BeneficialAreaStrategy,

[Obsolete]
[Default(15, 1, 30)] CooldownActionOneLine,
[Default(0, 0, 100)] MoveTargetAngle
}

public enum PluginConfigBool : byte
Expand Down Expand Up @@ -387,7 +383,7 @@ public enum PluginConfigFloat : byte
[Default(1f)] CountdownDelayMax,
[Default(0.6f, 0.5f, 0.7f)] CountDownAhead,

[Default(24f)] MoveTargetAngle,
[Default(24f, 0f, 90f)] MoveTargetAngle,
[Default(60f, 10f, 1800f)] DeadTimeBoss,
[Default(10f, 0f, 60f)] DeadTimeDying,

Expand Down
6 changes: 3 additions & 3 deletions RotationSolver/Localization/ConfigTranslation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ internal static class ConfigTranslation
public static string ToName(this PluginConfigInt config) => config switch
{
PluginConfigInt.PoslockModifier => LocalizationManager.RightLang.ConfigWindow_Param_PoslockModifier,
PluginConfigInt.MoveTargetAngle => LocalizationManager.RightLang.ConfigWindow_Param_MoveTargetAngle,

// UI
PluginConfigInt.KeyBoardNoiseMin => LocalizationManager.RightLang.ConfigWindow_Param_KeyBoardNoiseTimes,
PluginConfigInt.LessMPNoRaise => LocalizationManager.RightLang.ConfigWindow_Param_LessMPNoRaise,
PluginConfigInt.CooldownActionOneLine => LocalizationManager.RightLang.ConfigWindow_Control_CooldownActionOneLine,
_ => string.Empty,
};

Expand Down Expand Up @@ -178,6 +176,7 @@ internal static class ConfigTranslation
PluginConfigFloat.HealthDifference => LocalizationManager.RightLang.ConfigWindow_Param_HealthDifference,
PluginConfigFloat.HealthHealerRatio => LocalizationManager.RightLang.ConfigWindow_Param_HealthHealerRatio,
PluginConfigFloat.HealthTankRatio => LocalizationManager.RightLang.ConfigWindow_Param_HealthTankRatio,
PluginConfigFloat.MoveTargetAngle => LocalizationManager.RightLang.ConfigWindow_Param_MoveTargetAngle,

// target
PluginConfigFloat.DeadTimeBoss => LocalizationManager.RightLang.ConfigWindow_Param_DeadTimeBoss,
Expand Down Expand Up @@ -215,7 +214,6 @@ internal static class ConfigTranslation
{
PluginConfigInt.PoslockModifier => LocalizationManager.RightLang.ConfigWindow_Param_PoslockDescription,

PluginConfigInt.MoveTargetAngle => LocalizationManager.RightLang.ConfigWindow_Param_MoveTargetAngleDesc,
_ => string.Empty,
};

Expand All @@ -235,6 +233,8 @@ internal static class ConfigTranslation

public static string ToDescription(this PluginConfigFloat config) => config switch
{
PluginConfigFloat.MoveTargetAngle => LocalizationManager.RightLang.ConfigWindow_Param_MoveTargetAngleDesc,

_ => string.Empty,
};

Expand Down
2 changes: 0 additions & 2 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ internal partial class Strings
public string ConfigWindow_Control_ShowItemsCooldown { get; set; } = "Show Items' Cooldown";
public string ConfigWindow_Control_ShowGCDCooldown { get; set; } = "Show GCD' Cooldown";
public string ConfigWindow_Control_UseOriginalCooldown { get; set; } = "Show Original Cooldown";
public string ConfigWindow_Control_CooldownActionOneLine { get; set; } = "The count of cooldown actions in one line.";
public string ConfigWindow_Control_CooldownFontSize { get; set; } = "Change the cooldown font size.";
public string ConfigWindow_Control_UnlockBackgroundColor { get; set; } = "Unlocked Control Window's Background";
public string ConfigWindow_Control_LockBackgroundColor { get; set; } = "Locked Control Window's Background";
Expand All @@ -259,7 +258,6 @@ internal partial class Strings
public string ConfigWindow_Control_ControlWindow0GCDSize { get; set; } = "0GCD icon size";
public string ConfigWindow_Control_CooldownWindowIconSize { get; set; } = "Cooldown icon size";
public string ConfigWindow_Control_ControlWindowNextSizeRatio { get; set; } = "Next Action Size Ratio";
public string ConfigWindow_Control_ResetButtonOrKeyCommand { get; set; } = "Right click to reset the gamepad button or key board key.\nHold Left Ctrl and middle click to clear the key setting.";
public string ConfigWindow_Control_ClickToUse { get; set; } = "Click to use it!";
public string ConfigWindow_Rotation_BetaRotation { get; set; } = "Beta Rotation!";

Expand Down
187 changes: 25 additions & 162 deletions RotationSolver/UI/ControlWindow.cs
Original file line number Diff line number Diff line change
@@ -1,61 +1,27 @@
using Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing;
using ECommons.DalamudServices;
using ImGuiScene;
using RotationSolver.Basic.Configuration;
using RotationSolver.Commands;
using RotationSolver.Localization;
using RotationSolver.Updaters;
using System.Drawing;

namespace RotationSolver.UI;

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

public static IAction Wrong { get; set; }
public static DateTime DidTime { get; set; }

public ControlWindow()
: base(nameof(ControlWindow), BaseFlags)
: base(nameof(ControlWindow))
{
Size = new Vector2(570f, 300f);
SizeCondition = ImGuiCond.FirstUseEver;
}

public override void PreDraw()
{

Vector4 bgColor = Service.Config.GetValue(PluginConfigBool.IsControlWindowLock)
? Service.Config.GetValue(PluginConfigVector4.ControlWindowLockBg)
: Service.Config.GetValue(PluginConfigVector4.ControlWindowUnlockBg);
ImGui.PushStyleColor(ImGuiCol.WindowBg, bgColor);

Flags = BaseFlags;

if (Service.Config.GetValue(PluginConfigBool.IsControlWindowLock))
{
Flags |= ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove;
}

ImGui.PushStyleVar(ImGuiStyleVar.WindowBorderSize, 0);
}

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

public override void Draw()
{

ImGui.Columns(3, "Control Bolder", false);
var gcd = Service.Config.GetValue(PluginConfigFloat.ControlWindowGCDSize)
* Service.Config.GetValue(PluginConfigFloat.ControlWindowNextSizeRatio);
Expand Down Expand Up @@ -218,7 +184,7 @@ static void DrawCommandAction(IAction gcd, IAction ability, SpecialCommandType c
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + Math.Max(0, width / 2 - strWidth / 2));
ImGui.TextColored(color, str);

var help = GetHelp(command);
var help = command.ToHelp();
string baseId = "ImgButton" + command.ToString();

ImGui.SetCursorPosX(ImGui.GetCursorPosX() + Math.Max(0, strWidth / 2 - width / 2));
Expand Down Expand Up @@ -260,12 +226,12 @@ public static void HighLight(Vector2 pt, Vector2 size, float thickness = 2f)

static void DrawCommandAction(IAction ability, SpecialCommandType command, Vector4 color)
{
if (IconSet.GetTexture(ability, out var texture)) DrawCommandAction(texture, command, color);
if (ability.GetTexture(out var texture)) DrawCommandAction(texture, command, color);
}

static void DrawCommandAction(uint iconId, SpecialCommandType command, Vector4 color)
{
if(IconSet.GetTexture(iconId, out var texture)) DrawCommandAction(texture, command, color);
if (IconSet.GetTexture(iconId, out var texture)) DrawCommandAction(texture, command, color);
}

static void DrawCommandAction(TextureWrap texture, SpecialCommandType command, Vector4 color)
Expand All @@ -281,7 +247,7 @@ static void DrawCommandAction(TextureWrap texture, SpecialCommandType command, V
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + Math.Max(0, width / 2 - strWidth / 2));
ImGui.TextColored(color, str);

var help = GetHelp(command);
var help = command.ToHelp();
string baseId = "ImgButton" + command.ToString();

ImGui.SetCursorPosX(ImGui.GetCursorPosX() + Math.Max(0, strWidth / 2 - width / 2));
Expand Down Expand Up @@ -317,7 +283,7 @@ static void DrawCommandAction(uint iconId, StateCommandType command, Vector4 col
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + Math.Max(0, width / 2 - strWidth / 2));
ImGui.TextColored(color, str);

var help = GetHelp(command);
var help = command.ToHelp();
string baseId = "ImgButton" + command.ToString();

if(IconSet.GetTexture(iconId, out var texture))
Expand Down Expand Up @@ -347,59 +313,39 @@ static void DrawCommandAction(uint iconId, StateCommandType command, Vector4 col
}
}

static string GetHelp(SpecialCommandType command)
{
var help = command.ToHelp() + "\n ";

return help += "\n \n" + LocalizationManager.RightLang.ConfigWindow_Control_ResetButtonOrKeyCommand;
}

static string GetHelp(StateCommandType command)
{
var help = command.ToHelp() + "\n ";

return help += "\n \n" + LocalizationManager.RightLang.ConfigWindow_Control_ResetButtonOrKeyCommand;
}


static void DrawIAction(nint handle, string id, float width, SpecialCommandType command, string help)
{
ImGui.PushID(id);
if (ImGui.ImageButton(handle, new Vector2(width, width)))
var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(handle, Vector2.One * width, id))
{
Svc.Commands.ProcessCommand(command.GetCommandStr());
}
ImGui.PopID();
if (ImGui.IsItemHovered())
{
ImguiTooltips.ShowTooltip(help);
}
RotationConfigWindow.DrawActionOverlay(cursor, width, IconSet.GetTexture(0u, out var text) && text.ImGuiHandle == handle ? 0 : 1);
ImguiTooltips.HoveredTooltip(help);
}

static void DrawIAction(nint handle, string id, float width, StateCommandType command, string help)
{
ImGui.PushID(id);
if (ImGui.ImageButton(handle, new Vector2(width, width)))
var cursor = ImGui.GetCursorPos();
if(RotationConfigWindow.NoPaddingNoColorImageButton(handle, Vector2.One * width, id))
{
Svc.Commands.ProcessCommand(command.GetCommandStr());
}
ImGui.PopID();
if (ImGui.IsItemHovered())
{
ImguiTooltips.ShowTooltip(help);
}
RotationConfigWindow.DrawActionOverlay(cursor, width, 1);
ImguiTooltips.HoveredTooltip(help);
}

internal static (Vector2, Vector2) DrawIAction(IAction action, float width, float percent, bool isAdjust = true)
{
if (!IconSet.GetTexture(action, out var texture, isAdjust)) return (default, default);
var result = DrawIAction(texture.ImGuiHandle, width, action == null ? -1 : percent);
if (action != null) ImGuiHelper.HoveredString(action.Name, () =>
if (!action.GetTexture(out var texture, isAdjust)) return (default, default);

var cursor = ImGui.GetCursorPos();
if (RotationConfigWindow.NoPaddingNoColorImageButton(texture.ImGuiHandle, Vector2.One * width, action.Name))
{
if (!DataCenter.State)
{
bool canDoIt = false;
if(action is IBaseAction act)
if (action is IBaseAction act)
{
BaseAction.SkipDisable = true;
canDoIt = act.CanUse(out _, CanUseOption.MustUse | CanUseOption.EmptyOrSkipCombo | CanUseOption.IgnoreClippingCheck);
Expand All @@ -409,95 +355,18 @@ internal static (Vector2, Vector2) DrawIAction(IAction action, float width, floa
{
canDoIt = item.CanUse(out _, true);
}
if(canDoIt) action.Use();
if (canDoIt) action.Use();
}
else
{
DataCenter.AddCommandAction(action, 5);
}
});
return result;
}

internal static (Vector2, Vector2) DrawIAction(nint handle, float width, float percent)
{
var cursor = ImGui.GetCursorPos();
ImGui.BeginGroup();

var pt = ImGui.GetCursorPos();
ImGui.Image(handle, new Vector2(width, width));
var size = ImGui.GetItemRectSize();
var pixPerUnit = width / 82;

if (percent < 0)
{
if (IconSet.GetTexture("ui/uld/icona_frame_hr1.tex", out var cover))
{
ImGui.SetCursorPos(cursor - new Vector2(pixPerUnit * 3, pixPerUnit * 4));

var step = new Vector2(88f / cover.Width, 96f / cover.Height);
var start = new Vector2((96f * 0 + 4f) / cover.Width, (96f * 2) / cover.Height);

//Out Size is 88, 96
//Inner Size is 82, 82
ImGui.Image(cover.ImGuiHandle, new Vector2(pixPerUnit * 88, pixPerUnit * 96),
start, start + step);
}
}
else if (percent < 1)
{
if (IconSet.GetTexture("ui/uld/icona_recast_hr1.tex", out var cover))
{
ImGui.SetCursorPos(cursor - new Vector2(pixPerUnit * 3, pixPerUnit * 0));

var P = (int)(percent * 81);


var step = new Vector2(88f / cover.Width, 96f / cover.Height);
var start = new Vector2(P % 9 * step.X, P / 9 * step.Y);

//Out Size is 88, 96
//Inner Size is 82, 82
ImGui.Image(cover.ImGuiHandle, new Vector2(pixPerUnit * 88, pixPerUnit * 96),
start, start + step);
}
}
else
{
if (IconSet.GetTexture("ui/uld/icona_frame_hr1.tex", out var cover))
{

ImGui.SetCursorPos(cursor - new Vector2(pixPerUnit * 3, pixPerUnit * 4));

//Out Size is 88, 96
//Inner Size is 82, 82
ImGui.Image(cover.ImGuiHandle, new Vector2(pixPerUnit * 88, pixPerUnit * 96),
new Vector2(4f / cover.Width, 0f / cover.Height),
new Vector2(92f / cover.Width, 96f / cover.Height));
}
}

if (percent > 1)
{
if (IconSet.GetTexture("ui/uld/icona_recast2_hr1.tex", out var cover))
{
ImGui.SetCursorPos(cursor - new Vector2(pixPerUnit * 3, pixPerUnit * 0));

var P = (int)(percent % 1 * 81);

var step = new Vector2(88f / cover.Width, 96f / cover.Height);
var start = new Vector2((P % 9 + 9) * step.X, P / 9 * step.Y);

//Out Size is 88, 96
//Inner Size is 82, 82
ImGui.Image(cover.ImGuiHandle, new Vector2(pixPerUnit * 88, pixPerUnit * 96),
start, start + step);
}
}
var size = ImGui.GetItemRectSize();
RotationConfigWindow.DrawActionOverlay(cursor, width, action == null ? -1 : percent);
ImguiTooltips.HoveredTooltip(action.Name);


ImGui.EndGroup();
return (pt, size);
return (cursor, size);
}

static unsafe void DrawNextAction(float gcd, float ability, float width)
Expand All @@ -515,11 +384,5 @@ static unsafe void DrawNextAction(float gcd, float ability, float width)
ImGui.SameLine();

DrawIAction(next, ability, -1);
if (ImGui.IsItemHovered())
{
var help = LocalizationManager.RightLang.ConfigWindow_Control_ResetButtonOrKeyCommand;

ImguiTooltips.ShowTooltip(help);
}
}
}
Loading

0 comments on commit 1a7717a

Please sign in to comment.