Skip to content

Commit

Permalink
Show next map in map loading screen
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWolfHT committed Jan 3, 2024
1 parent c5b9f55 commit 603572b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 26 deletions.
2 changes: 1 addition & 1 deletion mods/ctf/ctf_map/map_functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function ctf_map.place_map(mapmeta, callback)
end
end

minetest.after(0, minetest.fix_light, mapmeta.pos1, mapmeta.pos2)
minetest.fix_light(mapmeta.pos1, mapmeta.pos2)

assert(res, "Unable to place schematic, does the MTS file exist? Path: " .. schempath)

Expand Down
104 changes: 79 additions & 25 deletions mods/ctf/ctf_modebase/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,38 @@ local hud = mhud.init()
local LOADING_SCREEN_TARGET_TIME = 7
local loading_screen_time

-- tag: map_image
local old_announce = ctf_modebase.map_chosen
function ctf_modebase.map_chosen(map, ...)
local found = false
for _, p in pairs(minetest.get_connected_players()) do
if hud:exists(p, "loading_screen") then
found = true

hud:add(p, "map_image", {
hud_elem_type = "image",
position = {x = 0.5, y = 0.5},
image_scale = -100,
z_index = 1001,
texture = map.dirname.."_screenshot.png^[opacity:30",
})

hud:change(p, "loading_text", {
text = "Loading Map: " .. map.name .. "...",
})
end
end

-- Reset loading screen timer
if found then
loading_screen_time = minetest.get_us_time()
end

return old_announce(map, ...)
end


local function update_playertag(player, t, nametag, team_nametag, team_symbol_nametag)
local function update_playertag(player, t, nametag, team_nametag, symbol_nametag)
local entity_players = {}
local nametag_players = table.copy(ctf_teams.online_players[t].players)
local symbol_players = {}
Expand All @@ -48,25 +78,18 @@ local function update_playertag(player, t, nametag, team_nametag, team_symbol_na
end
end

if not team_nametag.object or not team_symbol_nametag.object or not nametag.object then
minetest.log("warning", "update_playertag failed, invalid object: " ..
(not team_nametag.object) .. ", " ..
(not team_symbol_nametag.object) .. ", " ..
(not nametag.object) .. ", "
)
return
end

team_nametag.object:set_observers(nametag_players)
team_symbol_nametag.object:set_observers(symbol_players)
nametag.object:set_observers(entity_players)
-- Occasionally crashes in singleplayer, so call it safely
pcall( team_nametag.object.set_observers, team_nametag.object, nametag_players)
pcall(symbol_nametag.object.set_observers, symbol_nametag.object, symbol_players )
pcall( nametag.object.set_observers, nametag.object, entity_players )
end

local tags_hidden = false
local update_timer = false
local function update_playertags()
if not update_timer then
local function update_playertags(time)
if not update_timer and not tags_hidden then
update_timer = true
minetest.after(1.2, function()
minetest.after(time or 1.2, function()
update_timer = false
for _, p in pairs(minetest.get_connected_players()) do
local t = ctf_teams.get(p)
Expand All @@ -86,6 +109,34 @@ local function update_playertags()
end
end

local PLAYERTAGS_OFF = false
local PLAYERTAGS_ON = true
local function set_playertags_state(state)
if state == PLAYERTAGS_ON and tags_hidden then
tags_hidden = false

update_playertags(0)
elseif state == PLAYERTAGS_OFF and not tags_hidden then
tags_hidden = true

for _, p in pairs(minetest.get_connected_players()) do
local playertag = playertag.get(p)

if ctf_teams.get(p) and playertag then
local team_nametag = playertag.nametag_entity
local nametag = playertag.entity
local symbol_entity = playertag.symbol_entity

if nametag and team_nametag and symbol_entity then
-- Occasionally crashes in singleplayer, so call it safely
pcall( team_nametag.object.set_observers, team_nametag.object, {})
pcall(symbol_entity.object.set_observers, symbol_entity.object, {})
pcall( nametag.object.set_observers, nametag.object, {})
end
end
end
end
end

ctf_settings.register("teammate_nametag_style", {
type = "list",
Expand Down Expand Up @@ -389,39 +440,42 @@ return {
if loading_screen_time then
local total_time = (minetest.get_us_time() - loading_screen_time) / 1e6

minetest.log(dump(math.max(0, LOADING_SCREEN_TARGET_TIME - total_time)))
minetest.after(math.max(0, LOADING_SCREEN_TARGET_TIME - total_time), function()
hud:clear_all()
set_playertags_state(PLAYERTAGS_ON)
end)
end
end,
on_match_end = function()
set_playertags_state(PLAYERTAGS_OFF)
for _, p in pairs(minetest.get_connected_players()) do
if ctf_teams.get(p) then
hud:add(p, {
hud:add(p, "loading_screen", {
hud_elem_type = "image",
position = {x = 0.5, y = 0.5},
image_scale = -100,
z_index = 1000,
texture = "[combine:1x1^[invert:rgba^[opacity:1^[colorize:#141523:255"
})

hud:add(p, {
-- z_index 1001 is reserved for the next map's image. Search file for `tag: map_image`

hud:add(p, "loading_text", {
hud_elem_type = "text",
position = {x = 0.5, y = 0.5},
alignment = {x = "center", y = "up"},
text_scale = 2,
text = "Loading Next Map...",
color = 0x5cb6ff,
z_index = 1001,
color = 0x7ec5ff,
z_index = 1002,
})
hud:add(p, {
hud_elem_type = "text",
position = {x = 0.5, y = 0.9},
alignment = {x = "center", y = "up"},
position = {x = 0.5, y = 0.75},
alignment = {x = "center", y = "center"},
text = random_messages.get_random_message(),
color = 0xdddddd,
z_index = 1001,
color = 0xffffff,
z_index = 1002,
})
end
end
Expand Down
7 changes: 7 additions & 0 deletions mods/ctf/ctf_modebase/match.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ local restart_on_next_match = false
ctf_modebase.map_on_next_match = nil
ctf_modebase.mode_on_next_match = nil

-- Overridable
function ctf_modebase.map_chosen(map)
end

function ctf_modebase.start_match_after_vote()
local old_mode = ctf_modebase.current_mode

Expand All @@ -22,6 +26,9 @@ function ctf_modebase.start_match_after_vote()
end

local map = ctf_modebase.map_catalog.maps[ctf_modebase.map_catalog.current_map]

ctf_modebase.map_chosen(map)

ctf_map.place_map(map, function()
-- Set time and time_speed
minetest.set_timeofday(map.start_time/24000)
Expand Down

0 comments on commit 603572b

Please sign in to comment.