Darken handheld map in low light conditions

This commit is contained in:
Nils Dagsson Moskopp 2022-02-08 07:56:28 +01:00
parent b10214e1e0
commit f2e6e61c47
No known key found for this signature in database
GPG Key ID: A3BC671C35191080
1 changed files with 13 additions and 3 deletions

View File

@ -425,6 +425,7 @@ minetest.register_craft_predict(on_craft)
local maps = {}
local huds = {}
local light = {}
minetest.register_on_joinplayer(function(player)
local map_def = {
@ -445,6 +446,7 @@ end)
minetest.register_on_leaveplayer(function(player)
maps[player] = nil
light[player] = nil
huds[player] = nil
end)
@ -513,8 +515,15 @@ minetest.register_globalstep(function(dtime)
end
end
if texture ~= maps[player] then
player:hud_change(hud.map, "text", "[combine:140x140:0,0=mcl_maps_map_background.png:6,6=" .. texture)
local light_level
local light_level_overlay = ""
if nil ~= pos then -- do not crash while joining game
light_level = minetest.get_node_light(pos) or 0 -- can be nil somehow
light_level_overlay = "^[colorize:black:" .. 255 - (light_level * 17)
end
if texture ~= maps[player] or light_level ~= light[player] then
player:hud_change(hud.map, "text", "[combine:140x140:0,0=mcl_maps_map_background.png:6,6=" .. texture .. light_level_overlay)
if nil == maps[player] then
-- show tmp message if player
-- did not wield a map before
@ -523,6 +532,7 @@ minetest.register_globalstep(function(dtime)
S("Right click on a banner to add a colored marker.")
)
end
light[player] = light_level
maps[player] = texture
end
@ -578,7 +588,7 @@ minetest.register_globalstep(function(dtime)
end
end
player:hud_change(hud.marker, "text", marker)
player:hud_change(hud.marker, "text", marker .. light_level_overlay)
player:hud_change(hud.marker, "offset", {x = (6 - 140 / 2 + pos.x - minp.x) * 2, y = (6 - 140 + maxp.z - pos.z) * 2})
elseif maps[player] then
player:hud_change(hud.map, "text", "blank.png")