Add window that opens on login

This commit is contained in:
NotNite 2023-03-19 13:54:38 -04:00
parent 88a665cb58
commit c60bb99e77
No known key found for this signature in database
GPG key ID: BD91A5402CCEB08A
5 changed files with 541 additions and 200 deletions

View file

@ -371,6 +371,8 @@ internal sealed class DalamudConfiguration : IServiceType
/// </summary>
public double UiBuilderHitch { get; set; } = 100;
public bool HasSeenFools23 { get; set; } = false;
/// <summary>
/// Load a configuration from the provided path.
/// </summary>

View file

@ -2,8 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Dalamud.Configuration.Internal;
using Dalamud.Fools.Plugins;
using Dalamud.Game.ClientState;
using Dalamud.Interface;
using Dalamud.Interface.Internal;
using Dalamud.Logging.Internal;
namespace Dalamud.Fools;
@ -58,22 +61,28 @@ internal class FoolsManager : IDisposable, IServiceType
private static readonly ModuleLog Log = new("FOOLS");
private UiBuilder uiBuilder;
private ClientState clientState;
[ServiceManager.ServiceConstructor]
private FoolsManager()
{
this.uiBuilder = new UiBuilder("fools");
this.uiBuilder.Draw += this.DrawUI;
this.uiBuilder.Draw += this.DrawUi;
this.clientState = Service<ClientState>.Get();
this.clientState.Login += this.ClientStateOnLogin;
// reflect over all IFoolsPlugin implementations sometime(?)
this.FoolsPlugins = new List<FoolsPluginMetadata>
{
new("Pixel Imperfect", "PixelImperfectPlugin", "Whoops... we messed up the math on that one.", "Halpo",
typeof(PixelImperfectPlugin)),
new("DailyLifeDuty", "DailyLifeDutyPlugin", "Easily Track Daily and Weekly tasks... in real life", "MidoriKami", typeof(DailyLifeDutyPlugin)),
new("DailyLifeDuty", "DailyLifeDutyPlugin", "Easily Track Daily and Weekly tasks... in real life",
"MidoriKami", typeof(DailyLifeDutyPlugin)),
};
}
public void ActivatePlugin(string plugin)
{
if (this.ActivatedPlugins.ContainsKey(plugin))
@ -101,8 +110,8 @@ internal class FoolsManager : IDisposable, IServiceType
}
this.ActivatedPlugins.Clear();
((IDisposable)this.uiBuilder).Dispose();
this.clientState.Login -= this.ClientStateOnLogin;
}
public bool IsPluginActivated(string plugin)
@ -123,11 +132,34 @@ internal class FoolsManager : IDisposable, IServiceType
this.ActivatedPlugins.Remove(plugin);
}
private void DrawUI()
private void DrawUi()
{
foreach (var plugin in this.ActivatedPlugins.Values)
{
plugin.DrawUi();
}
}
private void ClientStateOnLogin(object? o, EventArgs e)
{
var dalamudConfig = Service<DalamudConfiguration>.Get();
#if !DEBUG
if (DateTime.Now is not { Month: 4, Day: 1 })
{
return;
}
#endif
if (dalamudConfig.HasSeenFools23)
{
return;
}
var di = Service<DalamudInterface>.Get();
di.OpenFoolsWindow();
dalamudConfig.HasSeenFools23 = true;
dalamudConfig.QueueSave();
}
}

View file

@ -0,0 +1,61 @@
using System;
using System.IO;
using System.Numerics;
using Dalamud.Interface;
using Dalamud.Interface.Internal;
using Dalamud.Interface.Windowing;
using ImGuiNET;
using ImGuiScene;
namespace Dalamud.Fools;
// Stolen from ChangelogWindow
public class FoolsWindow : Window, IDisposable {
private readonly TextureWrap logoTexture;
public FoolsWindow()
: base("Introducing Alternate Reality Dalamud", ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoResize)
{
this.Namespace = "FoolsWindow";
this.Size = new Vector2(885, 463);
this.SizeCondition = ImGuiCond.Appearing;
var interfaceManager = Service<InterfaceManager>.Get();
var dalamud = Service<Dalamud>.Get();
this.logoTexture =
interfaceManager.LoadImage(Path.Combine(dalamud.AssetDirectory.FullName, "UIRes", "logo.png"))!;
}
public override void Draw()
{
var imgCursor = ImGui.GetCursorPos();
ImGui.TextWrapped(@"
A team of scientists and plugin developers have collaborated to create a new
version of Dalamud that includes plugins from other realities.
With our high tech systems, the plugin installer will now offer new, unique
plugins with endless possibilities. Open the ""Alternate Reality"" tab in the
plugin installer to see what's available.
We hope you enjoy this new version of Dalamud, and we look forward to your feedback.
".Trim());
if (ImGui.Button("Open the plugin installer"))
{
var di = Service<DalamudInterface>.Get();
di.OpenPluginInstallerFools();
}
imgCursor.X += 500;
ImGui.SetCursorPos(imgCursor);
ImGui.Image(this.logoTexture.ImGuiHandle, new Vector2(100));
}
public void Dispose()
{
this.logoTexture.Dispose();
}
}

View file

@ -9,6 +9,7 @@ using System.Runtime.InteropServices;
using CheapLoc;
using Dalamud.Configuration.Internal;
using Dalamud.Fools;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.Gui;
using Dalamud.Game.Internal;
@ -62,6 +63,7 @@ internal class DalamudInterface : IDisposable, IServiceType
private readonly ProfilerWindow profilerWindow;
private readonly BranchSwitcherWindow branchSwitcherWindow;
private readonly HitchSettingsWindow hitchSettingsWindow;
private readonly FoolsWindow foolsWindow;
private readonly TextureWrap logoTexture;
private readonly TextureWrap tsmLogoTexture;
@ -110,6 +112,7 @@ internal class DalamudInterface : IDisposable, IServiceType
this.profilerWindow = new ProfilerWindow() { IsOpen = false };
this.branchSwitcherWindow = new BranchSwitcherWindow() { IsOpen = false };
this.hitchSettingsWindow = new HitchSettingsWindow() { IsOpen = false };
this.foolsWindow = new FoolsWindow() { IsOpen = false };
this.WindowSystem.AddWindow(this.changelogWindow);
this.WindowSystem.AddWindow(this.colorDemoWindow);
@ -127,6 +130,7 @@ internal class DalamudInterface : IDisposable, IServiceType
this.WindowSystem.AddWindow(this.profilerWindow);
this.WindowSystem.AddWindow(this.branchSwitcherWindow);
this.WindowSystem.AddWindow(this.hitchSettingsWindow);
this.WindowSystem.AddWindow(this.foolsWindow);
ImGuiManagedAsserts.AssertsEnabled = configuration.AssertsEnabledAtStartup;
this.isImGuiDrawDevMenu = this.isImGuiDrawDevMenu || configuration.DevBarOpenAtStartup;
@ -338,6 +342,18 @@ internal class DalamudInterface : IDisposable, IServiceType
this.branchSwitcherWindow.BringToFront();
}
public void OpenFoolsWindow()
{
this.foolsWindow.IsOpen = true;
this.foolsWindow.BringToFront();
}
public void OpenPluginInstallerFools()
{
this.pluginWindow.OpenFools();
this.pluginWindow.BringToFront();
}
#endregion
#region Close