找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 4680|回复: 1

[原创] [black Pineapple代码分享] 邮件系统

[复制链接]
发表于 2019-12-1 04:05:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 blackpineapple 于 2022-5-12 02:30 编辑

Screen Shot 2019-11-30 at 11.30.05 AM.png

图片上传一直失败,大家自己弄了代码去试试效果吧。
代码禁止商用,转载/自制免费游戏可以直接用,需要著名作者:black pineapple
后端代码:
[RenPy] 纯文本查看 复制代码
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")),
    ]


前端代码
[RenPy] 纯文本查看 复制代码
# 查阅邮件
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')


发邮件代码
[RenPy] 纯文本查看 复制代码
label c1_0():
    python:
        email_system.add_new_email(
            Email("测试邮件", "这是一封测试邮件", '李白',
                datetime.datetime.strptime("10 07 2019", "%m %d %Y")),)
    return




 楼主| 发表于 2019-12-1 11:16:07 | 显示全部楼层
订正:
需要在init python 的后面加上
import datetime

需要增加ok_button 的screen
[RenPy] 纯文本查看 复制代码
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") ]
回复 支持 抱歉

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|RenPy中文空间 ( 苏ICP备17067825号|苏公网安备 32092302000068号 )

GMT+8, 2024-4-18 12:40 , Processed in 0.062462 second(s), 13 queries , File On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表