Add 'time per frame' argument for hud.setVoteBackground

This commit is contained in:
Indev 2025-12-02 23:53:32 +03:00 committed by NepDisk
parent 636120b109
commit ad58341eb2
3 changed files with 24 additions and 10 deletions

View file

@ -1611,22 +1611,32 @@ static int lib_hudenabled(lua_State *L)
static int lib_hudsetvotebackground(lua_State *L)
{
// Reset to default
memset(VoteScreen.luaPrefix, 0, sizeof(VoteScreen.luaPrefix));
VoteScreen.timePerAnimFrame = 2;
if (lua_isnoneornil(L, 1))
if (!lua_isnoneornil(L, 1))
{
return 0;
const char *prefix = luaL_checkstring(L, 1);
if (strlen(prefix) != 4)
{
return luaL_argerror(L, 1, "prefix should 4 characters wide");
}
strncpy(VoteScreen.luaPrefix, prefix, 4);
strupr(VoteScreen.luaPrefix);
}
const char *prefix = luaL_checkstring(L, 1);
if (strlen(prefix) != 4)
if (!lua_isnoneornil(L, 2))
{
return luaL_argerror(L, 1, "prefix should 4 characters wide");
}
INT32 time_per_frame = luaL_checkinteger(L, 2);
strncpy(VoteScreen.luaPrefix, prefix, 4);
strupr(VoteScreen.luaPrefix);
if (time_per_frame <= 0)
return luaL_argerror(L, 2, "time per frame should be 1 or more");
VoteScreen.timePerAnimFrame = time_per_frame;
}
return 0;
}

View file

@ -1082,6 +1082,9 @@ static void Y_VoteScreenCheck(void)
VoteScreen.foundLuaVoteFrames = VoteScreen.foundLuaVoteWideFrames = 0;
VoteScreen.currentAnimFrame = 0;
if (VoteScreen.timePerAnimFrame == 0)
VoteScreen.timePerAnimFrame = 2;
INT32 i = 1;
// check for lua vote background replacements
@ -1173,7 +1176,7 @@ static void Y_DrawLuaVoteScreenPatch(boolean widePatch)
Y_VoteBackgroundDrawer(votebg);
if (renderisnewtic && (votetic % 2 == 0) && !paused)
if (renderisnewtic && (votetic % VoteScreen.timePerAnimFrame == 0) && !paused)
VoteScreen.currentAnimFrame = (nextframe > tempfoundAnimLuaVoteFrames) ? 0 : nextframe;
}

View file

@ -65,6 +65,7 @@ typedef struct
char luaPrefix[5]; // prefix for lua votescreens
INT32 currentAnimFrame; // current animated background frame
INT32 timePerAnimFrame; // time for 1 frame in ticks, 2 by default
INT32 foundLuaVoteFrames; // normal lua patch frames
INT32 foundLuaVoteWideFrames; // widescreen lua patch frames