Added HOOK_ON_RENDER_BEHIND, deprecated djui_hud_set_render_behind_hud()

This commit is contained in:
MysterD 2023-11-07 15:50:49 -08:00
parent ffc45277c4
commit cda2480ba4
21 changed files with 96 additions and 72 deletions

View File

@ -8999,7 +8999,10 @@ HOOK_ON_OBJECT_ANIM_UPDATE = 32
HOOK_ON_DIALOG = 33
--- @type LuaHookedEventType
HOOK_MAX = 34
HOOK_ON_HUD_RENDER_BEHIND = 34
--- @type LuaHookedEventType
HOOK_MAX = 35
--- @class HudDisplayFlags

View File

@ -3742,12 +3742,6 @@ function djui_hud_set_mouse_locked(locked)
-- ...
end
--- @param enable boolean
--- @return nil
function djui_hud_set_render_behind_hud(enable)
-- ...
end
--- @param resolutionType HudUtilsResolution
--- @return nil
function djui_hud_set_resolution(resolutionType)
@ -8266,6 +8260,12 @@ function smlua_collision_util_get(name)
-- ...
end
--- @param enable boolean
--- @return nil
function djui_hud_set_render_behind_hud(enable)
-- ...
end
--- @param localIndex integer
--- @return string
function network_discord_id_from_local_index(localIndex)

View File

@ -1028,6 +1028,7 @@
--- @field public isDirectory boolean
--- @field public name string
--- @field public relativePath string
--- @field public renderBehindHud boolean
--- @field public selectable boolean
--- @class ModFile

View File

@ -3198,7 +3198,8 @@
| HOOK_JOINED_GAME | 31 |
| HOOK_ON_OBJECT_ANIM_UPDATE | 32 |
| HOOK_ON_DIALOG | 33 |
| HOOK_MAX | 34 |
| HOOK_ON_HUD_RENDER_BEHIND | 34 |
| HOOK_MAX | 35 |
[:arrow_up_small:](#)

View File

@ -2406,26 +2406,6 @@
<br />
## [djui_hud_set_render_behind_hud](#djui_hud_set_render_behind_hud)
### Lua Example
`djui_hud_set_render_behind_hud(enable)`
### Parameters
| Field | Type |
| ----- | ---- |
| enable | `boolean` |
### Returns
- None
### C Prototype
`void djui_hud_set_render_behind_hud(bool enable);`
[:arrow_up_small:](#)
<br />
## [djui_hud_set_resolution](#djui_hud_set_resolution)
### Lua Example

View File

@ -738,7 +738,6 @@
- [djui_hud_set_color](functions-3.md#djui_hud_set_color)
- [djui_hud_set_font](functions-3.md#djui_hud_set_font)
- [djui_hud_set_mouse_locked](functions-3.md#djui_hud_set_mouse_locked)
- [djui_hud_set_render_behind_hud](functions-3.md#djui_hud_set_render_behind_hud)
- [djui_hud_set_resolution](functions-3.md#djui_hud_set_resolution)
- [djui_hud_set_rotation](functions-3.md#djui_hud_set_rotation)
- [djui_hud_world_pos_to_screen_pos](functions-3.md#djui_hud_world_pos_to_screen_pos)

View File

@ -1381,6 +1381,7 @@
| isDirectory | `boolean` | read-only |
| name | `string` | read-only |
| relativePath | `string` | read-only |
| renderBehindHud | `boolean` | read-only |
| selectable | `boolean` | read-only |
[:arrow_up_small:](#)

View File

@ -442,11 +442,11 @@ void render_game(void) {
gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, 0, BORDER_HEIGHT, SCREEN_WIDTH,
SCREEN_HEIGHT - BORDER_HEIGHT);
if (!gDjuiDisabled && gDjuiRenderBehindHud) {
if (!gDjuiDisabled) {
djui_reset_hud_params();
create_dl_ortho_matrix();
djui_gfx_displaylist_begin();
smlua_call_event_hooks_with_reset_func(HOOK_ON_HUD_RENDER, djui_reset_hud_params);
smlua_call_event_on_hud_render_behind(djui_reset_hud_params);
djui_gfx_displaylist_end();
}
render_hud();

View File

@ -23,7 +23,6 @@ static struct DjuiText* sDjuiLuaError = NULL;
static u32 sDjuiLuaErrorTimeout = 0;
bool gDjuiInMainMenu = true;
bool gDjuiDisabled = false;
bool gDjuiRenderBehindHud = false;
static bool sDjuiInited = false;
bool sDjuiRendered60fps = false;
@ -49,8 +48,6 @@ void patch_djui_before(void) {
}
void patch_djui_interpolated(UNUSED f32 delta) {
if (gDjuiRenderBehindHud && !gDjuiPanelPauseCreated) { return; }
// reset the head and re-render DJUI
if (delta >= 0.5f && !sDjuiRendered60fps && (gDjuiInMainMenu || gDjuiPanelPauseCreated)) {
sDjuiRendered60fps = true;
@ -132,10 +129,7 @@ void djui_render(void) {
create_dl_ortho_matrix();
djui_gfx_displaylist_begin();
if (!gDjuiRenderBehindHud) {
djui_reset_hud_params();
smlua_call_event_hooks_with_reset_func(HOOK_ON_HUD_RENDER, djui_reset_hud_params);
}
smlua_call_event_on_hud_render(djui_reset_hud_params);
djui_panel_update();
djui_popup_update();

View File

@ -37,7 +37,6 @@
extern struct DjuiRoot* gDjuiRoot;
extern bool gDjuiInMainMenu;
extern bool gDjuiDisabled;
extern bool gDjuiRenderBehindHud;
void djui_init(void);
void djui_init_late(void);

View File

@ -554,10 +554,6 @@ bool djui_hud_world_pos_to_screen_pos(Vec3f pos, Vec3f out) {
return true;
}
void djui_hud_set_render_behind_hud(bool enable) {
gDjuiRenderBehindHud = enable;
}
bool djui_hud_is_pause_menu_created(void) {
return gDjuiPanelPauseCreated;
}

View File

@ -64,9 +64,6 @@ void djui_hud_render_rect(f32 x, f32 y, f32 width, f32 height);
void djui_hud_render_rect_interpolated(f32 prevX, f32 prevY, f32 prevWidth, f32 prevHeight, f32 x, f32 y, f32 width, f32 height);
bool djui_hud_world_pos_to_screen_pos(Vec3f pos, Vec3f out);
void djui_hud_set_render_behind_hud(bool enable);
bool djui_hud_is_pause_menu_created(void);
void djui_open_pause_menu(void);

View File

@ -1131,7 +1131,7 @@ static struct LuaObjectField sMarioStateFields[LUA_MARIO_STATE_FIELD_COUNT] = {
{ "waterLevel", LVT_S16, offsetof(struct MarioState, waterLevel), false, LOT_NONE },
};
#define LUA_MOD_FIELD_COUNT 11
#define LUA_MOD_FIELD_COUNT 12
static struct LuaObjectField sModFields[LUA_MOD_FIELD_COUNT] = {
{ "basePath", LVT_STRING, offsetof(struct Mod, basePath), true, LOT_NONE },
{ "customBehaviorIndex", LVT_U8, offsetof(struct Mod, customBehaviorIndex), true, LOT_NONE },
@ -1143,6 +1143,7 @@ static struct LuaObjectField sModFields[LUA_MOD_FIELD_COUNT] = {
{ "isDirectory", LVT_BOOL, offsetof(struct Mod, isDirectory), true, LOT_NONE },
{ "name", LVT_STRING_P, offsetof(struct Mod, name), true, LOT_NONE },
{ "relativePath", LVT_STRING, offsetof(struct Mod, relativePath), true, LOT_NONE },
{ "renderBehindHud", LVT_BOOL, offsetof(struct Mod, renderBehindHud), true, LOT_NONE },
{ "selectable", LVT_BOOL, offsetof(struct Mod, selectable), true, LOT_NONE },
// { "size", LVT_???, offsetof(struct Mod, size), true, LOT_??? }, <--- UNIMPLEMENTED
};

View File

@ -3193,7 +3193,8 @@ char gSmluaConstants[] = ""
"HOOK_JOINED_GAME = 31\n"
"HOOK_ON_OBJECT_ANIM_UPDATE = 32\n"
"HOOK_ON_DIALOG = 33\n"
"HOOK_MAX = 34\n"
"HOOK_ON_HUD_RENDER_BEHIND = 34\n"
"HOOK_MAX = 35\n"
"ACTION_HOOK_EVERY_FRAME = 0\n"
"ACTION_HOOK_GRAVITY = 1\n"
"ACTION_HOOK_MAX = 2\n"
@ -4298,4 +4299,4 @@ char gSmluaConstants[] = ""
"VERSION_REGION = 'US'\n"
"MAX_VERSION_LENGTH = 32\n"
"MAX_LOCAL_VERSION_LENGTH = 36\n"
;
;

View File

@ -12388,23 +12388,6 @@ int smlua_func_djui_hud_set_mouse_locked(lua_State* L) {
return 1;
}
int smlua_func_djui_hud_set_render_behind_hud(lua_State* L) {
if (L == NULL) { return 0; }
int top = lua_gettop(L);
if (top != 1) {
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "djui_hud_set_render_behind_hud", 1, top);
return 0;
}
bool enable = smlua_to_boolean(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "djui_hud_set_render_behind_hud"); return 0; }
djui_hud_set_render_behind_hud(enable);
return 1;
}
int smlua_func_djui_hud_set_resolution(lua_State* L) {
if (L == NULL) { return 0; }
@ -27510,6 +27493,23 @@ int smlua_func_smlua_collision_util_get(lua_State* L) {
// smlua_deprecated.h //
////////////////////////
int smlua_func_djui_hud_set_render_behind_hud(lua_State* L) {
if (L == NULL) { return 0; }
int top = lua_gettop(L);
if (top != 1) {
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "djui_hud_set_render_behind_hud", 1, top);
return 0;
}
bool enable = smlua_to_boolean(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "djui_hud_set_render_behind_hud"); return 0; }
djui_hud_set_render_behind_hud(enable);
return 1;
}
int smlua_func_network_discord_id_from_local_index(lua_State* L) {
if (L == NULL) { return 0; }
@ -31721,7 +31721,6 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "djui_hud_set_color", smlua_func_djui_hud_set_color);
smlua_bind_function(L, "djui_hud_set_font", smlua_func_djui_hud_set_font);
smlua_bind_function(L, "djui_hud_set_mouse_locked", smlua_func_djui_hud_set_mouse_locked);
smlua_bind_function(L, "djui_hud_set_render_behind_hud", smlua_func_djui_hud_set_render_behind_hud);
smlua_bind_function(L, "djui_hud_set_resolution", smlua_func_djui_hud_set_resolution);
smlua_bind_function(L, "djui_hud_set_rotation", smlua_func_djui_hud_set_rotation);
smlua_bind_function(L, "djui_hud_world_pos_to_screen_pos", smlua_func_djui_hud_world_pos_to_screen_pos);
@ -32472,6 +32471,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "smlua_collision_util_get", smlua_func_smlua_collision_util_get);
// smlua_deprecated.h
smlua_bind_function(L, "djui_hud_set_render_behind_hud", smlua_func_djui_hud_set_render_behind_hud);
smlua_bind_function(L, "network_discord_id_from_local_index", smlua_func_network_discord_id_from_local_index);
// smlua_level_utils.h

View File

@ -173,20 +173,60 @@ void smlua_call_event_hooks(enum LuaHookedEventType hookType) {
}
}
void smlua_call_event_hooks_with_reset_func(enum LuaHookedEventType hookType, void (*resetFunc)(void)) {
void smlua_call_event_on_hud_render(void (*resetFunc)(void)) {
lua_State* L = gLuaState;
if (L == NULL) { return; }
struct LuaHookedEvent* hook = &sHookedEvents[hookType];
if (resetFunc) { resetFunc(); }
struct LuaHookedEvent* hook = &sHookedEvents[HOOK_ON_HUD_RENDER];
for (int i = 0; i < hook->count; i++) {
// support deprecated render behind hud
if (hook->mod[i]->renderBehindHud) { continue; }
// push the callback onto the stack
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
// call the callback
if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) {
LOG_LUA("Failed to call the event_hook callback: %u", HOOK_ON_HUD_RENDER);
}
if (resetFunc) { resetFunc(); }
}
}
void smlua_call_event_on_hud_render_behind(void (*resetFunc)(void)) {
lua_State* L = gLuaState;
if (L == NULL) { return; }
if (resetFunc) { resetFunc(); }
struct LuaHookedEvent* hook = &sHookedEvents[HOOK_ON_HUD_RENDER_BEHIND];
for (int i = 0; i < hook->count; i++) {
// push the callback onto the stack
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
// call the callback
if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) {
LOG_LUA("Failed to call the event_hook callback: %u", hookType);
LOG_LUA("Failed to call the event_hook callback: %u", HOOK_ON_HUD_RENDER_BEHIND);
}
if (resetFunc) { resetFunc(); }
}
// support deprecated render behind hud
hook = &sHookedEvents[HOOK_ON_HUD_RENDER];
for (int i = 0; i < hook->count; i++) {
// support deprecated render behind hud
if (!hook->mod[i]->renderBehindHud) { continue; }
// push the callback onto the stack
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
// call the callback
if (0 != smlua_call_hook(L, 0, 0, 0, hook->mod[i])) {
LOG_LUA("Failed to call the event_hook callback: %u", HOOK_ON_HUD_RENDER);
}
if (resetFunc) { resetFunc(); }
}
}
void smlua_call_event_hooks_bool_param(enum LuaHookedEventType hookType, bool value) {

View File

@ -45,6 +45,7 @@ enum LuaHookedEventType {
HOOK_JOINED_GAME,
HOOK_ON_OBJECT_ANIM_UPDATE,
HOOK_ON_DIALOG,
HOOK_ON_HUD_RENDER_BEHIND,
HOOK_MAX,
};
@ -83,6 +84,7 @@ static const char* LuaHookedEventTypeName[] = {
"HOOK_JOINED_GAME",
"HOOK_ON_OBJECT_ANIM_UPDATE",
"HOOK_ON_DIALOG",
"HOOK_ON_HUD_RENDER_BEHIND",
"HOOK_MAX"
};
@ -103,7 +105,8 @@ extern u32 gLuaMarioActionIndex[];
int smlua_hook_custom_bhv(BehaviorScript *bhvScript, const char *bhvName);
void smlua_call_event_hooks(enum LuaHookedEventType hookType);
void smlua_call_event_hooks_with_reset_func(enum LuaHookedEventType hookType, void (*resetFunc)(void));
void smlua_call_event_on_hud_render(void (*resetFunc)(void));
void smlua_call_event_on_hud_render_behind(void (*resetFunc)(void));
void smlua_call_event_hooks_bool_param(enum LuaHookedEventType hookType, bool value);
void smlua_call_event_hooks_bool_param_ret_bool(enum LuaHookedEventType hookType, bool value, bool* returnValue);
void smlua_call_event_hooks_mario_param(enum LuaHookedEventType hookType, struct MarioState* m);

View File

@ -3,6 +3,7 @@
#ifdef DISCORD_SDK
#include "pc/discord/discord.h"
#endif
#include "pc/lua/smlua.h"
char* network_discord_id_from_local_index(u8 localIndex) {
#ifdef DISCORD_SDK
@ -14,3 +15,8 @@ char* network_discord_id_from_local_index(u8 localIndex) {
#endif
return NULL;
}
void djui_hud_set_render_behind_hud(bool enable) {
if (!gLuaActiveMod) { return; }
gLuaActiveMod->renderBehindHud = enable;
}

View File

@ -1,3 +1,5 @@
#pragma once
char* network_discord_id_from_local_index(u8 localIndex);
void djui_hud_set_render_behind_hud(bool enable);

View File

@ -33,6 +33,7 @@ struct Mod {
bool isDirectory;
bool enabled;
bool selectable;
bool renderBehindHud;
size_t size;
u8 customBehaviorIndex;
};

View File

@ -639,7 +639,6 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
gLightingColor[2] = 255;
gOverrideBackground = -1;
gOverrideEnvFx = -1;
gDjuiRenderBehindHud = false;
gRomhackCameraAllowCentering = TRUE;
gRomhackCameraAllowDpad = FALSE;
camera_reset_overrides();