Amaroq7 / SPMod

SourcePawn Scripting Engine for Half-Life 1 based games
GNU General Public License v3.0
27 stars 12 forks source link

Menu manager #28

Closed Mistrick closed 5 years ago

Mistrick commented 5 years ago

Description

We need API for creating menus. In amxx exists Old style menu and New menus. I suggest create all in one.

enum Menu
{
    INVALID_MENU = -1
};

enum MenuStyle
{
    STYLE_ITEMS,
    STYLE_TEXT
}

enum MenuProps
{
    // def 7 like amxx
    MPROP_ITEMS_PER_PAGE,
    // def "\r#num#." like "1. item"
    // custom "\r[#num#]" like "[1] item"
    MPROP_NUMBER_FORMAT,
    // show/hide exit item
    MPROP_EXIT,
    // custom name for exit, back, next
    MPROP_EXIT_NAME,
    MPROP_NEXT_NAME,
    MPROP_BACK_NAME,
    // for hl, etc
    MPROP_NO_COLORS,
};

enum ItemStatus
{
    ITEM_ENABLED,
    ITEM_DISABLED
};

enum MenuItem
{
    MENU_EXIT = -3,
    MENU_NEXT = -2,
    MENU_BACK = -1
};

// typedef MenuHandler = function int (Menu menu, MenuAction action, int param1, int param2);

typeset MenuHandler
{
    // text style
    function void(
        Menu menu,
        int key,
        int player
    );

    // item style
    function void(
        Menu menu,
        MenuItem item,
        int player,
        any data
    );
};

typedef CallbackHandler = function ItemStatus (Menu menu, MenuItem item, int player);

methodmap Menu
{
    // param global if false then destroy after exit
    public native Menu(MenuHandler handler, MenuStyle style = STYLE_ITEMS, bool global = false);
    // param page only for STYLE_ITEMS
    public native void Show(int player, int time = -1, int page = 0);

    // only for STYLE_TEXT
    public native void AddText(const char text[]);
    public native void AddKeys(int keys);

    // only for STYLE_ITEMS
    public native void SetTitle(const char title[]);
    public native void AddItem(const char name[], any data = 0, CallbackHandler callback = 0);
    // for blank use AddText(0, "\n") or make "\n" by default instead ""
    // TODO: change native name
    public native void AddText(int slot = 0, const char text[] = "");
    public native void SetProp(MenuProps prop, any ...);
    property int Items {
        public native get();
    }
}

// close any active menu
native void CloseMenu(int player);

How do we replicate the issue?

Create manager?

Expected behavior (i.e. solution)

Other Comments