08-21-14, 04:50 PM | #1 |
New in AddOn Developpment - First shot
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 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 . |
|
08-21-14, 09:53 PM | #2 | |
First of all, whatever addon(s) you're looking at for guidance are horribly written, and I suggest you stop using them as examples of how to write Lua code or Wow addons.
Secondly,
You (and any potential users of your addons) will be be better off if you just write individual addons that each fill a specific purpose -- for example, have one addon that modifies the tooltip, and don't put any code into that addon that isn't related to modifying the tooltip. This way, people who want to use your tooltip addon aren't forced to also use your action bar addon, your unit frames addon, your bag addon, etc. and if a patch breaks your tooltip addon it doesn't also break everything else in your UI. If you're trying to add information to the existing tooltip, this won't achieve that goal. This creates a new tooltip frame. Even if you did want to create another tooltip frame, you should definitely not name it "gameToolTip" or anything else that's a near-exact match for an existing Blizzard frame name. Code:
gameToolTip:RegisterEvent("PLAYER_REGEN_ENABLED"); gameToolTip:RegisterEvent("PLAYER_REGEN_DISABLED"); Code:
self:RegisterEvent("PLAYER_REGEN_ENABLED") self:RegisterEvent("PLAYER_REGEN_DISABLED") Code:
gameToolTip:SetScript("OnEvent", Tooltip_OnEvent); Actually, on further investigation, you can get rid of those events, too, since all you're using them for is to toggle a boolean value, and instead of consulting that boolean, you can just check if the player is in combat directly when you're actually doing stuff: Code:
function TT:Tooltip_HookSetUnit() if UnitAffectingCombat("player") then return end -- do things here end bTooltip is a small tooltip addon that does inspect stuff, and its code didn't make me want to pour bleach into my eye sockets, so you may want to look at that as an example.
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
||
08-22-14, 02:46 AM | #3 |
Thx for reply .
i didn't think that do a complete suite is less powerful. Welcome to my garvage collector ! Can you link addons (you know) wich have good practice in they code ? I'll go analyze bToolTip, but if there is no best practices topic, if not many addons are good, how can we start coding ? i find the list of ace3 lib and example of using it. Is there a topic which explain a generic skeleton addon ? - How to init my addon - Which event should i catch, why - should i save data (savedVariable?), how, why - it's an ui addon (skada for example), how manage frame / elements in frame There is some questions i havn't an idea of solution ^^ In your signature are links i'll follow. Thank's again. |
|
08-22-14, 05:57 AM | #4 | ||
I'd recommend learning how to write addons without using libraries first. That way you'll have a better understanding of how addons actually work, and then later you can make an informed decision about whether to use a library or not.
Whether or not you "should" save data seems like a pretty straightforward question to answer. If you want to save any data -- such as the position of a frame, the user's preferred font, a count of how many murlocs the player has killed, or any other information -- between sessions, save it. If you don't have any data to save, then you don't. As for "managing frames" that's a pretty open-ended question. It really depends on what you want to do. If you want to show or hide a frame, show or hide a frame. If you want to show some text, create a font string and tell it what text to show. etc.
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|||
08-22-14, 08:49 AM | #5 |
AHHHHH HAHAHA I died laughing. X.X
__________________
My mother-in-law fell down a wishing well. I was amazed; I never knew they worked... |
|
08-22-14, 05:47 PM | #6 |
WoWInterface » Developer Discussions » Lua/XML Help » New in AddOn Developpment - First shot |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|