Use version and website information and add edit options.

This commit is contained in:
Ottermandias 2021-01-14 10:26:09 +01:00
parent 28cce87855
commit 8e87e2d1cf

View file

@ -6,8 +6,9 @@ using System.Numerics;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Plugin; using Dalamud.Plugin;
using ImGuiNET; using ImGuiNET;
using Newtonsoft.Json;
using Penumbra.Importer; using Penumbra.Importer;
using Penumbra.Models; using Penumbra.Models;
@ -500,7 +501,63 @@ namespace Penumbra.UI
} }
ImGui.EndPopup(); 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() void DrawInstalledMods()
{ {
@ -532,13 +589,25 @@ namespace Penumbra.UI
{ {
ImGui.BeginChild( "selectedModInfo", AutoFillSize, true ); 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.SameLine();
ImGui.TextColored( new Vector4( 1f, 1f, 1f, 0.66f ), "by" ); ImGui.TextColored( new Vector4( 1f, 1f, 1f, 0.66f ), "by" );
ImGui.SameLine(); ImGui.SameLine();
ImGui.Text( _selectedMod.Mod.Meta.Author ); if ((_selectedMod.Mod.Meta.Author?.Length ?? 0) > 0 )
ImGui.Text( _selectedMod.Mod.Meta.Author );
ImGui.TextWrapped( _selectedMod.Mod.Meta.Description ?? "" ); else
ImGui.Text( "Unknown" );
DrawWebsiteText();
ImGui.SetCursorPosY( ImGui.GetCursorPosY() + 10 ); ImGui.SetCursorPosY( ImGui.GetCursorPosY() + 10 );
@ -548,12 +617,12 @@ namespace Penumbra.UI
_selectedMod.Enabled = enabled; _selectedMod.Enabled = enabled;
_plugin.ModManager.Mods.Save(); _plugin.ModManager.Mods.Save();
_plugin.ModManager.CalculateEffectiveFileList(); _plugin.ModManager.CalculateEffectiveFileList();
} }
if( ImGui.Button( "Open Mod Folder" ) ) DrawEditButtons();
{
Process.Start( _selectedMod.Mod.ModBasePath.FullName );
} ImGui.TextWrapped( _selectedMod.Mod.Meta.Description ?? "" );
ImGui.BeginTabBar( "PenumbraPluginDetails" ); ImGui.BeginTabBar( "PenumbraPluginDetails" );
if( ImGui.BeginTabItem( "Files" ) ) if( ImGui.BeginTabItem( "Files" ) )