refactor: break ui code into parts

This commit is contained in:
Anna 2021-03-03 23:34:52 -05:00
parent d78f2f6dd7
commit 3602f54fa1
6 changed files with 459 additions and 382 deletions

View File

@ -28,11 +28,11 @@ namespace NoSoliciting {
}
if (args == "report") {
this.Plugin.Ui.ToggleReporting();
this.Plugin.Ui.Report.Toggle();
return;
}
this.Plugin.Ui.ToggleSettings();
this.Plugin.Ui.Settings.Toggle();
}
}
}

View File

@ -0,0 +1,29 @@
using System;
namespace NoSoliciting.Interface {
public class PluginUi : IDisposable {
private Plugin Plugin { get; }
public Settings Settings { get; }
public Report Report { get; }
public PluginUi(Plugin plugin) {
this.Plugin = plugin;
this.Settings = new Settings(plugin, this);
this.Report = new Report(plugin);
this.Plugin.Interface.UiBuilder.OnBuildUi += this.Draw;
}
public void Dispose() {
this.Plugin.Interface.UiBuilder.OnBuildUi -= this.Draw;
this.Settings.Dispose();
}
private void Draw() {
this.Settings.Draw();
this.Report.Draw();
}
}
}

305
NoSoliciting/Interface/Report.cs Executable file
View File

@ -0,0 +1,305 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using Dalamud.Game.Chat.SeStringHandling;
using Dalamud.Game.Chat.SeStringHandling.Payloads;
using Dalamud.Plugin;
using ImGuiNET;
namespace NoSoliciting.Interface {
public class Report {
private Plugin Plugin { get; }
private ReportStatus LastReportStatus { get; set; } = ReportStatus.None;
private bool _showReporting;
private bool ShowReporting {
get => this._showReporting;
set => this._showReporting = value;
}
public Report(Plugin plugin) {
this.Plugin = plugin;
}
public void Open() {
this.ShowReporting = true;
}
public void Toggle() {
this.ShowReporting = !this.ShowReporting;
}
public void Draw() {
if (!this.ShowReporting) {
return;
}
ImGui.SetNextWindowSize(new Vector2(1_000, 350), ImGuiCond.FirstUseEver);
if (!ImGui.Begin("NoSoliciting reporting", ref this._showReporting)) {
return;
}
ImGui.TextUnformatted("Click on one of the entries below to report it to the developer as miscategorised.");
if (this.LastReportStatus != ReportStatus.None) {
var status = this.LastReportStatus switch {
ReportStatus.Failure => "failed to send",
ReportStatus.Successful => "sent successfully",
ReportStatus.InProgress => "sending",
_ => "unknown",
};
ImGui.TextUnformatted($"Last report status: {status}");
}
ImGui.Separator();
ImGui.Spacing();
if (ImGui.BeginTabBar("##report-tabs")) {
this.ChatTab();
this.PartyFinderTab();
ImGui.EndTabBar();
}
ImGui.End();
}
private void ChatTab() {
if (!ImGui.BeginTabItem("Chat##chat-report")) {
return;
}
float[] maxSizes = {0f, 0f, 0f, 0f};
if (ImGui.BeginChild("##chat-messages", new Vector2(-1, -1))) {
ImGui.Columns(5);
AddRow(maxSizes, "Timestamp", "Channel", "Reason", "Sender", "Message");
ImGui.Separator();
foreach (var message in this.Plugin.MessageHistory) {
if (message.FilterReason != null) {
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(238f / 255f, 71f / 255f, 71f / 255f, 1f));
}
var sender = message.Sender.Payloads
.Where(payload => payload.Type == PayloadType.RawText)
.Cast<TextPayload>()
.Select(payload => payload.Text)
.FirstOrDefault() ?? "";
if (AddRow(maxSizes, message.Timestamp.ToString(CultureInfo.CurrentCulture), message.ChatType.Name(this.Plugin.Interface.Data), message.FilterReason ?? "", sender, message.Content.TextValue)) {
ImGui.OpenPopup($"###modal-message-{message.Id}");
}
if (message.FilterReason != null) {
ImGui.PopStyleColor();
}
this.SetUpReportModal(message);
}
for (var idx = 0; idx < maxSizes.Length; idx++) {
ImGui.SetColumnWidth(idx, maxSizes[idx] + ImGui.GetStyle().ItemSpacing.X * 2);
}
ImGui.Columns(1);
ImGui.EndChild();
}
ImGui.EndTabItem();
}
private void PartyFinderTab() {
if (!ImGui.BeginTabItem("Party Finder##pf-report")) {
return;
}
#if DEBUG
if (ImGui.Button("Copy CSV")) {
var builder = new StringBuilder();
foreach (var message in this.Plugin.PartyFinderHistory) {
if (message.FilterReason == null) {
continue;
}
message.ToCsv(builder).Append('\n');
}
ImGui.SetClipboardText(builder.ToString());
}
#endif
float[] maxSizes = {0f, 0f, 0f};
if (ImGui.BeginChild("##pf-messages", new Vector2(-1, -1))) {
ImGui.Columns(4);
AddRow(maxSizes, "Timestamp", "Reason", "Host", "Description");
ImGui.Separator();
foreach (var message in this.Plugin.PartyFinderHistory) {
if (message.FilterReason != null) {
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(238f / 255f, 71f / 255f, 71f / 255f, 1f));
}
var sender = message.Sender.Payloads
.Where(payload => payload.Type == PayloadType.RawText)
.Cast<TextPayload>()
.Select(payload => payload.Text)
.FirstOrDefault() ?? "";
if (AddRow(maxSizes, message.Timestamp.ToString(CultureInfo.CurrentCulture), message.FilterReason ?? "", sender, message.Content.TextValue)) {
ImGui.OpenPopup($"###modal-message-{message.Id}");
}
if (message.FilterReason != null) {
ImGui.PopStyleColor();
}
this.SetUpReportModal(message);
}
for (var idx = 0; idx < maxSizes.Length; idx++) {
ImGui.SetColumnWidth(idx, maxSizes[idx] + ImGui.GetStyle().ItemSpacing.X * 2);
}
ImGui.Columns(1);
ImGui.EndChild();
}
ImGui.EndTabItem();
}
#region Modal
private void SetUpReportModal(Message message) {
ImGui.SetNextWindowSize(new Vector2(350, -1));
if (!ImGui.BeginPopupModal($"Report to NoSoliciting###modal-message-{message.Id}")) {
return;
}
ImGui.PushTextWrapPos();
if (!message.Ml) {
ImGui.TextUnformatted("You cannot report messages filtered by definitions. Please switch to machine learning mode.");
goto EndPopup;
}
ImGui.TextUnformatted("Reporting this message will let the developer know that you think this message was incorrectly classified.");
ImGui.TextUnformatted(message.FilterReason != null
? "Specifically, this message WAS filtered but shouldn't have been."
: "Specifically, this message WAS NOT filtered but should have been.");
ImGui.Separator();
ImGui.TextUnformatted(message.Content.TextValue);
ImGui.Separator();
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0f, 0f, 1f));
ImGui.TextUnformatted("NoSoliciting only works for English messages. Do not report non-English messages.");
ImGui.PopStyleColor();
ImGui.Separator();
if (message.FilterReason == "custom") {
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0f, 0f, 1f));
ImGui.TextUnformatted("You cannot report messages filtered because of a custom filter.");
ImGui.PopStyleColor();
} else {
if (ImGui.Button("Report")) {
Task.Run(async () => {
string? resp = null;
try {
using var client = new WebClient();
this.LastReportStatus = ReportStatus.InProgress;
var reportUrl = this.Plugin.MlFilter?.ReportUrl;
if (reportUrl != null) {
resp = await client.UploadStringTaskAsync(reportUrl, message.ToJson()).ConfigureAwait(true);
}
} catch (Exception) {
// ignored
}
this.LastReportStatus = resp == "{\"message\":\"ok\"}" ? ReportStatus.Successful : ReportStatus.Failure;
PluginLog.Log(resp == null
? "Report not sent. ML model not set."
: $"Report sent. Response: {resp}");
});
ImGui.CloseCurrentPopup();
}
ImGui.SameLine();
}
if (ImGui.Button("Copy to clipboard")) {
ImGui.SetClipboardText(message.Content.TextValue);
}
#if DEBUG
ImGui.SameLine();
if (ImGui.Button("Copy CSV")) {
ImGui.SetClipboardText(message.ToCsv().ToString());
}
#endif
ImGui.SameLine();
EndPopup:
if (ImGui.Button("Cancel")) {
ImGui.CloseCurrentPopup();
}
ImGui.PopTextWrapPos();
ImGui.EndPopup();
}
#endregion
#region Utility
private static bool AddRow(IList<float> maxSizes, params string[] args) {
var clicked = false;
for (var i = 0; i < args.Length; i++) {
var arg = args[i];
var last = i == args.Length - 1;
if (last) {
ImGui.PushTextWrapPos();
}
ImGui.TextUnformatted(arg);
if (last) {
ImGui.PopTextWrapPos();
}
clicked = clicked || ImGui.IsItemClicked();
if (!last) {
maxSizes[i] = Math.Max(maxSizes[i], ImGui.CalcTextSize(arg).X);
}
ImGui.NextColumn();
}
return clicked;
}
#endregion
}
}

View File

@ -0,0 +1,8 @@
namespace NoSoliciting.Interface {
public enum ReportStatus {
None = -1,
Failure = 0,
Successful = 1,
InProgress = 2,
}
}

View File

@ -1,25 +1,15 @@
using Dalamud.Game.Chat.SeStringHandling;
using Dalamud.Game.Chat.SeStringHandling.Payloads;
using Dalamud.Interface;
using Dalamud.Plugin;
using ImGuiNET;
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Numerics;
#if DEBUG
using System.Text;
#endif
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Dalamud.Interface;
using ImGuiNET;
using NoSoliciting.Ml;
namespace NoSoliciting {
public class PluginUi : IDisposable {
namespace NoSoliciting.Interface {
public class Settings : IDisposable {
private Plugin Plugin { get; }
private ReportStatus LastReportStatus { get; set; } = ReportStatus.None;
private PluginUi Ui { get; }
private bool _showSettings;
@ -28,49 +18,27 @@ namespace NoSoliciting {
set => this._showSettings = value;
}
private bool _showReporting;
private bool ShowReporting {
get => this._showReporting;
set => this._showReporting = value;
}
public PluginUi(Plugin plugin) {
public Settings(Plugin plugin, PluginUi ui) {
this.Plugin = plugin;
this.Ui = ui;
this.Plugin.Interface.UiBuilder.OnBuildUi += this.Draw;
this.Plugin.Interface.UiBuilder.OnOpenConfigUi += this.OpenSettings;
this.Plugin.Interface.UiBuilder.OnOpenConfigUi += this.Open;
}
public void Dispose() {
this.Plugin.Interface.UiBuilder.OnOpenConfigUi -= this.OpenSettings;
this.Plugin.Interface.UiBuilder.OnBuildUi -= this.Draw;
this.Plugin.Interface.UiBuilder.OnOpenConfigUi -= this.Open;
}
private void OpenSettings(object? sender, EventArgs? e) {
private void Open(object? sender, EventArgs? e) {
this.ShowSettings = true;
}
public void ToggleSettings() {
public void Toggle() {
this.ShowSettings = !this.ShowSettings;
}
public void ToggleReporting() {
this.ShowReporting = !this.ShowReporting;
}
private void Draw() {
if (this.ShowSettings) {
this.DrawSettings();
}
if (this.ShowReporting) {
this.DrawReportWindow();
}
}
private void DrawSettings() {
if (!ImGui.Begin($"{this.Plugin.Name} settings", ref this._showSettings)) {
public void Draw() {
if (!this.ShowSettings || !ImGui.Begin($"{this.Plugin.Name} settings", ref this._showSettings)) {
return;
}
@ -129,96 +97,13 @@ namespace NoSoliciting {
ImGui.Separator();
if (ImGui.Button("Show reporting window")) {
this.ShowReporting = true;
this.Ui.Report.Open();
}
ImGui.End();
}
private void DrawOtherFilters() {
if (!ImGui.BeginTabItem("Other filters")) {
return;
}
if (ImGui.CollapsingHeader("Chat filters")) {
var customChat = this.Plugin.Config.CustomChatFilter;
if (ImGui.Checkbox("Enable custom chat filters", ref customChat)) {
this.Plugin.Config.CustomChatFilter = customChat;
this.Plugin.Config.Save();
}
if (this.Plugin.Config.CustomChatFilter) {
var substrings = this.Plugin.Config.ChatSubstrings;
var regexes = this.Plugin.Config.ChatRegexes;
this.DrawCustom("chat", ref substrings, ref regexes);
}
}
if (ImGui.CollapsingHeader("Party Finder filters")) {
var filterHugeItemLevelPFs = this.Plugin.Config.FilterHugeItemLevelPFs;
// ReSharper disable once InvertIf
if (ImGui.Checkbox("Filter PFs with item level above maximum", ref filterHugeItemLevelPFs)) {
this.Plugin.Config.FilterHugeItemLevelPFs = filterHugeItemLevelPFs;
this.Plugin.Config.Save();
}
var considerPrivate = this.Plugin.Config.ConsiderPrivatePfs;
if (ImGui.Checkbox("Apply filters to private Party Finder listings", ref considerPrivate)) {
this.Plugin.Config.ConsiderPrivatePfs = considerPrivate;
this.Plugin.Config.Save();
}
var customPf = this.Plugin.Config.CustomPFFilter;
if (ImGui.Checkbox("Enable custom Party Finder filters", ref customPf)) {
this.Plugin.Config.CustomPFFilter = customPf;
this.Plugin.Config.Save();
}
if (this.Plugin.Config.CustomPFFilter) {
var substrings = this.Plugin.Config.PFSubstrings;
var regexes = this.Plugin.Config.PFRegexes;
this.DrawCustom("pf", ref substrings, ref regexes);
}
}
ImGui.EndTabItem();
}
private void DrawDefsBasicSettings() {
if (this.Plugin.Definitions == null) {
return;
}
if (!ImGui.BeginTabItem("Filters")) {
return;
}
this.DrawCheckboxes(this.Plugin.Definitions.Chat.Values, true, "chat");
ImGui.Separator();
this.DrawCheckboxes(this.Plugin.Definitions.PartyFinder.Values, true, "Party Finder");
ImGui.EndTabItem();
}
private void DrawDefsAdvancedSettings() {
if (this.Plugin.Definitions == null) {
return;
}
if (ImGui.BeginTabItem("Chat")) {
this.DrawCheckboxes(this.Plugin.Definitions.Chat.Values, false, "chat");
ImGui.EndTabItem();
}
if (ImGui.BeginTabItem("Party Finder")) {
this.DrawCheckboxes(this.Plugin.Definitions.PartyFinder.Values, false, "Party Finder");
ImGui.EndTabItem();
}
}
#region ML config
private void DrawMachineLearningConfig() {
if (this.Plugin.Config.AdvancedMode) {
@ -338,6 +223,10 @@ namespace NoSoliciting {
ImGui.EndTabItem();
}
#endregion
#region Definitions config
private void DrawDefinitionsConfig() {
if (this.Plugin.Config.AdvancedMode) {
this.DrawDefsAdvancedSettings();
@ -373,6 +262,95 @@ namespace NoSoliciting {
ImGui.EndTabItem();
}
private void DrawDefsBasicSettings() {
if (this.Plugin.Definitions == null) {
return;
}
if (!ImGui.BeginTabItem("Filters")) {
return;
}
this.DrawCheckboxes(this.Plugin.Definitions.Chat.Values, true, "chat");
ImGui.Separator();
this.DrawCheckboxes(this.Plugin.Definitions.PartyFinder.Values, true, "Party Finder");
ImGui.EndTabItem();
}
private void DrawDefsAdvancedSettings() {
if (this.Plugin.Definitions == null) {
return;
}
if (ImGui.BeginTabItem("Chat")) {
this.DrawCheckboxes(this.Plugin.Definitions.Chat.Values, false, "chat");
ImGui.EndTabItem();
}
if (ImGui.BeginTabItem("Party Finder")) {
this.DrawCheckboxes(this.Plugin.Definitions.PartyFinder.Values, false, "Party Finder");
ImGui.EndTabItem();
}
}
#endregion
#region Other config
private void DrawOtherFilters() {
if (!ImGui.BeginTabItem("Other filters")) {
return;
}
if (ImGui.CollapsingHeader("Chat filters")) {
var customChat = this.Plugin.Config.CustomChatFilter;
if (ImGui.Checkbox("Enable custom chat filters", ref customChat)) {
this.Plugin.Config.CustomChatFilter = customChat;
this.Plugin.Config.Save();
}
if (this.Plugin.Config.CustomChatFilter) {
var substrings = this.Plugin.Config.ChatSubstrings;
var regexes = this.Plugin.Config.ChatRegexes;
this.DrawCustom("chat", ref substrings, ref regexes);
}
}
if (ImGui.CollapsingHeader("Party Finder filters")) {
var filterHugeItemLevelPFs = this.Plugin.Config.FilterHugeItemLevelPFs;
// ReSharper disable once InvertIf
if (ImGui.Checkbox("Filter PFs with item level above maximum", ref filterHugeItemLevelPFs)) {
this.Plugin.Config.FilterHugeItemLevelPFs = filterHugeItemLevelPFs;
this.Plugin.Config.Save();
}
var considerPrivate = this.Plugin.Config.ConsiderPrivatePfs;
if (ImGui.Checkbox("Apply filters to private Party Finder listings", ref considerPrivate)) {
this.Plugin.Config.ConsiderPrivatePfs = considerPrivate;
this.Plugin.Config.Save();
}
var customPf = this.Plugin.Config.CustomPFFilter;
if (ImGui.Checkbox("Enable custom Party Finder filters", ref customPf)) {
this.Plugin.Config.CustomPFFilter = customPf;
this.Plugin.Config.Save();
}
if (this.Plugin.Config.CustomPFFilter) {
var substrings = this.Plugin.Config.PFSubstrings;
var regexes = this.Plugin.Config.PFRegexes;
this.DrawCustom("pf", ref substrings, ref regexes);
}
}
ImGui.EndTabItem();
}
private void DrawCustom(string name, ref List<string> substrings, ref List<string> regexes) {
ImGui.Columns(2);
@ -452,6 +430,10 @@ namespace NoSoliciting {
}
}
#endregion
#region Utility
private void DrawCheckboxes(IEnumerable<Definition> defs, bool basic, string labelFillIn) {
foreach (var def in defs) {
this.Plugin.Config.FilterStatus.TryGetValue(def.Id, out var enabled);
@ -465,254 +447,6 @@ namespace NoSoliciting {
}
}
private void DrawReportWindow() {
ImGui.SetNextWindowSize(new Vector2(1_000, 350), ImGuiCond.FirstUseEver);
if (!ImGui.Begin("NoSoliciting reporting", ref this._showReporting)) {
return;
}
ImGui.TextUnformatted("Click on one of the entries below to report it to the developer as miscategorised.");
if (this.LastReportStatus != ReportStatus.None) {
var status = this.LastReportStatus switch {
ReportStatus.Failure => "failed to send",
ReportStatus.Successful => "sent successfully",
ReportStatus.InProgress => "sending",
_ => "unknown",
};
ImGui.TextUnformatted($"Last report status: {status}");
}
ImGui.Separator();
ImGui.Spacing();
if (ImGui.BeginTabBar("##report-tabs")) {
if (ImGui.BeginTabItem("Chat##chat-report")) {
float[] maxSizes = {0f, 0f, 0f, 0f};
if (ImGui.BeginChild("##chat-messages", new Vector2(-1, -1))) {
ImGui.Columns(5);
AddRow(maxSizes, "Timestamp", "Channel", "Reason", "Sender", "Message");
ImGui.Separator();
foreach (var message in this.Plugin.MessageHistory) {
if (message.FilterReason != null) {
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(238f / 255f, 71f / 255f, 71f / 255f, 1f));
}
var sender = message.Sender.Payloads
.Where(payload => payload.Type == PayloadType.RawText)
.Cast<TextPayload>()
.Select(payload => payload.Text)
.FirstOrDefault() ?? "";
if (AddRow(maxSizes, message.Timestamp.ToString(CultureInfo.CurrentCulture), message.ChatType.Name(this.Plugin.Interface.Data), message.FilterReason ?? "", sender, message.Content.TextValue)) {
ImGui.OpenPopup($"###modal-message-{message.Id}");
}
if (message.FilterReason != null) {
ImGui.PopStyleColor();
}
this.SetUpReportModal(message);
}
for (var idx = 0; idx < maxSizes.Length; idx++) {
ImGui.SetColumnWidth(idx, maxSizes[idx] + ImGui.GetStyle().ItemSpacing.X * 2);
}
ImGui.Columns(1);
ImGui.EndChild();
}
ImGui.EndTabItem();
}
if (ImGui.BeginTabItem("Party Finder##pf-report")) {
#if DEBUG
if (ImGui.Button("Copy CSV")) {
var builder = new StringBuilder();
foreach (var message in this.Plugin.PartyFinderHistory) {
if (message.FilterReason == null) {
continue;
}
message.ToCsv(builder).Append('\n');
}
ImGui.SetClipboardText(builder.ToString());
}
#endif
float[] maxSizes = {0f, 0f, 0f};
if (ImGui.BeginChild("##pf-messages", new Vector2(-1, -1))) {
ImGui.Columns(4);
AddRow(maxSizes, "Timestamp", "Reason", "Host", "Description");
ImGui.Separator();
foreach (var message in this.Plugin.PartyFinderHistory) {
if (message.FilterReason != null) {
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(238f / 255f, 71f / 255f, 71f / 255f, 1f));
}
var sender = message.Sender.Payloads
.Where(payload => payload.Type == PayloadType.RawText)
.Cast<TextPayload>()
.Select(payload => payload.Text)
.FirstOrDefault() ?? "";
if (AddRow(maxSizes, message.Timestamp.ToString(CultureInfo.CurrentCulture), message.FilterReason ?? "", sender, message.Content.TextValue)) {
ImGui.OpenPopup($"###modal-message-{message.Id}");
}
if (message.FilterReason != null) {
ImGui.PopStyleColor();
}
this.SetUpReportModal(message);
}
for (var idx = 0; idx < maxSizes.Length; idx++) {
ImGui.SetColumnWidth(idx, maxSizes[idx] + ImGui.GetStyle().ItemSpacing.X * 2);
}
ImGui.Columns(1);
ImGui.EndChild();
}
ImGui.EndTabItem();
}
ImGui.EndTabBar();
}
ImGui.End();
}
private void SetUpReportModal(Message message) {
ImGui.SetNextWindowSize(new Vector2(350, -1));
if (!ImGui.BeginPopupModal($"Report to NoSoliciting###modal-message-{message.Id}")) {
return;
}
ImGui.PushTextWrapPos();
if (!message.Ml) {
ImGui.TextUnformatted("You cannot report messages filtered by definitions. Please switch to machine learning mode.");
goto EndPopup;
}
ImGui.TextUnformatted("Reporting this message will let the developer know that you think this message was incorrectly classified.");
ImGui.TextUnformatted(message.FilterReason != null
? "Specifically, this message WAS filtered but shouldn't have been."
: "Specifically, this message WAS NOT filtered but should have been.");
ImGui.Separator();
ImGui.TextUnformatted(message.Content.TextValue);
ImGui.Separator();
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0f, 0f, 1f));
ImGui.TextUnformatted("NoSoliciting only works for English messages. Do not report non-English messages.");
ImGui.PopStyleColor();
ImGui.Separator();
if (message.FilterReason == "custom") {
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0f, 0f, 1f));
ImGui.TextUnformatted("You cannot report messages filtered because of a custom filter.");
ImGui.PopStyleColor();
} else {
if (ImGui.Button("Report")) {
Task.Run(async () => {
string? resp = null;
try {
using var client = new WebClient();
this.LastReportStatus = ReportStatus.InProgress;
var reportUrl = this.Plugin.MlFilter?.ReportUrl;
if (reportUrl != null) {
resp = await client.UploadStringTaskAsync(reportUrl, message.ToJson()).ConfigureAwait(true);
}
} catch (Exception) {
// ignored
}
this.LastReportStatus = resp == "{\"message\":\"ok\"}" ? ReportStatus.Successful : ReportStatus.Failure;
PluginLog.Log(resp == null
? "Report not sent. ML model not set."
: $"Report sent. Response: {resp}");
});
ImGui.CloseCurrentPopup();
}
ImGui.SameLine();
}
if (ImGui.Button("Copy to clipboard")) {
ImGui.SetClipboardText(message.Content.TextValue);
}
#if DEBUG
ImGui.SameLine();
if (ImGui.Button("Copy CSV")) {
ImGui.SetClipboardText(message.ToCsv().ToString());
}
#endif
ImGui.SameLine();
EndPopup:
if (ImGui.Button("Cancel")) {
ImGui.CloseCurrentPopup();
}
ImGui.PopTextWrapPos();
ImGui.EndPopup();
}
private enum ReportStatus {
None = -1,
Failure = 0,
Successful = 1,
InProgress = 2,
}
private static bool AddRow(IList<float> maxSizes, params string[] args) {
var clicked = false;
for (var i = 0; i < args.Length; i++) {
var arg = args[i];
var last = i == args.Length - 1;
if (last) {
ImGui.PushTextWrapPos();
}
ImGui.TextUnformatted(arg);
if (last) {
ImGui.PopTextWrapPos();
}
clicked = clicked || ImGui.IsItemClicked();
if (!last) {
maxSizes[i] = Math.Max(maxSizes[i], ImGui.CalcTextSize(arg).X);
}
ImGui.NextColumn();
}
return clicked;
}
#endregion
}
}

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using NoSoliciting.Interface;
using NoSoliciting.Ml;
namespace NoSoliciting {