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

Commit

Permalink
fix: fixed the config reading bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 16, 2023
1 parent add7eee commit ad4d9ed
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 184 deletions.
19 changes: 16 additions & 3 deletions RotationSolver.Basic/Attributes/LinkDescriptionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ namespace RotationSolver.Basic.Attributes;
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class LinkDescriptionAttribute : Attribute
{
static readonly SortedDictionary<string, TextureWrap> _TextureCache = new SortedDictionary<string, TextureWrap>();

static readonly List<string> _loadingTexture = new List<string>();

public TextureWrap Texture { get; private set; }
public string Path { get; }
public LinkDescriptionAttribute(string path)
Expand All @@ -19,19 +23,28 @@ public LinkDescriptionAttribute(string path)

private void LoadTexture(string path)
{
if(_TextureCache.TryGetValue(path,out var t))
{
Texture = t;
return;
}
if (_loadingTexture.Contains(path))
{
return;
}
_loadingTexture.Add(path);

try
{
Task.Run(async () =>
{
var bytes = await LoadBytes(path);
Texture = TryLoadImage(bytes);
_TextureCache[path] = Texture = TryLoadImage(bytes);
});
}
catch
{

}

}

private static async Task<byte[]> LoadBytes(string url)
Expand Down
6 changes: 6 additions & 0 deletions RotationSolver.Basic/Configuration/JsonCreationConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace RotationSolver.Basic.Configuration
{
internal class JsonCreationConverter<T>
{
}
}
1 change: 1 addition & 0 deletions RotationSolver.Basic/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dalamud.Configuration;
using Newtonsoft.Json;
using RotationSolver.Basic.Data;
using System.Numerics;

Expand Down
303 changes: 153 additions & 150 deletions RotationSolver/Localization/Localization.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion RotationSolver/Localization/Strings_Major.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ internal partial class Strings
public string ConfigWindow_Param_UseStopCasting { get; set; } = "Use stopping casting when target is dead.";
public string ConfigWindow_Param_ShowActionFlag { get; set; } = "Show action flag.";
public string ConfigWindow_Param_InDebug { get; set; } = "Debug Mode";
public string ConfigWindow_Param_InDebugWarning { get; set; } = "Debug Mode";
public string ConfigWindow_Param_ShowHealthRatio { get; set; } = "Show the health ratio for the check of Boss, Dying, Dot.";

public string ConfigWindow_Param_HealthRatioBoss { get; set; } = "If target's max health ratio is higher than this, regard it as Boss.";
Expand Down
12 changes: 9 additions & 3 deletions RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Dalamud.Utility;
using ImGuiScene;
using Newtonsoft.Json;
using RotationSolver.Basic;
using RotationSolver.Basic.Configuration;
using RotationSolver.Basic.Data;
Expand All @@ -8,6 +11,7 @@
using RotationSolver.SigReplacers;
using RotationSolver.UI;
using RotationSolver.Updaters;
using System.Net;

namespace RotationSolver;

Expand All @@ -19,16 +23,17 @@ public sealed class RotationSolverPlugin : IDalamudPlugin, IDisposable

static readonly List<IDisposable> _dis = new List<IDisposable>();
public string Name => "Rotation Solver";

public unsafe RotationSolverPlugin(DalamudPluginInterface pluginInterface)
{
pluginInterface.Create<Service>();

try
{
Service.Config = pluginInterface.GetPluginConfig() as PluginConfiguration ?? new PluginConfiguration();
Service.Config = JsonConvert.DeserializeObject<PluginConfiguration>(
File.ReadAllText(Service.Interface.ConfigFile.FullName))
?? new PluginConfiguration();
}
catch
catch(Exception ex)
{
Service.Config = new PluginConfiguration();
}
Expand Down Expand Up @@ -58,6 +63,7 @@ public unsafe RotationSolverPlugin(DalamudPluginInterface pluginInterface)
RotationUpdater.GetAllCustomRotations();
}


internal static void ChangeUITranslation()
{
_comboConfigWindow.WindowName = LocalizationManager.RightLang.ConfigWindow_Header
Expand Down
15 changes: 13 additions & 2 deletions RotationSolver/UI/ImGuiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using RotationSolver.Basic.Helpers;
using RotationSolver.Basic.Rotations;
using RotationSolver.Localization;
using RotationSolver.Updaters;
using System.ComponentModel;
using System.Numerics;
using System.Reflection;
Expand Down Expand Up @@ -443,7 +444,17 @@ public unsafe static void Display(this ICustomRotation rotation, ICustomRotation
ImGui.TextColored(isAllowed ? ImGuiColors.DalamudWhite : ImGuiColors.DalamudViolet,
rotation.GetAuthor());
if (!isAllowed)
HoveredString("This rotation is not allowed to be used in High-end Duty!");
{
var allHighEnds = string.Join('\n', SocialUpdater.HighEndDuties.Select(x => x.PlaceName?.Value?.Name.ToString())
.Where(s => !string.IsNullOrEmpty(s)));

var showStr = "This rotation is not allowed to be used in High-end Duty!";
if(!string.IsNullOrEmpty(allHighEnds))
{
showStr += "\n" + allHighEnds;
}
HoveredString(showStr);
}

ImGui.SameLine();
ImGui.TextDisabled(" - " + LocalizationManager.RightLang.ConfigWindow_Helper_GameVersion + ": ");
Expand Down Expand Up @@ -482,7 +493,7 @@ public unsafe static void Display(this ICustomRotation rotation, ICustomRotation
{
DrawTooltip(() =>
{
var ratio = Math.Min(1, 1000f / texture.Texture.Width);
var ratio = Math.Min(1, 1500f / texture.Texture.Width);
var size = new Vector2(texture.Texture.Width * ratio,
texture.Texture.Height * ratio);
ImGui.Image(texture.Texture.ImGuiHandle, size);
Expand Down
4 changes: 3 additions & 1 deletion RotationSolver/UI/RotationConfigWindow_Help.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void DrawHelpTab()

ImGui.TextWrapped(LocalizationManager.RightLang.ConfigWindow_HelpItem_Description);

if (ImGui.BeginChild("Help Infomation", new Vector2(0f, -1f), true))
if (ImGui.BeginChild("Help Information", new Vector2(0f, -1f), true))
{
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0f, 5f));

Expand Down Expand Up @@ -86,6 +86,8 @@ private void DrawHelpTab()
SpecialCommandType.Burst.DisplayCommandHelp(getHelp: EnumTranslations.ToHelp);

ImGui.PopStyleVar();

ImGui.EndChild();
}
}
}
4 changes: 4 additions & 0 deletions RotationSolver/UI/RotationConfigWindow_Major.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Dalamud.Utility;
using FFXIVClientStructs.Interop;
using ImGuiNET;
using ImGuiScene;
using Lumina.Excel;
using RotationSolver.Basic;
using RotationSolver.Basic.Actions;
using RotationSolver.Basic.Rotations;
using RotationSolver.Basic.Rotations.Basic;
using RotationSolver.Localization;
using System.IO;
using System.Net;
using System.Numerics;
using System.Reflection;
using System.Runtime.Serialization;
Expand Down
49 changes: 27 additions & 22 deletions RotationSolver/UI/RotationConfigWindow_RotationDev.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using RotationSolver.Basic;
using RotationSolver.Localization;
using RotationSolver.Updaters;
using System.Numerics;

namespace RotationSolver.UI;
internal partial class RotationConfigWindow
Expand All @@ -28,33 +29,37 @@ private void DrawRotationDevTab()
DrawCheckBox(LocalizationManager.RightLang.ConfigWindow_Param_InDebug,
ref Service.Config.InDebug);

if (Service.Config.InDebug)
if (ImGui.BeginChild("Third-party Libs", new Vector2(0f, -1f), true))
{
ImGui.TextColored(ImGuiColors.DalamudRed,
LocalizationManager.RightLang.ConfigWindow_Param_InDebugWarning);
}

int removeIndex = -1;
for (int i = 0; i < Service.Config.OtherLibs.Length; i++)
{
ImGui.InputText($"##OtherLib{i}", ref Service.Config.OtherLibs[i], 1024);
if (ImGui.Button("AddOne"))
{
Service.Config.OtherLibs = Service.Config.OtherLibs.Append(string.Empty).ToArray();
}
ImGui.SameLine();
if (ImGui.Button($"X##Remove{i}"))
ImGui.Text("Third-party Rotation Libraries");

int removeIndex = -1;
for (int i = 0; i < Service.Config.OtherLibs.Length; i++)
{
removeIndex = i;
if (ImGui.InputText($"##OtherLib{i}", ref Service.Config.OtherLibs[i], 1024))
{
Service.Config.Save();
}
ImGui.SameLine();
if (ImGui.Button($"X##Remove{i}"))
{
removeIndex = i;
}
}
if (removeIndex > -1)
{
var list = Service.Config.OtherLibs.ToList();
list.RemoveAt(removeIndex);
Service.Config.OtherLibs = list.ToArray();
}
}
if(removeIndex > -1)
{
var list = Service.Config.OtherLibs.ToList();
list.RemoveAt(removeIndex);
Service.Config.OtherLibs = list.ToArray();
}

string str = string.Empty;
if(ImGui.InputText($"##OtherLibExtra", ref str, 1024))
{
Service.Config.OtherLibs = Service.Config.OtherLibs.Append(str).ToArray();
ImGui.EndChild();

}
}
}
9 changes: 7 additions & 2 deletions RotationSolver/Updaters/SocialUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal class SocialUpdater

static bool _canSaying = false;
public static bool InHighEndDuty { get; private set; } = false;
public static TerritoryType[] HighEndDuties { get; private set; } = new TerritoryType[0];

static bool CanSocial
{
Expand All @@ -50,6 +51,10 @@ internal static void Enable()
Service.DutyState.DutyStarted += DutyState_DutyStarted;
Service.DutyState.DutyCompleted += DutyState_DutyCompleted;
Service.ClientState.TerritoryChanged += ClientState_TerritoryChanged;

HighEndDuties = Service.GetSheet<TerritoryType>()
.Where(t => t?.ContentFinderCondition?.Value?.HighEndDuty ?? false)
.ToArray();
}

static async void DutyState_DutyCompleted(object sender, ushort e)
Expand All @@ -71,13 +76,13 @@ static void ClientState_TerritoryChanged(object sender, ushort e)
{
_canSaying = true;
}
InHighEndDuty = territory?.ContentFinderCondition?.Value?.HighEndDuty ?? false;
InHighEndDuty = HighEndDuties.Any(t => t.RowId == territory.RowId);
}

static void DutyState_DutyStarted(object sender, ushort e)
{
var territory = Service.GetSheet<TerritoryType>().GetRow(e);
if (territory?.ContentFinderCondition?.Value?.HighEndDuty ?? false)
if (HighEndDuties.Any(t => t.RowId == territory.RowId))
{
var str = territory.PlaceName?.Value?.Name.ToString() ?? "High-end Duty";
Service.ToastGui.ShowError(string.Format(LocalizationManager.RightLang.HighEndWarning, str));
Expand Down

0 comments on commit ad4d9ed

Please sign in to comment.