Skip to content

Commit

Permalink
fix: make dialog work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Aug 30, 2024
1 parent bb649a8 commit 06759c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
6 changes: 5 additions & 1 deletion DownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,15 @@ private void DetermineIfUpdate(IDownloadTask_GetVersion info) {
Directory.Move(oldName, this.PenumbraModPath!);
}
} else if (directories.Length > 1) {
var rejoined = directories
.Select(name => Path.Join(this.ModDirectory, name))
.ToArray();

throw new MultipleModDirectoriesException(
info.Variant.Package.Name,
info.Variant.Name,
info.Version,
directories
rejoined
);
}
}
Expand Down
11 changes: 10 additions & 1 deletion Ui/Dialogs/Dialog.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using System.Numerics;
using Heliosphere.Util;
using ImGuiNET;

namespace Heliosphere.Ui.Dialogs;

internal abstract class Dialog(string title, ImGuiWindowFlags windowFlags = ImGuiWindowFlags.None) : IDrawable {
internal abstract class Dialog(
string title,
ImGuiWindowFlags windowFlags = ImGuiWindowFlags.None,
Vector2 windowSize = default
) : IDrawable {
internal string Title { get; } = title;
private ImGuiWindowFlags WindowFlags { get; } = windowFlags;
private bool _visible = true;
Expand All @@ -16,6 +21,10 @@ public DrawStatus Draw() {
return DrawStatus.Finished;
}

if (windowSize != default) {
ImGui.SetNextWindowSize(windowSize, ImGuiCond.Appearing);
}

using var end = new OnDispose(ImGui.End);
if (!ImGui.Begin(this.Title, ref this._visible, this.WindowFlags)) {
return DrawStatus.Continue;
Expand Down
17 changes: 6 additions & 11 deletions Ui/Dialogs/MultipleModDirectoriesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ internal class MultipleModDirectoriesDialog : Dialog {
private MultipleModDirectoriesException Info { get; }

private List<(string, string?)> DirectoryVersions { get; }
private Dictionary<string, bool> PathStatus { get; }
private Dictionary<string, bool> PathStatus { get; } = [];

private Stopwatch Stopwatch { get; } = Stopwatch.StartNew();

internal MultipleModDirectoriesDialog(Plugin plugin, MultipleModDirectoriesException info) : base($"{Plugin.Name}##mmdd-{info.PackageName}-{info.VariantName}-{info.Version}") {
internal MultipleModDirectoriesDialog(Plugin plugin, MultipleModDirectoriesException info) : base($"{Plugin.Name}##mmdd-{info.PackageName}-{info.VariantName}-{info.Version}", ImGuiWindowFlags.NoSavedSettings, new Vector2(450, 300)) {
this.Plugin = plugin;
this.Info = info;

this.DirectoryVersions = [
.. this.Info.Directories
.Select(path => (path, HeliosphereMeta.ParseDirectory(Path.GetFileName(path))?.Version))
.OrderBy(tuple => tuple.Version)
.OrderByDescending(tuple => tuple.Version),
];

this.UpdateStatuses();
Expand All @@ -40,10 +40,8 @@ private void UpdateStatuses() {
}

protected override DrawStatus InnerDraw() {
ImGui.SetWindowSize(new Vector2(450, 300), ImGuiCond.Appearing);

if (this.Stopwatch.Elapsed >= TimeSpan.FromSeconds(3)) {
this.Stopwatch.Reset();
this.Stopwatch.Restart();
this.UpdateStatuses();
}

Expand All @@ -63,16 +61,13 @@ protected override DrawStatus InnerDraw() {
foreach (var (path, version) in this.DirectoryVersions) {
ImGui.Bullet();

if (!this.PathStatus.TryGetValue(path, out var exists)) {
exists = false;
}

var exists = this.PathStatus.GetValueOrDefault(path, false);
using (ImGuiHelper.DisabledUnless(exists)) {
ImGui.SameLine();
ImGui.TextUnformatted($"v{version} -");

ImGui.SameLine();
if (ImGui.SmallButton("Open")) {
if (ImGui.SmallButton($"Open##{path}")) {
Process.Start(new ProcessStartInfo(path) {
UseShellExecute = true,
});
Expand Down

0 comments on commit 06759c6

Please sign in to comment.