diff --git a/fs_edit_options_dialog.lua b/fs_edit_options_dialog.lua index 42c9ba8..122d054 100644 --- a/fs_edit_options_dialog.lua +++ b/fs_edit_options_dialog.lua @@ -43,6 +43,16 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields) return end + -- for now, there's only trade as action + if(fields.table_of_actions) then + local trade_id = tostring(d_id).." "..tostring(o_id) + if(dialog.trades and dialog.trades[ trade_id ]) then + fields.effect_show_trade = true + else + fields.effect_add_trade = true + end + end + -- add or edit the trade associated with this dialog and option if(fields.effect_add_trade) then -- remember which option was selected @@ -130,6 +140,20 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id) end end + local list_of_actions = "" + if(dialog.trades and dialog.trades[ tostring(d_id).." "..tostring(o_id) ]) then + local tr = dialog.trades[ tostring(d_id).." "..tostring(o_id)] + -- show the trade in the result/effects list + list_of_actions = ",#00FF00,trade,".. + -- show a reasonable overview of what is traded for what + minetest.formspec_escape("NPC sells ".. + table.concat(tr.buy, ";").." for ".. + table.concat(tr.pay, ";")) + else + list_of_actions = ",#00FF00,add,".. + "Add a new effect" + end + -- find the right target dialog for this option (if it exists) local target_dialog = nil -- and build the list of effects @@ -148,28 +172,6 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id) end end end - -- trade is one of the very few effects players can set - local button_add_edit_trade = "" - if(dialog and dialog.trades and dialog.trades[ tostring(d_id).." "..tostring(o_id)]) then - button_add_edit_trade = "".. - "button[14.8,10;2.0,0.9;effect_show_trade;Show trade]".. - "tooltip[effect_show_trade;Show and edit the trade that starts ".. - "when selecting this option.]" - local tr = dialog.trades[ tostring(d_id).." "..tostring(o_id)] - -- show the trade in the result/effects list - list_of_effects = list_of_effects.. - ",#FFFF00,trade,".. - -- show a reasonable overview of what is traded for what - minetest.formspec_escape("NPC sells ".. - table.concat(tr.buy, ";").." for ".. - table.concat(tr.pay, ";")).."," - - else - button_add_edit_trade = "".. - "button[14.8,10;2.0,0.9;effect_add_trade;Add trade]".. - "tooltip[effect_add_trade;Add a trade that will start ".. - "when selecting this option.]" - end -- if no target dialog has been selected: default is to go to the dialog with d_sort 0 if(not(target_dialog) or target_dialog == "" or not(dialog.n_dialogs[target_dialog])) then @@ -223,13 +225,13 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id) for i, o in ipairs(sorted_list) do if(o == o_id and sorted_list[ i-1 ]) then button_prev = "".. - "button[7.4,17;2.0,0.9;edit_option_prev;Prev]".. + "button[7.4,18.7;2.0,0.9;edit_option_prev;Prev]".. "tooltip[edit_option_prev;Go to previous option/answer ".. "(according to o_sort).]" end if(o == o_id and sorted_list[ i+1 ]) then button_next = "".. - "button[12.0,17;2.0,0.9;edit_option_next;Next]".. + "button[12.0,18.7;2.0,0.9;edit_option_next;Next]".. "tooltip[edit_option_next;Go to next option/answer ".. "(according to o_sort).]" end @@ -238,7 +240,7 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id) -- less than yl_speak_up.max_number_of_options_per_dialog options? local button_add = "".. - "button[2.4,17;2.0,0.9;add_option;Add]".. + "button[2.4,18.7;2.0,0.9;add_option;Add]".. "tooltip[add_option;Add a new option/answer to this dialog.]" if(anz_options >= yl_speak_up.max_number_of_options_per_dialog) then button_add = "" @@ -247,7 +249,7 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id) -- build up the formspec local formspec = "".. "formspec_version[3]".. - "size[21,18]".. + "size[21,20]".. "bgcolor[#00000000;false]".. -- button back to the current dialog (of which this is an option) "button[15.8,0.2;5.0,0.9;show_current_dialog;Back to dialog ".. @@ -285,27 +287,32 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id) minetest.formspec_escape(d_option.o_text_when_prerequisites_not_met).."]".. "tooltip[option_text_not_met;This is the answer the player may choose if the ".. "preconditions are NOT all fulfilled.]".. + -- list of (A)ctions (there can only be one per option; i.e. a trade) + "label[0.2,10.6;When this answer has been selected, start the following (A)ction:]".. + "tablecolumns[text;color,span=1;text;text]".. + "table[1.2,10.9;19.6,0.7;table_of_actions;".. + list_of_actions..";0]".. -- list of effects - "label[0.2,10.6;When this answer has been selected, apply the following (Ef)fects:]".. - button_add_edit_trade.. + "label[0.2,12.0;If the player completed the above action successfully, ".. + "apply the following (Ef)fects:]".. -- TODO: perhaps add tooltip for the type of the conditions "tablecolumns[text;color,span=1;text;text]".. - "table[1.2,11.0;19.6,2.0;table_of_effect;".. + "table[1.2,12.3;21.0,2.0;table_of_effect;".. list_of_effects..";0]".. -- ..and what the NPC will reply to that answer - "label[0.2,13.6;The NPC will react to this answer with the following dialog:]".. - "hypertext[1.2,14.2;19.6,2.5;d_text_next;".. + "label[0.2,15.1;The NPC will react to this answer with the following dialog:]".. + "hypertext[1.2,15.7;19.6,2.5;d_text_next;".. minetest.formspec_escape(next_text) .. "\n".."]".. - "tooltip[1.2,14.2;19.6,2.5;This is what the NPC will say next when the player has ".. + "tooltip[1.2,16.8;21.0,2.5;This is what the NPC will say next when the player has ".. "selected this answer here.]".. -- allow to change the target dialog via a dropdown menu - "dropdown[14.8,13.2;5,0.9;d_id_"..minetest.formspec_escape(o_id)..";".. + "dropdown[14.8,14.7;5,0.9;d_id_"..minetest.formspec_escape(o_id)..";".. dialog_list..";"..dialog_selected..",]".. - "tooltip[14.8,13.2;5,0.9;Select the target dialog with which the NPC shall react ".. + "tooltip[14.8,14.7;5,0.9;Select the target dialog with which the NPC shall react ".. "to this answer. Currently, dialog "..minetest.formspec_escape(target_dialog).. " is beeing displayed.;#FFFFFF;#000000]".. -- button: delete - "button[0.2,17;2.0,0.9;del_option;Delete]".. + "button[0.2,18.7;2.0,0.9;del_option;Delete]".. "tooltip[del_option;Delete this option/answer.]".. -- button: add new button_add.. @@ -313,13 +320,13 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id) button_prev.. button_next.. -- button: go back to dialog (repeated from top of the page) - "button[15.8,17;5.0,0.9;show_current_dialog;Back to dialog ".. + "button[15.8,18.7;5.0,0.9;show_current_dialog;Back to dialog ".. minetest.formspec_escape(d_id).."]".. "tooltip[show_current_dialog;Go back to dialog ".. minetest.formspec_escape(d_id).." and continue editing that dialog.]".. -- allow to enter o_sort - "label[9.6,17.5;Sort:]".. - "field[10.6,17;1.0,0.9;edit_option_o_sort;;".. + "label[9.6,19.2;Sort:]".. + "field[10.6,18.7;1.0,0.9;edit_option_o_sort;;".. minetest.formspec_escape(d_option.o_sort).."]".. "tooltip[edit_option_o_sort;o_sort: The lower the number, the higher up in the ".. "list this option goes\nNegative values are ignored;#FFFFFF;#000000]"..