From db4370803a66b4e4d003de4f2f4b247f42c79ccc Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 15 Apr 2019 17:21:23 +0200 Subject: [PATCH] examples/options: rough way to change keys --- examples/menus/options/init.lua | 15 +++++++++++++++ examples/menus/options/widgets.lua | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/examples/menus/options/init.lua b/examples/menus/options/init.lua index ef23f81..5859d20 100644 --- a/examples/menus/options/init.lua +++ b/examples/menus/options/init.lua @@ -48,6 +48,9 @@ function OptionsMenu:new() Widgets.Exit(self, "main") self.menusystem:switchMenu("main") + + self.keyDetector = {} + self.keyDetector.widget = nil end -- MENU FUNCTION @@ -90,6 +93,18 @@ function OptionsMenu:setLanguageMenu() end end +function OptionsMenu:changeKey(widget) + self.keyDetector.isActive = true + self.keyDetector.widget = widget +end + +function OptionsMenu:keypressed( key ) + if (self.keyDetector.isActive) then + self.keyDetector.widget:receiveKey( key ) + self.menusystem:activate() + end +end + function OptionsMenu:draw() love.graphics.setColor(.3, .1, .4, 1) love.graphics.rectangle("fill", 0, 0, 424, 240) diff --git a/examples/menus/options/widgets.lua b/examples/menus/options/widgets.lua index ad1468d..bacb546 100644 --- a/examples/menus/options/widgets.lua +++ b/examples/menus/options/widgets.lua @@ -239,7 +239,14 @@ function widgets.Key:getLabel() end function widgets.Key:action() - --self.scene:changeKey(self.source, self.key) + self.scene:changeKey(self) + self.scene.menusystem:deactivate() +end + +function widgets.Key:receiveKey( key ) + core.options:setInputKey(self.source, self.key, key) + self.label2 = self:getLabel() + self:invalidateCanvas() end