Add 'time per frame' argument for hud.setVoteBackground

This commit is contained in:
indev committed 2025-12-02 23:59:02 +03:00
1 parent 56d1343f1b
commit ccfab57a8c
3 files changed
+24 -10

No files matched your search

+19 -9
View File
@@ -1287,22 +1287,32 @@ extern int lib_hudadd(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;
}
// Update background if we're already on vote screen
if (gamestate == GS_VOTING)
+4 -1
View File
@@ -831,6 +831,9 @@ 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
@@ -922,7 +925,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;
}
+1
View File
@@ -79,6 +79,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