Thread Tools Display Modes
01-11-12, 10:54 PM   #1
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Battle.net broadcast feed.

So I've been workin on a new addon for a little while that I haven't found a similar match to.

If you've ever logged into Starcraft II you have a nice broadcast list with client icons etc, and I'm simply trying to recreate the same idea but for wow.

My only issue is I'm a little unsure of how to set up a ticker style frame that can sort and so on. I've not really worked with xml much which I'm sure would be the best way of creating this addon.

Suggestions on how I should continue to build my addon would be appreciated, still somewhat of a novice when it comes to addons like this.

Here's my scripting so far:
lua Code:
  1. local Addon = "BattleNetFeed"
  2. local MessageList = {} -- Table of all friend messages and their timestamp listed by presenceID.
  3. local function Meta(vaL)
  4.     local text = GetAddOnMetadata(Addon, vaL)
  5.     return text
  6. end
  7. BNFText = Meta("Title")..": "
  8. local defaults = {
  9.     locked = true,
  10. }
  11. local copytable
  12. copytable = function(original)
  13.     local duplicate = {}
  14.     for key, value in pairs(original) do
  15.         if type(value) == "table" then duplicate[key] = copytable(value)
  16.         else duplicate[key] = value end
  17.     end
  18.     return duplicate
  19. end
  20.  
  21. local function CreateFeed(frame)
  22.     frame:SetWidth(220)
  23.     frame:SetHeight(160)
  24.     frame:SetPoint("TOPLEFT",FriendsFrame,"BOTTOMLEFT",0,-25)
  25.     frame.background = frame:CreateTexture(nil, "BACKGROUND")
  26.     frame.background:SetTexture(0,0,0,0.25)
  27.     frame.background:SetAllPoints(frame)
  28. end
  29.  
  30. BattleNetFeed = CreateFrame("Frame","BattleNetFeed");
  31. BattleNetFeed:RegisterEvent("ADDON_LOADED");
  32. BattleNetFeed:RegisterEvent("BN_CUSTOM_MESSAGE_CHANGED");
  33. BattleNetFeed:RegisterEvent("BN_CUSTOM_MESSAGE_LOADED");
  34. BattleNetFeed:RegisterEvent("BN_FRIEND_INFO_CHANGED");
  35. BattleNetFeed:RegisterEvent("BN_FRIEND_LIST_SIZE_CHANGED");
  36. function BattleNetFeed:Update()
  37.     local numBNetTotal, numBNetOnline = BNGetNumFriends();
  38.     local numBNetOffline = numBNetTotal - numBNetOnline;
  39.     local numWoWTotal, numWoWOnline = GetNumFriends();
  40.     local numWoWOffline = numWoWTotal - numWoWOnline;
  41.     local friends = numBNetTotal + numWoWTotal    
  42.     for i = 1, friends do
  43.         local presenceID, givenName, surname, toonName, toonID, client, isOnline, lastOnline, isAFK, isDND, messageText, noteText, isRIDFriend, messageTime, canSoR = BNGetFriendInfo(i);
  44.         if not MessageList[presenceID] then
  45.             MessageList[presenceID] = {};
  46.             MessageList[presenceID].message = messageText;
  47.             MessageList[presenceID].timestamp = messageTime;
  48.         end
  49.         if presenceID and MessageList[presenceID].message ~= messageText then -- If the message has changed, update.
  50.             MessageList[presenceID].message = messageText;
  51.             MessageList[presenceID].timestamp = messageTime;
  52.             if messageText ~= "" then -- Test updates to messages
  53.                 if toonName then
  54.                     print(givenName.." "..surname.." ("..toonName.."): "..messageText)
  55.                 else
  56.                     print(givenName.." "..surname.." :"..messageText)
  57.                 end
  58.             end
  59.         end
  60.     end
  61. end
  62.  
  63. BattleNetFeed:SetScript("OnEvent", function(self,event,...)
  64.     local arg1,arg2,arg3 = ...
  65.     if event == "ADDON_LOADED" then
  66.         if arg1 == Addon then
  67.             CreateFeed(self)
  68.             if not BNFDB then
  69.                 BNFDB = copytable(defaults)
  70.             end
  71.             self:UnregisterEvent("ADDON_LOADED")
  72.         end
  73.     elseif event == "BN_FRIEND_INFO_CHANGED" or event == "BN_FRIEND_LIST_SIZE_CHANGED" then
  74.         self:Update()
  75.     end
  76. end)
  77.  
  78. FriendsFrame:HookScript("OnShow", function() BattleNetFeed:Show(); BattleNetFeed:Update(); end)
  79. FriendsFrame:HookScript("OnHide", function() BattleNetFeed:Hide(); end)
  Reply With Quote
01-12-12, 12:31 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
XML is not the best way to make this addon, or any addon. The only reason you should ever use XML is if you need to create secure frame templates for other addons to inherit from.

I haven't ever played SC2, so I'm not really sure what the UI you're trying to recreate looks like. Also, if it's simply a feed of recent Battle.net broadcasts, what needs to be sortable? Is the user sorting it manually, or is the addon sorting it based on some criteria/events?
  Reply With Quote
01-12-12, 01:21 AM   #3
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Phanx View Post
XML is not the best way to make this addon, or any addon. The only reason you should ever use XML is if you need to create secure frame templates for other addons to inherit from.

I haven't ever played SC2, so I'm not really sure what the UI you're trying to recreate looks like. Also, if it's simply a feed of recent Battle.net broadcasts, what needs to be sortable? Is the user sorting it manually, or is the addon sorting it based on some criteria/events?
Not really going for looks, just the general premise. Sortable based on how recent.

Screeny:


I have the frame already created (see the "CreateFeed" function), just creating buttons (to click whisper) or a scrollframe that's sortable is kinda what I need.
  Reply With Quote
01-12-12, 01:34 AM   #4
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Ahh, I built a similar module several months ago (that never got completed due to me quitting WoW). I modified TabletLib to do the GUI for it. A very versatile little library, but unfortunately out of date at this point and does need some repair




Ah-hah! I found it. I did a different project using a similar library (though nowhere near as powerful, it's much easier to use) called lib-ScrollingTable. It's quite a versatile library and allows sorting of columns, scroll-bars, highlighting rows, etc.

(Picture from it's WoWAce page)

Last edited by Nibelheim : 01-12-12 at 01:50 AM.
  Reply With Quote
01-12-12, 01:51 AM   #5
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Nibelheim View Post
Ahh, I built a similar module several months ago (that never got completed due to me quitting WoW). I modified TabletLib to do the GUI for it. A very versatile little library, but unfortunately out of date at this point and does need some repair
I hope I can keep your nibSpac updated . I'm sad you've left WoW but it's always feeling like it's reaching its last breath with every patch.



I was actually thinking of taking ideas from the guild news tab, but it seemed pretty impractical to implement when just a few buttons with parented sorting would be enough.

Last edited by suicidalkatt : 01-12-12 at 02:01 AM. Reason: I know how to spell every, I swear.
  Reply With Quote
01-12-12, 01:54 AM   #6
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Originally Posted by suicidalkatt View Post
but it seemed pretty impractical to implement when just a few buttons with parented sorting would be enough.
True enough. If the project is going to remain fairly simple, it may be wise to start from scratch in Lua. Start with making a box, then borders, then a Scrolling Table, then frames for pictures etc. With your skills it shouldn't take too long at all to get it up and running
  Reply With Quote
01-12-12, 11:14 PM   #7
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Ok so, I've never used the sort() function and I'm not exactly sure where to go.

Basically what I'd like to do is have 2 separate tables with one that's simply the presenceID of bnet friends listed in order of the most recent timestamp.

I think I need a third table to accomplish this since I'm trying to sort information that's already a tabled value.

lua Code:
  1. MessageList = {
  2.     [412] = {
  3.         message = "Broadcast X",
  4.         timestamp = 1524321,
  5.     },
  6.     [523] = {
  7.         message = "Broadcast Y",
  8.         timestamp = 1624321,
  9.     },
  10. }
  11.  
  12. -- End Product
  13.  
  14. FeedInfo = {523,412} -- Sorted table of presenceID based on timestamp a>b not pressenceID a>b

What I've basically gotten to:
lua Code:
  1. for c,v in pairs(MessageList) do
  2.     if MessageList[c].timestamp and MessageList[c].timestamp > 0 then
  3.         --Create table with a timestamp index and presenceID value
  4.     end
  5. end
  6. --sort new table and insert to FeedInfo table?

Last edited by suicidalkatt : 01-12-12 at 11:43 PM. Reason: Fixed some wording
  Reply With Quote
01-12-12, 11:37 PM   #8
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Keep in mind that even if you sort a table, the "for k,v in pairs() do end" part won't go trough it sorted.

Meanwhile if you use sort() then "for i = 1, #tbl do ... = tbl[i] end" to iterate, that will work.

You can use sort like this:
sort(tbl sortFunc)
Then you got:
local function sortFunc(a, b)
return a > b
end
If a and b are tables, not integers or strings then you can:
return a[1] > b[1]
Or for example:
return a.test > b.test
The options are endless.

The only important thing is to be able to iterate without the using "pairs", try maybe "ipairs" would fix this issue. One of the pro LUA coders will probably reply what ipairs does and clarify this once and for all! :P
  Reply With Quote
01-12-12, 11:43 PM   #9
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Eh typo, didn't mean for the sort to occur for every pair. The table sorting would have been done outside of that first table creation. (edits post)
  Reply With Quote
01-13-12, 12:35 PM   #10
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
Originally Posted by Vladinator View Post
One of the pro LUA coders will probably reply what ipairs does and clarify this once and for all! :P
ipairs(table) does exactly the same process as for i=1,#table do when iterating through the table. Both ipairs() and #table follow the same rule in which they only count sequential indices starting at 1.



Originally Posted by suicidalkatt View Post
Basically what I'd like to do is have 2 separate tables with one that's simply the presenceID of bnet friends listed in order of the most recent timestamp.

I think I need a third table to accomplish this since I'm trying to sort information that's already a tabled value.
Here's what you can do.
lua Code:
  1. local MessageList={
  2.     [412]={
  3.         message="Broadcast X",
  4.         timestamp=1524321,
  5.     },
  6.     [523]={
  7.         message="Broadcast Y",
  8.         timestamp=1624321,
  9.     },
  10. }
  11. local FeedInfo={};
  12.  
  13. -- Put this function somewhere in the base of your addon, it's better to have a constant pointer to this than to recreate it every time you run the sort.
  14. local function FeedCompare(v1,v2)
  15. --  Ensures the most recent message is listed first
  16.     return MessageList[v1].timestamp>MessageList[v2].timestamp;
  17. end
  18.  
  19. local function SortMessages()
  20. --  Clear FeedInfo and repopulate it
  21.     table.wipe(FeedInfo);
  22.     for c,v in pairs(MessageList) do
  23.         if MessageList[c].timestamp and MessageList[c].timestamp > 0 then
  24.             FeedInfo[]=c;
  25.         end
  26.     end
  27.  
  28. --  Sort it
  29.     table.sort(FeedInfo,FeedCompare);
  30. end
For table.sort() to work with a custom compare function, sortcomp(v1,v2) and sortcomp(v2,v1) cannot evaluate to true. If both values are equal, the function must return false. If sortcomp(v1,v2) returns true, values are preserved, otherwise if false, values are swapped in the order that v1 comes before v2 in the table.
__________________
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
01-13-12, 04:37 PM   #11
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by SDPhantom View Post
For table.sort() to work with a custom compare function, sortcomp(v1,v2) and sortcomp(v2,v1) cannot evaluate to true. If both values are equal, the function must return false. If sortcomp(v1,v2) returns true, values are preserved, otherwise if false, values are swapped in the order that v1 comes before v2 in the table.
Is 'FeedInfo[]=c;' on line 24 there missing something?
  Reply With Quote
01-13-12, 10:04 PM   #12
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
Originally Posted by suicidalkatt View Post
Is 'FeedInfo[]=c;' on line 24 there missing something?
Using a blank key '[]' tells Lua to push the value at the end of the table. It's practically the same as calling table.insert(FeedInfo,c).
__________________
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
01-14-12, 06:46 PM   #13
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by SDPhantom View Post
Using a blank key '[]' tells Lua to push the value at the end of the table. It's practically the same as calling table.insert(FeedInfo,c).
It was returning an error thanks for the clarification.
  Reply With Quote
01-15-12, 12:18 AM   #14
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
Strange... I guess I was thinking of another language, I thought it worked in Lua too.... go ahead and change that line to the following.
Code:
FeedInfo[#FeedInfo+1]=c
... or the table.insert() method I posted earlier.
__________________
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
01-15-12, 01:34 AM   #15
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by SDPhantom View Post
Strange... I guess I was thinking of another language, I thought it worked in Lua too.... go ahead and change that line to the following.
Code:
FeedInfo[#FeedInfo+1]=c
... or the table.insert() method I posted earlier.
Yea I ended up just using tinsert(FeedInfo,c).

Thanks everyone for your help! AddOn is functional just polishing now
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Battle.net broadcast feed.


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