Skip to content

Commit 3adde87

Browse files
committed
DisplayHP and some fixes
1 parent 96de0c9 commit 3adde87

5 files changed

Lines changed: 53 additions & 7 deletions

File tree

docs/lua/guides/hooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh
138138
| HOOK_ON_ATTACK_OBJECT | Called when a player attacks an object. May be double-fired in some cases, you'll need to write special code for this | [MarioState](../structs.md#MarioState) attacker, [Object](../structs.md#Object) victim, `integer` interactionId |
139139
| HOOK_ON_LANGUAGE_CHANGED | Called when the language is changed | `string` language |
140140
| HOOK_ON_MODS_LOADED | Called directly after every mod file is loaded in by smlua | None |
141-
| HOOK_ON_NAMETAGS_RENDER | Called when nametags are rendered. Return a table with `name`, `pos` and/or `color` to override the nametag text, position and/or color. | `integer` playerIndex, `[Vec3f](../structs.md#vec3f)` pos, `[Color](../structs.md#color)` color |
141+
| HOOK_ON_NAMETAGS_RENDER | Called when nametags are rendered. Return a table with `name`, `pos`, `color` and/or `displayHP` to override the nametag text, position, color and/or power meter display. | `integer` playerIndex, `[Vec3f](../structs.md#vec3f)` pos, `[Color](../structs.md#color)` color, `boolean` displayHP |
142142
| HOOK_ON_DJUI_THEME_CHANGED | Called when the DJUI theme is changed. Run `djui_menu_get_theme()` to get the new theme. | None |
143143
| HOOK_ON_GEO_PROCESS | Called when a GeoLayout is processed **Note:** You must set the `hookProcess` field of the graph node to a non-zero value | [GraphNode](../structs.md#GraphNode) graphNode, `integer` matStackIndex |
144144
| HOOK_BEFORE_GEO_PROCESS | Called before a GeoLayout is processed **Note:** You must set the `hookProcess` field of the graph node to a non-zero value | [GraphNode](../structs.md#GraphNode) graphNode, `integer` matStackIndex |

src/pc/lua/smlua_functions_autogen.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13008,6 +13008,41 @@ int smlua_func_djui_hud_print_text_interpolated(lua_State* L) {
1300813008
return 1;
1300913009
}
1301013010

13011+
int smlua_func_djui_hud_print_outlined_text_interpolated(lua_State* L) {
13012+
if (L == NULL) { return 0; }
13013+
13014+
int top = lua_gettop(L);
13015+
if (top != 10) {
13016+
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "djui_hud_print_text_interpolated", 10, top);
13017+
return 0;
13018+
}
13019+
13020+
const char* message = smlua_to_string(L, 1);
13021+
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "djui_hud_print_text_interpolated"); return 0; }
13022+
f32 prevX = smlua_to_number(L, 2);
13023+
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "djui_hud_print_text_interpolated"); return 0; }
13024+
f32 prevY = smlua_to_number(L, 3);
13025+
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "djui_hud_print_text_interpolated"); return 0; }
13026+
f32 prevScale = smlua_to_number(L, 4);
13027+
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 4, "djui_hud_print_text_interpolated"); return 0; }
13028+
f32 prevOutlineThickness = smlua_to_number(L, 5);
13029+
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 5, "djui_hud_print_text_interpolated"); return 0; }
13030+
f32 x = smlua_to_number(L, 6);
13031+
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 6, "djui_hud_print_text_interpolated"); return 0; }
13032+
f32 y = smlua_to_number(L, 7);
13033+
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 7, "djui_hud_print_text_interpolated"); return 0; }
13034+
f32 scale = smlua_to_number(L, 8);
13035+
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 8, "djui_hud_print_text_interpolated"); return 0; }
13036+
f32 outlineThickness = smlua_to_number(L, 9);
13037+
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 9, "djui_hud_print_text_interpolated"); return 0; }
13038+
f32 outlineDarkness = smlua_to_number(L, 10);
13039+
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 10, "djui_hud_print_text_interpolated"); return 0; }
13040+
13041+
djui_hud_print_outlined_text_interpolated(message, prevX, prevY, prevScale, prevOutlineThickness, x, y, scale, outlineThickness, outlineDarkness);
13042+
13043+
return 1;
13044+
}
13045+
1301113046
int smlua_func_djui_hud_render_texture(lua_State* L) {
1301213047
if (L == NULL) { return 0; }
1301313048

@@ -37794,6 +37829,7 @@ void smlua_bind_functions_autogen(void) {
3779437829
smlua_bind_function(L, "djui_hud_print_text", smlua_func_djui_hud_print_text);
3779537830
smlua_bind_function(L, "djui_hud_print_outlined_text", smlua_func_djui_hud_print_outlined_text);
3779637831
smlua_bind_function(L, "djui_hud_print_text_interpolated", smlua_func_djui_hud_print_text_interpolated);
37832+
smlua_bind_function(L, "djui_hud_print_outlined_text_interpolated", smlua_func_djui_hud_print_outlined_text_interpolated);
3779737833
smlua_bind_function(L, "djui_hud_render_texture", smlua_func_djui_hud_render_texture);
3779837834
smlua_bind_function(L, "djui_hud_render_texture_tile", smlua_func_djui_hud_render_texture_tile);
3779937835
smlua_bind_function(L, "djui_hud_render_texture_interpolated", smlua_func_djui_hud_render_texture_interpolated);

src/pc/lua/smlua_hook_events.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ SMLUA_EVENT_HOOK(HOOK_ON_SEQ_LOAD, HOOK_RETURN_ON_OUTPUT_SET, u32 seqPlayer, u32
4444
SMLUA_EVENT_HOOK(HOOK_ON_ATTACK_OBJECT, HOOK_RETURN_NEVER, struct MarioState *m, struct Object *obj, s32 interaction)
4545
SMLUA_EVENT_HOOK(HOOK_ON_LANGUAGE_CHANGED, HOOK_RETURN_NEVER, const char *langName)
4646
SMLUA_EVENT_HOOK(HOOK_ON_MODS_LOADED, HOOK_RETURN_NEVER)
47-
SMLUA_EVENT_HOOK(HOOK_ON_NAMETAGS_RENDER, _, s32 playerIndex, Vec3f pos, OUTPUT const char **playerNameOverride, OUTPUT u8 **colorOverride) // Manually defined hook
47+
SMLUA_EVENT_HOOK(HOOK_ON_NAMETAGS_RENDER, _, s32 playerIndex, Vec3f pos, OUTPUT const char **playerNameOverride, OUTPUT u8 **colorOverride, OUTPUT bool *displayHP) // Manually defined hook
4848
SMLUA_EVENT_HOOK(HOOK_ON_DJUI_THEME_CHANGED, HOOK_RETURN_NEVER)
4949
SMLUA_EVENT_HOOK(HOOK_ON_GEO_PROCESS, HOOK_RETURN_NEVER, struct GraphNode *node, s32 matStackIndex)
5050
SMLUA_EVENT_HOOK(HOOK_BEFORE_GEO_PROCESS, HOOK_RETURN_NEVER, struct GraphNode *node, s32 matStackIndex)

src/pc/lua/smlua_hooks.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ bool smlua_call_event_hooks_HOOK_ON_HUD_RENDER_BEHIND(void (*resetFunc)(void)) {
157157
return smlua_call_event_hooks_on_hud_render(resetFunc, true);
158158
}
159159

160-
bool smlua_call_event_hooks_HOOK_ON_NAMETAGS_RENDER(s32 playerIndex, Vec3f pos, const char **playerNameOverride, u8 **colorOverride) {
160+
bool smlua_call_event_hooks_HOOK_ON_NAMETAGS_RENDER(s32 playerIndex, Vec3f pos, const char **playerNameOverride, u8 **colorOverride, bool *displayHP) {
161161
lua_State *L = gLuaState;
162162
if (L == NULL) { return false; }
163163

@@ -188,7 +188,7 @@ bool smlua_call_event_hooks_HOOK_ON_NAMETAGS_RENDER(s32 playerIndex, Vec3f pos,
188188
return true;
189189
}
190190

191-
// if it's a table, override name, pos and/or color
191+
// if it's a table, override name, pos, color and/or displayHP
192192
if (lua_type(L, -1) == LUA_TTABLE) {
193193
bool override = false;
194194

@@ -237,6 +237,14 @@ bool smlua_call_event_hooks_HOOK_ON_NAMETAGS_RENDER(s32 playerIndex, Vec3f pos,
237237
}
238238
lua_pop(L, 1);
239239

240+
//display power meter
241+
lua_getfield(L, -1, "displayHP");
242+
if (lua_isboolean(L, -1)) {
243+
*displayHP = smlua_to_boolean(L, -1);
244+
override = true;
245+
}
246+
lua_pop(L, 1);
247+
240248
lua_settop(L, prevTop);
241249
if (override) {
242250
return true;

src/pc/nametags.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ void nametags_render(void) {
184184
char name[MAX_CONFIG_STRING];
185185
const char* hookedString = NULL;
186186
u8* color = NULL;
187+
bool displayHP = NULL;
187188

188-
smlua_call_event_hooks(HOOK_ON_NAMETAGS_RENDER, i, pos, &hookedString, &color);
189+
smlua_call_event_hooks(HOOK_ON_NAMETAGS_RENDER, i, pos, &hookedString, &color, &displayHP);
189190
if (!djui_hud_world_pos_to_screen_pos(pos, out)) {
190191
continue;
191192
}
@@ -201,7 +202,6 @@ void nametags_render(void) {
201202
}
202203

203204
f32 scale = -300 / out[2] * djui_hud_get_fov_coeff();
204-
f32 measure = djui_hud_measure_text(name) * scale * 0.5f;
205205
out[1] -= 16 * scale;
206206

207207
u8 alpha = (i == 0 ? 255 : MIN(np->fadeOpacity << 3, 255)) * clamp(FADE_SCALE - scale, 0.f, 1.f);
@@ -233,13 +233,15 @@ void nametags_render(void) {
233233
name_without_hex(name);
234234
}
235235

236+
f32 measure = djui_hud_measure_text(name) * scale * 0.5f;
237+
236238
djui_hud_print_outlined_text_interpolated(name,
237239
e->prevPos[0] - measure, e->prevPos[1], e->prevScale, 1,
238240
out[0] - measure, out[1], scale, 1, 0.25
239241
);
240242
}
241243

242-
if (i != 0 && gNametagsSettings.showHealth) {
244+
if (i != 0 && (displayHP || gNametagsSettings.showHealth)) {
243245
djui_hud_set_color(255, 255, 255, alpha);
244246
f32 healthScale = 90 * scale;
245247
f32 prevHealthScale = 90 * e->prevScale;

0 commit comments

Comments
 (0)