From 33f76a04db1913e04c3b70e37df36bb5547eccab Mon Sep 17 00:00:00 2001 From: juso Date: Thu, 5 Jun 2025 19:13:54 +0200 Subject: [PATCH 1/5] Add new ui functions --- src/ui_utils/__init__.py | 30 ++++- src/ui_utils/hud_message.py | 256 +++++++++++++++++++++++++++++++++++- 2 files changed, 284 insertions(+), 2 deletions(-) diff --git a/src/ui_utils/__init__.py b/src/ui_utils/__init__.py index 9d3c3d0..516b557 100644 --- a/src/ui_utils/__init__.py +++ b/src/ui_utils/__init__.py @@ -2,13 +2,29 @@ from .chat import show_chat_message from .clipboard import clipboard_copy, clipboard_paste -from .hud_message import show_hud_message +from .hud_message import ( + ERewardPopup, + blocking_message_hide, + blocking_message_show, + contextual_prompt_hide, + contextual_prompt_show, + display_blocking_message, + display_contextual_prompt, + display_message, + message_hide, + message_show, + show_big_notification, + show_hud_message, + show_reward_popup, + show_top_center_message, +) from .option_box import OptionBox, OptionBoxButton from .reorder_box import ReorderBox from .training_box import EBackButtonScreen, TrainingBox __all__: tuple[str, ...] = ( "EBackButtonScreen", + "ERewardPopup", "OptionBox", "OptionBoxButton", "ReorderBox", @@ -16,10 +32,22 @@ "__author__", "__version__", "__version_info__", + "blocking_message_hide", + "blocking_message_show", "clipboard_copy", "clipboard_paste", + "contextual_prompt_hide", + "contextual_prompt_show", + "display_blocking_message", + "display_contextual_prompt", + "display_message", + "message_hide", + "message_show", + "show_big_notification", "show_chat_message", "show_hud_message", + "show_reward_popup", + "show_top_center_message", ) __version_info__: tuple[int, int] = (1, 3) diff --git a/src/ui_utils/hud_message.py b/src/ui_utils/hud_message.py index fb81a6e..d1e9011 100644 --- a/src/ui_utils/hud_message.py +++ b/src/ui_utils/hud_message.py @@ -1,8 +1,42 @@ +from collections.abc import Iterator +from contextlib import contextmanager +from types import EllipsisType +from typing import TYPE_CHECKING + import unrealsdk +from unrealsdk import unreal from mods_base import get_pc -__all__: tuple[str, ...] = ("show_hud_message",) +if TYPE_CHECKING: + from enum import IntEnum + + class ERewardPopup(IntEnum): + ERP_BadassToken = 0 + ERP_CharacterHead = 1 + ERP_CharacterSkin = 2 + ERP_VehicleSkin = 3 + ERP_MAX = 4 + +else: + ERewardPopup = unrealsdk.find_enum("ERewardPopup") + +__all__: tuple[str, ...] = ( + "ERewardPopup", + "blocking_message_hide", + "blocking_message_show", + "contextual_prompt_hide", + "contextual_prompt_show", + "display_blocking_message", + "display_contextual_prompt", + "display_message", + "message_hide", + "message_show", + "show_big_notification", + "show_hud_message", + "show_reward_popup", + "show_top_center_message", +) def show_hud_message(title: str, msg: str, duration: float = 2.5) -> None: @@ -39,3 +73,223 @@ def show_hud_message(title: str, msg: str, duration: float = 2.5) -> None: True, 0, ) + + +def show_big_notification( + msg: str, + ui_sound: unreal.UObject | None | EllipsisType = ..., +) -> None: + """ + Displays a big notification message in the main in game hud. + + Uses the message style of the Second Wind notification. + + Note this message can only display up to 33 characters. + + Args: + msg: The message to display. + ui_sound: An optional AkEvent to play when the message is displayed. + If Ellipsis, default sound will be used. + """ + if (hud_movie := get_pc().GetHUDMovie()) is None: + return + + sound_backup = None + sw_interaction = None + for gfx_movie in unrealsdk.find_all("GearboxGFxMovie", exact=False): + for interaction in gfx_movie.InteractionOverrideSounds: + if interaction.Interaction == "SecondWind": + sound_backup = interaction.AkEvent + sw_interaction = interaction + break + + if ui_sound is not Ellipsis and sw_interaction: + sw_interaction.AkEvent = ui_sound + + backup_string = hud_movie.SecondWindString + hud_movie.SecondWindString = msg + hud_movie.DisplaySecondWind() + hud_movie.SecondWindString = backup_string + if sw_interaction: + sw_interaction.AkEvent = sound_backup + + +def show_top_center_message(msg: str, show_discovered_message: bool = False) -> None: + """ + Displays a message in the top center of the screen. + + Uses the style of the new area discovered message. + + Note this message can only display up to 41 characters. + + Args: + msg: The message to display. + show_discovered_message: If True, the message 'You have discovered' header will show. + """ + if (hud_movie := get_pc().GetHUDMovie()) is None: + return + hud_movie.ShowWorldDiscovery("", "msg", show_discovered_message, False) + + +def show_reward_popup( + msg: str, + reward_type: ERewardPopup = ERewardPopup.ERP_BadassToken, +) -> None: + """ + Displays a reward popup with the given message and reward type. + + Note this message can only display up to 33 characters. + + Args: + msg: The message to display in the popup. + reward_type: The type of reward to display. Defaults to ERewardPopup.ERP_BadassToken. + """ + if (hud_movie := get_pc().GetHUDMovie()) is None: + return + + icon = { + ERewardPopup.ERP_BadassToken: "token", + ERewardPopup.ERP_CharacterHead: "head", + ERewardPopup.ERP_CharacterSkin: "playerSkin", + ERewardPopup.ERP_VehicleSkin: "vehicleSkin", + }.get(reward_type, "token") + + hud_movie.SingleArgInvokeS("p1.badassToken.gotoAndStop", "stop") + hud_movie.SingleArgInvokeS("p1.badassToken.gotoAndStop", "go") + hud_movie.SingleArgInvokeS("p1.badassToken.inner.gotoAndStop", icon) + hud_movie.SetVariableString("p1.badassToken.inner.dispText.text", msg) + + +def contextual_prompt_show(text: str, button_string: str) -> None: + """ + Displays a contextual prompt with the given text and button string. + + Note both text and button_string can each display up to 16 characters. + + Args: + text: The text top to display in the prompt. + button_string: The button string to display in the prompt. + """ + + if (hud_movie := get_pc().GetHUDMovie()) is None: + return + contextual_prompt = hud_movie.ContextualPromptButtonString + hud_movie.ContextualPromptButtonString = button_string + hud_movie.ToggleContextualPrompt(text, True) + hud_movie.ContextualPromptButtonString = contextual_prompt + + +def contextual_prompt_hide() -> None: + """Hides the currently displayed contextual prompt, if any.""" + if (hud_movie := get_pc().GetHUDMovie()) is None: + return + hud_movie.ToggleContextualPrompt("", False) + + +@contextmanager +def display_contextual_prompt(text: str, button_string: str) -> Iterator[None]: + """ + Context manager to display and hide a contextual prompt. + + This will display the prompt when entering the context and hide it when exiting. + + Args: + text: The text to display in the prompt. + button_string: The button string to display in the prompt. + """ + contextual_prompt_show(text, button_string) + try: + yield + finally: + contextual_prompt_hide() + + +def blocking_message_show(msg: str, reason: str | None = None) -> None: + """ + Displays a blocking message with the given text. + + This message will block any input until it is hidden. + + Note this message has no character limit, but only scales horizontally. + Multiple lines will not be displayed correctly. + + 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 blocking_message_hide() -> 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. + """ + blocking_message_show(msg, reason) + try: + yield + finally: + blocking_message_hide() + + +def message_show(msg: str) -> None: + """ + Displays a message on the left side of the screen. + + Note this message has no character limit, but only scales horizontally. + Multiple lines will not be displayed correctly. + + Args: + msg: The message to display. + """ + if (msg_movie := get_pc().GetOnlineMessageMovie()) is None: + return + + msg_movie.DisplayMessage(msg) + + +def message_hide() -> 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. + """ + message_show(msg) + try: + yield + finally: + message_hide() From a91d9c986522be56ac9c76f77b54a2f15b917f9a Mon Sep 17 00:00:00 2001 From: juso Date: Sun, 8 Jun 2025 11:36:50 +0200 Subject: [PATCH 2/5] Split into HUD and OnlineMessage UI, rename functions and reword docs --- src/ui_utils/__init__.py | 44 ++++----- src/ui_utils/hud_message.py | 157 +++++++-------------------------- src/ui_utils/online_message.py | 102 +++++++++++++++++++++ 3 files changed, 155 insertions(+), 148 deletions(-) create mode 100644 src/ui_utils/online_message.py diff --git a/src/ui_utils/__init__.py b/src/ui_utils/__init__.py index 516b557..9d85c55 100644 --- a/src/ui_utils/__init__.py +++ b/src/ui_utils/__init__.py @@ -4,19 +4,21 @@ from .clipboard import clipboard_copy, clipboard_paste from .hud_message import ( ERewardPopup, - blocking_message_hide, - blocking_message_show, - contextual_prompt_hide, - contextual_prompt_show, - display_blocking_message, - display_contextual_prompt, - display_message, - message_hide, - message_show, - show_big_notification, + display_button_prompt, + hide_button_prompt, + show_button_prompt, + show_discovery_message, show_hud_message, show_reward_popup, - show_top_center_message, + show_second_wind_notification, +) +from .online_message import ( + display_blocking_message, + display_message, + hide_blocking_message, + hide_message, + show_blocking_message, + show_message, ) from .option_box import OptionBox, OptionBoxButton from .reorder_box import ReorderBox @@ -32,25 +34,25 @@ "__author__", "__version__", "__version_info__", - "blocking_message_hide", - "blocking_message_show", "clipboard_copy", "clipboard_paste", - "contextual_prompt_hide", - "contextual_prompt_show", "display_blocking_message", - "display_contextual_prompt", + "display_button_prompt", "display_message", - "message_hide", - "message_show", - "show_big_notification", + "hide_blocking_message", + "hide_button_prompt", + "hide_message", + "show_blocking_message", + "show_button_prompt", "show_chat_message", + "show_discovery_message", "show_hud_message", + "show_message", "show_reward_popup", - "show_top_center_message", + "show_second_wind_notification", ) -__version_info__: tuple[int, int] = (1, 3) +__version_info__: tuple[int, int] = (1, 4) __version__: str = f"{__version_info__[0]}.{__version_info__[1]}" __author__: str = "bl-sdk" diff --git a/src/ui_utils/hud_message.py b/src/ui_utils/hud_message.py index d1e9011..76471e2 100644 --- a/src/ui_utils/hud_message.py +++ b/src/ui_utils/hud_message.py @@ -23,19 +23,13 @@ class ERewardPopup(IntEnum): __all__: tuple[str, ...] = ( "ERewardPopup", - "blocking_message_hide", - "blocking_message_show", - "contextual_prompt_hide", - "contextual_prompt_show", - "display_blocking_message", - "display_contextual_prompt", - "display_message", - "message_hide", - "message_show", - "show_big_notification", + "display_button_prompt", + "hide_button_prompt", + "show_button_prompt", + "show_discovery_message", "show_hud_message", "show_reward_popup", - "show_top_center_message", + "show_second_wind_notification", ) @@ -75,7 +69,7 @@ def show_hud_message(title: str, msg: str, duration: float = 2.5) -> None: ) -def show_big_notification( +def show_second_wind_notification( msg: str, ui_sound: unreal.UObject | None | EllipsisType = ..., ) -> None: @@ -84,24 +78,22 @@ def show_big_notification( Uses the message style of the Second Wind notification. - Note this message can only display up to 33 characters. + Note this should not be used for critical messages, it may silently fail at any point. Args: msg: The message to display. ui_sound: An optional AkEvent to play when the message is displayed. - If Ellipsis, default sound will be used. + If Ellipsis, default sound will be used. """ if (hud_movie := get_pc().GetHUDMovie()) is None: return sound_backup = None sw_interaction = None - for gfx_movie in unrealsdk.find_all("GearboxGFxMovie", exact=False): - for interaction in gfx_movie.InteractionOverrideSounds: - if interaction.Interaction == "SecondWind": - sound_backup = interaction.AkEvent - sw_interaction = interaction - break + for interaction in hud_movie.InteractionOverrideSounds: + if interaction.Interaction == "SecondWind": + sound_backup = interaction.AkEvent + sw_interaction = interaction if ui_sound is not Ellipsis and sw_interaction: sw_interaction.AkEvent = ui_sound @@ -114,13 +106,13 @@ def show_big_notification( sw_interaction.AkEvent = sound_backup -def show_top_center_message(msg: str, show_discovered_message: bool = False) -> None: +def show_discovery_message(msg: str, show_discovered_message: bool = False) -> None: """ Displays a message in the top center of the screen. Uses the style of the new area discovered message. - Note this message can only display up to 41 characters. + Note this should not be used for critical messages, it may silently fail at any point. Args: msg: The message to display. @@ -128,7 +120,7 @@ def show_top_center_message(msg: str, show_discovered_message: bool = False) -> """ if (hud_movie := get_pc().GetHUDMovie()) is None: return - hud_movie.ShowWorldDiscovery("", "msg", show_discovered_message, False) + hud_movie.ShowWorldDiscovery("", msg, show_discovered_message, False) def show_reward_popup( @@ -138,7 +130,7 @@ def show_reward_popup( """ Displays a reward popup with the given message and reward type. - Note this message can only display up to 33 characters. + Note this should not be used for critical messages, it may silently fail at any point. Args: msg: The message to display in the popup. @@ -160,26 +152,28 @@ def show_reward_popup( hud_movie.SetVariableString("p1.badassToken.inner.dispText.text", msg) -def contextual_prompt_show(text: str, button_string: str) -> None: +def show_button_prompt(reason: str, button: str) -> None: """ Displays a contextual prompt with the given text and button string. - Note both text and button_string can each display up to 16 characters. + This will stay visible until it is explicitly hidden, see `hide_contextual_prompt`. + + Note this should not be used for critical messages, it may silently fail at any point. Args: - text: The text top to display in the prompt. - button_string: The button string to display in the prompt. + reason: The text top to display in the prompt. + button: The button string to display in the prompt. """ if (hud_movie := get_pc().GetHUDMovie()) is None: return contextual_prompt = hud_movie.ContextualPromptButtonString - hud_movie.ContextualPromptButtonString = button_string - hud_movie.ToggleContextualPrompt(text, True) + hud_movie.ContextualPromptButtonString = button + hud_movie.ToggleContextualPrompt(reason, True) hud_movie.ContextualPromptButtonString = contextual_prompt -def contextual_prompt_hide() -> None: +def hide_button_prompt() -> None: """Hides the currently displayed contextual prompt, if any.""" if (hud_movie := get_pc().GetHUDMovie()) is None: return @@ -187,109 +181,18 @@ def contextual_prompt_hide() -> None: @contextmanager -def display_contextual_prompt(text: str, button_string: str) -> Iterator[None]: +def display_button_prompt(reason: str, button: str) -> Iterator[None]: """ Context manager to display and hide a contextual prompt. This will display the prompt when entering the context and hide it when exiting. Args: - text: The text to display in the prompt. - button_string: The button string to display in the prompt. - """ - contextual_prompt_show(text, button_string) - try: - yield - finally: - contextual_prompt_hide() - - -def blocking_message_show(msg: str, reason: str | None = None) -> None: - """ - Displays a blocking message with the given text. - - This message will block any input until it is hidden. - - Note this message has no character limit, but only scales horizontally. - Multiple lines will not be displayed correctly. - - 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 blocking_message_hide() -> 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. - """ - blocking_message_show(msg, reason) - try: - yield - finally: - blocking_message_hide() - - -def message_show(msg: str) -> None: - """ - Displays a message on the left side of the screen. - - Note this message has no character limit, but only scales horizontally. - Multiple lines will not be displayed correctly. - - Args: - msg: The message to display. - """ - if (msg_movie := get_pc().GetOnlineMessageMovie()) is None: - return - - msg_movie.DisplayMessage(msg) - - -def message_hide() -> 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. + reason: The text to display in the prompt. + button: The button string to display in the prompt. """ - message_show(msg) + show_button_prompt(reason, button) try: yield finally: - message_hide() + hide_button_prompt() diff --git a/src/ui_utils/online_message.py b/src/ui_utils/online_message.py new file mode 100644 index 0000000..870b586 --- /dev/null +++ b/src/ui_utils/online_message.py @@ -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() From bdb514fa85b0771dc3470afa09262ca5d5821c20 Mon Sep 17 00:00:00 2001 From: juso Date: Mon, 9 Jun 2025 09:26:43 +0200 Subject: [PATCH 3/5] Add early break --- src/ui_utils/hud_message.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui_utils/hud_message.py b/src/ui_utils/hud_message.py index 76471e2..da33e0d 100644 --- a/src/ui_utils/hud_message.py +++ b/src/ui_utils/hud_message.py @@ -94,6 +94,7 @@ def show_second_wind_notification( if interaction.Interaction == "SecondWind": sound_backup = interaction.AkEvent sw_interaction = interaction + break if ui_sound is not Ellipsis and sw_interaction: sw_interaction.AkEvent = ui_sound From 20e3e8cd035214c89fc4751263ec0800afb3e48a Mon Sep 17 00:00:00 2001 From: juso Date: Mon, 9 Jun 2025 09:51:26 +0200 Subject: [PATCH 4/5] Remove context managers --- src/ui_utils/__init__.py | 6 ----- src/ui_utils/hud_message.py | 21 ----------------- src/ui_utils/online_message.py | 41 ---------------------------------- 3 files changed, 68 deletions(-) diff --git a/src/ui_utils/__init__.py b/src/ui_utils/__init__.py index 9d85c55..e21cd82 100644 --- a/src/ui_utils/__init__.py +++ b/src/ui_utils/__init__.py @@ -4,7 +4,6 @@ from .clipboard import clipboard_copy, clipboard_paste from .hud_message import ( ERewardPopup, - display_button_prompt, hide_button_prompt, show_button_prompt, show_discovery_message, @@ -13,8 +12,6 @@ show_second_wind_notification, ) from .online_message import ( - display_blocking_message, - display_message, hide_blocking_message, hide_message, show_blocking_message, @@ -36,9 +33,6 @@ "__version_info__", "clipboard_copy", "clipboard_paste", - "display_blocking_message", - "display_button_prompt", - "display_message", "hide_blocking_message", "hide_button_prompt", "hide_message", diff --git a/src/ui_utils/hud_message.py b/src/ui_utils/hud_message.py index da33e0d..9452363 100644 --- a/src/ui_utils/hud_message.py +++ b/src/ui_utils/hud_message.py @@ -1,5 +1,3 @@ -from collections.abc import Iterator -from contextlib import contextmanager from types import EllipsisType from typing import TYPE_CHECKING @@ -23,7 +21,6 @@ class ERewardPopup(IntEnum): __all__: tuple[str, ...] = ( "ERewardPopup", - "display_button_prompt", "hide_button_prompt", "show_button_prompt", "show_discovery_message", @@ -179,21 +176,3 @@ def hide_button_prompt() -> None: if (hud_movie := get_pc().GetHUDMovie()) is None: return hud_movie.ToggleContextualPrompt("", False) - - -@contextmanager -def display_button_prompt(reason: str, button: str) -> Iterator[None]: - """ - Context manager to display and hide a contextual prompt. - - This will display the prompt when entering the context and hide it when exiting. - - Args: - reason: The text to display in the prompt. - button: The button string to display in the prompt. - """ - show_button_prompt(reason, button) - try: - yield - finally: - hide_button_prompt() diff --git a/src/ui_utils/online_message.py b/src/ui_utils/online_message.py index 870b586..0b277a7 100644 --- a/src/ui_utils/online_message.py +++ b/src/ui_utils/online_message.py @@ -1,11 +1,6 @@ -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", @@ -43,25 +38,6 @@ def hide_blocking_message() -> None: 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. @@ -83,20 +59,3 @@ def hide_message() -> 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() From a4d552017ff00ba23bcdd82f45c835f32118bf95 Mon Sep 17 00:00:00 2001 From: apple1417 Date: Sat, 14 Jun 2025 14:53:39 +1200 Subject: [PATCH 5/5] cleanup, update changelog --- changelog.md | 10 +++++++++- src/ui_utils/__init__.py | 8 ++++---- src/ui_utils/online_message.py | 18 +++++++++--------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/changelog.md b/changelog.md index 9b67268..9ba35c3 100644 --- a/changelog.md +++ b/changelog.md @@ -28,7 +28,15 @@ - Moved a few warnings to go through Python's system, so they get attributed to the right place. ### UI Utils v1.3 -- Linting fixes. +- Added several new helper functions: + - `show_blocking_message`, `hide_blocking_message` + - `show_button_prompt`, `hide_button_prompt` + - `show_coop_message`, `hide_coop_message` + - `show_discovery_message` + - `show_reward_popup` + - `show_second_wind_notification` + + [See examples here](https://bl-sdk.github.io/developing/ui_utils/willow2/). ### [unrealsdk v2.0.0](https://github.com/bl-sdk/unrealsdk/blob/master/changelog.md#v200) > - Now supports Borderlands 1. Big thanks to Ry for doing basically all the reverse engineering. diff --git a/src/ui_utils/__init__.py b/src/ui_utils/__init__.py index e21cd82..610b3af 100644 --- a/src/ui_utils/__init__.py +++ b/src/ui_utils/__init__.py @@ -13,9 +13,9 @@ ) from .online_message import ( hide_blocking_message, - hide_message, + hide_coop_message, show_blocking_message, - show_message, + show_coop_message, ) from .option_box import OptionBox, OptionBoxButton from .reorder_box import ReorderBox @@ -35,13 +35,13 @@ "clipboard_paste", "hide_blocking_message", "hide_button_prompt", - "hide_message", + "hide_coop_message", "show_blocking_message", "show_button_prompt", "show_chat_message", + "show_coop_message", "show_discovery_message", "show_hud_message", - "show_message", "show_reward_popup", "show_second_wind_notification", ) diff --git a/src/ui_utils/online_message.py b/src/ui_utils/online_message.py index 0b277a7..1e74b63 100644 --- a/src/ui_utils/online_message.py +++ b/src/ui_utils/online_message.py @@ -2,9 +2,9 @@ __all__: tuple[str, ...] = ( "hide_blocking_message", - "hide_message", + "hide_coop_message", "show_blocking_message", - "show_message", + "show_coop_message", ) @@ -12,9 +12,9 @@ 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 blocks all user input until it is hidden. - This message will block any input until it is hidden. + This message will stay until it is explicitly hidden, see `hide_blocking_message`. Args: msg: The message to display. @@ -38,11 +38,11 @@ def hide_blocking_message() -> None: msg_movie.HideBlocking() -def show_message(msg: str) -> None: +def show_coop_message(msg: str) -> None: """ - Displays a message on the left side of the screen. + Displays a short message on the left of the screen, like those used when coop players join. - This message will stay until it is explicitly hidden, see `hide_message`. + This message will stay until it is explicitly hidden, see `hide_coop_message`. Args: msg: The message to display. @@ -53,8 +53,8 @@ def show_message(msg: str) -> None: msg_movie.DisplayMessage(msg) -def hide_message() -> None: - """Hides the currently displayed message in the online message movie.""" +def hide_coop_message() -> None: + """Hides the currently displayed coop message, if any.""" if (msg_movie := get_pc().GetOnlineMessageMovie()) is None: return