-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In-game settings menu using separate Lua env #15614
Conversation
7ccfcc6
to
c47edfb
Compare
I'm thinking about porting #15152 to Lua as a followup for this PR. Then we will be able to embed the entire keybinding form into the settings form. |
it's a good idea, but if i'm correct some settings won't apply when game is launched. I don't think we have notice for those specific cached settings |
See #6722 (comment) linked above, specifically this section:
|
bf9662a
to
b9297ed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. 👍
Tested, works nicely!
The fps unfocused should probably only be used if the window is actually unfocused.
Nitpick: Should the back button be a close button, because it closes the pause menu completely?
Other parts of the pause menu do use formspec prepend. Disabling it for now because of security risks is reasonable, but we should at some point think about filtering it or something.
Speaking of which, the main pause menu (or how should I call it? x)) still has formspec prepend. This might be dangerous.
Indeed. See also #13780. While this is a trivial change from a technical perspective, I don't want to make it in this PR because I imagine it may result in additional discussion later.
Changing the button label to something like "Exit" would make sense.
"Other parts"? Only the main pause menu formspec, other sub-menus are implemented in raw Irrlicht GUI.
If (the current implementation of) formspec prepend was allowed on the settings formspec, you could probably use it to completely replace the formspec (container, syntax error) and add a button and some hidden fields. Then if the user clicks the button, the settings menu will handle the input, allowing you to set arbitrary settings.
The main pause menu input handler isn't as powerful as the settings menu input handler, I don't see how. You could prevent the user from exiting the game or something (Alt+F4 still exists), but otherwise ...? |
Oh right, it's only the main pause menu.
It could show a fake main menu and grab passwords, see also #12067. But yes, right now it's not a big issue. |
note: this means async mainmenu env no longer get the privilege
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! <3
(Funnily, the "Exit" button is still translated to "Zurück" in our german translation.)
Closes #6722
With this PR, users can access the settings menu via the pause menu, making it possible to change settings in-game.
settings.in-game.mp4
I've outlined this PR's approach in #6722 (comment)
This PR is, from a technical perspective, unrelated to rollerozxa's POC or PR #14785. These patches (ab)use the CSM API, this PR does it the proper way by introducing a separate Lua environment (see comment linked above for reasoning).
High level overview of scripting changes
New
PauseMenuScripting
owned byGameFormSpec
(thanks for the nice refactor, cx384)cpp_api
:ScriptApiPauseMenu
: functions exclusive toPauseMenuScripting
ScriptApiClientCommon
: functions shared betweenClientScripting
andPauseMenuScripting
(code moved fromScriptApiClient
)lua_api
:ModApiPauseMenu
: functions exclusive toPauseMenuScripting
ModApiClientCommon
: functions shared betweenClientScripting
andPauseMenuScripting
(code moved fromModApiClient
)ModApiMenuCommon
: functions shared betweenMainMenuScripting
andPauseMenuScripting
(code moved fromModApiMainMenu
)To do
This PR is a Ready for Review. When reviewing, please pay special attention to the security stuff.
Things this PR will not do, as described in #6722 (comment):
registerChangedCallback
)settingtypes.txt
, don't show server-side settings if playing on a remote serversettingtypes.txt
These are big tasks on their own and are left for future PRs to keep the scope of this one reasonable.
How to test
Open the pause menu, click "Settings" and enjoy :)
Additional testing:
.help
command)