diff --git a/mods/kingdoms/chat.lua b/mods/kingdoms/chat.lua index 9454cc5..5c4ec66 100644 --- a/mods/kingdoms/chat.lua +++ b/mods/kingdoms/chat.lua @@ -295,7 +295,10 @@ ChatCmdBuilder.new("kingdoms", function(cmd) end) -- Bring up kingdoms gui cmd:sub("", function(name) - local fs = kingdoms.get_gui(name) - minetest.show_formspec(name, "kingdoms:gui", fs) + if kingdoms.members[name] == nil then + return false, "You are not in a kingdom" + end + local fs = kingdoms.get_gui(name, "news") + minetest.show_formspec(name, "kingdoms:gui_news", fs) end) end) diff --git a/mods/kingdoms/gui.lua b/mods/kingdoms/gui.lua index 3d35932..3809594 100644 --- a/mods/kingdoms/gui.lua +++ b/mods/kingdoms/gui.lua @@ -1,8 +1,9 @@ function kingdoms.get_gui(pname, tab) - local fs = "size[8,9;]button[0,0;2,1;news;News]" + 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 -- Get news tabs if tab == nil or tab == "news" then - fs = fs .. "textlist[0,1;7.8,8;news;" + fs = fs .. "textlist[0,1;7.8,8;newslist;Server News:," -- Get news and break it into lines local ntable = kingdoms.get_news(20) local nidx = 1 @@ -21,5 +22,28 @@ function kingdoms.get_gui(pname, tab) end fs = fs:sub(1, -2) .. "]" return fs + 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 end end + +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)