|
| 1 | +init python: |
| 2 | + class NotifyEx(renpy.python.RevertableObject): |
| 3 | + """Notifications, to use: default ... = NotifyEx(msg="...", img="...")""" |
| 4 | + def __init__(self, |
| 5 | + msg: str, |
| 6 | + img: str |
| 7 | + ): |
| 8 | + super(NotifyEx, self).__init__() |
| 9 | + self.msg = msg |
| 10 | + self.img = img |
| 11 | + self.remain = gui.notifyEx_delay |
| 12 | + |
| 13 | + |
| 14 | + def notifyEx(msg: str = None, img: str = None): |
| 15 | + notifications.append(NotifyEx(msg, img)) |
| 16 | + if len(store.notifications) == 1: |
| 17 | + renpy.show_screen("notifyEx") |
| 18 | + |
| 19 | + |
| 20 | + def notifyExClean(value): |
| 21 | + if value in store.notifications: |
| 22 | + store.notifications.remove(value) |
| 23 | + if len(store.notifications) == 0: |
| 24 | + renpy.hide_screen("notifyEx") |
| 25 | + |
| 26 | + |
| 27 | + def notify(notific): |
| 28 | + """View defined notifications. |
| 29 | + to use: $ notify(...)""" |
| 30 | + notifications.append(NotifyEx(notific.msg, notific.img)) |
| 31 | + if len(store.notifications) == 1: |
| 32 | + renpy.show_screen("notifyEx") |
| 33 | + |
| 34 | +# Delay of visibility of a notification. |
| 35 | +define gui.notifyEx_delay = 10.0 |
| 36 | +# Width of the images. |
| 37 | +define gui.notifyEx_width = 64 |
| 38 | +# Height of the images. |
| 39 | +define gui.notifyEx_height = 64 |
| 40 | + |
| 41 | +define gui.notifyEx_color = "#000000" |
| 42 | + |
| 43 | +default notifications = [] |
| 44 | + |
| 45 | +style notify_text is default: |
| 46 | + color gui.notifyEx_color |
| 47 | + yalign 0.5 |
| 48 | + |
| 49 | +style notify_hbox is default: |
| 50 | + ysize gui.notifyEx_height |
| 51 | + |
| 52 | +screen notifyEx(): |
| 53 | + |
| 54 | + zorder 100 |
| 55 | + |
| 56 | + style_prefix "notify" |
| 57 | + |
| 58 | + vbox: |
| 59 | + for d in notifications: |
| 60 | + use notifyExInternal( d ) |
| 61 | + # aerate a little. |
| 62 | + null height 5 |
| 63 | + |
| 64 | +screen notifyExInternal( n ): |
| 65 | + |
| 66 | + style_prefix "notify" |
| 67 | + |
| 68 | + frame at notify_appear: |
| 69 | + hbox: |
| 70 | + if not n.img is None: |
| 71 | + add n.img |
| 72 | + else: |
| 73 | + # Ensure that all the texts will be aligned. |
| 74 | + null width gui.notifyEx_width |
| 75 | + |
| 76 | + # aerate a little. |
| 77 | + null width 5 |
| 78 | + |
| 79 | + if not n.msg is None: |
| 80 | + text n.msg |
| 81 | + |
| 82 | + timer 0.05 repeat True action [ SetField( n, "remain", n.remain - 0.05 ), If( n.remain <= 0, Function( notifyExClean, n ), NullAction() ) ] |
0 commit comments