2022-12-21 19:23:48 +00:00
|
|
|
|
using Account;
|
|
|
|
|
using Dalamud.Interface;
|
|
|
|
|
using Dalamud.Interface.Components;
|
|
|
|
|
using Dalamud.Interface.ImGuiFileDialog;
|
2022-10-25 21:31:35 +00:00
|
|
|
|
using Dalamud.Interface.Windowing;
|
2022-11-24 06:24:45 +00:00
|
|
|
|
using Dalamud.Logging;
|
2022-12-22 00:01:09 +00:00
|
|
|
|
using ECommons;
|
2022-12-21 19:23:48 +00:00
|
|
|
|
using Google.Protobuf;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
using ImGuiNET;
|
2022-12-21 19:23:48 +00:00
|
|
|
|
using Pal.Client.Net;
|
2023-02-08 15:06:43 +00:00
|
|
|
|
using Pal.Client.Rendering;
|
2022-12-22 00:01:09 +00:00
|
|
|
|
using Pal.Client.Scheduled;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
using System;
|
2022-12-21 19:23:48 +00:00
|
|
|
|
using System.IO;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Numerics;
|
2022-11-25 08:43:24 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
2022-11-24 06:24:45 +00:00
|
|
|
|
using System.Threading;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
using Dalamud.Game.Gui;
|
2023-02-16 23:54:23 +00:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2023-02-10 19:48:14 +00:00
|
|
|
|
using Pal.Client.Properties;
|
2023-02-15 01:38:04 +00:00
|
|
|
|
using Pal.Client.Configuration;
|
2023-02-16 18:51:54 +00:00
|
|
|
|
using Pal.Client.Database;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
using Pal.Client.DependencyInjection;
|
2023-02-16 09:46:19 +00:00
|
|
|
|
using Pal.Client.Extensions;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2022-10-26 18:43:24 +00:00
|
|
|
|
namespace Pal.Client.Windows
|
2022-10-23 02:38:58 +00:00
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
internal sealed class ConfigWindow : Window, ILanguageChanged, IDisposable
|
2022-10-23 02:38:58 +00:00
|
|
|
|
{
|
2023-02-11 13:31:43 +00:00
|
|
|
|
private const string WindowId = "###PalPalaceConfig";
|
2023-02-15 22:17:19 +00:00
|
|
|
|
|
2023-02-16 23:54:23 +00:00
|
|
|
|
private readonly ILogger<ConfigWindow> _logger;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
private readonly WindowSystem _windowSystem;
|
|
|
|
|
private readonly ConfigurationManager _configurationManager;
|
|
|
|
|
private readonly IPalacePalConfiguration _configuration;
|
|
|
|
|
private readonly RenderAdapter _renderAdapter;
|
|
|
|
|
private readonly TerritoryState _territoryState;
|
|
|
|
|
private readonly FrameworkService _frameworkService;
|
|
|
|
|
private readonly FloorService _floorService;
|
|
|
|
|
private readonly DebugState _debugState;
|
2023-02-17 14:51:45 +00:00
|
|
|
|
private readonly Chat _chat;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
private readonly RemoteApi _remoteApi;
|
2023-02-16 18:51:54 +00:00
|
|
|
|
private readonly ImportService _importService;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
|
2022-10-23 02:38:58 +00:00
|
|
|
|
private int _mode;
|
2023-02-08 15:06:43 +00:00
|
|
|
|
private int _renderer;
|
2023-02-15 01:38:04 +00:00
|
|
|
|
private ConfigurableMarker _trapConfig = new();
|
|
|
|
|
private ConfigurableMarker _hoardConfig = new();
|
|
|
|
|
private ConfigurableMarker _silverConfig = new();
|
2022-10-25 21:31:35 +00:00
|
|
|
|
|
2022-10-30 10:02:49 +00:00
|
|
|
|
private string? _connectionText;
|
2022-11-25 08:43:24 +00:00
|
|
|
|
private bool _switchToCommunityTab;
|
2022-12-21 19:23:48 +00:00
|
|
|
|
private string _openImportPath = string.Empty;
|
|
|
|
|
private string _saveExportPath = string.Empty;
|
|
|
|
|
private string? _openImportDialogStartPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
|
|
|
|
private string? _saveExportDialogStartPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
2023-02-11 20:10:45 +00:00
|
|
|
|
private readonly FileDialogManager _importDialog;
|
|
|
|
|
private readonly FileDialogManager _exportDialog;
|
2023-02-16 18:51:54 +00:00
|
|
|
|
private ImportHistory? _lastImport;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2023-02-13 21:42:24 +00:00
|
|
|
|
private CancellationTokenSource? _testConnectionCts;
|
2023-02-16 23:54:23 +00:00
|
|
|
|
private CancellationTokenSource? _lastImportCts;
|
2023-02-13 21:42:24 +00:00
|
|
|
|
|
2023-02-15 22:17:19 +00:00
|
|
|
|
public ConfigWindow(
|
2023-02-16 23:54:23 +00:00
|
|
|
|
ILogger<ConfigWindow> logger,
|
2023-02-15 22:17:19 +00:00
|
|
|
|
WindowSystem windowSystem,
|
|
|
|
|
ConfigurationManager configurationManager,
|
|
|
|
|
IPalacePalConfiguration configuration,
|
|
|
|
|
RenderAdapter renderAdapter,
|
|
|
|
|
TerritoryState territoryState,
|
|
|
|
|
FrameworkService frameworkService,
|
|
|
|
|
FloorService floorService,
|
|
|
|
|
DebugState debugState,
|
2023-02-17 14:51:45 +00:00
|
|
|
|
Chat chat,
|
2023-02-16 18:51:54 +00:00
|
|
|
|
RemoteApi remoteApi,
|
|
|
|
|
ImportService importService)
|
2023-02-15 22:17:19 +00:00
|
|
|
|
: base(WindowId)
|
2022-10-23 02:38:58 +00:00
|
|
|
|
{
|
2023-02-16 23:54:23 +00:00
|
|
|
|
_logger = logger;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_windowSystem = windowSystem;
|
|
|
|
|
_configurationManager = configurationManager;
|
|
|
|
|
_configuration = configuration;
|
|
|
|
|
_renderAdapter = renderAdapter;
|
|
|
|
|
_territoryState = territoryState;
|
|
|
|
|
_frameworkService = frameworkService;
|
|
|
|
|
_floorService = floorService;
|
|
|
|
|
_debugState = debugState;
|
2023-02-17 14:51:45 +00:00
|
|
|
|
_chat = chat;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_remoteApi = remoteApi;
|
2023-02-16 18:51:54 +00:00
|
|
|
|
_importService = importService;
|
2023-02-15 22:17:19 +00:00
|
|
|
|
|
2023-02-11 13:31:43 +00:00
|
|
|
|
LanguageChanged();
|
2023-02-11 13:40:22 +00:00
|
|
|
|
|
2022-10-23 02:38:58 +00:00
|
|
|
|
Size = new Vector2(500, 400);
|
|
|
|
|
SizeCondition = ImGuiCond.FirstUseEver;
|
|
|
|
|
Position = new Vector2(300, 300);
|
|
|
|
|
PositionCondition = ImGuiCond.FirstUseEver;
|
2022-12-21 19:23:48 +00:00
|
|
|
|
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_importDialog = new FileDialogManager
|
|
|
|
|
{ AddedWindowFlags = ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoDocking };
|
|
|
|
|
_exportDialog = new FileDialogManager
|
|
|
|
|
{ AddedWindowFlags = ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoDocking };
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_windowSystem.AddWindow(this);
|
2023-02-11 13:31:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-15 01:38:04 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_windowSystem.RemoveWindow(this);
|
2023-02-16 23:54:23 +00:00
|
|
|
|
_lastImportCts?.Cancel();
|
2023-02-15 01:38:04 +00:00
|
|
|
|
_testConnectionCts?.Cancel();
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-15 22:17:19 +00:00
|
|
|
|
public void LanguageChanged()
|
|
|
|
|
{
|
|
|
|
|
var version = typeof(Plugin).Assembly.GetName().Version!.ToString(2);
|
|
|
|
|
WindowName = $"{Localization.Palace_Pal} v{version}{WindowId}";
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-23 02:38:58 +00:00
|
|
|
|
public override void OnOpen()
|
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_mode = (int)_configuration.Mode;
|
|
|
|
|
_renderer = (int)_configuration.Renderer.SelectedRenderer;
|
|
|
|
|
_trapConfig = new ConfigurableMarker(_configuration.DeepDungeons.Traps);
|
|
|
|
|
_hoardConfig = new ConfigurableMarker(_configuration.DeepDungeons.HoardCoffers);
|
|
|
|
|
_silverConfig = new ConfigurableMarker(_configuration.DeepDungeons.SilverCoffers);
|
2022-10-23 02:38:58 +00:00
|
|
|
|
_connectionText = null;
|
2023-02-16 18:51:54 +00:00
|
|
|
|
|
|
|
|
|
UpdateLastImport();
|
2022-10-23 02:38:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-21 19:23:48 +00:00
|
|
|
|
public override void OnClose()
|
|
|
|
|
{
|
|
|
|
|
_importDialog.Reset();
|
|
|
|
|
_exportDialog.Reset();
|
2023-02-13 21:42:24 +00:00
|
|
|
|
_testConnectionCts?.Cancel();
|
|
|
|
|
_testConnectionCts = null;
|
2022-12-21 19:23:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-23 02:38:58 +00:00
|
|
|
|
public override void Draw()
|
|
|
|
|
{
|
|
|
|
|
bool save = false;
|
|
|
|
|
bool saveAndClose = false;
|
|
|
|
|
if (ImGui.BeginTabBar("PalTabs"))
|
|
|
|
|
{
|
2023-02-10 19:48:14 +00:00
|
|
|
|
DrawDeepDungeonItemsTab(ref save, ref saveAndClose);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
DrawCommunityTab(ref saveAndClose);
|
2022-12-22 00:01:09 +00:00
|
|
|
|
DrawImportTab();
|
2022-12-21 19:23:48 +00:00
|
|
|
|
DrawExportTab();
|
2023-02-08 15:06:43 +00:00
|
|
|
|
DrawRenderTab(ref save, ref saveAndClose);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
DrawDebugTab();
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.EndTabBar();
|
|
|
|
|
}
|
2022-10-25 21:31:35 +00:00
|
|
|
|
|
2022-12-21 19:23:48 +00:00
|
|
|
|
_importDialog.Draw();
|
|
|
|
|
|
2022-12-10 19:53:07 +00:00
|
|
|
|
if (save || saveAndClose)
|
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_configuration.Mode = (EMode)_mode;
|
|
|
|
|
_configuration.Renderer.SelectedRenderer = (ERenderer)_renderer;
|
|
|
|
|
_configuration.DeepDungeons.Traps = _trapConfig.Build();
|
|
|
|
|
_configuration.DeepDungeons.HoardCoffers = _hoardConfig.Build();
|
|
|
|
|
_configuration.DeepDungeons.SilverCoffers = _silverConfig.Build();
|
2023-02-15 01:38:04 +00:00
|
|
|
|
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_configurationManager.Save(_configuration);
|
2022-10-25 21:31:35 +00:00
|
|
|
|
|
2022-12-10 19:53:07 +00:00
|
|
|
|
if (saveAndClose)
|
|
|
|
|
IsOpen = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2023-02-10 19:48:14 +00:00
|
|
|
|
private void DrawDeepDungeonItemsTab(ref bool save, ref bool saveAndClose)
|
2022-12-10 19:53:07 +00:00
|
|
|
|
{
|
2023-02-11 13:40:22 +00:00
|
|
|
|
if (ImGui.BeginTabItem($"{Localization.ConfigTab_DeepDungeons}###TabDeepDungeons"))
|
2022-12-10 19:53:07 +00:00
|
|
|
|
{
|
2023-02-15 01:38:04 +00:00
|
|
|
|
ImGui.Checkbox(Localization.Config_Traps_Show, ref _trapConfig.Show);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.Indent();
|
2023-02-15 01:38:04 +00:00
|
|
|
|
ImGui.BeginDisabled(!_trapConfig.Show);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.Spacing();
|
2023-02-15 01:38:04 +00:00
|
|
|
|
ImGui.ColorEdit4(Localization.Config_Traps_Color, ref _trapConfig.Color, ImGuiColorEditFlags.NoInputs);
|
|
|
|
|
ImGui.Checkbox(Localization.Config_Traps_HideImpossible, ref _trapConfig.OnlyVisibleAfterPomander);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.SameLine();
|
2023-02-10 19:48:14 +00:00
|
|
|
|
ImGuiComponents.HelpMarker(Localization.Config_Traps_HideImpossible_ToolTip);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.EndDisabled();
|
|
|
|
|
ImGui.Unindent();
|
|
|
|
|
|
|
|
|
|
ImGui.Separator();
|
|
|
|
|
|
2023-02-15 01:38:04 +00:00
|
|
|
|
ImGui.Checkbox(Localization.Config_HoardCoffers_Show, ref _hoardConfig.Show);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.Indent();
|
2023-02-15 01:38:04 +00:00
|
|
|
|
ImGui.BeginDisabled(!_hoardConfig.Show);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.Spacing();
|
2023-02-15 22:17:19 +00:00
|
|
|
|
ImGui.ColorEdit4(Localization.Config_HoardCoffers_Color, ref _hoardConfig.Color,
|
|
|
|
|
ImGuiColorEditFlags.NoInputs);
|
|
|
|
|
ImGui.Checkbox(Localization.Config_HoardCoffers_HideImpossible,
|
|
|
|
|
ref _hoardConfig.OnlyVisibleAfterPomander);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.SameLine();
|
2023-02-10 19:48:14 +00:00
|
|
|
|
ImGuiComponents.HelpMarker(Localization.Config_HoardCoffers_HideImpossible_ToolTip);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.EndDisabled();
|
|
|
|
|
ImGui.Unindent();
|
|
|
|
|
|
|
|
|
|
ImGui.Separator();
|
|
|
|
|
|
2023-02-15 01:38:04 +00:00
|
|
|
|
ImGui.Checkbox(Localization.Config_SilverCoffer_Show, ref _silverConfig.Show);
|
2023-02-10 19:48:14 +00:00
|
|
|
|
ImGuiComponents.HelpMarker(Localization.Config_SilverCoffers_ToolTip);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.Indent();
|
2023-02-15 01:38:04 +00:00
|
|
|
|
ImGui.BeginDisabled(!_silverConfig.Show);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.Spacing();
|
2023-02-15 22:17:19 +00:00
|
|
|
|
ImGui.ColorEdit4(Localization.Config_SilverCoffer_Color, ref _silverConfig.Color,
|
|
|
|
|
ImGuiColorEditFlags.NoInputs);
|
2023-02-15 01:38:04 +00:00
|
|
|
|
ImGui.Checkbox(Localization.Config_SilverCoffer_Filled, ref _silverConfig.Fill);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.EndDisabled();
|
|
|
|
|
ImGui.Unindent();
|
|
|
|
|
|
|
|
|
|
ImGui.Separator();
|
|
|
|
|
|
2023-02-10 19:48:14 +00:00
|
|
|
|
save = ImGui.Button(Localization.Save);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.SameLine();
|
2023-02-10 19:48:14 +00:00
|
|
|
|
saveAndClose = ImGui.Button(Localization.SaveAndClose);
|
2022-12-10 19:53:07 +00:00
|
|
|
|
|
|
|
|
|
ImGui.EndTabItem();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2022-12-10 19:53:07 +00:00
|
|
|
|
private void DrawCommunityTab(ref bool saveAndClose)
|
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
if (BeginTabItemEx($"{Localization.ConfigTab_Community}###TabCommunity",
|
|
|
|
|
_switchToCommunityTab ? ImGuiTabItemFlags.SetSelected : ImGuiTabItemFlags.None))
|
2022-12-10 19:53:07 +00:00
|
|
|
|
{
|
|
|
|
|
_switchToCommunityTab = false;
|
2022-11-25 08:43:24 +00:00
|
|
|
|
|
2023-02-10 19:48:14 +00:00
|
|
|
|
ImGui.TextWrapped(Localization.Explanation_3);
|
|
|
|
|
ImGui.TextWrapped(Localization.Explanation_4);
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2023-02-15 01:38:04 +00:00
|
|
|
|
ImGui.RadioButton(Localization.Config_UploadMyDiscoveries_ShowOtherTraps, ref _mode, (int)EMode.Online);
|
2023-02-15 22:17:19 +00:00
|
|
|
|
ImGui.RadioButton(Localization.Config_NeverUploadDiscoveries_ShowMyTraps, ref _mode,
|
|
|
|
|
(int)EMode.Offline);
|
2023-02-10 19:48:14 +00:00
|
|
|
|
saveAndClose = ImGui.Button(Localization.SaveAndClose);
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.Separator();
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2023-02-15 22:17:19 +00:00
|
|
|
|
ImGui.BeginDisabled(_configuration.Mode != EMode.Online);
|
2023-02-10 19:48:14 +00:00
|
|
|
|
if (ImGui.Button(Localization.Config_TestConnection))
|
2022-12-10 19:53:07 +00:00
|
|
|
|
TestConnection();
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2022-12-10 19:53:07 +00:00
|
|
|
|
if (_connectionText != null)
|
|
|
|
|
ImGui.Text(_connectionText);
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.EndDisabled();
|
|
|
|
|
ImGui.EndTabItem();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2022-12-21 19:23:48 +00:00
|
|
|
|
private void DrawImportTab()
|
|
|
|
|
{
|
2023-02-11 13:40:22 +00:00
|
|
|
|
if (ImGui.BeginTabItem($"{Localization.ConfigTab_Import}###TabImport"))
|
2022-12-21 19:23:48 +00:00
|
|
|
|
{
|
2023-02-10 19:48:14 +00:00
|
|
|
|
ImGui.TextWrapped(Localization.Config_ImportExplanation1);
|
|
|
|
|
ImGui.TextWrapped(Localization.Config_ImportExplanation2);
|
|
|
|
|
ImGui.TextWrapped(Localization.Config_ImportExplanation3);
|
2022-12-22 00:01:09 +00:00
|
|
|
|
ImGui.Separator();
|
2023-02-15 22:17:19 +00:00
|
|
|
|
ImGui.TextWrapped(string.Format(Localization.Config_ImportDownloadLocation,
|
|
|
|
|
"https://github.com/carvelli/PalacePal/releases/"));
|
2023-02-10 19:48:14 +00:00
|
|
|
|
if (ImGui.Button(Localization.Config_Import_VisitGitHub))
|
2023-02-02 15:45:54 +00:00
|
|
|
|
GenericHelpers.ShellStart("https://github.com/carvelli/PalacePal/releases/latest");
|
2022-12-22 00:01:09 +00:00
|
|
|
|
ImGui.Separator();
|
2023-02-10 19:48:14 +00:00
|
|
|
|
ImGui.Text(Localization.Config_SelectImportFile);
|
2022-12-21 19:23:48 +00:00
|
|
|
|
ImGui.SameLine();
|
2023-02-11 13:40:22 +00:00
|
|
|
|
ImGui.InputTextWithHint("", Localization.Config_SelectImportFile_Hint, ref _openImportPath, 260);
|
2022-12-21 19:23:48 +00:00
|
|
|
|
ImGui.SameLine();
|
|
|
|
|
if (ImGuiComponents.IconButton(FontAwesomeIcon.Search))
|
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_importDialog.OpenFileDialog(Localization.Palace_Pal, $"{Localization.Palace_Pal} (*.pal) {{.pal}}",
|
|
|
|
|
(success, paths) =>
|
2022-12-21 19:23:48 +00:00
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
if (success && paths.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
_openImportPath = paths.First();
|
|
|
|
|
}
|
|
|
|
|
}, selectionCountMax: 1, startPath: _openImportDialogStartPath, isModal: false);
|
|
|
|
|
_openImportDialogStartPath =
|
|
|
|
|
null; // only use this once, FileDialogManager will save path between calls
|
2022-12-21 19:23:48 +00:00
|
|
|
|
}
|
2022-12-22 00:01:09 +00:00
|
|
|
|
|
|
|
|
|
ImGui.BeginDisabled(string.IsNullOrEmpty(_openImportPath) || !File.Exists(_openImportPath));
|
2023-02-10 19:48:14 +00:00
|
|
|
|
if (ImGui.Button(Localization.Config_StartImport))
|
2022-12-22 00:01:09 +00:00
|
|
|
|
DoImport(_openImportPath);
|
|
|
|
|
ImGui.EndDisabled();
|
2022-12-24 09:27:59 +00:00
|
|
|
|
|
2023-02-16 18:51:54 +00:00
|
|
|
|
ImportHistory? importHistory = _lastImport;
|
2022-12-24 09:27:59 +00:00
|
|
|
|
if (importHistory != null)
|
|
|
|
|
{
|
|
|
|
|
ImGui.Separator();
|
2023-02-15 22:17:19 +00:00
|
|
|
|
ImGui.TextWrapped(string.Format(Localization.Config_UndoImportExplanation1,
|
2023-02-16 18:51:54 +00:00
|
|
|
|
importHistory.ImportedAt.ToLocalTime(),
|
|
|
|
|
importHistory.RemoteUrl,
|
|
|
|
|
importHistory.ExportedAt.ToUniversalTime()));
|
2023-02-10 19:48:14 +00:00
|
|
|
|
ImGui.TextWrapped(Localization.Config_UndoImportExplanation2);
|
|
|
|
|
if (ImGui.Button(Localization.Config_UndoImport))
|
2022-12-24 09:27:59 +00:00
|
|
|
|
UndoImport(importHistory.Id);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-21 19:23:48 +00:00
|
|
|
|
ImGui.EndTabItem();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawExportTab()
|
|
|
|
|
{
|
2023-02-16 12:27:28 +00:00
|
|
|
|
if (_configuration.HasRoleOnCurrentServer(RemoteApi.RemoteUrl, "export:run") &&
|
2023-02-15 22:17:19 +00:00
|
|
|
|
ImGui.BeginTabItem($"{Localization.ConfigTab_Export}###TabExport"))
|
2022-12-21 19:23:48 +00:00
|
|
|
|
{
|
|
|
|
|
string todaysFileName = $"export-{DateTime.Today:yyyy-MM-dd}.pal";
|
|
|
|
|
if (string.IsNullOrEmpty(_saveExportPath) && !string.IsNullOrEmpty(_saveExportDialogStartPath))
|
|
|
|
|
_saveExportPath = Path.Join(_saveExportDialogStartPath, todaysFileName);
|
|
|
|
|
|
2023-02-10 19:48:14 +00:00
|
|
|
|
ImGui.TextWrapped(string.Format(Localization.Config_ExportSource, RemoteApi.RemoteUrl));
|
|
|
|
|
ImGui.Text(Localization.Config_Export_SaveAs);
|
2022-12-21 19:23:48 +00:00
|
|
|
|
ImGui.SameLine();
|
2023-02-11 13:40:22 +00:00
|
|
|
|
ImGui.InputTextWithHint("", Localization.Config_SelectImportFile_Hint, ref _saveExportPath, 260);
|
2022-12-21 19:23:48 +00:00
|
|
|
|
ImGui.SameLine();
|
|
|
|
|
if (ImGuiComponents.IconButton(FontAwesomeIcon.Search))
|
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_importDialog.SaveFileDialog(Localization.Palace_Pal, $"{Localization.Palace_Pal} (*.pal) {{.pal}}",
|
|
|
|
|
todaysFileName, "pal", (success, path) =>
|
2022-12-21 19:23:48 +00:00
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
if (success && !string.IsNullOrEmpty(path))
|
|
|
|
|
{
|
|
|
|
|
_saveExportPath = path;
|
|
|
|
|
}
|
|
|
|
|
}, startPath: _saveExportDialogStartPath, isModal: false);
|
|
|
|
|
_saveExportDialogStartPath =
|
|
|
|
|
null; // only use this once, FileDialogManager will save path between calls
|
2022-12-21 19:23:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui.BeginDisabled(string.IsNullOrEmpty(_saveExportPath) || File.Exists(_saveExportPath));
|
2023-02-10 19:48:14 +00:00
|
|
|
|
if (ImGui.Button(Localization.Config_StartExport))
|
2022-12-22 00:01:09 +00:00
|
|
|
|
DoExport(_saveExportPath);
|
2022-12-21 19:23:48 +00:00
|
|
|
|
ImGui.EndDisabled();
|
|
|
|
|
|
|
|
|
|
ImGui.EndTabItem();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-08 15:06:43 +00:00
|
|
|
|
private void DrawRenderTab(ref bool save, ref bool saveAndClose)
|
|
|
|
|
{
|
2023-02-11 13:40:22 +00:00
|
|
|
|
if (ImGui.BeginTabItem($"{Localization.ConfigTab_Renderer}###TabRenderer"))
|
2023-02-08 15:06:43 +00:00
|
|
|
|
{
|
2023-02-10 19:48:14 +00:00
|
|
|
|
ImGui.Text(Localization.Config_SelectRenderBackend);
|
2023-02-15 22:17:19 +00:00
|
|
|
|
ImGui.RadioButton(
|
|
|
|
|
$"{Localization.Config_Renderer_Splatoon} ({Localization.Config_Renderer_Splatoon_Hint})",
|
|
|
|
|
ref _renderer, (int)ERenderer.Splatoon);
|
|
|
|
|
ImGui.RadioButton($"{Localization.Config_Renderer_Simple} ({Localization.Config_Renderer_Simple_Hint})",
|
|
|
|
|
ref _renderer, (int)ERenderer.Simple);
|
2023-02-08 15:06:43 +00:00
|
|
|
|
|
|
|
|
|
ImGui.Separator();
|
|
|
|
|
|
2023-02-10 19:48:14 +00:00
|
|
|
|
save = ImGui.Button(Localization.Save);
|
2023-02-08 15:06:43 +00:00
|
|
|
|
ImGui.SameLine();
|
2023-02-10 19:48:14 +00:00
|
|
|
|
saveAndClose = ImGui.Button(Localization.SaveAndClose);
|
2023-02-08 15:06:43 +00:00
|
|
|
|
|
|
|
|
|
ImGui.Separator();
|
2023-02-10 19:48:14 +00:00
|
|
|
|
ImGui.Text(Localization.Config_Splatoon_Test);
|
2023-02-15 22:17:19 +00:00
|
|
|
|
ImGui.BeginDisabled(!(_renderAdapter.Implementation is IDrawDebugItems));
|
2023-02-10 19:48:14 +00:00
|
|
|
|
if (ImGui.Button(Localization.Config_Splatoon_DrawCircles))
|
2023-02-16 09:46:19 +00:00
|
|
|
|
(_renderAdapter.Implementation as IDrawDebugItems)?.DrawDebugItems(_trapConfig.Color,
|
|
|
|
|
_hoardConfig.Color);
|
2023-02-08 15:06:43 +00:00
|
|
|
|
ImGui.EndDisabled();
|
|
|
|
|
|
|
|
|
|
ImGui.EndTabItem();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-10 19:53:07 +00:00
|
|
|
|
private void DrawDebugTab()
|
|
|
|
|
{
|
2023-02-11 13:40:22 +00:00
|
|
|
|
if (ImGui.BeginTabItem($"{Localization.ConfigTab_Debug}###TabDebug"))
|
2022-12-10 19:53:07 +00:00
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
if (_territoryState.IsInDeepDungeon())
|
2022-10-23 02:38:58 +00:00
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
ImGui.Text($"You are in a deep dungeon, territory type {_territoryState.LastTerritory}.");
|
|
|
|
|
ImGui.Text($"Sync State = {_territoryState.TerritorySyncState}");
|
|
|
|
|
ImGui.Text($"{_debugState.DebugMessage}");
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.Indent();
|
2023-02-15 22:17:19 +00:00
|
|
|
|
if (_floorService.FloorMarkers.TryGetValue(_territoryState.LastTerritory, out var currentFloor))
|
2022-12-10 19:53:07 +00:00
|
|
|
|
{
|
2023-02-15 01:38:04 +00:00
|
|
|
|
if (_trapConfig.Show)
|
2022-10-23 02:38:58 +00:00
|
|
|
|
{
|
2022-12-10 19:53:07 +00:00
|
|
|
|
int traps = currentFloor.Markers.Count(x => x.Type == Marker.EType.Trap);
|
|
|
|
|
ImGui.Text($"{traps} known trap{(traps == 1 ? "" : "s")}");
|
2022-10-23 02:38:58 +00:00
|
|
|
|
}
|
2023-02-15 22:17:19 +00:00
|
|
|
|
|
2023-02-15 01:38:04 +00:00
|
|
|
|
if (_hoardConfig.Show)
|
2022-12-10 19:53:07 +00:00
|
|
|
|
{
|
|
|
|
|
int hoardCoffers = currentFloor.Markers.Count(x => x.Type == Marker.EType.Hoard);
|
|
|
|
|
ImGui.Text($"{hoardCoffers} known hoard coffer{(hoardCoffers == 1 ? "" : "s")}");
|
|
|
|
|
}
|
2023-02-15 22:17:19 +00:00
|
|
|
|
|
2023-02-15 01:38:04 +00:00
|
|
|
|
if (_silverConfig.Show)
|
2022-12-10 19:53:07 +00:00
|
|
|
|
{
|
2023-02-16 09:46:19 +00:00
|
|
|
|
int silverCoffers =
|
|
|
|
|
_floorService.EphemeralMarkers.Count(x => x.Type == Marker.EType.SilverCoffer);
|
2023-02-15 22:17:19 +00:00
|
|
|
|
ImGui.Text(
|
|
|
|
|
$"{silverCoffers} silver coffer{(silverCoffers == 1 ? "" : "s")} visible on current floor");
|
2022-12-10 19:53:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-15 22:17:19 +00:00
|
|
|
|
ImGui.Text($"Pomander of Sight: {_territoryState.PomanderOfSight}");
|
|
|
|
|
ImGui.Text($"Pomander of Intuition: {_territoryState.PomanderOfIntuition}");
|
2022-10-23 02:38:58 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.Text("Could not query current trap/coffer count.");
|
2023-02-15 22:17:19 +00:00
|
|
|
|
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.Unindent();
|
2023-02-15 22:17:19 +00:00
|
|
|
|
ImGui.TextWrapped(
|
|
|
|
|
"Traps and coffers may not be discovered even after using a pomander if they're far away (around 1,5-2 rooms).");
|
2022-10-23 02:38:58 +00:00
|
|
|
|
}
|
2022-12-10 19:53:07 +00:00
|
|
|
|
else
|
2023-02-10 19:48:14 +00:00
|
|
|
|
ImGui.Text(Localization.Config_Debug_NotInADeepDungeon);
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2022-12-10 19:53:07 +00:00
|
|
|
|
ImGui.EndTabItem();
|
2022-10-23 02:38:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-07 13:50:12 +00:00
|
|
|
|
|
2022-11-25 08:43:24 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// None of the default BeginTabItem methods allow using flags without making the tab have a close button for some reason.
|
|
|
|
|
/// </summary>
|
2023-02-11 20:10:45 +00:00
|
|
|
|
private static unsafe bool BeginTabItemEx(string label, ImGuiTabItemFlags flags)
|
2022-11-25 08:43:24 +00:00
|
|
|
|
{
|
|
|
|
|
int labelLength = Encoding.UTF8.GetByteCount(label);
|
|
|
|
|
byte* labelPtr = stackalloc byte[labelLength + 1];
|
|
|
|
|
byte[] labelBytes = Encoding.UTF8.GetBytes(label);
|
|
|
|
|
|
|
|
|
|
Marshal.Copy(labelBytes, 0, (IntPtr)labelPtr, labelLength);
|
|
|
|
|
labelPtr[labelLength] = 0;
|
|
|
|
|
|
|
|
|
|
return ImGuiNative.igBeginTabItem(labelPtr, null, flags) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void TestConnection()
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
2023-02-11 13:40:22 +00:00
|
|
|
|
_connectionText = Localization.Config_TestConnection_Connecting;
|
2022-11-25 08:43:24 +00:00
|
|
|
|
_switchToCommunityTab = true;
|
|
|
|
|
|
2023-02-13 21:42:24 +00:00
|
|
|
|
_testConnectionCts?.Cancel();
|
|
|
|
|
|
|
|
|
|
CancellationTokenSource cts = new();
|
2022-11-25 08:43:24 +00:00
|
|
|
|
cts.CancelAfter(TimeSpan.FromSeconds(60));
|
2023-02-13 21:42:24 +00:00
|
|
|
|
_testConnectionCts = cts;
|
2022-11-25 08:43:24 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_connectionText = await _remoteApi.VerifyConnection(cts.Token);
|
2022-11-25 08:43:24 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2023-02-13 21:42:24 +00:00
|
|
|
|
if (cts == _testConnectionCts)
|
|
|
|
|
{
|
2023-02-16 23:54:23 +00:00
|
|
|
|
_logger.LogError(e, "Could not establish remote connection");
|
2023-02-13 21:42:24 +00:00
|
|
|
|
_connectionText = e.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
2023-02-16 23:54:23 +00:00
|
|
|
|
_logger.LogWarning(e,
|
2023-02-15 22:17:19 +00:00
|
|
|
|
"Could not establish a remote connection, but user also clicked 'test connection' again so not updating UI");
|
2022-11-25 08:43:24 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-12-21 19:23:48 +00:00
|
|
|
|
|
2023-02-11 20:10:45 +00:00
|
|
|
|
private void DoImport(string sourcePath)
|
2022-12-22 00:01:09 +00:00
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_frameworkService.EarlyEventQueue.Enqueue(new QueuedImport(sourcePath));
|
2022-12-22 00:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-11 20:10:45 +00:00
|
|
|
|
private void UndoImport(Guid importId)
|
2022-12-24 09:27:59 +00:00
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_frameworkService.EarlyEventQueue.Enqueue(new QueuedUndoImport(importId));
|
2022-12-24 09:27:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-16 18:51:54 +00:00
|
|
|
|
internal void UpdateLastImport()
|
|
|
|
|
{
|
2023-02-16 23:54:23 +00:00
|
|
|
|
_lastImportCts?.Cancel();
|
|
|
|
|
CancellationTokenSource cts = new CancellationTokenSource();
|
|
|
|
|
_lastImportCts = cts;
|
|
|
|
|
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
_lastImport = await _importService.FindLast(cts.Token);
|
|
|
|
|
}, cts.Token);
|
2023-02-16 18:51:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-11 20:10:45 +00:00
|
|
|
|
private void DoExport(string destinationPath)
|
2022-12-21 19:23:48 +00:00
|
|
|
|
{
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
(bool success, ExportRoot export) = await _remoteApi.DoExport();
|
2022-12-21 19:23:48 +00:00
|
|
|
|
if (success)
|
|
|
|
|
{
|
2023-02-11 20:10:45 +00:00
|
|
|
|
await using var output = File.Create(destinationPath);
|
2022-12-21 19:23:48 +00:00
|
|
|
|
export.WriteTo(output);
|
|
|
|
|
|
2023-02-17 14:51:45 +00:00
|
|
|
|
_chat.Message($"Export saved as {destinationPath}.");
|
2022-12-21 19:23:48 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-02-17 14:51:45 +00:00
|
|
|
|
_chat.Error("Export failed due to server error.");
|
2022-12-21 19:23:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2023-02-16 23:54:23 +00:00
|
|
|
|
_logger.LogError(e, "Export failed");
|
2023-02-17 14:51:45 +00:00
|
|
|
|
_chat.Error($"Export failed: {e}");
|
2022-12-21 19:23:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-02-15 01:38:04 +00:00
|
|
|
|
|
2023-02-15 22:17:19 +00:00
|
|
|
|
private sealed class ConfigurableMarker
|
2023-02-15 01:38:04 +00:00
|
|
|
|
{
|
|
|
|
|
public bool Show;
|
|
|
|
|
public Vector4 Color;
|
|
|
|
|
public bool OnlyVisibleAfterPomander;
|
|
|
|
|
public bool Fill;
|
|
|
|
|
|
|
|
|
|
public ConfigurableMarker()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ConfigurableMarker(MarkerConfiguration config)
|
|
|
|
|
{
|
|
|
|
|
Show = config.Show;
|
|
|
|
|
Color = ImGui.ColorConvertU32ToFloat4(config.Color);
|
|
|
|
|
OnlyVisibleAfterPomander = config.OnlyVisibleAfterPomander;
|
|
|
|
|
Fill = config.Fill;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MarkerConfiguration Build()
|
|
|
|
|
{
|
|
|
|
|
return new MarkerConfiguration
|
|
|
|
|
{
|
|
|
|
|
Show = Show,
|
|
|
|
|
Color = ImGui.ColorConvertFloat4ToU32(Color),
|
|
|
|
|
OnlyVisibleAfterPomander = OnlyVisibleAfterPomander,
|
|
|
|
|
Fill = Fill
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-23 02:38:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|