-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMissingEventFlagsChecker.cs
More file actions
104 lines (86 loc) · 3.52 KB
/
MissingEventFlagsChecker.cs
File metadata and controls
104 lines (86 loc) · 3.52 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
namespace MissingEventFlagsCheckerPlugin
{
public class MissingEventFlagsChecker : IPlugin
{
public string Name => LocalizedStrings.Find("MissingEventFlagsChecker.Title", "Missing Event Flags Checker");
public int Priority => 100; // Loading order, lowest is first.
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public ISaveFileProvider SaveFileEditor { get; private set; }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
private ToolStripMenuItem? ctrl;
public void Initialize(params object[] args)
{
//LocalizedStrings.Initialize("br");
LocalizedStrings.Initialize(GameInfo.CurrentLanguage);
SaveFileEditor = (ISaveFileProvider)Array.Find(args, z => z is ISaveFileProvider)!;
var menu = (ToolStrip)Array.Find(args, z => z is ToolStrip)!;
LoadMenuStrip(menu);
}
private void LoadMenuStrip(ToolStrip menuStrip)
{
var items = menuStrip.Items;
var tools = (ToolStripDropDownItem)items.Find("Menu_Tools", false)[0];
AddPluginControl(tools);
}
private void AddPluginControl(ToolStripDropDownItem tools)
{
ctrl = new ToolStripMenuItem(Name)
{
Enabled = false
};
ctrl.Click += ChecklistViewer_UIEvt;
tools.DropDownItems.Add(ctrl);
}
private void ChecklistViewer_UIEvt(object? sender, EventArgs e)
{
var form = new Forms.ChecklistViewer(SaveFileEditor.SAV);
form.ShowDialog();
}
public void NotifySaveLoaded()
{
ctrl!.Enabled = true;
var savData = SaveFileEditor.SAV;
// Prevent usage if state is not Exportable
if (!savData.State.Exportable)
{
ctrl.Enabled = false;
return;
}
ctrl.Enabled = savData.Version switch
{
GameVersion.Any or
GameVersion.RBY or
GameVersion.StadiumJ or
GameVersion.Stadium or
GameVersion.Stadium2 or
GameVersion.RSBOX or
GameVersion.COLO or
GameVersion.XD or
GameVersion.CXD or
GameVersion.BATREV or
GameVersion.ORASDEMO or
GameVersion.GO or
GameVersion.Invalid
=> false,
// Check for AS Demo
GameVersion.AS
=> savData is not SAV6AODemo,
// Check for SN Demo
GameVersion.SN
// Can't have a renamed box which is locked in non-demo version
=> !(((SAV7SM)savData).BoxLayout.BoxesUnlocked == 8 && string.IsNullOrWhiteSpace(((SAV7SM)savData).BoxLayout.GetBoxName(10))),
_ => true
};
}
public void NotifyDisplayLanguageChanged(string language)
{
// Refresh language if needed
LocalizedStrings.Initialize(language);
ctrl!.Text = Name;
}
public bool TryLoadFile(string filePath)
{
return false; // no action taken
}
}
}