添加一个新的按键绑定,使你可以返回到上一个屏幕。
它通过 4 种方式来查找上一个屏幕。
首先,它会尝试查找屏幕上是否有任何按钮,在 en_us(英文)语言文件中,其标题包含以下任意一个词:back、return、done、cancel。如果找到仅包含这些词之一的按钮,则会点击该按钮。
如果失败,它会尝试检查屏幕类。某些屏幕会存储一个变量来记住之前所在的屏幕。例如从视频设置子屏幕返回到主设置屏幕。模组会尝试查找名称为以下任一的字段的变量:
previous, previousscreen, lastscreen, parent, parentscreen。这些变量名来源于我能找到的任何原版屏幕类。如果你有建议添加的字段名,欢迎提出。
如果仍然失败,它会尝试追溯父类。某些类会继承其他类,而被继承的类可能存储了指向上一个屏幕的变量。因此,它会以深度 7(随意设定的值)进行搜索,并采用上述字段技术进行查找。
如果以上所有方法都失败,它会尝试调用 close 方法,本质上等同于按下 Escape 键。
如果你出于某种原因想知道,作为模组开发者,如何确保此模组能够正常工作。那么只需简单地让按钮仅包含文本:back、return、done、cancel,或者将前一个屏幕的变量命名为 previous、lastscreen、previousscreen、parent、parentscreens。
Adds a new keybind that makes you go back to the previous screen.
It has 4 ways of finding the previous screen.
It first tries to find any buttons on screen that in the en_us language, has any of these words as its title: back, return, done, cancel. If it finds any button that only contain one of those words, then it will click that.
If that fails, it tries to check the screen class. Some screens store a variable to remember the previous screen it was on. Think going from the video settings subscreen back to the settings screen. The mod tries to find any field that is named the following:
previous, previousscreen, lastscreen, parent, parentscreen. These variable names are taken from any vanilla screen class I can find. If you have suggestions of ones to add then im all ears.
If that fails. It tries to go to the extending class. Some classes extend other classes and the class they extend may store a variable to the previous screen. So it tries to search with a depth of 7, arbitrarily chosen, and does the field technique described above.
If all of that fails, it tries calling the close method, basically just pressing escape.
If you are for some reason wondering, as a mod dev, on how to make sure this mod works. Then just simple have either a button that only has the text being: back, return, done, cancel. Or store a previous screen variable as previous, lastscreen, previousscreen, parent, parentscreen
评论 0
登录后参与评分
还没有评论,来抢沙发吧