valrix Posted March 24, 2015 Share Posted March 24, 2015 I'm not sure if this counts as more of a mod or script, but I've managed to enable custom tooltips by setting an item's getModData()["tooltip"] object. It supports multiple labels, too! I haven't managed to make the values stay centered, but got pretty close. Example:local md = result:getModData();md.tooltip = {};md.tooltip.amount = ZombRand(3) .. "." .. ZombRand(99);Installation:Paste the following spoiler'd script into a new file and save it in the "client" folder of your mod for it to work. Script:require "ISUI/ISToolTipInv"if ISToolTipInv.loaded ~= nil then print("Custom tooltips already loaded, skipping..."); returnelse ISToolTipInv.loaded = 1endfunction ISToolTipInv:render() -- we render the tool tip for inventory item only if there's no context menu showed if not ISContextMenu.instance or not ISContextMenu.instance.visibleCheck then -- tool tips are glitched in that they do not set their properties set before DoTooltip is called -- therefore we cannot ensure that they are placed correctly local mx = getMouseX() + 24; local my = getMouseY() + 24; if not self.followMouse then mx = self:getX() my = self:getY() end -- if not self.toolTipDone then self.tooltip:setX(mx+11); self.tooltip:setY(my); self.tooltip:setWidth(50) self.item:DoTooltip(self.tooltip); -- self.toolTipDone = true; -- return; -- end -- clampy x, y local myCore = getCore(); local maxX = myCore:getScreenWidth(); local maxY = myCore:getScreenHeight(); local tw = self.tooltip:getWidth(); local th = self.tooltip:getHeight(); local lh = getTextManager():getFontFromEnum(UIFont.Small):getLineHeight(); self.tooltip:setX(math.max(0, math.min(mx + 11, maxX - tw - 1))); self.tooltip:setY(math.max(0, math.min(my, maxY - th - 1))); self:setX(self.tooltip:getX() - 11); self:setY(self.tooltip:getY()); self:setWidth(tw + 11); -- helper function function len(T) local c = 0 for _ in pairs(T) do c = c + 1 end return c end local itemData = nil; if self.item:hasModData() then itemData = self.item:getModData(); if itemData.tooltip ~= nil then th = th + (lh * len(itemData.tooltip)); end end self:setHeight(th); self:drawRect(0, 0, self.width, self.height, self.backgroundColor.a, self.backgroundColor.r, self.backgroundColor.g, self.backgroundColor.b); self:drawRectBorder(0, 0, self.width, self.height, self.borderColor.a, self.borderColor.r, self.borderColor.g, self.borderColor.b); if itemData ~= nil and itemData.tooltip ~= nil then -- local x = 5; local count = 1; local label; local ty; for key in pairs(itemData.tooltip) do ty = 25 + (lh * count); label = key:gsub("^%l", string.upper) .. ":"; self.tooltip:DrawText(label, 5, ty, 1,1,0.8,1); -- [x = ] pad + 40 + getTextManager():MeasureStringX(UIFont.Small, label) self.tooltip:DrawText(itemData.tooltip[key], (self.width / 2) + 12, ty, 1,1,1,1); count = count + 1; end end self.item:DoTooltip(self.tooltip); endend Changelog:v0.2.0- Added check so only the first one it finds will be loaded. v0.1.0- Added ability to add custom tooltips as key/value pairs. abreu20011, blindcoder and WolfeClaw 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now