From aeabcb6faa07768e92deb4351bb9ee1fd67329b9 Mon Sep 17 00:00:00 2001 From: ComplexPlane Date: Wed, 3 Feb 2021 21:51:06 -0500 Subject: [PATCH] Allow toggling rumble from ApeSphere menu --- rel/include/mkb2.us.lst | 3 +- rel/menu_defn.cpp | 63 ++++++++++++++++++++++++++++++++--------- rel/menu_impl.cpp | 4 +-- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/rel/include/mkb2.us.lst b/rel/include/mkb2.us.lst index 133ed915..462c5020 100644 --- a/rel/include/mkb2.us.lst +++ b/rel/include/mkb2.us.lst @@ -14934,4 +14934,5 @@ E0000094:locked_cache_mtx_stack_ptr E000019C:e E00001A0:0.5 8032bfb0:sprite_loadin_stage_name_tick -8032ccb4:sprite_bonus_stage_tick \ No newline at end of file +8032ccb4:sprite_bonus_stage_tick +804a7560:rumble_enabled_bitflag \ No newline at end of file diff --git a/rel/menu_defn.cpp b/rel/menu_defn.cpp index 88719a09..bde085e6 100644 --- a/rel/menu_defn.cpp +++ b/rel/menu_defn.cpp @@ -9,6 +9,16 @@ #define ARRAY_LEN(a) (sizeof((a)) / sizeof((a)[0])) +namespace mkb +{ + +extern "C" +{ +extern u8 rumble_enabled_bitflag; +} + +} + namespace menu { @@ -33,14 +43,40 @@ static void set_practice_tools_enabled(bool enable) } } -static void set_jump_mod_enabled(bool enable) { if (enable) jump::init(); else jump::dest(); } - -static bool get_rumble_enabled() -{ - return true; -} - -static void set_rumble_enabled(bool enable) {} +static Widget rumble_widgets[] = { + { + .type = WidgetType::Checkbox, + .checkbox = { + .label = "Controller 1 Rumble", + .get = []() { return static_cast(mkb::rumble_enabled_bitflag & (1 << 0)); }, + .set = [](bool enable) { mkb::rumble_enabled_bitflag ^= (1 << 0); }, + } + }, + { + .type = WidgetType::Checkbox, + .checkbox = { + .label = "Controller 2 Rumble", + .get = []() { return static_cast(mkb::rumble_enabled_bitflag & (1 << 1)); }, + .set = [](bool enable) { mkb::rumble_enabled_bitflag ^= (1 << 1); }, + } + }, + { + .type = WidgetType::Checkbox, + .checkbox = { + .label = "Controller 3 Rumble", + .get = []() { return static_cast(mkb::rumble_enabled_bitflag & (1 << 2)); }, + .set = [](bool enable) { mkb::rumble_enabled_bitflag ^= (1 << 2); }, + } + }, + { + .type = WidgetType::Checkbox, + .checkbox = { + .label = "Controller 4 Rumble", + .get = []() { return static_cast(mkb::rumble_enabled_bitflag & (1 << 3)); }, + .set = [](bool enable) { mkb::rumble_enabled_bitflag ^= (1 << 3); }, + } + } +}; static Widget help_widgets[] = { {.type = WidgetType::Header, .header = {"Practice Tools Bindings"}}, @@ -70,12 +106,13 @@ static Widget root_widgets[] = { }, { .type = WidgetType::Checkbox, - .checkbox = {"Jump Mod", jump::is_enabled, set_jump_mod_enabled}, - }, - { - .type = WidgetType::Checkbox, - .checkbox = {"Rumble", get_rumble_enabled, set_rumble_enabled}, + .checkbox = { + .label = "Jump Mod", + .get = jump::is_enabled, + .set = [](bool enable) { if (enable) jump::init(); else jump::dest(); }, + }, }, + {.type = WidgetType::Menu, .menu = {"Rumble", rumble_widgets, ARRAY_LEN(rumble_widgets)}}, {.type = WidgetType::Menu, .menu = {"Help", help_widgets, ARRAY_LEN(help_widgets)}}, }; diff --git a/rel/menu_impl.cpp b/rel/menu_impl.cpp index 472594ce..818962d7 100644 --- a/rel/menu_impl.cpp +++ b/rel/menu_impl.cpp @@ -173,8 +173,8 @@ void draw_menu_widget(MenuWidget *menu, u32 cursor_pos) MARGIN + PAD, y, cursor_pos == selectable_idx ? lerped_color : unfocused, - " %s", - widget.checkbox.get() ? "Enabled" : "Disabled"); + " %s", + widget.checkbox.get() ? "On" : "Off"); if (cursor_pos == selectable_idx) cursor_y = y; y += LINE_HEIGHT;