Active button issue in the info panel

Hello,
Thank you for the mod, I love it!

I wanted to use alpha colors with the interface; I noticed that the color I choose for the active button seems to remain randomly when I click on others buttons.
After some research in your code, I noticed that the destroyed active button may not be correct under certain condition.
If we don't use alpha colors, it is not visible because the non-active button will be create over an active one, but it is still here, under the non-active one.

If I am not wrong, the problem come from the way the active button is handled when ShowInfo is call for the first time and also in ChangeTab.
You can easily reproduce the issue with 3 btn or more and with alpha color for the UI (I used black 50% as non active btn and orange 50% for active btn)
This is what I understood after some tests today (see bellow).

1st instance - init
btn1 *active* [cmd=changeTab 0]
btn2 *nonactive* [cmd=changeTab 1 btn1 btn2 pannelName]
btn3 *nonactive* [cmd=changeTab 2 btn1 btn3 pannelName]

2nd instance - click on btn2
btn1 *nonactive* [cmd=changeTab 0 btn2 btn1 pannelName] => the command is updated correctly here
btn2 *active* [cmd=changeTab 1]
btn3 *nonactive* [cmd=changeTab 2 btn1 btn3 pannelName] => the command did not change, still refering on btn1 as previous active btn

Btn destroyed:
*active* btn1 => OK
*nonactive* btn2 => OK

3rd instance - click on btn3
btn1 *nonactive* [cmd=changeTab 0 btn2 btn1 pannelName] => again, not updated. must be btn3 now
btn2 *nonactive* [cmd=changeTab 1 btn3 btn2 pannelName] => updated according the new click
btn3 *active* [cmd=changeTab 2]

Btn destroyed:
*active* btn1 => NOK (doesn't exist anymore, btn2 is still here, bellow btn2 *nonactive*)
*nonactive* btn3 => OK

I tried the fix the problem myself but it seems to be beyond my capacity. Probably need to destroy all the buttons everytime you click on a non active one, to update correctly the command on all of them.

Meanwhile, I just don't use the alpha colors, and it is fine too. :)
Thank you for your help.

Hello,

I did a fix for this issue, up to you if you want take it like this or re do it.

        private static void AddNonActiveButton(
            int tabIndex,
            CuiElementContainer container,
            HelpTab helpTab,
            string mainPanelName,
            string activeTabButtonName)
        {
            Color nonActiveButtonColor;
            ColorExtensions.TryParseHexString(_settings.InactiveButtonColor, out nonActiveButtonColor);

            CuiButton helpTabButton = CreateTabButton(tabIndex, helpTab, nonActiveButtonColor);
            string helpTabButtonName = container.Add(helpTabButton, mainPanelName, $"serverinfo::btnnactive{tabIndex}");// Fix Buttons

            CuiElement helpTabButtonCuiElement =
                container.First(i => i.Name.Equals(helpTabButtonName, StringComparison.OrdinalIgnoreCase));
            CuiButtonComponent generatedHelpTabButton = helpTabButtonCuiElement.Components.OfType<CuiButtonComponent>().First();

            string command = string.Format("changeTab {0} {1} {2} {3}", tabIndex, activeTabButtonName, helpTabButtonName, mainPanelName);
            generatedHelpTabButton.Command = command;
        }
​
        private void ChangeTab(ConsoleSystem.Arg arg)
        {
            if (arg.Connection == null || arg.Connection.player == null || !arg.HasArgs(4) || _settings == null)
                return;

            var player = arg.Connection.player as BasePlayer;
            if (player == null)
                return;

            if (!PlayerActiveTabs.ContainsKey(player.userID))
                return;

            var previousTabIndex = PlayerActiveTabs[player.userID].ActiveTabIndex;
            var tabToChangeTo = arg.GetInt(0, 65535);

            if (previousTabIndex == tabToChangeTo)
                return;

            var tabToSelectIndex = arg.GetInt(0);
            var activeButtonName = arg.GetString(1);
            var tabToSelectButtonName = arg.GetString(2);
            var mainPanelName = arg.GetString(3);

            CuiHelper.DestroyUi(player, PlayerActiveTabs[player.userID].ActiveTabContentPanelName);
            //CuiHelper.DestroyUi(player, activeButtonName);// Fix Buttons
            //CuiHelper.DestroyUi(player, tabToSelectButtonName);// Fix Buttons

            var allowedTabs = _settings.Tabs
                .Where((tab, tabIndex) => string.IsNullOrEmpty(tab.OxideGroup) ||
                    tab.OxideGroup.Split(',')
                        .Any(group => Permission.UserHasGroup(player.userID.ToString(CultureInfo.InvariantCulture), group)))
                .ToList();
            var tabToSelect = allowedTabs[tabToSelectIndex];
            PlayerActiveTabs[player.userID].ActiveTabIndex = tabToSelectIndex;
            PlayerActiveTabs[player.userID].PageIndex = 0;

            var container = new CuiElementContainer();
            var tabContentPanelName = CreateTabContent(tabToSelect, container, mainPanelName);
            /* Fix buttons */
            CuiHelper.DestroyUi(player, activeButtonName);
            var newActiveButtonName = AddActiveButton(tabToSelectIndex, tabToSelect, container, mainPanelName);
            for (int tabIndex = 0; tabIndex < allowedTabs.Count; tabIndex++)
            {
                if (tabIndex == tabToSelectIndex)
                    continue;
                CuiHelper.DestroyUi(player, $"serverinfo::btnnactive{tabIndex}");
                AddNonActiveButton(tabIndex, container, allowedTabs[tabIndex], mainPanelName, newActiveButtonName);
            }
            /* End Fix buttons */   
            PlayerActiveTabs[player.userID].ActiveTabContentPanelName = tabContentPanelName;

            SendUI(player, container);
        }

I also found a minor bug; the panel can ben open severial time and stack up. I just added a 
"CuiHelper.DestroyUi(player, PlayerActiveTabs[player.userID].MainPanelName);"
before opening a new interface in ShowInfo().

The buttons not switching the highlight on/off properly was driving me nuts and makes for a rather unprofessional touch for players wondering if my server is going to be a great place to play - or is poorly maintained...
I have no clue what I'm doing, but was able to read Hiroshi248's post and find those locations in the original cs file. It works like a charm! I had an extra character that messed things up, but was able to track it down and delete it.

Thank you Hiroshi248, for posting this fix!

The fix does not work anymire since we got a new version :(