Create GlobalForward & PrivateForward methodmaps (#1004)
This commit is contained in:
parent
81dc80fbd1
commit
4f3c3175e6
@ -733,27 +733,36 @@ static cell_t sm_AddFrameAction(IPluginContext *pContext, const cell_t *params)
|
|||||||
|
|
||||||
REGISTER_NATIVES(functionNatives)
|
REGISTER_NATIVES(functionNatives)
|
||||||
{
|
{
|
||||||
{"GetFunctionByName", sm_GetFunctionByName},
|
{"GetFunctionByName", sm_GetFunctionByName},
|
||||||
{"CreateGlobalForward", sm_CreateGlobalForward},
|
{"CreateGlobalForward", sm_CreateGlobalForward},
|
||||||
{"CreateForward", sm_CreateForward},
|
{"CreateForward", sm_CreateForward},
|
||||||
{"GetForwardFunctionCount", sm_GetForwardFunctionCount},
|
{"GetForwardFunctionCount", sm_GetForwardFunctionCount},
|
||||||
{"AddToForward", sm_AddToForward},
|
{"AddToForward", sm_AddToForward},
|
||||||
{"RemoveFromForward", sm_RemoveFromForward},
|
{"RemoveFromForward", sm_RemoveFromForward},
|
||||||
{"RemoveAllFromForward", sm_RemoveAllFromForward},
|
{"RemoveAllFromForward", sm_RemoveAllFromForward},
|
||||||
{"Call_StartFunction", sm_CallStartFunction},
|
{"Call_StartFunction", sm_CallStartFunction},
|
||||||
{"Call_StartForward", sm_CallStartForward},
|
{"Call_StartForward", sm_CallStartForward},
|
||||||
{"Call_PushCell", sm_CallPushCell},
|
{"Call_PushCell", sm_CallPushCell},
|
||||||
{"Call_PushCellRef", sm_CallPushCellRef},
|
{"Call_PushCellRef", sm_CallPushCellRef},
|
||||||
{"Call_PushFloat", sm_CallPushFloat},
|
{"Call_PushFloat", sm_CallPushFloat},
|
||||||
{"Call_PushFloatRef", sm_CallPushFloatRef},
|
{"Call_PushFloatRef", sm_CallPushFloatRef},
|
||||||
{"Call_PushArray", sm_CallPushArray},
|
{"Call_PushArray", sm_CallPushArray},
|
||||||
{"Call_PushArrayEx", sm_CallPushArrayEx},
|
{"Call_PushArrayEx", sm_CallPushArrayEx},
|
||||||
{"Call_PushString", sm_CallPushString},
|
{"Call_PushString", sm_CallPushString},
|
||||||
{"Call_PushStringEx", sm_CallPushStringEx},
|
{"Call_PushStringEx", sm_CallPushStringEx},
|
||||||
{"Call_PushNullVector", sm_CallPushNullVector},
|
{"Call_PushNullVector", sm_CallPushNullVector},
|
||||||
{"Call_PushNullString", sm_CallPushNullString},
|
{"Call_PushNullString", sm_CallPushNullString},
|
||||||
{"Call_Finish", sm_CallFinish},
|
{"Call_Finish", sm_CallFinish},
|
||||||
{"Call_Cancel", sm_CallCancel},
|
{"Call_Cancel", sm_CallCancel},
|
||||||
{"RequestFrame", sm_AddFrameAction},
|
{"RequestFrame", sm_AddFrameAction},
|
||||||
{NULL, NULL},
|
|
||||||
|
{"GlobalForward.GlobalForward", sm_CreateGlobalForward},
|
||||||
|
{"GlobalForward.FunctionCount.get", sm_GetForwardFunctionCount},
|
||||||
|
|
||||||
|
{"PrivateForward.PrivateForward", sm_CreateForward},
|
||||||
|
{"PrivateForward.AddFunction", sm_AddToForward},
|
||||||
|
{"PrivateForward.RemoveFunction", sm_RemoveFromForward},
|
||||||
|
{"PrivateForward.RemoveAllFunctions", sm_RemoveAllFromForward},
|
||||||
|
|
||||||
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
|
@ -48,8 +48,8 @@ public Plugin myinfo =
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Forwards */
|
/* Forwards */
|
||||||
Handle hOnAdminMenuReady = null;
|
GlobalForward hOnAdminMenuReady;
|
||||||
Handle hOnAdminMenuCreated = null;
|
GlobalForward hOnAdminMenuCreated;
|
||||||
|
|
||||||
/* Menus */
|
/* Menus */
|
||||||
TopMenu hAdminMenu;
|
TopMenu hAdminMenu;
|
||||||
@ -75,8 +75,8 @@ public void OnPluginStart()
|
|||||||
LoadTranslations("common.phrases");
|
LoadTranslations("common.phrases");
|
||||||
LoadTranslations("adminmenu.phrases");
|
LoadTranslations("adminmenu.phrases");
|
||||||
|
|
||||||
hOnAdminMenuCreated = CreateGlobalForward("OnAdminMenuCreated", ET_Ignore, Param_Cell);
|
hOnAdminMenuCreated = new GlobalForward("OnAdminMenuCreated", ET_Ignore, Param_Cell);
|
||||||
hOnAdminMenuReady = CreateGlobalForward("OnAdminMenuReady", ET_Ignore, Param_Cell);
|
hOnAdminMenuReady = new GlobalForward("OnAdminMenuReady", ET_Ignore, Param_Cell);
|
||||||
|
|
||||||
RegAdminCmd("sm_admin", Command_DisplayMenu, ADMFLAG_GENERIC, "Displays the admin menu");
|
RegAdminCmd("sm_admin", Command_DisplayMenu, ADMFLAG_GENERIC, "Displays the admin menu");
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,74 @@ enum ExecType
|
|||||||
* @endsection
|
* @endsection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
methodmap GlobalForward < Handle {
|
||||||
|
// Creates a global forward.
|
||||||
|
//
|
||||||
|
// @note The name used to create the forward is used as its public function in all target plugins.
|
||||||
|
// @note This is ideal for global, static forwards that are never changed.
|
||||||
|
// @note Global forwards cannot be cloned.
|
||||||
|
// @note Use CloseHandle() to destroy these.
|
||||||
|
//
|
||||||
|
// @param name Name of public function to use in forward.
|
||||||
|
// @param type Execution type to be used.
|
||||||
|
// @param ... Variable number of parameter types (up to 32).
|
||||||
|
// @return Handle to new global forward.
|
||||||
|
// @error More than 32 paramater types passed.
|
||||||
|
public native GlobalForward(const char[] name, ExecType type, ParamType ...);
|
||||||
|
|
||||||
|
// Returns the number of functions in a global or private forward's call list.
|
||||||
|
property int FunctionCount {
|
||||||
|
public native get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
methodmap PrivateForward < GlobalForward {
|
||||||
|
// Creates a private forward.
|
||||||
|
//
|
||||||
|
// @note No functions are automatically added. Use AddToForward() to do this.
|
||||||
|
// @note Private forwards can be cloned.
|
||||||
|
// @note Use CloseHandle() to destroy these.
|
||||||
|
//
|
||||||
|
// @param type Execution type to be used.
|
||||||
|
// @param ... Variable number of parameter types (up to 32).
|
||||||
|
// @return Handle to new private forward.
|
||||||
|
// @error More than 32 paramater types passed.
|
||||||
|
public native PrivateForward(ExecType type, ParamType ...);
|
||||||
|
|
||||||
|
// Adds a function to a private forward's call list.
|
||||||
|
//
|
||||||
|
// @note Cannot be used during an incomplete call.
|
||||||
|
//
|
||||||
|
// @param plugin Handle of the plugin that contains the function.
|
||||||
|
// Pass INVALID_HANDLE to specify the calling plugin.
|
||||||
|
// @param func Function to add to forward.
|
||||||
|
// @return True on success, false otherwise.
|
||||||
|
// @error Invalid or corrupt private forward handle, invalid or corrupt plugin handle, or invalid function.
|
||||||
|
public native bool AddFunction(Handle plugin, Function func);
|
||||||
|
|
||||||
|
// Removes a function from a private forward's call list.
|
||||||
|
//
|
||||||
|
// @note Only removes one instance.
|
||||||
|
// @note Functions will be removed automatically if their parent plugin is unloaded.
|
||||||
|
//
|
||||||
|
// @param plugin Handle of the plugin that contains the function.
|
||||||
|
// Pass INVALID_HANDLE to specify the calling plugin.
|
||||||
|
// @param func Function to remove from forward.
|
||||||
|
// @return True on success, false otherwise.
|
||||||
|
// @error Invalid or corrupt private forward handle, invalid or corrupt plugin handle, or invalid function.
|
||||||
|
public native bool RemoveFunction(Handle plugin, Function func);
|
||||||
|
|
||||||
|
// Removes all instances of a plugin from a private forward's call list.
|
||||||
|
//
|
||||||
|
// @note Functions will be removed automatically if their parent plugin is unloaded.
|
||||||
|
//
|
||||||
|
// @param plugin Handle of the plugin to remove instances of.
|
||||||
|
// Pass INVALID_HANDLE to specify the calling plugin.
|
||||||
|
// @return Number of functions removed from forward.
|
||||||
|
// @error Invalid or corrupt private forward handle or invalid or corrupt plugin handle.
|
||||||
|
public native int RemoveAllFunctions(Handle plugin);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a function id from a function name.
|
* Gets a function id from a function name.
|
||||||
*
|
*
|
||||||
@ -136,7 +204,7 @@ native Function GetFunctionByName(Handle plugin, const char[] name);
|
|||||||
* @return Handle to new global forward.
|
* @return Handle to new global forward.
|
||||||
* @error More than 32 paramater types passed.
|
* @error More than 32 paramater types passed.
|
||||||
*/
|
*/
|
||||||
native Handle CreateGlobalForward(const char[] name, ExecType type, ParamType ...);
|
native GlobalForward CreateGlobalForward(const char[] name, ExecType type, ParamType ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a private forward.
|
* Creates a private forward.
|
||||||
@ -150,7 +218,7 @@ native Handle CreateGlobalForward(const char[] name, ExecType type, ParamType ..
|
|||||||
* @return Handle to new private forward.
|
* @return Handle to new private forward.
|
||||||
* @error More than 32 paramater types passed.
|
* @error More than 32 paramater types passed.
|
||||||
*/
|
*/
|
||||||
native Handle CreateForward(ExecType type, ParamType ...);
|
native PrivateForward CreateForward(ExecType type, ParamType ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of functions in a global or private forward's call list.
|
* Returns the number of functions in a global or private forward's call list.
|
||||||
|
@ -95,8 +95,8 @@ int g_mapFileSerial = -1;
|
|||||||
|
|
||||||
MapChange g_ChangeTime;
|
MapChange g_ChangeTime;
|
||||||
|
|
||||||
Handle g_NominationsResetForward = null;
|
GlobalForward g_NominationsResetForward;
|
||||||
Handle g_MapVoteStartedForward = null;
|
GlobalForward g_MapVoteStartedForward;
|
||||||
|
|
||||||
/* Upper bound of how many team there could be */
|
/* Upper bound of how many team there could be */
|
||||||
#define MAXTEAMS 10
|
#define MAXTEAMS 10
|
||||||
@ -181,8 +181,8 @@ public void OnPluginStart()
|
|||||||
g_Cvar_Bonusroundtime.SetBounds(ConVarBound_Upper, true, 30.0);
|
g_Cvar_Bonusroundtime.SetBounds(ConVarBound_Upper, true, 30.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell);
|
g_NominationsResetForward = new GlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell);
|
||||||
g_MapVoteStartedForward = CreateGlobalForward("OnMapVoteStarted", ET_Ignore);
|
g_MapVoteStartedForward = new GlobalForward("OnMapVoteStarted", ET_Ignore);
|
||||||
}
|
}
|
||||||
|
|
||||||
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
|
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
|
||||||
|
Loading…
Reference in New Issue
Block a user