mirror of
https://gitlab.com/lunovox/e-urn.git
synced 2025-03-15 07:21:22 +00:00
[refact] Revazenfo painel de votação.
This commit is contained in:
parent
fee5afb486
commit
eadb8c3f3c
2 changed files with 141 additions and 30 deletions
27
api.lua
27
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,
|
||||
|
|
142
formspecs.lua
142
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
|
||||
|
@ -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 = [[
|
||||
<center>
|
||||
<img name=text_candidate_face.png width=128 height=128>
|
||||
<bigger><b>%s</b></bigger>
|
||||
</center>
|
||||
<justify>%s</justify>
|
||||
]]
|
||||
myFormSpec = myFormSpec
|
||||
--.."style[htmPanel;bgcolor=white;border=#008800CC;color=black]"
|
||||
.."hypertext[4.0,0.5;11.25,6.00;htmPanel;"
|
||||
--..minetest.formspec_escape("<global margin=10 valign=0 color=#FF00FF hovercolor=#00FFFF size=12 font=normal halign=center >")
|
||||
.."<global valign=middle halign=center margin=30 background=#001100CC bordercolor=#008800CC color=#FFFFFF hovercolor=#00FF00 size=12 font=normal>"
|
||||
.."<tag name=action color=#FF0000 hovercolor=#00FF00 font=normal size=12>"
|
||||
.."<tag name=bigger color=#00CC00 font=normal size=28>"
|
||||
.."<tag name=big color=#CCCC00 font=normal size=18>"
|
||||
.."<tag name=b color=#00CC00 font=normal>"
|
||||
..minetest.formspec_escape(body:format(candidatename, Campaign))
|
||||
.."]" -- Fim de hypertext[]
|
||||
|
||||
local voterTimePlayed = modEUrn.getVoterPlayedTime(playername)
|
||||
if type(voterTimePlayed)=="number" and voterTimePlayed >= modEUrn.MinPlayedHours * (60*60) then
|
||||
myFormSpec = myFormSpec
|
||||
.."style[btnWhiteVote;bgcolor=white;color=black]"
|
||||
.."button[4.0,6.75;3.00,1;btnWhiteVote;"..minetest.formspec_escape(modEUrn.translate("WHITE")).."]"
|
||||
.."style[btnPresVote;bgimg=;bgimg_pressed=;border=;bgcolor=green]"
|
||||
.."button[7.10,6.75;5.65,1;btnPresVote;"..minetest.formspec_escape(modEUrn.translate("CONFIRM")).."]"
|
||||
end
|
||||
myFormSpec = myFormSpec
|
||||
.."style[btnBack;bgimg=;bgimg_pressed=;border=;bgcolor=red]"
|
||||
.."button[12.85,6.75;2.55,1;btnBack;"..minetest.formspec_escape(modEUrn.translate("CANCEL")).."]"
|
||||
minetest.sound_play("sfx_eurn_button", {to_player=playername, max_hear_distance=5.0,})
|
||||
minetest.show_formspec(playername, "frmEUrnPresVote", myFormSpec)
|
||||
|
||||
|
||||
--[[
|
||||
local Campaign = modEUrn.getPresCandCampaign(candidatename)
|
||||
--if type(modEUrn.handler.candidates.president[candidatename])=="nil" then Campaign = "" end
|
||||
local myFormSpec = ""
|
||||
|
@ -185,6 +277,7 @@ modEUrn.FormSpecs = {
|
|||
minetest.log('action',modEUrn.translate("Candidate Campaign")..Campaign)
|
||||
minetest.sound_play("sfx_eurn_button", {to_player=playername, max_hear_distance=5.0,})
|
||||
minetest.show_formspec(playername, "frmEUrnInfoCampaign", myFormSpec)
|
||||
--]]
|
||||
end,
|
||||
|
||||
--[[
|
||||
|
@ -282,10 +375,19 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
if type(lstCands.index)=="number" and lstCands.index>=1 then
|
||||
local cands = modEUrn.getPresidentCandidates()
|
||||
modEUrn.selCand[playername] = cands[lstCands.index]
|
||||
local cands = modEUrn.getPresidentCandidates()
|
||||
modEUrn.FormSpecs.showFormPresCands(playername, cands[lstCands.index])
|
||||
end
|
||||
elseif type(fields.btnPresVote) ~= "nil" then
|
||||
elseif type(fields.btnPresCandSel) ~= "nil" then
|
||||
if type(modEUrn.selCand[playername])=="string" and modEUrn.selCand[playername]~="" then
|
||||
modEUrn.FormSpecs.showFormPresVote(playername, modEUrn.selCand[playername])
|
||||
end
|
||||
elseif type(fields.btnWhiteVote) ~= "nil" then
|
||||
modEUrn.showWhiteVote(playername)
|
||||
elseif type(fields.btnBack) ~= "nil" then
|
||||
modEUrn.FormSpecs.showFormPresElection(playername)
|
||||
end
|
||||
elseif type(formname)=="string" and formname == "frmEUrnPresVote" then
|
||||
if type(fields.btnPresVote) ~= "nil" then
|
||||
if type(modEUrn.selCand[playername])=="string" and modEUrn.selCand[playername]~="" then
|
||||
local resulte, cause = modEUrn.doVote(playername, modEUrn.selCand[playername])
|
||||
local color = "#FF0000"
|
||||
|
@ -319,32 +421,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
)
|
||||
end
|
||||
elseif type(fields.btnWhiteVote) ~= "nil" then
|
||||
local resulte, cause = modEUrn.doUnvote(playername)
|
||||
if type(modEUrn.selCand[playername])=="string" and modEUrn.selCand[playername]~="" then
|
||||
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,
|
||||
"btnEUrnPresCands",
|
||||
buttonsound
|
||||
)
|
||||
end
|
||||
modEUrn.showWhiteVote(playername)
|
||||
elseif type(fields.btnBack) ~= "nil" then
|
||||
modEUrn.FormSpecs.showFormPresElection(playername)
|
||||
local candidatename = ""
|
||||
if type(modEUrn.selCand)=="table"
|
||||
and type(modEUrn.selCand[playername])=="string"
|
||||
and modEUrn.selCand[playername]~=""
|
||||
then
|
||||
candidatename = modEUrn.selCand[playername]
|
||||
end
|
||||
modEUrn.FormSpecs.showFormPresCands(playername, candidatename)
|
||||
end
|
||||
elseif type(formname)=="string" and formname == "frmEUrnPresElect" then
|
||||
if type(fields.btnBack) ~= "nil" then
|
||||
|
|
Loading…
Add table
Reference in a new issue