From a470b40defcba59d24331df48c2e1317c4bfa438 Mon Sep 17 00:00:00 2001 From: Ishaan Bhardwaj Date: Tue, 10 Nov 2020 20:08:34 -0500 Subject: [PATCH] Refactored input handling, so that arrow keys will always work on menus. --- scene/game.lua | 4 ++-- scene/game_config.lua | 8 ++++---- scene/mode_select.lua | 6 +++--- scene/title.lua | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/scene/game.lua b/scene/game.lua index 05b5ff3..2629ae6 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -71,11 +71,11 @@ function GameScene:render() end function GameScene:onInputPress(e) - if self.game.completed and (e.input == "menu_decide" or e.input == "menu_back") then + if self.game.completed and (e.input == "menu_decide" or e.input == "menu_back" or e.input == "retry") then highscore_entry = self.game:getHighscoreData() highscore_hash = self.game.hash .. "-" .. self.ruleset.hash submitHighscore(highscore_hash, highscore_entry) - scene = ModeSelectScene() + scene = e.input == "retry" and GameScene(self.retry_mode, self.retry_ruleset) or ModeSelectScene() elseif e.input == "retry" then scene = GameScene(self.retry_mode, self.retry_ruleset) elseif e.input == "menu_back" then diff --git a/scene/game_config.lua b/scene/game_config.lua index 824906c..ed0877e 100644 --- a/scene/game_config.lua +++ b/scene/game_config.lua @@ -56,17 +56,17 @@ function ConfigScene:onInputPress(e) playSE("mode_decide") saveConfig() scene = TitleScene() - elseif e.input == "up" then + elseif e.input == "up" or e.scancode == "up" then playSE("cursor") self.highlight = Mod1(self.highlight-1, optioncount) - elseif e.input == "down" then + elseif e.input == "down" or e.scancode == "down" then playSE("cursor") self.highlight = Mod1(self.highlight+1, optioncount) - elseif e.input == "left" then + elseif e.input == "left" or e.scancode == "left" then playSE("cursor_lr") local option = ConfigScene.options[self.highlight] config.gamesettings[option[1]] = Mod1(config.gamesettings[option[1]]-1, #option[3]) - elseif e.input == "right" then + elseif e.input == "right" or e.scancode == "right" then playSE("cursor_lr") local option = ConfigScene.options[self.highlight] config.gamesettings[option[1]] = Mod1(config.gamesettings[option[1]]+1, #option[3]) diff --git a/scene/mode_select.lua b/scene/mode_select.lua index 51ee21e..071cb61 100755 --- a/scene/mode_select.lua +++ b/scene/mode_select.lua @@ -67,13 +67,13 @@ function ModeSelectScene:onInputPress(e) playSE("mode_decide") saveConfig() scene = GameScene(game_modes[self.menu_state.mode], rulesets[self.menu_state.ruleset]) - elseif e.input == "up" then + elseif e.input == "up" or e.scancode == "up" then self:changeOption(-1) playSE("cursor") - elseif e.input == "down" then + elseif e.input == "down" or e.scancode == "down" then self:changeOption(1) playSE("cursor") - elseif e.input == "left" or e.input == "right" then + elseif e.input == "left" or e.input == "right" or e.scancode == "left" or e.scancode == "right" then self:switchSelect() playSE("cursor_lr") elseif e.input == "menu_back" then diff --git a/scene/title.lua b/scene/title.lua index 0a7dc52..ed5b8ba 100644 --- a/scene/title.lua +++ b/scene/title.lua @@ -61,10 +61,10 @@ function TitleScene:onInputPress(e) if e.input == "menu_decide" then playSE("main_decide") scene = main_menu_screens[self.main_menu_state]() - elseif e.input == "up" then + elseif e.input == "up" or e.scancode == "up" then self:changeOption(-1) playSE("cursor") - elseif e.input == "down" then + elseif e.input == "down" or e.scancode == "down" then self:changeOption(1) playSE("cursor") elseif e.input == "menu_back" then