From f7a48d23fe3a75980cc255e0195cdd6c3bf4c6d2 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+AgentXLP@users.noreply.github.com> Date: Wed, 11 Dec 2024 23:55:10 -0500 Subject: [PATCH] HOOK_ON_DJUI_THEME_CHANGED --- autogen/lua_constants/built-in.lua | 48 ----------------------- autogen/lua_definitions/constants.lua | 55 +++------------------------ docs/lua/constants.md | 3 +- docs/lua/guides/hooks.md | 1 + src/pc/djui/djui_panel_menu_options.c | 3 ++ src/pc/lua/smlua_constants_autogen.c | 49 ++---------------------- src/pc/lua/smlua_hooks.h | 2 + 7 files changed, 18 insertions(+), 143 deletions(-) diff --git a/autogen/lua_constants/built-in.lua b/autogen/lua_constants/built-in.lua index 5241b381f..a31e615d6 100644 --- a/autogen/lua_constants/built-in.lua +++ b/autogen/lua_constants/built-in.lua @@ -193,54 +193,6 @@ function vec3s_dist(v1, v2) return math.sqrt(dx * dx + dy * dy + dz * dz) end ---- @param current number ---- @param target number ---- @param inc number ---- @param dec number ---- @return number -function approach_f32(current, target, inc, dec) - if current < target then - current = current + inc - if current > target then - current = target - end - else - current = current - dec - if current < target then - current = target - end - end - return current -end - ---- @param current integer ---- @param target integer ---- @param inc integer ---- @param dec integer ---- @return integer -function approach_s32(current, target, inc, dec) - if current < target then - current = current + inc - if current > target then - current = target - end - else - current = current - dec - if current < target then - current = target - end - end - - -- keep within 32 bits - if current > 2147483647 then - current = -2147483648 + (current - 2147483647) - elseif current < -2147483648 then - current = 2147483647 + (current - (-2147483648)) - end - return current -end - - ----------- -- sound -- ----------- diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index 923dd8df6..f5f17c479 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -195,54 +195,6 @@ function vec3s_dist(v1, v2) return math.sqrt(dx * dx + dy * dy + dz * dz) end ---- @param current number ---- @param target number ---- @param inc number ---- @param dec number ---- @return number -function approach_f32(current, target, inc, dec) - if current < target then - current = current + inc - if current > target then - current = target - end - else - current = current - dec - if current < target then - current = target - end - end - return current -end - ---- @param current integer ---- @param target integer ---- @param inc integer ---- @param dec integer ---- @return integer -function approach_s32(current, target, inc, dec) - if current < target then - current = current + inc - if current > target then - current = target - end - else - current = current - dec - if current < target then - current = target - end - end - - -- keep within 32 bits - if current > 2147483647 then - current = -2147483648 + (current - 2147483647) - elseif current < -2147483648 then - current = 2147483647 + (current - (-2147483648)) - end - return current -end - - ----------- -- sound -- ----------- @@ -333,6 +285,7 @@ COURSE_MIN = 1 --- @param np NetworkPlayer --- @param part PlayerPart --- @return Color +--- Gets the palette color of `part` on `np` function network_player_get_palette_color(np, part) local color = { r = network_player_get_palette_color_channel(np, part, 0), @@ -345,6 +298,7 @@ end --- @param np NetworkPlayer --- @param part PlayerPart --- @return Color +--- Gets the override palette color of `part` on `np` function network_player_get_override_palette_color(np, part) local color = { r = network_player_get_override_palette_color_channel(np, part, 0), @@ -9184,7 +9138,10 @@ HOOK_ON_MODS_LOADED = 45 HOOK_ON_NAMETAGS_RENDER = 46 --- @type LuaHookedEventType -HOOK_MAX = 47 +HOOK_ON_DJUI_THEME_CHANGED = 47 + +--- @type LuaHookedEventType +HOOK_MAX = 48 --- @class LuaModMenuElementType diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 9d6a058df..491784ea9 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -3317,7 +3317,8 @@ | HOOK_ON_LANGUAGE_CHANGED | 44 | | HOOK_ON_MODS_LOADED | 45 | | HOOK_ON_NAMETAGS_RENDER | 46 | -| HOOK_MAX | 47 | +| HOOK_ON_DJUI_THEME_CHANGED | 47 | +| HOOK_MAX | 48 | ### [enum LuaModMenuElementType](#LuaModMenuElementType) | Identifier | Value | diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index 9fbfa6a32..8459e3795 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -138,6 +138,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_ON_LANGUAGE_CHANGED | Called when the language is changed | `string` language | | HOOK_ON_MODS_LOADED | Called directly after every mod file is loaded in by smlua | None | | HOOK_ON_NAMETAGS_RENDER | Called when nametags are rendered. Return a `string` to change what renders on the nametag, return an empty `string` to render nothing. | `string` playerIndex | +| HOOK_ON_DJUI_THEME_CHANGED | Called when the DJUI theme is changed. Run `djui_menu_get_theme()` to get the new theme. | None | ### Parameters diff --git a/src/pc/djui/djui_panel_menu_options.c b/src/pc/djui/djui_panel_menu_options.c index faacdccf6..3f211e1cf 100644 --- a/src/pc/djui/djui_panel_menu_options.c +++ b/src/pc/djui/djui_panel_menu_options.c @@ -12,6 +12,7 @@ #include "djui_hud_utils.h" #include "pc/utils/misc.h" #include "pc/configfile.h" +#include "pc/lua/smlua_hooks.h" #include "game/level_update.h" #include "seq_ids.h" @@ -86,6 +87,8 @@ static void djui_panel_menu_options_djui_setting_change(UNUSED struct DjuiBase* djui_text_set_font(gDjuiPauseOptions, gDjuiFonts[configDjuiThemeFont == 0 ? FONT_NORMAL : FONT_ALIASED]); djui_text_set_text(gDjuiPauseOptions, DLANG(MISC, R_BUTTON)); } + + smlua_call_event_hooks(HOOK_ON_DJUI_THEME_CHANGED); } void djui_panel_main_menu_create(struct DjuiBase* caller) { diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index d29db2d41..5552b443e 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -171,50 +171,6 @@ char gSmluaConstants[] = "" " dz = v1.z - v2.z\n" " return math.sqrt(dx * dx + dy * dy + dz * dz)\n" "end\n" -"--- @param current number\n" -"--- @param target number\n" -"--- @param inc number\n" -"--- @param dec number\n" -"--- @return number\n" -"function approach_f32(current, target, inc, dec)\n" -" if current < target then\n" -" current = current + inc\n" -" if current > target then\n" -" current = target\n" -" end\n" -" else\n" -" current = current - dec\n" -" if current < target then\n" -" current = target\n" -" end\n" -" end\n" -" return current\n" -"end\n" -"--- @param current integer\n" -"--- @param target integer\n" -"--- @param inc integer\n" -"--- @param dec integer\n" -"--- @return integer\n" -"function approach_s32(current, target, inc, dec)\n" -" if current < target then\n" -" current = current + inc\n" -" if current > target then\n" -" current = target\n" -" end\n" -" else\n" -" current = current - dec\n" -" if current < target then\n" -" current = target\n" -" end\n" -" end\n" -" -- keep within 32 bits\n" -" if current > 2147483647 then\n" -" current = -2147483648 + (current - 2147483647)\n" -" elseif current < -2147483648 then\n" -" current = 2147483647 + (current - (-2147483648))\n" -" end\n" -" return current\n" -"end\n" "-----------\n" "-- sound --\n" "-----------\n" @@ -298,6 +254,7 @@ char gSmluaConstants[] = "" "--- @param np NetworkPlayer\n" "--- @param part PlayerPart\n" "--- @return Color\n" +"--- Gets the palette color of `part` on `np`\n" "function network_player_get_palette_color(np, part)\n" " local color = {\n" " r = network_player_get_palette_color_channel(np, part, 0),\n" @@ -309,6 +266,7 @@ char gSmluaConstants[] = "" "--- @param np NetworkPlayer\n" "--- @param part PlayerPart\n" "--- @return Color\n" +"--- Gets the override palette color of `part` on `np`\n" "function network_player_get_override_palette_color(np, part)\n" " local color = {\n" " r = network_player_get_override_palette_color_channel(np, part, 0),\n" @@ -3238,7 +3196,8 @@ char gSmluaConstants[] = "" "HOOK_ON_LANGUAGE_CHANGED = 44\n" "HOOK_ON_MODS_LOADED = 45\n" "HOOK_ON_NAMETAGS_RENDER = 46\n" -"HOOK_MAX = 47\n" +"HOOK_ON_DJUI_THEME_CHANGED = 47\n" +"HOOK_MAX = 48\n" "ACTION_HOOK_EVERY_FRAME = 0\n" "ACTION_HOOK_GRAVITY = 1\n" "ACTION_HOOK_MAX = 2\n" diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index ced55b2ad..5edeea0d5 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -58,6 +58,7 @@ enum LuaHookedEventType { HOOK_ON_LANGUAGE_CHANGED, HOOK_ON_MODS_LOADED, HOOK_ON_NAMETAGS_RENDER, + HOOK_ON_DJUI_THEME_CHANGED, HOOK_MAX, }; @@ -109,6 +110,7 @@ static const char* LuaHookedEventTypeName[] = { "HOOK_ON_LANGUAGE_CHANGED", "HOOK_ON_MODS_LOADED", "HOOK_ON_NAMETAGS_RENDER", + "HOOK_ON_DJUI_THEME_CHANGED", "HOOK_MAX" };