Skip to content

Commit

Permalink
imp - Made an addon for icons
Browse files Browse the repository at this point in the history
---

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
  • Loading branch information
AptiviCEO committed Jan 8, 2025
1 parent f27a41d commit 934faa7
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 6 deletions.
8 changes: 8 additions & 0 deletions Nitrocid.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,10 @@
"name": "ExtrasMods",
"display": "Extras - Mods",
"project": "Extras.Mods"
},
{
"name": "ExtrasImagesIcons",
"display": "Extras - Icons",
"project": "Extras.Images.Icons"
}
]
40 changes: 40 additions & 0 deletions public/Nitrocid.Addons/Nitrocid.Extras.Images.Icons/IconsInit.cs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
//

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()
{ }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<!-- Extras.Images.Icons addon General Information -->
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DefineTrace>true</DefineTrace>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\..\Nitrocid\KSBuild\$(TargetFramework)\Addons\Extras.Images.Icons</OutputPath>
<Description>Nitrocid KS Extras - Icons</Description>
<AssemblyTitle>Nitrocid KS Extras - Icons</AssemblyTitle>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<!-- Extras.Images.Icons addon General Information End -->

<!-- Extras.Images.Icons addon Platform Information -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineDebug>true</DefineDebug>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DefineDebug>false</DefineDebug>
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\private\Nitrocid.LocaleChecker\Nitrocid.LocaleChecker.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\..\Nitrocid\Nitrocid.csproj" Private="false" />
</ItemGroup>
<!-- Extras.Images.Icons addon Platform Information End -->

<ItemGroup>
<PackageReference Include="Terminaux.Images.Icons" Version="6.1.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
//

using System.Linq;
using Terminaux.Images.Icons;
using Terminaux.Writer.ConsoleWriters;

namespace Nitrocid.Extras.Images.Icons.Tools
{
/// <summary>
/// Tools for the icons
/// </summary>
public static class IconsTools
{
/// <summary>
/// Gets the icon names
/// </summary>
/// <returns>An array of all icon names</returns>
public static string[] GetIconNames() =>
IconsManager.GetIconNames();

/// <summary>
/// Checks an icon
/// </summary>
/// <param name="iconName">Icon name</param>
/// <returns>True if this icon is found; false otherwise.</returns>
public static bool HasIcon(string iconName) =>
GetIconNames().Contains(iconName);

/// <summary>
/// Renders the icon to a string that you can print to the console
/// </summary>
/// <param name="iconName">Icon name</param>
/// <param name="width">Width of the resulting icon</param>
/// <param name="height">Height of the resulting icon</param>
/// <param name="left">Zero-based console left position to start writing the icon to</param>
/// <param name="top">Zero-based console top position to start writing the icon to</param>
/// <returns>A string that contains the resulting pixels that you can print to the console using the <see cref="TextWriterRaw.WriteRaw(string, object[])"/> function</returns>
public static string RenderIcon(string iconName, int width, int height, int left, int top) =>
IconsManager.RenderIcon(iconName, width, height, left, top);

/// <summary>
/// Prompts the user for an icon
/// </summary>
/// <param name="initialIcon">Initial icon to use</param>
/// <returns>Selected icon</returns>
public static string PromptForIcons(string initialIcon) =>
IconsSelector.PromptForIcons(initialIcon);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -442,7 +443,7 @@ public int DigitalMaximumColorLevel
}
#endregion

#region
#region Emoji
private string emojiWidgetCurrentEmoticon = "gem-stone";

/// <summary>
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@
//

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
{
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;
Expand Down
1 change: 1 addition & 0 deletions public/Nitrocid/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
27 changes: 25 additions & 2 deletions public/Nitrocid/Users/Login/Widgets/Implementations/Emoji.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

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
{
Expand All @@ -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 "";
}

Expand Down

0 comments on commit 934faa7

Please sign in to comment.