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

Commit

Permalink
fix: command unify
Browse files Browse the repository at this point in the history
Issues: #584
  • Loading branch information
ArchiDog1998 committed Apr 11, 2024
1 parent 46244fa commit c9cb180
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 100 deletions.
1 change: 0 additions & 1 deletion RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace RotationSolver.Basic.Configuration;

[Command("Settings")]
internal partial class Configs : IPluginConfiguration
{
public int Version { get; set; } = 8;
Expand Down
6 changes: 0 additions & 6 deletions RotationSolver.Basic/Data/UiString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,6 @@ internal enum UiString
[Description("Off")]
SpecialCommandType_Off,

[Description("Open config window.")]
Commands_Rotation,

[Description("Rotation Solver Settings v")]
ConfigWindowHeader,

[Description("This config is job specific")]
JobConfigTip,

Expand Down
1 change: 0 additions & 1 deletion RotationSolver/Commands/RSCommands_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using ECommons.GameHelpers;
using RotationSolver.Basic.Configuration;
using RotationSolver.Data;
using RotationSolver.Localization;
using RotationSolver.UI;
using RotationSolver.Updaters;
using XIVConfigUI;
Expand Down
23 changes: 2 additions & 21 deletions RotationSolver/Commands/RSCommands_BasicInfo.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
using Dalamud.Game.Command;
using ECommons.DalamudServices;
using RotationSolver.Data;
using XIVConfigUI;

namespace RotationSolver.Commands;
namespace RotationSolver.Commands;

public static partial class RSCommands
{
internal static void Enable()
=> Svc.Commands.AddHandler(Service.COMMAND, new CommandInfo(OnCommand)
{
HelpMessage = UiString.Commands_Rotation.Local(),
ShowInHelp = true,
});

internal static void Disable() => Svc.Commands.RemoveHandler(Service.COMMAND);

private static void OnCommand(string command, string arguments)
{
DoOneCommand(arguments);
}

private static void DoOneCommand(string str)
internal static void DoOneCommand(string str)
{
if (TryGetOneEnum<StateCommandType>(str, out var stateType))
{
Expand Down
2 changes: 0 additions & 2 deletions RotationSolver/Localization/Localization.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"RotationSolver.Data.UiString.ConfigWindowHeader": "Rotation Solver Settings v",
"RotationSolver.Data.UiString.Commands_Rotation": "Open config window.",
"RotationSolver.Basic.Data.StateCommandType.Manual": "Start the addon in Manual mode. You need to choose the target manually. This will bypass any engage settings that you have set up and will start attacking immediately once something is targeted.",
"RotationSolver.Basic.Data.StateCommandType.Cancel": "Stop the addon. Always remember to turn it off when it is not in use!",
"RotationSolver.Basic.Data.StateCommandType.Auto": "Start the addon in Auto mode. When out of combat or when combat starts, switches the target according to the set condition.",
Expand Down
18 changes: 1 addition & 17 deletions RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using ECommons;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using ECommons.ImGuiMethods;
using RotationSolver.Basic.Configuration;
using RotationSolver.Basic.Configuration.Timeline;
using RotationSolver.Basic.Configuration.Timeline.TimelineCondition;
Expand All @@ -14,7 +13,6 @@
using RotationSolver.Data;
using RotationSolver.Helpers;
using RotationSolver.UI;
using RotationSolver.UI.SearchableConfigs;
using RotationSolver.Updaters;
using XIVConfigUI;

Expand All @@ -37,7 +35,7 @@ public sealed class RotationSolverPlugin : IDalamudPlugin, IDisposable
public RotationSolverPlugin(DalamudPluginInterface pluginInterface)
{
ECommonsMain.Init(pluginInterface, this, ECommons.Module.DalamudReflector, ECommons.Module.ObjectFunctions);
XIVConfigUIMain.Init(pluginInterface, Service.USERNAME, Service.REPO, Service.COMMAND + "Config");
XIVConfigUIMain.Init(pluginInterface, Service.USERNAME, Service.REPO, Service.COMMAND, "Open config window.", RSCommands.DoOneCommand);
XIVConfigUIMain.ShowTooltip = () => Service.Config.ShowTooltips;

_dis.Add(new Service());
Expand Down Expand Up @@ -71,11 +69,9 @@ public RotationSolverPlugin(DalamudPluginInterface pluginInterface)

PainterManager.Init();

LocalManager.LanguageChanged += ChangeUITranslation;
MajorUpdater.Enable();
Watcher.Enable();
OtherConfiguration.Init();
ChangeUITranslation();

OpenLinkPayload = pluginInterface.AddChatLinkHandler(0, (id, str) =>
{
Expand Down Expand Up @@ -109,21 +105,11 @@ private void OnDraw()
windowSystem.Draw();
}

internal static void ChangeUITranslation()
{
_rotationConfigWindow!.WindowName = UiString.ConfigWindowHeader.Local()
+ typeof(RotationConfigWindow).Assembly.GetName().Version?.ToString() ?? "?.?.?";

RSCommands.Disable();
RSCommands.Enable();
}

public async void Dispose()
{
DataCenter.RightNowDutyRotation?.Dispose();
DataCenter.RightNowRotation?.Dispose();

RSCommands.Disable();
Watcher.Disable();

Svc.PluginInterface.UiBuilder.OpenConfigUi -= OnOpenConfigUi;
Expand All @@ -135,8 +121,6 @@ public async void Dispose()
}
_dis?.Clear();

LocalManager.LanguageChanged -= ChangeUITranslation;

MajorUpdater.Dispose();
PainterManager.Dispose();
XIVConfigUIMain.Dispose();
Expand Down
78 changes: 29 additions & 49 deletions RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace RotationSolver.UI;

public class RotationConfigWindow : ConfigWindow
{
public SearchableCollection AllSearchable { get; } = new(Service.Config,
public override SearchableCollection Collection { get; } = new(Service.Config,
new SearchableConfigRS());

public static Vector3 HoveredPosition { get; private set; } = Vector3.Zero;
Expand All @@ -40,7 +40,7 @@ public class RotationConfigWindow : ConfigWindow
public override IEnumerable<Searchable> Searchables => [.. base.Searchables, ..DataCenter.RightNowRotation?.Configs];

public RotationConfigWindow()
: base("")
: base(typeof(RotationConfigWindow).Assembly.GetName())
{
Size = new Vector2(740f, 490f);
}
Expand Down Expand Up @@ -591,12 +591,7 @@ private static void DrawAboutLinks()
{
var width = ImGui.GetWindowWidth();

if (ImageLoader.GetTexture("https://GitHub-readme-stats.vercel.app/api/pin/?username=ArchiDog1998&repo=RotationSolver&theme=dark", out var icon) && ImGuiHelper.TextureButton(icon, width, width))
{
Util.OpenLink($"https://GitHub.com/{Service.USERNAME}/{Service.REPO}");
}

if (ImageLoader.GetTexture("https://badges.crowdin.net/badge/light/crowdin-on-dark.png", out icon) && ImGuiHelper.TextureButton(icon, width, width))
if (ImageLoader.GetTexture("https://badges.crowdin.net/badge/light/crowdin-on-dark.png", out var icon) && ImGuiHelper.TextureButton(icon, width, width))
{
Util.OpenLink("https://crowdin.com/project/rotationsolver");
}
Expand Down Expand Up @@ -1272,8 +1267,6 @@ public class RotationsItem : ConfigWindowItemRS

public override void Draw(ConfigWindow window)
{
var rsWindow = (RotationConfigWindow)window;

var width = ImGui.GetWindowWidth();

var text = UiString.ConfigWindow_Rotations_Download.Local();
Expand Down Expand Up @@ -1302,7 +1295,7 @@ public override void Draw(ConfigWindow window)

_rotationsHeader ??= new(new()
{
{ () => UiString.ConfigWindow_Rotations_Settings.Local(), () => DrawRotationsSettings(rsWindow)},
{ () => UiString.ConfigWindow_Rotations_Settings.Local(), () => DrawRotationsSettings(window)},
{ () => UiString.ConfigWindow_Rotations_Loaded.Local(), DrawRotationsLoaded},
{ () => UiString.ConfigWindow_Rotations_GitHub.Local(), DrawRotationsGitHub},
{ () => UiString.ConfigWindow_Rotations_Libraries.Local(), DrawRotationsLibraries},
Expand All @@ -1311,9 +1304,9 @@ public override void Draw(ConfigWindow window)
_rotationsHeader?.Draw();
}

private static void DrawRotationsSettings(RotationConfigWindow window)
private static void DrawRotationsSettings(ConfigWindow window)
{
window.AllSearchable.DrawItems((int)UiString.ConfigWindow_Rotations_Settings);
window.Collection.DrawItems((int)UiString.ConfigWindow_Rotations_Settings);
}

private static void DrawRotationsLoaded()
Expand Down Expand Up @@ -1566,15 +1559,13 @@ public class ListItem : ConfigWindowItemRS

public override void Draw(ConfigWindow window)
{
var rsWindow = (RotationConfigWindow)window;

ImGui.TextWrapped(UiString.ConfigWindow_List_Description.Local());

_idsHeader ??= new(new()
{
{ () => UiString.ConfigWindow_List_Statuses.Local(), DrawListStatuses},
{ () => Service.Config.UseDefenseAbility ? UiString.ConfigWindow_List_Actions.Local() : string.Empty,
() => DrawListActions(rsWindow)},
() => DrawListActions(window)},
{() => UiString.ConfigWindow_List_Territories.Local(), DrawListTerritories},
});
_idsHeader?.Draw();
Expand Down Expand Up @@ -1730,7 +1721,7 @@ private static void DrawStatusList(string name, HashSet<uint> statuses, Status[]
}
}

private static void DrawListActions(RotationConfigWindow window)
private static void DrawListActions(ConfigWindow window)
{
ImGui.SetNextItemWidth(ImGui.GetWindowWidth());
ImGui.InputTextWithHint("##Searching the action", UiString.ConfigWindow_List_ActionNameOrId.Local(), ref _actionSearching, 128);
Expand All @@ -1757,12 +1748,12 @@ private static void DrawListActions(RotationConfigWindow window)
DrawActionsList(nameof(OtherConfiguration.HostileCastingTank), OtherConfiguration.HostileCastingTank);

ImGui.TableNextColumn();
window.AllSearchable.DrawItems((int)UiString.ConfigWindow_List_HostileCastingArea);
window.Collection.DrawItems((int)UiString.ConfigWindow_List_HostileCastingArea);
ImGui.TextWrapped(UiString.ConfigWindow_List_HostileCastingAreaDesc.Local());
DrawActionsList(nameof(OtherConfiguration.HostileCastingArea), OtherConfiguration.HostileCastingArea);

ImGui.TableNextColumn();
window.AllSearchable.DrawItems((int)UiString.ConfigWindow_List_HostileCastingKnockback);
window.Collection.DrawItems((int)UiString.ConfigWindow_List_HostileCastingKnockback);
ImGui.TextWrapped(UiString.ConfigWindow_List_HostileCastingKnockbackDesc.Local());
DrawActionsList(nameof(OtherConfiguration.HostileCastingKnockback), OtherConfiguration.HostileCastingKnockback);
}
Expand Down Expand Up @@ -2030,14 +2021,12 @@ public class BasicItem : ConfigWindowItemRS
private CollapsingHeaderGroup? _baseHeader;
public override void Draw(ConfigWindow window)
{
var rsWindow = (RotationConfigWindow)window;

_baseHeader ??= new(new()
{
{ () => UiString.ConfigWindow_Basic_Timer.Local(), () => DrawBasicTimer(rsWindow) },
{ () => UiString.ConfigWindow_Basic_AutoSwitch.Local(), () => DrawBasicAutoSwitch(rsWindow) },
{ () => UiString.ConfigWindow_Basic_Timer.Local(), () => DrawBasicTimer(window) },
{ () => UiString.ConfigWindow_Basic_AutoSwitch.Local(), () => DrawBasicAutoSwitch(window) },
{ () => UiString.ConfigWindow_Basic_NamedConditions.Local(), DrawBasicNamedConditions },
{ () => UiString.ConfigWindow_Basic_Others.Local(), () => DrawBasicOthers(rsWindow) },
{ () => UiString.ConfigWindow_Basic_Others.Local(), () => DrawBasicOthers(window) },
});
_baseHeader?.Draw();
}
Expand Down Expand Up @@ -2098,7 +2087,7 @@ private static void AddPingLockTime(ImDrawListPtr drawList, Vector2 lineStart, f
time += clickTime;
}
}
private static void DrawBasicTimer(RotationConfigWindow window)
private static void DrawBasicTimer(ConfigWindow window)
{
var gcdTime = DataCenter.WeaponTotal;
if (gcdTime == 0) gcdTime = 2.5f;
Expand Down Expand Up @@ -2188,7 +2177,7 @@ private static void DrawBasicTimer(RotationConfigWindow window)

ImGui.Spacing();

window.AllSearchable.DrawItems((int)UiString.ConfigWindow_Basic_Timer);
window.Collection.DrawItems((int)UiString.ConfigWindow_Basic_Timer);
}

private static readonly CollapsingHeaderGroup _autoSwitch = new(new()
Expand All @@ -2209,9 +2198,9 @@ private static void DrawBasicTimer(RotationConfigWindow window)
{
HeaderSize = FontSize.Forth,
};
private static void DrawBasicAutoSwitch(RotationConfigWindow window)
private static void DrawBasicAutoSwitch(ConfigWindow window)
{
window.AllSearchable.DrawItems((int)UiString.ConfigWindow_Basic_AutoSwitch);
window.Collection.DrawItems((int)UiString.ConfigWindow_Basic_AutoSwitch);
_autoSwitch?.Draw();
}

Expand Down Expand Up @@ -2265,9 +2254,9 @@ private static void DrawBasicNamedConditions()
}
}

private static void DrawBasicOthers(RotationConfigWindow window)
private static void DrawBasicOthers(ConfigWindow window)
{
window.AllSearchable.DrawItems((int)UiString.ConfigWindow_Basic_Others);
window.Collection.DrawItems((int)UiString.ConfigWindow_Basic_Others);

if (Service.Config.SayHelloToAll)
{
Expand Down Expand Up @@ -2304,8 +2293,7 @@ public class UIItem : ConfigWindowItemRS

public override void Draw(ConfigWindow window)
{
var rsWindow = (RotationConfigWindow)window;
_UIHeader ??= rsWindow.AllSearchable.GetGroups<UiString>([
_UIHeader ??= window.Collection.GetGroups<UiString>([
UiString.ConfigWindow_UI_Information,
UiString.ConfigWindow_UI_Overlay,
UiString.ConfigWindow_UI_Windows,
Expand All @@ -2323,8 +2311,6 @@ public class AutoItem : ConfigWindowItemRS

public override void Draw(ConfigWindow window)
{
var rsWindow = (RotationConfigWindow)window;

ImGui.TextWrapped(UiString.ConfigWindow_Auto_Description.Local());
_autoHeader ??= new(new()
{
Expand All @@ -2334,10 +2320,10 @@ public override void Draw(ConfigWindow window)
.Local());
ImGui.Separator();

rsWindow.AllSearchable.DrawItems((int)UiString.ConfigWindow_Auto_ActionUsage);
window.Collection.DrawItems((int)UiString.ConfigWindow_Auto_ActionUsage);
}
},
{ () => UiString.ConfigWindow_Auto_ActionCondition.Local(), () => DrawAutoActionCondition(rsWindow) },
{ () => UiString.ConfigWindow_Auto_ActionCondition.Local(), () => DrawAutoActionCondition(window) },
{ () => UiString.ConfigWindow_Auto_StateCondition.Local(), () => _autoState?.Draw() },
});

Expand Down Expand Up @@ -2405,12 +2391,12 @@ public override void Draw(ConfigWindow window)
HeaderSize = FontSize.Forth,
};

private static void DrawAutoActionCondition(RotationConfigWindow window)
private static void DrawAutoActionCondition(ConfigWindow window)
{
ImGui.TextWrapped(UiString.ConfigWindow_Auto_ActionCondition_Description.Local());
ImGui.Separator();

window.AllSearchable.DrawItems((int)UiString.ConfigWindow_Auto_ActionCondition);
window.Collection.DrawItems((int)UiString.ConfigWindow_Auto_ActionCondition);
}
}

Expand All @@ -2423,19 +2409,17 @@ public class TargetItem : ConfigWindowItemRS

public override void Draw(ConfigWindow window)
{
var rsWindow = (RotationConfigWindow)window;

_targetHeader ??= new(new()
{
{ () =>UiString.ConfigWindow_Target_Config.Local(), () => DrawTargetConfig(rsWindow) },
{ () =>UiString.ConfigWindow_Target_Config.Local(), () => DrawTargetConfig(window) },
{ () =>UiString.ConfigWindow_List_Hostile.Local(), DrawTargetHostile },
});
_targetHeader?.Draw();
}

private static void DrawTargetConfig(RotationConfigWindow window)
private static void DrawTargetConfig(ConfigWindow window)
{
window.AllSearchable.DrawItems((int)UiString.ConfigWindow_Target_Config);
window.Collection.DrawItems((int)UiString.ConfigWindow_Target_Config);
}

private static void DrawTargetHostile()
Expand Down Expand Up @@ -2512,14 +2496,12 @@ public class ExtraItem : ConfigWindowItemRS

public override void Draw(ConfigWindow window)
{
var rsWindow = (RotationConfigWindow)window;

_extraHeader ??= new(new()
{
{ () =>UiString.ConfigWindow_EventItem.Local(), DrawEventTab },
{
() =>UiString.ConfigWindow_Extra_Others.Local(),
() => rsWindow.AllSearchable.DrawItems((int)UiString.ConfigWindow_Extra_Others)
() => window.Collection.DrawItems((int)UiString.ConfigWindow_Extra_Others)
},
});
ImGui.TextWrapped(UiString.ConfigWindow_Extra_Description.Local());
Expand Down Expand Up @@ -2572,9 +2554,7 @@ public class DebutItem : ConfigWindowItemRS
public override uint Icon => 5;
public override void Draw(ConfigWindow window)
{
var rsWindow = (RotationConfigWindow)window;

rsWindow.AllSearchable.DrawItems(-1);
window.Collection.DrawItems(-1);

if (!Player.Available || !Service.Config.InDebug) return;

Expand Down
Loading

0 comments on commit c9cb180

Please sign in to comment.