Add vote hud hook for lua #48

Merged
Indev450 merged 1 commits from lua-feature-votehud into Saturn 2023-08-30 13:51:29 +02:00
4 changed files with 67 additions and 12 deletions

No files matched your search

+1
View File
@@ -8735,6 +8735,7 @@ struct {
// Custom client features exposed to lua
{"FEATURE_INTERMISSIONHUD",1},
{"FEATURE_VOTEHUD",1},
#endif
{NULL,0}
+1
View File
@@ -44,5 +44,6 @@ boolean LUA_HudEnabled(enum hud option);
void LUAh_GameHUD(player_t *stplyr, huddrawlist_h list);
void LUAh_ScoresHUD(huddrawlist_h list);
void LUAh_IntermissionHUD(huddrawlist_h list);
void LUAh_VoteHUD(huddrawlist_h list);
#endif // __LUA_HUD_H__
+41 -3
View File
@@ -86,11 +86,13 @@ enum hudhook {
hudhook_game = 0,
hudhook_scores = 1,
hudhook_intermission = 2,
hudhook_vote = 3,
};
static const char *const hudhook_opt[] = {
"game",
"scores",
"intermission",
"vote",
NULL};
// alignment types for v.drawString
@@ -993,6 +995,9 @@ int LUA_HudLib(lua_State *L)
lua_newtable(L);
lua_rawseti(L, -2, 4); // HUD[4] = intermission rendering functions array
lua_newtable(L);
lua_rawseti(L, -2, 5); // HUD[5] = vote rendering functions array
lua_setfield(L, LUA_REGISTRYINDEX, "HUD");
luaL_newmetatable(L, META_HUDINFO);
@@ -1061,7 +1066,7 @@ void LUAh_GameHUD(player_t *stplayr, huddrawlist_h list)
lua_getfield(gL, LUA_REGISTRYINDEX, "HUD");
I_Assert(lua_istable(gL, -1));
lua_rawgeti(gL, -1, 2); // HUD[2] = rendering funcs
lua_rawgeti(gL, -1, hudhook_game+2); // HUD[2] = rendering funcs
I_Assert(lua_istable(gL, -1));
lua_rawgeti(gL, -2, 1); // HUD[1] = lib_draw
@@ -1119,7 +1124,7 @@ void LUAh_ScoresHUD(huddrawlist_h list)
lua_getfield(gL, LUA_REGISTRYINDEX, "HUD");
I_Assert(lua_istable(gL, -1));
lua_rawgeti(gL, -1, 3); // HUD[3] = rendering funcs
lua_rawgeti(gL, -1, hudhook_scores+2); // HUD[3] = rendering funcs
I_Assert(lua_istable(gL, -1));
lua_rawgeti(gL, -2, 1); // HUD[1] = lib_draw
@@ -1152,7 +1157,40 @@ void LUAh_IntermissionHUD(huddrawlist_h list)
lua_getfield(gL, LUA_REGISTRYINDEX, "HUD");
I_Assert(lua_istable(gL, -1));
lua_rawgeti(gL, -1, 4); // HUD[4] = rendering funcs
lua_rawgeti(gL, -1, hudhook_intermission+2); // HUD[4] = rendering funcs
I_Assert(lua_istable(gL, -1));
lua_rawgeti(gL, -2, 1); // HUD[1] = lib_draw
I_Assert(lua_istable(gL, -1));
lua_remove(gL, -3); // pop HUD
lua_pushnil(gL);
while (lua_next(gL, -3) != 0) {
lua_pushvalue(gL, -3); // graphics library (HUD[1])
LUA_Call(gL, 1, 0, 1);
}
lua_settop(gL, 0);
hud_running = false;
lua_pushlightuserdata(gL, NULL);
lua_setfield(gL, LUA_REGISTRYINDEX, "HUD_DRAW_LIST");
}
void LUAh_VoteHUD(huddrawlist_h list)
{
if (!gL || !(hudAvailable & (1<<hudhook_vote)))
return;
lua_pushlightuserdata(gL, list);
lua_setfield(gL, LUA_REGISTRYINDEX, "HUD_DRAW_LIST");
hud_running = true;
lua_settop(gL, 0);
lua_pushcfunction(gL, LUA_GetErrorMessage);
lua_getfield(gL, LUA_REGISTRYINDEX, "HUD");
I_Assert(lua_istable(gL, -1));
lua_rawgeti(gL, -1, hudhook_vote+2); // HUD[5] = rendering funcs
I_Assert(lua_istable(gL, -1));
lua_rawgeti(gL, -2, 1); // HUD[1] = lib_draw
+24 -9
View File
@@ -121,6 +121,7 @@ intertype_t intertype = int_none;
#ifdef HAVE_BLUA
static huddrawlist_h luahuddrawlist_intermission = NULL;
static huddrawlist_h luahuddrawlist_vote = NULL;
#endif
static void Y_FollowIntermission(void);
@@ -366,15 +367,6 @@ void Y_IntermissionDrawer(void)
if (usebuffer) // Fade everything out
V_DrawFadeScreen(0xFF00, 22);
#ifdef HAVE_BLUA
if (renderisnewtic)
{
LUA_HUD_ClearDrawList(luahuddrawlist_intermission);
LUAh_IntermissionHUD(luahuddrawlist_intermission);
}
LUA_HUD_DrawList(luahuddrawlist_intermission);
#endif
if (!splitscreen)
whiteplayer = demo.playback ? displayplayers[0] : consoleplayer;
@@ -609,6 +601,15 @@ dotimer:
// Make it obvious that scrambling is happening next round.
if (cv_scrambleonchange.value && cv_teamscramble.value && (intertic/TICRATE % 2 == 0))
V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT/2, hilicol, M_GetText("Teams will be scrambled next round!"));
#ifdef HAVE_BLUA
if (renderisnewtic)
{
LUA_HUD_ClearDrawList(luahuddrawlist_intermission);
LUAh_IntermissionHUD(luahuddrawlist_intermission);
}
LUA_HUD_DrawList(luahuddrawlist_intermission);
#endif
}
//
@@ -1230,6 +1231,15 @@ void Y_VoteDrawer(void)
V_DrawCenteredString(BASEVIDWIDTH/2, 188, hilicol,
va("Vote ends in %d", tickdown));
}
#ifdef HAVE_BLUA
if (renderisnewtic)
{
LUA_HUD_ClearDrawList(luahuddrawlist_vote);
LUAh_VoteHUD(luahuddrawlist_vote);
}
LUA_HUD_DrawList(luahuddrawlist_vote);
#endif
}
//
@@ -1559,6 +1569,11 @@ void Y_StartVote(void)
}
voteclient.loaded = true;
#ifdef HAVE_BLUA
LUA_HUD_DestroyDrawList(luahuddrawlist_vote);
luahuddrawlist_vote = LUA_HUD_CreateDrawList();
#endif
}
//