Skip to content
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

Merged
merged 5 commits into from
Jan 19, 2025

Conversation

grorp
Copy link
Contributor

@grorp grorp commented Jan 1, 2025

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 by GameFormSpec (thanks for the nice refactor, cx384)

  • cpp_api:

    • New ScriptApiPauseMenu: functions exclusive to PauseMenuScripting
    • New ScriptApiClientCommon: functions shared between ClientScripting and PauseMenuScripting (code moved from ScriptApiClient)
  • lua_api:

    • New ModApiPauseMenu: functions exclusive to PauseMenuScripting
    • New ModApiClientCommon: functions shared between ClientScripting and PauseMenuScripting (code moved from ModApiClient)
    • New ModApiMenuCommon: functions shared between MainMenuScripting and PauseMenuScripting (code moved from ModApiMainMenu)

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):

  • Make more settings actually support in-game changes (registerChangedCallback)
  • Make it clear which settings are server-side and which are client-side in settingtypes.txt, don't show server-side settings if playing on a remote server
  • Make it clear which settings support in-game changes in settingtypes.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:

  1. Settings menu must still work in the mainmenu
  2. CSM must still work (you can try the .help command)

@grorp grorp added @ Startup / Config / Util Feature ✨ PRs that add or enhance a feature UI/UX labels Jan 1, 2025
@grorp grorp force-pushed the pause-menu-env branch 5 times, most recently from 7ccfcc6 to c47edfb Compare January 1, 2025 22:20
@grorp grorp marked this pull request as ready for review January 2, 2025 13:34
@grorp
Copy link
Contributor Author

grorp commented Jan 3, 2025

The button for changing key bindings being called "Controls" doesn't make much sense.

screenshot of the settings menu page in question

To change key bindings, you have to navigate to "Controls / Keyboard and Mouse" -> "Controls". Calling that button "Key bindings" or something would make more sense.

(This PR replaces the "Controls" entry in the pause menu with the "Settings" entry, since there's not enough space for both and the "Controls" entry is now redundant. It would be possible to replace the "Sound Volume" entry instead of the "Controls" entry if desired.)

@y5nw
Copy link
Contributor

y5nw commented Jan 3, 2025

To change key bindings, you have to navigate to "Controls / Keyboard and Mouse" -> "Controls". Calling that button "Key bindings" or something would make more sense.

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.

@nerzhul
Copy link
Contributor

nerzhul commented Jan 6, 2025

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

@grorp
Copy link
Contributor Author

grorp commented Jan 6, 2025

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:

[...]

Additional considerations

For an in-game settings menu to be really useful, we'll need to implement support for in-game changes for more settings.

  • Many settings already support in-game changes.
  • Many settings are missing callbacks for in-game change support. Some of these can be implemented easily, some are more complicated (e.g. shader settings would need shader recompilation).
  • Some settings are incompatible with in-game changes in general, we need a way to declare that in settingtypes.txt.
  • This should be done in later PRs to keep scope reasonable.

[...]

@sfan5 sfan5 self-requested a review January 6, 2025 11:53
builtin/common/register.lua Show resolved Hide resolved
builtin/common/settings/dlg_settings.lua Outdated Show resolved Hide resolved
src/client/game_formspec.cpp Outdated Show resolved Hide resolved
src/client/game_formspec.h Outdated Show resolved Hide resolved
src/script/cpp_api/s_base.cpp Outdated Show resolved Hide resolved
src/script/lua_api/l_client_common.cpp Outdated Show resolved Hide resolved
src/script/lua_api/l_menu_common.cpp Outdated Show resolved Hide resolved
src/script/scripting_pause_menu.cpp Outdated Show resolved Hide resolved
@grorp grorp force-pushed the pause-menu-env branch 2 times, most recently from bf9662a to b9297ed Compare January 7, 2025 12:12
@sfan5 sfan5 self-requested a review January 7, 2025 13:08
@y5nw y5nw mentioned this pull request Jan 8, 2025
5 tasks
Copy link
Member

@Desour Desour left a 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.

src/script/lua_api/l_settings.cpp Outdated Show resolved Hide resolved
src/client/game_formspec.cpp Outdated Show resolved Hide resolved
@Zughy Zughy added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Jan 8, 2025
@grorp
Copy link
Contributor Author

grorp commented Jan 8, 2025

The fps unfocused should probably only be used if the window is actually unfocused.

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.

Nitpick: Should the back button be a close button, because it closes the pause menu completely?

Changing the button label to something like "Exit" would make sense.

Other parts of the pause menu do use formspec prepend.

"Other parts"? Only the main pause menu formspec, other sub-menus are implemented in raw Irrlicht GUI.

Disabling it for now because of security risks is reasonable, but we should at some point think about filtering it or something.

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.

Speaking of which, the main pause menu (or how should I call it? x)) still has formspec prepend. This might be dangerous.

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 ...?

@Desour
Copy link
Member

Desour commented Jan 8, 2025

Other parts of the pause menu do use formspec prepend.

"Other parts"? Only the main pause menu formspec, other sub-menus are implemented in raw Irrlicht GUI.

Oh right, it's only the main pause menu.

Speaking of which, the main pause menu (or how should I call it? x)) still has formspec prepend. This might be dangerous.

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 ...?

It could show a fake main menu and grab passwords, see also #12067. But yes, right now it's not a big issue.
However, if in future the main pause menu is also implemented in lua, it might be different.
(Or maybe it will never be an issue because formspec prepend can't influence the formname. 🤷)

@grorp grorp removed the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Jan 16, 2025
@grorp grorp requested a review from Desour January 16, 2025 21:42
Copy link
Member

@Desour Desour left a 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.)

@grorp grorp merged commit eeb6cab into luanti-org:master Jan 19, 2025
18 checks passed
@grorp grorp deleted the pause-menu-env branch January 19, 2025 18:07
@grorp grorp added this to the 5.11.0 milestone Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more settings to the pause menu.
6 participants