forked from Sokomine/yl_speak_up
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?
|
-- can the button "next" be shown?
|
||||||
local button_next = ""
|
local button_next = ""
|
||||||
-- sort all options by o_sort
|
-- 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
|
local o_found = o_id
|
||||||
for i, o in ipairs(sorted_list) do
|
for i, o in ipairs(sorted_list) do
|
||||||
if(o == o_id and sorted_list[ i-1 ]) then
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- helper function for sorting options/answers using options[o_id].o_sort
|
-- 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 = {}
|
local sorted_list = {}
|
||||||
for k,v in pairs(options) do
|
for k,v in pairs(options) do
|
||||||
table.insert(sorted_list, k)
|
table.insert(sorted_list, k)
|
||||||
end
|
end
|
||||||
table.sort(sorted_list,
|
table.sort(sorted_list,
|
||||||
function(a,b)
|
function(a,b)
|
||||||
return tonumber(options[a].o_sort)
|
return tonumber(options[a][sort_by])
|
||||||
and tonumber(options[b].o_sort)
|
and tonumber(options[b][sort_by])
|
||||||
and tonumber(options[a].o_sort) < tonumber(options[b].o_sort)
|
and tonumber(options[a][sort_by]) < tonumber(options[b][sort_by])
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
return sorted_list
|
return sorted_list
|
||||||
@ -2117,7 +2120,7 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
|||||||
local o_id = fields.o_id
|
local o_id = fields.o_id
|
||||||
-- which dialog to show instead of the deleted one?
|
-- which dialog to show instead of the deleted one?
|
||||||
local next_o_id = o_id
|
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
|
for i, o in ipairs(sorted_list) do
|
||||||
if(o == o_id and sorted_list[ i+1 ]) then
|
if(o == o_id and sorted_list[ i+1 ]) then
|
||||||
next_o_id = sorted_list[ i+1 ]
|
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).")
|
"Dialog "..d_id..": Option "..tostring(o_id).." was set to -1 (do not list).")
|
||||||
else
|
else
|
||||||
-- get the old sorted list
|
-- 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
|
-- negative numbers are not shown
|
||||||
local entries_shown_list = {}
|
local entries_shown_list = {}
|
||||||
for i, o in ipairs(sorted_list) do
|
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
|
-- the player wants to see the previous option/answer
|
||||||
if(fields.edit_option_prev) then
|
if(fields.edit_option_prev) then
|
||||||
-- sort all options by o_sort
|
-- 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
|
local o_found = o_id
|
||||||
for i, o in ipairs(sorted_list) do
|
for i, o in ipairs(sorted_list) do
|
||||||
if(o == o_id and sorted_list[ i-1]) then
|
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
|
-- the player wants to see the next option/answer
|
||||||
elseif(fields.edit_option_next) then
|
elseif(fields.edit_option_next) then
|
||||||
-- sort all options by o_sort
|
-- 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
|
local o_found = o_id
|
||||||
for i, o in ipairs(sorted_list) do
|
for i, o in ipairs(sorted_list) do
|
||||||
if(o == o_id and sorted_list[ i+1 ]) then
|
if(o == o_id and sorted_list[ i+1 ]) then
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user