|
|
|
@ -252,36 +252,36 @@ end
|
|
|
|
|
-- Display a list of menu options and wait for user to choose one. |
|
|
|
|
-- Returns the index of the selected option. |
|
|
|
|
-- Returns 0 if options list is empty. Note: Lua array indices start at 1, not 0). |
|
|
|
|
-- args: an array of option strings. e.g. choose{ "Option 1", "Option 2" } |
|
|
|
|
function M.choose(args) |
|
|
|
|
return M.choosetimer(args, 0, 0) |
|
|
|
|
-- options: an array of option strings. e.g. { "Option 1", "Option 2" } |
|
|
|
|
function M.choose(options) |
|
|
|
|
return M.choosetimer(options, 0, 0) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
-- Display a list of menu options and wait for user to choose one, or for a timer to expire. |
|
|
|
|
-- Returns the index of the selected option, or the defaultoption if the timer expires. |
|
|
|
|
-- Returns 0 if options list is empty. Note: Lua array indices start at 1, not 0). |
|
|
|
|
-- args: an array of option strings. e.g. choose{ "Option 1", "Option 2" } |
|
|
|
|
-- options: an array of option strings. e.g. { "Option 1", "Option 2" } |
|
|
|
|
-- duration: Time player has to pick an option. |
|
|
|
|
-- defaultoption: Option index to return if the timer expires. |
|
|
|
|
function M.choosetimer(args, duration, defaultoption) |
|
|
|
|
if (args == nil or #args == 0) then |
|
|
|
|
function M.choosetimer(options, duration, defaultoption) |
|
|
|
|
if (options == nil or #options == 0) then |
|
|
|
|
return 0 |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
local md = M.getmenudialog() |
|
|
|
|
|
|
|
|
|
-- Do variable substitution before displaying text |
|
|
|
|
local subbed = M.sub(text) |
|
|
|
|
|
|
|
|
|
local selection = 0 |
|
|
|
|
|
|
|
|
|
for i, name in ipairs(args) do |
|
|
|
|
for i, text in ipairs(options) do |
|
|
|
|
|
|
|
|
|
local callback = function () |
|
|
|
|
selection = i; |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
md.AddOption(name, true, M.luaenvironment, callback) |
|
|
|
|
-- Do variable substitution before displaying text |
|
|
|
|
local subbed = M.sub(text) |
|
|
|
|
|
|
|
|
|
md.AddOption(subbed, true, M.luaenvironment, callback) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
if (duration > 0) then |
|
|
|
|