-
Notifications
You must be signed in to change notification settings - Fork 13
Add new ui functions #63
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| from collections.abc import Iterator | ||
| from contextlib import contextmanager | ||
|
|
||
| from mods_base import get_pc | ||
|
|
||
| __all__: tuple[str, ...] = ( | ||
| "display_blocking_message", | ||
| "display_message", | ||
| "hide_blocking_message", | ||
| "hide_message", | ||
| "show_blocking_message", | ||
| "show_message", | ||
| ) | ||
|
|
||
|
|
||
| def show_blocking_message(msg: str, reason: str | None = None) -> None: | ||
| """ | ||
| Displays a blocking message with the given text. | ||
|
|
||
| This message will stay until it is explicitly hidden, see `hide_blocking_message`. | ||
|
|
||
| This message will block any input until it is hidden. | ||
|
|
||
| Args: | ||
| msg: The message to display. | ||
| reason: An optional reason for the blocking message, which will be displayed as a subtitle. | ||
| If None, the default text will show. | ||
| """ | ||
| if (msg_movie := get_pc().GetOnlineMessageMovie()) is None: | ||
| return | ||
|
|
||
| backup = msg_movie.BlockingSubtitle | ||
| msg_movie.BlockingSubtitle = reason if reason is not None else backup | ||
| msg_movie.DisplayBlockingMessage(msg) | ||
| msg_movie.BlockingSubtitle = backup | ||
|
|
||
|
|
||
| def hide_blocking_message() -> None: | ||
| """Hides the currently displayed blocking message, if any.""" | ||
| if (msg_movie := get_pc().GetOnlineMessageMovie()) is None: | ||
| return | ||
|
|
||
| msg_movie.HideBlocking() | ||
|
|
||
|
|
||
| @contextmanager | ||
| def display_blocking_message(msg: str, reason: str | None = None) -> Iterator[None]: | ||
| """ | ||
| Context manager to display and hide a blocking message. | ||
|
|
||
| This will display the message when entering the context and hide it when exiting. | ||
|
|
||
| Args: | ||
| msg: The message to display. | ||
| reason: An optional reason for the blocking message, which will be displayed as a subtitle. | ||
| If None, the default text will show. | ||
| """ | ||
| show_blocking_message(msg, reason) | ||
| try: | ||
| yield | ||
| finally: | ||
| hide_blocking_message() | ||
|
|
||
|
|
||
| def show_message(msg: str) -> None: | ||
| """ | ||
| Displays a message on the left side of the screen. | ||
|
||
|
|
||
| This message will stay until it is explicitly hidden, see `hide_message`. | ||
|
|
||
| Args: | ||
| msg: The message to display. | ||
| """ | ||
| if (msg_movie := get_pc().GetOnlineMessageMovie()) is None: | ||
| return | ||
|
|
||
| msg_movie.DisplayMessage(msg) | ||
|
|
||
|
|
||
| def hide_message() -> None: | ||
| """Hides the currently displayed message in the online message movie.""" | ||
| if (msg_movie := get_pc().GetOnlineMessageMovie()) is None: | ||
| return | ||
|
|
||
| msg_movie.Hide() | ||
|
|
||
|
|
||
| @contextmanager | ||
| def display_message(msg: str) -> Iterator[None]: | ||
| """ | ||
| Context manager to display and hide a message. | ||
|
|
||
| This will display the message when entering the context and hide it when exiting. | ||
|
|
||
| Args: | ||
| msg: The message to display. | ||
| """ | ||
| show_message(msg) | ||
| try: | ||
| yield | ||
| finally: | ||
| hide_message() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.