找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 620|回复: 2

[教程] 密码锁教程++

[复制链接]
发表于 2024-6-23 01:48:48 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 blackpineapple 于 2024-6-23 04:51 编辑

受烈林凤的帖子启发


https://www.renpy.cn/forum.php?m ... 545&_dsign=96b5403a

使用条件:
1)使用需要署名:黑凤梨black_pineapple
2)可以用在商用或者非商用的项目
3)可以修改后使用
4)如果你还可以继续优化代码,可以再优化了发出来给大家学习。继承本使用条件。

Screenshot 2024-06-22 at 8.49.27 AM.png


后端代码是
[RenPy] 纯文本查看 复制代码
init -99 python:
    class NumericLock:
        def __init__(self):
            self.current_input = ""

            self.password = None

        def set_password(self, value):
            if not value.isnumeric():
                raise Exception('密码锁的密码必须全是数字。')

            self.password = value

        def append(self, value):
            self.current_input += str(value)

        def pop(self):
            self.current_input = self.current_input[:-1]

        def clear(self):
            self.current_input = ""

        def accept_new_input(self):
            return len(self.current_input) < len(self.password)

        def is_input_length_match(self):
            return len(self.current_input) == len(self.password)

        def is_input_match(self):
            return self.current_input == self.password

        def get_error_msg_length(self):
            return "密码有%d位数,请保证输入的位数正确。" % len(self.password)





界面代码是
[RenPy] 纯文本查看 复制代码
screen numeric_lock:
    style_prefix "numeric"
    
    default error_msg_length = numeric_lock_obj.get_error_msg_length()

    frame:
        background Solid("#fff")
        xysize (190, 85)
        xalign 0
        ypos 300

        has vbox
        text _("密码"):
            color "#000"
        text numeric_lock_obj.password:
            color "#000"
    
    frame:
        background Solid("#00f4")
        align (0.5, 0.5)

        frame:
            background Solid("#fff")
            xysize (190, 85)
            xalign 0.5
            ypos 100

            text numeric_lock_obj.current_input:
                color "#000"
        
        frame:
            background Solid("#fff")
            xalign 0.5
            ypos 220

            has vbox
            spacing 10

            grid 3 3:
                xalign 0.5
                spacing 10
                for i in range(1, 10):
                    use numeric_lock_button(i)

            use numeric_lock_button(0)

        hbox:
            xalign 0.5
            ypos 800
            spacing 20

            button:
                background Solid("#9dc974")
                hover_background Solid("#c7e3ae")
                xysize (180, 120)

                text _("确定"):
                    color "#000"

                keysym 'K_RETURN'

                if not numeric_lock_obj.is_input_length_match():
                    action Notify(error_msg_length)
                elif numeric_lock_obj.is_input_match():
                    action Notify("密码正确")
                else:
                    action Notify("密码错误")


            button:
                background Solid("#c97471")
                hover_background Solid("#d5b2b1")
                xysize (180, 120)

                text _("清除"):
                    color "#000"

                keysym 'K_CLEAR'

                action Function(numeric_lock_obj.clear)

            button:
                background Solid("#7492c8")
                hover_background Solid("#b1bed6")
                xysize (180, 120)

                text _("后退"):
                    color "#000"

                keysym 'K_DELETE'

                action Function(numeric_lock_obj.pop)


screen numeric_lock_button(i):
    default error_msg_length = numeric_lock_obj.get_error_msg_length()

    button:
        style "numeric_button"

        text "[i]":
            color "#000"

        keysym 'K_%d' % i

        if numeric_lock_obj.accept_new_input():
            action Function(numeric_lock_obj.append, value=i)
        else:
            action Notify(error_msg_length)


style numeric_text:
    align (0.5, 0.5)
    color "#000"

style numeric_button:
    background Solid("#7492c8")
    hover_background Solid("#b1bed6")
    xalign 0.5

    xysize (120, 120)







评分

参与人数 1干货 +3 收起 理由
烈林凤 + 3 感谢分享!

查看全部评分

 楼主| 发表于 2024-6-23 01:50:42 | 显示全部楼层
使用的部分是
[RenPy] 纯文本查看 复制代码
label start:
    python:
        quick_menu = False
        numeric_lock_obj.set_password("123456")
    jump numeric_lock

    return


[RenPy] 纯文本查看 复制代码
label numeric_lock:
    call screen numeric_lock
    return
回复 支持 抱歉

使用道具 举报

发表于 2024-8-16 23:04:14 | 显示全部楼层
感谢分享
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-10-18 16:12 , Processed in 0.134914 second(s), 29 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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