From 3d362341d506208be5be7ccb0d093315c3ee8fdf Mon Sep 17 00:00:00 2001 From: James David Clarke Date: Sat, 23 Dec 2023 20:42:45 +0000 Subject: [PATCH] Hopefully comments are fixed now --- init.lua | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/init.lua b/init.lua index a8ecb61..02d7d4e 100644 --- a/init.lua +++ b/init.lua @@ -77,20 +77,15 @@ end --- Function to show proposal details and voting options, with delete and edit buttons for the author or admin --- Function to show proposal details and voting options, with delete and edit buttons for the author or admin --- Function to show proposal details and voting options, with delete and edit buttons for the author or admin --- Function to show proposal details and voting options, with delete and edit buttons for the author or admin +-- Function to show proposal details and voting options local function show_proposal_details(player_name, proposal_index) local proposal = proposals[proposal_index] if not proposal then return end proposal.comments = proposal.comments or {} - local player_has_privilege = minetest.check_player_privs(player_name, {proposals_admin=true}) local is_author = proposal.author == player_name local has_commented = proposal.comments[player_name] ~= nil - local can_edit = is_author or player_has_privilege local formspec = "size[12,12]" .. "label[0.5,0.5;" .. minetest.formspec_escape(proposal.title) .. " by " .. proposal.author .. "]" .. @@ -98,49 +93,39 @@ local function show_proposal_details(player_name, proposal_index) "label[0.5,4;Votes: Yes(" .. proposal.votes.yes .. ") No(" .. proposal.votes.no .. ") Abstain(" .. proposal.votes.abstain .. ")]" .. "button[0.5,5;2,1;vote_yes;Vote Yes]" .. "button[3,5;2,1;vote_no;Vote No]" .. - "button[5.5,5;2,1;vote_abstain;Abstain]" - - -- Comments section - formspec = formspec .. "label[0.5,6;Comments:]" + "button[5.5,5;2,1;vote_abstain;Abstain]" .. + "label[0.5,6;Comments:]" local comments_str = "" for commenter, comment in pairs(proposal.comments) do comments_str = comments_str .. commenter .. ":\n" .. comment .. "\n\n" end - -- Trim the final newlines comments_str = comments_str:gsub("\n\n$", "") - -- Comments textarea with a scrollbar + -- Scrollable area for comments formspec = formspec .. "scroll_container[0.5,6.5;11,3;scrollbar;vertical]" .. - "textarea[0.25,0.25;10.5,4;;;" .. comments_str .. ";true]" .. + "textarea[0.25,0.25;10.5,4;;;" .. minetest.formspec_escape(comments_str) .. ";true]" .. "scroll_container_end[]" - -- Add Comment button only if the player has not commented yet - if not has_commented and player_name ~= proposal.author then - formspec = formspec .. "button[0.5,10;3,1;add_comment;Add Comment]" + if not is_author then + if not has_commented then + formspec = formspec .. "button[0.5,10;3,1;add_comment;Add Comment]" + else + formspec = formspec .. "button[0.5,10;3,1;edit_my_comment;Edit My Comment]" .. + "button[4,10;3,1;delete_my_comment;Delete My Comment]" + end end - -- Edit and Delete Comment buttons only if the player has commented - if has_commented and not can_edit then - formspec = formspec .. "button[9,10;3,1;edit_comment;Edit Comment]" .. - "button[9,11;3,1;delete_comment;Delete Comment]" - end - - -- Edit Proposal and Delete Proposal buttons if the player has privileges or is the author - if can_edit then + if player_has_privilege or is_author then formspec = formspec .. "button[0.5,11;3,1;edit_proposal;Edit Proposal]" .. "button[4,11;3,1;delete_proposal;Delete Proposal]" end - -- Back button formspec = formspec .. "button[9,11;3,1;back;Back]" minetest.show_formspec(player_name, "vote_changes:proposal_" .. proposal_index, formspec) end - - - -- Function to show the edit proposal formspec local function show_edit_proposal_formspec(player_name, proposal_index) local proposal = proposals[proposal_index]