-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.cs
More file actions
118 lines (98 loc) · 4.79 KB
/
Copy pathPlugin.cs
File metadata and controls
118 lines (98 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using Dalamud.Game.Command;
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using Dalamud.Interface.Windowing;
using Restocker.Windows;
using Restocker.Localization;
using Restocker.Execution;
using Restocker.Market;
namespace Restocker;
public sealed class Plugin : IDalamudPlugin
{
[PluginService] internal static IDalamudPluginInterface PluginInterface { get; private set; } = null!;
[PluginService] internal static ICommandManager CommandManager { get; private set; } = null!;
[PluginService] internal static IClientState ClientState { get; private set; } = null!;
[PluginService] internal static IDataManager DataManager { get; private set; } = null!;
[PluginService] internal static IPluginLog Log { get; private set; } = null!;
[PluginService] internal static IChatGui ChatGui { get; private set; } = null!;
[PluginService] internal static IGameGui GameGui { get; private set; } = null!;
[PluginService] internal static IFramework Framework { get; private set; } = null!;
[PluginService] internal static IGameInventory GameInventory { get; private set; } = null!;
[PluginService] internal static IAddonLifecycle AddonLifecycle { get; private set; } = null!;
[PluginService] internal static IToastGui ToastGui { get; private set; } = null!;
[PluginService] internal static INotificationManager NotificationManager { get; private set; } = null!;
[PluginService] internal static IPlayerState PlayerState { get; private set; } = null!;
[PluginService] internal static IObjectTable ObjectTable { get; private set; } = null!;
[PluginService] internal static IMarketBoard MarketBoard { get; private set; } = null!;
private const string CommandName = "/restocker";
public static Configuration Configuration { get; private set; } = null!;
public static Plugin Instance { get; private set; } = null!;
public RetainerWatcher RetainerWatcher { get; private set; } = null!;
public readonly WindowSystem WindowSystem = new("Restocker");
private MainWindow MainWindow { get; }
private ProgressWindow ProgressWindow { get; }
private BellWatcher BellWatcher { get; }
private AutoRetainerDetector ArDetector { get; }
private Executor Executor { get; }
private MarketWatcher MarketWatcher { get; }
public Plugin()
{
Instance = this;
Configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
Strings.SetLanguage(Configuration.ResolveLanguage(ClientState.ClientLanguage));
MarketWatcher = new MarketWatcher(MarketBoard, Log);
Executor = new Executor(Framework, Log, Configuration, MarketWatcher.Cache);
MainWindow = new MainWindow(Configuration, Executor, MarketWatcher);
WindowSystem.AddWindow(MainWindow);
ProgressWindow = new ProgressWindow(Executor);
WindowSystem.AddWindow(ProgressWindow);
RetainerWatcher = new RetainerWatcher(
Configuration,
AddonLifecycle,
PlayerState,
ObjectTable,
DataManager,
Log
);
BellWatcher = new BellWatcher(
Framework,
GameGui,
open => MainWindow.IsOpen = open,
() => Configuration.AutoOpenOnBell,
() => RetainerWatcher.CaptureCharacterSnapshot()
);
ArDetector = new AutoRetainerDetector(PluginInterface, NotificationManager, Log);
ArDetector.WarnIfPresent();
CommandManager.AddHandler(CommandName, new CommandInfo(OnCommand)
{
HelpMessage = "Open the Restocker window."
});
PluginInterface.UiBuilder.Draw += WindowSystem.Draw;
PluginInterface.UiBuilder.OpenMainUi += ToggleMainUi;
// 設定タブは MainWindow 内にあるので OpenConfigUi も同じウィンドウへ
PluginInterface.UiBuilder.OpenConfigUi += ToggleMainUi;
}
public void Dispose()
{
PluginInterface.UiBuilder.Draw -= WindowSystem.Draw;
PluginInterface.UiBuilder.OpenMainUi -= ToggleMainUi;
PluginInterface.UiBuilder.OpenConfigUi -= ToggleMainUi;
WindowSystem.RemoveAllWindows();
MarketWatcher.Dispose();
Executor.Dispose();
BellWatcher.Dispose();
RetainerWatcher.Dispose();
MainWindow.Dispose();
CommandManager.RemoveHandler(CommandName);
}
private void OnCommand(string command, string args)
{
ToggleMainUi();
}
public void ToggleMainUi() => MainWindow.Toggle();
/// <summary>Executor 用: 自動 fetch 中に「期待アイテム」フィルタを設定。</summary>
public void SetMarketWatcherExpected(uint itemId, bool isHq) => MarketWatcher.SetExpectedItem(itemId, isHq);
public void ClearMarketWatcherExpected() => MarketWatcher.ClearExpectedItem();
}