From 8e87e2d1cf0aab45ac9620ef15311d055a943d49 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Thu, 14 Jan 2021 10:26:09 +0100 Subject: [PATCH] Use version and website information and add edit options. --- Penumbra/UI/SettingsInterface.cs | 95 +++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 13 deletions(-) diff --git a/Penumbra/UI/SettingsInterface.cs b/Penumbra/UI/SettingsInterface.cs index 88b4242f..62a4235e 100644 --- a/Penumbra/UI/SettingsInterface.cs +++ b/Penumbra/UI/SettingsInterface.cs @@ -6,8 +6,9 @@ using System.Numerics; using System.Threading.Tasks; using System.Windows.Forms; using Dalamud.Interface; -using Dalamud.Plugin; -using ImGuiNET; +using Dalamud.Plugin; +using ImGuiNET; +using Newtonsoft.Json; using Penumbra.Importer; using Penumbra.Models; @@ -500,7 +501,63 @@ namespace Penumbra.UI } ImGui.EndPopup(); + } + + // Website button with On-Hover address if valid http(s), otherwise text. + private void DrawWebsiteText() + { + if ((_selectedMod.Mod.Meta.Website?.Length ?? 0) > 0) + { + var validUrl = Uri.TryCreate(_selectedMod.Mod.Meta.Website, UriKind.Absolute, out Uri uriResult) + && (uriResult.Scheme == Uri.UriSchemeHttps ||uriResult.Scheme == Uri.UriSchemeHttp); + ImGui.SameLine(); + if (validUrl) + { + if (ImGui.SmallButton("Open Website")) + { + Process.Start( _selectedMod.Mod.Meta.Website ); + } + if (ImGui.IsItemHovered()) + { + ImGui.BeginTooltip(); + ImGui.Text( _selectedMod.Mod.Meta.Website ); + ImGui.EndTooltip(); + } + } + else + { + ImGui.TextColored( new Vector4( 1f, 1f, 1f, 0.66f ), "from" ); + ImGui.SameLine(); + ImGui.Text(_selectedMod.Mod.Meta.Website); + } + } } + + // Create Mod-Handling buttons. + private void DrawEditButtons() + { + ImGui.SameLine(); + if( ImGui.Button( "Open Mod Folder" ) ) + { + Process.Start( _selectedMod.Mod.ModBasePath.FullName ); + } + + ImGui.SameLine(); + if( ImGui.Button( "Edit JSON" ) ) + { + var metaPath = Path.Combine( _selectedMod.Mod.ModBasePath.FullName, "meta.json"); + File.WriteAllText( metaPath, JsonConvert.SerializeObject( _selectedMod.Mod.Meta, Formatting.Indented ) ); + Process.Start( metaPath ); + } + + ImGui.SameLine(); + if( ImGui.Button( "Reload JSON" ) ) + { + ReloadMods(); + _selectedMod = _plugin.ModManager.Mods.ModSettings[ _selectedModIndex ]; + } + } + void DrawInstalledMods() { @@ -532,13 +589,25 @@ namespace Penumbra.UI { ImGui.BeginChild( "selectedModInfo", AutoFillSize, true ); - ImGui.Text( _selectedMod.Mod.Meta.Name ); + ImGui.Text( _selectedMod.Mod.Meta.Name ); + + // (Version ...) or nothing. + if ((_selectedMod.Mod.Meta.Version?.Length ?? 0) > 0) + { + ImGui.SameLine(); + ImGui.Text($"(Version {_selectedMod.Mod.Meta.Version})" ); + } + + // by Author or Unknown. ImGui.SameLine(); ImGui.TextColored( new Vector4( 1f, 1f, 1f, 0.66f ), "by" ); - ImGui.SameLine(); - ImGui.Text( _selectedMod.Mod.Meta.Author ); - - ImGui.TextWrapped( _selectedMod.Mod.Meta.Description ?? "" ); + ImGui.SameLine(); + if ((_selectedMod.Mod.Meta.Author?.Length ?? 0) > 0 ) + ImGui.Text( _selectedMod.Mod.Meta.Author ); + else + ImGui.Text( "Unknown" ); + + DrawWebsiteText(); ImGui.SetCursorPosY( ImGui.GetCursorPosY() + 10 ); @@ -548,12 +617,12 @@ namespace Penumbra.UI _selectedMod.Enabled = enabled; _plugin.ModManager.Mods.Save(); _plugin.ModManager.CalculateEffectiveFileList(); - } - - if( ImGui.Button( "Open Mod Folder" ) ) - { - Process.Start( _selectedMod.Mod.ModBasePath.FullName ); - } + } + + DrawEditButtons(); + + + ImGui.TextWrapped( _selectedMod.Mod.Meta.Description ?? "" ); ImGui.BeginTabBar( "PenumbraPluginDetails" ); if( ImGui.BeginTabItem( "Files" ) )