Beispiel #1
0
    public void UpdateUI()
    {
        // Update game version UI
        GameVersion.UpdateUI(ShowUI);

        // Don't draw the UI if we're not showing it
        if (!ShowUI)
        {
            return;
        }

        // Add selection index if not set
        if (!SelectedMenuItem.Any())
        {
            SelectedMenuItem.Add(0);
        }

        // Get current menu
        var menu          = GetCurrentMenu();
        var selectedIndex = GetSelectedMenuItemIndex;

        // TODO: Allow these to be modified from settings
        // TODO: Only draw within the game frame
        // UI values
        int       xPos           = 50;
        Color     defaultColor   = Color.White;
        Color     highlightColor = Color.Yellow;
        int       yPos           = 50;
        const int lineHeight     = 20;

        // Add every menu item
        for (var i = 0; i < menu.Length; i++)
        {
            // Get the menu
            var m = menu[i];

            // Get the name
            var name = m.DisplayName;

            // If there are options for the item we add horizontal scroll indicators
            if (m.Options.Any())
            {
                if (m.CanDecreaseOptionsIndex)
                {
                    name = $"< {name}";
                }
                if (m.CanIncreaseOptionsIndex)
                {
                    name = $"{name} >";
                }
            }
            // If there are children we show an indicator
            if (m.Children.Any())
            {
                name = $"{name} ->";
            }

            // Add the text to the UI
            DrawString(xPos, yPos, name, i == selectedIndex ? highlightColor : defaultColor);

            // Increment the y position
            yPos += lineHeight;
        }

        // Add the back option to return to previous menu
        if (HasBackOption)
        {
            yPos += lineHeight / 2;
            DrawString(xPos, yPos, "<- Back", selectedIndex == menu.Length ? highlightColor : defaultColor);
        }

        Color valueColor = Color.Orange;
        int   valueYPos  = 5;
        int   valueXPos  = 200;

        // Add values
        foreach (var v in Values)
        {
            DrawString(valueXPos, valueYPos, v.DisplayText, valueColor);
            valueYPos += lineHeight;
        }

        void DrawString(int x, int y, string str, Color c)
        {
            if (RenderUIInGame)
            {
                API.Gui.DrawString(x, y, str, c, fontsize: 12, fontstyle: "Bold", backcolor: Color.Black);
            }
            else
            {
                API.Gui.Text(x, y, str, c);
            }
        }
    }