From 0f652bc39906e8339593f02527980ff609485865 Mon Sep 17 00:00:00 2001 From: Nimmy2222 <99696781+Nimmy2222@users.noreply.github.com> Date: Fri, 26 Jan 2024 22:01:09 -0500 Subject: [PATCH] implement track/style params, edit force updating logic --- .../scripting/include/shavit/hud.inc | 16 +- addons/sourcemod/scripting/shavit-hud.sp | 265 ++++++++++-------- 2 files changed, 162 insertions(+), 119 deletions(-) diff --git a/addons/sourcemod/scripting/include/shavit/hud.inc b/addons/sourcemod/scripting/include/shavit/hud.inc index 74a139b16..45d11f10b 100644 --- a/addons/sourcemod/scripting/include/shavit/hud.inc +++ b/addons/sourcemod/scripting/include/shavit/hud.inc @@ -122,10 +122,12 @@ enum struct huddata_t * @param target Target entity that is either the client or what the client is spectating. * @param topleft Reference to the HUD buffer. * @param topleftlength Max length of the topleft buffer. + * @param track Clients current track + * @param style Clients current style * * @return Plugin_Handled or Plugin_Stop to block the HUD message from appearing. Anything else to pass along new values. */ -forward Action Shavit_OnTopLeftHUD(int client, int target, char[] topleft, int topleftlength); +forward Action Shavit_OnTopLeftHUD(int client, int target, char[] topleft, int topleftlength, int track, int style); /** * Called before the top left HUD updates and used to build the string for shavit-hud. @@ -134,10 +136,12 @@ forward Action Shavit_OnTopLeftHUD(int client, int target, char[] topleft, int t * @param target Target entity that is either the client or what the client is spectating. * @param topleft Reference to the HUD buffer. * @param topleftlength Max length of the topleft buffer. + * @param track Clients current track + * @param style Clients current style * * @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); +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). @@ -146,10 +150,12 @@ forward Action Shavit_PreOnTopLeftHUD(int client, int target, char[] topleft, in * @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 Clients current track + * @param style Clients current 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); +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). @@ -158,10 +164,12 @@ forward Action Shavit_OnKeyHintHUD(int client, int target, char[] keyhint, int k * @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 Clients current track + * @param style Clients current style * * @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); +forward Action Shavit_PreOnKeyHintHUD(int client, int target, char[] keyhint, int keyhintlength, int track, int style, bool &forceUpdate); /** * Called before the center hud updates. diff --git a/addons/sourcemod/scripting/shavit-hud.sp b/addons/sourcemod/scripting/shavit-hud.sp index 30b23ef4d..b94693dee 100644 --- a/addons/sourcemod/scripting/shavit-hud.sp +++ b/addons/sourcemod/scripting/shavit-hud.sp @@ -130,10 +130,10 @@ public Plugin myinfo = 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); - gH_Forwards_PreOnTopLeftHUD = CreateGlobalForward("Shavit_PreOnTopLeftHUD", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell); - gH_Forwards_OnKeyHintHUD = CreateGlobalForward("Shavit_OnKeyHintHUD", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell); - gH_Forwards_PreOnKeyHintHUD = CreateGlobalForward("Shavit_PreOnKeyHintHUD", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell); + 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, 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); @@ -2138,129 +2138,148 @@ 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) { - int target = GetSpectatorTarget(client, client); - bool bReplay = (gB_ReplayPlayback && Shavit_IsReplayEntity(target)); + return; + } - if (!bReplay && !IsValidClient(target)) - { - return; - } + int target = GetSpectatorTarget(client, client); + bool bReplay = (gB_ReplayPlayback && Shavit_IsReplayEntity(target)); - int track = 0; - int style = 0; - float fTargetPB = 0.0; + if (!bReplay && !IsValidClient(target)) + { + return; + } - if(!bReplay) - { - style = Shavit_GetBhopStyle(target); - track = Shavit_GetClientTrack(target); - fTargetPB = Shavit_GetClientPB(target, style, track); - } - else - { - style = Shavit_GetReplayBotStyle(target); - track = Shavit_GetReplayBotTrack(target); - } + int track = 0; + int style = 0; + float fTargetPB = 0.0; - style = (style == -1) ? 0 : style; // central replay bot probably - track = (track == -1) ? 0 : track; // central replay bot probably + if(!bReplay) + { + style = Shavit_GetBhopStyle(target); + track = Shavit_GetClientTrack(target); + fTargetPB = Shavit_GetClientPB(target, style, track); + } + else + { + style = Shavit_GetReplayBotStyle(target); + track = Shavit_GetReplayBotTrack(target); + } - if ((0 <= style < gI_Styles) && (0 <= track <= TRACKS_SIZE)) - { - char sTopLeft[512]; + style = (style == -1) ? 0 : style; // central replay bot probably + track = (track == -1) ? 0 : track; // central replay bot probably - Action preresult = Plugin_Continue; - 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_Finish(preresult); + if (!(0 <= style < gI_Styles) && !(0 <= track <= TRACKS_SIZE)) + { + return; + } - if (preresult == Plugin_Handled || preresult == Plugin_Stop) - { - return; - } + char sTopLeft[512]; - float fWRTime = Shavit_GetWorldRecord(style, track); + Action preresult = Plugin_Continue; + bool forceUpdate = false; - if (fWRTime != 0.0) - { - char sWRTime[16]; - FormatSeconds(fWRTime, sWRTime, 16); + 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); - char sWRName[MAX_NAME_LENGTH]; - Shavit_GetWRName(style, sWRName, MAX_NAME_LENGTH, track); + if (preresult == Plugin_Handled || preresult == Plugin_Stop) + { + return; + } - FormatEx(sTopLeft, sizeof(sTopLeft), "WR: %s (%s)", sWRTime, sWRName); - } + if(!(gI_HUDSettings[client] & HUD_TOPLEFT) && !forceUpdate) + { + return; + } - char sTargetPB[64]; - FormatSeconds(fTargetPB, sTargetPB, sizeof(sTargetPB)); - Format(sTargetPB, sizeof(sTargetPB), "%T: %s", "HudBestText", client, sTargetPB); + if((gI_HUDSettings[client] & HUD_TOPLEFT)) + { + float fWRTime = Shavit_GetWorldRecord(style, track); + + if (fWRTime != 0.0) + { + char sWRTime[16]; + FormatSeconds(fWRTime, sWRTime, 16); + + char sWRName[MAX_NAME_LENGTH]; + Shavit_GetWRName(style, sWRName, MAX_NAME_LENGTH, track); + + FormatEx(sTopLeft, sizeof(sTopLeft), "%sWR: %s (%s)", sTopLeft, sWRTime, sWRName); + } + + char sTargetPB[64]; + FormatSeconds(fTargetPB, sTargetPB, sizeof(sTargetPB)); + Format(sTargetPB, sizeof(sTargetPB), "%T: %s", "HudBestText", client, sTargetPB); - float fSelfPB = Shavit_GetClientPB(client, style, track); - char sSelfPB[64]; - FormatSeconds(fSelfPB, sSelfPB, sizeof(sSelfPB)); - Format(sSelfPB, sizeof(sSelfPB), "%T: %s", "HudBestText", client, sSelfPB); + float fSelfPB = Shavit_GetClientPB(client, style, track); + char sSelfPB[64]; + FormatSeconds(fSelfPB, sSelfPB, sizeof(sSelfPB)); + Format(sSelfPB, sizeof(sSelfPB), "%T: %s", "HudBestText", client, sSelfPB); - if((gI_HUD2Settings[client] & HUD2_SPLITPB) == 0 && target != client) + if((gI_HUD2Settings[client] & HUD2_SPLITPB) == 0 && target != client) + { + if(fTargetPB != 0.0) { - if(fTargetPB != 0.0) + if((gI_HUD2Settings[client]& HUD2_TOPLEFT_RANK) == 0) { - if((gI_HUD2Settings[client]& HUD2_TOPLEFT_RANK) == 0) - { - Format(sTopLeft, sizeof(sTopLeft), "%s\n%s (#%d) (%N)", sTopLeft, sTargetPB, Shavit_GetRankForTime(style, fTargetPB, track), target); - } - else - { - Format(sTopLeft, sizeof(sTopLeft), "%s\n%s (%N)", sTopLeft, sTargetPB, target); - } + Format(sTopLeft, sizeof(sTopLeft), "%s\n%s (#%d) (%N)", sTopLeft, sTargetPB, Shavit_GetRankForTime(style, fTargetPB, track), target); } - - if(fSelfPB != 0.0) + else { - if((gI_HUD2Settings[client]& HUD2_TOPLEFT_RANK) == 0) - { - Format(sTopLeft, sizeof(sTopLeft), "%s\n%s (#%d) (%N)", sTopLeft, sSelfPB, Shavit_GetRankForTime(style, fSelfPB, track), client); - } - else - { - Format(sTopLeft, sizeof(sTopLeft), "%s\n%s (%N)", sTopLeft, sSelfPB, client); - } + Format(sTopLeft, sizeof(sTopLeft), "%s\n%s (%N)", sTopLeft, sTargetPB, target); } } - else if(fSelfPB != 0.0) + + if(fSelfPB != 0.0) { - Format(sTopLeft, sizeof(sTopLeft), "%s\n%s (#%d)", sTopLeft, sSelfPB, Shavit_GetRankForTime(style, fSelfPB, track)); + if((gI_HUD2Settings[client]& HUD2_TOPLEFT_RANK) == 0) + { + Format(sTopLeft, sizeof(sTopLeft), "%s\n%s (#%d) (%N)", sTopLeft, sSelfPB, Shavit_GetRankForTime(style, fSelfPB, track), client); + } + else + { + Format(sTopLeft, sizeof(sTopLeft), "%s\n%s (%N)", sTopLeft, sSelfPB, client); + } } + } + else if(fSelfPB != 0.0) + { + Format(sTopLeft, sizeof(sTopLeft), "%s\n%s (#%d)", sTopLeft, sSelfPB, Shavit_GetRankForTime(style, fSelfPB, track)); + } + } - Action postresult = Plugin_Continue; - Call_StartForward(gH_Forwards_OnTopLeftHUD); - Call_PushCell(client); - Call_PushCell(target); - Call_PushStringEx(sTopLeft, sizeof(sTopLeft), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); - Call_PushCell(sizeof(sTopLeft)); - Call_Finish(postresult); + Action postresult = Plugin_Continue; + Call_StartForward(gH_Forwards_OnTopLeftHUD); + 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_Finish(postresult); - if (postresult != Plugin_Continue && postresult != Plugin_Changed) - { - return; - } + if (postresult != Plugin_Continue && postresult != Plugin_Changed) + { + return; + } - SetHudTextParams(0.01, 0.01, 2.6, 255, 255, 255, 255, 0, 0.0, 0.0, 0.0); + SetHudTextParams(0.01, 0.01, 2.6, 255, 255, 255, 255, 0, 0.0, 0.0, 0.0); - if (gB_DynamicChannels) - { - ShowHudText(client, GetDynamicChannel(5), "%s", sTopLeft); - } - else - { - ShowSyncHudText(client, gH_HUDTopleft, "%s", sTopLeft); - } - } + if (gB_DynamicChannels) + { + ShowHudText(client, GetDynamicChannel(5), "%s", sTopLeft); + } + else + { + ShowSyncHudText(client, gH_HUDTopleft, "%s", sTopLeft); } } @@ -2277,12 +2296,40 @@ void UpdateKeyHint(int client) int target = GetSpectatorTarget(client, client); + int bReplay = gB_ReplayPlayback && Shavit_IsReplayEntity(target); + int style; + int track; + + if(!bReplay) + { + 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) @@ -2290,17 +2337,11 @@ void UpdateKeyHint(int client) return; } - //Allows listening plugins to force this function despite player settings for sync, timeleft, perfs - if(strlen(sMessage) == 0 && !(gI_HUDSettings[client] & HUD_SYNC) && !(gI_HUDSettings[client] & HUD_TIMELEFT) && gI_HUD2Settings[client] & HUD2_PERFS) + if(!forceUpdate && !(gI_HUDSettings[client] & HUD_SYNC) && !(gI_HUDSettings[client] & HUD_TIMELEFT) && gI_HUD2Settings[client] & HUD2_PERFS) { return; } - if(strlen(sMessage) > 0) - { - FormatEx(sMessage, sizeof(sMessage), "%s\n", sMessage); - } - 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); @@ -2308,20 +2349,12 @@ void UpdateKeyHint(int client) if(target == client || (gI_HUDSettings[client] & HUD_OBSERVE) > 0) { - int bReplay = gB_ReplayPlayback && Shavit_IsReplayEntity(target); if (!bReplay && !IsValidClient(target)) { return; } - int style = bReplay ? Shavit_GetReplayBotStyle(target) : Shavit_GetBhopStyle(target); - - if(!(0 <= style < gI_Styles)) - { - style = 0; - } - if (!bReplay && Shavit_GetTimerStatus(target) != Timer_Stopped) { bool perf_double_newline = true; @@ -2389,6 +2422,8 @@ void UpdateKeyHint(int 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)