2019-05-12 13:23:31 +00:00
|
|
|
-- Maps Catalog Formspec
|
|
|
|
|
|
|
|
local indices = {}
|
|
|
|
|
|
|
|
local function show_catalog(name, idx)
|
|
|
|
indices[name] = idx
|
|
|
|
|
|
|
|
-- Select map to be displayed
|
|
|
|
local map = ctf_map.available_maps[idx]
|
|
|
|
|
2019-05-15 15:04:25 +00:00
|
|
|
local fs = "size[10,9]"
|
2019-05-12 13:23:31 +00:00
|
|
|
|
|
|
|
fs = fs .. "container[0,0]"
|
|
|
|
fs = fs .. "box[0,0;9.8,1;#111]"
|
|
|
|
if idx > 1 then
|
|
|
|
fs = fs .. "button[0.5,0.1;1,1;btn_prev;<---]"
|
|
|
|
end
|
|
|
|
if idx < #ctf_map.available_maps then
|
|
|
|
fs = fs .. "button[8.5,0.1;1,1;btn_next;--->]"
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Map name and author
|
2019-05-15 15:04:25 +00:00
|
|
|
fs = fs .. "label[1.75,0;" ..
|
|
|
|
minetest.colorize("#ffff00", minetest.formspec_escape(map.name)) .. "]"
|
|
|
|
fs = fs .. "label[1.75,0.5;" .. minetest.colorize("#cccccc",
|
|
|
|
"by " .. minetest.formspec_escape(map.author)) .. "]"
|
2019-05-12 13:23:31 +00:00
|
|
|
fs = fs .. "container_end[]"
|
|
|
|
|
|
|
|
-- List of maps
|
2019-05-15 15:04:25 +00:00
|
|
|
fs = fs .. "textlist[0,1.2;3.5,7.8;maps_list;"
|
2019-05-12 13:23:31 +00:00
|
|
|
for i, v in pairs(ctf_map.available_maps) do
|
|
|
|
local mname = v.name
|
|
|
|
|
|
|
|
-- If entry corresponds to selected map, highlight in yellow
|
|
|
|
if i == idx then
|
|
|
|
mname = "#FFFF00" .. mname
|
|
|
|
end
|
|
|
|
|
|
|
|
fs = fs .. mname
|
|
|
|
if i < #ctf_map.available_maps then
|
|
|
|
fs = fs .. ","
|
|
|
|
end
|
|
|
|
end
|
|
|
|
fs = fs .. ";" .. idx .. ";false]"
|
|
|
|
|
|
|
|
-- Display screenshot if present, and move other elements down
|
|
|
|
local y = 1
|
|
|
|
if map.screenshot then
|
|
|
|
fs = fs .. "image[4,1.5;6.5,3.5;" .. map.screenshot .. "]"
|
2019-05-15 15:04:25 +00:00
|
|
|
y = y + 3.5
|
2019-05-12 13:23:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Other fields
|
|
|
|
fs = fs .. "container[3.5," .. y + 0.5 .. "]"
|
2019-05-15 15:04:25 +00:00
|
|
|
y = 0
|
|
|
|
if map.hint then
|
|
|
|
fs = fs .. "label[0.5," .. y .. ";" ..
|
|
|
|
minetest.colorize("#FFFF00", "HINT:") .. "]"
|
|
|
|
fs = fs .. "textarea[0.8," .. y + 0.5 .. ";5.5,1;;;" ..
|
|
|
|
minetest.formspec_escape(map.hint) .. "]"
|
|
|
|
y = y + 1.375
|
|
|
|
end
|
|
|
|
if map.license then
|
|
|
|
fs = fs .. "label[0.5," .. y .. ";" ..
|
|
|
|
minetest.colorize("#FFFF00", "LICENSE:") .. "]"
|
|
|
|
fs = fs .. "textarea[0.8," .. y + 0.5 .. ";5.5,1;;;" ..
|
|
|
|
minetest.formspec_escape(map.license) .. "]"
|
|
|
|
y = y + 1.375
|
|
|
|
end
|
|
|
|
if map.others then
|
|
|
|
fs = fs .. "label[0.5," .. y .. ";" ..
|
|
|
|
minetest.colorize("#FFFF00", "MORE INFORMATION:") .. "]"
|
|
|
|
fs = fs .. "textarea[0.8," .. y + 0.5 .. ";5.5,1;;;" ..
|
|
|
|
minetest.formspec_escape(map.others) .. "]"
|
|
|
|
end
|
2019-05-12 13:23:31 +00:00
|
|
|
fs = fs .. "container_end[]"
|
|
|
|
|
|
|
|
minetest.show_formspec(name, "ctf_map:maps_catalog", fs)
|
|
|
|
end
|
|
|
|
|
2019-07-14 09:18:40 +00:00
|
|
|
local function send_irc_catalog(name, idx)
|
|
|
|
-- Select map to be displayed
|
|
|
|
local map = ctf_map.available_maps[idx]
|
|
|
|
local red = string.char(3) .. "4"
|
|
|
|
local normal = string.char(3)
|
|
|
|
minetest.chat_send_player(name, red .. "Map: " .. normal .. map.name)
|
|
|
|
minetest.chat_send_player(name, red .. "Author: " .. normal .. map.author)
|
|
|
|
if map.hint then
|
|
|
|
minetest.chat_send_player(name, red .. "Hint: " .. normal .. map.hint)
|
|
|
|
end
|
|
|
|
if map.license then
|
|
|
|
minetest.chat_send_player(name, red .. "License: " .. normal .. map.license)
|
|
|
|
end
|
|
|
|
if map.others then
|
|
|
|
minetest.chat_send_player(name,
|
|
|
|
red .. "More Information: " .. normal .. map.others)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-12 13:23:31 +00:00
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
if not player or formname ~= "ctf_map:maps_catalog" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local name = player:get_player_name()
|
|
|
|
|
|
|
|
if fields.btn_prev then
|
|
|
|
show_catalog(name, indices[name] - 1)
|
|
|
|
elseif fields.btn_next then
|
|
|
|
show_catalog(name, indices[name] + 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields.maps_list then
|
|
|
|
local evt = minetest.explode_textlist_event(fields.maps_list)
|
|
|
|
if evt.type ~= "INV" then
|
|
|
|
show_catalog(name, evt.index)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_chatcommand("maps", {
|
|
|
|
privs = {interact = true},
|
|
|
|
func = function(name, param)
|
2019-05-12 17:19:14 +00:00
|
|
|
if #ctf_map.available_maps == 0 then
|
|
|
|
return false, "No maps are available!"
|
|
|
|
end
|
2019-05-12 13:23:31 +00:00
|
|
|
|
|
|
|
-- Set param to nil if it's empty
|
|
|
|
if param and param:trim() == "" then
|
|
|
|
param = nil
|
|
|
|
end
|
|
|
|
|
2019-07-14 09:18:40 +00:00
|
|
|
local player = minetest.get_player_by_name(name)
|
2019-05-12 13:23:31 +00:00
|
|
|
local idx
|
|
|
|
|
|
|
|
-- If arg. supplied, set idx to index of the matching map name
|
|
|
|
-- or path. Else, set to indices[name] or index of current map
|
|
|
|
if param then
|
2019-05-12 17:33:32 +00:00
|
|
|
idx = ctf_map.get_idx_and_map(param)
|
2019-05-12 13:23:31 +00:00
|
|
|
else
|
2019-07-14 09:18:40 +00:00
|
|
|
idx = (player and indices[name]) or ctf_map.map and ctf_map.map.idx or 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if player then
|
|
|
|
show_catalog(name, idx or 1)
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(name, " *** CTF Map Catalog for IRC *** ")
|
|
|
|
if not param then
|
|
|
|
minetest.chat_send_player(name,
|
|
|
|
"No param supplied, showing information for current map.")
|
|
|
|
end
|
|
|
|
send_irc_catalog(name, idx or 1)
|
2019-05-12 13:23:31 +00:00
|
|
|
end
|
|
|
|
|
2019-10-18 05:52:18 +00:00
|
|
|
minetest.log("action", name .. " views the map catalog")
|
2019-05-12 13:23:31 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|