From b6cd262ff2674f0e5187c081fc5051f378492d9f Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sun, 27 Dec 2020 13:27:44 +0100 Subject: [PATCH] Fixed (#388) and add percentage overlay to timers --- CookieMonster.js | 21 ++++++++------------- src/Disp.js | 21 ++++++++------------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index cab285e..c8215fd 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -1558,7 +1558,7 @@ CM.Disp.CreateTimerBar = function() { CM.Disp.TimerBar.id = 'CMTimerBar'; CM.Disp.TimerBar.style.position = 'absolute'; CM.Disp.TimerBar.style.display = 'none'; - CM.Disp.TimerBar.style.height = '48px'; + CM.Disp.TimerBar.style.height = '30px'; CM.Disp.TimerBar.style.fontSize = '10px'; CM.Disp.TimerBar.style.fontWeight = 'bold'; CM.Disp.TimerBar.style.backgroundColor = 'black'; @@ -1707,7 +1707,8 @@ CM.Disp.UpdateTimerBar = function() { } else classColor = CM.Disp.colorPurple; timer.lastChild.children[1].className = CM.Disp.colorBackPre + classColor; - timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time *(maxWidthOneBar - Math.ceil(Game.buffs[i].time / Game.fps).toString().length * 8) / Game.buffs[i].maxTime) + 'px'; + timer.lastChild.children[1].textContent = Math.round(100 * (Game.buffs[i].time / Game.buffs[i].maxTime)) + "%"; + timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time * (maxWidthOneBar - Math.ceil(Game.buffs[i].time / Game.fps).toString().length * 8) / Game.buffs[i].maxTime) + 'px'; timer.lastChild.children[2].textContent = Math.ceil(Game.buffs[i].time / Game.fps); numberOfTimers++; CM.Disp.BuffTimerBars[Game.buffs[i].name] = timer @@ -1718,13 +1719,7 @@ CM.Disp.UpdateTimerBar = function() { } if (numberOfTimers != 0) { - var height = 48 / numberOfTimers; - for (var i in CM.Disp.TimerBars) { - CM.Disp.TimerBars[i].style.height = height + 'px'; - } - for (var i in CM.Disp.BuffTimerBars) { - CM.Disp.BuffTimerBars[i].style.height = height + 'px'; - } + CM.Disp.TimerBar.style.height = numberOfTimers * 12 + 2 + 'px'; } } } @@ -1766,22 +1761,22 @@ CM.Disp.ToggleTimerBarPos = function() { */ CM.Disp.UpdateBotTimerBarPosition = function() { if (CM.Options.BotBar == 1 && CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 1) { - CM.Disp.BotBar.style.bottom = '48px'; - l('game').style.bottom = '118px'; + CM.Disp.BotBar.style.bottom = CM.Disp.TimerBar.style.height; + l('game').style.bottom = Number(CM.Disp.TimerBar.style.height.replace("px","")) + 70 + "px"; } else if (CM.Options.BotBar == 1) { CM.Disp.BotBar.style.bottom = '0px'; l('game').style.bottom = '70px'; } else if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 1) { - l('game').style.bottom = '48px'; + l('game').style.bottom = CM.Disp.TimerBar.style.height; } else { // No bars l('game').style.bottom = '0px'; } if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 0) { - l('sectionLeft').style.top = '48px'; + l('sectionLeft').style.top = CM.Disp.TimerBar.style.height; } else { l('sectionLeft').style.top = ''; diff --git a/src/Disp.js b/src/Disp.js index 045c4a7..52f5eeb 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -442,7 +442,7 @@ CM.Disp.CreateTimerBar = function() { CM.Disp.TimerBar.id = 'CMTimerBar'; CM.Disp.TimerBar.style.position = 'absolute'; CM.Disp.TimerBar.style.display = 'none'; - CM.Disp.TimerBar.style.height = '48px'; + CM.Disp.TimerBar.style.height = '30px'; CM.Disp.TimerBar.style.fontSize = '10px'; CM.Disp.TimerBar.style.fontWeight = 'bold'; CM.Disp.TimerBar.style.backgroundColor = 'black'; @@ -591,7 +591,8 @@ CM.Disp.UpdateTimerBar = function() { } else classColor = CM.Disp.colorPurple; timer.lastChild.children[1].className = CM.Disp.colorBackPre + classColor; - timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time *(maxWidthOneBar - Math.ceil(Game.buffs[i].time / Game.fps).toString().length * 8) / Game.buffs[i].maxTime) + 'px'; + timer.lastChild.children[1].textContent = Math.round(100 * (Game.buffs[i].time / Game.buffs[i].maxTime)) + "%"; + timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time * (maxWidthOneBar - Math.ceil(Game.buffs[i].time / Game.fps).toString().length * 8) / Game.buffs[i].maxTime) + 'px'; timer.lastChild.children[2].textContent = Math.ceil(Game.buffs[i].time / Game.fps); numberOfTimers++; CM.Disp.BuffTimerBars[Game.buffs[i].name] = timer @@ -602,13 +603,7 @@ CM.Disp.UpdateTimerBar = function() { } if (numberOfTimers != 0) { - var height = 48 / numberOfTimers; - for (var i in CM.Disp.TimerBars) { - CM.Disp.TimerBars[i].style.height = height + 'px'; - } - for (var i in CM.Disp.BuffTimerBars) { - CM.Disp.BuffTimerBars[i].style.height = height + 'px'; - } + CM.Disp.TimerBar.style.height = numberOfTimers * 12 + 2 + 'px'; } } } @@ -650,22 +645,22 @@ CM.Disp.ToggleTimerBarPos = function() { */ CM.Disp.UpdateBotTimerBarPosition = function() { if (CM.Options.BotBar == 1 && CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 1) { - CM.Disp.BotBar.style.bottom = '48px'; - l('game').style.bottom = '118px'; + CM.Disp.BotBar.style.bottom = CM.Disp.TimerBar.style.height; + l('game').style.bottom = Number(CM.Disp.TimerBar.style.height.replace("px","")) + 70 + "px"; } else if (CM.Options.BotBar == 1) { CM.Disp.BotBar.style.bottom = '0px'; l('game').style.bottom = '70px'; } else if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 1) { - l('game').style.bottom = '48px'; + l('game').style.bottom = CM.Disp.TimerBar.style.height; } else { // No bars l('game').style.bottom = '0px'; } if (CM.Options.TimerBar == 1 && CM.Options.TimerBarPos == 0) { - l('sectionLeft').style.top = '48px'; + l('sectionLeft').style.top = CM.Disp.TimerBar.style.height; } else { l('sectionLeft').style.top = '';