Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions huds.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local HUD_POSITION = { x = postool.hudPosX, y = postool.hudPosY }
local HUD_ALIGNMENT = { x = 1, y = 0 }
local HUD_SCALE = { x = 100, y = 100 }
local HUD_STATBAR_SIZE = { x = 160, y = 18 }

-- hud id map (playername -> { playername = { tIDs = { hud-ids }, tb = { toggles }, ... )
postool.tHudDB = {}
Expand Down Expand Up @@ -142,35 +143,26 @@ postool.rebuildHud = function(oPlayer)
local bAdvTrains = postool.hasAdvancedTrains()
local bMesecons = postool.hasMeseconsDebug()

local iID = tIDs.meseconsUsageBG
local iID = tIDs.meseconsUsageFG
if tb[5] and bMesecons then

if nil == iID then
tIDs.meseconsUsageBG = oPlayer:hud_add({
hud_elem_type = 'statbar',
name = 'postoolMeseconsUsageBG',
position = tPosition,
offset = { x = 0, y = iY -23 },
text = 'mesecons_use_bg.png',
scale = HUD_SCALE,
alignment = HUD_ALIGNMENT,
number = 3
})
tIDs.meseconsUsageFG = oPlayer:hud_add({
hud_elem_type = 'statbar',
name = 'postoolMeseconsUsageFG',
position = tPosition,
offset = { x = 0, y = iY -23 },
offset = { x = -2, y = iY - 27 },
text = 'mesecons_use_fg.png',
scale = HUD_SCALE,
size = { x = 1, y = HUD_STATBAR_SIZE.y },
alignment = HUD_ALIGNMENT,
number = 4
})
tIDs.meseconsPenalty = oPlayer:hud_add({
hud_elem_type = 'text',
name = 'postoolMeseconsPenalty',
position = tPosition,
offset = { x = 0, y = 0 },
offset = { x = 0, y = -16 },
text = 'Initializing...',
scale = HUD_SCALE,
alignment = HUD_ALIGNMENT,
Expand All @@ -183,7 +175,6 @@ postool.rebuildHud = function(oPlayer)
elseif nil ~= iID then

oPlayer:hud_remove(iID)
tIDs.meseconsUsageBG = nil
oPlayer:hud_remove(tIDs.meseconsUsageFG)
tIDs.meseconsUsageFG = nil
oPlayer:hud_remove(tIDs.meseconsPenalty)
Expand Down Expand Up @@ -359,8 +350,10 @@ postool.updateHudMesecons = function(oPlayer)
oPlayer:hud_change(tIDs.meseconsPenalty, 'text', sPenalty)
oPlayer:hud_change(tIDs.meseconsUsageFG, 'text', sTexture)
-- give a minimum to show, so can see red penalty even when no usage
oPlayer:hud_change(tIDs.meseconsUsageFG, 'number', math.max(8, nPercent * 3))

oPlayer:hud_change(tIDs.meseconsUsageFG, 'size', {
x = math.max(8, .01 * nPercent * HUD_STATBAR_SIZE.x),
y = HUD_STATBAR_SIZE.y + math.floor(tCtx.penalty * 16)
})
end -- updateHudMesecons


Expand Down
2 changes: 1 addition & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- read the readme.md for more info on origin.

-- safety check in case translation function does not exist
if not minetest.global_exists('S') then S = function(s) return s end end
local S = (minetest.global_exists('S') and S) or function(s) return s end

--settings
postool = {
Expand Down
Binary file removed textures/mesecons_use_bg.png
Binary file not shown.