2019-05-12 13:23:31 +00:00
|
|
|
-- Maps Catalog Formspec
|
|
|
|
|
|
|
|
local indices = {}
|
|
|
|
|
2019-09-13 09:20:10 +00:00
|
|
|
local function show_catalog(name)
|
2019-05-12 13:23:31 +00:00
|
|
|
-- Select map to be displayed
|
2019-09-13 09:20:10 +00:00
|
|
|
local idx = indices[name]
|
2019-05-12 13:23:31 +00:00
|
|
|
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",
|
2019-09-13 09:20:10 +00:00
|
|
|
"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
|
2019-10-29 08:48:58 +00:00
|
|
|
if ctf_map.file_exists(map.dirname, "screenshot.png") then
|
|
|
|
-- Check for mapdir .. "/screenshot.png", but pass in the texture
|
|
|
|
-- name, which would've been renamed to mapdir .. ".png"
|
|
|
|
fs = fs .. "image[4,1.5;6.5,3.5;" .. map.dirname .. ".png" .. "]"
|
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[]"
|
|
|
|
|
2019-09-13 09:20:10 +00:00
|
|
|
-- Add some special buttons, if player has ctf_admin priv
|
|
|
|
if minetest.check_player_privs(name, { ctf_admin = true }) then
|
|
|
|
fs = fs .. "button[4,8;2,1;btn_jump;Skip to map]"
|
|
|
|
fs = fs .. "button[6,8;2,1;btn_set;Set as next map]"
|
2019-07-14 09:18:40 +00:00
|
|
|
end
|
2019-09-13 09:20:10 +00:00
|
|
|
|
|
|
|
minetest.show_formspec(name, "ctf_map:maps_catalog", fs)
|
2019-07-14 09:18:40 +00:00
|
|
|
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
|
2019-09-13 09:20:10 +00:00
|
|
|
indices[name] = indices[name] - 1
|
|
|
|
show_catalog(name)
|
2019-05-12 13:23:31 +00:00
|
|
|
elseif fields.btn_next then
|
2019-09-13 09:20:10 +00:00
|
|
|
indices[name] = indices[name] + 1
|
|
|
|
show_catalog(name)
|
2019-05-12 13:23:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if fields.maps_list then
|
|
|
|
local evt = minetest.explode_textlist_event(fields.maps_list)
|
|
|
|
if evt.type ~= "INV" then
|
2019-09-13 09:20:10 +00:00
|
|
|
indices[name] = evt.index
|
|
|
|
show_catalog(name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if minetest.check_player_privs(name, { ctf_admin = true }) then
|
|
|
|
if fields.btn_set then
|
|
|
|
ctf_map.next_idx = indices[name]
|
|
|
|
minetest.chat_send_player(name, "Selected " ..
|
|
|
|
ctf_map.available_maps[ctf_map.next_idx].name .. " as next map.")
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields.btn_jump then
|
|
|
|
ctf_map.next_idx = indices[name]
|
|
|
|
minetest.chat_send_player(name, "Skipping to next map")
|
|
|
|
ctf_match.next()
|
2019-05-12 13:23:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2019-09-13 09:20:10 +00:00
|
|
|
local function send_irc_catalog(name)
|
|
|
|
-- Select map to be displayed
|
|
|
|
local map = ctf_map.available_maps[indices[name]]
|
|
|
|
|
|
|
|
-- IRC color codes
|
|
|
|
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_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
|
|
|
|
2019-09-13 09:20:10 +00:00
|
|
|
-- If param supplied, set to idx of specified map
|
2019-05-12 13:23:31 +00:00
|
|
|
if param then
|
2019-09-13 09:20:10 +00:00
|
|
|
indices[name] = ctf_map.get_idx_and_map(param)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- If no player and no param supplied, or indices[name] doesn't
|
|
|
|
-- exist, set to idx of current map, or 1 as fallback
|
|
|
|
if not player and not param or not indices[name] then
|
|
|
|
indices[name] = ctf_map.map and ctf_map.map.idx or 1
|
2019-07-14 09:18:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if player then
|
2019-09-13 09:20:10 +00:00
|
|
|
show_catalog(name)
|
2019-07-14 09:18:40 +00:00
|
|
|
else
|
2019-09-13 09:20:10 +00:00
|
|
|
minetest.chat_send_player(name, " *** CTF Maps Catalog for IRC *** ")
|
2019-07-14 09:18:40 +00:00
|
|
|
if not param then
|
|
|
|
minetest.chat_send_player(name,
|
2019-09-13 09:20:10 +00:00
|
|
|
"No param supplied, showing information for current map.")
|
2019-07-14 09:18:40 +00:00
|
|
|
end
|
2019-09-13 09:20:10 +00:00
|
|
|
send_irc_catalog(name)
|
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
|
|
|
|
})
|