Changed reserved keys (arrows are no longer reserved) and now F2 always gets to the input config except when in-game.

This commit is contained in:
nightmareci 2020-11-10 14:37:59 -08:00
parent e1dc01d0d0
commit fd739dcfdf
3 changed files with 29 additions and 37 deletions

View File

@ -114,14 +114,15 @@ function love.keypressed(key, scancode)
if scancode == "f4" then if scancode == "f4" then
config["fullscreen"] = not config["fullscreen"] config["fullscreen"] = not config["fullscreen"]
love.window.setFullscreen(config["fullscreen"]) love.window.setFullscreen(config["fullscreen"])
-- reserved keys, so the user can always get back to configure input elseif scancode == "f2" and scene.title ~= "Input Config" and scene.title ~= "Game" then
elseif scancode == "return" then scene = InputConfigScene()
scene:onInputPress({input="menu_decide", type="key", key=key, scancode=scancode}) -- function keys are reserved
elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f[1-9][0-9]+$") then
return
-- escape is reserved for menu_back
elseif scancode == "escape" then elseif scancode == "escape" then
scene:onInputPress({input="menu_back", type="key", key=key, scancode=scancode}) scene:onInputPress({input="menu_back", type="key", key=key, scancode=scancode})
elseif scancode == "left" or scancode == "right" or scancode == "up" or scancode == "down" then -- pass any other key to the scene, with its configured mapping
scene:onInputPress({input=scancode, type="key", key=key, scancode=scancode})
-- other keys can be configured
else else
local input_pressed = nil local input_pressed = nil
if config.input and config.input.keys then if config.input and config.input.keys then
@ -132,14 +133,13 @@ function love.keypressed(key, scancode)
end end
function love.keyreleased(key, scancode) function love.keyreleased(key, scancode)
-- reserved keys, so the user can always get back to configure input -- escape is reserved for menu_back
if scancode == "return" then if scancode == "escape" then
scene:onInputRelease({input="menu_decide", type="key", key=key, scancode=scancode})
elseif scancode == "escape" then
scene:onInputRelease({input="menu_back", type="key", key=key, scancode=scancode}) scene:onInputRelease({input="menu_back", type="key", key=key, scancode=scancode})
elseif scancode == "left" or scancode == "right" or scancode == "up" or scancode == "down" then -- function keys are reserved
scene:onInputRelease({input=scancode, type="key", key=key, scancode=scancode}) elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f[1-9][0-9]+$") then
-- other keys can be configured return
-- handle all other keys; tab is reserved, but the input config scene keeps it from getting configured as a game input, so pass tab to the scene here
else else
local input_released = nil local input_released = nil
if config.input and config.input.keys then if config.input and config.input.keys then

View File

@ -1,4 +1,7 @@
local GameScene = Scene:extend() local GameScene = Scene:extend()
GameScene.title = "Game"
require 'load.save' require 'load.save'
function GameScene:new(game_mode, ruleset) function GameScene:new(game_mode, ruleset)

View File

@ -61,7 +61,7 @@ function ConfigScene:render()
love.graphics.print("press enter to confirm, delete/backspace to retry" .. (config.input and ", escape to cancel" or "")) love.graphics.print("press enter to confirm, delete/backspace to retry" .. (config.input and ", escape to cancel" or ""))
else else
love.graphics.print("press key or joystick input for " .. configurable_inputs[self.input_state] .. ", tab to skip" .. (config.input and ", escape to cancel" or ""), 0, 0) love.graphics.print("press key or joystick input for " .. configurable_inputs[self.input_state] .. ", tab to skip" .. (config.input and ", escape to cancel" or ""), 0, 0)
love.graphics.print("enter, delete, backspace, tab, arrows, and escape can't be changed", 0, 20) love.graphics.print("function keys (F1, F2, etc.), escape, and tab can't be changed", 0, 20)
end end
end end
@ -76,8 +76,9 @@ end
function ConfigScene:onInputPress(e) function ConfigScene:onInputPress(e)
if e.type == "key" then if e.type == "key" then
-- enter, delete, backspace, tab, arrows, and escape are reserved and can't be remapped -- function keys, escape, and tab are reserved and can't be remapped
if e.scancode == "escape" and config.input then if e.scancode == "escape" and config.input then
-- cancel only if there was an input config already
scene = TitleScene() scene = TitleScene()
elseif self.input_state > table.getn(configurable_inputs) then elseif self.input_state > table.getn(configurable_inputs) then
if e.scancode == "return" then if e.scancode == "return" then
@ -90,23 +91,12 @@ function ConfigScene:onInputPress(e)
self.input_state = 1 self.input_state = 1
self.set_inputs = newSetInputs() self.set_inputs = newSetInputs()
self.new_input = {} self.new_input = {}
elseif e.scancode == "escape" and config.input then
-- cancel only if there was an input config already
scene = TitleScene()
end end
elseif elseif e.scancode == "tab" then
e.scancode ~= "delete" and
e.scancode ~= "backspace" and
e.scancode ~= "return" and
e.scancode ~= "left" and
e.scancode ~= "right" and
e.scancode ~= "up" and
e.scancode ~= "down"
then
if e.scancode == "tab" then
self.set_inputs[configurable_inputs[self.input_state]] = "skipped" self.set_inputs[configurable_inputs[self.input_state]] = "skipped"
self.input_state = self.input_state + 1 self.input_state = self.input_state + 1
else elseif e.scancode ~= "escape" then
-- all other keys can be configured
if not self.new_input.keys then if not self.new_input.keys then
self.new_input.keys = {} self.new_input.keys = {}
end end
@ -114,7 +104,6 @@ function ConfigScene:onInputPress(e)
self.new_input.keys[e.scancode] = configurable_inputs[self.input_state] self.new_input.keys[e.scancode] = configurable_inputs[self.input_state]
self.input_state = self.input_state + 1 self.input_state = self.input_state + 1
end end
end
elseif string.sub(e.type, 1, 3) == "joy" then elseif string.sub(e.type, 1, 3) == "joy" then
if self.input_state <= table.getn(configurable_inputs) then if self.input_state <= table.getn(configurable_inputs) then
if e.type == "joybutton" then if e.type == "joybutton" then