From d54683833e7bfdd864fc5552df6f388c04cf44e9 Mon Sep 17 00:00:00 2001 From: SwissalpS Date: Tue, 30 Mar 2021 04:33:07 +0200 Subject: [PATCH 1/4] depricated statbar without size fix A basic working fix. Proposals are: -as is without background -as is but constrained to background (-no background and going into most annoying directions: up and left/right) --- huds.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/huds.lua b/huds.lua index e29c7bf..67ea743 100644 --- a/huds.lua +++ b/huds.lua @@ -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 } +postool.HUD_STATBAR_SIZE = { x = 160, y = 18 } -- hud id map (playername -> { playername = { tIDs = { hud-ids }, tb = { toggles }, ... ) postool.tHudDB = {} @@ -150,9 +151,10 @@ postool.rebuildHud = function(oPlayer) hud_elem_type = 'statbar', name = 'postoolMeseconsUsageBG', position = tPosition, - offset = { x = 0, y = iY -23 }, + offset = { x = -2, y = iY - 27 }, text = 'mesecons_use_bg.png', scale = HUD_SCALE, + size = postool.HUD_STATBAR_SIZE, alignment = HUD_ALIGNMENT, number = 3 }) @@ -160,9 +162,10 @@ postool.rebuildHud = function(oPlayer) 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 = postool.HUD_STATBAR_SIZE.y }, alignment = HUD_ALIGNMENT, number = 4 }) @@ -170,7 +173,7 @@ postool.rebuildHud = function(oPlayer) 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, @@ -359,8 +362,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 * postool.HUD_STATBAR_SIZE.x), + y = postool.HUD_STATBAR_SIZE.y + math.floor(tCtx.penalty * 16) + }) end -- updateHudMesecons From 64c7400a0b691c96c4808a5ce22924060361b63a Mon Sep 17 00:00:00 2001 From: SwissalpS Date: Tue, 30 Mar 2021 04:42:17 +0200 Subject: [PATCH 2/4] removes background statbar --- huds.lua | 14 +------------- textures/mesecons_use_bg.png | Bin 158 -> 0 bytes 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 textures/mesecons_use_bg.png diff --git a/huds.lua b/huds.lua index 67ea743..de54df6 100644 --- a/huds.lua +++ b/huds.lua @@ -143,21 +143,10 @@ 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 = -2, y = iY - 27 }, - text = 'mesecons_use_bg.png', - scale = HUD_SCALE, - size = postool.HUD_STATBAR_SIZE, - alignment = HUD_ALIGNMENT, - number = 3 - }) tIDs.meseconsUsageFG = oPlayer:hud_add({ hud_elem_type = 'statbar', name = 'postoolMeseconsUsageFG', @@ -186,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) diff --git a/textures/mesecons_use_bg.png b/textures/mesecons_use_bg.png deleted file mode 100644 index 12bc4617ffa81ed88b3ed121f829ea1c5a070f89..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 158 zcmeAS@N?(olHy`uVBq!ia0vp^DL~A@!3HGxuSAssDYhhUcNd2LAh=-f^2tCE&H|6f zVg?4j!ywFfJbwj94||EHuPgf_Rt|0*#vA#}`9L9UPZ!4!kK=DIItnrva2(iR_+Q`T wA$LwejMBp1Gp~+I#WOh@91-9#WO05ceR3YtcMln>+dyp$p00i_>zopr05kn9Jpcdz From 8e0ae5a24c264147602cc70dc9cd100d6d596d7d Mon Sep 17 00:00:00 2001 From: SwissalpS Date: Tue, 30 Mar 2021 04:47:56 +0200 Subject: [PATCH 3/4] reset tuning helper code --- huds.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/huds.lua b/huds.lua index de54df6..ba08487 100644 --- a/huds.lua +++ b/huds.lua @@ -1,7 +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 } -postool.HUD_STATBAR_SIZE = { x = 160, y = 18 } +local HUD_STATBAR_SIZE = { x = 160, y = 18 } -- hud id map (playername -> { playername = { tIDs = { hud-ids }, tb = { toggles }, ... ) postool.tHudDB = {} @@ -154,7 +154,7 @@ postool.rebuildHud = function(oPlayer) offset = { x = -2, y = iY - 27 }, text = 'mesecons_use_fg.png', scale = HUD_SCALE, - size = { x = 1, y = postool.HUD_STATBAR_SIZE.y }, + size = { x = 1, y = HUD_STATBAR_SIZE.y }, alignment = HUD_ALIGNMENT, number = 4 }) @@ -351,8 +351,8 @@ postool.updateHudMesecons = function(oPlayer) 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, 'size', { - x = math.max(8, .01 * nPercent * postool.HUD_STATBAR_SIZE.x), - y = postool.HUD_STATBAR_SIZE.y + math.floor(tCtx.penalty * 16) + x = math.max(8, .01 * nPercent * HUD_STATBAR_SIZE.x), + y = HUD_STATBAR_SIZE.y + math.floor(tCtx.penalty * 16) }) end -- updateHudMesecons From 216c814e5dff92ce5eef8394a88dacfdfd7dd7f5 Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Tue, 30 Mar 2021 16:51:20 +0200 Subject: [PATCH 4/4] syntax cleanup If no global was declared, we shouldn't do so with our dummy function --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 17bdeaf..74a7ab8 100644 --- a/init.lua +++ b/init.lua @@ -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 = {