build workflow and spacing cleanup
This commit is contained in:
@@ -15,14 +15,14 @@ public class ModListComponent : IRenderComponent
|
||||
{
|
||||
private readonly string _configPath;
|
||||
private readonly JsonSerializerOptions _options = new(JsonSerializerDefaults.Web);
|
||||
|
||||
|
||||
private bool _visible;
|
||||
private string _searchQuery = string.Empty;
|
||||
private Task? _searchTask;
|
||||
|
||||
private PublishedFileId_t[] _mods = [];
|
||||
private ImmutableDictionary<ulong, WhitelistItem> _whitelist = ImmutableDictionary<ulong, WhitelistItem>.Empty;
|
||||
|
||||
|
||||
private List<ModItem> _modList = [];
|
||||
private ModItem? _selected;
|
||||
public HashSet<ulong> Installed { get; }
|
||||
@@ -57,18 +57,18 @@ public class ModListComponent : IRenderComponent
|
||||
|
||||
var mods = new List<PublishedFileId_t>();
|
||||
var builder = ImmutableDictionary.CreateBuilder<ulong, WhitelistItem>();
|
||||
|
||||
|
||||
foreach (var item in response.Mods)
|
||||
{
|
||||
if (!ulong.TryParse(item.Id, out var id)) continue;
|
||||
|
||||
|
||||
mods.Add(new PublishedFileId_t(id));
|
||||
builder.Add(id, item);
|
||||
}
|
||||
|
||||
|
||||
_mods = mods.ToArray();
|
||||
_whitelist = builder.ToImmutable();
|
||||
await RefreshAsync();
|
||||
await RefreshAsync();
|
||||
}
|
||||
|
||||
public void OnFrame()
|
||||
@@ -80,7 +80,7 @@ public class ModListComponent : IRenderComponent
|
||||
try
|
||||
{
|
||||
InputText("##searchbox", ref _searchQuery, 256);
|
||||
|
||||
|
||||
SameLine();
|
||||
|
||||
if (Button("Search"))
|
||||
@@ -88,26 +88,27 @@ public class ModListComponent : IRenderComponent
|
||||
_searchTask = RefreshAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Spacing();
|
||||
|
||||
|
||||
switch (_searchTask)
|
||||
{
|
||||
case { IsCompleted: false }:
|
||||
TextDisabled("Loading...");
|
||||
return;
|
||||
case { IsCompletedSuccessfully: false }:
|
||||
{
|
||||
TextDisabled("Failed to load plugins list");
|
||||
if (_searchTask.Exception is null) return;
|
||||
|
||||
foreach (var exception in _searchTask.Exception.InnerExceptions)
|
||||
{
|
||||
TextWrapped($"{exception.GetType()}: {exception.Message}");
|
||||
}
|
||||
TextDisabled("Failed to load plugins list");
|
||||
if (_searchTask.Exception is null)
|
||||
return;
|
||||
|
||||
return;
|
||||
}
|
||||
foreach (var exception in _searchTask.Exception.InnerExceptions)
|
||||
{
|
||||
TextWrapped($"{exception.GetType()}: {exception.Message}");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_modList.Count == 0)
|
||||
@@ -115,7 +116,7 @@ public class ModListComponent : IRenderComponent
|
||||
TextDisabled("Nothing found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
BeginChild("List", new(400, 0), ImGuiChildFlags.Border | ImGuiChildFlags.ResizeX);
|
||||
{
|
||||
if (BeginTable("AvailableModsTable", 3,
|
||||
@@ -155,83 +156,83 @@ public class ModListComponent : IRenderComponent
|
||||
|
||||
EndChild();
|
||||
}
|
||||
|
||||
|
||||
SameLine();
|
||||
|
||||
BeginGroup();
|
||||
BeginGroup();
|
||||
|
||||
BeginChild("Mod View", new(0, -GetFrameHeightWithSpacing())); // Leave room for 1 line below us
|
||||
BeginChild("Mod View", new(0, -GetFrameHeightWithSpacing())); // Leave room for 1 line below us
|
||||
|
||||
if (_selected is not null)
|
||||
{
|
||||
Text(_selected.Name);
|
||||
Separator();
|
||||
if (BeginTabBar("##ModViewTabs"))
|
||||
if (_selected is not null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_selected.Description) && BeginTabItem("Description"))
|
||||
Text(_selected.Name);
|
||||
Separator();
|
||||
if (BeginTabBar("##ModViewTabs"))
|
||||
{
|
||||
TextWrapped(_selected.Description);
|
||||
EndTabItem();
|
||||
if (!string.IsNullOrEmpty(_selected.Description) && BeginTabItem("Description"))
|
||||
{
|
||||
TextWrapped(_selected.Description);
|
||||
EndTabItem();
|
||||
}
|
||||
|
||||
if (BeginTabItem("Mod Description"))
|
||||
{
|
||||
TextWrapped(string.IsNullOrEmpty(_selected.ModDescription) ? "Nothing." : _selected.ModDescription);
|
||||
EndTabItem();
|
||||
}
|
||||
|
||||
if (BeginTabItem("Details"))
|
||||
{
|
||||
TextLinkOpenURL("Mod URL", _selected.Url);
|
||||
|
||||
Text("Author:");
|
||||
SameLine();
|
||||
TextWrapped(_selected.Author);
|
||||
|
||||
Text("Created:");
|
||||
SameLine();
|
||||
TextWrapped(DateTimeOffset.FromUnixTimeSeconds(_selected.Created).ToString("g"));
|
||||
|
||||
Text("Updated:");
|
||||
SameLine();
|
||||
TextWrapped(DateTimeOffset.FromUnixTimeSeconds(_selected.Updated).ToString("g"));
|
||||
|
||||
EndTabItem();
|
||||
}
|
||||
|
||||
EndTabBar();
|
||||
}
|
||||
|
||||
if (BeginTabItem("Mod Description"))
|
||||
{
|
||||
TextWrapped(string.IsNullOrEmpty(_selected.ModDescription) ? "Nothing." : _selected.ModDescription);
|
||||
EndTabItem();
|
||||
}
|
||||
|
||||
if (BeginTabItem("Details"))
|
||||
{
|
||||
TextLinkOpenURL("Mod URL", _selected.Url);
|
||||
|
||||
Text("Author:");
|
||||
SameLine();
|
||||
TextWrapped(_selected.Author);
|
||||
|
||||
Text("Created:");
|
||||
SameLine();
|
||||
TextWrapped(DateTimeOffset.FromUnixTimeSeconds(_selected.Created).ToString("g"));
|
||||
|
||||
Text("Updated:");
|
||||
SameLine();
|
||||
TextWrapped(DateTimeOffset.FromUnixTimeSeconds(_selected.Updated).ToString("g"));
|
||||
|
||||
EndTabItem();
|
||||
}
|
||||
|
||||
EndTabBar();
|
||||
}
|
||||
}
|
||||
|
||||
EndChild();
|
||||
EndChild();
|
||||
|
||||
if (_selected is not null)
|
||||
{
|
||||
var installed = Installed.Contains(_selected.Id);
|
||||
if (Button(installed ? "Uninstall" : "Install"))
|
||||
if (_selected is not null)
|
||||
{
|
||||
if (installed)
|
||||
Installed.Remove(_selected.Id);
|
||||
else
|
||||
Installed.Add(_selected.Id);
|
||||
var installed = Installed.Contains(_selected.Id);
|
||||
if (Button(installed ? "Uninstall" : "Install"))
|
||||
{
|
||||
if (installed)
|
||||
Installed.Remove(_selected.Id);
|
||||
else
|
||||
Installed.Add(_selected.Id);
|
||||
|
||||
Save();
|
||||
Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EndGroup();
|
||||
EndGroup();
|
||||
}
|
||||
finally
|
||||
{
|
||||
End();
|
||||
End();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void Save()
|
||||
{
|
||||
using var stream = File.Create(_configPath);
|
||||
|
||||
|
||||
JsonSerializer.Serialize(stream, Installed, _options);
|
||||
}
|
||||
|
||||
@@ -241,14 +242,14 @@ public class ModListComponent : IRenderComponent
|
||||
|
||||
if (handle.m_UGCQueryHandle == ulong.MaxValue)
|
||||
throw new Exception("Failed to create UGC request");
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
SteamUGC.SetSearchText(handle, _searchQuery);
|
||||
SteamUGC.SetReturnLongDescription(handle, true);
|
||||
// TODO font support for other languages
|
||||
// SteamUGC.SetLanguage(handle, MapLanguage(MySandboxGame.Config.Language));
|
||||
|
||||
|
||||
var call = SteamUGC.SendQueryUGCRequest(handle);
|
||||
|
||||
var result = await CallResultAsync<SteamUGCQueryCompleted_t>.Create(call);
|
||||
@@ -261,9 +262,9 @@ public class ModListComponent : IRenderComponent
|
||||
break;
|
||||
if (details.m_eResult != EResult.k_EResultOK)
|
||||
continue;
|
||||
|
||||
|
||||
var title = details.m_rgchTitle;
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(_searchQuery) && !title.Contains(_searchQuery, StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
|
||||
@@ -278,7 +279,7 @@ public class ModListComponent : IRenderComponent
|
||||
description, $"https://steamcommunity.com/sharedfiles/filedetails/?id={details.m_nPublishedFileId.m_PublishedFileId}",
|
||||
details.m_rtimeCreated, details.m_rtimeUpdated, item.Author));
|
||||
}
|
||||
|
||||
|
||||
_modList = list;
|
||||
}
|
||||
finally
|
||||
|
Reference in New Issue
Block a user