-
-
Notifications
You must be signed in to change notification settings - Fork 139
/
Changelog.cs
387 lines (312 loc) · 16.5 KB
/
Changelog.cs
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#if DEBUG
global using static SimpleTweaksPlugin.Changelog;
#endif
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Windowing;
using ImGuiNET;
using SimpleTweaksPlugin.TweakSystem;
namespace SimpleTweaksPlugin;
public class ChangelogEntry {
public BaseTweak? Tweak { get; }
public TweakProvider? TweakProvider { get; }
public Version Version { get; }
public string Change { get; private set; } = string.Empty;
public bool IsNewTweak { get; }
public string? ChangeAuthor { get; private set; }
public ChangelogEntry(BaseTweak tweak, string version, string log, bool isNewTweak = false) {
Tweak = tweak;
TweakProvider = tweak.TweakProvider;
Version = Version.Parse(version);
Change = log;
IsNewTweak = isNewTweak;
}
public ChangelogEntry(string version, string log) {
Version = Version.Parse(version);
Change = log;
}
public ChangelogEntry Author(string? author) {
ChangeAuthor = author;
return this;
}
public ChangelogEntry Sub(string text, int level = 1) {
Change += "\n";
for (var i = 0; i < level; i++) {
Change += "\t";
}
Change += $" - {text}";
return this;
}
}
public class Changelog : Window {
internal static void AddGeneralChangelogs() {
Add("1.8.3.0", "Added a changelog");
Add("1.8.3.0", "Fixed graphical issue when resizing windows on clear blue theme.");
Add("1.8.2.0", "Now using the Dalamud Window system.\nESC will now close Simple Tweaks windows.");
Add("1.8.5.0", "Added command to open the config window to a specific tweak. (/tweaks find [id])");
Add("1.8.5.2", "Made April Fools Joke Stupid");
Add("1.8.5.3", "Removed April Fools joke due to potential crash.");
Add("1.8.6.0", "General fixes for 6.38");
Add("1.8.7.1", "General fixes for 6.4");
Add("1.8.9.0", "Added an option to opt out of analytics\n\tNote:\n\t\tNo analytics are currently being collected.\n\t\tThis is a preemptive opt out for the future.");
Add("1.8.9.2", "Added preview images to some tweaks.");
Add("1.9.0.0", "Tweaks that add commands can now have their commands customized.");
Add("1.9.0.0", "The tweak list is now split into more categories")
.Sub("Tweaks can be in multiple categories.")
.Sub("Categories can be disabled in settings.")
.Sub("The 'All Tweaks' pseudo-category displays all available tweaks.", 2)
.Sub("The 'Enabled Tweaks' pesudo-category displays only enabled tweaks.", 2);
Add("1.9.3.0", "Added optional metrics collection")
.Sub("Everyone will be given a chance to opt in or our to the collection of a list of enabled tweaks when first accessing the simple tweaks config window.")
.Sub("Anyone who preemptivly opted out will not see the notice as they already made the choice.")
.Sub("No information will be collected until the 'Allow collection' button is pressed.");
Add("1.9.5.0", "The Simple Tweaks config window will now be decorated during various festive periods.")
.Sub("This can be disabled in the 'General Options' tab.")
.Sub("You can also set a permanent decoration to be used all year round.");
Add("1.10.0.0", "Support for Dawntrail");
Add("1.10.0.1", "Updated more tweaks for Dawntrail");
}
#if DEBUG
public const string UnreleasedVersion = "99.99.99.99";
#endif
private static Dictionary<Version, List<ChangelogEntry>> Entries = new();
public static ChangelogEntry Add(BaseTweak tweak, string version, string log) {
var changelog = new ChangelogEntry(tweak, version, log);
Add(changelog);
return changelog;
}
public static ChangelogEntry AddNewTweak(BaseTweak tweak, string version) {
var changelog = new ChangelogEntry(tweak, version, string.Empty, isNewTweak: true);
Add(changelog);
return changelog;
}
internal static ChangelogEntry Add(string version, string log) {
var changelog = new ChangelogEntry(version, log);
Add(changelog);
return changelog;
}
private static void Add(ChangelogEntry changelog) {
if (!Entries.ContainsKey(changelog.Version)) Entries.Add(changelog.Version, new List<ChangelogEntry>());
Entries[changelog.Version].Add(changelog);
if (HasNewChangelog || SimpleTweaksPlugin.Plugin.ChangelogWindow.IsOpen) return;
if (Version.TryParse(SimpleTweaksPlugin.Plugin.PluginConfig.LastSeenChangelog, out var lastVersion)) {
#if DEBUG
HasNewChangelog = !SimpleTweaksPlugin.Plugin.PluginConfig.DisableChangelogNotification && lastVersion < changelog.Version && changelog.Version.Major != 99;
#else
HasNewChangelog = !SimpleTweaksPlugin.Plugin.PluginConfig.DisableChangelogNotification && lastVersion < changelog.Version;
#endif
} else {
HasNewChangelog = !SimpleTweaksPlugin.Plugin.PluginConfig.DisableChangelogNotification;
}
if (HasNewChangelog && SimpleTweaksPlugin.Plugin.PluginConfig.AutoOpenChangelog) {
SimpleTweaksPlugin.Plugin.ChangelogWindow.IsOpen = true;
}
}
public Version CurrentVersion { get; }
public static bool HasNewChangelog { get; private set; } = false;
public Changelog() : base("###simpleTweaksChangelog") {
CurrentVersion = Assembly.GetExecutingAssembly().GetName().Version;
WindowName = $"Simple Tweaks Changelog ({CurrentVersion})###simpleTweaksChangelog";
Size = ImGuiHelpers.ScaledVector2(600, 600);
SizeCondition = ImGuiCond.FirstUseEver;
}
public override void OnOpen() {
HasNewChangelog = false;
SimpleTweaksPlugin.Plugin.PluginConfig.LastSeenChangelog = $"{CurrentVersion}";
SimpleTweaksPlugin.Plugin.PluginConfig.Save();
foreach (var v in Entries) v.Value.RemoveAll(e => e.Tweak is { IsDisposed: true } || e.TweakProvider is { IsDisposed: true });
base.OnOpen();
}
private static bool ShouldShowTweak(BaseTweak tweak) {
if (tweak == null) return false;
if (tweak.IsDisposed) return false;
var config = SimpleTweaksPlugin.Plugin.PluginConfig;
// Don't show hidden tweaks
if (config.HiddenTweaks.Contains(tweak.Key)) return false;
// Don't show experimental tweaks, unless they're enabled or Experimental tweaks are enabled
if (tweak.Experimental && !config.ShowExperimentalTweaks && !config.EnabledTweaks.Contains(tweak.Key)) return false;
return true;
}
public static string GenerateChangelogMarkdown(Version changelogVersion = null, StringBuilder stringBuilder = null) {
stringBuilder ??= new StringBuilder();
if (changelogVersion == null) {
stringBuilder.AppendLine("# Changelog");
stringBuilder.AppendLine();
foreach (var version in Entries.Keys.OrderByDescending(v => v)) {
var versionLabel = version.Major == 99 ? "Unreleased" : $"{version}";
var versionStringBuilder = new StringBuilder();
if (!string.IsNullOrWhiteSpace(GenerateChangelogMarkdown(version, versionStringBuilder))) {
stringBuilder.AppendLine($"## {versionLabel}");
stringBuilder.Append(versionStringBuilder);
stringBuilder.AppendLine();
}
}
return stringBuilder.ToString();
}
if (Entries.TryGetValue(changelogVersion, out var changelogs)) {
var generalChanges = changelogs.Where(c => c.Tweak == null);
var newTweaks = changelogs.Where(c => c.IsNewTweak && c.Tweak != null && c.TweakProvider is not CustomTweakProvider).OrderBy(c => c.Tweak.Name);
var tweakChanges = changelogs.Where(c => c.Tweak != null && c.IsNewTweak == false && c.TweakProvider is not CustomTweakProvider).OrderBy(c => c.Tweak.Name);
if (generalChanges.Any()) {
if (newTweaks.Any() || tweakChanges.Any()) {
stringBuilder.AppendLine("***General Changes***");
}
foreach (var c in generalChanges) {
stringBuilder.Append($"- {c.Change}");
if (!string.IsNullOrEmpty(c.ChangeAuthor)) {
stringBuilder.Append($" *({c.ChangeAuthor})*");
}
stringBuilder.AppendLine();
}
if (newTweaks.Any() || tweakChanges.Any()) {
stringBuilder.AppendLine();
}
}
if (newTweaks.Any()) {
stringBuilder.AppendLine("***New Tweaks***");
foreach (var c in newTweaks) {
stringBuilder.Append($"- **`{c.Tweak.Name}`** - {c.Tweak.Description.Split('\n')[0]}");
if (!string.IsNullOrEmpty(c.ChangeAuthor)) {
stringBuilder.Append($" *({c.ChangeAuthor})*");
}
stringBuilder.AppendLine("\n");
}
if (tweakChanges.Any()) {
stringBuilder.AppendLine();
}
}
if (tweakChanges.Any()) {
stringBuilder.AppendLine("***Tweak Changes***");
var tweakChangeGroups = tweakChanges.GroupBy(c => c.Tweak);
foreach (var g in tweakChangeGroups) {
if (!g.Any()) continue; // Who knows
if (g.Count() >= 2) {
stringBuilder.AppendLine($"- **`{g.Key.Name}`**");
foreach (var c in g) {
if (c.Tweak != g.Key) continue;
stringBuilder.Append($" - {c.Change}");
if (!string.IsNullOrEmpty(c.ChangeAuthor)) {
stringBuilder.Append($" *({c.ChangeAuthor})*");
}
stringBuilder.AppendLine();
}
stringBuilder.AppendLine();
} else {
var c = g.First();
if (c.Tweak == null) continue;
stringBuilder.Append($"- **`{c.Tweak.Name}`** - {c.Change}");
if (!string.IsNullOrEmpty(c.ChangeAuthor)) {
stringBuilder.Append($" *({c.ChangeAuthor})*");
}
stringBuilder.AppendLine("\n");
}
}
}
}
return stringBuilder.ToString();
}
public override void Draw() {
#if DEBUG
if (ImGui.Button("Copy Full Changelog")) {
ImGui.SetClipboardText(GenerateChangelogMarkdown());
}
#endif
foreach (var (version, changelogs) in Entries.OrderByDescending(v => v.Key)) {
#if DEBUG
if (ImGui.Button($"C##{version}")) {
ImGui.SetClipboardText(GenerateChangelogMarkdown(version));
}
ImGui.SameLine();
#endif
var flags = CurrentVersion == version ? ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.CollapsingHeader : ImGuiTreeNodeFlags.CollapsingHeader;
#if DEBUG
if (version.Major == 99) flags |= ImGuiTreeNodeFlags.DefaultOpen;
var versionHeaderText = version.Major == 99 ? "Unreleased" : $"Version {version}";
#else
var versionHeaderText = $"Version {version}";
#endif
if (flags.HasFlag(ImGuiTreeNodeFlags.DefaultOpen)) ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.HealerGreen);
var versionHeaderOpen = ImGui.CollapsingHeader($"{versionHeaderText}##ChangeLogHeader", flags);
if (flags.HasFlag(ImGuiTreeNodeFlags.DefaultOpen)) ImGui.PopStyleColor();
if (!versionHeaderOpen) continue;
var generalChanges = changelogs.Where(c => c.Tweak == null);
if (generalChanges.Any()) {
if (ImGui.TreeNodeEx($"General Changes##{version}", ImGuiTreeNodeFlags.DefaultOpen)) {
foreach (var c in generalChanges) {
ImGui.TreeNodeEx(c.Change, ImGuiTreeNodeFlags.Leaf | ImGuiTreeNodeFlags.NoTreePushOnOpen | ImGuiTreeNodeFlags.Bullet);
if (c.ChangeAuthor != null) {
ImGui.SameLine();
ImGui.TextDisabled($"({c.ChangeAuthor})");
}
}
ImGui.TreePop();
}
}
var newTweaks = changelogs.Where(c => c.IsNewTweak && c.Tweak != null && ShouldShowTweak(c.Tweak)).OrderBy(c => c.Tweak.Name);
if (newTweaks.Any()) {
if (ImGui.TreeNodeEx($"New Tweaks##{version}", ImGuiTreeNodeFlags.DefaultOpen)) {
foreach (var c in newTweaks) {
if (c.Tweak == null) continue;
ImGui.BeginGroup();
var tweakTreeOpen = ImGui.TreeNodeEx(c.Tweak.Name, ImGuiTreeNodeFlags.Leaf | ImGuiTreeNodeFlags.Bullet);
if (ImGui.IsItemClicked()) {
SimpleTweaksPlugin.Plugin.ConfigWindow.IsOpen = true;
SimpleTweaksPlugin.Plugin.PluginConfig.FocusTweak(c.Tweak);
}
if (ImGui.IsItemHovered()) {
ImGui.SetTooltip($"Click to find '{c.Tweak.Name}' in Simple Tweaks config window");
}
if (c.ChangeAuthor != null) {
ImGui.SameLine();
ImGui.TextDisabled($"({c.ChangeAuthor})");
}
if (tweakTreeOpen) {
ImGui.Indent();
ImGui.PushStyleColor(ImGuiCol.Text, ImGui.GetColorU32(ImGuiCol.TextDisabled));
ImGui.TextWrapped(c.Tweak.Description);
ImGui.PopStyleColor();
ImGui.Unindent();
ImGui.TreePop();
}
}
ImGui.TreePop();
}
}
var tweakChanges = changelogs.Where(c => c.Tweak != null && c.IsNewTweak == false && ShouldShowTweak(c.Tweak)).GroupBy(c => c.Tweak);
if (tweakChanges.Any()) {
if (ImGui.TreeNodeEx($"Tweak Changes##{version}", ImGuiTreeNodeFlags.DefaultOpen)) {
foreach (var group in tweakChanges.OrderBy(g => g.Key.Name)) {
var tweak = group.Key;
var xBefore = ImGui.GetCursorPosX();
var open = ImGui.TreeNodeEx($"{tweak.Name}##{version}_{tweak.Key}", ImGuiTreeNodeFlags.DefaultOpen);
var xAfter = ImGui.GetCursorPosX();
ImGui.SameLine();
ImGui.SetCursorPosX(xBefore - ImGui.GetIO().FontGlobalScale * 16);
if (ImGui.SmallButton($">###{version}_{tweak.Key}_openSettings")) {
SimpleTweaksPlugin.Plugin.ConfigWindow.IsOpen = true;
SimpleTweaksPlugin.Plugin.PluginConfig.FocusTweak(tweak);
}
if (ImGui.IsItemHovered()) ImGui.SetTooltip($"Find '{tweak.Name}' in Simple Tweaks config");
ImGui.SetCursorPosX(xAfter);
if (open) {
foreach (var c in group) {
ImGui.TreeNodeEx(c.Change, ImGuiTreeNodeFlags.Leaf | ImGuiTreeNodeFlags.NoTreePushOnOpen | ImGuiTreeNodeFlags.Bullet);
if (c.ChangeAuthor != null) {
ImGui.SameLine();
ImGui.TextDisabled($"({c.ChangeAuthor})");
}
}
ImGui.TreePop();
}
}
ImGui.TreePop();
}
}
}
}
}