From 23f19b4d6249f241d76b7c2b1c1366a26c56b042 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Tue, 26 Jan 2021 14:57:59 +0100 Subject: [PATCH] Created (empty) tooltip for garden plots --- CookieMonster.js | 29 ++++++++++++++++++++--------- src/Disp.js | 15 ++++++++++++++- src/Main.js | 14 ++++++-------- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index 0f8c20e..bd905c3 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2416,9 +2416,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 // Adds area for extra tooltip-sections - if ((type == 'b' && Game.buyMode == 1) || type == 'u' || type == 's' || type == 'g') { + if ((type == 'b' && Game.buyMode == 1) || type == 'u' || type == 's' || type == 'g' || type == 'p') { var area = document.createElement('div'); area.id = 'CMTooltipArea'; l('tooltip').appendChild(area); @@ -2583,6 +2584,9 @@ CM.Disp.UpdateTooltip = function() { else if (CM.Disp.tooltipType === 'g') { CM.Disp.UpdateTooltipGrimoire(); } + else if (CM.Disp.tooltipType === 'p') { + CM.Disp.UpdateTooltipGardenPlots(); + } CM.Disp.UpdateTooltipWarnings(); } else if (l('CMTooltipArea') == null) { // Remove warnings if its a basic tooltip @@ -2779,6 +2783,15 @@ CM.Disp.UpdateTooltipGrimoire = function() { } } +/** + * This function adds extra info to the Garden plots tooltips + * It is called when Garden plots tooltips are created or refreshed by CM.Disp.UpdateTooltip() + * It adds to the additional information to l('CMTooltipArea') + */ +CM.Disp.UpdateTooltipGardenPlots = function() { + var minigame = Game.Objects['Farm'].minigame; +} + /** * This function updates the warnings section of the building and upgrade tooltips * It is called by CM.Disp.UpdateTooltip() @@ -4335,18 +4348,16 @@ CM.Main.ReplaceTooltipLump = function() { }; /** - * This function replaces the original .onmouseover functions of sugar lumps so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to '?' + * This function replaces the original .onmouseover functions of all garden plants so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'p' * It is called by CM.Main.ReplaceTooltips() */ CM.Main.ReplaceTooltipGarden = function() { if (Game.Objects['Farm'].minigameLoaded) { - CM.Main.TooltipGardenBackup = []; - for (var i in Game.Objects['Farm'].minigame.plot) { - for (var j in i) { - //console.log(j, i) - } - } + 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 5b55a01..e96b144 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1233,9 +1233,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 // Adds area for extra tooltip-sections - if ((type == 'b' && Game.buyMode == 1) || type == 'u' || type == 's' || type == 'g') { + if ((type == 'b' && Game.buyMode == 1) || type == 'u' || type == 's' || type == 'g' || type == 'p') { var area = document.createElement('div'); area.id = 'CMTooltipArea'; l('tooltip').appendChild(area); @@ -1400,6 +1401,9 @@ CM.Disp.UpdateTooltip = function() { else if (CM.Disp.tooltipType === 'g') { CM.Disp.UpdateTooltipGrimoire(); } + else if (CM.Disp.tooltipType === 'p') { + CM.Disp.UpdateTooltipGardenPlots(); + } CM.Disp.UpdateTooltipWarnings(); } else if (l('CMTooltipArea') == null) { // Remove warnings if its a basic tooltip @@ -1596,6 +1600,15 @@ CM.Disp.UpdateTooltipGrimoire = function() { } } +/** + * This function adds extra info to the Garden plots tooltips + * It is called when Garden plots tooltips are created or refreshed by CM.Disp.UpdateTooltip() + * It adds to the additional information to l('CMTooltipArea') + */ +CM.Disp.UpdateTooltipGardenPlots = function() { + var minigame = Game.Objects['Farm'].minigame; +} + /** * 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 ed34fd0..9a8e75e 100644 --- a/src/Main.js +++ b/src/Main.js @@ -323,18 +323,16 @@ CM.Main.ReplaceTooltipLump = function() { }; /** - * This function replaces the original .onmouseover functions of sugar lumps so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to '?' + * This function replaces the original .onmouseover functions of all garden plants so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'p' * It is called by CM.Main.ReplaceTooltips() */ CM.Main.ReplaceTooltipGarden = function() { if (Game.Objects['Farm'].minigameLoaded) { - CM.Main.TooltipGardenBackup = []; - for (var i in Game.Objects['Farm'].minigame.plot) { - for (var j in i) { - //console.log(j, i) - } - } + 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();}; + }); } };