Skip to content

Commit

Permalink
Update pluginmenu plugin to use new functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaroq7 committed Jun 6, 2016
1 parent ceee48c commit 2584e85
Showing 1 changed file with 46 additions and 59 deletions.
105 changes: 46 additions & 59 deletions plugins/pluginmenu.sma
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public client_connect(id)
*
* @param MenuText The text to display as the title.
* @param Handler The function to call when an item is selected.
* @param Command The function to pass to the handler. It will be passed as "PLID Command".
* @param Command The function to pass to the handler.
* @param Callback Function to call for each plugin to be listed. Displays a number next to it (how many cvars, etc.)
*/
stock DisplayPluginMenu(id,const MenuText[], const Handler[], const Command[], const Callback[])
Expand All @@ -121,8 +121,8 @@ stock DisplayPluginMenu(id,const MenuText[], const Handler[], const Command[], c
new PluginName[64];
new func=get_func_id(Callback);
new tally;
new PluginCmd[64];
new MenuText[64];
new DataPack:itemData;
for (new i=0, max=get_pluginsnum();
i<max;
i++)
Expand All @@ -135,17 +135,19 @@ stock DisplayPluginMenu(id,const MenuText[], const Handler[], const Command[], c
get_plugin(i,"",0,PluginName,charsmax(PluginName),"",0,"",0,PluginState,charsmax(PluginState));

// Command syntax is: "# Function", # being plugin ID, function being public function to call.
formatex(PluginCmd,charsmax(PluginCmd),"%d %s",i,Command);
formatex(MenuText,charsmax(MenuText),"%s - %d",PluginName,tally);
// If the plugin is running, add this as an activated menu item.
if (strcmp(PluginState,"running",true)==0 ||
strcmp(PluginState,"debug", true)==0)
{
menu_additem(Menu,MenuText,PluginCmd,EnabledCallback);
itemData = CreateDataPack();
WritePackCell(itemData, i); //Plugin id
WritePackString(itemData, Command); //Function name
menu_additem2(Menu, MenuText, itemData, EnabledCallback);
}
else
{
menu_additem(Menu,MenuText,"",_,DisabledCallback);
menu_additem2(Menu, MenuText, Invalid_DataPack, 0, DisabledCallback);
}
}
}
Expand Down Expand Up @@ -319,8 +321,9 @@ public AlwaysEnableCallback(playerid, menuid, itemid)
* @param id The client selecting an item.
* @param menu The menu handle.
* @param item The item number that was selected.
* @param data Item data.
*/
public PluginMenuSelection(id, menu, item)
public PluginMenuSelection(id, menu, item, DataPack:data)
{
if (item==MENU_EXIT)
{
Expand All @@ -331,31 +334,16 @@ public PluginMenuSelection(id, menu, item)
return PLUGIN_HANDLED;
}

new Command[64];
new Dummy[1];
ResetPack(data); //Reset pack position before read

// All of the commands set for each item is the public
// function that we want to call after the item is selected.
// The parameters are: function(idPlayer,itemnumber)
// Note the menu is destroyed BEFORE the command
// gets executed.
// The command retrieved is in the format: "PLID Command"
menu_item_getinfo(menu, item, Dummy[0], Command, charsmax(Command),Dummy,0,Dummy[0]);


new plid=str_to_num(Command);
new plid = ReadPackCell(data); //Plugin id
new Function[32];

for (new i=0;i<charsmax(Command);i++)
{
if (Command[i]==' ')
{
// we're at the break. move up one space.
i++;
copy(Function,charsmax(Function),Command[i]);
break;
}
}
ReadPackString(data, Function, charsmax(Function)); //Function name

menu_destroy(menu);

Expand Down Expand Up @@ -458,10 +446,10 @@ public CommandChangeCvar(id)
* @param id The client who chose an item.
* @param menu The menu handle.
* @param item The item that has been selected.
* @param data Item data.
*/
public CvarMenuSelection(id, menu, item)
public CvarMenuSelection(id, menu, item, DataPack:data)
{

if (item==MENU_EXIT)
{
menu_destroy(menu);
Expand All @@ -484,12 +472,11 @@ public CvarMenuSelection(id, menu, item)
else
{
new CvarName[64];
new Command[32];
new Dummy[1];
// pcvar pointer is stored in command, extract the name of the cvar from the name field.
menu_item_getinfo(menu, item, Dummy[0], Command, charsmax(Command),CvarName,charsmax(CvarName),Dummy[0]);

ResetPack(data); //Reset pack position before read

CurrentCvar[id]=str_to_num(Command);
CurrentCvar[id] = ReadPackCell(data); //cvar ptr
ReadPackString(data, CvarName, charsmax(CvarName)); //cvar name

if (CurrentCvar[id]==0) // This should never happen, but just incase..
{
Expand All @@ -498,15 +485,6 @@ public CvarMenuSelection(id, menu, item)
}
// TODO: ML this

// Scan up "CvarName" and stop at the first space
for (new i=0;i<charsmax(CvarName);i++)
{
if (CvarName[i]==' ')
{
CvarName[i]='^0';
break;
}
}
copy(CurrentCvarName[id],charsmax(CurrentCvarName[]),CvarName);
client_print(id,print_chat,"[AMXX] Type in the new value for %s, or !cancel to cancel.",CvarName);
client_cmd(id,"messagemode amx_changecvar");
Expand Down Expand Up @@ -538,6 +516,7 @@ public DisplayCvarMenu(id, plid, page)
new CvarText[64];
new CvarData[32];
new CvarPtr;
new DataPack:itemData;

for (new i=0, max=get_plugins_cvarsnum();
i<max;
Expand All @@ -553,12 +532,14 @@ public DisplayCvarMenu(id, plid, page)
formatex(CvarText,charsmax(CvarText),"%s - %s",Cvar,CvarData);

// Now store the pcvar data in Cvar
num_to_str(CvarPtr,Cvar,charsmax(Cvar));
menu_additem(Menu,CvarText,Cvar,_,EnabledCallback);
itemData = CreateDataPack();
WritePackCell(itemData, CvarPtr); //Cvar ptr
WritePackString(itemData, Cvar); //Cvar name
menu_additem2(Menu, CvarText, itemData, _, EnabledCallback);
}
else
{
menu_additem(Menu,Cvar,"",_,DisabledCallback);
menu_additem2(Menu, Cvar, Invalid_DataPack, _, DisabledCallback);
}

}
Expand Down Expand Up @@ -614,8 +595,9 @@ public CvarMenuCommand(id, level, cid)
* @param id Id of the client.
* @param menu Menu handle.
* @param item Item that was selected.
* @param data Item data.
*/
public SpecificCommandHandler(id,menu,item)
public SpecificCommandHandler(id,menu,item,DataPack:data)
{
// Exit was called, return to the previous menu.
if (item<0)
Expand All @@ -632,10 +614,11 @@ public SpecificCommandHandler(id,menu,item)
return PLUGIN_HANDLED;
}

new Dummy[1];
ResetPack(data); //Reset pack postion before read

if (item==0) // "With params"
{
menu_item_getinfo(menu, item, Dummy[0], CurrentCommand[id], charsmax(CurrentCommand[]),"",0,Dummy[0]);
ReadPackString(data, CurrentCommand[id], charsmax(CurrentCommand[]));
if (CurrentCommand[id][0]==0) // This should never happen, but just incase..
{
client_print(id,print_chat,"[AMXX] There was an error extracting the command name.");
Expand All @@ -652,7 +635,7 @@ public SpecificCommandHandler(id,menu,item)
}
else if (item==1) // "No params"
{
menu_item_getinfo(menu, item, Dummy[0], CurrentCommand[id], charsmax(CurrentCommand[]),"",0,Dummy[0]);
ReadPackString(data, CurrentCommand[id], charsmax(CurrentCommand[]));
if (CurrentCommand[id][0]==0) // This should never happen, but just incase..
{
client_print(id,print_chat,"[AMXX] There was an error extracting the command name.");
Expand Down Expand Up @@ -696,6 +679,7 @@ stock DisplaySpecificCommand(id,cid)
new CommandTitle[256];
new CommandAccess;
new Menu;
new DataPack:itemData = CreateDataPack();

get_concmd(cid,CommandName,charsmax(CommandName),CommandAccess, CommandDesc, charsmax(CommandDesc), -1, -1);

Expand All @@ -708,8 +692,11 @@ stock DisplaySpecificCommand(id,cid)
{
Menu=menu_create(CommandName,"SpecificCommandHandler");
}
menu_additem(Menu,"Execute with parameters.",CommandName,_,EnabledCallback);
menu_additem(Menu,"Execute with no parameters.",CommandName,_,EnabledCallback);

WritePackString(itemData, CommandName);

menu_additem2(Menu, "Execute with parameters.", itemData, _, EnabledCallback);
menu_additem2(Menu, "Execute with no parameters.", itemData, _, EnabledCallback);

menu_setprop(Menu,MPROP_NUMBER_COLOR,"\y");
menu_display(id,Menu,0);
Expand Down Expand Up @@ -778,8 +765,9 @@ public CommandExecuteCommand(id)
* @param id id of the client who made the selection.
* @param menu The menu handle.
* @param item The item that was selected.
* @param data Item data.
*/
public CommandMenuSelection(id, menu, item)
public CommandMenuSelection(id, menu, item, DataPack:data)
{
if (item==MENU_EXIT)
{
Expand All @@ -805,14 +793,12 @@ public CommandMenuSelection(id, menu, item)
}
else
{
new Command[32];
new Dummy[1];
// pcvar pointer is stored in command, extract the name of the cvar from the name field.
menu_item_getinfo(menu, item, Dummy[0], Command, charsmax(Command),"",0,Dummy[0]);
ResetPack(data); //Reset pack position before read
new cid = ReadPackCell(data);

menu_destroy(menu);

DisplaySpecificCommand(id,str_to_num(Command));
DisplaySpecificCommand(id,cid);
}

return PLUGIN_HANDLED;
Expand Down Expand Up @@ -851,7 +837,7 @@ public DisplayCmdMenu(id, plid, page)
new Menu=menu_create(MenuTitle,"CommandMenuSelection");

new Command[64];
new CidString[32];
new DataPack:itemData;
new CommandAccess;
new userflags=get_user_flags(id);
new bool:isadmin=bool:is_user_admin(id);
Expand All @@ -872,12 +858,13 @@ public DisplayCmdMenu(id, plid, page)
CommandAccess==ADMIN_USER ||
CommandAccess==ADMIN_ALL)
{
num_to_str(i,CidString,charsmax(CidString));
menu_additem(Menu,Command,CidString,0,EnabledCallback);
itemData = CreateDataPack();
WritePackCell(itemData, i); //Command id
menu_additem2(Menu, Command, itemData, 0, EnabledCallback);
}
else
{
menu_additem(Menu,Command,"",0,DisabledCallback);
menu_additem2(Menu, Command, Invalid_DataPack, 0, DisabledCallback);
}
}
}
Expand Down

0 comments on commit 2584e85

Please sign in to comment.