roflmuffin / CounterStrikeSharp

CounterStrikeSharp allows you to write server plugins in C# for Counter-Strike 2/Source2/CS2
https://docs.cssharp.dev
Other
743 stars 111 forks source link

Add CenterHtmlMenu button colors #398

Closed WidovV closed 4 months ago

WidovV commented 4 months ago

This pull request is only for allowing each developer to change the color of the title, enabled, disabled, previous page, next page and close color options in the centerhtmlmenu. Since ChatMenu and perhaps ConsoleMenu colors is restricted to the Colors class, a seperate and closed functionality to change these colors in the Center menu therefore it's not added into the IMenu interface. I haven't digged deeper into better solutions nor any safeguards, but I'll gladly work further on it.

Test plugin:

using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Menu;

namespace MenuTester;

public class MenuTest : BasePlugin
{
    public override string ModuleName => "Menu test";

    public override string ModuleVersion => "NaN";

    public override string ModuleAuthor => "WidovV";
    public override string ModuleDescription => "Testing menu colors";

    [ConsoleCommand("css_centermenu")]
    public void MenuTesting(CCSPlayerController player, CommandInfo info)
    {
        if (!player.IsValid)
            return;

        CenterHtmlMenu menu = new CenterHtmlMenu("Test menu!", this);

        menu.TitleColor = "red";
        menu.EnabledColor = "#b891e6";
        menu.DisabledColor = "#262626";
        menu.NextPageColor = "#2a977f";
        menu.PrevPageColor = "#365df8";
        menu.CloseColor = "#ffe3b7";

        menu.AddMenuOption("Option 1", (_, _) => PrintMessageToPlayer(player, "option 1"));
        menu.AddMenuOption("Option 2", (_, _) => PrintMessageToPlayer(player, "option 2"), true);
        menu.AddMenuOption("Option 3", (_, _) => PrintMessageToPlayer(player, "option 3"));
        menu.AddMenuOption("Option 4", (_, _) => PrintMessageToPlayer(player, "option 4"), true);
        menu.AddMenuOption("Option 5", (_, _) => PrintMessageToPlayer(player, "option 5"));
        menu.AddMenuOption("Option 6", (_, _) => PrintMessageToPlayer(player, "option 6"), true);
        menu.AddMenuOption("Option 7", (_, _) => PrintMessageToPlayer(player, "option 7"));
        menu.AddMenuOption("Option 8", (_, _) => PrintMessageToPlayer(player, "option 8"), true);
        menu.AddMenuOption("Option 9", (_, _) => PrintMessageToPlayer(player, "option 9"));
        menu.AddMenuOption("Option 10", (_, _) => PrintMessageToPlayer(player, "option 10"), true);
        menu.AddMenuOption("Option 11", (_, _) => PrintMessageToPlayer(player, "option 11"));
        menu.AddMenuOption("Option 12", (_, _) => PrintMessageToPlayer(player, "option 12"), true);
        menu.AddMenuOption("Option 13", (_, _) => PrintMessageToPlayer(player, "option 13"));

        menu.Open(player);
    }

    private void PrintMessageToPlayer(CCSPlayerController player, string message)
    {
        MenuManager.CloseActiveMenu(player);
        player.PrintToChat($"echo {message}");
    }
}

image

WidovV commented 4 months ago

The title color could also be added to a overloaded ctor

roflmuffin commented 4 months ago

Happy with this PR & it looks fully backwards compatible. Are you ready for merge @WidovV?

WidovV commented 4 months ago

@roflmuffin Hold up ima make a small Update to it :D

WidovV commented 4 months ago

I added colors to the chat menu also.

Plugin:

using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Menu;
using CounterStrikeSharp.API.Modules.Utils;

namespace MenuTester;

public class MenuTest : BasePlugin
{
    public override string ModuleName => "Menu test";

    public override string ModuleVersion => "NaN";

    public override string ModuleAuthor => "WidovV";
    public override string ModuleDescription => "Testing menu colors";

    [ConsoleCommand("css_centermenu")]
    public void MenuTesting(CCSPlayerController player, CommandInfo info)
    {
        if (!player.IsValid)
            return;

        CenterHtmlMenu menu = new CenterHtmlMenu("Test menu!", this);

        menu.TitleColor = "red";
        menu.EnabledColor = "#b891e6";
        menu.DisabledColor = "#262626";
        menu.NextPageColor = "#2a977f";
        menu.PrevPageColor = "#365df8";
        menu.CloseColor = "#ffe3b7";

        menu.AddMenuOption("Option 1", (_, _) => PrintMessageToPlayer(player, "option 1"));
        menu.AddMenuOption("Option 2", (_, _) => PrintMessageToPlayer(player, "option 2"), true);
        menu.AddMenuOption("Option 3", (_, _) => PrintMessageToPlayer(player, "option 3"));
        menu.AddMenuOption("Option 4", (_, _) => PrintMessageToPlayer(player, "option 4"), true);
        menu.AddMenuOption("Option 5", (_, _) => PrintMessageToPlayer(player, "option 5"));
        menu.AddMenuOption("Option 6", (_, _) => PrintMessageToPlayer(player, "option 6"), true);
        menu.AddMenuOption("Option 7", (_, _) => PrintMessageToPlayer(player, "option 7"));
        menu.AddMenuOption("Option 8", (_, _) => PrintMessageToPlayer(player, "option 8"), true);
        menu.AddMenuOption("Option 9", (_, _) => PrintMessageToPlayer(player, "option 9"));
        menu.AddMenuOption("Option 10", (_, _) => PrintMessageToPlayer(player, "option 10"), true);
        menu.AddMenuOption("Option 11", (_, _) => PrintMessageToPlayer(player, "option 11"));
        menu.AddMenuOption("Option 12", (_, _) => PrintMessageToPlayer(player, "option 12"), true);
        menu.AddMenuOption("Option 13", (_, _) => PrintMessageToPlayer(player, "option 13"));

        menu.Open(player);
    }

    [ConsoleCommand("css_chatmenu")]
    public void ChatMenuTesting(CCSPlayerController player, CommandInfo info)
    {
        if (!player.IsValid)
            return;

        ChatMenu chatMenu = new ChatMenu("Test chat menu!");

        chatMenu.TitleColor = ChatColors.Magenta;
        chatMenu.EnabledColor = ChatColors.Blue;
        chatMenu.DisabledColor = ChatColors.Orange;
        chatMenu.NextPageColor = ChatColors.Green;
        chatMenu.PrevPageColor = ChatColors.White;
        chatMenu.CloseColor = ChatColors.Magenta;

        chatMenu.ExitButton = true;

        chatMenu.AddMenuOption("Option 1", (_, _) => PrintMessageToPlayer(player, "option 1"));
        chatMenu.AddMenuOption("Option 2", (_, _) => PrintMessageToPlayer(player, "option 2"), true);
        chatMenu.AddMenuOption("Option 3", (_, _) => PrintMessageToPlayer(player, "option 3"));
        chatMenu.AddMenuOption("Option 4", (_, _) => PrintMessageToPlayer(player, "option 4"), true);
        chatMenu.AddMenuOption("Option 5", (_, _) => PrintMessageToPlayer(player, "option 5"));
        chatMenu.AddMenuOption("Option 6", (_, _) => PrintMessageToPlayer(player, "option 6"), true);
        chatMenu.AddMenuOption("Option 7", (_, _) => PrintMessageToPlayer(player, "option 7"));
        chatMenu.AddMenuOption("Option 8", (_, _) => PrintMessageToPlayer(player, "option 8"), true);
        chatMenu.AddMenuOption("Option 9", (_, _) => PrintMessageToPlayer(player, "option 9"));
        chatMenu.AddMenuOption("Option 10", (_, _) => PrintMessageToPlayer(player, "option 10"), true);
        chatMenu.AddMenuOption("Option 11", (_, _) => PrintMessageToPlayer(player, "option 11"));
        chatMenu.AddMenuOption("Option 12", (_, _) => PrintMessageToPlayer(player, "option 12"), true);
        chatMenu.AddMenuOption("Option 13", (_, _) => PrintMessageToPlayer(player, "option 13"));

        chatMenu.Open(player);

    }

    private void PrintMessageToPlayer(CCSPlayerController player, string message)
    {
        MenuManager.CloseActiveMenu(player);
        player.PrintToChat($"echo {message}");
    }
}

image

WidovV commented 4 months ago

I'm not sure if there should be any kind of string checks, as an example adding the '#' to the string-values in CenterHtmlMenus if it's missing etc.

WidovV commented 4 months ago

Otherwise I'm ready for merge

Dliix66 commented 4 months ago

I'm not sure if there should be any kind of string checks, as an example adding the '#' to the string-values in CenterHtmlMenus if it's missing etc.

I guess it's up to the plugin developer to check this IMO, good job