From 2460a248f58c3c778adc9cb7a9355d06b712569f Mon Sep 17 00:00:00 2001 From: hunter2actual Date: Wed, 10 Jul 2024 00:29:48 +0100 Subject: [PATCH] 1.2.0.0 - Update for FFXIV 7.0 Dawntrail --- .../DalamudMinesweeper.Tests.csproj | 14 +++-- DalamudMinesweeper.json | 8 +-- DalamudMinesweeper/Configuration.cs | 6 +-- DalamudMinesweeper/DalamudMinesweeper.csproj | 4 +- DalamudMinesweeper/Plugin.cs | 34 +++++++------ DalamudMinesweeper/Sprites/NumberSprites.cs | 49 +++++++++--------- DalamudMinesweeper/Sprites/TileSprites.cs | 51 +++++++++---------- DalamudMinesweeper/Windows/MainWindow.cs | 15 +++--- DalamudMinesweeper/packages.lock.json | 6 +-- README.md | 3 +- 10 files changed, 94 insertions(+), 96 deletions(-) diff --git a/DalamudMinesweeper.Tests/DalamudMinesweeper.Tests.csproj b/DalamudMinesweeper.Tests/DalamudMinesweeper.Tests.csproj index 3135626..c8a95cb 100644 --- a/DalamudMinesweeper.Tests/DalamudMinesweeper.Tests.csproj +++ b/DalamudMinesweeper.Tests/DalamudMinesweeper.Tests.csproj @@ -11,10 +11,16 @@ - - - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/DalamudMinesweeper.json b/DalamudMinesweeper.json index feb2538..359c3f7 100644 --- a/DalamudMinesweeper.json +++ b/DalamudMinesweeper.json @@ -3,7 +3,7 @@ "Author": "hunter2_", "Name": "Minesweeper", "InternalName": "DalamudMinesweeper", - "AssemblyVersion": "1.1.0.4", + "AssemblyVersion": "1.2.0.0", "Description": "Logic puzzle in which you find and flag hidden mines.\n\nLeft click to uncover a square, right click to place a flag.\nThe game ends when all mines are flagged and all safe squares have been uncovered.\nClick the smiley face to start a new game.", "ApplicableVersion": "any", "Tags": [ @@ -18,9 +18,9 @@ "LoadPriority": 0, "Punchline": "Classic puzzle game.", "AcceptsFeedback": true, - "DownloadLinkInstall": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.1.0.4/latest.zip", - "DownloadLinkUpdate": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.1.0.4/latest.zip", + "DownloadLinkInstall": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.2.0.0/latest.zip", + "DownloadLinkUpdate": "https://github.com/hunter2actual/DalamudMinesweeper/releases/download/1.2.0.0/latest.zip", "IconUrl": "https://raw.githubusercontent.com/hunter2actual/DalamudMinesweeper/master/images/icon.png", - "Changelog": "Add expert mode" + "Changelog": "Update for FFXIV 7.0" } ] \ No newline at end of file diff --git a/DalamudMinesweeper/Configuration.cs b/DalamudMinesweeper/Configuration.cs index 3b3c9ce..7c6dd88 100644 --- a/DalamudMinesweeper/Configuration.cs +++ b/DalamudMinesweeper/Configuration.cs @@ -18,14 +18,12 @@ public class Configuration : IPluginConfiguration public int NoGuessTimeoutMs { get; set; } = 1500; public bool RevealShortcut { get; set; } = false; public bool FlagShortcut { get; set; } = false; - public Scores Scores { get; set; } = new Scores([]); - // the below exist just to make saving less cumbersome [NonSerialized] - private DalamudPluginInterface? _pluginInterface; + private IDalamudPluginInterface? _pluginInterface; - public void Initialize(DalamudPluginInterface pluginInterface) + public void Initialize(IDalamudPluginInterface pluginInterface) { _pluginInterface = pluginInterface; } diff --git a/DalamudMinesweeper/DalamudMinesweeper.csproj b/DalamudMinesweeper/DalamudMinesweeper.csproj index 6a8a335..6408727 100644 --- a/DalamudMinesweeper/DalamudMinesweeper.csproj +++ b/DalamudMinesweeper/DalamudMinesweeper.csproj @@ -1,9 +1,9 @@ - + - 1.1.0.4 + 1.2.0.0 A logic puzzle featuring hidden mines. https://github.com/hunter2actual/DalamudMinesweeper AGPL-3.0-or-later diff --git a/DalamudMinesweeper/Plugin.cs b/DalamudMinesweeper/Plugin.cs index 704326f..52c9b1b 100644 --- a/DalamudMinesweeper/Plugin.cs +++ b/DalamudMinesweeper/Plugin.cs @@ -1,50 +1,54 @@ using Dalamud.Game.Command; -using Dalamud.IoC; using Dalamud.Plugin; using Dalamud.Interface.Windowing; using Dalamud.Plugin.Services; using DalamudMinesweeper.Windows; +using Dalamud.IoC; namespace DalamudMinesweeper; +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. +public sealed class Service +{ + [PluginService] public static IDalamudPluginInterface PluginInterface { get; set; } + [PluginService] public static ITextureProvider TextureProvider { get; set; } + [PluginService] public static ICommandManager CommandManager { get; set; } +} + public sealed class Plugin : IDalamudPlugin { private const string CommandName = "/minesweeper"; - public DalamudPluginInterface PluginInterface { get; init; } public Configuration Configuration { get; init; } public WindowSystem WindowSystem = new("Minesweeper"); private ConfigWindow _configWindow { get; init; } private ScoresWindow _scoresWindow { get; init; } private MainWindow _mainWindow { get; init; } - private ICommandManager _commandManager { get; init; } public Plugin( - [RequiredVersion("1.0")] DalamudPluginInterface pluginInterface, - [RequiredVersion("1.0")] ICommandManager commandManager) + IDalamudPluginInterface pluginInterface) { - PluginInterface = pluginInterface; - _commandManager = commandManager; + pluginInterface.Create(); - Configuration = PluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); - Configuration.Initialize(PluginInterface); + Configuration = pluginInterface.GetPluginConfig() as Configuration ?? new Configuration(); + Configuration.Initialize(pluginInterface); _configWindow = new ConfigWindow(this); _scoresWindow = new ScoresWindow(this); - _mainWindow = new MainWindow(this, Configuration); + _mainWindow = new MainWindow(this, Configuration, Service.TextureProvider); WindowSystem.AddWindow(_configWindow); WindowSystem.AddWindow(_scoresWindow); WindowSystem.AddWindow(_mainWindow); - _commandManager.AddHandler(CommandName, new CommandInfo(OnCommand) + Service.CommandManager.AddHandler(CommandName, new CommandInfo(OnCommand) { HelpMessage = "Open the Minesweeper window" }); - PluginInterface.UiBuilder.Draw += DrawUI; - PluginInterface.UiBuilder.OpenMainUi += DrawMainUI; - PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI; + pluginInterface.UiBuilder.Draw += DrawUI; + pluginInterface.UiBuilder.OpenMainUi += DrawMainUI; + pluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI; } public void Dispose() @@ -54,7 +58,7 @@ public void Dispose() _configWindow.Dispose(); _mainWindow.Dispose(); - _commandManager.RemoveHandler(CommandName); + Service.CommandManager.RemoveHandler(CommandName); } private void OnCommand(string command, string args) diff --git a/DalamudMinesweeper/Sprites/NumberSprites.cs b/DalamudMinesweeper/Sprites/NumberSprites.cs index 4f4687e..3b74ee7 100644 --- a/DalamudMinesweeper/Sprites/NumberSprites.cs +++ b/DalamudMinesweeper/Sprites/NumberSprites.cs @@ -1,33 +1,25 @@ using Dalamud.Plugin; -using Dalamud.Interface.Internal; using System.IO; -using System; using ImGuiNET; using System.Numerics; using System.Collections.Generic; +using Dalamud.Interface.Textures; +using System; namespace DalamudMinesweeper.Sprites; -public class NumberSprites : IDisposable +public class NumberSprites { - private DalamudPluginInterface _pluginInterface { get; set; } - private IDalamudTextureWrap[] Sheets { get; init; } + private IDalamudPluginInterface _pluginInterface { get; set; } + private ISharedImmediateTexture[] Sheets { get; set; } = Array.Empty(); private record SpriteData(Vector2 topLeftCoord, Vector2 sizePx); private readonly Dictionary _spriteDict; + private bool _loaded = false; - public NumberSprites(DalamudPluginInterface pluginInterface) + public NumberSprites(IDalamudPluginInterface pluginInterface) { _pluginInterface = pluginInterface; - Sheets = - [ - LoadImage("numbers_1x.png"), - LoadImage("numbers_2x.png"), - LoadImage("numbers_3x.png"), - LoadImage("numbers_4x.png"), - LoadImage("numbers_5x.png"), - ]; - var numberSpriteSize = new Vector2(13, 23); _spriteDict = new Dictionary @@ -54,7 +46,20 @@ public void DrawNumber(ImDrawListPtr drawList, char digit, Vector2 cursorPos, in private void Draw(ImDrawListPtr drawList, SpriteData sprite, Vector2 cursorPos, int zoom) { - var sheet = Sheets[zoom - 1]; + if (!_loaded) + { + Sheets = + [ + LoadImage("numbers_1x.png"), + LoadImage("numbers_2x.png"), + LoadImage("numbers_3x.png"), + LoadImage("numbers_4x.png"), + LoadImage("numbers_5x.png"), + ]; + _loaded = true; + } + + var sheet = Sheets[zoom - 1].GetWrapOrDefault(); var uvMin = sprite.topLeftCoord * zoom / sheet.Size; var uvMax = (sprite.topLeftCoord + sprite.sizePx) * zoom / sheet.Size; @@ -67,17 +72,9 @@ private void Draw(ImDrawListPtr drawList, SpriteData sprite, Vector2 cursorPos, uvMax); } - public void Dispose() - { - foreach (var sheet in Sheets) - { - sheet.Dispose(); - } - } - - private IDalamudTextureWrap LoadImage(string path) + private ISharedImmediateTexture LoadImage(string path) { var fullPath = Path.Combine(_pluginInterface.AssemblyLocation.Directory?.FullName!, path); - return _pluginInterface.UiBuilder.LoadImage(fullPath); + return Service.TextureProvider.GetFromFile(fullPath); } } \ No newline at end of file diff --git a/DalamudMinesweeper/Sprites/TileSprites.cs b/DalamudMinesweeper/Sprites/TileSprites.cs index ce49127..42712e1 100644 --- a/DalamudMinesweeper/Sprites/TileSprites.cs +++ b/DalamudMinesweeper/Sprites/TileSprites.cs @@ -1,33 +1,25 @@ using Dalamud.Plugin; -using Dalamud.Interface.Internal; using System.IO; -using System; using ImGuiNET; using System.Numerics; using System.Collections.Generic; using DalamudMinesweeper.Game; +using Dalamud.Interface.Textures; +using System; namespace DalamudMinesweeper.Sprites; -public class TileSprites : IDisposable +public class TileSprites { - private DalamudPluginInterface _pluginInterface { get; set; } - private IDalamudTextureWrap[] Sheets { get; init; } + private IDalamudPluginInterface _pluginInterface { get; set; } + private ISharedImmediateTexture[] Sheets { get; set; } = Array.Empty(); private record SpriteData(Vector2 topLeftCoord, Vector2 sizePx); private readonly Dictionary _spriteDict; + private bool _loaded = false; - public TileSprites(DalamudPluginInterface pluginInterface) + public TileSprites(IDalamudPluginInterface pluginInterface) { - _pluginInterface = pluginInterface; - - Sheets = - [ - LoadImage("spritesheet_1x.png"), - LoadImage("spritesheet_2x.png"), - LoadImage("spritesheet_3x.png"), - LoadImage("spritesheet_4x.png"), - LoadImage("spritesheet_5x.png"), - ]; + _pluginInterface = pluginInterface; _spriteDict = new Dictionary { @@ -63,7 +55,20 @@ public void DrawSmiley(ImDrawListPtr drawList, string smileyName, Vector2 cursor private void Draw(ImDrawListPtr drawList, SpriteData sprite, Vector2 cursorPos, int zoom) { - var sheet = Sheets[zoom - 1]; + if (!_loaded) + { + Sheets = + [ + LoadImage("spritesheet_1x.png"), + LoadImage("spritesheet_2x.png"), + LoadImage("spritesheet_3x.png"), + LoadImage("spritesheet_4x.png"), + LoadImage("spritesheet_5x.png"), + ]; + _loaded = true; + } + + var sheet = Sheets[zoom - 1].GetWrapOrDefault(); var uvMin = sprite.topLeftCoord * zoom / sheet.Size; var uvMax = (sprite.topLeftCoord + sprite.sizePx) * zoom / sheet.Size; @@ -99,17 +104,9 @@ private static string CellToSpriteName(Cell cell) }; } - public void Dispose() - { - foreach (var sheet in Sheets) - { - sheet.Dispose(); - } - } - - private IDalamudTextureWrap LoadImage(string path) + private ISharedImmediateTexture LoadImage(string path) { var fullPath = Path.Combine(_pluginInterface.AssemblyLocation.Directory?.FullName!, path); - return _pluginInterface.UiBuilder.LoadImage(fullPath); + return Service.TextureProvider.GetFromFile(fullPath); } } \ No newline at end of file diff --git a/DalamudMinesweeper/Windows/MainWindow.cs b/DalamudMinesweeper/Windows/MainWindow.cs index f5e8a76..6888ec4 100644 --- a/DalamudMinesweeper/Windows/MainWindow.cs +++ b/DalamudMinesweeper/Windows/MainWindow.cs @@ -6,6 +6,7 @@ using DalamudMinesweeper.Sweepers; using DalamudMinesweeper.Sprites; using ImGuiNET; +using Dalamud.Plugin.Services; namespace DalamudMinesweeper.Windows; @@ -35,7 +36,7 @@ public class MainWindow : Window, IDisposable private Footer _footer; private Background _background; - public MainWindow(Plugin plugin, Configuration configuration) : base("Minesweeper", + public MainWindow(Plugin plugin, Configuration configuration, ITextureProvider textureProvider) : base("Minesweeper", ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse | ImGuiWindowFlags.NoResize @@ -48,8 +49,8 @@ public MainWindow(Plugin plugin, Configuration configuration) : base("Minesweepe }; _configuration = configuration; - _tileSprites = new TileSprites(plugin.PluginInterface); - _numberSprites = new NumberSprites(plugin.PluginInterface); + _tileSprites = new TileSprites(Service.PluginInterface); + _numberSprites = new NumberSprites(Service.PluginInterface); _gridSquareSizePxVec2 = new Vector2(0, 0); _sweeper = new Sweeper(); @@ -60,12 +61,6 @@ public MainWindow(Plugin plugin, Configuration configuration) : base("Minesweepe _background = new Background(_game, _configuration, _borderWidthPx); } - public void Dispose() - { - _tileSprites.Dispose(); - _numberSprites.Dispose(); - } - public override void Draw() { // Calculate element sizes @@ -154,4 +149,6 @@ private void RecordScore() _canSaveScore = false; } } + + public void Dispose() { } } diff --git a/DalamudMinesweeper/packages.lock.json b/DalamudMinesweeper/packages.lock.json index 8ca7ea5..19fcea9 100644 --- a/DalamudMinesweeper/packages.lock.json +++ b/DalamudMinesweeper/packages.lock.json @@ -4,9 +4,9 @@ "net8.0-windows7.0": { "DalamudPackager": { "type": "Direct", - "requested": "[2.1.12, )", - "resolved": "2.1.12", - "contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg==" + "requested": "[2.1.13, )", + "resolved": "2.1.13", + "contentHash": "rMN1omGe8536f4xLMvx9NwfvpAc9YFFfeXJ1t4P4PE6Gu8WCIoFliR1sh07hM+bfODmesk/dvMbji7vNI+B/pQ==" } } } diff --git a/README.md b/README.md index fc893e8..b27ac86 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # DalamudMinesweeper -Dalamud plugin for FFXIV, now available in the main Dalamud repository! -For dev builds, install by adding `https://raw.githubusercontent.com/hunter2actual/DalamudMinesweeper/master/DalamudMinesweeper.json` to your plugin sources. +Dalamud plugin for FFXIV. How to play: - Left click to uncover a square, right click to place a flag.