chore: add data widget for servicecontainer status, remove serveropcode data widget

This commit is contained in:
goat 2023-09-17 20:35:40 +02:00
parent 428e1afefd
commit ab9b7e1602
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
4 changed files with 70 additions and 41 deletions

View file

@ -19,7 +19,7 @@ internal class DataWindow : Window
{
private readonly IDataWindowWidget[] modules =
{
new ServerOpcodeWidget(),
new ServicesWidget(),
new AddressesWidget(),
new ObjectTableWidget(),
new FateTableWidget(),

View file

@ -1,40 +0,0 @@
using Dalamud.Data;
using ImGuiNET;
using Newtonsoft.Json;
namespace Dalamud.Interface.Internal.Windows.Data.Widgets;
/// <summary>
/// Widget to display the currently set server opcodes.
/// </summary>
internal class ServerOpcodeWidget : IDataWindowWidget
{
private string? serverOpString;
/// <inheritdoc/>
public string[]? CommandShortcuts { get; init; } = { "opcode", "serveropcode" };
/// <inheritdoc/>
public string DisplayName { get; init; } = "Server Opcode";
/// <inheritdoc/>
public bool Ready { get; set; }
/// <inheritdoc/>
public void Load()
{
var dataManager = Service<DataManager>.Get();
if (dataManager.IsDataReady)
{
this.serverOpString = JsonConvert.SerializeObject(dataManager.ServerOpCodes, Formatting.Indented);
this.Ready = true;
}
}
/// <inheritdoc/>
public void Draw()
{
ImGui.TextUnformatted(this.serverOpString ?? "serverOpString not initialized");
}
}

View file

@ -0,0 +1,59 @@
using System.Linq;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using Dalamud.IoC.Internal;
using ImGuiNET;
namespace Dalamud.Interface.Internal.Windows.Data.Widgets;
/// <summary>
/// Widget for displaying start info.
/// </summary>
internal class ServicesWidget : IDataWindowWidget
{
/// <inheritdoc/>
public string[]? CommandShortcuts { get; init; } = { "services" };
/// <inheritdoc/>
public string DisplayName { get; init; } = "Service Container";
/// <inheritdoc/>
public bool Ready { get; set; }
/// <inheritdoc/>
public void Load()
{
this.Ready = true;
}
/// <inheritdoc/>
public void Draw()
{
var container = Service<ServiceContainer>.Get();
foreach (var instance in container.Instances)
{
var hasInterface = container.InterfaceToTypeMap.Values.Any(x => x == instance.Key);
var isPublic = instance.Key.IsPublic;
ImGui.BulletText($"{instance.Key.FullName} ({instance.Key.GetServiceKind()})");
using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudRed, !hasInterface))
{
ImGui.Text(hasInterface
? $"\t => Provided via interface: {container.InterfaceToTypeMap.First(x => x.Value == instance.Key).Key.FullName}"
: "\t => NO INTERFACE!!!");
}
if (isPublic)
{
using var color = ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
ImGui.Text("\t => PUBLIC!!!");
}
ImGuiHelpers.ScaledDummy(2);
}
}
}

View file

@ -29,6 +29,16 @@ internal class ServiceContainer : IServiceProvider, IServiceType
public ServiceContainer()
{
}
/// <summary>
/// Gets a dictionary of all registered instances.
/// </summary>
public IReadOnlyDictionary<Type, ObjectInstance> Instances => this.instances;
/// <summary>
/// Gets a dictionary mapping interfaces to their implementations.
/// </summary>
public IReadOnlyDictionary<Type, Type> InterfaceToTypeMap => this.interfaceToTypeMap;
/// <summary>
/// Register a singleton object of any type into the current IOC container.