refactor: update to api4

This commit is contained in:
Anna 2021-09-20 14:26:42 -04:00
parent ca42df5117
commit 9fd271f7ca
6 changed files with 50 additions and 42 deletions

View File

@ -1,26 +1,39 @@
using Dalamud.Plugin;
using Dalamud.Game.Command;
using Dalamud.Game.Gui;
using Dalamud.Game.Gui.Toast;
using Dalamud.IoC;
using Dalamud.Plugin;
using XivCommon;
namespace BurntToast {
public class BurntToast : IDalamudPlugin {
public string Name => "Burnt Toast";
internal DalamudPluginInterface Interface { get; private set; } = null!;
internal Configuration Config { get; private set; } = null!;
internal PluginUi Ui { get; private set; } = null!;
internal XivCommonBase Common { get; private set; } = null!;
private Commands Commands { get; set; } = null!;
private Filter Filter { get; set; } = null!;
[PluginService]
internal DalamudPluginInterface Interface { get; private init; } = null!;
public void Initialize(DalamudPluginInterface pluginInterface) {
this.Interface = pluginInterface;
[PluginService]
internal ChatGui ChatGui { get; private init; } = null!;
[PluginService]
internal CommandManager CommandManager { get; private init; } = null!;
[PluginService]
internal ToastGui ToastGui { get; private init; } = null!;
internal Configuration Config { get; }
internal PluginUi Ui { get; }
internal XivCommonBase Common { get; }
private Commands Commands { get; }
private Filter Filter { get; }
public BurntToast() {
this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration();
this.Config.Initialise(this);
this.Ui = new PluginUi(this);
this.Commands = new Commands(this);
this.Common = new XivCommonBase(this.Interface, Hooks.BattleTalk);
this.Common = new XivCommonBase(Hooks.BattleTalk);
this.Filter = new Filter(this);
}

View File

@ -1,34 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<TargetFramework>net5-windows</TargetFramework>
<RootNamespace>BurntToast</RootNamespace>
<AssemblyName>BurntToast</AssemblyName>
<Nullable>enable</Nullable>
<Version>1.2.1</Version>
<LangVersion>latest</LangVersion>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Dalamud>$(AppData)\XIVLauncher\addon\Hooks\dev</Dalamud>
</PropertyGroup>
<ItemGroup>
<Reference Include="Dalamud">
<HintPath>D:\code\Dalamud\bin\Dalamud.dll</HintPath>
<HintPath>$(Dalamud)\Dalamud.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGui.NET">
<HintPath>D:\code\Dalamud\bin\ImGui.NET.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGuiScene">
<HintPath>D:\code\Dalamud\bin\ImGuiScene.dll</HintPath>
<HintPath>$(Dalamud)\ImGui.NET.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DalamudPackager" Version="1.2.1"/>
<PackageReference Include="Fody" Version="6.5.1" PrivateAssets="all"/>
<PackageReference Include="ILMerge.Fody" Version="1.16.0" PrivateAssets="all"/>
<PackageReference Include="XivCommon" Version="1.2.0"/>
<PackageReference Include="DalamudLinter" Version="1.0.3"/>
<PackageReference Include="DalamudPackager" Version="2.1.2"/>
<PackageReference Include="XivCommon" Version="3.0.2"/>
</ItemGroup>
</Project>

View File

@ -14,16 +14,16 @@ namespace BurntToast {
internal Commands(BurntToast plugin) {
this.Plugin = plugin;
foreach (var entry in CommandList) {
this.Plugin.Interface.CommandManager.AddHandler(entry.Key, new CommandInfo(this.OnCommand) {
HelpMessage = entry.Value,
foreach (var (name, desc) in CommandList) {
this.Plugin.CommandManager.AddHandler(name, new CommandInfo(this.OnCommand) {
HelpMessage = desc,
});
}
}
public void Dispose() {
foreach (var name in CommandList.Keys) {
this.Plugin.Interface.CommandManager.RemoveHandler(name);
this.Plugin.CommandManager.RemoveHandler(name);
}
}

View File

@ -1,6 +1,6 @@
using System;
using System.Linq;
using Dalamud.Game.Internal.Gui.Toast;
using Dalamud.Game.Gui.Toast;
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using XivCommon.Functions;
@ -12,17 +12,17 @@ namespace BurntToast {
internal Filter(BurntToast plugin) {
this.Plugin = plugin;
this.Plugin.Interface.Framework.Gui.Toast.OnToast += this.OnToast;
this.Plugin.Interface.Framework.Gui.Toast.OnQuestToast += this.OnQuestToast;
this.Plugin.Interface.Framework.Gui.Toast.OnErrorToast += this.OnErrorToast;
this.Plugin.ToastGui.Toast += this.OnToast;
this.Plugin.ToastGui.QuestToast += this.OnQuestToast;
this.Plugin.ToastGui.ErrorToast += this.OnErrorToast;
this.Plugin.Common.Functions.BattleTalk.OnBattleTalk += this.OnBattleTalk;
}
public void Dispose() {
this.Plugin.Common.Functions.BattleTalk.OnBattleTalk -= this.OnBattleTalk;
this.Plugin.Interface.Framework.Gui.Toast.OnErrorToast -= this.OnErrorToast;
this.Plugin.Interface.Framework.Gui.Toast.OnQuestToast -= this.OnQuestToast;
this.Plugin.Interface.Framework.Gui.Toast.OnToast -= this.OnToast;
this.Plugin.ToastGui.ErrorToast -= this.OnErrorToast;
this.Plugin.ToastGui.QuestToast -= this.OnQuestToast;
this.Plugin.ToastGui.Toast -= this.OnToast;
}
private bool AnyMatches(string text) {
@ -65,10 +65,10 @@ namespace BurntToast {
isHandled = true;
if (pattern.ShowMessage) {
this.Plugin.Interface.Framework.Gui.Chat.PrintChat(new XivChatEntry {
this.Plugin.ChatGui.PrintChat(new XivChatEntry {
Type = (XivChatType) 68,
Name = sender.TextValue,
MessageBytes = message.Encode(),
Message = message,
});
}
}

View File

@ -1,3 +0,0 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ILMerge/>
</Weavers>

View File

@ -17,20 +17,20 @@ namespace BurntToast {
public PluginUi(BurntToast plugin) {
this.Plugin = plugin;
this.Plugin.Interface.UiBuilder.OnBuildUi += this.Draw;
this.Plugin.Interface.UiBuilder.OnOpenConfigUi += this.OnOpenConfig;
this.Plugin.Interface.UiBuilder.Draw += this.Draw;
this.Plugin.Interface.UiBuilder.OpenConfigUi += this.OnOpenConfig;
}
public void Dispose() {
this.Plugin.Interface.UiBuilder.OnOpenConfigUi -= this.OnOpenConfig;
this.Plugin.Interface.UiBuilder.OnBuildUi -= this.Draw;
this.Plugin.Interface.UiBuilder.OpenConfigUi -= this.OnOpenConfig;
this.Plugin.Interface.UiBuilder.Draw -= this.Draw;
}
internal void ToggleConfig() {
this.ShowSettings = !this.ShowSettings;
}
private void OnOpenConfig(object? sender, EventArgs e) {
private void OnOpenConfig() {
this.ShowSettings = true;
}