Skip to content

Commit ec6a630

Browse files
💥 Change behavior of send_banner
1 parent ea4dbe4 commit ec6a630

File tree

8 files changed

+135
-13
lines changed

8 files changed

+135
-13
lines changed

‎CHANGELOG.changes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Adds new CHANGELOG file to builds.
1111
- Updates design language of notification banners in NotificationKit.
1212
- Updates ScreenKit to new Candella design language.
13+
- Changes behavior of CAApplication.send_banner to include automatic and manual modes.
1314

1415
[v21.02-refs/tags/21.02-beta1]
1516
- Initial beta release.

‎docs/03-candella-app.md‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,36 @@ Send an alert with respect to the user's settings.
179179

180180
- response (any): The response from the alert, if any. This response is also emitted as a signal.
181181

182-
### `CAApplication.send_banner(title, supporting, callback=Return('didClickRespond'))`
182+
### `CAApplication.send_banner(title, supporting, callback=Return('didClickRespond'))` {label:updated}
183183
Send a notification banner with respect to the user's settings.
184184

185+
The banner request can be used in one of two ways: automatic, which utilizes the CANotificationBanner class
186+
to create a notification banner, and manual, which uses keyword arguments at call time to generate a
187+
banner on the fly. In most cases, it is recommended to use the automatic mode since the
188+
CANotificationBanner class offers more granular control over the appearance of the banner such as the
189+
action button text.
190+
185191
**Arguments**
186192

187-
- title (str): The title of the banner.
188-
- supporting (str): The supporting text for the banner.
189-
- callback (callable): The response callback function to run when clicking the 'Respond' button.
193+
- mode (str): The means of sending the request. 'automatic' utilizes the [`CANotificationBanner`](./11-notifications.md#creating-modular-banners-labelnew) class to
194+
create a banner, and 'manual' uses to the old style. By default, this method uses manual mode to
195+
ensure backwards-compatibility with AliceOS and older Candella versions.
196+
197+
**Keyword Arguments**
198+
199+
- banner (CANotificationBanner): The banner object to send through this app. Required in automatic
200+
mode.
201+
- title (str): The title of the banner. Required in manual mode.
202+
- supporting (str): The supporting text for the banner. Required in manual mode.
203+
- callback (callable): The response callback function to run when clicking the 'Respond' button. Required
204+
in manual mode.
190205

191206
**Returns**
192207

193-
- response (any): The response from the banner request, if any. This response is also emitted as a signal.
208+
- response (any): The response from the banner request, if any.
194209

210+
!!! warning "Add keyword arguments"
211+
For Candella apps that use the manual mode or have supplied the contents of the banner as arguments, make sure that these are changed to keyword arguments, appropriately.
195212
## Sending app signals
196213

197214
Apps can send information to other services and even other apps. Candella apps adopt the Observable framework, which allows for signal emission.

‎docs/11-notifications.md‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# NotificationKit Changes
2+
3+
Candella includes a few improvements to the NotificationKit framework that adds more functionality and modularity to creating notifications with AppKit and NotificationKit screens.
4+
5+
## Notification banner design
6+
7+
Banners in Candella have been moved to the right side of the screen and take up less screen space. They take on the light theme present in the rest of Candella via ScreenKit and use the same fonts. Banners have been positioned so they sit just underneath the top bar in Celeste Shell but also look great in-game.
8+
9+
![Banners in Candella](./images/design/banner.png)
10+
11+
## Creating modular banners {label:new}
12+
13+
Notification banners can be generated automatically using the `CANotificationBanner` class, rather than at call time when invoking `CANotification.send_banner`. This class offers more control over the appearance of the banner and is typically easier to use than the manual mode in previous releases.
14+
15+
To create a banner using `CANotificationBanner`, create an instance of the object with specified details:
16+
17+
```py
18+
banner = CANotificationBanner(
19+
"Message not sent.", "The message could not be delivered to the recipient.")
20+
```
21+
22+
There are three arguments that must be supplied when creating a new banner:
23+
24+
- message (str): The primary message of the banner.
25+
- details (str): Supporting text for the banner. This could further explain the main message, or provide additional context.
26+
- callback (any): The callback to execute when clicking on the action button. Defaults to `Return('didClickRespond')`.
27+
28+
To invoke this banner in a banner request, pass it as a keyword argument in [`CAApplication.send_banner`](./03-candella-app.md#caapplicationsend_bannertitle-supporting-callbackreturndidclickrespond-labelupdated) and set the mode to `automatic`:
29+
30+
```py
31+
response = CANotification.send_banner(mode='automatic', banner=banner)
32+
```
33+
34+
### Customizing banners
35+
36+
The following attributes are present in `CANotificationBanner` to let developers customize banners:
37+
38+
| Attribute | Type | What it does |
39+
| :-------- | :--- | ------------ |
40+
| message | `str` | The primary message of the banner. |
41+
| details | `str` | The supporting text for the banner. Generally, this explains the primary message or adds additional context. |
42+
| callback | `callable` | A Ren'Py callback function to execute when clicking the action button on the banner. Defaults to `Return('didClickRespond')`. |
43+
| callback_text | `str` | The text for the action button. Defaults to `"Respond"`. |
4.34 MB
Loading

‎game/System/Applications/Messages.aosapp/Messages.rpy‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ init 5 python:
1818
return True
1919

2020
def applicationWillLaunch(self):
21-
self.send_banner(
21+
banner = CANotificationBanner(
2222
"Messages app functionality not implemented.",
2323
"You will still be able to receive message notifications from characters in-game."
2424
)
25+
banner.callback_text = "Dismiss"
26+
self.send_banner("automatic", banner=banner)
2527

2628
messages = ASMessages()

‎game/System/Frameworks/AppKit.aosframework/CAApplication.rpy‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,40 @@ init python:
175175
self.application_did_terminate()
176176
self.emit_signal("application_terminated")
177177

178-
def send_banner(self, title, supporting, callback=Return('didClickRespond')):
178+
def send_banner(self, mode='manual', **kwargs):
179179
"""Send a notification banner with respect to the user's settings.
180180
181+
The banner request can be used in one of two ways: automatic, which utilizes the CANotificationBanner class
182+
to create a notification banner, and manual, which uses keyword arguments at call time to generate a
183+
banner on the fly. In most cases, it is recommended to use the automatic mode since the
184+
CANotificationBanner class offers more granular control over the appearance of the banner such as the
185+
action button text.
186+
181187
Arguments:
182-
title (str): The title of the banner.
183-
supporting (str): The supporting text for the banner.
184-
callback (callable): The response callback function to run when clicking the 'Respond' button.
188+
mode (str): The means of sending the request. 'automatic' utilizes the CANotificationBanner class to
189+
create a banner, and 'manual' uses to the old style. By default, this method uses manual mode to
190+
ensure backwards-compatibility with AliceOS and older Candella versions.
191+
192+
Keyword Arguments:
193+
banner (CANotificationBanner): The banner object to send through this app. Required in automatic
194+
mode.
195+
title (str): The title of the banner. Required in manual mode.
196+
supporting (str): The supporting text for the banner. Required in manual mode.
197+
callback (callable): The response callback function to run when clicking the 'Respond' button. Required
198+
in manual mode.
185199
186200
Returns:
187201
response (any): The response from the banner request, if any.
188202
"""
189-
response = self.application_will_request_notification(title, supporting, response_callback=callback)
203+
204+
if mode not in ["automatic", "manual"]:
205+
raise TypeError("mode must be 'automatic' or 'manual, but received %s" % (mode))
206+
207+
if mode == "automatic" and self.application_should_request_notification():
208+
response = kwargs['banner']._send(self)
209+
else:
210+
response = self.application_will_request_notification(
211+
kwargs["title"], kwargs["supporting"], response_callback=kwargs["callback"])
190212
self.application_did_request_notification()
191213
self.emit_signal("banner_sent", response=response)
192214
return response

‎game/System/Frameworks/NotificationKit.aosframework/ASNotificationBanner.rpy‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Copyright © 2019 ProjectAliceDev. All rights reserved.
77
#
88

9-
init screen ASNotificationBanner(applet=None, message, withDetails, responseCallback=Return('didClickRespond')):
9+
init screen ASNotificationBanner(applet=None, message, withDetails, r_text="Respond", responseCallback=Return('didClickRespond')):
1010
tag ASNotificationBanner
1111
zorder 100
1212
style_prefix "ASNotificationBanner"
@@ -35,7 +35,7 @@ init screen ASNotificationBanner(applet=None, message, withDetails, responseCall
3535
add _app_icon
3636
text "[_app_name]":
3737
style "ASNotificationBannerSource"
38-
textbutton _("Respond") action [Hide("ASNotificationBanner"), responseCallback]:
38+
textbutton _("[r_text]") action [Hide("ASNotificationBanner"), responseCallback]:
3939
style "ASNotificationBannerButton"
4040
xalign 1.0
4141

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# CSNotificationBanner.rpy
3+
# Candella
4+
#
5+
# Created by Marquis Kurt on 03/08/21.
6+
# Copyright © 2021 Marquis Kurt. All rights reserved.
7+
#
8+
# This Source Code Form is subject to the terms of the Mozilla Public
9+
# License, v. 2.0. If a copy of the MPL was not distributed with this
10+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
11+
#
12+
13+
init offset = -10
14+
15+
init python:
16+
class CANotificationBanner():
17+
def __init__(self, message, details, callback=Return('didClickRespond')):
18+
self.message = message
19+
self.details = details
20+
self.callback = callback
21+
self.callback_text = "Respond"
22+
23+
24+
def __str__(self):
25+
return "CANotificationBanner(%s, %s, callback='%s')" % (self.message, self.details, self.callback_text)
26+
27+
28+
def _send(self, reference=None):
29+
return renpy.invoke_in_new_context(
30+
renpy.call_screen,
31+
"ASNotificationBanner",
32+
applet=reference,
33+
message=self.message,
34+
withDetails=self.details,
35+
r_text=self.callback_text,
36+
responseCallback=self.callback
37+
)

0 commit comments

Comments
 (0)