From 0c6e464cf35a24990a86d84893fe2b3953474b97 Mon Sep 17 00:00:00 2001 From: terpyderp Date: Wed, 20 Oct 2021 17:41:54 -0500 Subject: [PATCH] Revert "Revert "Separate in-game bindings from menu bindings"" This reverts commit b2e20895b8923e41eb012659754084c35f7ea632. --- load/version.lua | 2 +- scene.lua | 1 + scene/credits.lua | 3 +- scene/game_config.lua | 12 +++--- scene/input_config.lua | 15 ++++--- scene/key_config.lua | 13 +++--- scene/menu_config.lua | 93 ++++++++++++++++++++++++++++++++++++++++++ scene/mode_select.lua | 14 +++---- scene/settings.lua | 9 ++-- scene/stick_config.lua | 2 +- scene/title.lua | 8 ++-- scene/tuning.lua | 12 +++--- 12 files changed, 140 insertions(+), 44 deletions(-) create mode 100644 scene/menu_config.lua diff --git a/load/version.lua b/load/version.lua index 0f04b6a..0328391 100644 --- a/load/version.lua +++ b/load/version.lua @@ -1 +1 @@ -version = "v0.3" \ No newline at end of file +version = "v0.3.1" \ No newline at end of file diff --git a/scene.lua b/scene.lua index aaa81b8..2839dc5 100644 --- a/scene.lua +++ b/scene.lua @@ -13,6 +13,7 @@ GameScene = require "scene.game" ModeSelectScene = require "scene.mode_select" KeyConfigScene = require "scene.key_config" StickConfigScene = require "scene.stick_config" +MenuConfigScene = require "scene.menu_config" InputConfigScene = require "scene.input_config" GameConfigScene = require "scene.game_config" TuningScene = require "scene.tuning" diff --git a/scene/credits.lua b/scene/credits.lua index c3ecbe7..be92055 100644 --- a/scene/credits.lua +++ b/scene/credits.lua @@ -80,8 +80,7 @@ function CreditsScene:render() end function CreditsScene:onInputPress(e) - if e.input == "menu_decide" or e.scancode == "return" or - e.input == "menu_back" or e.scancode == "delete" or e.scancode == "backspace" then + if e.input == "menu_decide" or e.input == "menu_back" then scene = TitleScene() switchBGM(nil) end diff --git a/scene/game_config.lua b/scene/game_config.lua index c71aa17..c958676 100644 --- a/scene/game_config.lua +++ b/scene/game_config.lua @@ -84,17 +84,17 @@ function ConfigScene:render() end function ConfigScene:onInputPress(e) - if e.input == "menu_decide" or e.scancode == "return" then + if e.input == "menu_decide" then playSE("mode_decide") saveConfig() scene = SettingsScene() - elseif e.input == "up" or e.scancode == "up" then + elseif e.input == "menu_up" then playSE("cursor") self.highlight = Mod1(self.highlight-1, optioncount) - elseif e.input == "down" or e.scancode == "down" then + elseif e.input == "menu_down" then playSE("cursor") self.highlight = Mod1(self.highlight+1, optioncount) - elseif e.input == "left" or e.scancode == "left" then + elseif e.input == "menu_left" then if not self.options[self.highlight][3] then playSE("cursor_lr") local option = ConfigScene.options[self.highlight] @@ -105,7 +105,7 @@ function ConfigScene:onInputPress(e) sld:update() playSE("cursor") end - elseif e.input == "right" or e.scancode == "right" then + elseif e.input == "menu_right" then if not self.options[self.highlight][3] then playSE("cursor_lr") local option = ConfigScene.options[self.highlight] @@ -116,7 +116,7 @@ function ConfigScene:onInputPress(e) sld:update() playSE("cursor") end - elseif e.input == "menu_back" or e.scancode == "delete" or e.scancode == "backspace" then + elseif e.input == "menu_back" then loadSave() scene = SettingsScene() end diff --git a/scene/input_config.lua b/scene/input_config.lua index 7b488f8..3e34bb3 100644 --- a/scene/input_config.lua +++ b/scene/input_config.lua @@ -1,6 +1,6 @@ local ConfigScene = Scene:extend() -ConfigScene.title = "Input Config" +ConfigScene.title = "Game Controls" local menu_screens = { KeyConfigScene, @@ -27,7 +27,7 @@ function ConfigScene:render() ) love.graphics.setFont(font_3x5_4) - love.graphics.print("INPUT CONFIG", 80, 40) + love.graphics.print("IN-GAME CONTROLS", 80, 40) love.graphics.setFont(font_3x5_2) love.graphics.print("Which controls do you want to configure?", 80, 90) @@ -48,18 +48,17 @@ function ConfigScene:changeOption(rel) end function ConfigScene:onInputPress(e) - if e.input == "menu_decide" or e.scancode == "return" then + local had_config = config.input ~= nil + if e.input == "menu_decide" or (not had_config and e.scancode == "return") then playSE("main_decide") scene = menu_screens[self.menu_state]() - elseif e.input == "up" or e.scancode == "up" then + elseif e.input == "menu_up" or (not had_config and e.scancode == "up") then self:changeOption(-1) playSE("cursor") - elseif e.input == "down" or e.scancode == "down" then + elseif e.input == "menu_down" or (not had_config and e.scancode == "down") then self:changeOption(1) playSE("cursor") - elseif config.input and ( - e.input == "menu_back" or e.scancode == "backspace" or e.scancode == "delete" - ) then + elseif had_config and e.input == "menu_back" then scene = SettingsScene() end end diff --git a/scene/key_config.lua b/scene/key_config.lua index 419ebb5..0d398b0 100644 --- a/scene/key_config.lua +++ b/scene/key_config.lua @@ -5,8 +5,6 @@ KeyConfigScene.title = "Key Config" require 'load.save' local configurable_inputs = { - "menu_decide", - "menu_back", "left", "right", "up", @@ -75,10 +73,15 @@ function KeyConfigScene:onInputPress(e) if e.scancode == "return" then -- save new input, then load next scene local had_config = config.input ~= nil - if not config.input then config.input = {} end - config.input.keys = self.new_input + if not had_config then + config.input = {} + config.input.keys = {} + end + for k, v in pairs(self.new_input) do + config.input.keys[k] = v + end saveConfig() - scene = had_config and InputConfigScene() or TitleScene() + scene = had_config and InputConfigScene() or MenuConfigScene() elseif e.scancode == "delete" or e.scancode == "backspace" then -- retry self.input_state = 1 diff --git a/scene/menu_config.lua b/scene/menu_config.lua new file mode 100644 index 0000000..b0d2bd0 --- /dev/null +++ b/scene/menu_config.lua @@ -0,0 +1,93 @@ +local MenuConfigScene = Scene:extend() + +MenuConfigScene.title = "Menu Controls" + +require 'load.save' + +local configurable_inputs = { + "menu_left", + "menu_right", + "menu_up", + "menu_down", + "menu_decide", + "menu_back", +} + +local function newSetInputs() + local set_inputs = {} + for i, input in ipairs(configurable_inputs) do + set_inputs[input] = false + end + return set_inputs +end + +function MenuConfigScene:new() + self.input_state = 1 + self.set_inputs = newSetInputs() + self.new_input = {} + + DiscordRPC:update({ + details = "In settings", + state = "Changing key config", + }) +end + +function MenuConfigScene:update() +end + +function MenuConfigScene:render() + love.graphics.setColor(1, 1, 1, 1) + love.graphics.draw( + backgrounds["input_config"], + 0, 0, 0, + 0.5, 0.5 + ) + + love.graphics.setFont(font_3x5_2) + for i, input in ipairs(configurable_inputs) do + love.graphics.printf(input, 40, 50 + i * 20, 200, "left") + if self.set_inputs[input] then + love.graphics.printf(self.set_inputs[input], 240, 50 + i * 20, 300, "left") + end + end + if self.input_state > table.getn(configurable_inputs) then + love.graphics.print("press enter to confirm, delete/backspace to retry" .. (config.input and ", escape to cancel" or "")) + else + love.graphics.print("press key input for " .. configurable_inputs[self.input_state] .. ", tab to skip, escape to cancel", 0, 0) + love.graphics.print("function keys (F1, F2, etc.), escape, and tab can't be changed", 0, 20) + end +end + +function MenuConfigScene:onInputPress(e) + if e.type == "key" then + -- function keys, escape, and tab are reserved and can't be remapped + if e.scancode == "escape" then + scene = SettingsScene() + elseif self.input_state > table.getn(configurable_inputs) then + if e.scancode == "return" then + -- save new input, then load next scene + local had_config = config.input.menu_left ~= nil + for k, v in pairs(self.new_input) do + config.input.keys[k] = v + end + saveConfig() + scene = had_config and SettingsScene() or TitleScene() + elseif e.scancode == "delete" or e.scancode == "backspace" then + -- retry + self.input_state = 1 + self.set_inputs = newSetInputs() + self.new_input = {} + end + elseif e.scancode == "tab" then + self.set_inputs[configurable_inputs[self.input_state]] = "skipped" + self.input_state = self.input_state + 1 + elseif e.scancode ~= "escape" and not self.new_input[e.scancode] then + -- all other keys can be configured + self.set_inputs[configurable_inputs[self.input_state]] = "key " .. love.keyboard.getKeyFromScancode(e.scancode) .. " (" .. e.scancode .. ")" + self.new_input[e.scancode] = configurable_inputs[self.input_state] + self.input_state = self.input_state + 1 + end + end +end + +return MenuConfigScene \ No newline at end of file diff --git a/scene/mode_select.lua b/scene/mode_select.lua index d35594c..4ec3eee 100755 --- a/scene/mode_select.lua +++ b/scene/mode_select.lua @@ -120,7 +120,7 @@ function ModeSelectScene:onInputPress(e) if e.y ~= 0 then self:changeOption(-e.y) end - elseif e.input == "menu_decide" or e.scancode == "return" then + elseif e.input == "menu_decide" then current_mode = self.menu_state.mode current_ruleset = self.menu_state.ruleset config.current_mode = current_mode @@ -132,17 +132,17 @@ function ModeSelectScene:onInputPress(e) rulesets[self.menu_state.ruleset], self.secret_inputs ) - elseif e.input == "up" or e.scancode == "up" then + elseif e.input == "menu_up" then self:changeOption(-1) self.das_up = true self.das_down = nil - elseif e.input == "down" or e.scancode == "down" then + elseif e.input == "menu_down" then self:changeOption(1) self.das_down = true self.das_up = nil - elseif e.input == "left" or e.input == "right" or e.scancode == "left" or e.scancode == "right" then + elseif e.input == "menu_left" or e.input == "menu_right" then self:switchSelect() - elseif e.input == "menu_back" or e.scancode == "delete" or e.scancode == "backspace" then + elseif e.input == "menu_back" then scene = TitleScene() elseif e.input then self.secret_inputs[e.input] = true @@ -150,9 +150,9 @@ function ModeSelectScene:onInputPress(e) end function ModeSelectScene:onInputRelease(e) - if e.input == "up" or e.scancode == "up" then + if e.input == "menu_up" then self.das_up = nil - elseif e.input == "down" or e.scancode == "down" then + elseif e.input == "menu_down" then self.das_down = nil elseif e.input then self.secret_inputs[e.input] = false diff --git a/scene/settings.lua b/scene/settings.lua index c9663aa..3478887 100644 --- a/scene/settings.lua +++ b/scene/settings.lua @@ -4,6 +4,7 @@ SettingsScene.title = "Settings" local menu_screens = { InputConfigScene, + MenuConfigScene, GameConfigScene, TuningScene } @@ -57,16 +58,16 @@ function SettingsScene:changeOption(rel) end function SettingsScene:onInputPress(e) - if e.input == "menu_decide" or e.scancode == "return" then + if e.input == "menu_decide" then playSE("main_decide") scene = menu_screens[self.menu_state]() - elseif e.input == "up" or e.scancode == "up" then + elseif e.input == "menu_up" then self:changeOption(-1) playSE("cursor") - elseif e.input == "down" or e.scancode == "down" then + elseif e.input == "menu_down" then self:changeOption(1) playSE("cursor") - elseif e.input == "menu_back" or e.scancode == "backspace" or e.scancode == "delete" then + elseif e.input == "menu_back" then scene = TitleScene() end end diff --git a/scene/stick_config.lua b/scene/stick_config.lua index 3e7be01..6c435ba 100644 --- a/scene/stick_config.lua +++ b/scene/stick_config.lua @@ -86,7 +86,7 @@ function StickConfigScene:onInputPress(e) if not config.input then config.input = {} end config.input.joysticks = self.new_input saveConfig() - scene = had_config and InputConfigScene() or TitleScene() + scene = had_config and InputConfigScene() or MenuConfigScene() elseif e.scancode == "delete" or e.scancode == "backspace" then -- retry self.input_state = 1 diff --git a/scene/title.lua b/scene/title.lua index cddb8df..437d5bb 100644 --- a/scene/title.lua +++ b/scene/title.lua @@ -114,16 +114,16 @@ function TitleScene:changeOption(rel) end function TitleScene:onInputPress(e) - if e.input == "menu_decide" or e.scancode == "return" then + if e.input == "menu_decide" then playSE("main_decide") scene = main_menu_screens[self.main_menu_state]() - elseif e.input == "up" or e.scancode == "up" then + elseif e.input == "menu_up" then self:changeOption(-1) playSE("cursor") - elseif e.input == "down" or e.scancode == "down" then + elseif e.input == "menu_down" then self:changeOption(1) playSE("cursor") - elseif e.input == "menu_back" or e.scancode == "backspace" or e.scancode == "delete" then + elseif e.input == "menu_back" then love.event.quit() -- no winter easter egg for now --[[ diff --git a/scene/tuning.lua b/scene/tuning.lua index ef0f4ee..efa546b 100644 --- a/scene/tuning.lua +++ b/scene/tuning.lua @@ -63,25 +63,25 @@ function TuningScene:render() end function TuningScene:onInputPress(e) - if e.input == "menu_decide" or e.scancode == "return" then + if e.input == "menu_decide" then playSE("mode_decide") saveConfig() scene = SettingsScene() - elseif e.input == "up" or e.scancode == "up" then + elseif e.input == "menu_up" then playSE("cursor") self.highlight = Mod1(self.highlight-1, optioncount) - elseif e.input == "down" or e.scancode == "down" then + elseif e.input == "menu_down" then playSE("cursor") self.highlight = Mod1(self.highlight+1, optioncount) - elseif e.input == "left" or e.scancode == "left" then + elseif e.input == "menu_left" then playSE("cursor") sld = self[self.options[self.highlight][3]] sld.value = math.max(sld.min, math.min(sld.max, (sld:getValue() - 1) / (sld.max - sld.min))) - elseif e.input == "right" or e.scancode == "right" then + elseif e.input == "menu_right" then playSE("cursor") sld = self[self.options[self.highlight][3]] sld.value = math.max(sld.min, math.min(sld.max, (sld:getValue() + 1) / (sld.max - sld.min))) - elseif e.input == "menu_back" or e.scancode == "delete" or e.scancode == "backspace" then + elseif e.input == "menu_back" then loadSave() scene = SettingsScene() end