made yl_speak_up.get_sorted_options more flexible
This commit is contained in:
parent
e8ce4b1c23
commit
e262e3fb9a
@ -948,7 +948,7 @@ local function get_fs_edit_option_dialog(player, n_id, d_id, o_id)
|
||||
-- can the button "next" be shown?
|
||||
local button_next = ""
|
||||
-- sort all options by o_sort
|
||||
local sorted_list = yl_speak_up.get_sorted_options(n_dialog.d_options)
|
||||
local sorted_list = yl_speak_up.get_sorted_options(n_dialog.d_options, "o_sort")
|
||||
local o_found = o_id
|
||||
for i, o in ipairs(sorted_list) do
|
||||
if(o == o_id and sorted_list[ i-1 ]) then
|
||||
@ -2030,17 +2030,20 @@ yl_speak_up.save_changes_and_switch_to_other_dialog = function(player, fields, t
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-- helper function for sorting options/answers using options[o_id].o_sort
|
||||
yl_speak_up.get_sorted_options = function(options)
|
||||
-- (or dialogs by d_sort)
|
||||
yl_speak_up.get_sorted_options = function(options, sort_by)
|
||||
local sorted_list = {}
|
||||
for k,v in pairs(options) do
|
||||
table.insert(sorted_list, k)
|
||||
end
|
||||
table.sort(sorted_list,
|
||||
function(a,b)
|
||||
return tonumber(options[a].o_sort)
|
||||
and tonumber(options[b].o_sort)
|
||||
and tonumber(options[a].o_sort) < tonumber(options[b].o_sort)
|
||||
return tonumber(options[a][sort_by])
|
||||
and tonumber(options[b][sort_by])
|
||||
and tonumber(options[a][sort_by]) < tonumber(options[b][sort_by])
|
||||
end
|
||||
)
|
||||
return sorted_list
|
||||
@ -2117,7 +2120,7 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
||||
local o_id = fields.o_id
|
||||
-- which dialog to show instead of the deleted one?
|
||||
local next_o_id = o_id
|
||||
local sorted_list = yl_speak_up.get_sorted_options(dialog.n_dialogs[d_id].d_options)
|
||||
local sorted_list = yl_speak_up.get_sorted_options(dialog.n_dialogs[d_id].d_options, "o_sort")
|
||||
for i, o in ipairs(sorted_list) do
|
||||
if(o == o_id and sorted_list[ i+1 ]) then
|
||||
next_o_id = sorted_list[ i+1 ]
|
||||
@ -2151,7 +2154,7 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
||||
"Dialog "..d_id..": Option "..tostring(o_id).." was set to -1 (do not list).")
|
||||
else
|
||||
-- get the old sorted list
|
||||
local sorted_list = yl_speak_up.get_sorted_options(dialog.n_dialogs[d_id].d_options)
|
||||
local sorted_list = yl_speak_up.get_sorted_options(dialog.n_dialogs[d_id].d_options, "o_sort")
|
||||
-- negative numbers are not shown
|
||||
local entries_shown_list = {}
|
||||
for i, o in ipairs(sorted_list) do
|
||||
@ -2369,7 +2372,7 @@ minetest.register_on_player_receive_fields(
|
||||
-- the player wants to see the previous option/answer
|
||||
if(fields.edit_option_prev) then
|
||||
-- sort all options by o_sort
|
||||
local sorted_list = yl_speak_up.get_sorted_options(n_dialog.d_options)
|
||||
local sorted_list = yl_speak_up.get_sorted_options(n_dialog.d_options, "o_sort")
|
||||
local o_found = o_id
|
||||
for i, o in ipairs(sorted_list) do
|
||||
if(o == o_id and sorted_list[ i-1]) then
|
||||
@ -2383,7 +2386,7 @@ minetest.register_on_player_receive_fields(
|
||||
-- the player wants to see the next option/answer
|
||||
elseif(fields.edit_option_next) then
|
||||
-- sort all options by o_sort
|
||||
local sorted_list = yl_speak_up.get_sorted_options(n_dialog.d_options)
|
||||
local sorted_list = yl_speak_up.get_sorted_options(n_dialog.d_options, "o_sort")
|
||||
local o_found = o_id
|
||||
for i, o in ipairs(sorted_list) do
|
||||
if(o == o_id and sorted_list[ i+1 ]) then
|
||||
|
Loading…
Reference in New Issue
Block a user