From 6c852e2c50d992882ac70c4d0e6e10fae4dfbacc Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Wed, 27 Jan 2021 22:12:37 +0100 Subject: [PATCH] Tooltip for harvest all button #227 --- CookieMonster.js | 48 +++++++++++++++++++++++++++++++++++++++++++++++- src/Disp.js | 47 ++++++++++++++++++++++++++++++++++++++++++++++- src/Main.js | 1 + 3 files changed, 94 insertions(+), 2 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index d5faf20..cfece1b 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2446,9 +2446,10 @@ CM.Disp.Tooltip = function(type, name) { else if (type === 's') l('tooltip').innerHTML = Game.lumpTooltip(); // Sugar Lumps else if (type === 'g') l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); // Grimoire else if (type == 'p') l('tooltip').innerHTML = Game.ObjectsById[2].minigame.tileTooltip(name[0], name[1])(); // Garden plots + else if (type == 'ha') l('tooltip').innerHTML = Game.ObjectsById[2].minigame.toolTooltip(1)(); // Harvest all button in garden // Adds area for extra tooltip-sections - if ((type == 'b' && Game.buyMode == 1) || type == 'u' || type == 's' || type == 'g' || type == 'p') { + if ((type == 'b' && Game.buyMode == 1) || type == 'u' || type == 's' || type == 'g' || type == 'p' || type == 'ha') { var area = document.createElement('div'); area.id = 'CMTooltipArea'; l('tooltip').appendChild(area); @@ -2613,6 +2614,9 @@ CM.Disp.UpdateTooltip = function() { else if (CM.Disp.tooltipType === 'p') { CM.Disp.UpdateTooltipGardenPlots(); } + else if (CM.Disp.tooltipType === 'ha') { + CM.Disp.UpdateTooltipHarvestAll(); + } CM.Disp.UpdateTooltipWarnings(); } else if (l('CMTooltipArea') == null) { // Remove warnings if its a basic tooltip @@ -2844,6 +2848,47 @@ CM.Disp.UpdateTooltipGardenPlots = function() { else l('CMTooltipArea').style.display = "none"; } +/** + * This function adds extra info to the Garden Harvest All tooltip + * It is called when the Harvest All tooltip is created or refreshed by CM.Disp.UpdateTooltip() + * It adds to the additional information to l('CMTooltipArea') + */ +CM.Disp.UpdateTooltipHarvestAll = function() { + var minigame = Game.Objects['Farm'].minigame; + if (CM.Options.TooltipLump) { + l('CMTooltipBorder').appendChild(CM.Disp.TooltipCreateHeader('Cookies gained from harvesting:')); + var totalGain = 0; + if (Game.keys[16] && Game.keys[17]) var mortal = 1; + for (var y=0;y<6;y++) { + for (var x=0;x<6;x++) { + if (minigame.plot[y][x][0]>=1) { + let tile = minigame.plot[y][x]; + let me = minigame.plantsById[tile[0] - 1]; + let plantName = me.name + + let count = true; + if (mortal && me.immortal) count = false; + if (tile[1] < me.matureBase) count = false; + if (count && plantName == "Bakeberry") { + totalGain += Math.min(Game.cookies * 0.03, Game.cookiesPs * 60 * 30); + } + else if (count && plantName == "Chocoroot" || plantName == "White chocoroot") { + totalGain += Math.min(Game.cookies * 0.03, Game.cookiesPs * 60 * 3); + } + else if (count && plantName == "Queenbeet") { + totalGain += Math.min(Game.cookies * 0.04, Game.cookiesPs * 60 * 60); + } + else if (count && plantName == "Duketater") { + totalGain += Math.min(Game.cookies * 0.08, Game.cookiesPs * 60 * 120); + } + } + } + } + l('CMTooltipBorder').appendChild(document.createTextNode(CM.Disp.Beautify(totalGain))); + } + else l('CMTooltipArea').style.display = "none"; +} + /** * This function updates the warnings section of the building and upgrade tooltips * It is called by CM.Disp.UpdateTooltip() @@ -4407,6 +4452,7 @@ CM.Main.ReplaceTooltipLump = function() { */ CM.Main.ReplaceTooltipGarden = function() { if (Game.Objects['Farm'].minigameLoaded) { + l('gardenTool-1').onmouseover = function() {Game.tooltip.dynamic=1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip('ha', 'HarvestAllButton');}, 'this'); Game.tooltip.wobble();} Array.from(l('gardenPlot').children).forEach((child, index) => { var coords = child.id.slice(-3,); child.onmouseover = function() {Game.tooltip.dynamic=1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip('p', [`${coords[0]}`,`${coords[2]}`]);}, 'this'); Game.tooltip.wobble();}; diff --git a/src/Disp.js b/src/Disp.js index 019439a..2e10ea6 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1234,9 +1234,10 @@ CM.Disp.Tooltip = function(type, name) { else if (type === 's') l('tooltip').innerHTML = Game.lumpTooltip(); // Sugar Lumps else if (type === 'g') l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); // Grimoire else if (type == 'p') l('tooltip').innerHTML = Game.ObjectsById[2].minigame.tileTooltip(name[0], name[1])(); // Garden plots + else if (type == 'ha') l('tooltip').innerHTML = Game.ObjectsById[2].minigame.toolTooltip(1)(); // Harvest all button in garden // Adds area for extra tooltip-sections - if ((type == 'b' && Game.buyMode == 1) || type == 'u' || type == 's' || type == 'g' || type == 'p') { + if ((type == 'b' && Game.buyMode == 1) || type == 'u' || type == 's' || type == 'g' || type == 'p' || type == 'ha') { var area = document.createElement('div'); area.id = 'CMTooltipArea'; l('tooltip').appendChild(area); @@ -1401,6 +1402,9 @@ CM.Disp.UpdateTooltip = function() { else if (CM.Disp.tooltipType === 'p') { CM.Disp.UpdateTooltipGardenPlots(); } + else if (CM.Disp.tooltipType === 'ha') { + CM.Disp.UpdateTooltipHarvestAll(); + } CM.Disp.UpdateTooltipWarnings(); } else if (l('CMTooltipArea') == null) { // Remove warnings if its a basic tooltip @@ -1632,6 +1636,47 @@ CM.Disp.UpdateTooltipGardenPlots = function() { else l('CMTooltipArea').style.display = "none"; } +/** + * This function adds extra info to the Garden Harvest All tooltip + * It is called when the Harvest All tooltip is created or refreshed by CM.Disp.UpdateTooltip() + * It adds to the additional information to l('CMTooltipArea') + */ +CM.Disp.UpdateTooltipHarvestAll = function() { + var minigame = Game.Objects['Farm'].minigame; + if (CM.Options.TooltipLump) { + l('CMTooltipBorder').appendChild(CM.Disp.TooltipCreateHeader('Cookies gained from harvesting:')); + var totalGain = 0; + if (Game.keys[16] && Game.keys[17]) var mortal = 1; + for (var y=0;y<6;y++) { + for (var x=0;x<6;x++) { + if (minigame.plot[y][x][0]>=1) { + let tile = minigame.plot[y][x]; + let me = minigame.plantsById[tile[0] - 1]; + let plantName = me.name + + let count = true; + if (mortal && me.immortal) count = false; + if (tile[1] < me.matureBase) count = false; + if (count && plantName == "Bakeberry") { + totalGain += Math.min(Game.cookies * 0.03, Game.cookiesPs * 60 * 30); + } + else if (count && plantName == "Chocoroot" || plantName == "White chocoroot") { + totalGain += Math.min(Game.cookies * 0.03, Game.cookiesPs * 60 * 3); + } + else if (count && plantName == "Queenbeet") { + totalGain += Math.min(Game.cookies * 0.04, Game.cookiesPs * 60 * 60); + } + else if (count && plantName == "Duketater") { + totalGain += Math.min(Game.cookies * 0.08, Game.cookiesPs * 60 * 120); + } + } + } + } + l('CMTooltipBorder').appendChild(document.createTextNode(CM.Disp.Beautify(totalGain))); + } + else l('CMTooltipArea').style.display = "none"; +} + /** * This function updates the warnings section of the building and upgrade tooltips * It is called by CM.Disp.UpdateTooltip() diff --git a/src/Main.js b/src/Main.js index 06265b7..87b3c48 100644 --- a/src/Main.js +++ b/src/Main.js @@ -330,6 +330,7 @@ CM.Main.ReplaceTooltipLump = function() { */ CM.Main.ReplaceTooltipGarden = function() { if (Game.Objects['Farm'].minigameLoaded) { + l('gardenTool-1').onmouseover = function() {Game.tooltip.dynamic=1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip('ha', 'HarvestAllButton');}, 'this'); Game.tooltip.wobble();} Array.from(l('gardenPlot').children).forEach((child, index) => { var coords = child.id.slice(-3,); child.onmouseover = function() {Game.tooltip.dynamic=1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip('p', [`${coords[0]}`,`${coords[2]}`]);}, 'this'); Game.tooltip.wobble();};