diff --git a/formspec_helpers.lua b/formspec_helpers.lua index 245fcac..2c7549b 100644 --- a/formspec_helpers.lua +++ b/formspec_helpers.lua @@ -263,3 +263,56 @@ yl_speak_up.get_fs_manage_general = function(player, param, -- either nil or the text of the selected entry return selected end + + + +-- small helper function for the function below +yl_speak_up.get_fs_colorize_table = function(formspec, table_specs, liste, color) + table.insert(formspec, "tablecolumns[color;text]table[") + table.insert(formspec, table_specs) + local tmp = {} + for k, v in pairs(liste) do + table.insert(tmp, color or "#FFFFFF") + table.insert(tmp, minetest.formspec_escape(v)) + end + table.insert(formspec, table.concat(tmp, ",")) + table.insert(formspec, ";]") +end + + +yl_speak_up.get_fs_show_list_in_box = function(formspec, + label, field_name, liste, start_x, start_y, width, height, label_ident, + box_color, column_color, + tooltip_text, add_lines) + local dim_str = tostring(width)..","..tostring(height) + table.insert(formspec, "container[") + table.insert(formspec, tostring(start_x)..","..tostring(start_y)..";") + table.insert(formspec, dim_str) + table.insert(formspec, "]") + table.insert(formspec, "box[0,0;") + table.insert(formspec, dim_str) + table.insert(formspec, ";") + table.insert(formspec, box_color or "#666666") + table.insert(formspec, "]") + -- add buttons etc. first so that the label remains visible on top + if(add_lines) then + table.insert(formspec, add_lines) + end + table.insert(formspec, "label[") + table.insert(formspec, tostring(0.1 + label_ident)) + table.insert(formspec, ",0.5;") + table.insert(formspec, label) + table.insert(formspec, "]") + yl_speak_up.get_fs_colorize_table(formspec, + "0.1,0.7;"..tostring(width-0.2)..","..tostring(height-0.8)..";"..tostring(field_name)..";", + liste or {}, column_color) + if(tooltip_text and tooltip_text ~= "") then + table.insert(formspec, "tooltip[") + table.insert(formspec, field_name) + table.insert(formspec, ";") + table.insert(formspec, tooltip_text) + table.insert(formspec, "\n\nClick on an element to select it.") + table.insert(formspec, "]") + end + table.insert(formspec, "container_end[]") +end diff --git a/fs_manage_quest_steps.lua b/fs_manage_quest_steps.lua index 956bf92..02931d8 100644 --- a/fs_manage_quest_steps.lua +++ b/fs_manage_quest_steps.lua @@ -256,58 +256,6 @@ yl_speak_up.input_fs_manage_quest_steps = function(player, formname, fields) end --- small helper function for yl_speak_up.get_fs_manage_quest_steps -yl_speak_up.quest_step_show_table = function(formspec, table_specs, liste, color) - table.insert(formspec, "tablecolumns[color;text]table[") - table.insert(formspec, table_specs) - local tmp = {} - for k, v in pairs(liste) do - table.insert(tmp, color or "#FFFFFF") - table.insert(tmp, minetest.formspec_escape(v)) - end - table.insert(formspec, table.concat(tmp, ",")) - table.insert(formspec, ";]") -end - - -yl_speak_up.quest_step_show_table_decorated = function(formspec, - label, field_name, liste, start_x, start_y, width, height, label_ident, - box_color, column_color, - tooltip_text, add_lines) - local dim_str = tostring(width)..","..tostring(height) - table.insert(formspec, "container[") - table.insert(formspec, tostring(start_x)..","..tostring(start_y)..";") - table.insert(formspec, dim_str) - table.insert(formspec, "]") - table.insert(formspec, "box[0,0;") - table.insert(formspec, dim_str) - table.insert(formspec, ";") - table.insert(formspec, box_color or "#666666") - table.insert(formspec, "]") - -- add buttons etc. first so that the label remains visible on top - if(add_lines) then - table.insert(formspec, add_lines) - end - table.insert(formspec, "label[") - table.insert(formspec, tostring(0.1 + label_ident)) - table.insert(formspec, ",0.5;") - table.insert(formspec, label) - table.insert(formspec, "]") - yl_speak_up.quest_step_show_table(formspec, - "0.1,0.7;"..tostring(width-0.2)..","..tostring(height-0.8)..";"..tostring(field_name)..";", - liste or {}, column_color) - if(tooltip_text and tooltip_text ~= "") then - table.insert(formspec, "tooltip[") - table.insert(formspec, field_name) - table.insert(formspec, ";") - table.insert(formspec, tooltip_text) - table.insert(formspec, "\n\nClick on an element to select it.") - table.insert(formspec, "]") - end - table.insert(formspec, "container_end[]") -end - - yl_speak_up.get_fs_manage_quest_steps = function(player, param) -- small helper function local em = function(text) @@ -355,20 +303,20 @@ yl_speak_up.get_fs_manage_quest_steps = function(player, param) table.insert(formspec, yl_speak_up.get_fs_add_quest_steps(player, nil)) table.insert(formspec, "container_end[]") local lists = yl_speak_up.quest_step_get_start_end_unconnected_lists(step_data) - yl_speak_up.quest_step_show_table_decorated(formspec, + yl_speak_up.get_fs_show_list_in_box(formspec, "Start steps:", "TODO_select_from_start_steps", lists.start_steps, "0.1", "2.7", "5.6", "4.3", 0, nil, "#AAFFAA", "The quest begins with this (or one of these) steps.\n".. "You need at least one start step.", nil) - yl_speak_up.quest_step_show_table_decorated(formspec, + yl_speak_up.get_fs_show_list_in_box(formspec, "Unconnected steps:", "TODO_select_from_unconnected_steps", lists.unconnected_steps, "0.1", "7.0", "5.6", "4.3", 0, nil, "#FFAAAA", "These steps are not used yet. They are not required\n".. "by any other steps and do not require steps either.\n".. "Please decide what to do with them!", nil) - yl_speak_up.quest_step_show_table_decorated(formspec, + yl_speak_up.get_fs_show_list_in_box(formspec, "Quest ends with steps:", "TODO_select_from_end_steps", lists.end_steps, "24", "2.7", "5.6", "8.5", "0.1", nil, "#AAFFAA", "This quest ends with these steps. They are not required\n".. @@ -396,7 +344,7 @@ yl_speak_up.get_fs_manage_quest_steps = function(player, param) "label[0.2,2.4;quest step(s):]".. "style[insert_before_next_step,insert_after_prev_step,".. "add_to_one_needed,add_to_all_needed;bgcolor=blue;textcolor=yellow]") - yl_speak_up.quest_step_show_table_decorated(formspec, + yl_speak_up.get_fs_show_list_in_box(formspec, em("One of").." these quest steps:", "one_step_required", step_data[selected].one_step_required, "0.1", "2.7", "5.6", "4.3", 0, nil, "#AAFFAA", @@ -410,7 +358,7 @@ yl_speak_up.get_fs_manage_quest_steps = function(player, param) "to achieve this current quest step here.", "button[4.6,0.0;0.94,0.7;add_to_one_needed;Edit]".. "tooltip[add_to_one_needed;Add or remove a quest step to this list.]") - yl_speak_up.quest_step_show_table_decorated(formspec, + yl_speak_up.get_fs_show_list_in_box(formspec, em("All of").." these quest steps:", "all_steps_required", step_data[selected].all_steps_required, "0.1", "7.0", "5.6", "4.3", 0, nil, "#AAFFAA", @@ -457,7 +405,7 @@ yl_speak_up.get_fs_manage_quest_steps = function(player, param) table.insert(formspec, "container[23.8,0;5.8,13.5]".. "label[0.6,2.0;Achieving this quest step]".. "label[0.6,2.4;"..em("helps").." the quester to:]") - yl_speak_up.quest_step_show_table_decorated(formspec, + yl_speak_up.get_fs_show_list_in_box(formspec, "get these quest step(s) "..em("next")..":", "next_steps_show", required_for, -- the label needs to be moved slightly to the right to make room for the > button