diff --git a/Lua/cheat menu.lua b/Lua/cheat menu.lua index 035a9a1..8008336 100755 --- a/Lua/cheat menu.lua +++ b/Lua/cheat menu.lua @@ -8,7 +8,25 @@ require "flag manager" -- TODO: make OoT versions for most of these menus +--[[ control schemes: +normal: (alt_input = false; eat_input = false) + L opens the menu + L selects menu items + D-Pad navigates up/down items and left/right through pages +alternate: (alt_input = true; eat_input = false) + L+R opens/closes the menu + L goes back a menu (or closes) + R selects menu items + L+Z hides menu without closing (FIXME: interferes with back) + D-Pad navigates +greedy: (alt_input = false; eat_input = true) + TODO: joystick, a/b button etc +--]] + local run_while_paused = true +local alt_input = true +local eat_input = false + local fn = 'cheat menu.save.lua' local saved = deserialize('cheat menu.save.lua') or {} local function save() @@ -222,9 +240,8 @@ local playas_menu = require "menus.playas" local main_menu = Menu{ Screen{ Text("Main Menu #1/2"), - --Toggle("L to Levitate", levitate), + Toggle("L to Levitate", levitate), Toggle("A to Run Fast", supersonic), - Hold("Levitate", levitate), Toggle("Infinite Items", infinite_items), Text(""), Oneshot("100% Items", everything), @@ -261,7 +278,9 @@ local main_menu = Menu{ } local input = InputHandler{ - enter = "P1 L", + L = "P1 L", + R = "P1 R", + Z = "P1 Z", up = "P1 DPad U", down = "P1 DPad D", left = "P1 DPad L", @@ -270,8 +289,38 @@ local input = InputHandler{ local handle = MenuHandler(main_menu, T_TL) +function handle_alt_input(handle, ctrl, pressed) + pressed.enter = false + ctrl.enter = false + local open_close = ctrl.L and ctrl.R and (pressed.L or pressed.R) + local hide = ctrl.L and ctrl.Z and (pressed.L or pressed.Z) + if open_close then + if handle.menu then -- if menu is open + handle:navigate('close') + else + pressed.enter = true + ctrl.enter = true + end + else + if hide then + handle:navigate('hide') + elseif pressed.L then + handle:navigate('back') + elseif handle.menu then + pressed.enter = pressed.R + ctrl.enter = ctrl.R + end + end +end + while mm or oot do local ctrl, pressed = input:update() + if alt_input then + handle_alt_input(handle, ctrl, pressed) + else + ctrl.enter = ctrl.L + pressed.enter = pressed.L + end handle:update(ctrl, pressed) for i, passive in ipairs(passives) do diff --git a/Lua/classes/InputHandler.lua b/Lua/classes/InputHandler.lua index 9ed49e5..08b3d63 100644 --- a/Lua/classes/InputHandler.lua +++ b/Lua/classes/InputHandler.lua @@ -4,10 +4,10 @@ function InputHandler:init(binds) self.old_ctrl = {} end -function InputHandler:update() +function InputHandler:update(inputs) local ctrl = {} local pressed = {} - local j = joypad.getimmediate() + local j = inputs or joypad.getimmediate() for k, v in pairs(self.binds) do ctrl[k] = j[v] end diff --git a/Lua/menu classes.lua b/Lua/menu classes.lua index a267d93..0872eda 100644 --- a/Lua/menu classes.lua +++ b/Lua/menu classes.lua @@ -275,6 +275,7 @@ function MenuHandler:init(main_menu, brush) self.backstack = {} self.brush = brush self.menu = nil + self.hidden = false end function MenuHandler:push(menu) @@ -285,23 +286,35 @@ function MenuHandler:pop() return table.remove(self.backstack) end -function MenuHandler:update(ctrl, pressed) - if not self.menu and pressed.enter then - self.menu = self.main_menu - self.menu:focus() - elseif self.menu then - local new_menu = self.menu:navigate(ctrl, pressed) +function MenuHandler:navigate(new_menu) + if new_menu ~= self.menu then if new_menu == 'back' then new_menu = self:pop() elseif new_menu == 'close' then self.backstack = {} new_menu = nil - elseif new_menu ~= self.menu then + elseif new_menu == 'hide' then + self.hidden = true + return + elseif self.menu and new_menu ~= self.menu then self:push(self.menu) self.menu:unfocus() end - if new_menu and new_menu ~= self.menu then new_menu:focus() end - self.menu = new_menu + if new_menu then new_menu:focus() end + end + self.menu = new_menu +end + +function MenuHandler:update(ctrl, pressed) + if self.hidden then + if not pressed.enter then return end + self.hidden = false + end + if not self.menu and pressed.enter then + self:navigate(self.main_menu) + elseif self.menu then + local new_menu = self.menu:navigate(ctrl, pressed) + self:navigate(new_menu) end if self.menu then self.menu:draw(self.brush, 0) end end