mirror of
https://github.com/JamesClarke7283/proposals.git
synced 2025-03-21 16:01:23 +00:00
Added back button
This commit is contained in:
parent
318df60596
commit
28f547e1f9
1 changed files with 16 additions and 8 deletions
24
init.lua
24
init.lua
|
@ -30,11 +30,13 @@ local function show_formspec(player_name)
|
||||||
"label[0.5,0.5;Vote on Changes]" ..
|
"label[0.5,0.5;Vote on Changes]" ..
|
||||||
"textlist[0.5,1;9,4;proposals;"
|
"textlist[0.5,1;9,4;proposals;"
|
||||||
|
|
||||||
for i, proposal in ipairs(proposals) do
|
if #proposals > 0 then
|
||||||
formspec = formspec .. minetest.formspec_escape(proposal.title .. " by " .. proposal.author) .. ","
|
for _, proposal in ipairs(proposals) do
|
||||||
|
formspec = formspec .. minetest.formspec_escape(proposal.title .. " by " .. proposal.author) .. ","
|
||||||
|
end
|
||||||
|
formspec = formspec:sub(1, -2)
|
||||||
end
|
end
|
||||||
|
|
||||||
formspec = formspec:sub(1, -2) -- Remove last comma
|
|
||||||
formspec = formspec .. "]" ..
|
formspec = formspec .. "]" ..
|
||||||
"button[0.5,6;3,1;add_proposal;Add Proposal]" ..
|
"button[0.5,6;3,1;add_proposal;Add Proposal]" ..
|
||||||
"button_exit[6.5,6;3,1;exit;Exit]"
|
"button_exit[6.5,6;3,1;exit;Exit]"
|
||||||
|
@ -42,6 +44,7 @@ local function show_formspec(player_name)
|
||||||
minetest.show_formspec(player_name, "vote_changes:main", formspec)
|
minetest.show_formspec(player_name, "vote_changes:main", formspec)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Function to show the add proposal formspec
|
-- Function to show the add proposal formspec
|
||||||
local function show_add_proposal_formspec(player_name)
|
local function show_add_proposal_formspec(player_name)
|
||||||
local formspec = "size[8,4]" ..
|
local formspec = "size[8,4]" ..
|
||||||
|
@ -51,7 +54,7 @@ local function show_add_proposal_formspec(player_name)
|
||||||
minetest.show_formspec(player_name, "vote_changes:add_proposal", formspec)
|
minetest.show_formspec(player_name, "vote_changes:add_proposal", formspec)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function to show proposal details and voting options, with delete button for the author
|
-- Function to show proposal details and voting options, with delete button for the author or admin
|
||||||
local function show_proposal_details(player_name, proposal_index)
|
local function show_proposal_details(player_name, proposal_index)
|
||||||
local proposal = proposals[proposal_index]
|
local proposal = proposals[proposal_index]
|
||||||
if not proposal then return end
|
if not proposal then return end
|
||||||
|
@ -59,7 +62,7 @@ local function show_proposal_details(player_name, proposal_index)
|
||||||
local player_has_privilege = minetest.check_player_privs(player_name, {proposals_admin=true})
|
local player_has_privilege = minetest.check_player_privs(player_name, {proposals_admin=true})
|
||||||
local is_author = proposal.author == player_name
|
local is_author = proposal.author == player_name
|
||||||
|
|
||||||
local formspec = "size[8,7]" ..
|
local formspec = "size[8,8]" ..
|
||||||
"label[0.5,0.5;" .. minetest.formspec_escape(proposal.title) .. " by " .. proposal.author .. "]" ..
|
"label[0.5,0.5;" .. minetest.formspec_escape(proposal.title) .. " by " .. proposal.author .. "]" ..
|
||||||
"textarea[0.5,1.5;7.5,2;;" .. minetest.formspec_escape(proposal.description) .. ";]" ..
|
"textarea[0.5,1.5;7.5,2;;" .. minetest.formspec_escape(proposal.description) .. ";]" ..
|
||||||
"label[0.5,4;Votes: Yes(" .. proposal.votes.yes .. ") No(" .. proposal.votes.no .. ") Abstain(" .. proposal.votes.abstain .. ")]"
|
"label[0.5,4;Votes: Yes(" .. proposal.votes.yes .. ") No(" .. proposal.votes.no .. ") Abstain(" .. proposal.votes.abstain .. ")]"
|
||||||
|
@ -71,13 +74,16 @@ local function show_proposal_details(player_name, proposal_index)
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_author or player_has_privilege then
|
if is_author or player_has_privilege then
|
||||||
formspec = formspec .. "button[2.5,6;3,1;delete_proposal;Delete Proposal]"
|
formspec = formspec .. "button[0.5,6;3,1;delete_proposal;Delete Proposal]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
formspec = formspec .. "button[5.5,6;2,1;back;Back]"
|
||||||
|
|
||||||
minetest.show_formspec(player_name, "vote_changes:proposal_" .. proposal_index, formspec)
|
minetest.show_formspec(player_name, "vote_changes:proposal_" .. proposal_index, formspec)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Register the /vote_changes command
|
-- Register the /vote_changes command
|
||||||
minetest.register_chatcommand("proposals", {
|
minetest.register_chatcommand("proposals", {
|
||||||
description = "Open the voting interface",
|
description = "Open the voting interface",
|
||||||
|
@ -106,8 +112,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
if proposal then
|
if proposal then
|
||||||
local player_has_privilege = minetest.check_player_privs(player_name, {proposals_admin=true})
|
local player_has_privilege = minetest.check_player_privs(player_name, {proposals_admin=true})
|
||||||
local is_author = proposal.author == player_name
|
local is_author = proposal.author == player_name
|
||||||
|
|
||||||
if fields.delete_proposal and (is_author or player_has_privilege) then
|
if fields.back then
|
||||||
|
show_formspec(player_name)
|
||||||
|
elseif fields.delete_proposal and (is_author or player_has_privilege) then
|
||||||
table.remove(proposals, proposal_index)
|
table.remove(proposals, proposal_index)
|
||||||
save_proposals()
|
save_proposals()
|
||||||
show_formspec(player_name)
|
show_formspec(player_name)
|
||||||
|
|
Loading…
Add table
Reference in a new issue