--- game/engines/default/engine/ui/Dialog.lua.orig 2013-06-24 23:29:28.000000000 -0400 +++ game/engines/default/engine/ui/Dialog.lua 2013-09-21 23:08:19.000000000 -0400 @@ -96,12 +96,27 @@ end d:setupUI(true, true) game:registerDialog(d) return d end +local function configureYesNoKeys(d, fct, yes_text, no_text) + yes_text = yes_text or "Yes" + no_text = no_text or "No" + if yes_text:sub(1, 1):lower() ~= no_text:sub(1, 1):lower() then + d.key:addCommands{ + __TEXTINPUT = function(c) + if c:lower() == yes_text:sub(1, 1):lower() then game:unregisterDialog(d) fct(true) + elseif c:lower() == no_text:sub(1, 1):lower() then game:unregisterDialog(d) fct(false) + end + end, + } + d.on_register = function() game:onTickEnd(function() d.key:unicodeInput(true) end) end + end +end + --- Requests a simple yes-no dialog function _M:yesnoPopup(title, text, fct, yes_text, no_text, no_leave, escape) local w, h = self.font:size(text) local d = new(title, 1, 1) -- d.key:addBind("EXIT", function() game:unregisterDialog(d) fct(false) end) @@ -112,12 +127,13 @@ {left = 3, top = 3, ui=require("engine.ui.Textzone").new{width=w+20, height=h+5, text=text}}, {left = 3, bottom = 3, ui=ok}, {right = 3, bottom = 3, ui=cancel}, } d:setFocus(ok) d:setupUI(true, true) + configureYesNoKeys(d, fct, yes_text, no_text) game:registerDialog(d) return d end --- Requests a long yes-no dialog @@ -133,12 +149,13 @@ {left = 3, top = 3, ui=require("engine.ui.Textzone").new{width=w+20, height=self.font_h * #list, text=text}}, {left = 3, bottom = 3, ui=ok}, {right = 3, bottom = 3, ui=cancel}, } d:setFocus(ok) d:setupUI(true, true) + configureYesNoKeys(d, fct, yes_text, no_text) game:registerDialog(d) return d end --- Requests a simple yes-no dialog @@ -156,12 +173,13 @@ {left = 3, bottom = 3, ui=ok}, {left = 3 + ok.w, bottom = 3, ui=no}, {right = 3, bottom = 3, ui=cancel}, } d:setFocus(ok) d:setupUI(true, true) + configureYesNoKeys(d, fct, yes_text, no_text) game:registerDialog(d) return d end --- Requests a simple yes-no dialog @@ -179,12 +197,13 @@ {left = 3, bottom = 3, ui=ok}, {left = 3 + ok.w, bottom = 3, ui=no}, {right = 3, bottom = 3, ui=cancel}, } d:setFocus(ok) d:setupUI(true, true) + configureYesNoKeys(d, fct, yes_text, no_text) game:registerDialog(d) return d end