10/06/24, 09:48 AM | #1 | |
Join Date: Oct 2024
Posts: 2
|
How to tooltip?
Hello everyone,
I'm new to addon developing. I have years of experience in .net and general application development but eso addons and pythong is new to me. I started with a "simple" addon that would show a tooltip when hovering over an item with that item's id in it. This is mainly because I want to create an addon based on Dolgubon's LazyAlchemyLearner bit expended upon it and also for enchanting glyph's. Since I would need Item Id's for this and I couldn't find a list online with Id's of items I thought making an addon that would display the Id's in a tooltip on hovering would help me a lot. I almost got it to work. I can display the name and the Id of an item in chat when hovering over that item in inventory or craftbag. When trying to place it in a tooltip however things stop working. No error, just nothing showing up. Code:
-- Addon Name MyItemIDViewer = {} MyItemIDViewer.name = "MyItemIDViewer" local tooltipControl -- Function to print item name and ID to the custom tooltip local function ShowTooltip(itemName, itemId, mouseX, mouseY) tooltipControl:SetHidden(false) --tooltipControl:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, mouseX + 10, mouseY + 10) -- Position it near the mouse tooltipControl:SetAnchor(LEFT, GuiMouse, RIGHT, 32, 0) tooltipControl:SetText("test") --tooltipControl:SetText("Item Name: " .. itemName .. "\nItem ID: " .. itemId) end -- Function to hide the custom tooltip local function HideTooltip() tooltipControl:SetHidden(true) end -- Hook function for mouse exit to hide the tooltip local function OnMouseExit() HideTooltip() end -- Function to print item name and ID to chat local function PrintItemInfo(bagId, slotId) -- Get the item name and item ID from the item link local itemLink = GetItemLink(bagId, slotId) local itemName = GetItemLinkName(itemLink) local itemId = GetItemLinkItemId(itemLink) -- Use this method to get the item ID from the item link -- Show the custom tooltip at the mouse position local mouseX, mouseY = GetUIMousePosition() ShowTooltip(itemName, itemId, mouseX, mouseY) end -- Hook function for when the tooltip is set local function OnTooltipSetItem(tooltipControl, bagId, slotId) PrintItemInfo(bagId, slotId) end -- Hook into the tooltip functions local function HookBagTips() ZO_PreHook(ItemTooltip, "SetBagItem", OnTooltipSetItem) -- Inventory bags ItemTooltip:SetHandler("OnMouseLeave", OnMouseExit) -- Hide tooltip on mouse leave end -- Function that runs when the addon is loaded local function OnAddOnLoaded(event, name) if name ~= MyItemIDViewer.name then return end -- If it's not our addon loaded, don't run this. Would get errors. -- Create the tooltip control tooltipControl = WINDOW_MANAGER:CreateControl("MyItemIDViewerTooltip", GuiRoot, CT_LABEL) tooltipControl:SetFont("ZoFontHeader") tooltipControl:SetColor(1, 1, 1, 1) tooltipControl:SetText("Test Text") tooltipControl:SetDimensions(300, 100) tooltipControl:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, 800, 800) tooltipControl:SetDrawLayer(DL_OVERLAY) tooltipControl:SetHidden(false) HookBagTips() EVENT_MANAGER:UnregisterForEvent(MyItemIDViewer.name, event) -- We no longer want this to run as the game loads addons. It only needs to run once. end -- Register for the event when the addon is loaded EVENT_MANAGER:RegisterForEvent(MyItemIDViewer.name, EVENT_ADD_ON_LOADED, OnAddOnLoaded) -- As the game loads, the event manager registers our addon for an event. Could someone push me in the right direction? Kind Regards, Mathinator Last edited by Mathinator : 10/06/24 at 09:48 AM. Reason: forgot to mention it only worked in chat |
|
10/06/24, 12:52 PM | #2 | |
You need to create a TopLevelControl fist and then add (parent) your tooltip control (label) to it!
Then you can hide and show that TLC as tooltip control. https://github.com/esoui/esoui/blob/...balvars.lua#L9 Lua Code:
You cannot just create a label control and show and hide it without an underlaying TLC or other controls that belong to a TLC. Another idea but I guess the missing TLC is the reason here: Most probably your PreHook here is calling your code, showing the tooltip but then hides it again as the original function "SetBagItem" is called after your "pre hook"?
Add debug messages d("got here") to see how far your code get's executed and see what works, and what is never called. Also try to add: tooltipControl:ClearAnchors() as first line of your ShowTooltip function Last edited by Baertram : 10/06/24 at 01:01 PM. |
||
10/06/24, 07:03 PM | #3 |
For the tooltip question, you could do this, to make 'just' a tooltip with text.
InitializeTooltip(InformationTooltip, GuiRoot, TOP, 0, 0) SetTooltipText(InformationTooltip, "Text") Or, you can do this to add a line to specifically an item tooltip: ItemTooltip:AddLine("HIHIHIH") I don't think there's a real need to create any new controls for your use case. But, assuming your end goal is to get the item IDs into a .lua file, it's probably easiest to just dump all the item IDs and names you need into chat, and then use pChat's copy channel function to copy them. If you want to take over lazy alchemy learner and improve it that'd be awesome Even if not, feel free to grab the IDs from the addon. There's all the base game reagent IDs as well as some of the DLC IDs. (I think it was uploaded. If not, I have it locally and can send some to you) |
|
Yesterday, 05:03 PM | #4 | |
Join Date: Oct 2024
Posts: 2
|
Thanks for the help guys, I ended up just printing them in chat and just dealing with it since I couldn't get the tooltip to work at all.
@Dolgubon, did not expect to hear from the author himself . I think I almost got it to a working stage. Did a lot of rework on the alchemyQueuer function. But its nicely detecting what combo's I still need to do, based on actual missing traits. Code:
local function alchemyQueuer(combos) local LLC = LazyAlchemyLearner.LLC local remainingSolvent = 0 local solvent local position = 0 local queued = 0 for i = 1, #combos do local known = true -- we check what traits between the two reagents are matching local matchingTraits = GetMatchingTraits(combos[i][1], combos[i][2]) local amountMatchingReagant1 = 0 local amountMatchingReagant2 = 0 for j = 1, 4 do local k1, n1 = GetItemLinkReagentTraitInfo(getItemLinkFromItemId(combos[i][1]), j) local k2, n2 = GetItemLinkReagentTraitInfo(getItemLinkFromItemId(combos[i][2]), j) --we count the amount of known matching traits of each reagant if Contains(matchingTraits, n1) then amountMatchingReagant1 = amountMatchingReagant1 + 1 end if Contains(matchingTraits, n2) then amountMatchingReagant2 = amountMatchingReagant2 + 1 end end known = known and amountMatchingReagant1 == #matchingTraits and amountMatchingReagant2 == #matchingTraits --Leaving this here for debug purposes for now local reagantName1 = GetItemLinkName(getItemLinkFromItemId(combos[i][1])) local reagantName2 = GetItemLinkName(getItemLinkFromItemId(combos[i][2])) --d("Combination '" .. tostring(reagantName1) .. "' and '" .. tostring(reagantName2) .. "' known? -> " .. tostring(known)) if not known then --decide the solvent we are going to use, currently with poison only remainingSolvent, solvent = getSolvent(GetNonCombatBonus(NON_COMBAT_BONUS_ALCHEMY_LEVEL) + 1) local solventName = GetItemLinkName(getItemLinkFromItemId(solvent)) remainingSolvent = remainingSolvent - 1 --queued = queued + 1 d("Lazy Alchemy Learner: Queued " .. tostring(solventName) .. " with " .. tostring(reagantName1) .. " and " .. tostring(reagantName2) .. ".") --LLC:CraftAlchemyItemId(solvent, combos[i][1],combos[i][2],nil, 1, true,'1') end end return queued end Now I just hope the LLC:CraftAlchemyItemId is just gonna work out of the box XD But I'll keep that excitement for another time it's 1am and have to go to work tomorrow (or I guess today) in about 6 hours. Cheers |
|
Today, 02:31 AM | #5 | |
If you are in the flow... |
||
ESOUI » Developer Discussions » Lua/XML Help » How to tooltip? |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|