forked from aly/qstbak
164 lines
5.3 KiB
C#
164 lines
5.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using Dalamud.Bindings.ImGui;
|
|
using Dalamud.Interface;
|
|
using Dalamud.Interface.Utility;
|
|
using Dalamud.Interface.Utility.Raii;
|
|
using Dalamud.Plugin;
|
|
using Microsoft.Extensions.Logging;
|
|
using Questionable.Windows.Setup;
|
|
|
|
namespace Questionable.Windows;
|
|
|
|
internal sealed class OneTimeSetupWindow : ThemedWindow
|
|
{
|
|
private readonly IReadOnlyList<ISetupStep> _steps;
|
|
|
|
private readonly Configuration _configuration;
|
|
|
|
private readonly IDalamudPluginInterface _pluginInterface;
|
|
|
|
private readonly ILogger<OneTimeSetupWindow> _logger;
|
|
|
|
private int _currentIndex;
|
|
|
|
public OneTimeSetupWindow(WelcomeStep welcomeStep, PluginsStep pluginsStep, EssentialSettingsStep essentialSettingsStep, ReadyStep readyStep, Configuration configuration, IDalamudPluginInterface pluginInterface, ILogger<OneTimeSetupWindow> logger)
|
|
: base("Questionable Setup###QuestionableOneTimeSetup", ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings, forceMainWindow: true)
|
|
{
|
|
_steps = new global::_003C_003Ez__ReadOnlyArray<ISetupStep>(new ISetupStep[4] { welcomeStep, pluginsStep, essentialSettingsStep, readyStep });
|
|
_configuration = configuration;
|
|
_pluginInterface = pluginInterface;
|
|
_logger = logger;
|
|
base.RespectCloseHotkey = false;
|
|
base.ShowCloseButton = false;
|
|
base.AllowPinning = false;
|
|
base.AllowClickthrough = false;
|
|
base.IsOpen = !_configuration.IsPluginSetupComplete();
|
|
_logger.LogDebug("One-time setup needed: {IsOpen}", base.IsOpen);
|
|
}
|
|
|
|
public override void OnOpen()
|
|
{
|
|
_currentIndex = 0;
|
|
}
|
|
|
|
public override void DrawContent()
|
|
{
|
|
List<ISetupStep> list = _steps.Where((ISetupStep s) => s.ShouldShow()).ToList();
|
|
if (list.Count != 0)
|
|
{
|
|
_currentIndex = Math.Clamp(_currentIndex, 0, list.Count - 1);
|
|
ISetupStep setupStep = list[_currentIndex];
|
|
ImU8String text = new ImU8String(9, 2);
|
|
text.AppendLiteral("Step ");
|
|
text.AppendFormatted(_currentIndex + 1);
|
|
text.AppendLiteral(" of ");
|
|
text.AppendFormatted(list.Count);
|
|
ImGui.TextColored(in UiThemeUtils.DimTextColor, text);
|
|
ImGui.SameLine();
|
|
DrawStepDots(list.Count);
|
|
UiThemeUtils.SectionHeader(setupStep.Title);
|
|
var (contentStartPos, availableWidth, drawList) = UiThemeUtils.BeginCard();
|
|
setupStep.Draw();
|
|
UiThemeUtils.EndCard(contentStartPos, availableWidth, drawList);
|
|
UiThemeUtils.SectionSpacing();
|
|
DrawFooter(list.Count, setupStep);
|
|
}
|
|
}
|
|
|
|
private void DrawStepDots(int visibleCount)
|
|
{
|
|
float num = 3f * ImGuiHelpers.GlobalScale;
|
|
float num2 = 12f * ImGuiHelpers.GlobalScale;
|
|
float textLineHeight = ImGui.GetTextLineHeight();
|
|
ImDrawListPtr windowDrawList = ImGui.GetWindowDrawList();
|
|
Vector2 cursorScreenPos = ImGui.GetCursorScreenPos();
|
|
float y = cursorScreenPos.Y + textLineHeight / 2f;
|
|
uint col = ImGui.ColorConvertFloat4ToU32(UiThemeUtils.AccentColor);
|
|
uint col2 = ImGui.ColorConvertFloat4ToU32(UiThemeUtils.MutedTextColor);
|
|
for (int i = 0; i < visibleCount; i++)
|
|
{
|
|
Vector2 center = new Vector2(cursorScreenPos.X + num + (float)i * num2, y);
|
|
if (i == _currentIndex)
|
|
{
|
|
windowDrawList.AddCircleFilled(center, num, col);
|
|
}
|
|
else
|
|
{
|
|
windowDrawList.AddCircle(center, num, col2, 0, 1f);
|
|
}
|
|
}
|
|
ImGui.Dummy(new Vector2(num * 2f + (float)(visibleCount - 1) * num2, textLineHeight));
|
|
}
|
|
|
|
private void DrawFooter(int visibleCount, ISetupStep current)
|
|
{
|
|
bool disabled = _currentIndex == 0;
|
|
bool flag = _currentIndex == visibleCount - 1;
|
|
using (ImRaii.Disabled(disabled))
|
|
{
|
|
if (UiThemeUtils.IconTextButton(FontAwesomeIcon.ArrowLeft, "Back", ButtonWidth(FontAwesomeIcon.ArrowLeft, "Back")))
|
|
{
|
|
_currentIndex--;
|
|
}
|
|
}
|
|
ImGui.SameLine();
|
|
if (flag)
|
|
{
|
|
using (ImRaii.Disabled(!current.CanAdvance))
|
|
{
|
|
using (ImRaii.PushColor(ImGuiCol.Button, UiThemeUtils.PlayButtonColor))
|
|
{
|
|
using (ImRaii.PushColor(ImGuiCol.ButtonHovered, UiThemeUtils.PlayButtonHover))
|
|
{
|
|
using (ImRaii.PushColor(ImGuiCol.ButtonActive, UiThemeUtils.PlayButtonActive))
|
|
{
|
|
using (ImRaii.PushColor(ImGuiCol.Text, UiThemeUtils.PlayButtonText))
|
|
{
|
|
if (UiThemeUtils.IconTextButton(FontAwesomeIcon.Check, "Finish Setup", ButtonWidth(FontAwesomeIcon.Check, "Finish Setup")))
|
|
{
|
|
_logger.LogDebug("Marking setup as complete");
|
|
_configuration.MarkPluginSetupComplete();
|
|
_pluginInterface.SavePluginConfig(_configuration);
|
|
RequestClose();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
using (ImRaii.Disabled(!current.CanAdvance))
|
|
{
|
|
if (UiThemeUtils.IconTextButton(FontAwesomeIcon.ArrowRight, "Next", ButtonWidth(FontAwesomeIcon.ArrowRight, "Next")))
|
|
{
|
|
_currentIndex++;
|
|
}
|
|
}
|
|
}
|
|
ImGui.SameLine();
|
|
string text = (_configuration.IsPluginSetupComplete() ? "Close" : "Close window & don't enable Questionable");
|
|
if (UiThemeUtils.IconTextButton(FontAwesomeIcon.Times, text, ButtonWidth(FontAwesomeIcon.Times, text)))
|
|
{
|
|
if (!_configuration.IsPluginSetupComplete())
|
|
{
|
|
_logger.LogWarning("Closing window without completing setup");
|
|
}
|
|
RequestClose();
|
|
}
|
|
static float ButtonWidth(FontAwesomeIcon icon, string text2)
|
|
{
|
|
float x;
|
|
using (ImRaii.PushFont(UiBuilder.IconFont))
|
|
{
|
|
x = ImGui.CalcTextSize(icon.ToIconString()).X;
|
|
}
|
|
float x2 = ImGui.CalcTextSize(text2).X;
|
|
return x + 6f + x2 + ImGui.GetStyle().FramePadding.X * 2f;
|
|
}
|
|
}
|
|
}
|