Thread Tools Display Modes
09-09-12, 05:51 PM   #1
Maggz
A Cyclonian
 
Maggz's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 45
Updating tooltip while tooltip is still active.

ok i am still a bit on the newb side, so im asking this question to see if this is something that is even possible. i can show a tiny snippet of my code to see what im tying to accomplish.

Lua Code:
  1. local malObject = {
  2.     type = "launcher",
  3.     icon = "Interface\\Addons\\MaggzAutoLog\\disabled",
  4.     label = "MaggzAutoLog",
  5.     OnClick = function(self, button)
  6.         if button == "RightButton" then
  7.             LOGSTATE()
  8.         end
  9.         if button == "LeftButton" then
  10.             if LoggingCombat() then
  11.                 disablelogging()
  12.             else
  13.                 enablelogging()
  14.             end
  15.         end
  16.     end,
  17.     OnTooltipShow = function(tooltip)
  18.     tooltip:AddLine("|cff00FF00MaggzAutoLog|r");
  19.     tooltip:AddLine("hold left mouse button to drag");
  20.     tooltip:AddLine("right click to enable/disable logging");
  21.     if LoggingCombat() then
  22.         tooltip:AddLine("Logging |cff00FF00Enabled|r");
  23.     else
  24.         tooltip:AddLine("Logging |cffFF0000Disabled|r");
  25.     end
  26. end,
  27. };

i used the minimap button creation tips i had found thru searching and atm it all works well for me, with one minor issue, i cant seem to find any documentation anywhere about how to update that last tooltip:AddLine("information here"); while the tooltip is still open and displaying. If this is something that cant be currently done that would be nice to know as well.

What my main goal is here is to add in some displayfunctionality to my addon to show current state of your combat logging. i do believe i have accomplished that with just this one issue perplexing me. Only reason i wanted to add this sort of ability is because i used loggerhead for a long while and liked how it functioned, however its not been updated for atleast last 2 patches. I know my addon is going to be NO WHERE near the functionality as that one.

If i need to post my entire LUA file here please let me know as well, i just wanted to atleast get some inut as to what im looking to do is capable
__________________
Maggz Turalyon-US

Last edited by Maggz : 09-09-12 at 06:09 PM.
  Reply With Quote
09-09-12, 08:12 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You can call GameTooltip:AddLine() whenever you want and add text just fine. What you're missing is that you should always call GameTooltip:Show() after adding to it in order to refresh the tooltip, make sure everything is shown that you want, and to make the GameTooltip resize itself to fit your new lines.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-09-12, 08:38 PM   #3
Maggz
A Cyclonian
 
Maggz's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 45
i can get my tooltip to display perfectly with one exception, i would like for it to reset when i right click to update the tooltip info without having to move my mouse off the tooltip and rehover. i tried adding what your proposing and it isnt working. i tried adding just the GameTooltip:Show() in under my right onclick events and it just doesnt reset the tooltip unless i rehover over the tooltip. Am i missing something in my understanding? or can you not refresh a tooltip on a mouseclick?



++++++
sorry i passed my event in an incorrect variable i had similar to the enable and disable logging functions. it adds a line just fine, however if i just keep clicking i can end up with 500 lines of tooltips. Is there a way to simply overwrite an existing ine in your tooltip?
__________________
Maggz Turalyon-US

Last edited by Maggz : 09-09-12 at 08:49 PM.
  Reply With Quote
09-09-12, 09:09 PM   #4
Maggz
A Cyclonian
 
Maggz's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 45
AHHH i did figure it out, sorry to have bugged ya with the reply, it took me some figuring out to call a GameTooltip:ClearLines() first then append all the tooltips i want added back after that call. Tho it would be much nicer if there was a way to just remove line 3 and replace it with a new line. Sorry to seem such a newb and TY for your help, you pointed me in the right direction and i definatly appreciate that. Guess now that leaves my TODO list at figuring out how to save the position of my minimap icon properly lol thats another day tho.
__________________
Maggz Turalyon-US

Last edited by Maggz : 09-09-12 at 09:13 PM.
  Reply With Quote
09-09-12, 09:16 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Just change the text of line three then.

GameTooltipTextLeft3:SetText("new text!")
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-09-12, 10:21 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Generally, if you have access to the function that creates the tooltip in the first place, you can just call it again. It shouldn't matter if the tooltip is still showing.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
09-09-12, 11:28 PM   #7
Maggz
A Cyclonian
 
Maggz's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 45
Well ty again guys, i do appreciate all your help. I am having trouble with another issue now and it keep reading and still havent found my answer so possibly maybe you could also give me alil more help. What im trying to do is have my minimap icon remember its position and well i just cant seem to figure this one out, ive read 5 different sites and each one seems to have completely different ways of doing it and i cant seem to get any of them to work, so ill post my LUA file and see if you could possibly point me in a direction other than ive attempted.


Lua Code:
  1. local db;
  2. local defaults = { 
  3.         profile = {    
  4.             LDBIconStorage = {},
  5.         },
  6. };
  7. local malObject = {
  8.     type = "launcher",
  9.     icon = "Interface\\Addons\\MaggzAutoLog\\disabled",
  10.     label = "MaggzAutoLog",
  11.     OnClick = function(self, button)
  12.         if button == "RightButton" then
  13.             LOGSTATE()
  14.         end
  15.         if button == "LeftButton" then
  16.             if LoggingCombat() then
  17.                 disablelogging()
  18.             else
  19.                 enablelogging()
  20.             end
  21.         end
  22.     end,
  23.     OnTooltipShow = function(tooltip)
  24.     tooltip:AddLine("|cff00FF00MaggzAutoLog|r");
  25.     tooltip:AddLine("hold left mouse button to drag");
  26.     tooltip:AddLine("right click to enable/disable logging");
  27.     if LoggingCombat() then
  28.         tooltip:AddLine("Logging |cff00FF00Enabled|r");
  29.     else
  30.         tooltip:AddLine("Logging |cffFF0000Disabled|r");
  31.     end
  32. end,
  33. };
  34. function updateDB(self, event, database)
  35.     db = database.profile;
  36.     LibStub("LibDBIcon-1.0"):Refresh("MaggzAutoLogDB", db.LDBIconStorage);
  37.     end
  38. local vars = LibStub("AceDB-3.0"):New("MaggzAutoLogBD", defaults);
  39. vars:RegisterCallback("OnProfileChanged", updateDB);
  40. vars:RegisterCallback("OnProfileCopied", updateDB);
  41. vars:RegisterCallback("OnProfileReset", updateDB);
  42. db = vars.profile;
  43.  
  44. LibStub("LibDataBroker-1.1"):NewDataObject("MaggzAutoLogDB", malObject);
  45. LibStub("LibDBIcon-1.0"):Register("MaggzAutoLogDB", malObject, db.LDBIconStorage);

That is the part of my LUA that has anything to do with my icon aside from my already assigned functions:
LOGSTATE()
enablelogging()
disablelogging()

my toc file contains a line reading ## SavedVariables: MaggzAutoLogDB


i cant seem to figure out what im doing wrong. its probably something so simple and im just too dumb to figure it out.
__________________
Maggz Turalyon-US
  Reply With Quote
09-09-12, 11:29 PM   #8
Maggz
A Cyclonian
 
Maggz's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 45
Originally Posted by Seerah View Post
Just change the text of line three then.

GameTooltipTextLeft3:SetText("new text!")
bw i will use that method over what i currently did, that is definatly alot less and cleaner method TY.
__________________
Maggz Turalyon-US
  Reply With Quote
09-10-12, 03:10 AM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Maggz View Post
... ive read 5 different sites and each one seems to have completely different ways of doing it and i cant seem to get any of them to work ...
I've been writing addons for 7 years and I've honestly never had a use for Ace3. When bringing in different libraries that do different things, there are literally hundreds of ways that open up to accomplish the same thing. All of them use the base mechanic of registering a global through their ToC and read/write data to it. Ace3 has its own method that I have yet to read through their code to figure out, but it seems that you're using one half of the base method and the other half is of Ace3. First of all, to use the base method, you need to choose a global variable that won't be accessed by anything else, not even Ace3. If the global isn't exclusive to your code only, there could be problems with data corruption.



The bad thing if you start off programming directly with libraries is you never really learn how the actual WoW API works, instead, the libraries are doing all the grunt work for you and you develop a dependency on them.



Let's say you name your global MaggzAutoLog_Options:
ToC:
Code:
## SavedVariables: MaggzAutoLog_Options
Lua:
Lua Code:
  1. --  This gets our directory name and shared table
  2. local Name,Addon=...;
  3.  
  4. --  Saved Variable (this is our initial value)
  5. MaggzAutoLog_Options={
  6.     Enabled=true;
  7. };
  8.  
  9. --  We'll need an event frame to trigger an update when we actually get our variable loaded
  10. local EFrame=CreateFrame("Frame");--    Just an anonymous frame so we can listen to events firing
  11. EFrame:RegisterEvent("ADDON_LOADED");-- The event we want to listen for
  12. EFrame:SetScript("OnEvent",function(self,event,...)--       Events fire through this script handler
  13. --  Right now, this will only fire with the ADDON_LOADED event, no check needed for that
  14. --  Note ADDON_LOADED fires with the addon's directory name as its only argument
  15.  
  16.     if (...)==Name then--   Check if our addon is the one that's done loading (checks versus the first argument vararg takes)
  17.         LoggingCombat(MaggzAutoLog_Options.Enabled);--  Update logging according to saved variable
  18.         self:UnregisterEvent(event);--  Don't need to run this event anymore
  19.     end
  20. end);
  21.  
  22. --  This is a special hook to update your saved variable in case someone else decides to toggle logging
  23. local OldFunc=LoggingCombat;--  Backup the unhooked version (this will prevent recursive calls later)
  24. hooksecurefunc("LoggingCombat",function(flag)
  25. --  No external input should be trusted if you can help it, so we'll ask the function itself if logging has been enabled
  26.     MaggzAutoLog_Options.Enabled=OldFunc();
  27. end);

This is pretty much a self-contained addon, all that it needs is an interface that toggles LoggingCombat().
If anyone with Ace3 knowledge wants to create better code, go right ahead.



Edit: Line 38:
Code:
local vars = LibStub("AceDB-3.0"):New("MaggzAutoLogBD", defaults);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 09-10-12 at 03:25 AM.
  Reply With Quote
09-10-12, 02:11 PM   #10
Maggz
A Cyclonian
 
Maggz's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 45
ty for seeing that darn typo, im actually not looking to add a variable in to call for if the log is enabled, thats something i can easily do in game, im having an issue with setting and remembering minimap icon position. i have been reading alot more and did get my DB to add my character nam and realm to the DB which is something im not trying to do but atleast my DB is adding stuff altho its not the right stuff lol. ill keep at this and see if i get any luck TY all for your help here BTW.


ok with a few more changes im getting my DB to have the correct data, however i dont know how to get my minimap icon to load at the saved position, still reading thru stuff so i may end up getting this one however if someone sees changes i need to make to do this here is my NEW lua file::

Lua Code:
  1. local f = CreateFrame("Frame")
  2. MaggzAutoLog = LibStub("AceAddon-3.0"):NewAddon("MaggzAutoLog")
  3. function MaggzAutoLog:OnInitialize()
  4.   self.db = LibStub("AceDB-3.0"):New("MaggzAutoLogDB")
  5. end
  6. local db;
  7. local defaults = { 
  8.         profile = {    
  9.             LDBIconStorage = {},
  10.         },
  11. };
  12. local malObject = {
  13.     type = "launcher",
  14.     icon = "Interface\\Addons\\MaggzAutoLog\\disabled",
  15.     label = "MaggzAutoLog",
  16.     OnClick = function(self, button)
  17.         if button == "RightButton" then
  18.             LOGSTATE()
  19.         end
  20.         if button == "LeftButton" then
  21.             if LoggingCombat() then
  22.                 disablelogging()
  23.             else
  24.                 enablelogging()
  25.             end
  26.         end
  27.     end,
  28.     OnTooltipShow = function(tooltip)
  29.     tooltip:AddLine("|cff00FF00MaggzAutoLog|r");
  30.     tooltip:AddLine("hold left mouse button to drag");
  31.     tooltip:AddLine("right click to enable/disable logging");
  32.     if LoggingCombat() then
  33.         tooltip:AddLine("Logging |cff00FF00Enabled|r");
  34.     else
  35.         tooltip:AddLine("Logging |cffFF0000Disabled|r");
  36.     end
  37. end,
  38. };
  39. function updateDB(self, event, database)
  40.     db = database.profile;
  41.     LibStub("LibDBIcon-1.0"):Refresh("MaggzAutoLogDB", db.LDBIconStorage);
  42.     end
  43. local vars = LibStub("AceDB-3.0"):New("MaggzAutoLogDB", defaults);
  44. vars:RegisterCallback("OnProfileChanged", updateDB);
  45. vars:RegisterCallback("OnProfileCopied", updateDB);
  46. vars:RegisterCallback("OnProfileReset", updateDB);
  47. db = vars.profile;
  48.  
  49. LibStub("LibDataBroker-1.1"):NewDataObject("MaggzAutoLogDB", malObject);
  50. LibStub("LibDBIcon-1.0"):Register("MaggzAutoLog", malObject, db.LDBIconStorage);

still working some things out so it is still a but messy.
__________________
Maggz Turalyon-US

Last edited by Maggz : 09-10-12 at 03:19 PM. Reason: db adding correct stuff now
  Reply With Quote
09-10-12, 08:23 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The problem is that you are initializing your DB before the user's saved DB is actually loaded, so it's always resetting to defaults, and ignoring whatever the user had saved before.

Using AceAddon is massive overkill for something so small.

Using AceDB is probably also overkill for something so simple. Unless you plan to add a large number of complex options that users are likely to want to share between some characters but not others and take a long time to set up, I'd avoid using AceDB. For shared settings, use SavedVariables. For per-character settings, use SavedVariablesPerCharacter.

I'd go with something like this:

Code:
local f = CreateFrame("Frame", "MaggzAutoLog")

f.dataObject = {
    type = "launcher",
    icon = "Interface\\Addons\\MaggzAutoLog\\disabled",
    label = "MaggzAutoLog",
    OnClick = function(self, button)
        if button == "RightButton" then
            LOGSTATE() -- Where is this function defined?
        else
			-- No need to do "if X then ... end" followed by "if Y then ... end".
			-- Use a simple "if X then ... else ... end" instead.
            if LoggingCombat() then
                disablelogging() -- Where is this function defined?
            else
                enablelogging() -- Where is this function defined?
            end
        end
    end,
    OnTooltipShow = function(tooltip)
		tooltip:AddLine("|cff00FF00MaggzAutoLog|r")
		tooltip:AddLine("hold left mouse button to drag")
			-- What are you dragging? This is the tooltip for an icon
			-- on your Broker display; you're not dragging it anywhere.
		tooltip:AddLine("right click to enable/disable logging")
		if LoggingCombat() then
			tooltip:AddLine("Logging |cff00FF00Enabled|r")
		else
			tooltip:AddLine("Logging |cffFF0000Disabled|r")
		end
	end,
}

f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function()
	MaggzAutoLogDB = MaggzAutoLogDB or {}
	MaggzAutoLogDB.LDBIconStorage = MaggzAutoLogDB.LDBIconStorage or {}

	LibStub("LibDataBroker-1.1"):NewDataObject("MaggzAutoLogDB", f.dataObject)
	LibStub("LibDBIcon-1.0"):Register("MaggzAutoLog", f.dataObject, MaggzAutoLogDB.LDBIconStorage)
end)
__________________
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
09-10-12, 11:09 PM   #12
Maggz
A Cyclonian
 
Maggz's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 45
Ty phanx, your setup definatly assisted me in getting my addon working 100%. I didnt end up using your simpler approach mainly because i couldnt figure out how to change the minimap icon using frames. it just seemed easier to do it in something similar to my original setup. I wouldnt have been able to even get this nailed down tho if it wasnt for you and seerah's help for sure so i thank you VERY VERY much. This will allow me to now change my autolog from just a text based cmd line addon to something nicer, along the lines of what loggerhead was prior to it adding in the learning based on previous instances. maybe eventually ill head that way with this addon however i mainly used this addon to help me learn all this stuff as i am wanting to do something else after this.
__________________
Maggz Turalyon-US
  Reply With Quote
09-10-12, 11:32 PM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
What do you mean by "change the minimap icon"? Change it how? When?
__________________
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
09-11-12, 12:56 AM   #14
Maggz
A Cyclonian
 
Maggz's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 45
Originally Posted by Phanx View Post
What do you mean by "change the minimap icon"? Change it how? When?
oh ive made it so on left click it changes my icon to another (grey for logging OFF, green for logging ON) basicaly im using the minimap icon as sort of a status monitor for th combat logging state. Currently the method im using works pretty easily. (that functionality was hidden in those functions you had asked if i had defined because they were not defined there in the section i pasted here) I am sure there is a way to do it outside of using the libdbicon however i found this was pretty easily understood by my simple mind.
__________________
Maggz Turalyon-US
  Reply With Quote
09-11-12, 04:44 PM   #15
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
LibDBIcon just uses your data object's icon.

Code:
f.dataObject = {
	type = "launcher",
	icon = "Interface\\Addons\\MaggzAutoLog\\disabled",
	label = "MaggzAutoLog",
	OnClick = function(self, button)
		if button == "RightButton" then
			LOGSTATE()
		elseif LoggingCombat() then
			disablelogging()
			f.dataObject.icon = "Interface\\Addons\\MaggzAutoLog\\disabled"
		else
			enablelogging()
			f.dataObject.icon = "Interface\\Addons\\MaggzAutoLog\\enabled"
		end
	end,
}
__________________
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
09-11-12, 07:02 PM   #16
Maggz
A Cyclonian
 
Maggz's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 45
ahh see i was calling for the icon change in the functions i created and it wasnt working for me with that method which is why i chose to use the libDbicon method which just allowed me to call externally outside the actual object i was creating. was doing that to try and keep things clean and understandable to me in the future incase i have to update things later, however it seems your way does do the same thing and im just a nub who didnt figure it out. only issue im really having now with it is, if i am in a raid instance do a /reload or logout and back in (either form does this to me) is that my initial icon does not change i did try putting the IF THEN ELSE setup you showed me there to have it set the icon on load to whichever is currently the state of logging, however it seems to return errors using that in the first half of the creation.

Ill probably try and see about setting up a DB to perform this function at a later date, just have some other things im working on atm. however regardless ty for the suggestions and help thus far.
__________________
Maggz Turalyon-US
  Reply With Quote
09-12-12, 05:52 AM   #17
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Maggz View Post
ahh see i was calling for the icon change in the functions i created and it wasnt working for me with that method which is why i chose to use the libDbicon method which just allowed me to call externally outside the actual object i was creating. was doing that to try and keep things clean and understandable to me in the future incase i have to update things later, however it seems your way does do the same thing and im just a nub who didnt figure it out. only issue im really having now with it is, if i am in a raid instance do a /reload or logout and back in (either form does this to me) is that my initial icon does not change i did try putting the IF THEN ELSE setup you showed me there to have it set the icon on load to whichever is currently the state of logging, however it seems to return errors using that in the first half of the creation.
See, this is why you should show your whole code. Showing bits and pieces, and guessing about the rest, is just such a waste of time for everyone involved.
__________________
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
09-16-12, 09:49 PM   #18
Maggz
A Cyclonian
 
Maggz's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 45
A big Thank You

Ok i wanted to post to this thread again even tho it is a bit late. I finished my addon and posted it for download, it all works great (even tho i tend to mess with it EVERYDAY). Anyhow i wanted to specifically thank Phanx and Seerah for your immense help. After a week or so i actually went thru it all and redid all my ACE3 bloat functions and removed them defaulting back to the normal coding you guys posted here as help for me. Not only where you both correct that this addon i made was FAR to small to even need any of that stuff, when i tried adding new features (hiding minimap icon so a UI looks clean while having chocolate bar or something similar) it just made things so confusing for me i broke the addon itself because of all the confusion. So in essence i want to thank the both of you for your help and showing me there is NO need for all that bloat on small addons. I just wanted to post this message as a thanks to you for all your help.
__________________
Maggz Turalyon-US
  Reply With Quote
09-16-12, 09:53 PM   #19
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
SDPhantom spoke of no need for libraries, not me. (Though I agree with him on it - I only use libs to make my options panels, and then only if they're more than just a few settings.)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-16-12, 10:10 PM   #20
Maggz
A Cyclonian
 
Maggz's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 45
Well then i also extend my thank you to them as well.
__________________
Maggz Turalyon-US
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Updating tooltip while tooltip is still active.

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off