NotificationBar

Base type for creating a notification bar to show incoming VPlayMultiplayer push notifications in-game. More...

Import Statement: import VPlay 2.0
Inherits:

Item

Signals

  • display(string message, var additionalData, bool isActive)

Detailed Description

NotificationBar is the base type for creating a notification bar to show VPlayMultiplayer push notifications.

When a push notification arrives, the VPlayMultiplayer item automatically displays a default notification bar to show the message if the chat view is not opened. After a few seconds, the notification will disappear automatically. Clicking the notification opens the chat view.

Alternatively, you may specify a custom NotificationBar item to replace the default navigation bar and handle notifications on your own.

Note: The notification bar is only displayed if VPlayMultiplayer::handleNotificationInternal is activated, which is the default setting. The VPlayMultiplayer::notificationReceived() signal is emitted in every case, so it is possible to still react to notifications on your own.

Set your own NotificationBar implementation for VPlayMultiplayer::notificationBar to replace the default notification bar. Whenever VPlayMultiplayer forwards an incoming notification to be displayed by the NotificationBar, the NotificationBar::display signal is emitted.

Signal Documentation

display(string message, var additionalData, bool isActive)

Whenever VPlayMultiplayer forwards an incoming notification to be displayed by the NotificationBar, this signal is emitted.

The following example uses the signal to disable the default notification bar for chat messages and opens the chat view instead. For friend requests and game invites the notification bar will still be shown.

 VPlayMultiplayer {
   id: multiplayer

   // ...

   // use signal handler to hide notification bar for text messages and jump to chat instead
   Connections {
     target: multiplayer.notificationBar || null
     onDisplay: {
       if(additionalData.type === "text") {
         multiplayer.notificationBar.visible = false
         multiplayer.showChat(additionalData.sender, additionalData.sender_name)
       }
     }
   }
 }

To set a completely custom notification bar instead of the default one, specify your own implementation as the VPlayMultiplayer::notificationBar. Then implement the signal in your custom notification bar to show incoming notifications in the way you want.

The following example shows notifications in a native alert dialog instead of a notification bar (the actual NotificationBar item is never visible in this case):

 GameWindow {
   // ...

   VPlayMultiplayer {
     // ...
     notificationBar: myNotificationBar
   }

   NotificationBar {
     id: myNotificationBar
     onDisplay: {
       nativeUtils.displayMessageBox(additionalData.title, message, 1)
     }
   }
 }

Note: If the multiplayer chat view is opened and can display a notification directly, this signal is not fired. The notification can be consumed and visualized directly in that case. To react on all notifications regardless of the opened view or other VPlayMultiplayer settings, use the VPlayMultiplayer::notificationReceived signal instead.


Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support