Added ability for Lua to show/hide SM64 HUD

This commit is contained in:
MysterD 2022-03-10 18:33:52 -08:00
parent 497a250476
commit 859feb530d
9 changed files with 98 additions and 11 deletions

View File

@ -624,6 +624,8 @@
- smlua_misc_utils.h
- [get_network_area_timer](#get_network_area_timer)
- [hud_hide](#hud_hide)
- [hud_show](#hud_show)
<br />
@ -11461,6 +11463,42 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
<br />
## [hud_hide](#hud_hide)
### Lua Example
`hud_hide()`
### Parameters
- None
### Returns
- None
### C Prototype
`void hud_hide(void);`
[:arrow_up_small:](#)
<br />
## [hud_show](#hud_show)
### Lua Example
`hud_show()`
### Parameters
- None
### Returns
- None
### C Prototype
`void hud_show(void);`
[:arrow_up_small:](#)
<br />
---
# functions from smlua_obj_utils.h

View File

@ -679,6 +679,9 @@ gGlobalSyncTable.scoreRed = 0
gGlobalSyncTable.scoreBlue = 0
function gamemode_initialize()
-- hide the SM64 HUD
hud_hide()
-- prevent warp doors from working
local wasRefreshed = false
local obj = obj_get_first(OBJ_LIST_SURFACE)

View File

@ -18,6 +18,7 @@
#include "pc/network/network.h"
extern bool gDjuiInMainMenu;
u8 gOverrideHideHud;
/* @file hud.c
* This file implements HUD rendering and power meter animations.
@ -492,32 +493,34 @@ void render_hud(void) {
create_dl_ortho_matrix();
#endif
bool showHud = (configHUD && !gDjuiInMainMenu && !gOverrideHideHud);
if (gCurrentArea != NULL && gCurrentArea->camera->mode == CAMERA_MODE_INSIDE_CANNON) {
render_hud_cannon_reticle();
}
if (hudDisplayFlags & HUD_DISPLAY_FLAG_LIVES && configHUD && !gDjuiInMainMenu) {
if (hudDisplayFlags & HUD_DISPLAY_FLAG_LIVES && showHud) {
render_hud_mario_lives();
}
if (hudDisplayFlags & HUD_DISPLAY_FLAG_COIN_COUNT && configHUD && !gDjuiInMainMenu) {
if (hudDisplayFlags & HUD_DISPLAY_FLAG_COIN_COUNT && showHud) {
render_hud_coins();
}
if (hudDisplayFlags & HUD_DISPLAY_FLAG_STAR_COUNT && configHUD && !gDjuiInMainMenu) {
if (hudDisplayFlags & HUD_DISPLAY_FLAG_STAR_COUNT && showHud) {
render_hud_stars();
}
if (hudDisplayFlags & HUD_DISPLAY_FLAG_KEYS && configHUD && !gDjuiInMainMenu) {
if (hudDisplayFlags & HUD_DISPLAY_FLAG_KEYS && showHud) {
render_hud_keys();
}
if (hudDisplayFlags & HUD_DISPLAY_FLAG_CAMERA_AND_POWER && configHUD && !gDjuiInMainMenu) {
if (hudDisplayFlags & HUD_DISPLAY_FLAG_CAMERA_AND_POWER && showHud) {
render_hud_power_meter();
render_hud_camera_status();
}
if (hudDisplayFlags & HUD_DISPLAY_FLAG_TIMER && configHUD && !gDjuiInMainMenu) {
if (hudDisplayFlags & HUD_DISPLAY_FLAG_TIMER && showHud) {
render_hud_timer();
}
}

View File

@ -25,6 +25,8 @@ enum CameraHUDLut {
GLYPH_CAM_WARIO_HEAD,
};
u8 gOverrideHideHud;
void set_hud_camera_status(s16 status);
void render_hud(void);

View File

@ -7304,6 +7304,24 @@ int smlua_func_get_network_area_timer(UNUSED lua_State* L) {
return 1;
}
int smlua_func_hud_hide(UNUSED lua_State* L) {
if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
hud_hide();
return 1;
}
int smlua_func_hud_show(UNUSED lua_State* L) {
if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
hud_show();
return 1;
}
///////////////////////
// smlua_obj_utils.h //
///////////////////////
@ -8618,6 +8636,8 @@ void smlua_bind_functions_autogen(void) {
// smlua_misc_utils.h
smlua_bind_function(L, "get_network_area_timer", smlua_func_get_network_area_timer);
smlua_bind_function(L, "hud_hide", smlua_func_hud_hide);
smlua_bind_function(L, "hud_show", smlua_func_hud_show);
// smlua_obj_utils.h
smlua_bind_function(L, "obj_get_first", smlua_func_obj_get_first);

View File

@ -1,9 +1,19 @@
#include "types.h"
#include "game/hud.h"
#include "pc/lua/smlua.h"
#include "smlua_misc_utils.h"
#include "pc/debuglog.h"
u32 get_network_area_timer(void) {
return gNetworkAreaTimer;
}
}
void hud_hide(void) {
gOverrideHideHud = 1;
}
void hud_show(void) {
gOverrideHideHud = 0;
}

View File

@ -3,4 +3,7 @@
u32 get_network_area_timer(void);
void hud_hide(void);
void hud_show(void);
#endif

View File

@ -66,6 +66,10 @@ void network_set_system(enum NetworkSystemType nsType) {
}
bool network_init(enum NetworkType inNetworkType) {
// reset override hide hud
extern u8 gOverrideHideHud;
gOverrideHideHud = 0;
// sanity check network system
if (gNetworkSystem == NULL) {
LOG_ERROR("no network system attached");

View File

@ -120,16 +120,20 @@ struct NetworkPlayer* get_network_player_smallest_global(void) {
}
void network_player_update(void) {
for (int i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* np = &gNetworkPlayers[i];
if (!np->connected && i > 0) { continue; }
network_player_update_model(i);
}
if (!network_player_any_connected()) { return; }
if (gNetworkType == NT_SERVER) {
for (int i = 0; i < MAX_PLAYERS; i++) {
for (int i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* np = &gNetworkPlayers[i];
if (!np->connected && i > 0) { continue; }
network_player_update_model(i);
if (i == 0) { continue; }
float elapsed = (clock_elapsed() - np->lastReceived);
#ifndef DEVELOPMENT
if (elapsed > NETWORK_PLAYER_TIMEOUT) {