halflife icon indicating copy to clipboard operation
halflife copied to clipboard

[Feature Request] Modern Native Menu API with VGUI Styling, Auto-Size & Rich Text Support

Open Zetsukt opened this issue 11 months ago • 1 comments

Hello Valve team,

First of all, thank you for the continued updates to GoldSrc and the 25th Anniversary update.

I would like to propose a feature request regarding the in-game Menu System. Currently, plugin creators and modders are limited to the legacy ShowMenu (fixed size, monospaced font) or compelled to use MOTD windows (HTML) which are heavy and intrusive.

The Proposal: Implementation of a new UserMessage (e.g., ShowMenuStyled) that allows the creation of "Modern Menus" using the native VGUI2 engine but with exposed styling parameters and a new Rich Text Parsing system for easy alignment.

Technical Analysis & Implementation Points: I have analyzed the SDK, specifically cl_dll/hud_msg.cpp, where MsgFunc_ShowMenu handles the current logic. The suggestion is to implement a parallel handler (e.g., MsgFunc_ShowMenuStyled) that reads additional styling bytes before passing the string to a new VGUI2 Panel instance instead of the legacy drawing method.

Key Features Requested:

1. Auto-sizing & Background: The menu background should optionally auto-scale to fit the content (as shown in the attached mockup, Fig 1), instead of taking up the whole screen.

2. Visual Customization: Support for RGBA background colors (translucency), border thickness, and border colors.

3. Rich Text & Alignment Tags: We propose a simple tag system within the string to handle colors and alignment dynamically.

  • Standard Colors: \w (White), \r (Red), \y (Yellow), \g (Green), \c (Cyan), \o (Orange), \m (Magenta).

  • Right Alignment Suffix ('R'): Adding 'R' to a color tag should align the subsequent text to the right side of the menu panel. This is crucial for displaying prices, stats, or values cleanly.

  • Examples:

  • \gR$16000 -> Displays "$16000" in Green, aligned to the Right.
  • \rR[LOCKED] -> Displays "[LOCKED]" in Red, aligned to the Right.
  • \yR100 HP -> Displays "100 HP" in Yellow, aligned to the Right.

Implementation Logic (Pseudo-code Concept): The server sends style definitions along with the string. The client VGUI panel parses the tags. In the Client DLL (receiving the message):

// Example logic for a new message handler, e.g., "ShowMenuStyled"
void MsgFunc_ShowMenuStyled(const char *pszName, int iSize, void *pbuf)
{
    BufferReader reader(pszName, pbuf);

    // 1. Read style bytes
    int bgColor[4]; // R, G, B, Alpha (e.g., 0, 0, 0, 150 for translucent)
    reader.ReadColors(bgColor);
    
    int borderColor[4]; 
    reader.ReadColors(borderColor);

    // 2. Read the menu string containing tags
    // e.g., "1. Golden AK47 \r[Damage++] \gR$5000"
    char *menuString = reader.ReadString();

    // 3. Render VGUI Panel
    // The VGUI Label implementation should parse "\gR" to split the string 
    // and render the following text using PaintTraverse() on the far right x-axis.
    g_pViewPort->ShowCustomMenu(menuString, bgColor, borderColor);
}

Backward Compatibility (Legacy Clients): Crucially, this system must handle clients that do not support the new message type. The server needs a way to query the client's capabilities (feature negotiation) before sending the new menu type to avoid Host_Error crashes on older/legacy builds (non-steam or non-updated clients).

Example Use Case for AMX Mod X (Plugin Logic): If implemented, developers could create clean, modern interfaces natively

// Hypothetical AMXX Code
public show_modern_shop(id)
{
    // Check if client supports the modern VGUI menu
    // This prevents crashes on older/non-official game clients.
    if (client_has_feature(id, FEATURE_MODERN_MENU))
    {
        new menu = menu_create_styled("ADVANCED WEAPON SHOP");
        
        // Set style: Translucent Black background, Orange Border
        menu_set_style(menu, 
            .bg_color = {0, 0, 0, 180}, 
            .border_color = {255, 157, 0, 255}
        );
        
        // Item with Left text and Right-aligned price
        // "1. Golden AK-47" (Left) | "$5000" (Right, Green)
        menu_additem(menu, "Golden AK-47 \r[Damage++] \gR$5000", "1");
        
        // Item with Left text and Right-aligned status
        // "2. Admin Tools" (Left) | "NO ACCESS" (Right, Red)
        menu_additem(menu, "Admin Tools \rR[NO ACCESS]", "2");

        menu_display_styled(id, menu);
    }
    else
    {
        // Fallback for legacy clients (standard white text menu)
        show_old_style_menu(id);
    }
}

Visual Mockup: (Please see the attached image below)

  • Left (Blue): Demonstrates Auto-Size. The background wraps tightly around the content.
  • Right (Orange): Demonstrates Right Alignment tags. Note how prices ($5000, $4800) are perfectly aligned to the right edge using the proposed \gR tag logic, while item names remain on the left. Image This feature would modernize the game's UX significantly while keeping the performance benefits of native VGUI.

Thank you for your time.

Zetsukt avatar Dec 11 '25 12:12 Zetsukt

Hello @Zetsukt, this request is already being tracked at #1639 / #2267. Closing as a duplicate.

kisak-valve avatar Dec 11 '25 13:12 kisak-valve