View Single Post
08-21-14, 09:53 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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,
Originally Posted by melanorion View Post
The idea is simple : do a complete suite like elvui (for example), so i can see all sides of developpment.
There's nothing simple about this idea, and nothing good about a bloated all-in-one suite like ElvUI. It causes more problems than it's worth unless you're an egomaniac who needs to pee on all the fire hydrants or spray-paint your name on all the walls.

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.

Originally Posted by melanorion View Post
local gameToolTip = CreateFrame("Frame", "gameToolTip", Tooltip)
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");
You don't need to create your own frame to receive events -- your AceAddon object already inherits AceEvent, so you can just register events directly on your addon object:

Code:
    self:RegisterEvent("PLAYER_REGEN_ENABLED")
    self:RegisterEvent("PLAYER_REGEN_DISABLED")
And this doesn't actually do anything:

Code:
    gameToolTip:SetScript("OnEvent", Tooltip_OnEvent);
... because it's looking for a function named Tooltip_OnEvent which doesn't exist anywhere in your code. You do have a method on your addon object with that name, but you'd need to refer to it as self.Tooltip_OnEvent here if you wanted to use it. However, since you should be getting rid of this confusing tooltip-like frame and registering events directly on your addon object, you can also get rid of this method.

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
As for the rest, it probably won't work at all for units other than yourself, and if it does, it won't work consistently, since inspecting is not instant. For the player unit, you can just use GetAverageItemLevel to get your own average item level, and not worry about the inspection API. For other players, though, after you ask the game to inspect someone with NotifyInspect you need to wait until the INSPECT_READY event fires to signify that inspection data is available before you scan their items. There's also the problem of inspections being throttled, so if other addons are also calling NotifyInspect then some requests may be dropped.

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.
  Reply With Quote