2019-04-21 16:31:02 -04:00
|
|
|
function kingdoms.get_gui(pname, tab)
|
2019-04-21 17:53:46 -04:00
|
|
|
local fs = "size[8,9;]button[0,0;2,1;news;News]button[2,0;2,1;apls;Applications]"
|
|
|
|
local kingdom = kingdoms.members[pname].kingdom
|
2019-04-21 16:31:02 -04:00
|
|
|
-- Get news tabs
|
|
|
|
if tab == nil or tab == "news" then
|
2019-04-21 17:53:46 -04:00
|
|
|
fs = fs .. "textlist[0,1;7.8,8;newslist;Server News:,"
|
2019-04-21 16:31:02 -04:00
|
|
|
-- Get news and break it into lines
|
|
|
|
local ntable = kingdoms.get_news(20)
|
|
|
|
local nidx = 1
|
|
|
|
local lidx
|
|
|
|
local lines
|
|
|
|
while true do
|
|
|
|
if ntable[nidx] == nil then break end
|
|
|
|
lines = kingdoms.helpers.split_into_lengths(ntable[nidx], 70)
|
|
|
|
lidx = 1
|
|
|
|
while true do
|
|
|
|
if lines[lidx] == nil then break end
|
|
|
|
fs = fs .. minetest.formspec_escape(lines[lidx]) .. ","
|
|
|
|
lidx = lidx + 1
|
|
|
|
end
|
|
|
|
nidx = nidx + 1
|
|
|
|
end
|
|
|
|
fs = fs:sub(1, -2) .. "]"
|
|
|
|
return fs
|
2019-04-21 17:53:46 -04:00
|
|
|
elseif tab == "apls" then
|
|
|
|
fs = fs .. "textlist[0,1;7.8,8;aplslist;Kingdom Applications:,"
|
|
|
|
for n,k in pairs(kingdoms.pending) do
|
|
|
|
if k == kingdom then
|
|
|
|
fs = fs .. n .. ","
|
|
|
|
end
|
|
|
|
end
|
|
|
|
fs = fs:sub(1, -2) .. "]"
|
|
|
|
return fs
|
2019-04-21 16:31:02 -04:00
|
|
|
end
|
|
|
|
end
|
2019-04-21 17:53:46 -04:00
|
|
|
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
-- Check if this is one of the correct forms
|
|
|
|
if formname:find("^kingdoms:gui") == nil then return end
|
|
|
|
local pname = player:get_player_name()
|
|
|
|
-- Check if we are moving to a different tab
|
|
|
|
if fields["news"] then
|
|
|
|
minetest.show_formspec(pname, "kingdoms:gui_news", kingdoms.get_gui(pname, "news"))
|
|
|
|
return
|
|
|
|
elseif fields["apls"] then
|
|
|
|
minetest.show_formspec(pname, "kingdoms:gui_apls", kingdoms.get_gui(pname, "apls"))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end)
|