This commit is contained in:
Lunovox 2024-02-25 11:28:25 -03:00
parent a713e0fabb
commit a37f854374
5 changed files with 126 additions and 3 deletions

19
api.lua
View file

@ -242,6 +242,18 @@ modEUrn.getPresidentCandidates = function()
return cands
end
modEUrn.getVoterPlayedTime = function(playername)
if type(playername)=="string"
and playername~=""
and type(modEUrn.handler.voters)=="table"
and type(modEUrn.handler.voters[playername])=="table"
and type(modEUrn.handler.voters[playername].times)=="table"
and type(modEUrn.handler.voters[playername].times.played)=="number"
then
return modEUrn.handler.voters[playername].times.played --in secounds
end
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
@ -314,8 +326,11 @@ end
--[[ ]]
modEUrn.doVote = function(playername, candidatename)
if type(modEUrn.handler.voters[playername])=="table" then
local voterTimePlayed = modEUrn.handler.voters[playername].times.played --in secounds
local voterTimePlayed = modEUrn.getVoterPlayedTime(playername)
--modEUrn.debug("modEUrn.doVote(): voterTimePlayed = "..dump(voterTimePlayed))
if type(voterTimePlayed)=="number" then
--if type(modEUrn.handler.voters[playername])=="table" then
--local voterTimePlayed = modEUrn.handler.voters[playername].times.played --in secounds
if voterTimePlayed >= modEUrn.MinPlayedHours * (60*60) then
if type(candidatename)=="string" and candidatename ~= "" then
if minetest.player_exists(candidatename) then

View file

@ -204,6 +204,9 @@ modEUrn.getPropCommCandVote = function()
local color = "#FF0000"
if resulte then
color = "#00FF00"
minetest.sound_play("sfx_eurn_confirm", {to_player=playername, max_hear_distance=5.0,})
else
minetest.sound_play("sfx_failure", {to_player=playername, max_hear_distance=5.0,})
end
minetest.chat_send_player(
playername,

View file

@ -26,6 +26,68 @@ modEUrn.FormSpecs = {
.."button[2.15,3.65;7.55,1;btnBack;"..modEUrn.translate("BACK").."]"
minetest.sound_play("sfx_eurn_button", {to_player=playername, max_hear_distance=5.0,})
minetest.show_formspec(playername, "frmEUrnPresElection", myFormSpec)
end,
showFormPresCands = function(playername, candidatename)
local cands = modEUrn.getPresidentCandidates()
local candList = ""
local candCount = 0
local selected = 0
--minetest.chat_send_all("Numero de Candidatos: "..#modEUrn.handler.candidates.president)
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;#00110088]"
.."textlist[0.5,0.5;3,7;lstCands;"..candList..";"..selected..";true]"
if selected >= 1 then
local Campaign = modEUrn.getPresCandCampaign(candidatename)
local body = [[
<center>
<img name=text_candidate_face.png width=64 height=64>
<bigger><b>%s</b></bigger>
</center>
<justify>%s</justify>
]]
myFormSpec = myFormSpec
.."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=10 background=#001100CC 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(cands[selected], Campaign))
.."]" -- Fim de hypertext[]
local voterTimePlayed = modEUrn.getVoterPlayedTime(playername)
if type(voterTimePlayed)=="number" and voterTimePlayed >= modEUrn.MinPlayedHours * (60*60) then
myFormSpec = myFormSpec
.."style[btnPresVote;bgimg=;bgimg_pressed=;border=;bgcolor=green]"
.."button[4.0,6.75;8.75,1;btnPresVote;"..modEUrn.translate("VOTE").."]"
end
end
myFormSpec = myFormSpec
.."style[btnBack;bgimg=;bgimg_pressed=;border=;bgcolor=red]"
.."button[12.85,6.75;2.55,1;btnBack;"..modEUrn.translate("BACK").."]"
minetest.sound_play("sfx_eurn_button", {to_player=playername, max_hear_distance=5.0,})
minetest.show_formspec(playername, "frmEUrnPresCands", myFormSpec)
end,
showFormRegCampaign = function(playername, political_campaign)
local Campaign = modEUrn.getPresCandCampaign(playername)
@ -126,9 +188,52 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
minetest.sound_play("sfx_eurn_button", {to_player=playername, max_hear_distance=5.0,})
end
elseif type(formname)=="string" and formname == "frmEUrnPresElection" then
if type(fields.btnBack) ~= "nil" then
if type(fields.btnPresCandidates) ~= "nil" then
modEUrn.FormSpecs.showFormPresCands(playername, nil)
elseif type(fields.btnBack) ~= "nil" then
modEUrn.FormSpecs.showFormMain(playername)
end
elseif type(formname)=="string" and formname == "frmEUrnPresCands" then
if type(modEUrn.selCand)~="table" then
modEUrn.selCand = {}
end
if type(fields.lstCands) ~= "nil" then
local lstCands = minetest.explode_textlist_event(fields.lstCands)
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
if type(modEUrn.selCand[playername])=="string" and modEUrn.selCand[playername]~="" then
local voterTimePlayed = modEUrn.getVoterPlayedTime(playername)
if type(voterTimePlayed)=="number" and voterTimePlayed >= modEUrn.MinPlayedHours * (60*60) then
local resulte, cause = modEUrn.doVote(playername, modEUrn.selCand[playername])
local color = "#FF0000"
if resulte then
color = "#00FF00"
minetest.sound_play("sfx_eurn_confirm", {to_player=playername, max_hear_distance=5.0,})
else
minetest.sound_play("sfx_failure", {to_player=playername, max_hear_distance=5.0,})
end
minetest.chat_send_player(
playername,
core.colorize(color, "[E-URN]").." "..cause
)
modEUrn.FormSpecs.showFormPresElection(playername)
else
minetest.sound_play("sfx_failure", {to_player=playername, max_hear_distance=5.0,})
minetest.chat_send_player(
playername,
core.colorize("#FF0000", "[E-URN]").." "
..modEUrn.translate("You have not yet played the minimum number of hours to become a presidential voter. (Minimum %02d hours)"):format(modEUrn.MinPlayedHours)
)
end
end
elseif type(fields.btnBack) ~= "nil" then
modEUrn.FormSpecs.showFormPresElection(playername)
end
elseif type(formname)=="string" and formname == "frmEUrnRegCampaign" then
if type(fields.txtCampaign)~= "nil" and type(fields.btnSave) ~= "nil" then
--modEUrn.debug("modEUrn.doPresidentCandidate(playername='"..playername.."', playername='"..playername.."', fields.txtCampaign="..dump(fields.txtCampaign)..")")

BIN
sounds/sfx_failure.ogg Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB