Postal system

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Postal system

#1 Post by Andredron »

https://www.renpy.cn/thread-455-1-7.html

The code is prohibited for commercial use, re-release/self-made free games can be used directly, need a well-known author: black pineapple

Code: Select all


init 1 python:
    class EmailSystem(object):
        MAX_NUM_OF_EMAIL_ON_EACH_PAGE = 3
        def __init__(self):
            self._emails = []
            self._current_page = 0
            self._has_unread = False
 
        @property
        def has_unread(self):
            return self._has_unread
 
        def read_email(self):
            self._has_unread = False
 
        def has_next_page(self):
            return \
                (self._current_page + 1) * \
                EmailSystem.MAX_NUM_OF_EMAIL_ON_EACH_PAGE < len(self._emails)
 
        def next_page(self):
            self._current_page += 1
 
        def has_previous_page(self):
            return self._current_page != 0
 
        def previous_page(self):
            self._current_page -= 1
 
        def get_email_on_current_page(self):
            start = EmailSystem.MAX_NUM_OF_EMAIL_ON_EACH_PAGE * \
                self._current_page
            end = start + EmailSystem.MAX_NUM_OF_EMAIL_ON_EACH_PAGE
            return [x for x in self._emails[start : end]]
 
        def add_new_email(self, email):
            self._emails.insert(0, email)
            self._has_unread = True
 
        def get_email(self, num):
            index = self._current_page * \
                EmailSystem.MAX_NUM_OF_EMAIL_ON_EACH_PAGE + num
            return self._emails[index]
 
    class Email(object):
        def __init__(self, title, content, sender, date):
            self._title = title
            self._content = content
            self._sender = sender
            self._date = date
            self._read = False
 
        @property
        def title(self):
            return self._title
 
        @property
        def content(self):
            return self._content
 
        @property
        def date(self):
            return self._date
 
        @property
        def sender(self):
            return self._sender
 
        @property
        def read(self):
            return self._read
 
        def visited(self):
            self._read = True
 
        @staticmethod
        def title_hire():
            return '[工作] 关于合约'
 
        @staticmethod
        def title_gossip(title):
            return '[八卦新闻]' + title
 
        @staticmethod
        def content_fail_to_hire():
            return '关于合约我还想再考虑下,感谢您的机会。'
 
        @staticmethod
        def content_succeed_to_hire():
            return '谢谢您考虑我,我很荣幸加入贵公司'
 
    # test data
    email_system = EmailSystem()
    email_system._emails = [
        Email(Email.title_hire(), Email.content_succeed_to_hire(), '李白',
            datetime.datetime.strptime("10 07 2019", "%m %d %Y")),
        Email(Email.title_gossip('八卦新闻'), "这是一则八卦新闻", '八卦周刊',
            datetime.datetime.strptime("10 06 2019", "%m %d %Y")),
        Email(Email.title_gossip('八卦新闻'), "这是一则八卦新闻1", '明星八卦',
            datetime.datetime.strptime("10 05 2019", "%m %d %Y")),
        Email(Email.title_hire(), Email.content_succeed_to_hire(), '杜甫',
            datetime.datetime.strptime("10 04 2019", "%m %d %Y")),
        Email(Email.title_hire(), Email.content_succeed_to_hire(), '张三',
            datetime.datetime.strptime("10 03 2019", "%m %d %Y")),
        Email(Email.title_hire(), Email.content_succeed_to_hire(), '张言',
            datetime.datetime.strptime("10 02 2019", "%m %d %Y")),
        Email(Email.title_hire(), Email.content_succeed_to_hire(), '苏三',
            datetime.datetime.strptime("10 01 2019", "%m %d %Y")),
        Email(Email.title_hire(), Email.content_succeed_to_hire(), '姜韩',
            datetime.datetime.strptime("09 07 2019", "%m %d %Y")),
    ]

# 查阅邮件
screen email():
    zorder 1
    modal True
    style_prefix 'company'
    python:
 
        emails = email_system.get_email_on_current_page()
 
    fixed:
        add "gui/company/bg.png"
        hbox:
            xalign .3
            yalign .3
            spacing 30
 
            if email_system.has_previous_page():
                textbutton '上一页' action Function(email_system.previous_page)
            if email_system.has_next_page():
                textbutton '下一页' action Function(email_system.next_page)
        vbox:
            xalign .5
            yalign .5
            for i in range(len(emails)):
                hbox:
                    python:                         text_button_name = '[发件人:' + emails[i].sender + \
                            ']' + emails[i].title
                    if not emails[i].read:
                        $ text_button_name = '[未读]' + text_button_name
                    textbutton text_button_name:
                        action [Function(emails[i].visited),
                            Show('email_content', index=i)]
 
 
    # 加上翻页功能
    use ok_button('email', 'end_a_day', 1400, 900)
 
screen email_content(index):
    zorder 1
    modal True
 
    python:
        email = email_system.get_email(index)
 
    fixed:
        add "gui/company/bg.png"
        vbox:
            xalign .5
            yalign .5
            hbox:
                text \
                    '发送日期[email.date.year]年[email.date.month]月[email.date.day]日'
                null width 10
                text '发件人:[email.sender]'
            text '标题:' + email.title
            text '内容:\n[email.content]'
 
 
    textbutton '离开' action Hide('email_content')


label c1_0():
    python:
        email_system.add_new_email(
            Email("测试邮件", "这是一封测试邮件", '李白',
                datetime.datetime.strptime("10 07 2019", "%m %d %Y")),)
    return

need to add date and time of import
after python initialization and add screen ok_button

Code: Select all

screen ok_button(current_page, land_page, x, y):
    fixed:
        xpos x
        ypos y
        xysize 226, 112
        imagebutton:
            action [Hide(current_page), Jump(land_page)]
            idle "gui/planner/button_red_big_idle.png"
            hover "gui/planner/button_red_big_hover.png"
        text "确定":
            xalign .5
            yalign .5
            bold True
            color "#fff"
            size 40
            outlines [ (2, "#7593a7") ]

Post Reply

Who is online

Users browsing this forum: No registered users