diff --git a/Ui/PenumbraWindowIntegration.cs b/Ui/PenumbraWindowIntegration.cs index cf75c11..0b10e2c 100644 --- a/Ui/PenumbraWindowIntegration.cs +++ b/Ui/PenumbraWindowIntegration.cs @@ -43,38 +43,40 @@ internal void PreSettingsTabBarDraw(string directory, float width, float titleWi return; } - if (pkg.CoverImage is { } img) { - var maxHeight = width * this.Plugin.Config.Penumbra.ImageSize; + if (pkg.CoverImage is not { } img) { + return; + } - ImGuiHelper.ImageFullWidth(img, maxHeight, true); + var maxHeight = width * this.Plugin.Config.Penumbra.ImageSize; - if (ImGui.IsItemHovered()) { - ImGui.BeginTooltip(); - using var endTooltip = new OnDispose(ImGui.EndTooltip); + ImGuiHelper.ImageFullWidth(img, maxHeight, true); - ImGui.TextUnformatted("Click to open this image. Hold right-click to zoom."); - } + if (ImGui.IsItemHovered()) { + ImGui.BeginTooltip(); + using var endTooltip = new OnDispose(ImGui.EndTooltip); - if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) { - Process.Start(new ProcessStartInfo(pkg.CoverImagePath) { - UseShellExecute = true, - }); - } - - if (ImGui.IsItemHovered() && ImGui.IsMouseDown(ImGuiMouseButton.Right)) { - var winSize = ImGuiHelpers.MainViewport.WorkSize; - var imgSize = new Vector2(img.Width, img.Height); + ImGui.TextUnformatted("Click to open this image. Hold right-click to zoom."); + } - if (imgSize.X > winSize.X || imgSize.Y > winSize.Y) { - var ratio = Math.Min(winSize.X / img.Width, winSize.Y / img.Height); - imgSize *= ratio; - } + if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) { + Process.Start(new ProcessStartInfo(pkg.CoverImagePath) { + UseShellExecute = true, + }); + } - var min = new Vector2(winSize.X / 2 - imgSize.X / 2, winSize.Y / 2 - imgSize.Y / 2); - var max = new Vector2(winSize.X / 2 + imgSize.X / 2, winSize.Y / 2 + imgSize.Y / 2); + if (ImGui.IsItemHovered() && ImGui.IsMouseDown(ImGuiMouseButton.Right)) { + var winSize = ImGuiHelpers.MainViewport.WorkSize; + var imgSize = new Vector2(img.Width, img.Height); - ImGui.GetForegroundDrawList().AddImage(img.ImGuiHandle, min, max); + if (imgSize.X > winSize.X || imgSize.Y > winSize.Y) { + var ratio = Math.Min(winSize.X / img.Width, winSize.Y / img.Height); + imgSize *= ratio; } + + var min = new Vector2(winSize.X / 2 - imgSize.X / 2, winSize.Y / 2 - imgSize.Y / 2); + var max = new Vector2(winSize.X / 2 + imgSize.X / 2, winSize.Y / 2 + imgSize.Y / 2); + + ImGui.GetForegroundDrawList().AddImage(img.ImGuiHandle, min, max); } } @@ -87,12 +89,20 @@ internal void PostEnabledDraw(string directory) { return; } + ImGui.Spacing(); + var cursor = ImGui.GetCursorPos(); Widget.BeginFramedGroup("Heliosphere"); using (new OnDispose(() => Widget.EndFramedGroup())) { - if (ImGui.Button("Download updates")) { + if (ImGuiHelper.WideButton("Check for and download updates")) { meta.DownloadUpdates(this.Plugin); } + + if (ImGuiHelper.WideButton("Open in Heliosphere")) { + this.Plugin.PluginUi.ForceOpen = PluginUi.Tab.Manager; + this.Plugin.PluginUi.ForceOpenVariant = meta.VariantId; + this.Plugin.PluginUi.Visible = true; + } } var afterCursor = ImGui.GetCursorPos(); diff --git a/Ui/PluginUi.cs b/Ui/PluginUi.cs index 04d770d..3972e05 100644 --- a/Ui/PluginUi.cs +++ b/Ui/PluginUi.cs @@ -20,6 +20,7 @@ internal enum Tab { internal bool Visible; internal Tab? ForceOpen; + internal Guid? ForceOpenVariant; private Guard> ToDraw { get; } = new([]); private List ToDispose { get; } = []; diff --git a/Ui/Tabs/Manager.cs b/Ui/Tabs/Manager.cs index b25acd8..e4fbd3f 100644 --- a/Ui/Tabs/Manager.cs +++ b/Ui/Tabs/Manager.cs @@ -31,6 +31,7 @@ internal class Manager : IDisposable { private bool _downloadingUpdates; private bool _checkingForUpdates; private string _filter = string.Empty; + private bool _forced; internal Manager(Plugin plugin) { this.Plugin = plugin; @@ -85,6 +86,11 @@ internal void Draw() { } ImGui.EndTabItem(); + + if (this._forced) { + this._forced = false; + this.Ui.ForceOpenVariant = null; + } } private async Task GetInfo() { @@ -193,10 +199,19 @@ private void DrawPackageList(Dictionary allInfo) { (float) scanned / toScan, $"Scanning - {scanned} / {toScan}" ); + } else { + this._forced = true; } var lower = this._filter.ToLowerInvariant(); foreach (var (pkgId, pkg) in this.Plugin.State.InstalledNoBlock.OrderBy(entry => entry.Value.Name)) { + if (this.Ui.ForceOpenVariant is { } forceVariant && pkg.Variants.Any(v => v.VariantId == forceVariant)) { + this._selected = pkgId; + this._selectedVariant = forceVariant; + + ImGui.SetScrollHereY(0.5f); + } + if (!pkg.Name.ToLowerInvariant().Contains(lower)) { continue; } diff --git a/Util/ImGuiHelper.cs b/Util/ImGuiHelper.cs index 6b1ece1..551f786 100644 --- a/Util/ImGuiHelper.cs +++ b/Util/ImGuiHelper.cs @@ -190,6 +190,16 @@ internal static bool CentredWideButton(string label) { return ImGui.Button(label, new Vector2(buttonWidth, 0)); } + internal static bool WideButton(string label) { + var avail = ImGui.GetContentRegionAvail().X; + var textSize = ImGui.CalcTextSize(label).X; + + var buttonSizeBase = Math.Max(avail / 2, textSize); + var buttonWidth = buttonSizeBase + ImGui.GetStyle().FramePadding.X * 2; + + return ImGui.Button(label, new Vector2(buttonWidth, 0)); + } + internal static void FullWidthProgressBar(float ratio, string? overlay = null) { if (overlay == null) { ImGui.ProgressBar(