2023-07-26 17:23:08 -03:00
2023-09-18 11:02:42 -03:00
modEUrn.FormSpecs = {
2024-02-25 02:06:51 -03:00
showFormMain = function ( playername )
local myFormSpec = " "
myFormSpec = myFormSpec
.. " formspec_version[6] "
.. " size[16,8,false] "
.. " background[0,-8;16,16;text_eurn_front.png] "
.. " box[2.05,1.50;7.75,5.00;#001100CC] "
.. " button[2.15,1.65;7.55,1;btnPresElection; " .. modEUrn.translate ( " PRESIDENTIAL ELECTION " ) .. " ] "
--.."button[2.15,2.65;7.55,1;btnElectoralCourt;"..modEUrn.translate("ELECTORAL COURT").."]"
2024-02-25 21:21:46 -03:00
.. " style_type[button_exit;bgimg=;bgimg_pressed=;border=;bgcolor=red] "
2024-02-25 02:06:51 -03:00
.. " button_exit[2.15,3.65;7.55,1;; " .. modEUrn.translate ( " EXIT " ) .. " ] "
minetest.sound_play ( " sfx_eurn_button " , { to_player = playername , max_hear_distance = 5.0 , } )
minetest.show_formspec ( playername , " frmEUrnMain " , myFormSpec )
end ,
showFormPresElection = function ( playername )
local myFormSpec = " "
myFormSpec = myFormSpec
.. " formspec_version[6] "
.. " size[16,8,false] "
.. " background[0,-8;16,16;text_eurn_front.png] "
.. " box[2.05,1.50;7.75,5.00;#001100CC] "
.. " button[2.15,1.65;7.55,1;btnPresCandidates; " .. modEUrn.translate ( " PRESIDENTIAL CANDIDATES " ) .. " ] "
2024-02-25 21:21:46 -03:00
.. " button[2.15,2.65;7.55,1;btnPresElect; " .. modEUrn.translate ( " PRESIDENT ELECT " ) .. " ] "
.. " style[btnBack;bgimg=;bgimg_pressed=;border=;bgcolor=red] "
2024-02-25 02:06:51 -03:00
.. " 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 )
2024-02-25 11:28:25 -03:00
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] "
2024-02-25 21:21:46 -03:00
.. " style[lstCands;bgcolor=red] "
.. " style_type[textlist;bgcolor=red] "
2024-02-25 11:28:25 -03:00
.. " textlist[0.5,0.5;3,7;lstCands; " .. candList .. " ; " .. selected .. " ;true] "
if selected >= 1 then
local Campaign = modEUrn.getPresCandCampaign ( candidatename )
local body = [ [
< center >
2024-02-25 21:21:46 -03:00
< img name = text_candidate_face.png width = 128 height = 128 >
2024-02-25 11:28:25 -03:00
< 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 )
2024-02-25 21:21:46 -03:00
end ,
showFormPresElect = function ( playername )
local body = " "
local presidentname = modEUrn.getPresidentName ( )
if presidentname ~= " " then
body = [ [
< center >
< img name = text_candidate_face.png width = 128 height = 128 >
< bigger >< b >% s </ b ></ bigger >
% s
</ center >
] ]
body = body : format (
presidentname : upper ( ) ,
modEUrn.translate ( " PRESIDENT ELECT " )
)
else
body = [ [
< center >
< img name = favicon.png width = 128 height = 128 >
< bigger >< b >% s </ b ></ bigger >
% s
</ center >
] ]
body = body : format (
modEUrn.translate ( " E-URN " ) ,
modEUrn.translate ( " No presidential candidate has yet been elected! " )
)
end
local myFormSpec = " "
myFormSpec = myFormSpec
.. " formspec_version[6] "
.. " size[16,8,false] "
.. " background[0,-8;16,16;text_eurn_front.png] "
.. " box[2.05,1.50;7.75,5.00;#001100CC] "
.. " hypertext[2.15,1.50;7.55,4.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 )
.. " ] " -- Fim de hypertext[]
.. " style[btnBack;bgimg=;bgimg_pressed=;border=;bgcolor=red] "
.. " button[2.15,5.50;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 , " frmEUrnPresElect " , myFormSpec )
2024-02-25 02:06:51 -03:00
end ,
2024-02-20 23:03:09 -03:00
showFormRegCampaign = function ( playername , political_campaign )
local Campaign = modEUrn.getPresCandCampaign ( playername )
if type ( political_campaign ) ~= " string " or political_campaign == " " then
political_campaign = Campaign
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.75;15,5.75;#000000CC] "
.. " textarea[0.5,0.75;15,5.75;txtCampaign; "
.. minetest.formspec_escape (
2024-02-22 15:59:51 -03:00
modEUrn.translate ( " Political Campaign of " ) .. " : " ..
2024-02-20 23:03:09 -03:00
core.colorize ( " #00FF00 " , playername )
) .. " ; "
.. minetest.formspec_escape ( political_campaign ) ..
" ] "
.. " button_exit[0.5,6.75;12.25,1;btnSave; " .. modEUrn.translate ( " REGISTER " ) .. " ] "
2024-02-25 02:06:51 -03:00
.. " button_exit[12.85,6.75;2.55,1;; " .. modEUrn.translate ( " CANCEL " ) .. " ] "
minetest.sound_play ( " sfx_eurn_button " , { to_player = playername , max_hear_distance = 5.0 , } )
2024-02-20 23:03:09 -03:00
minetest.show_formspec ( playername , " frmEUrnRegCampaign " , myFormSpec )
end ,
showFormInfoCampaign = function ( playername , candidatename )
local Campaign = modEUrn.getPresCandCampaign ( candidatename )
--if type(modEUrn.handler.candidates.president[candidatename])=="nil" then Campaign = "" 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.75;15,5.75;#00000088] "
.. " textarea[0.5,0.75;15,5.75;; "
.. minetest.formspec_escape (
2024-02-22 15:59:51 -03:00
modEUrn.translate ( " Political Campaign of " ) .. " : " ..
2024-02-20 23:03:09 -03:00
core.colorize ( " #00FF00 " , candidatename )
) .. " ; "
.. minetest.formspec_escape ( Campaign ) ..
" ] "
2024-02-25 02:06:51 -03:00
.. " button_exit[0.5,6.75;12.25,1;btnVote; " .. modEUrn.translate ( " VOTE " ) .. " ] "
.. " button_exit[13.25,6.75;2,1;; " .. modEUrn.translate ( " CLOSE " ) .. " ] "
2024-02-20 23:03:09 -03:00
minetest.log ( ' action ' , modEUrn.translate ( " Player %s is listing campaign data... " ) : format ( playername ) )
minetest.log ( ' action ' , modEUrn.translate ( " Candidate Name " ) .. candidatename )
minetest.log ( ' action ' , modEUrn.translate ( " Candidate Campaign " ) .. Campaign )
2024-02-25 02:06:51 -03:00
minetest.sound_play ( " sfx_eurn_button " , { to_player = playername , max_hear_distance = 5.0 , } )
2024-02-20 23:03:09 -03:00
minetest.show_formspec ( playername , " frmEUrnInfoCampaign " , myFormSpec )
end ,
--[[
2023-09-18 11:02:42 -03:00
showHypertext = function ( playername )
--Fonte:
-- * https://minetest.gitlab.io/minetest/formspec/
-- * https://minetest.gitlab.io/minetest/formspec/#hypertextxywhnametext
-- * https://github.com/minetest/minetest/blob/master/doc/lua_api.md
local myFormSpec = " "
myFormSpec = myFormSpec
--.."formspec_version[5.6.0]"
.. " formspec_version[6] "
.. " size[16,8,false] "
.. " background[0,-8;16,16;text_eurn_front.png] "
--.."bgcolor[000000;false;FFFFFF]"
--.."bgcolor[#00880044;false;#000000]"
--.."bgcolor[#636D7600;true]"
--.."position[0,0]"
--.."container[0,0]"
--.."image[0,-8;16,16;text_eurn_front.png]"
.. " vertlabel[15.75,0.5; " .. minetest.formspec_escape ( modEUrn.translate ( " E-URN " ) ) .. " ] "
.. " hypertext[0.5,0.5;15,7;myPage; "
--..minetest.formspec_escape("<global margin=10 valign=0 color=#FF00FF hovercolor=#00FFFF size=12 font=normal halign=center >")
.. " <global valign=middle halign=left margin=10 background=#FFFFFFCC color=#000000 hovercolor=#00FF00 size=12 font=normal> "
.. " <tag name=action color=#FF0000 hovercolor=#00FF00 font=normal size=12> "
.. minetest.formspec_escape ( body : format ( playername : upper ( ) ) )
2023-07-26 17:23:08 -03:00
.. " ] " -- Fim de hypertext[]
--.."container_end[]"
--"hypertext[<X>,<Y>;<W>,<H>;<name>;<text>]"
minetest.show_formspec ( playername , " frmEUrnInit " , myFormSpec )
end ,
2024-02-20 23:03:09 -03:00
--]]
2023-07-26 17:23:08 -03:00
}
2024-02-20 23:03:09 -03:00
minetest.register_on_player_receive_fields ( function ( player , formname , fields )
local playername = player : get_player_name ( )
2024-02-25 02:06:51 -03:00
--modEUrn.debug("formname: "..formname.."\n".."fields: "..dump(fields), playername)
if type ( formname ) == " string " and formname == " frmEUrnMain " then
if type ( fields.btnPresElection ) ~= " nil " then
modEUrn.FormSpecs . showFormPresElection ( playername )
elseif type ( fields.quit ) ~= " true " then
minetest.sound_play ( " sfx_eurn_button " , { to_player = playername , max_hear_distance = 5.0 , } )
end
elseif type ( formname ) == " string " and formname == " frmEUrnPresElection " then
2024-02-25 11:28:25 -03:00
if type ( fields.btnPresCandidates ) ~= " nil " then
modEUrn.FormSpecs . showFormPresCands ( playername , nil )
2024-02-25 21:21:46 -03:00
elseif type ( fields.btnPresElect ) ~= " nil " then
modEUrn.FormSpecs . showFormPresElect ( playername )
2024-02-25 11:28:25 -03:00
elseif type ( fields.btnBack ) ~= " nil " then
2024-02-25 02:06:51 -03:00
modEUrn.FormSpecs . showFormMain ( playername )
end
2024-02-25 11:28:25 -03:00
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
2024-02-25 21:21:46 -03:00
modEUrn.FormSpecs . showFormPresElection ( playername )
end
elseif type ( formname ) == " string " and formname == " frmEUrnPresElect " then
if type ( fields.btnBack ) ~= " nil " then
2024-02-25 11:28:25 -03:00
modEUrn.FormSpecs . showFormPresElection ( playername )
end
2024-02-25 02:06:51 -03:00
elseif type ( formname ) == " string " and formname == " frmEUrnRegCampaign " then
if type ( fields.txtCampaign ) ~= " nil " and type ( fields.btnSave ) ~= " nil " then
2024-02-20 23:03:09 -03:00
--modEUrn.debug("modEUrn.doPresidentCandidate(playername='"..playername.."', playername='"..playername.."', fields.txtCampaign="..dump(fields.txtCampaign)..")")
if modEUrn.doPresidentCandidate ( playername , playername , fields.txtCampaign ) then
modEUrn.doSave ( )
minetest.chat_send_player (
playername ,
--os.date("%Y-%m-%d %Hh:%Mm:%Ss", now) ..
core.colorize ( " #00FF00 " , " [E-URN] " ) .. " "
2024-02-25 02:06:51 -03:00
.. modEUrn.translate ( " Player @1 has been registered to run as a candidate for president of this server! " , dump ( playername ) )
2024-02-20 23:03:09 -03:00
)
2024-02-25 02:06:51 -03:00
minetest.sound_play ( " sfx_eurn_confirm " , { to_player = playername , max_hear_distance = 5.0 , } )
2024-02-20 23:03:09 -03:00
end
2024-02-25 02:06:51 -03:00
elseif type ( fields.quit ) ~= " true " then
minetest.sound_play ( " sfx_eurn_button " , { to_player = playername , max_hear_distance = 5.0 , } )
2024-02-20 23:03:09 -03:00
end
end
end )