From 934faa70d36f8e2876c0b9210977ddb94678f525 Mon Sep 17 00:00:00 2001 From: Aptivi Date: Wed, 8 Jan 2025 11:52:42 +0300 Subject: [PATCH] imp - Made an addon for icons --- This addon is not ready yet, because Terminaux 6.1.0, which holds necessary changes, is not released yet. As a result, the build will fail. --- Type: imp Breaking: False Doc Required: False Backport Required: False Part: 1/2 --- Nitrocid.sln | 8 +++ .../Resources/KnownAddons.json | 5 ++ .../Nitrocid.Extras.Images.Icons/IconsInit.cs | 40 +++++++++++ .../Nitrocid.Extras.Images.Icons.csproj | 36 ++++++++++ .../Tools/IconsTools.cs | 66 +++++++++++++++++++ .../Instances/KernelWidgetsConfig.cs | 12 +++- .../KeyInputs/IconSettingsKeyInput.cs | 16 ++++- public/Nitrocid/Properties/AssemblyInfo.cs | 1 + .../Login/Widgets/Implementations/Emoji.cs | 27 +++++++- 9 files changed, 205 insertions(+), 6 deletions(-) create mode 100644 public/Nitrocid.Addons/Nitrocid.Extras.Images.Icons/IconsInit.cs create mode 100644 public/Nitrocid.Addons/Nitrocid.Extras.Images.Icons/Nitrocid.Extras.Images.Icons.csproj create mode 100644 public/Nitrocid.Addons/Nitrocid.Extras.Images.Icons/Tools/IconsTools.cs diff --git a/Nitrocid.sln b/Nitrocid.sln index aae25d04e..1d8fc690d 100644 --- a/Nitrocid.sln +++ b/Nitrocid.sln @@ -16,6 +16,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nitrocid.Tests", "private\N {239472BF-B9F5-49FD-9E9F-9F5A034C8337} = {239472BF-B9F5-49FD-9E9F-9F5A034C8337} {2D768D78-7BBF-43CE-823D-081881BA941E} = {2D768D78-7BBF-43CE-823D-081881BA941E} {3495603B-2389-410C-899C-F69EFDD17EE1} = {3495603B-2389-410C-899C-F69EFDD17EE1} + {38D7F3AD-EA2F-49D3-87A6-1E4A362547D0} = {38D7F3AD-EA2F-49D3-87A6-1E4A362547D0} {46CC2699-A9BB-4748-B1FF-ABD4C501DAA1} = {46CC2699-A9BB-4748-B1FF-ABD4C501DAA1} {47239E70-B4A0-4127-A6E9-0749EED2B3BB} = {47239E70-B4A0-4127-A6E9-0749EED2B3BB} {47BECAD8-5DB2-4DE1-B0F0-3225E3396AF7} = {47BECAD8-5DB2-4DE1-B0F0-3225E3396AF7} @@ -211,6 +212,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Reserved", "Reserved", "{DA EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nitrocid.Locales", "public\Nitrocid.Locales\Nitrocid.Locales.csproj", "{38B58904-50C4-4E0D-A8E7-FD8766D7923C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nitrocid.Extras.Images.Icons", "public\Nitrocid.Addons\Nitrocid.Extras.Images.Icons\Nitrocid.Extras.Images.Icons.csproj", "{38D7F3AD-EA2F-49D3-87A6-1E4A362547D0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -465,6 +468,10 @@ Global {38B58904-50C4-4E0D-A8E7-FD8766D7923C}.Debug|Any CPU.Build.0 = Debug|Any CPU {38B58904-50C4-4E0D-A8E7-FD8766D7923C}.Release|Any CPU.ActiveCfg = Release|Any CPU {38B58904-50C4-4E0D-A8E7-FD8766D7923C}.Release|Any CPU.Build.0 = Release|Any CPU + {38D7F3AD-EA2F-49D3-87A6-1E4A362547D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {38D7F3AD-EA2F-49D3-87A6-1E4A362547D0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {38D7F3AD-EA2F-49D3-87A6-1E4A362547D0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {38D7F3AD-EA2F-49D3-87A6-1E4A362547D0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -542,6 +549,7 @@ Global {2617CFBB-4AF9-48DB-B2A7-7BEAF8575011} = {DA50500B-3F8A-4817-842B-40C957416C2C} {DA50500B-3F8A-4817-842B-40C957416C2C} = {A32F9CED-BCDB-48A7-A42D-E98E33BD6E65} {38B58904-50C4-4E0D-A8E7-FD8766D7923C} = {804E124D-5B66-4F40-BB98-776CD386E618} + {38D7F3AD-EA2F-49D3-87A6-1E4A362547D0} = {B60F276A-FE12-4001-916E-080344ED1FD9} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {424D8E7A-CFEB-40AE-A79C-437D603177FD} diff --git a/private/Nitrocid.Generators/Nitrocid.Generators.KnownAddons/Resources/KnownAddons.json b/private/Nitrocid.Generators/Nitrocid.Generators.KnownAddons/Resources/KnownAddons.json index 9fcf6a5b0..ef285099c 100644 --- a/private/Nitrocid.Generators/Nitrocid.Generators.KnownAddons/Resources/KnownAddons.json +++ b/private/Nitrocid.Generators/Nitrocid.Generators.KnownAddons/Resources/KnownAddons.json @@ -238,5 +238,10 @@ "name": "ExtrasMods", "display": "Extras - Mods", "project": "Extras.Mods" + }, + { + "name": "ExtrasImagesIcons", + "display": "Extras - Icons", + "project": "Extras.Images.Icons" } ] diff --git a/public/Nitrocid.Addons/Nitrocid.Extras.Images.Icons/IconsInit.cs b/public/Nitrocid.Addons/Nitrocid.Extras.Images.Icons/IconsInit.cs new file mode 100644 index 000000000..6527caa70 --- /dev/null +++ b/public/Nitrocid.Addons/Nitrocid.Extras.Images.Icons/IconsInit.cs @@ -0,0 +1,40 @@ +// +// Nitrocid KS Copyright (C) 2018-2025 Aptivi +// +// This file is part of Nitrocid KS +// +// Nitrocid KS is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nitrocid KS is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using Nitrocid.Kernel.Extensions; + +namespace Nitrocid.Extras.Images.Icons +{ + internal class IconsInit : IAddon + { + string IAddon.AddonName => + InterAddonTranslations.GetAddonName(KnownAddons.ExtrasImagesIcons); + + ModLoadPriority IAddon.AddonType => ModLoadPriority.Optional; + + void IAddon.FinalizeAddon() + { } + + void IAddon.StartAddon() + { } + + void IAddon.StopAddon() + { } + } +} diff --git a/public/Nitrocid.Addons/Nitrocid.Extras.Images.Icons/Nitrocid.Extras.Images.Icons.csproj b/public/Nitrocid.Addons/Nitrocid.Extras.Images.Icons/Nitrocid.Extras.Images.Icons.csproj new file mode 100644 index 000000000..824f7e158 --- /dev/null +++ b/public/Nitrocid.Addons/Nitrocid.Extras.Images.Icons/Nitrocid.Extras.Images.Icons.csproj @@ -0,0 +1,36 @@ + + + + + Debug + AnyCPU + AnyCPU + true + true + false + ..\..\Nitrocid\KSBuild\$(TargetFramework)\Addons\Extras.Images.Icons + Nitrocid KS Extras - Icons + Nitrocid KS Extras - Icons + True + + + + + + true + + + false + true + + + + + + + + + + + + diff --git a/public/Nitrocid.Addons/Nitrocid.Extras.Images.Icons/Tools/IconsTools.cs b/public/Nitrocid.Addons/Nitrocid.Extras.Images.Icons/Tools/IconsTools.cs new file mode 100644 index 000000000..fd609b6b4 --- /dev/null +++ b/public/Nitrocid.Addons/Nitrocid.Extras.Images.Icons/Tools/IconsTools.cs @@ -0,0 +1,66 @@ +// +// Nitrocid KS Copyright (C) 2018-2025 Aptivi +// +// This file is part of Nitrocid KS +// +// Nitrocid KS is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Nitrocid KS is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System.Linq; +using Terminaux.Images.Icons; +using Terminaux.Writer.ConsoleWriters; + +namespace Nitrocid.Extras.Images.Icons.Tools +{ + /// + /// Tools for the icons + /// + public static class IconsTools + { + /// + /// Gets the icon names + /// + /// An array of all icon names + public static string[] GetIconNames() => + IconsManager.GetIconNames(); + + /// + /// Checks an icon + /// + /// Icon name + /// True if this icon is found; false otherwise. + public static bool HasIcon(string iconName) => + GetIconNames().Contains(iconName); + + /// + /// Renders the icon to a string that you can print to the console + /// + /// Icon name + /// Width of the resulting icon + /// Height of the resulting icon + /// Zero-based console left position to start writing the icon to + /// Zero-based console top position to start writing the icon to + /// A string that contains the resulting pixels that you can print to the console using the function + public static string RenderIcon(string iconName, int width, int height, int left, int top) => + IconsManager.RenderIcon(iconName, width, height, left, top); + + /// + /// Prompts the user for an icon + /// + /// Initial icon to use + /// Selected icon + public static string PromptForIcons(string initialIcon) => + IconsSelector.PromptForIcons(initialIcon); + } +} diff --git a/public/Nitrocid/Kernel/Configuration/Instances/KernelWidgetsConfig.cs b/public/Nitrocid/Kernel/Configuration/Instances/KernelWidgetsConfig.cs index 6a9e8cccc..599fa1d89 100644 --- a/public/Nitrocid/Kernel/Configuration/Instances/KernelWidgetsConfig.cs +++ b/public/Nitrocid/Kernel/Configuration/Instances/KernelWidgetsConfig.cs @@ -20,6 +20,7 @@ using Newtonsoft.Json; using Nitrocid.Kernel.Configuration.Settings; using Nitrocid.Kernel.Exceptions; +using Nitrocid.Kernel.Extensions; using Nitrocid.Languages; using Nitrocid.Misc.Reflection.Internal; using System.Linq; @@ -442,7 +443,7 @@ public int DigitalMaximumColorLevel } #endregion - #region + #region Emoji private string emojiWidgetCurrentEmoticon = "gem-stone"; /// @@ -455,7 +456,14 @@ public int DigitalMaximumColorLevel public string EmojiWidgetEmoticonName { get => emojiWidgetCurrentEmoticon; - set => emojiWidgetCurrentEmoticon = IconsManager.GetIconNames().Contains(value) ? value : emojiWidgetCurrentEmoticon; + set + { + if (AddonTools.GetAddon(InterAddonTranslations.GetAddonName(KnownAddons.ExtrasImagesIcons)) is null) + emojiWidgetCurrentEmoticon = value; + var type = InterAddonTools.GetTypeFromAddon(KnownAddons.ExtrasImagesIcons, "Nitrocid.Extras.Images.Icons.Tools.IconsTools"); + var hasIcon = (bool?)InterAddonTools.ExecuteCustomAddonFunction(KnownAddons.ExtrasImagesIcons, "HasIcon", type, value) ?? false; + emojiWidgetCurrentEmoticon = hasIcon ? value : emojiWidgetCurrentEmoticon; + } } #endregion } diff --git a/public/Nitrocid/Kernel/Configuration/Settings/KeyInputs/IconSettingsKeyInput.cs b/public/Nitrocid/Kernel/Configuration/Settings/KeyInputs/IconSettingsKeyInput.cs index ba9bd2263..37ca53ba4 100644 --- a/public/Nitrocid/Kernel/Configuration/Settings/KeyInputs/IconSettingsKeyInput.cs +++ b/public/Nitrocid/Kernel/Configuration/Settings/KeyInputs/IconSettingsKeyInput.cs @@ -18,7 +18,9 @@ // using Nitrocid.Kernel.Configuration.Instances; -using Terminaux.Images.Icons; +using Nitrocid.Kernel.Extensions; +using Nitrocid.Languages; +using Terminaux.Inputs.Styles.Infobox; namespace Nitrocid.Kernel.Configuration.Settings.KeyInputs { @@ -26,7 +28,17 @@ internal class IconSettingsKeyInput : ISettingsKeyInput { public object? PromptForSet(SettingsKey key, object? KeyDefaultValue, BaseKernelConfig configType, out bool bail) { - string icon = IconsSelector.PromptForIcons((string?)KeyDefaultValue ?? "heart-suit"); + if (AddonTools.GetAddon(InterAddonTranslations.GetAddonName(KnownAddons.ExtrasImagesIcons)) is null) + { + InfoBoxModalColor.WriteInfoBoxModal(Translate.DoTranslation("The icons addon needs to be installed before being able to set this value.")); + bail = true; + return KeyDefaultValue; + } + string defaultValue = (string?)KeyDefaultValue ?? "heart-suit"; + var type = InterAddonTools.GetTypeFromAddon(KnownAddons.ExtrasImagesIcons, "Nitrocid.Extras.Images.Icons.Tools.IconsTools"); + var hasIcon = (bool?)InterAddonTools.ExecuteCustomAddonFunction(KnownAddons.ExtrasImagesIcons, "HasIcon", type, defaultValue) ?? false; + defaultValue = hasIcon ? defaultValue : "heart-suit"; + string icon = (bool?)InterAddonTools.ExecuteCustomAddonFunction(KnownAddons.ExtrasImagesIcons, "PromptForIcons", type, defaultValue) ?? false; // Bail and return bail = true; diff --git a/public/Nitrocid/Properties/AssemblyInfo.cs b/public/Nitrocid/Properties/AssemblyInfo.cs index 7a10da367..770bef825 100644 --- a/public/Nitrocid/Properties/AssemblyInfo.cs +++ b/public/Nitrocid/Properties/AssemblyInfo.cs @@ -75,6 +75,7 @@ [assembly: InternalsVisibleTo("Nitrocid.Extras.Ssh, PublicKey=0024000004800000940000000602000000240000525341310004000001000100812e5231186da64504a543d5306da254e9062027fdaee10f569d93ecc1debc91770d1a077b762aea3ced57c09d9f033f9991960429980b625908628c80785a67a3b65bbb410c7623a0d7bbc1a9770b978358941714b5e2a806e5aa8fa58bb505f859be5fc3ebcce5b2c5d4c0820460c9d3e23cf66f3c00de5e0d154fec6a89b3")] [assembly: InternalsVisibleTo("Nitrocid.Extras.Chemistry, PublicKey=0024000004800000940000000602000000240000525341310004000001000100812e5231186da64504a543d5306da254e9062027fdaee10f569d93ecc1debc91770d1a077b762aea3ced57c09d9f033f9991960429980b625908628c80785a67a3b65bbb410c7623a0d7bbc1a9770b978358941714b5e2a806e5aa8fa58bb505f859be5fc3ebcce5b2c5d4c0820460c9d3e23cf66f3c00de5e0d154fec6a89b3")] [assembly: InternalsVisibleTo("Nitrocid.Extras.Mods, PublicKey=0024000004800000940000000602000000240000525341310004000001000100812e5231186da64504a543d5306da254e9062027fdaee10f569d93ecc1debc91770d1a077b762aea3ced57c09d9f033f9991960429980b625908628c80785a67a3b65bbb410c7623a0d7bbc1a9770b978358941714b5e2a806e5aa8fa58bb505f859be5fc3ebcce5b2c5d4c0820460c9d3e23cf66f3c00de5e0d154fec6a89b3")] +[assembly: InternalsVisibleTo("Nitrocid.Extras.Images.Icons, PublicKey=0024000004800000940000000602000000240000525341310004000001000100812e5231186da64504a543d5306da254e9062027fdaee10f569d93ecc1debc91770d1a077b762aea3ced57c09d9f033f9991960429980b625908628c80785a67a3b65bbb410c7623a0d7bbc1a9770b978358941714b5e2a806e5aa8fa58bb505f859be5fc3ebcce5b2c5d4c0820460c9d3e23cf66f3c00de5e0d154fec6a89b3")] // Misc internal projects [assembly: InternalsVisibleTo("Nitrocid.Benchmarks, PublicKey=0024000004800000940000000602000000240000525341310004000001000100812e5231186da64504a543d5306da254e9062027fdaee10f569d93ecc1debc91770d1a077b762aea3ced57c09d9f033f9991960429980b625908628c80785a67a3b65bbb410c7623a0d7bbc1a9770b978358941714b5e2a806e5aa8fa58bb505f859be5fc3ebcce5b2c5d4c0820460c9d3e23cf66f3c00de5e0d154fec6a89b3")] diff --git a/public/Nitrocid/Users/Login/Widgets/Implementations/Emoji.cs b/public/Nitrocid/Users/Login/Widgets/Implementations/Emoji.cs index 7a1ff68cd..699d8d889 100644 --- a/public/Nitrocid/Users/Login/Widgets/Implementations/Emoji.cs +++ b/public/Nitrocid/Users/Login/Widgets/Implementations/Emoji.cs @@ -17,10 +17,16 @@ // along with this program. If not, see . // +using Nitrocid.ConsoleBase.Colors; using Nitrocid.Drivers.RNG; using Nitrocid.Kernel.Configuration; +using Nitrocid.Kernel.Extensions; +using Nitrocid.Languages; using System.Text; +using Terminaux.Base; using Terminaux.Images.Icons; +using Terminaux.Writer.CyclicWriters; +using Terminaux.Writer.CyclicWriters.Renderer.Tools; namespace Nitrocid.Users.Login.Widgets.Implementations { @@ -40,9 +46,26 @@ public override string Initialize(int left, int top, int width, int height) int iconTop = top; // Render the icon, caching it in the process - string[] emojiList = IconsManager.GetIconNames(); + if (AddonTools.GetAddon(InterAddonTranslations.GetAddonName(KnownAddons.ExtrasImagesIcons)) is null) + { + var message = new AlignedText() + { + Text = Translate.DoTranslation("The icons addon needs to be installed before being able to display this emoji."), + Top = iconTop, + LeftMargin = left, + RightMargin = ConsoleWrapper.WindowWidth - (left + width), + ForegroundColor = KernelColorTools.GetColor(KernelColorType.Error), + Settings = new() + { + Alignment = TextAlignment.Middle + }, + }; + return message.Render(); + } + var type = InterAddonTools.GetTypeFromAddon(KnownAddons.ExtrasImagesIcons, "Nitrocid.Extras.Images.Icons.Tools.IconsTools"); + string[] emojiList = (string[]?)InterAddonTools.ExecuteCustomAddonFunction(KnownAddons.ExtrasImagesIcons, "GetIconNames", type) ?? []; string finalEmojiName = Config.WidgetConfig.EmojiWidgetCycleEmoticons ? emojiList[RandomDriver.RandomIdx(emojiList.Length)] : Config.WidgetConfig.EmojiWidgetEmoticonName; - cachedIcon = IconsManager.RenderIcon(finalEmojiName, iconWidth, iconHeight, iconLeft, iconTop); + cachedIcon = (string?)InterAddonTools.ExecuteCustomAddonFunction(KnownAddons.ExtrasImagesIcons, "RenderIcon", type, finalEmojiName, iconWidth, iconHeight, iconLeft, iconTop) ?? ""; return ""; }