mirror of
https://github.com/notwa/mm
synced 2025-02-05 13:23:23 -08:00
alternate control scheme for menus
This commit is contained in:
parent
f0eac171f9
commit
2436eee982
3 changed files with 76 additions and 14 deletions
|
@ -8,7 +8,25 @@ require "flag manager"
|
||||||
|
|
||||||
-- TODO: make OoT versions for most of these menus
|
-- 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 run_while_paused = true
|
||||||
|
local alt_input = true
|
||||||
|
local eat_input = false
|
||||||
|
|
||||||
local fn = 'cheat menu.save.lua'
|
local fn = 'cheat menu.save.lua'
|
||||||
local saved = deserialize('cheat menu.save.lua') or {}
|
local saved = deserialize('cheat menu.save.lua') or {}
|
||||||
local function save()
|
local function save()
|
||||||
|
@ -222,9 +240,8 @@ local playas_menu = require "menus.playas"
|
||||||
local main_menu = Menu{
|
local main_menu = Menu{
|
||||||
Screen{
|
Screen{
|
||||||
Text("Main Menu #1/2"),
|
Text("Main Menu #1/2"),
|
||||||
--Toggle("L to Levitate", levitate),
|
Toggle("L to Levitate", levitate),
|
||||||
Toggle("A to Run Fast", supersonic),
|
Toggle("A to Run Fast", supersonic),
|
||||||
Hold("Levitate", levitate),
|
|
||||||
Toggle("Infinite Items", infinite_items),
|
Toggle("Infinite Items", infinite_items),
|
||||||
Text(""),
|
Text(""),
|
||||||
Oneshot("100% Items", everything),
|
Oneshot("100% Items", everything),
|
||||||
|
@ -261,7 +278,9 @@ local main_menu = Menu{
|
||||||
}
|
}
|
||||||
|
|
||||||
local input = InputHandler{
|
local input = InputHandler{
|
||||||
enter = "P1 L",
|
L = "P1 L",
|
||||||
|
R = "P1 R",
|
||||||
|
Z = "P1 Z",
|
||||||
up = "P1 DPad U",
|
up = "P1 DPad U",
|
||||||
down = "P1 DPad D",
|
down = "P1 DPad D",
|
||||||
left = "P1 DPad L",
|
left = "P1 DPad L",
|
||||||
|
@ -270,8 +289,38 @@ local input = InputHandler{
|
||||||
|
|
||||||
local handle = MenuHandler(main_menu, T_TL)
|
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
|
while mm or oot do
|
||||||
local ctrl, pressed = input:update()
|
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)
|
handle:update(ctrl, pressed)
|
||||||
|
|
||||||
for i, passive in ipairs(passives) do
|
for i, passive in ipairs(passives) do
|
||||||
|
|
|
@ -4,10 +4,10 @@ function InputHandler:init(binds)
|
||||||
self.old_ctrl = {}
|
self.old_ctrl = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function InputHandler:update()
|
function InputHandler:update(inputs)
|
||||||
local ctrl = {}
|
local ctrl = {}
|
||||||
local pressed = {}
|
local pressed = {}
|
||||||
local j = joypad.getimmediate()
|
local j = inputs or joypad.getimmediate()
|
||||||
for k, v in pairs(self.binds) do
|
for k, v in pairs(self.binds) do
|
||||||
ctrl[k] = j[v]
|
ctrl[k] = j[v]
|
||||||
end
|
end
|
||||||
|
|
|
@ -275,6 +275,7 @@ function MenuHandler:init(main_menu, brush)
|
||||||
self.backstack = {}
|
self.backstack = {}
|
||||||
self.brush = brush
|
self.brush = brush
|
||||||
self.menu = nil
|
self.menu = nil
|
||||||
|
self.hidden = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuHandler:push(menu)
|
function MenuHandler:push(menu)
|
||||||
|
@ -285,23 +286,35 @@ function MenuHandler:pop()
|
||||||
return table.remove(self.backstack)
|
return table.remove(self.backstack)
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuHandler:update(ctrl, pressed)
|
function MenuHandler:navigate(new_menu)
|
||||||
if not self.menu and pressed.enter then
|
if new_menu ~= self.menu then
|
||||||
self.menu = self.main_menu
|
|
||||||
self.menu:focus()
|
|
||||||
elseif self.menu then
|
|
||||||
local new_menu = self.menu:navigate(ctrl, pressed)
|
|
||||||
if new_menu == 'back' then
|
if new_menu == 'back' then
|
||||||
new_menu = self:pop()
|
new_menu = self:pop()
|
||||||
elseif new_menu == 'close' then
|
elseif new_menu == 'close' then
|
||||||
self.backstack = {}
|
self.backstack = {}
|
||||||
new_menu = nil
|
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:push(self.menu)
|
||||||
self.menu:unfocus()
|
self.menu:unfocus()
|
||||||
end
|
end
|
||||||
if new_menu and new_menu ~= self.menu then new_menu:focus() end
|
if new_menu then new_menu:focus() end
|
||||||
|
end
|
||||||
self.menu = new_menu
|
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
|
end
|
||||||
if self.menu then self.menu:draw(self.brush, 0) end
|
if self.menu then self.menu:draw(self.brush, 0) end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue