refactor: fix warnings and code smells

This commit is contained in:
Anna 2020-07-31 13:58:56 -04:00
parent b69de5653a
commit cd08d08e5c
8 changed files with 149 additions and 81 deletions

View File

@ -0,0 +1,10 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "Will be done eventually", Scope = "module")]
[assembly: SuppressMessage("Globalization", "CA1305", Scope = "module")]
[assembly: SuppressMessage("Globalization", "CA1304", Scope = "module")]

View File

@ -12,13 +12,13 @@ namespace HudSwap {
private delegate IntPtr GetFilePointerDelegate(byte index);
private delegate uint SetHudLayoutDelegate(IntPtr filePtr, uint hudLayout, byte unk0, byte unk1);
private GetFilePointerDelegate _getFilePointer;
private SetHudLayoutDelegate _setHudLayout;
private readonly GetFilePointerDelegate _getFilePointer;
private readonly SetHudLayoutDelegate _setHudLayout;
private readonly DalamudPluginInterface pi;
public HUD(DalamudPluginInterface pi) {
this.pi = pi;
this.pi = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null");
IntPtr getFilePointerPtr = this.pi.TargetModuleScanner.ScanText("E8 ?? ?? ?? ?? 48 85 C0 74 14 83 7B 44 00");
IntPtr setHudLayoutPtr = this.pi.TargetModuleScanner.ScanText("E8 ?? ?? ?? ?? 33 C0 EB 15");
if (getFilePointerPtr != IntPtr.Zero) {
@ -80,6 +80,9 @@ namespace HudSwap {
}
public void WriteLayout(HudSlot slot, byte[] layout) {
if (layout == null) {
throw new ArgumentNullException(nameof(layout), "layout cannot be null");
}
if (layout.Length != LAYOUT_SIZE) {
throw new ArgumentException($"layout must be {LAYOUT_SIZE} bytes", nameof(layout));
}
@ -102,6 +105,7 @@ namespace HudSwap {
[NonSerialized]
private byte[] uncompressed = null;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "nah")]
public byte[] Layout() {
if (this.uncompressed != null) {
return this.uncompressed;

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.6\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.6\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" />
<Import Project="..\packages\Microsoft.NetFramework.Analyzers.2.9.6\build\Microsoft.NetFramework.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.6\build\Microsoft.NetFramework.Analyzers.props')" />
<Import Project="..\packages\Microsoft.NetCore.Analyzers.2.9.6\build\Microsoft.NetCore.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.6\build\Microsoft.NetCore.Analyzers.props')" />
<Import Project="..\packages\Microsoft.CodeQuality.Analyzers.2.9.6\build\Microsoft.CodeQuality.Analyzers.props" Condition="Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.6\build\Microsoft.CodeQuality.Analyzers.props')" />
<Import Project="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.6\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.6\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -12,6 +17,8 @@
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -63,7 +70,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration.cs" />
<Compile Include="PluginConfig.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="HUD.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="PluginUI.cs" />
@ -72,6 +80,28 @@
</ItemGroup>
<ItemGroup>
<None Include="HudSwap.json" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.6\analyzers\dotnet\cs\Microsoft.CodeAnalysis.VersionCheckAnalyzer.resources.dll" />
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.6\analyzers\dotnet\Microsoft.CodeAnalysis.VersionCheckAnalyzer.dll" />
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.6\analyzers\dotnet\cs\Humanizer.dll" />
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.6\analyzers\dotnet\cs\Microsoft.CodeQuality.Analyzers.dll" />
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.6\analyzers\dotnet\cs\Microsoft.CodeQuality.CSharp.Analyzers.dll" />
<Analyzer Include="..\packages\Microsoft.NetCore.Analyzers.2.9.6\analyzers\dotnet\cs\Microsoft.NetCore.Analyzers.dll" />
<Analyzer Include="..\packages\Microsoft.NetCore.Analyzers.2.9.6\analyzers\dotnet\cs\Microsoft.NetCore.CSharp.Analyzers.dll" />
<Analyzer Include="..\packages\Microsoft.NetFramework.Analyzers.2.9.6\analyzers\dotnet\cs\Microsoft.NetFramework.Analyzers.dll" />
<Analyzer Include="..\packages\Microsoft.NetFramework.Analyzers.2.9.6\analyzers\dotnet\cs\Microsoft.NetFramework.CSharp.Analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.6\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.6\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.6\build\Microsoft.CodeQuality.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeQuality.Analyzers.2.9.6\build\Microsoft.CodeQuality.Analyzers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.6\build\Microsoft.NetCore.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetCore.Analyzers.2.9.6\build\Microsoft.NetCore.Analyzers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.6\build\Microsoft.NetFramework.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetFramework.Analyzers.2.9.6\build\Microsoft.NetFramework.Analyzers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.6\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.6\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props'))" />
</Target>
</Project>

View File

@ -7,30 +7,31 @@ namespace HudSwap {
private DalamudPluginInterface pi;
private PluginUI ui;
public HUD hud;
public Configuration config;
public HUD Hud { get; private set; }
public PluginConfig Config { get; private set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "nah")]
public void Initialize(DalamudPluginInterface pluginInterface) {
this.pi = pluginInterface;
this.pi = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface cannot be null");
try {
this.config = this.pi.GetPluginConfig() as Configuration ?? new Configuration();
this.Config = this.pi.GetPluginConfig() as PluginConfig ?? new PluginConfig();
} catch (Exception) {
this.pi.UiBuilder.OnBuildUi += PluginUI.ConfigError;
return;
}
this.config.Initialize(this.pi);
this.Config.Initialize(this.pi);
this.ui = new PluginUI(this, this.pi);
this.hud = new HUD(this.pi);
this.Hud = new HUD(this.pi);
if (this.config.FirstRun) {
this.config.FirstRun = false;
if (this.config.Layouts.Count == 0) {
if (this.Config.FirstRun) {
this.Config.FirstRun = false;
if (this.Config.Layouts.Count == 0) {
foreach (HudSlot slot in Enum.GetValues(typeof(HudSlot))) {
this.ui.ImportSlot(slot, $"Auto-import {(int)slot + 1}", false);
}
}
this.config.Save();
this.Config.Save();
}
this.pi.UiBuilder.OnBuildUi += this.ui.Draw;
@ -41,12 +42,17 @@ namespace HudSwap {
});
}
public void Dispose() {
protected virtual void Dispose(bool all) {
this.pi.UiBuilder.OnBuildUi -= this.ui.Draw;
this.pi.UiBuilder.OnOpenConfigUi -= this.ui.ConfigUI;
this.pi.CommandManager.RemoveHandler("/phudswap");
}
public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}
private void OnCommand(string command, string args) {
this.ui.SettingsVisible = true;
}

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
namespace HudSwap {
[Serializable]
public class Configuration : IPluginConfiguration {
public class PluginConfig : IPluginConfiguration {
public int Version { get; set; } = 1;
[NonSerialized]
@ -18,8 +18,9 @@ namespace HudSwap {
public HudSlot StagingSlot { get; set; } = HudSlot.Four;
public Guid defaultLayout = Guid.Empty;
public Guid DefaultLayout { get; set; } = Guid.Empty;
#pragma warning disable CA1051 // Do not declare visible instance fields
[Obsolete("Individual layout fields are deprecated; use StatusLayouts instead")]
public Guid combatLayout = Guid.Empty;
[Obsolete("Individual layout fields are deprecated; use StatusLayouts instead")]
@ -34,10 +35,11 @@ namespace HudSwap {
public Guid fishingLayout = Guid.Empty;
[Obsolete("Individual layout fields are deprecated; use StatusLayouts instead")]
public Guid roleplayingLayout = Guid.Empty;
#pragma warning restore CA1051 // Do not declare visible instance fields
public Dictionary<Status, Guid> StatusLayouts { get; set; } = new Dictionary<Status, Guid>();
public Dictionary<Status, Guid> StatusLayouts { get; } = new Dictionary<Status, Guid>();
public Dictionary<string, Guid> JobLayouts { get; set; } = new Dictionary<string, Guid>();
public Dictionary<string, Guid> JobLayouts { get; } = new Dictionary<string, Guid>();
public bool HighPriorityJobs { get; set; } = false;
public bool JobsCombatOnly { get; set; } = false;

View File

@ -55,7 +55,7 @@ namespace HudSwap {
if (ImGui.Begin("HudSwap", ref this._settingsVisible, ImGuiWindowFlags.AlwaysAutoResize)) {
if (ImGui.BeginTabBar("##hudswap-tabs")) {
if (!this.plugin.config.UnderstandsRisks) {
if (!this.plugin.Config.UnderstandsRisks) {
if (ImGui.BeginTabItem("About")) {
ImGui.TextColored(new Vector4(1f, 0f, 0f, 1f), "Read this first");
ImGui.Separator();
@ -72,10 +72,10 @@ namespace HudSwap {
ImGui.Separator();
ImGui.Text("If you have read all of the above and are okay with continuing, check the box below to enable HudSwap. You only need to do this once.");
ImGui.PopTextWrapPos();
bool understandsRisks = this.plugin.config.UnderstandsRisks;
bool understandsRisks = this.plugin.Config.UnderstandsRisks;
if (ImGui.Checkbox("I understand", ref understandsRisks)) {
this.plugin.config.UnderstandsRisks = understandsRisks;
this.plugin.config.Save();
this.plugin.Config.UnderstandsRisks = understandsRisks;
this.plugin.Config.Save();
}
ImGui.EndTabItem();
@ -88,11 +88,11 @@ namespace HudSwap {
if (ImGui.BeginTabItem("Layouts")) {
ImGui.Text("Saved layouts");
if (this.plugin.config.Layouts.Keys.Count == 0) {
if (this.plugin.Config.Layouts.Keys.Count == 0) {
ImGui.Text("None saved!");
} else {
if (ImGui.ListBoxHeader("##saved-layouts")) {
foreach (KeyValuePair<Guid, Tuple<string, byte[]>> entry in this.plugin.config.Layouts) {
foreach (KeyValuePair<Guid, Tuple<string, byte[]>> entry in this.plugin.Config.Layouts) {
if (ImGui.Selectable(entry.Value.Item1, this.selectedLayout == entry.Key)) {
this.selectedLayout = entry.Key;
this.renameName = entry.Value.Item1;
@ -105,22 +105,22 @@ namespace HudSwap {
foreach (HudSlot slot in Enum.GetValues(typeof(HudSlot))) {
string buttonName = $"{(int)slot + 1}##copy";
if (ImGui.Button(buttonName) && this.selectedLayout != null) {
byte[] layout = this.plugin.config.Layouts[this.selectedLayout].Item2;
this.plugin.hud.WriteLayout(slot, layout);
byte[] layout = this.plugin.Config.Layouts[this.selectedLayout].Item2;
this.plugin.Hud.WriteLayout(slot, layout);
}
ImGui.SameLine();
}
if (ImGui.Button("Delete") && this.selectedLayout != null) {
this.plugin.config.Layouts.Remove(this.selectedLayout);
this.plugin.Config.Layouts.Remove(this.selectedLayout);
this.selectedLayout = Guid.Empty;
this.renameName = "";
this.plugin.config.Save();
this.plugin.Config.Save();
}
ImGui.SameLine();
if (ImGui.Button("Copy to clipboard") && this.selectedLayout != null) {
if (this.plugin.config.Layouts.TryGetValue(this.selectedLayout, out Tuple<string, byte[]> layout)) {
if (this.plugin.Config.Layouts.TryGetValue(this.selectedLayout, out Tuple<string, byte[]> layout)) {
SharedLayout shared = new SharedLayout(layout.Item2);
string json = JsonConvert.SerializeObject(shared);
ImGui.SetClipboardText(json);
@ -129,10 +129,10 @@ namespace HudSwap {
ImGui.InputText("##rename-input", ref this.renameName, 100);
ImGui.SameLine();
if (ImGui.Button("Rename") && this.renameName != "" && this.selectedLayout != null) {
Tuple<string, byte[]> entry = this.plugin.config.Layouts[this.selectedLayout]; ;
this.plugin.config.Layouts[this.selectedLayout] = new Tuple<string, byte[]>(this.renameName, entry.Item2);
this.plugin.config.Save();
if (ImGui.Button("Rename") && this.renameName.Length != 0 && this.selectedLayout != null) {
Tuple<string, byte[]> entry = this.plugin.Config.Layouts[this.selectedLayout]; ;
this.plugin.Config.Layouts[this.selectedLayout] = new Tuple<string, byte[]>(this.renameName, entry.Item2);
this.plugin.Config.Save();
}
}
@ -144,18 +144,20 @@ namespace HudSwap {
foreach (HudSlot slot in Enum.GetValues(typeof(HudSlot))) {
string buttonName = $"{(int)slot + 1}##import";
if (ImGui.Button(buttonName) && this.importName != "") {
if (ImGui.Button(buttonName) && this.importName.Length != 0) {
this.ImportSlot(slot, this.importName);
this.importName = "";
}
ImGui.SameLine();
}
if (ImGui.Button("Clipboard") && this.importName != "") {
if (ImGui.Button("Clipboard") && this.importName.Length != 0) {
SharedLayout shared = null;
try {
shared = (SharedLayout)JsonConvert.DeserializeObject(ImGui.GetClipboardText(), typeof(SharedLayout));
#pragma warning disable CA1031 // Do not catch general exception types
} catch (Exception) {
#pragma warning restore CA1031 // Do not catch general exception types
}
if (shared != null) {
byte[] layout = shared.Layout();
@ -170,20 +172,20 @@ namespace HudSwap {
}
if (ImGui.BeginTabItem("Swaps")) {
bool enabled = this.plugin.config.SwapsEnabled;
bool enabled = this.plugin.Config.SwapsEnabled;
if (ImGui.Checkbox("Enable swaps", ref enabled)) {
this.plugin.config.SwapsEnabled = enabled;
this.plugin.config.Save();
this.plugin.Config.SwapsEnabled = enabled;
this.plugin.Config.Save();
}
ImGui.Text("Note: Disable swaps when editing your HUD.");
ImGui.Spacing();
string staging = ((int)this.plugin.config.StagingSlot + 1).ToString();
string staging = ((int)this.plugin.Config.StagingSlot + 1).ToString();
if (ImGui.BeginCombo("Staging slot", staging)) {
foreach (HudSlot slot in Enum.GetValues(typeof(HudSlot))) {
if (ImGui.Selectable(((int)slot + 1).ToString())) {
this.plugin.config.StagingSlot = slot;
this.plugin.config.Save();
this.plugin.Config.StagingSlot = slot;
this.plugin.Config.Save();
}
}
ImGui.EndCombo();
@ -195,11 +197,11 @@ namespace HudSwap {
ImGui.Text("This is the default layout. If none of the below conditions are\nsatisfied, this layout will be enabled.");
if (ImGui.BeginCombo("##default-layout", this.LayoutNameOrDefault(this.plugin.config.defaultLayout))) {
foreach (KeyValuePair<Guid, Tuple<string, byte[]>> entry in this.plugin.config.Layouts) {
if (ImGui.BeginCombo("##default-layout", this.LayoutNameOrDefault(this.plugin.Config.DefaultLayout))) {
foreach (KeyValuePair<Guid, Tuple<string, byte[]>> entry in this.plugin.Config.Layouts) {
if (ImGui.Selectable(entry.Value.Item1)) {
this.plugin.config.defaultLayout = entry.Key;
this.plugin.config.Save();
this.plugin.Config.DefaultLayout = entry.Key;
this.plugin.Config.Save();
}
}
ImGui.EndCombo();
@ -218,12 +220,12 @@ namespace HudSwap {
foreach (Status status in Statuses.ORDER.Reverse()) {
maxSize = Math.Max(maxSize, ImGui.CalcTextSize(status.Name()).X);
this.plugin.config.StatusLayouts.TryGetValue(status, out Guid layout);
this.plugin.Config.StatusLayouts.TryGetValue(status, out Guid layout);
if (this.LayoutBox(status.Name(), layout, out Guid newLayout)) {
this.plugin.config.StatusLayouts[status] = newLayout;
this.plugin.config.Save();
if (this.plugin.config.SwapsEnabled) {
this.plugin.Config.StatusLayouts[status] = newLayout;
this.plugin.Config.Save();
if (this.plugin.Config.SwapsEnabled) {
this.statuses.SetHudLayout(player, true);
}
}
@ -253,12 +255,12 @@ namespace HudSwap {
foreach (ClassJob job in acceptableJobs) {
maxSize = Math.Max(maxSize, ImGui.CalcTextSize(job.NameEnglish).X);
this.plugin.config.JobLayouts.TryGetValue(job.Abbreviation, out Guid layout);
this.plugin.Config.JobLayouts.TryGetValue(job.Abbreviation, out Guid layout);
if (this.LayoutBox(job.NameEnglish, layout, out Guid newLayout)) {
this.plugin.config.JobLayouts[job.Abbreviation] = newLayout;
this.plugin.config.Save();
if (this.plugin.config.SwapsEnabled) {
this.plugin.Config.JobLayouts[job.Abbreviation] = newLayout;
this.plugin.Config.Save();
if (this.plugin.Config.SwapsEnabled) {
this.statuses.SetHudLayout(player, true);
}
}
@ -270,27 +272,27 @@ namespace HudSwap {
ImGui.EndChild();
}
bool combatOnlyJobs = this.plugin.config.JobsCombatOnly;
bool combatOnlyJobs = this.plugin.Config.JobsCombatOnly;
if (ImGui.Checkbox("Jobs only in combat/weapon drawn", ref combatOnlyJobs)) {
this.plugin.config.JobsCombatOnly = combatOnlyJobs;
this.plugin.config.Save();
if (this.plugin.config.SwapsEnabled) {
this.plugin.Config.JobsCombatOnly = combatOnlyJobs;
this.plugin.Config.Save();
if (this.plugin.Config.SwapsEnabled) {
this.statuses.SetHudLayout(player, true);
}
}
ImGui.SameLine();
this.HelpMarker("Selecting this will make the HUD layout change for a job only when in combat or when your weapon is drawn.");
HelpMarker("Selecting this will make the HUD layout change for a job only when in combat or when your weapon is drawn.");
bool highPriorityJobs = this.plugin.config.HighPriorityJobs;
bool highPriorityJobs = this.plugin.Config.HighPriorityJobs;
if (ImGui.Checkbox("Jobs take priority over status", ref highPriorityJobs)) {
this.plugin.config.HighPriorityJobs = highPriorityJobs;
this.plugin.config.Save();
if (this.plugin.config.SwapsEnabled) {
this.plugin.Config.HighPriorityJobs = highPriorityJobs;
this.plugin.Config.Save();
if (this.plugin.Config.SwapsEnabled) {
this.statuses.SetHudLayout(player, true);
}
}
ImGui.SameLine();
this.HelpMarker("Selecting this will make job layouts always apply when on that job. If this is unselected, job layouts will only apply if the default layout was going to be used (or only in combat if the above checkbox is selected).");
HelpMarker("Selecting this will make job layouts always apply when on that job. If this is unselected, job layouts will only apply if the default layout was going to be used (or only in combat if the above checkbox is selected).");
}
ImGui.EndTabItem();
@ -303,7 +305,7 @@ namespace HudSwap {
}
}
private void HelpMarker(string text) {
private static void HelpMarker(string text) {
ImGui.TextDisabled("(?)");
if (ImGui.IsItemHovered()) {
ImGui.BeginTooltip();
@ -315,7 +317,7 @@ namespace HudSwap {
}
private string LayoutNameOrDefault(Guid key) {
if (this.plugin.config.Layouts.TryGetValue(key, out Tuple<string, byte[]> tuple)) {
if (this.plugin.Config.Layouts.TryGetValue(key, out Tuple<string, byte[]> tuple)) {
return tuple.Item1;
} else {
return "";
@ -325,7 +327,7 @@ namespace HudSwap {
public void Draw() {
this.DrawSettings();
if (!(this.plugin.config.SwapsEnabled && this.plugin.config.UnderstandsRisks)) {
if (!(this.plugin.Config.SwapsEnabled && this.plugin.Config.UnderstandsRisks)) {
return;
}
@ -349,7 +351,7 @@ namespace HudSwap {
updated = true;
}
ImGui.Separator();
foreach (KeyValuePair<Guid, Tuple<string, byte[]>> entry in this.plugin.config.Layouts) {
foreach (KeyValuePair<Guid, Tuple<string, byte[]>> entry in this.plugin.Config.Layouts) {
if (ImGui.Selectable(entry.Value.Item1)) {
updated = true;
newLayout = entry.Key;
@ -363,13 +365,13 @@ namespace HudSwap {
}
public void ImportSlot(HudSlot slot, string name, bool save = true) {
this.Import(this.plugin.hud.ReadLayout(slot), name, save);
this.Import(this.plugin.Hud.ReadLayout(slot), name, save);
}
public void Import(byte[] layout, string name, bool save = true) {
this.plugin.config.Layouts[Guid.NewGuid()] = new Tuple<string, byte[]>(name, layout);
this.plugin.Config.Layouts[Guid.NewGuid()] = new Tuple<string, byte[]>(name, layout);
if (save) {
this.plugin.config.Save();
this.plugin.Config.Save();
}
}
}

View File

@ -3,14 +3,13 @@ using Dalamud.Game.ClientState.Actors.Types;
using Dalamud.Plugin;
using Lumina.Excel.GeneratedSheets;
using System;
using System.Linq;
using System.Runtime.InteropServices;
// TODO: Zone swaps?
namespace HudSwap {
public class Statuses {
public static Status[] ORDER = {
public static readonly Status[] ORDER = {
Status.Roleplaying,
Status.Fishing,
Status.Gathering,
@ -67,7 +66,7 @@ namespace HudSwap {
}
// get the job layout if there is one and check if jobs are high priority
if (this.plugin.config.JobLayouts.TryGetValue(this.job.Abbreviation, out Guid jobLayout) && this.plugin.config.HighPriorityJobs) {
if (this.plugin.Config.JobLayouts.TryGetValue(this.job.Abbreviation, out Guid jobLayout) && this.plugin.Config.HighPriorityJobs) {
return jobLayout;
}
@ -79,7 +78,7 @@ namespace HudSwap {
continue;
}
Status status = ORDER[i];
if (this.plugin.config.StatusLayouts.TryGetValue(status, out Guid statusLayout)) {
if (this.plugin.Config.StatusLayouts.TryGetValue(status, out Guid statusLayout)) {
layout = statusLayout;
}
}
@ -87,17 +86,17 @@ namespace HudSwap {
// if a job layout is set for the current job
if (jobLayout != Guid.Empty) {
// if jobs are combat only and the player is either in combat or has their weapon drawn, use the job layout
if (this.plugin.config.JobsCombatOnly && (this.condition[5] || this.condition[6])) {
if (this.plugin.Config.JobsCombatOnly && (this.condition[5] || this.condition[6])) {
layout = jobLayout;
}
// if the layout was going to be default, use job layout unless jobs are not combat only
if (!this.plugin.config.JobsCombatOnly && layout == Guid.Empty) {
if (!this.plugin.Config.JobsCombatOnly && layout == Guid.Empty) {
layout = jobLayout;
}
}
return layout == Guid.Empty ? this.plugin.config.defaultLayout : layout;
return layout == Guid.Empty ? this.plugin.Config.DefaultLayout : layout;
}
public void SetHudLayout(PlayerCharacter player, bool update = false) {
@ -109,11 +108,11 @@ namespace HudSwap {
if (layout == Guid.Empty) {
return; // FIXME: do something better
}
if (!this.plugin.config.Layouts.TryGetValue(layout, out Tuple<string, byte[]> entry)) {
if (!this.plugin.Config.Layouts.TryGetValue(layout, out Tuple<string, byte[]> entry)) {
return; // FIXME: do something better
}
this.plugin.hud.WriteLayout(this.plugin.config.StagingSlot, entry.Item2);
this.plugin.hud.SelectSlot(this.plugin.config.StagingSlot, true);
this.plugin.Hud.WriteLayout(this.plugin.Config.StagingSlot, entry.Item2);
this.plugin.Hud.SelectSlot(this.plugin.Config.StagingSlot, true);
}
}
@ -150,6 +149,13 @@ namespace HudSwap {
}
public static bool Active(this Status status, PlayerCharacter player, DalamudPluginInterface pi) {
if (player == null) {
throw new ArgumentNullException(nameof(player), "PlayerCharacter cannot be null");
}
if (pi == null) {
throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null");
}
ConditionFlag flag = (ConditionFlag)status;
if (flag != ConditionFlag.None) {
return pi.ClientState.Condition[flag];

8
HudSwap/packages.config Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.CodeAnalysis.FxCopAnalyzers" version="2.9.6" targetFramework="net48" developmentDependency="true" />
<package id="Microsoft.CodeAnalysis.VersionCheckAnalyzer" version="2.9.6" targetFramework="net48" developmentDependency="true" />
<package id="Microsoft.CodeQuality.Analyzers" version="2.9.6" targetFramework="net48" developmentDependency="true" />
<package id="Microsoft.NetCore.Analyzers" version="2.9.6" targetFramework="net48" developmentDependency="true" />
<package id="Microsoft.NetFramework.Analyzers" version="2.9.6" targetFramework="net48" developmentDependency="true" />
</packages>