diff --git a/api.lua b/api.lua index 9efdbd4..6466671 100644 --- a/api.lua +++ b/api.lua @@ -254,13 +254,38 @@ modEUrn.getVoterPlayedTime = function(playername) end end +modEUrn.showWhiteVote = function(playername) + local resulte, cause = modEUrn.doUnvote(playername) + local color = "#FF0000" + local buttonsound = "sfx_failure" + + if resulte then + color = "#00FF00" + buttonsound = "sfx_eurn_confirm" + end + minetest.chat_send_player( + playername, + core.colorize(color, "[E-URN]").." "..cause + ) + modEUrn.FormSpecs.showFormAlert( + playername, + "favicon.png", + modEUrn.translate("E-URN"), + color, + cause, + "btnEUrnPresElection", + buttonsound + ) +end + modEUrn.showPresCandCampaign = function(playername, candidatename) if type(candidatename)=="string" and candidatename ~= "" then --Se o nome do candidato foi dito if minetest.player_exists(candidatename) then --Se existe algum jogador o nome que foi dito if type(modEUrn.handler.candidates.president[candidatename])=="table" then --Se foi algum candidato registrado. local player = minetest.get_player_by_name(playername) if player:is_player() then --verifica se o jogador está online ou por terminal - modEUrn.FormSpecs.showFormInfoCampaign(playername, candidatename) + --modEUrn.FormSpecs.showFormInfoCampaign(playername, candidatename) + modEUrn.FormSpecs.showFormPresVote(playername, candidatename) else minetest.chat_send_player( playername, diff --git a/formspecs.lua b/formspecs.lua index c10a572..a5ed678 100644 --- a/formspecs.lua +++ b/formspecs.lua @@ -30,6 +30,47 @@ modEUrn.FormSpecs = { minetest.show_formspec(playername, "frmEUrnPresElection", myFormSpec) end, showFormPresCands = function(playername, candidatename) + local voterTimePlayed = modEUrn.getVoterPlayedTime(playername) + local cands = modEUrn.getPresidentCandidates() + local candList = "" + local candCount = 0 + local selected = 0 + for _, iCandPresName in ipairs(cands) do + candCount = candCount + 1 + if candList == "" then + candList = minetest.formspec_escape(iCandPresName) + else + candList = candList..","..minetest.formspec_escape(iCandPresName) + end + if type(candidatename)=="string" and candidatename==iCandPresName then + selected = candCount + end + end + local myFormSpec = "" + myFormSpec = myFormSpec + .."formspec_version[6]" + .."size[16,8,false]" + .."background[0,-8;16,16;text_eurn_front.png]" + --.."box[-0.5,-0.5;16.5,8.5;#001100CC]" + .."box[2.05,1.50;7.75,5.00;#001100CC]" + .."textlist[2.15,1.50;7.55,4;lstCands;"..candList..";"..selected..";true]" + if type(voterTimePlayed)=="number" and voterTimePlayed >= modEUrn.MinPlayedHours * (60*60) then + myFormSpec = myFormSpec + .."style[btnWhiteVote;bgcolor=white;color=black]" + .."button[2.10,5.50;2.25,1;btnWhiteVote;"..minetest.formspec_escape(modEUrn.translate("WHITE")).."]" + end + myFormSpec = myFormSpec + .."style[btnBack;bgimg=;bgimg_pressed=;border=;bgcolor=red]" + .."button[4.40,5.50;2.50,1;btnBack;"..minetest.formspec_escape(modEUrn.translate("CANCEL")).."]" + if selected >= 1 and type(voterTimePlayed)=="number" and voterTimePlayed >= modEUrn.MinPlayedHours * (60*60) then + myFormSpec = myFormSpec + .."style[btnPresCandSel;bgimg=;bgimg_pressed=;border=;bgcolor=green]" + .."button[6.95,5.50;2.75,1;btnPresCandSel;"..minetest.formspec_escape(modEUrn.translate("SELECT")).."]" + end + minetest.sound_play("sfx_eurn_button", {to_player=playername, max_hear_distance=5.0,}) + minetest.show_formspec(playername, "frmEUrnPresCands", myFormSpec) + end, + showFormPresCands_deprecated = function(playername, candidatename) local cands = modEUrn.getPresidentCandidates() local candList = "" local candCount = 0 @@ -57,7 +98,7 @@ modEUrn.FormSpecs = { .."style[lstCands;bgcolor=red]" .."style_type[textlist;bgcolor=red]" .."textlist[0.5,0.5;3,7;lstCands;"..candList..";"..selected..";true]" - + if selected >= 1 then local Campaign = modEUrn.getPresCandCampaign(candidatename) local body = [[ @@ -161,7 +202,58 @@ modEUrn.FormSpecs = { minetest.sound_play("sfx_eurn_button", {to_player=playername, max_hear_distance=5.0,}) minetest.show_formspec(playername, "frmEUrnRegCampaign", myFormSpec) end, - showFormInfoCampaign = function(playername, candidatename) + showFormPresVote = function(playername, candidatename) + local myFormSpec = "" + myFormSpec = myFormSpec + .."formspec_version[6]" + .."size[16,8,false]" + .."background[0,-8;16,16;text_eurn_front.png]" + .."box[-0.5,-0.5;16.5,8.5;#001100CC]" + .."style[lstCands;bgcolor=red]" + --.."style_type[textlist;bgcolor=red]" + --.."textlist[0.5,0.5;3,7;lstCands;"..candList..";"..selected..";true]" + + local Campaign = modEUrn.getPresCandCampaign(candidatename) + + if type(modEUrn.handler.candidates.president[candidatename])=="nil" then + Campaign = "" + end + + local body = [[ +