Allow display dimming/vignette

Deeper dimming/vignette when server is empty
to make it a little more visually interesting, plus
add a clearer indication that the server is in
a different state than normal play.
This commit is contained in:
Aaron Suen 2022-04-24 21:03:36 -04:00
parent 65ad490837
commit bafddf2bf6
2 changed files with 61 additions and 26 deletions

View File

@ -1,8 +1,10 @@
-- LUALOCALS < ---------------------------------------------------------
local ipairs, math, minetest, pairs, type
= ipairs, math, minetest, pairs, type
local math_atan2, math_cos, math_pi, math_random, math_sin, math_sqrt
= math.atan2, math.cos, math.pi, math.random, math.sin, math.sqrt
local math_atan2, math_ceil, math_cos, math_pi, math_random, math_sin,
math_sqrt
= math.atan2, math.ceil, math.cos, math.pi, math.random, math.sin,
math.sqrt
-- LUALOCALS > ---------------------------------------------------------
local cycletime = 20 -- time between cycles
@ -23,6 +25,11 @@ local minlight = 4 -- min light level to not affect cam time
local maxidle = 10 -- max idle time before penalty
local idlepenalty = 4 -- extra countdown speed for being idle
local actvig = 0.25 -- vignette when active
local actdark = 0 -- darken when active
local dummyvig = 0.75 -- vignette when dummycam
local dummydark = 0.3 -- darken when dummycam
local modname = minetest.get_current_modname()
minetest.register_privilege(modname, {
@ -108,6 +115,45 @@ do
end
end
local function hudset(player, data, key, def)
local hud = data[key]
if hud then
if hud.text == def.text then return end
player:hud_change(hud.id, "text", def.text)
hud.text = def.text
else
data[key] = {
id = player:hud_add(def),
text = def.text
}
end
end
local function dimhuds(player, data, darken, vignette)
hudset(player, data, "darken", {
hud_elem_type = "image",
position = {x = 0.5, y = 0.5},
text = darken == 0 and "" or (
"[combine:1x1^[noalpha^[opacity:"
.. math_ceil(255 * darken)),
direction = 0,
scale = {x = -100, y = -100},
offset = {x = 0, y = 0},
quick = true
})
hudset(player, data, "vignette", {
hud_elem_type = "image",
position = {x = 0.5, y = 0.5},
text = vignette == 0 and "" or (
"szutil_cinecam_vignette.png^[opacity:"
.. math_ceil(255 * vignette)),
direction = 0,
scale = {x = -100, y = -100},
offset = {x = 0, y = 0},
quick = true
})
end
local function camdummy(player, data, dtime)
data.dummycam = (data.dummycam or 0) - dtime
if data.dummycam > 0 then
@ -130,6 +176,8 @@ local function camdummy(player, data, dtime)
local tpos = vector.multiply(dpos, (len - dummyclear) / len)
if sightblocked(dpos, tpos) then return end
dimhuds(player, data, dummydark, dummyvig)
setcamera(player, dpos, tpos)
data.dummycam = cycletime
end
@ -141,31 +189,17 @@ local function camcheck(player, dtime)
if data.target then
text = "Watching: " .. data.target
end
if data.tip then
if text ~= data.tip.text then data.tip.time = 0 end
data.tip.text = text
local show = text
if data.tip.time >= hudtime then show = "" end
if data.tip.show ~= show then
player:hud_change(data.tip.id, "text", show)
data.tip.show = text
end
data.tip.time = data.tip.time + dtime
elseif text ~= "" then
data.tip = {
id = player:hud_add({
if data.tiptext ~= text then data.tiptime = 0 end
data.tiptext = text
if data.tiptime > hudtime then text = "" end
hudset(player, data, "tip", {
hud_elem_type = "text",
position = {x = 0.5, y = 1},
text = text,
number = 0xFFFFFF,
alignment = {x = 0, y = -1},
offset = {x = 0, y = -8},
}),
text = text,
show = text,
time = 0
}
end
})
if data.locked then
data.locked = data.locked - dtime
@ -243,6 +277,7 @@ local function camcheck(player, dtime)
if not allow(trypos) then return end
dimhuds(player, data, actdark, actvig)
setcamera(player, trypos, tpos)
data.moved = 0

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB