Reworked free_space indicator

It now will show percent used rather than percent free.
This commit is contained in:
david 2021-10-19 19:42:02 -04:00
parent e8da2782ad
commit 620101a8db
4 changed files with 18 additions and 16 deletions

View File

@ -14,8 +14,8 @@ function inotify.render_inv(player, pos, off, align, scaler)
end
end
local space_max = inv:get_size("main")
-- = Form free space percent
local perc = (empty / space_max) * 100
-- = Form free space percent (Change it so instead of tracking empty track used percent)
local perc = math.abs(((empty / space_max) * 100) - 100) -- 3% used rather than 3% free
-- = Check if in the health tracker, check if needing update to HUD
local dirty = true -- Assume we do need to update
if inotify.free_space[pname] ~= nil then
@ -31,15 +31,15 @@ function inotify.render_inv(player, pos, off, align, scaler)
if inotify.free_space_hud[pname] == nil then
local color = inotify.colors.white
if perc <= 25 then
color = inotify.colors.red
color = inotify.colors.green
elseif perc <= 50 and perc > 25 then
color = inotify.colors.orange
color = inotify.colors.dark_green
elseif perc <= 75 and perc > 50 then
color = inotify.colors.yellow
elseif perc <= 95 and perc > 75 then
color = inotify.colors.dark_green
color = inotify.colors.orange
elseif perc > 95 then
color = inotify.colors.green
color = inotify.colors.red
end
inotify.free_space_hud[pname] = player:hud_add({
hud_elem_type = "text",
@ -55,15 +55,15 @@ function inotify.render_inv(player, pos, off, align, scaler)
player:hud_change(inotify.free_space_hud[pname], "text", ""..inotify.free_space[pname].."/"..inv:get_size("main").." "..string.format("%.0f", perc).."%")
local color = inotify.colors.white
if perc <= 25 then
color = inotify.colors.red
color = inotify.colors.green
elseif perc <= 50 and perc > 25 then
color = inotify.colors.orange
color = inotify.colors.dark_green
elseif perc <= 75 and perc > 50 then
color = inotify.colors.yellow
elseif perc <= 95 and perc > 75 then
color = inotify.colors.dark_green
color = inotify.colors.orange
elseif perc > 95 then
color = inotify.colors.green
color = inotify.colors.red
end
player:hud_change(inotify.free_space_hud[pname], "number", color)
end

View File

@ -9,7 +9,7 @@ function inotify.render_health(player, pos, off, align, scaler)
local hp = player:get_hp()
local hp_max = player:get_properties().hp_max
-- = Form HP percent
local hp_perc = (hp / hp_max) * 100
local hp_perc = ((hp / hp_max) * 100)
-- = Check if in the health tracker, check if needing update to HUD
local dirty = true -- Assume we do need to update
if inotify.health[pname] ~= nil then
@ -46,7 +46,7 @@ function inotify.render_health(player, pos, off, align, scaler)
})
else
if dirty then
player:hud_change(inotify.health_hud[pname], "text", "HP: "..string.format("%.0f", hp_perc).."%")
--player:hud_change(inotify.health_hud[pname], "text", "HP: "..string.format("%.0f", hp_perc).."%")
local color = inotify.colors.white
if hp_perc <= 25 then
color = inotify.colors.red

View File

@ -3,7 +3,7 @@ inotify = {}
--inotify.store = minetest.get_mod_storage()
-- Settings
inotify.interval_rate = 3
inotify.interval_rate = 0
inotify.include_day_count = true
-- Colors, HEX, and RGB
@ -63,6 +63,7 @@ minetest.register_globalstep(function(dtime)
end
-- Update time per second
for _, player in ipairs(minetest.get_connected_players()) do
inotify.render_worldt(
player,
{x=0.15, y=0.85},

View File

@ -3,8 +3,8 @@ inotify.worldt_hud = {}
function inotify.get_mi(hour)
hr = tonumber(hour)
if hr >= 0 and hr <= 11 then return 'am' end -- midnight->noon
if hr >= 12 and hr <= 23 then return 'pm' end -- noon->midnight
if hr >= 0 and hr <= 11 then return 'AM' end -- midnight->noon
if hr >= 12 and hr <= 23 then return 'PM' end -- noon->midnight
minetest.log("warning", "Could not get mi from "..tostring(hour))
end
@ -28,6 +28,7 @@ function inotify.render_worldt(player, posi, off, align, scaler)
--minetest.log("action", time_stamp)
if inotify.worldt_hud[pname] == nil then
-- Change the color based on the time (I really want it to "follow" the time of day, if it's bright or dark)
local cl = inotify.colors.green -- Daytime == bright
if mi == "am" then -- Nighttime == dark
cl = inotify.colors.dark_green
@ -43,7 +44,7 @@ function inotify.render_worldt(player, posi, off, align, scaler)
})
else
local cl = inotify.colors.green
if mi == "am" then
if mi == "AM" then
cl = inotify.colors.dark_green
end
player:hud_change(