Skip to content

Commit

Permalink
Merge pull request #122 from FFXIV-CombatReborn/config-overhaul
Browse files Browse the repository at this point in the history
Overhauled how rotations load. All rotations are now opt-in. Please see the rotations tab in the /rotations window for more details.
  • Loading branch information
NostraThomas99 authored Apr 22, 2024
2 parents a15ee3d + 4fc318b commit 6513444
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 236 deletions.
28 changes: 16 additions & 12 deletions RotationSolver.Basic/Configuration/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ECommons.ExcelServices;
using Newtonsoft.Json.Linq;
using RotationSolver.Basic.Configuration.Timeline;
using System.Windows.Forms.VisualStyles;
using static RotationSolver.Basic.Configuration.ConfigTypes;

namespace RotationSolver.Basic.Configuration;
Expand All @@ -28,14 +29,16 @@ public const string

public int Version { get; set; } = 8;

public string LastSeenChangelog { get; set; } = "0.0.0";
public string LastSeenChangelog { get; set; } = "0.0.0.0";
public bool FirstTimeSetupDone { get; set; } = false;

public List<ActionEventInfo> Events { get; private set; } = [];
public SortedSet<Job> DisabledJobs { get; private set; } = [];

public string[] OtherLibs { get; set; } = [];
[JsonIgnore]
public static string[] DefaultRotations = ["https://github.com/FFXIV-CombatReborn/LTSDefaults/releases/latest/download/DefaultRotations.dll"];

public string[] GitHubLibs { get; set; } = [];
public string[] RotationLibs { get; set; } = DefaultRotations;
public List<TargetingType> TargetingTypes { get; set; } = [];

public MacroInfo DutyStart { get; set; } = new MacroInfo();
Expand Down Expand Up @@ -254,13 +257,18 @@ public const string

[ConditionBool, UI("Debug Mode", Filter = Debug)]
private static readonly bool _inDebug = false;
public bool AutoUpdateLibs { get; set; } = false;

[ConditionBool, UI("Auto Download Rotations", Filter = Rotations)]
private static readonly bool _downloadRotations = true;
[ConditionBool, UI("Load rotations automatically at startup", Filter = Rotations)]
private static readonly bool _autoLoadRotations = false;

[ConditionBool, UI("Download custom rotations from the internet",
Description = "This will allow RSR to download custom rotations from the internet. This is a security risk and should only be enabled if you trust the source of the rotations.",
Filter = Rotations)]
private static readonly bool _downloadCustomRotations = true;

[ConditionBool, UI("Auto Update Rotations", Parent = nameof(DownloadRotations))]
private static readonly bool _autoUpdateRotations = true;
[ConditionBool, UI("Monitor local rotations for changes (Developer Mode)",
Filter = Rotations)]
private static readonly bool _autoReloadRotations = false;

[ConditionBool, UI("Make /rotation Manual as a toggle command.",
Filter = BasicParams)]
Expand Down Expand Up @@ -310,10 +318,6 @@ public const string
Filter = UiInformation)]
private static readonly bool _showTooltips = true;

[ConditionBool, UI("Auto load rotations",
Filter = Rotations)]
private static readonly bool _autoLoadCustomRotations = true;

[ConditionBool, UI("Target Fate priority",
Filter = TargetConfig, Section = 1)]
private static readonly bool _targetFatePriority = true;
Expand Down
1 change: 0 additions & 1 deletion RotationSolver.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitignore = .gitignore
Resources\ContributorsHash.json = Resources\ContributorsHash.json
Directory.Build.props = Directory.Build.props
Resources\downloadList.json = Resources\downloadList.json
Resources\IncompatiblePlugins.json = Resources\IncompatiblePlugins.json
manifest.json = manifest.json
UpdateDownloads.ts = UpdateDownloads.ts
Expand Down
52 changes: 50 additions & 2 deletions RotationSolver/Data/UiString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ internal enum UiString
[Description("The condition set you chose, click to modify.")]
ConfigWindow_ConditionSetDesc,

[Description("No rotations loaded! Please see the rotations tab!")]
ConfigWindow_NoRotation,

[Description("The duty rotation you chose, click to modify.")]
ConfigWindow_DutyRotationDesc,

Expand Down Expand Up @@ -156,9 +159,24 @@ internal enum UiString
[Description("Conditions for automatic use of action being disabled.")]
ConfigWindow_Actions_DisabledConditionSet_Description,

[Description("Download Rotations")]
[Description("It looks like this might be your first time here. Rotation Solver Reborn does not come with rotations out of the box, but you can download ones created by the community. You can also create your own rotations! For your convenience, Rotation Solver Reborn comes pre-loaded with links to well-known community rotations, but it still your responsibility to install them.")]
ConfigWindow_Rotations_FirstTime,

[Description("Custom rotations are just like plugins and have full access to the game and your computer")]
ConfigWindow_Rotations_Warning,

[Description("Please only load rotations from sources that you trust")]
ConfigWindow_Rotations_Warning2,

[Description("Update Rotations")]
ConfigWindow_Rotations_Download,

[Description("Reset To Defaults")]
ConfigWindow_Rotations_Reset,

[Description("Rotation Sources:")]
ConfigWindow_Rotations_Sources,

[Description("Links of the rotations online")]
ConfigWindow_Rotations_Links,

Expand All @@ -183,7 +201,7 @@ internal enum UiString
[Description("File Name")]
ConfigWindow_Rotations_FileName,

[Description("The folder contains rotation libs or the download url about rotation lib.")]
[Description("The folder contains the rotation library or the download url for the rotation library.")]
ConfigWindow_Rotations_Library,

[Description("In this window, you can set the parameters that can be customised using lists.")]
Expand Down Expand Up @@ -731,4 +749,34 @@ internal enum UiString

[Description("The duration of this action.")]
TimelineItemDuration,

[Description("Welcome to Rotation Solver Reborn!")]
WelcomeWindow_Header,

[Description("Here's what you missed since the last time you were here")]
WelcomeWindow_WelcomeBack,

[Description("It looks like you might be new here! Let's get you started!")]
WelcomeWindow_Welcome,

[Description("Rotation Solver Reborn does not come with rotations out of the box, but for your convenience a link to a set of rotations maintained by the Combat Reborn team is included by default.")]
WelcomeWindow_FirstTime,

[Description("Would you like to install the default rotations now?")]
WelcomeWindow_FirstTime2,

[Description("Some other settings you may want to consider:")]
WelcomeWindow_FirstTime3,

[Description("Click here to install")]
WelcomeWindow_SaveAndInstall,

[Description("Recent Changes:")]
WelcomeWindow_Changelog,

[Description("Do you want your rotations to update and reload automatically upon login?")]
WelcomeWindow_LoadAtStartup,

[Description("Do you want to automatically reload local rotations when they are updated? (Developer Mode)")]
WelcomeWindow_AutoReload,
}
2 changes: 0 additions & 2 deletions RotationSolver/Helpers/DownloadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ public static class DownloadHelper
/// <see href="https://garlandtools.org/db/#status/1093"><strong>HP and MP Boost</strong></see> ↑ (All Classes)
/// <para>Maximum HP and MP are increased.</para>
/// </summary>
public static string[] LinkLibraries { get; private set; } = [];
public static string[] UsersHash { get; private set; } = [];
public static string[] Supporters { get; private set; } = [];
public static IncompatiblePlugin[] IncompatiblePlugins { get; private set; } = [];

public static async Task DownloadAsync()
{
LinkLibraries = await DownloadOneAsync<string[]>($"https://raw.githubusercontent.com/{Service.USERNAME}/{Service.REPO}/main/Resources/downloadList.json") ?? [];
IncompatiblePlugins = await DownloadOneAsync<IncompatiblePlugin[]>($"https://raw.githubusercontent.com/{Service.USERNAME}/{Service.REPO}/main/Resources/IncompatiblePlugins.json") ?? [];

DataCenter.ContributorsHash = await DownloadOneAsync<string[]>($"https://raw.githubusercontent.com/{Service.USERNAME}/{Service.REPO}/main/Resources/ContributorsHash.json") ?? [];
Expand Down
6 changes: 3 additions & 3 deletions RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using System.Xml.Linq;
using XIVPainter;
using XIVPainter.Vfx;
using ChangelogWindow = RotationSolver.UI.ChangelogWindow;
using WelcomeWindow = RotationSolver.UI.WelcomeWindow;

namespace RotationSolver;

Expand All @@ -31,7 +31,7 @@ public sealed class RotationSolverPlugin : IDalamudPlugin, IDisposable
static ControlWindow? _controlWindow;
static NextActionWindow? _nextActionWindow;
static CooldownWindow? _cooldownWindow;
static ChangelogWindow? _changelogWindow;
static WelcomeWindow? _changelogWindow;

static readonly List<IDisposable> _dis = [];
public static string Name => "Rotation Solver Reborn";
Expand Down Expand Up @@ -100,7 +100,7 @@ public RotationSolverPlugin(DalamudPluginInterface pluginInterface)
Task.Run(async () =>
{
await DownloadHelper.DownloadAsync();
await RotationUpdater.GetAllCustomRotationsAsync(DownloadOption.Download);
if (Service.Config.AutoLoadRotations) await RotationUpdater.GetAllCustomRotationsAsync(DownloadOption.Download);
});

#if DEBUG
Expand Down
133 changes: 53 additions & 80 deletions RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using RotationSolver.UI.SearchableConfigs;
using RotationSolver.Updaters;
using XIVPainter;
using static System.Net.Mime.MediaTypeNames;
using GAction = Lumina.Excel.GeneratedSheets.Action;
using Status = Lumina.Excel.GeneratedSheets.Status;
using TargetType = RotationSolver.Basic.Actions.TargetType;
Expand Down Expand Up @@ -374,7 +375,12 @@ private void DrawHeader(float wholeWidth)
if (rotation == null)
{
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudOrange);
ImGui.TextWrapped("No rotations loaded! Was there recently a big update?");
var text = UiString.ConfigWindow_NoRotation.Local();
var textWidth = ImGuiHelpers.GetButtonSize(text).X;
ImGuiHelper.DrawItemMiddle(() =>
{
ImGui.TextWrapped(text);
}, wholeWidth, textWidth);
ImGui.PopStyleColor();
ImguiTooltips.HoveredTooltip("Please update your rotations!");
return;
Expand Down Expand Up @@ -1607,9 +1613,36 @@ private static void DrawRotations()
{
var width = ImGui.GetWindowWidth();

var text = UiString.ConfigWindow_Rotations_Download.Local();
ImGui.PushFont(DrawingExtensions.GetFont(ImGui.GetFontSize() + 5));
var text = UiString.ConfigWindow_Rotations_Warning.Local();
var textWidth = ImGuiHelpers.GetButtonSize(text).X;
ImGuiHelper.DrawItemMiddle(() =>
{
ImGui.TextColored(ImGuiColors.DalamudYellow, text);
}, width, textWidth);
text = UiString.ConfigWindow_Rotations_Warning2.Local();
textWidth = ImGuiHelpers.GetButtonSize(text).X;
ImGuiHelper.DrawItemMiddle(() =>
{
ImGui.TextColored(ImGuiColors.DalamudYellow, text);
}, width, textWidth);
ImGui.PopFont();

if (DataCenter.RightNowRotation == null)
{
text = UiString.ConfigWindow_Rotations_FirstTime.Local();
textWidth = ImGuiHelpers.GetButtonSize(text).X;
ImGui.TextWrapped(text);
}

ImGui.Separator();

ImGui.Separator();
DrawRotationsSettings();

ImGui.Separator();
text = UiString.ConfigWindow_Rotations_Download.Local();
textWidth = ImGuiHelpers.GetButtonSize(text).X;
ImGuiHelper.DrawItemMiddle(() =>
{
if (ImGui.Button(text))
Expand All @@ -1620,25 +1653,30 @@ private static void DrawRotations()
});
}
}, width, textWidth);

text = UiString.ConfigWindow_Rotations_Links.Local();
text = UiString.ConfigWindow_Rotations_Reset.Local();
textWidth = ImGuiHelpers.GetButtonSize(text).X;
ImGuiHelper.DrawItemMiddle(() =>
{
if (ImGui.Button(text))
{
Util.OpenLink($"https://github.com/{Service.USERNAME}/{Service.REPO}/blob/main/RotationsLink.md");
Task.Run(async () =>
{
await RotationUpdater.ResetToDefaults();
await RotationUpdater.GetAllCustomRotationsAsync(DownloadOption.MustDownload | DownloadOption.ShowList);
});
}
}, width, textWidth);
ImGui.PushFont(DrawingExtensions.GetFont(ImGui.GetFontSize() + 3));
ImGui.Text(UiString.ConfigWindow_Rotations_Sources.Local());
ImGui.PopFont();
DrawRotationsLibraries();


_rotationsHeader?.Draw();
}
private static readonly CollapsingHeaderGroup _rotationsHeader = new(new()
{
{ UiString.ConfigWindow_Rotations_Settings.Local, DrawRotationsSettings},
{ UiString.ConfigWindow_Rotations_Loaded.Local, DrawRotationsLoaded},
{ UiString.ConfigWindow_Rotations_GitHub.Local, DrawRotationsGitHub},
{ UiString.ConfigWindow_Rotations_Libraries.Local, DrawRotationsLibraries},
});

private static void DrawRotationsSettings()
Expand Down Expand Up @@ -1783,100 +1821,35 @@ private static void DrawGitHubBadge(string userName, string repository, string i
style.ItemSpacing = spacing;
}

private static void DrawRotationsGitHub()
{
if (!Service.Config.GitHubLibs.Any(s => string.IsNullOrEmpty(s) || s == "||"))
{
Service.Config.GitHubLibs = [.. Service.Config.GitHubLibs, "||"];
}

ImGui.Spacing();

foreach (var gitHubLink in DownloadHelper.LinkLibraries ?? [])
{
var strs = gitHubLink.Split('|');
var userName = strs.FirstOrDefault() ?? string.Empty;
var repository = strs.Length > 1 ? strs[1] : string.Empty;
var fileName = strs.LastOrDefault() ?? string.Empty;

DrawGitHubBadge(userName, repository, fileName, center: true);
ImGui.Spacing();
ImGui.Separator();
}

int removeIndex = -1;
for (int i = 0; i < Service.Config.GitHubLibs.Length; i++)
{
var strs = Service.Config.GitHubLibs[i].Split('|');
var userName = strs.FirstOrDefault() ?? string.Empty;
var repository = strs.Length > 1 ? strs[1] : string.Empty;
var fileName = strs.LastOrDefault() ?? string.Empty;

DrawGitHubBadge(userName, repository, fileName, center: true);

var changed = false;

var width = ImGui.GetWindowWidth() - ImGuiEx.CalcIconSize(FontAwesomeIcon.Ban).X - ImGui.GetStyle().ItemSpacing.X * 3 - 10 * Scale;
width /= 3;

ImGui.SetNextItemWidth(width);
changed |= ImGui.InputTextWithHint($"##GitHubLib{i}UserName", UiString.ConfigWindow_Rotations_UserName.Local(), ref userName, 1024);
ImGui.SameLine();

ImGui.SetNextItemWidth(width);
changed |= ImGui.InputTextWithHint($"##GitHubLib{i}Repository", UiString.ConfigWindow_Rotations_Repository.Local(), ref repository, 1024);
ImGui.SameLine();

ImGui.SetNextItemWidth(width);
changed |= ImGui.InputTextWithHint($"##GitHubLib{i}FileName", UiString.ConfigWindow_Rotations_FileName.Local(), ref fileName, 1024);
ImGui.SameLine();

if (changed)
{
Service.Config.GitHubLibs[i] = $"{userName}|{repository}|{fileName}";
}

if (ImGuiEx.IconButton(FontAwesomeIcon.Ban, $"##Rotation Solver Remove GitHubLibs{i}"))
{
removeIndex = i;
}
}
if (removeIndex > -1)
{
var list = Service.Config.GitHubLibs.ToList();
list.RemoveAt(removeIndex);
Service.Config.GitHubLibs = [.. list];
}
}

private static void DrawRotationsLibraries()
{
if (!Service.Config.OtherLibs.Any(string.IsNullOrEmpty))
if (!Service.Config.RotationLibs.Any(string.IsNullOrEmpty))
{
Service.Config.OtherLibs = [.. Service.Config.OtherLibs, string.Empty];
Service.Config.RotationLibs = [.. Service.Config.RotationLibs, string.Empty];
}

ImGui.Spacing();

var width = ImGui.GetWindowWidth() - ImGuiEx.CalcIconSize(FontAwesomeIcon.Ban).X - ImGui.GetStyle().ItemSpacing.X - 10 * Scale;

int removeIndex = -1;
for (int i = 0; i < Service.Config.OtherLibs.Length; i++)
for (int i = 0; i < Service.Config.RotationLibs.Length; i++)
{
ImGui.SetNextItemWidth(width);
ImGui.InputTextWithHint($"##Rotation Solver OtherLib{i}", UiString.ConfigWindow_Rotations_Library.Local(), ref Service.Config.OtherLibs[i], 1024);
ImGui.InputTextWithHint($"##Rotation Solver OtherLib{i}", UiString.ConfigWindow_Rotations_Library.Local(), ref Service.Config.RotationLibs[i], 1024);
ImGui.SameLine();

if (ImGuiEx.IconButton(FontAwesomeIcon.Ban, $"##Rotation Solver Remove OtherLibs{i}"))
if (ImGuiEx.IconButton(FontAwesomeIcon.Ban, $"##Rotation Solver Remove Rotation Library{i}"))
{
removeIndex = i;
}
}
if (removeIndex > -1)
{
var list = Service.Config.OtherLibs.ToList();
var list = Service.Config.RotationLibs.ToList();
list.RemoveAt(removeIndex);
Service.Config.OtherLibs = [.. list];
Service.Config.RotationLibs = [.. list];
}
}
#endregion
Expand Down
Loading

0 comments on commit 6513444

Please sign in to comment.