Hello,
first, english is not my favorite language, sorry for mistakes
.
I'm here to increase my addOn developpment skills, and i try a first shot. I think the code is awful, but i didn't find best practice to do some stuff.
The idea is simple : do a complete suite like elvui (for example), so i can see all sides of developpment.
At the beginning, i only want to modify general tooltip to add the mouseover ilevel. I made different search, look at different addon (SimpleILevel, AiL, InspectEquip-2.0.6, draiks-broker-ilevel-r56, EquippedAverageItemLevelTooltip-2.1.1) but no way to do something good.
Here is the code, next my different questions
.
Code:
local E, L, V, P, G = unpack(select(2, ...)); --Inport: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
local TT = E:NewModule('Tooltip', 'AceTimer-3.0', 'AceHook-3.0', 'AceEvent-3.0')
local ItemUpgradeInfo = LibStub("LibItemUpgradeInfo-1.0")
local gameToolTip = CreateFrame("Frame", "gameToolTip", Tooltip);
local showIlevel = true;
local slots = { "HeadSlot", "NeckSlot", "ShoulderSlot", "BackSlot", "ChestSlot",
"WristSlot", "HandsSlot", "WaistSlot", "LegsSlot", "FeetSlot",
"Finger0Slot", "Finger1Slot", "Trinket0Slot", "Trinket1Slot", "MainHandSlot",
"SecondaryHandSlot" }
function TT:OnInitialize()
E:Print("Module Tooltip initialization");
gameToolTip:SetScript("OnEvent", Tooltip_OnEvent);
gameToolTip:RegisterEvent("PLAYER_REGEN_ENABLED");
gameToolTip:RegisterEvent("PLAYER_REGEN_DISABLED");
self:HookScript(GameTooltip, "OnTooltipSetUnit", "Tooltip_HookSetUnit");
--GameTooltip:HookScript("OnTooltipSetItem", Tooltip_HookSetItem);
--ShoppingTooltip1:HookScript("OnTooltipSetItem", Tooltip_HookCompareItem);
--ShoppingTooltip2:HookScript("OnTooltipSetItem", Tooltip_HookCompareItem2);
--ItemRefTooltip:HookScript("OnTooltipSetItem", Tooltip_HookRefItem);
end
function TT:Tooltip_OnEvent(self, event, ...)
if(event == "PLAYER_REGEN_ENABLED") then
showIlevel = true;
end
if(event == "PLAYER_REGEN_DISABLED") then
showIlevel = false;
end
end
function TT:Tooltip_HookSetUnit()
if(showIlevel) then
local avgItemLevelEquipped = self:getAverageIlevel();
if(avgItemLevelEquipped) then
GameTooltip:AddLine("Ilevel : "..avgItemLevelEquipped,255,255,255);
end
end
end
function TT:getAverageIlevel()
local unit = "mouseover";
if unit and CanInspect(unit) and CheckInteractDistance(unit, 1) then
NotifyInspect(unit);
local playerName = UnitName(unit);
local sum, count=0,0;
for _,slot in pairs(slots) do
local idSlot = GetInventorySlotInfo(slot);
local itemId = GetInventoryItemID("mouseover", idSlot);
if itemId then
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType,
itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(itemId);
if itemLink then
local ilvl = ItemUpgradeInfo:GetUpgradedItemLevel(itemLink);
count = count + 1;
sum = sum + ilvl;
end
end
end
ClearInspectPlayer();
if (sum or 0) >= (count or 0) and (count or 0) > 0 then
return sum/count;
else
return 0;
end
end
end
It works, but not as better as possible. Transmog break all the result for example (it takes transmog ilevel and not original item).
I think here isn't any best practice, like when / whow declare my registerEvent.
When i over a player character. inspect frame do not show correctly, i have to try few times before it shows. Same for items in inspect frame's slots (they don't load).
I see hook, but don't find the exact goal.
After the code review, my wish is to add all tooltips to a frame, item's tooltip from bag or inspect with mouse anchor with more infos, and others like player character mouseover at the top of screen. Anyway that's the futur
.
Thanks a lot
.