diff --git a/Data Files/MWSE/mods/mer/ashfall/activators/activatorMenu.lua b/Data Files/MWSE/mods/mer/ashfall/activators/activatorMenu.lua index 5dbcacf..d8a0551 100644 --- a/Data Files/MWSE/mods/mer/ashfall/activators/activatorMenu.lua +++ b/Data Files/MWSE/mods/mer/ashfall/activators/activatorMenu.lua @@ -155,7 +155,12 @@ event.register("activate", function(e) "pickup", }, tooltipExtra = function(campfire, tooltip) - itemTooltips(campfire.object, campfire.itemData, tooltip) + itemTooltips.addItemTooltips{ + item = campfire.object, + itemData = campfire.itemData, + reference = campfire, + tooltip = tooltip + } end } diff --git a/Data Files/MWSE/mods/mer/ashfall/activators/config/ActivatorMenuConfig.lua b/Data Files/MWSE/mods/mer/ashfall/activators/config/ActivatorMenuConfig.lua index b4c9adb..b5a54c8 100644 --- a/Data Files/MWSE/mods/mer/ashfall/activators/config/ActivatorMenuConfig.lua +++ b/Data Files/MWSE/mods/mer/ashfall/activators/config/ActivatorMenuConfig.lua @@ -148,7 +148,12 @@ ActivatorMenuConfig.nodeMapping = { }, shiftCommand = "removeUtensil", tooltipExtra = function(reference, tooltip) - itemTooltips(reference.object, reference.itemData, tooltip) + itemTooltips.addItemTooltips{ + item = reference.object, + itemData = reference.itemData, + reference = reference, + tooltip = tooltip + } end, }, KETTLE = { @@ -170,7 +175,12 @@ ActivatorMenuConfig.nodeMapping = { shiftCommand = "removeUtensil", tooltipExtra = function(reference, tooltip) - itemTooltips(reference.object, reference.itemData, tooltip) + itemTooltips.addItemTooltips{ + item = reference.object, + itemData = reference.itemData, + reference = reference, + tooltip = tooltip + } end, }, SWITCH_LADLE = { diff --git a/Data Files/MWSE/mods/mer/ashfall/common/common.lua b/Data Files/MWSE/mods/mer/ashfall/common/common.lua index 591eb18..7ac7b05 100644 --- a/Data Files/MWSE/mods/mer/ashfall/common/common.lua +++ b/Data Files/MWSE/mods/mer/ashfall/common/common.lua @@ -94,6 +94,7 @@ end ---@field woodAxesForHarvesting table a map of woodaxe objects which are to be registered for harvesting on load ---@field woodAxesForBackpack table a map of woodaxe objects which are to be registered for backpack display on load ---@field inventorySelectStew boolean True while in the inventory select menu for adding ingredients to stew +---@field inventorySelectTrinket boolean True while in the inventory select menu for adding trinkets to the trinket bag this.data = setmetatable({}, { __index = function(t, key) if not ( tes3.player and tes3.player.data) then diff --git a/Data Files/MWSE/mods/mer/ashfall/ui/itemTooltips.lua b/Data Files/MWSE/mods/mer/ashfall/ui/itemTooltips.lua index 2efc8a8..0962cfd 100644 --- a/Data Files/MWSE/mods/mer/ashfall/ui/itemTooltips.lua +++ b/Data Files/MWSE/mods/mer/ashfall/ui/itemTooltips.lua @@ -8,6 +8,15 @@ local WoodStack = require("mer.ashfall.items.woodStack") local LiquidContainer = require("mer.ashfall.liquid.LiquidContainer") local HeatUtil = require("mer.ashfall.heat.HeatUtil") +---@class Ashfall.addItemTooltips +local itemTooltips = {} + +---@class Ashfall.addItemTooltips.params +---@field item tes3object +---@field itemData tes3itemData +---@field reference tes3reference +---@field tooltip tes3uiElement + --Todo- refactor and get rid of these duplicate functions --They are in CampfireUtil, but that file requires this one already local function getUtensilData(dataHolder) @@ -39,31 +48,33 @@ local function centerText(element) element.justifyText = "center" end -local function addLadleTooltips(item, itemData, tooltip) - if not itemData then return end +---@param e Ashfall.addItemTooltips.params +local function addLadleTooltips(e) + if not e.itemData then return end --Ladle - if common.staticConfigs.cookingPots[item.id:lower()] and itemData.data.ladle then - common.helper.addLabelToTooltip(tooltip, + if common.staticConfigs.cookingPots[e.item.id:lower()] and e.itemData.data.ladle then + common.helper.addLabelToTooltip(e.tooltip, string.format("+Ladle") ) end end -local function addWaterTooltips(item, itemData, tooltip) - local data = itemData and itemData.data or nil +---@param e Ashfall.addItemTooltips.params +local function addWaterTooltips(e) + local data = e.itemData and e.itemData.data or nil local waterHeat = data and data.waterHeat if waterHeat and waterHeat > 0 then - common.helper.addLabelToTooltip(tooltip, + common.helper.addLabelToTooltip(e.tooltip, string.format("Heat: %d/100", waterHeat) ) end - local capacity = getUtensilCapacity{ dataHolder = itemData, object = item } + local capacity = getUtensilCapacity{ dataHolder = e.itemData, object = e.item } if capacity then local waterAmount = data and data.waterAmount or 0 local waterType = data and data.waterType or nil - common.helper.addLabelToTooltip(tooltip, + common.helper.addLabelToTooltip(e.tooltip, string.format("Water: %d/%d %s", math.floor(waterAmount), capacity, @@ -74,25 +85,26 @@ local function addWaterTooltips(item, itemData, tooltip) local unfilteredWater = data and data.unfilteredWater if unfilteredWater and capacity then - common.helper.addLabelToTooltip(tooltip, + common.helper.addLabelToTooltip(e.tooltip, string.format("Unfiltered Water: %d/%d", math.floor(unfilteredWater), capacity)) end end -local function addFoodTooltips(item, itemData, tooltip) +---@param e Ashfall.addItemTooltips.params +local function addFoodTooltips(e) --Food tooltips local labelText - local thisFoodType = foodConfig.getFoodType(item) + local thisFoodType = foodConfig.getFoodType(e.item) if thisFoodType then - local nutrition = hungerController.getNutrition(item, itemData) + local nutrition = hungerController.getNutrition(e.item, e.itemData) if nutrition and nutrition ~= 0 then labelText = string.format("Nutrition: %d", nutrition) - common.helper.addLabelToTooltip(tooltip, labelText) + common.helper.addLabelToTooltip(e.tooltip, labelText) end local cookedLabel = "" - if foodConfig.getGrillValues(item) then + if foodConfig.getGrillValues(e.item) then --Remove cook state from the ingredient name for TR foods local cookStrings = { @@ -101,7 +113,7 @@ local function addFoodTooltips(item, itemData, tooltip) "grilled ", "roasted " } - local nameLabel = tooltip:findChild(tes3ui.registerID("HelpMenu_name")) + local nameLabel = e.tooltip:findChild(tes3ui.registerID("HelpMenu_name")) if not nameLabel then return end for _, pattern in ipairs(cookStrings) do if string.startswith(nameLabel.text:lower(), pattern) then @@ -110,12 +122,12 @@ local function addFoodTooltips(item, itemData, tooltip) end --Add Food type and Cook state label to Tooltip - local cookedAmount = itemData and itemData.data.cookedAmount - if cookedAmount and itemData.data.grillState == nil then + local cookedAmount = e.itemData and e.itemData.data.cookedAmount + if cookedAmount and e.itemData.data.grillState == nil then cookedLabel = string.format(" (%d%% Cooked)", cookedAmount) - elseif itemData and itemData.data.grillState == "cooked" then + elseif e.itemData and e.itemData.data.grillState == "cooked" then cookedLabel = " (Cooked)" - elseif itemData and itemData.data.grillState == "burnt" then + elseif e.itemData and e.itemData.data.grillState == "burnt" then cookedLabel = " (Burnt)" else cookedLabel = " (Raw)" @@ -123,43 +135,41 @@ local function addFoodTooltips(item, itemData, tooltip) end local foodTypeLabel = string.format("%s%s", thisFoodType, cookedLabel) - common.helper.addLabelToTooltip(tooltip, foodTypeLabel) + common.helper.addLabelToTooltip(e.tooltip, foodTypeLabel) --Meat disease/blight if config.enableDiseasedMeat then - if itemData and itemData.data.mer_disease then + if e.itemData and e.itemData.data.mer_disease then local diseaseLabel - local diseaseType = itemData.data.mer_disease.spellType + local diseaseType = e.itemData.data.mer_disease.spellType if diseaseType == tes3.spellType.disease then diseaseLabel = "Diseased" elseif diseaseType == tes3.spellType.blight then diseaseLabel = "Blighted" end if diseaseLabel then - common.helper.addLabelToTooltip(tooltip, diseaseLabel, tes3ui.getPalette("negative_color")) + common.helper.addLabelToTooltip(e.tooltip, diseaseLabel, tes3ui.getPalette("negative_color")) end end end if common.helper.isModifierKeyPressed() then - local actionLabel = tooltip:createLabel({ text = "Eat" }) + local actionLabel = e.tooltip:createLabel({ text = "Eat" }) actionLabel.color = tes3ui.getPalette("active_color") centerText(actionLabel) end end end ----@param item tes3object ----@param itemData tes3itemData ----@param tooltip tes3uiElement -local function addTeaTooltips(item, itemData, tooltip) - if itemData and teaConfig.teaTypes[itemData.data.waterType] then - local progress = itemData.data.teaProgress or 0 - local teaData = teaConfig.teaTypes[itemData.data.waterType] +---@param e Ashfall.addItemTooltips.params +local function addTeaTooltips(e) + if e.itemData and teaConfig.teaTypes[e.itemData.data.waterType] then + local progress = e.itemData.data.teaProgress or 0 + local teaData = teaConfig.teaTypes[e.itemData.data.waterType] if progress >= 100 then - local effectBlock = common.helper.addLabelToTooltip(tooltip) + local effectBlock = common.helper.addLabelToTooltip(e.tooltip) local icon = effectBlock:createImage{ path = "Icons/ashfall/spell/teaBuff.dds" } icon.height = 16 icon.width = 16 @@ -169,8 +179,8 @@ local function addTeaTooltips(item, itemData, tooltip) --for X hours local hoursText = "" if teaData.duration then - local amount = itemData.data.waterAmount - local duration = common.helper.calculateTeaBuffDuration(teaData.duration, itemData.data.waterHeat) + local amount = e.itemData.data.waterAmount + local duration = common.helper.calculateTeaBuffDuration(teaData.duration, e.itemData.data.waterHeat) hoursText = string.format(" for %d hour%s", duration, (duration >= 2 and "s" or "") ) end local effectLabelText = teaData.effectDescription .. hoursText @@ -180,7 +190,7 @@ local function addTeaTooltips(item, itemData, tooltip) local teaLabelText = teaData.teaName - local waterHeat = itemData.data.waterHeat or 0 + local waterHeat = e.itemData.data.waterHeat or 0 local isCold = waterHeat < common.staticConfigs.hotWaterHeatValue if progress == 0 then teaLabelText = string.format("%s (Unbrewed)", teaLabelText) @@ -189,17 +199,18 @@ local function addTeaTooltips(item, itemData, tooltip) elseif isCold then teaLabelText = teaLabelText .. " (Cold)" end - local teaLabel = common.helper.addLabelToTooltip(tooltip, teaLabelText, tes3ui.getPalette("header_color")) - + common.helper.addLabelToTooltip(e.tooltip, teaLabelText, tes3ui.getPalette("header_color")) end end -local function addStewTooltips(item, itemData, tooltip) - - local liquidContainer = LiquidContainer.createFromInventory(item, itemData) +---@param e Ashfall.addItemTooltips.params +---@param liquidContainer Ashfall.LiquidContainer? +local function addStewTooltips(e, liquidContainer) + logger:trace("addStewTooltips") if not (liquidContainer and liquidContainer.stewLevels) then return end + logger:trace("Have Stew") - local outerBlock = tooltip:createBlock{} + local outerBlock = e.tooltip:createBlock{} outerBlock.autoHeight = true outerBlock.autoWidth = true outerBlock.childAlignX = 0.5 @@ -223,6 +234,7 @@ local function addStewTooltips(item, itemData, tooltip) centerText(stewProgressLabel) for foodType, ingredLevel in pairs(liquidContainer.stewLevels) do + logger:trace("Food Type: %s, Level: %d", foodType, ingredLevel) local block = outerBlock:createBlock{} block.autoHeight = true block.autoWidth = true @@ -235,6 +247,7 @@ local function addStewTooltips(item, itemData, tooltip) local ingredText = string.format("(%d%% %s)", value, foodType ) local ingredLabel if liquidContainer.stewProgress >= 100 then + logger:trace("Have Stew Buff") local image = block:createImage{path=("icons\\" .. effect.object.icon)} image.wrapText = false image.borderLeft = 4 @@ -265,7 +278,7 @@ local function addStewTooltips(item, itemData, tooltip) ingredLabel.wrapText = false ingredLabel.borderLeft = 4 else - ingredLabel = tooltip:createLabel{text = ingredText } + ingredLabel = e.tooltip:createLabel{text = ingredText } centerText(ingredLabel) end end @@ -281,19 +294,34 @@ local function addWoodStackTooltips(item, itemData, tooltip) end -local function additemTooltips(item, itemData, tooltip) - local liquidContainer = LiquidContainer.createFromInventory(item, itemData) +---@param e Ashfall.addItemTooltips.params +function itemTooltips.addItemTooltips(e) + local liquidContainer + if e.reference then + liquidContainer = LiquidContainer.createFromReference(e.reference) + else + liquidContainer = LiquidContainer.createFromInventory(e.item, e.itemData) + end + if not e.item then + e.item = e.reference.object + end + if not e.itemData then + e.itemData = e.reference.itemData + end + local menu = tes3ui.findMenu("MenuInventory") if liquidContainer and tes3ui.menuMode() and menu and menu.visible then HeatUtil.updateWaterHeat(liquidContainer) end - addLadleTooltips(item, itemData, tooltip) - addTeaTooltips(item, itemData, tooltip) - addWaterTooltips(item, itemData, tooltip) - addFoodTooltips(item, itemData, tooltip) - addStewTooltips(item, itemData, tooltip) - addWoodStackTooltips(item, itemData, tooltip) - tooltip:updateLayout() + addLadleTooltips(e) + addTeaTooltips(e) + addWaterTooltips(e) + addFoodTooltips(e) + addStewTooltips(e, liquidContainer) + addWoodStackTooltips(e) + e.tooltip:updateLayout() end -return additemTooltips \ No newline at end of file + + +return itemTooltips \ No newline at end of file diff --git a/Data Files/MWSE/mods/mer/ashfall/ui/needsTooltips.lua b/Data Files/MWSE/mods/mer/ashfall/ui/needsTooltips.lua index 1ce496f..8dc52cd 100644 --- a/Data Files/MWSE/mods/mer/ashfall/ui/needsTooltips.lua +++ b/Data Files/MWSE/mods/mer/ashfall/ui/needsTooltips.lua @@ -140,7 +140,12 @@ local function createNeedsTooltip(e) end --used for item and campfire tooltips - itemTooltips(e.object, e.itemData, tooltip) + itemTooltips.addItemTooltips{ + item = e.object, + itemData = e.itemData, + reference = e.reference, + tooltip = tooltip + } local icon = e.tooltip:findChild(tes3ui.registerID("HelpMenu_icon")) if icon then