Thread Tools Display Modes
11/02/15, 03:21 PM   #1
CaptainBlagbird
 
CaptainBlagbird's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 53
Possible to create notification?

Is it possible to create a chat window notification (speech bubble symbol near number of online friends)?

AFAIK there are 3 options to notify the user about something:
  • System message in chat
  • Custom UI element
  • Sound
It's not possible to send a mail to self (probably so ppl can't temp-store items when their inventory is full), but would be useful for longer add-on notifications without having to create a custom UI.

But maybe it is possible to create a notification? If so, how? If not, would it be possible to "fake" it (something like this: playing sound + changing the variable that stores the number of notifications + adding element to the table with the pending notifications)?
  Reply With Quote
11/02/15, 03:59 PM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
It is possible to add your own notifications provider in order to fake a notification.

I have played around with it a bit in the past, and managed to make a notification with accept and decline button.
The gist of it is that you need to subclass ZO_NotificationProvider and overwrite all the necessary methods.
I am not sure if this code still works, but maybe you can use it as a starting point:
Lua Code:
  1. local MyNotificationProvider = ZO_NotificationProvider:Subclass()
  2. function MyNotificationProvider:New(notificationManager)
  3.     local provider = ZO_NotificationProvider.New(self, notificationManager)
  4.     provider.nextId = 1
  5.     return provider
  6. end
  7.  
  8. function MyNotificationProvider:GetNextId()
  9.     local id = self.nextId
  10.     self.nextId = id + 1
  11.     return id
  12. end
  13.  
  14. function MyNotificationProvider:AddNotification(data)
  15.     if(data.id == nil) then
  16.         local list = self.list
  17.         data.id = self:GetNextId()
  18.         list[data.id] = data
  19.     else
  20.         d("Cannot add a notification with an existing id.")
  21.     end
  22. end
  23.  
  24. function MyNotificationProvider:RemoveNotification(id)
  25.     self.list[id] = nil
  26. end
  27.  
  28. function MyNotificationProvider:Accept(data)
  29.     self:RemoveNotification(data.id)
  30. end
  31.  
  32. function MyNotificationProvider:Decline(data)
  33.     self:RemoveNotification(data.id)
  34. end
  35.  
  36. local myProvider = MyNotificationProvider:New(NOTIFICATIONS)
  37. table.insert(NOTIFICATIONS.providers, myProvider)
  38.  
  39. myProvider:AddNotification( {
  40.     "Hello World!"
  41.     })
  Reply With Quote
11/03/15, 02:16 PM   #3
CaptainBlagbird
 
CaptainBlagbird's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 53
Thanks, this helped a lot!

Your example doesn't work anymore though. I managed to get this minimalistic example to work so far (only one notification handled etc.):

Lua Code:
  1. local MyNotificationProvider = ZO_NotificationProvider:Subclass()
  2. function MyNotificationProvider:New(notificationManager)
  3.     return ZO_NotificationProvider.New(self, notificationManager)
  4. end
  5.  
  6. function MyNotificationProvider:RemoveNotification()
  7.     ZO_ClearNumericallyIndexedTable(self.list)
  8.     self:PushUpdateToNotificationManager()
  9. end
  10.  
  11. function MyNotificationProvider:AddNotification(data)
  12.     self.list[1] = data
  13.     self:PushUpdateToNotificationManager()
  14.  
  15.     if data.notificationType == nil then
  16.         ZO_NotificationsList1Row1Icon:SetTexture("EsoUI/Art/MainMenu/menuBar_notifications_down.dds")
  17.         ZO_NotificationsList1Row1Type:SetText("Notification")
  18.     end
  19. end
  20.  
  21. function MyNotificationProvider:Accept()
  22.     self:RemoveNotification()
  23.     d("Accepted")
  24. end
  25.  
  26. function MyNotificationProvider:Decline()
  27.     self:RemoveNotification()
  28.     d("Declined")
  29. end
  30.  
  31. myProvider = MyNotificationProvider:New(NOTIFICATIONS)
  32. table.insert(NOTIFICATIONS.providers, myProvider)
  33.  
  34.  
  35. -- Later, e.g. with /script
  36. myProvider:AddNotification({
  37.             notificationType = NOTIFICATION_TYPE_TRADE, -- Icon & title
  38.             dataType = NOTIFICATIONS_REQUEST_DATA,      -- Buttons / waiting symbol / note symbol
  39.             note = "note",                              -- Note on hover over note symbol
  40.             message = "message",                        -- Main message
  41.             -- controlsOwnSounds = true,                -- true: No sound
  42.         })

Last edited by CaptainBlagbird : 11/03/15 at 03:25 PM.
  Reply With Quote
11/03/15, 08:24 PM   #4
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Here you go, try this. I didn't test it very much, but it seemed to work fine. If you run into any problems let me know & I'll fix it.

LibNotifications

And P.S. there is also ZO_Alert() to display alert messages in the upper right hand corner:
Lua Code:
  1. ZO_Alert(UI_ALERT_CATEGORY_ERROR, SOUNDS.NEGATIVE_CLICK, "some message")
  Reply With Quote
11/04/15, 01:32 AM   #5
CaptainBlagbird
 
CaptainBlagbird's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 53
Awesome thanks!

That's what I wanted to do eventually (after having a stable example and learning how to create a library )
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » Possible to create notification?


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