Implement per-client randomized menus with MenuShufflePerClient native.
Add MenuSetClientMapping native.
This commit is contained in:
@@ -816,8 +816,14 @@ static cell_t GetMenuItem(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
ItemDrawInfo dr;
|
||||
const char *info;
|
||||
cell_t client = (params[0] >= 8) ? params[8] : 0;
|
||||
if(!client && menu->IsPerClientShuffled())
|
||||
{
|
||||
return pContext->ThrowNativeError("This menu has been per-client random shuffled. "
|
||||
"You have to call GetMenuItem with a client index!");
|
||||
}
|
||||
|
||||
if ((info=menu->GetItemInfo(params[2], &dr)) == NULL)
|
||||
if ((info=menu->GetItemInfo(params[2], &dr, client)) == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -832,6 +838,57 @@ static cell_t GetMenuItem(IPluginContext *pContext, const cell_t *params)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t MenuShufflePerClient(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = (Handle_t)params[1];
|
||||
HandleError err;
|
||||
IBaseMenu *menu;
|
||||
|
||||
if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
|
||||
{
|
||||
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
|
||||
}
|
||||
|
||||
int start = params[2];
|
||||
int stop = params[3];
|
||||
|
||||
if (stop > 0 && !(stop >= start))
|
||||
{
|
||||
return pContext->ThrowNativeError("Stop must be -1 or >= start!");
|
||||
}
|
||||
|
||||
menu->ShufflePerClient(start, stop);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t MenuSetClientMapping(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = (Handle_t)params[1];
|
||||
HandleError err;
|
||||
IBaseMenu *menu;
|
||||
|
||||
if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
|
||||
{
|
||||
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
|
||||
}
|
||||
|
||||
int client = params[2];
|
||||
if (client < 1 || client > SM_MAXPLAYERS)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid client index!");
|
||||
}
|
||||
|
||||
cell_t *array;
|
||||
pContext->LocalToPhysAddr(params[3], &array);
|
||||
|
||||
int length = params[4];
|
||||
|
||||
menu->SetClientMapping(client, array, length);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t SetMenuPagination(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = (Handle_t)params[1];
|
||||
@@ -1645,6 +1702,8 @@ REGISTER_NATIVES(menuNatives)
|
||||
{"SetPanelKeys", SetPanelKeys},
|
||||
{"SetVoteResultCallback", SetVoteResultCallback},
|
||||
{"VoteMenu", VoteMenu},
|
||||
{"MenuShufflePerClient", MenuShufflePerClient},
|
||||
{"MenuSetClientMapping", MenuSetClientMapping},
|
||||
{"SetMenuNoVoteButton", SetMenuNoVoteButton},
|
||||
|
||||
// Transitional syntax support.
|
||||
@@ -1673,6 +1732,8 @@ REGISTER_NATIVES(menuNatives)
|
||||
{"Menu.ToPanel", CreatePanelFromMenu},
|
||||
{"Menu.Cancel", CancelMenu},
|
||||
{"Menu.DisplayVote", VoteMenu},
|
||||
{"Menu.ShufflePerClient", MenuShufflePerClient},
|
||||
{"Menu.SetClientMapping", MenuSetClientMapping},
|
||||
{"Menu.Pagination.get", GetMenuPagination},
|
||||
{"Menu.Pagination.set", SetMenuPagination},
|
||||
{"Menu.OptionFlags.get", GetMenuOptionFlags},
|
||||
|
||||
Reference in New Issue
Block a user