Skip to content

Commit 5afaf2d

Browse files
authored
Merge pull request techwithtim#6 from DRincs-Productions/2-renpy-notifications
2 renpy notifications
2 parents 961cff2 + 0c41b8f commit 5afaf2d

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This template includes VSCode launchs and extensions for developing Ren'Py proje
2222
- `.gitignore`: Git configuration file for ignoring certain file paths and types.
2323
- `/game/tool/utility.rpy`: Useful functions such as: isNullOrEmpty
2424
- `/game/tool/flags.rpy`: Flags System
25+
- `/game/tool/notify.rpy`: Notify System
2526

2627
## How Run Debug (F5)
2728

game/tool/notify.rpy

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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

Comments
 (0)