add keyhint forwards and forceUpdate (#1201)

* add keyhint forwards/remove unused params from topleft forwards

* allow forcing keyhint through pre forward

* implement track/style params, edit force updating logic

* doc touchups

* fix typo

* do some styling since the blame was already affected by the indentation changes

---------

Co-authored-by: Nimmy2222 <99696781+Nimmy2222@users.noreply.github.com>
Co-authored-by: rtldg <55846624+rtldg@users.noreply.github.com>
This commit is contained in:
enimmy 2024-03-12 08:51:37 -04:00 committed by GitHub
parent 64d6a1d9f3
commit d57ec73adb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 294 additions and 188 deletions

View File

@ -138,10 +138,40 @@ forward Action Shavit_OnTopLeftHUD(int client, int target, char[] topleft, int t
* @param topleftlength Max length of the topleft buffer.
* @param track Target's track.
* @param style Target's style.
* @param forceUpdate Force even if the client has disabled HUD_TOPLEFT.
*
* @return Plugin_Handled or Plugin_Stop to block the HUD message from appearing. Plugin_Changed to use own topleft string instead of shavit-hud building it.
*/
forward Action Shavit_PreOnTopLeftHUD(int client, int target, char[] topleft, int topleftlength, int track, int style);
forward Action Shavit_PreOnTopLeftHUD(int client, int target, char[] topleft, int topleftlength, int track, int style, bool &forceUpdate);
/**
* Called when key hint (bottom left) HUD updates (Source 2013 only).
*
* @param client Client index that recieves the hud.
* @param target Target entity that is either the client or what the client is spectating.
* @param keyhint Reference to the HUD buffer.
* @param keyhintlength Max length of the keyhint buffer.
* @param track Target's track.
* @param style Target's style.
*
* @return Plugin_Handled or Plugin_Stop to block the HUD message from appearing. Anything else to pass along new values.
*/
forward Action Shavit_OnKeyHintHUD(int client, int target, char[] keyhint, int keyhintlength, int track, int style);
/**
* Called before the key hint HUD (bottom left) updates and used to build the string for shavit-hud (Source 2013 only).
*
* @param client Client index that recieves the hud.
* @param target Target entity that is either the client or what the client is spectating.
* @param keyhint Reference to the HUD buffer.
* @param keyhintlength Max length of the keyhint buffer.
* @param track Target's track.
* @param style Target's style.
* @param forceUpdate Force even if the client has disabled HUD_SYNC, HUD_TIMELEFT, and HUD2_PERFS.
*
* @return Plugin_Handled or Plugin_Stop to block the HUD message from appearing. Plugin_Changed to use own keyhint string instead of shavit-hud building it.
*/
forward Action Shavit_PreOnKeyHintHUD(int client, int target, char[] keyhint, int keyhintlength, int track, int style, bool &forceUpdate);
/**
* Called before the center hud updates.

View File

@ -63,6 +63,8 @@ UserMsg gI_TextMsg = view_as<UserMsg>(-1);
// forwards
Handle gH_Forwards_OnTopLeftHUD = null;
Handle gH_Forwards_PreOnTopLeftHUD = null;
Handle gH_Forwards_OnKeyHintHUD = null;
Handle gH_Forwards_PreOnKeyHintHUD = null;
Handle gH_Forwards_PreOnDrawCenterHUD = null;
Handle gH_Forwards_PreOnDrawKeysHUD = null;
@ -129,7 +131,9 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
{
// forwards
gH_Forwards_OnTopLeftHUD = CreateGlobalForward("Shavit_OnTopLeftHUD", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Cell, Param_Cell);
gH_Forwards_PreOnTopLeftHUD = CreateGlobalForward("Shavit_PreOnTopLeftHUD", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Cell, Param_Cell);
gH_Forwards_PreOnTopLeftHUD = CreateGlobalForward("Shavit_PreOnTopLeftHUD", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Cell, Param_Cell, Param_CellByRef);
gH_Forwards_OnKeyHintHUD = CreateGlobalForward("Shavit_OnKeyHintHUD", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Cell, Param_Cell);
gH_Forwards_PreOnKeyHintHUD = CreateGlobalForward("Shavit_PreOnKeyHintHUD", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Cell, Param_Cell, Param_CellByRef);
gH_Forwards_PreOnDrawCenterHUD = CreateGlobalForward("Shavit_PreOnDrawCenterHUD", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Array);
gH_Forwards_PreOnDrawKeysHUD = CreateGlobalForward("Shavit_PreOnDrawKeysHUD", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
@ -2134,8 +2138,11 @@ void UpdateSpectatorList(int client, Panel panel, bool &draw)
void UpdateTopLeftHUD(int client, bool wait)
{
if((!wait || gI_Cycle % 20 == 0) && (gI_HUDSettings[client] & HUD_TOPLEFT) > 0)
if (wait && gI_Cycle % 20 != 0)
{
return;
}
int target = GetSpectatorTarget(client, client);
bool bReplay = (gB_ReplayPlayback && Shavit_IsReplayEntity(target));
@ -2163,16 +2170,24 @@ void UpdateTopLeftHUD(int client, bool wait)
style = (style == -1) ? 0 : style; // central replay bot probably
track = (track == -1) ? 0 : track; // central replay bot probably
if ((0 <= style < gI_Styles) && (0 <= track <= TRACKS_SIZE))
if (!(0 <= style < gI_Styles) || !(0 <= track <= TRACKS_SIZE))
{
return;
}
char sTopLeft[512];
Action preresult = Plugin_Continue;
bool forceUpdate = false;
Call_StartForward(gH_Forwards_PreOnTopLeftHUD);
Call_PushCell(client);
Call_PushCell(target);
Call_PushStringEx(sTopLeft, sizeof(sTopLeft), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
Call_PushCell(sizeof(sTopLeft));
Call_PushCell(track);
Call_PushCell(style);
Call_PushCellRef(forceUpdate);
Call_Finish(preresult);
if (preresult == Plugin_Handled || preresult == Plugin_Stop)
@ -2180,6 +2195,13 @@ void UpdateTopLeftHUD(int client, bool wait)
return;
}
if (!(gI_HUDSettings[client] & HUD_TOPLEFT) && !forceUpdate)
{
return;
}
if ((gI_HUDSettings[client] & HUD_TOPLEFT))
{
float fWRTime = Shavit_GetWorldRecord(style, track);
if (fWRTime != 0.0)
@ -2190,7 +2212,7 @@ void UpdateTopLeftHUD(int client, bool wait)
char sWRName[MAX_NAME_LENGTH];
Shavit_GetWRName(style, sWRName, MAX_NAME_LENGTH, track);
FormatEx(sTopLeft, sizeof(sTopLeft), "WR: %s (%s)", sWRTime, sWRName);
FormatEx(sTopLeft, sizeof(sTopLeft), "%sWR: %s (%s)", sTopLeft, sWRTime, sWRName);
}
char sTargetPB[64];
@ -2232,6 +2254,7 @@ void UpdateTopLeftHUD(int client, bool wait)
{
Format(sTopLeft, sizeof(sTopLeft), "%s\n%s (#%d)", sTopLeft, sSelfPB, Shavit_GetRankForTime(style, fSelfPB, track));
}
}
Action postresult = Plugin_Continue;
Call_StartForward(gH_Forwards_OnTopLeftHUD);
@ -2239,6 +2262,8 @@ void UpdateTopLeftHUD(int client, bool wait)
Call_PushCell(target);
Call_PushStringEx(sTopLeft, sizeof(sTopLeft), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
Call_PushCell(sizeof(sTopLeft));
Call_PushCell(track);
Call_PushCell(style);
Call_Finish(postresult);
if (postresult != Plugin_Continue && postresult != Plugin_Changed)
@ -2257,37 +2282,75 @@ void UpdateTopLeftHUD(int client, bool wait)
ShowSyncHudText(client, gH_HUDTopleft, "%s", sTopLeft);
}
}
}
}
void UpdateKeyHint(int client)
{
if ((gI_Cycle % 10) == 0 && ((gI_HUDSettings[client] & HUD_SYNC) > 0 || (gI_HUDSettings[client] & HUD_TIMELEFT) > 0 || !(gI_HUD2Settings[client] & HUD2_PERFS)))
{
char sMessage[256];
int iTimeLeft = -1;
if((gI_HUDSettings[client] & HUD_TIMELEFT) > 0 && GetMapTimeLeft(iTimeLeft) && iTimeLeft > 0)
{
FormatEx(sMessage, 256, (iTimeLeft > 150)? "%T: %d minutes":"%T: %d seconds", "HudTimeLeft", client, (iTimeLeft > 150) ? (iTimeLeft / 60)+1 : iTimeLeft);
}
int target = GetSpectatorTarget(client, client);
if(target == client || (gI_HUDSettings[client] & HUD_OBSERVE) > 0)
{
int bReplay = gB_ReplayPlayback && Shavit_IsReplayEntity(target);
if (!bReplay && !IsValidClient(target))
if ((gI_Cycle % 10) != 0)
{
return;
}
int style = bReplay ? Shavit_GetReplayBotStyle(target) : Shavit_GetBhopStyle(target);
char sMessage[256];
int iTimeLeft = -1;
if(!(0 <= style < gI_Styles))
int target = GetSpectatorTarget(client, client);
int bReplay = gB_ReplayPlayback && Shavit_IsReplayEntity(target);
int style;
int track;
if (!bReplay)
{
style = 0;
style = Shavit_GetBhopStyle(target);
track = Shavit_GetClientTrack(target);
}
else
{
style = Shavit_GetReplayBotStyle(target);
track = Shavit_GetReplayBotTrack(target);
}
style = (style == -1) ? 0 : style;
track = (track == -1) ? 0 : track;
if (!(0 <= style < gI_Styles) || !(0 <= track <= TRACKS_SIZE))
{
return;
}
Action preresult = Plugin_Continue;
bool forceUpdate = false;
Call_StartForward(gH_Forwards_PreOnKeyHintHUD);
Call_PushCell(client);
Call_PushCell(target);
Call_PushStringEx(sMessage, sizeof(sMessage), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
Call_PushCell(sizeof(sMessage));
Call_PushCell(track);
Call_PushCell(style);
Call_PushCellRef(forceUpdate);
Call_Finish(preresult);
if (preresult == Plugin_Handled || preresult == Plugin_Stop)
{
return;
}
if (!forceUpdate && !(gI_HUDSettings[client] & HUD_SYNC) && !(gI_HUDSettings[client] & HUD_TIMELEFT) && gI_HUD2Settings[client] & HUD2_PERFS)
{
return;
}
if ((gI_HUDSettings[client] & HUD_TIMELEFT) > 0 && GetMapTimeLeft(iTimeLeft) && iTimeLeft > 0)
{
FormatEx(sMessage, 256, (iTimeLeft > 150)? "%s%T: %d minutes":"%T: %d seconds", sMessage, "HudTimeLeft", client, (iTimeLeft > 150) ? (iTimeLeft / 60)+1 : iTimeLeft);
}
if (target == client || (gI_HUDSettings[client] & HUD_OBSERVE) > 0)
{
if (!bReplay && !IsValidClient(target))
{
return;
}
if (!bReplay && Shavit_GetTimerStatus(target) != Timer_Stopped)
@ -2338,7 +2401,6 @@ void UpdateKeyHint(int client)
if (i == 7)
{
Format(sMessage, 256, "%s\n...", sMessage);
break;
}
@ -2351,6 +2413,21 @@ void UpdateKeyHint(int client)
}
}
Action postresult = Plugin_Continue;
Call_StartForward(gH_Forwards_OnKeyHintHUD);
Call_PushCell(client);
Call_PushCell(target);
Call_PushStringEx(sMessage, sizeof(sMessage), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
Call_PushCell(sizeof(sMessage));
Call_PushCell(track);
Call_PushCell(style);
Call_Finish(postresult);
if (postresult == Plugin_Handled || postresult == Plugin_Stop)
{
return;
}
if (strlen(sMessage) > 0)
{
Handle hKeyHintText = StartMessageOne("KeyHintText", client);
@ -2359,7 +2436,6 @@ void UpdateKeyHint(int client)
EndMessage();
}
}
}
public int PanelHandler_Nothing(Menu m, MenuAction action, int param1, int param2)
{