Skip to content

Commit aa74dc1

Browse files
authored
Merge pull request #63 from juso40/master
Add new ui functions
2 parents 58f9d89 + a4d5520 commit aa74dc1

File tree

4 files changed

+234
-4
lines changed

4 files changed

+234
-4
lines changed

changelog.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@
2828
- Moved a few warnings to go through Python's system, so they get attributed to the right place.
2929

3030
### UI Utils v1.3
31-
- Linting fixes.
31+
- Added several new helper functions:
32+
- `show_blocking_message`, `hide_blocking_message`
33+
- `show_button_prompt`, `hide_button_prompt`
34+
- `show_coop_message`, `hide_coop_message`
35+
- `show_discovery_message`
36+
- `show_reward_popup`
37+
- `show_second_wind_notification`
38+
39+
[See examples here](https://bl-sdk.github.io/developing/ui_utils/willow2/).
3240

3341
### [unrealsdk v2.0.0](https://github.com/bl-sdk/unrealsdk/blob/master/changelog.md#v200)
3442
> - Now supports Borderlands 1. Big thanks to Ry for doing basically all the reverse engineering.

src/ui_utils/__init__.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
22

33
from .chat import show_chat_message
44
from .clipboard import clipboard_copy, clipboard_paste
5-
from .hud_message import show_hud_message
5+
from .hud_message import (
6+
ERewardPopup,
7+
hide_button_prompt,
8+
show_button_prompt,
9+
show_discovery_message,
10+
show_hud_message,
11+
show_reward_popup,
12+
show_second_wind_notification,
13+
)
14+
from .online_message import (
15+
hide_blocking_message,
16+
hide_coop_message,
17+
show_blocking_message,
18+
show_coop_message,
19+
)
620
from .option_box import OptionBox, OptionBoxButton
721
from .reorder_box import ReorderBox
822
from .training_box import EBackButtonScreen, TrainingBox
923

1024
__all__: tuple[str, ...] = (
1125
"EBackButtonScreen",
26+
"ERewardPopup",
1227
"OptionBox",
1328
"OptionBoxButton",
1429
"ReorderBox",
@@ -18,11 +33,20 @@
1833
"__version_info__",
1934
"clipboard_copy",
2035
"clipboard_paste",
36+
"hide_blocking_message",
37+
"hide_button_prompt",
38+
"hide_coop_message",
39+
"show_blocking_message",
40+
"show_button_prompt",
2141
"show_chat_message",
42+
"show_coop_message",
43+
"show_discovery_message",
2244
"show_hud_message",
45+
"show_reward_popup",
46+
"show_second_wind_notification",
2347
)
2448

25-
__version_info__: tuple[int, int] = (1, 3)
49+
__version_info__: tuple[int, int] = (1, 4)
2650
__version__: str = f"{__version_info__[0]}.{__version_info__[1]}"
2751
__author__: str = "bl-sdk"
2852

src/ui_utils/hud_message.py

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
1+
from types import EllipsisType
2+
from typing import TYPE_CHECKING
3+
14
import unrealsdk
5+
from unrealsdk import unreal
26

37
from mods_base import get_pc
48

5-
__all__: tuple[str, ...] = ("show_hud_message",)
9+
if TYPE_CHECKING:
10+
from enum import IntEnum
11+
12+
class ERewardPopup(IntEnum):
13+
ERP_BadassToken = 0
14+
ERP_CharacterHead = 1
15+
ERP_CharacterSkin = 2
16+
ERP_VehicleSkin = 3
17+
ERP_MAX = 4
18+
19+
else:
20+
ERewardPopup = unrealsdk.find_enum("ERewardPopup")
21+
22+
__all__: tuple[str, ...] = (
23+
"ERewardPopup",
24+
"hide_button_prompt",
25+
"show_button_prompt",
26+
"show_discovery_message",
27+
"show_hud_message",
28+
"show_reward_popup",
29+
"show_second_wind_notification",
30+
)
631

732

833
def show_hud_message(title: str, msg: str, duration: float = 2.5) -> None:
@@ -39,3 +64,115 @@ def show_hud_message(title: str, msg: str, duration: float = 2.5) -> None:
3964
True,
4065
0,
4166
)
67+
68+
69+
def show_second_wind_notification(
70+
msg: str,
71+
ui_sound: unreal.UObject | None | EllipsisType = ...,
72+
) -> None:
73+
"""
74+
Displays a big notification message in the main in game hud.
75+
76+
Uses the message style of the Second Wind notification.
77+
78+
Note this should not be used for critical messages, it may silently fail at any point.
79+
80+
Args:
81+
msg: The message to display.
82+
ui_sound: An optional AkEvent to play when the message is displayed.
83+
If Ellipsis, default sound will be used.
84+
"""
85+
if (hud_movie := get_pc().GetHUDMovie()) is None:
86+
return
87+
88+
sound_backup = None
89+
sw_interaction = None
90+
for interaction in hud_movie.InteractionOverrideSounds:
91+
if interaction.Interaction == "SecondWind":
92+
sound_backup = interaction.AkEvent
93+
sw_interaction = interaction
94+
break
95+
96+
if ui_sound is not Ellipsis and sw_interaction:
97+
sw_interaction.AkEvent = ui_sound
98+
99+
backup_string = hud_movie.SecondWindString
100+
hud_movie.SecondWindString = msg
101+
hud_movie.DisplaySecondWind()
102+
hud_movie.SecondWindString = backup_string
103+
if sw_interaction:
104+
sw_interaction.AkEvent = sound_backup
105+
106+
107+
def show_discovery_message(msg: str, show_discovered_message: bool = False) -> None:
108+
"""
109+
Displays a message in the top center of the screen.
110+
111+
Uses the style of the new area discovered message.
112+
113+
Note this should not be used for critical messages, it may silently fail at any point.
114+
115+
Args:
116+
msg: The message to display.
117+
show_discovered_message: If True, the message 'You have discovered' header will show.
118+
"""
119+
if (hud_movie := get_pc().GetHUDMovie()) is None:
120+
return
121+
hud_movie.ShowWorldDiscovery("", msg, show_discovered_message, False)
122+
123+
124+
def show_reward_popup(
125+
msg: str,
126+
reward_type: ERewardPopup = ERewardPopup.ERP_BadassToken,
127+
) -> None:
128+
"""
129+
Displays a reward popup with the given message and reward type.
130+
131+
Note this should not be used for critical messages, it may silently fail at any point.
132+
133+
Args:
134+
msg: The message to display in the popup.
135+
reward_type: The type of reward to display. Defaults to ERewardPopup.ERP_BadassToken.
136+
"""
137+
if (hud_movie := get_pc().GetHUDMovie()) is None:
138+
return
139+
140+
icon = {
141+
ERewardPopup.ERP_BadassToken: "token",
142+
ERewardPopup.ERP_CharacterHead: "head",
143+
ERewardPopup.ERP_CharacterSkin: "playerSkin",
144+
ERewardPopup.ERP_VehicleSkin: "vehicleSkin",
145+
}.get(reward_type, "token")
146+
147+
hud_movie.SingleArgInvokeS("p1.badassToken.gotoAndStop", "stop")
148+
hud_movie.SingleArgInvokeS("p1.badassToken.gotoAndStop", "go")
149+
hud_movie.SingleArgInvokeS("p1.badassToken.inner.gotoAndStop", icon)
150+
hud_movie.SetVariableString("p1.badassToken.inner.dispText.text", msg)
151+
152+
153+
def show_button_prompt(reason: str, button: str) -> None:
154+
"""
155+
Displays a contextual prompt with the given text and button string.
156+
157+
This will stay visible until it is explicitly hidden, see `hide_contextual_prompt`.
158+
159+
Note this should not be used for critical messages, it may silently fail at any point.
160+
161+
Args:
162+
reason: The text top to display in the prompt.
163+
button: The button string to display in the prompt.
164+
"""
165+
166+
if (hud_movie := get_pc().GetHUDMovie()) is None:
167+
return
168+
contextual_prompt = hud_movie.ContextualPromptButtonString
169+
hud_movie.ContextualPromptButtonString = button
170+
hud_movie.ToggleContextualPrompt(reason, True)
171+
hud_movie.ContextualPromptButtonString = contextual_prompt
172+
173+
174+
def hide_button_prompt() -> None:
175+
"""Hides the currently displayed contextual prompt, if any."""
176+
if (hud_movie := get_pc().GetHUDMovie()) is None:
177+
return
178+
hud_movie.ToggleContextualPrompt("", False)

src/ui_utils/online_message.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from mods_base import get_pc
2+
3+
__all__: tuple[str, ...] = (
4+
"hide_blocking_message",
5+
"hide_coop_message",
6+
"show_blocking_message",
7+
"show_coop_message",
8+
)
9+
10+
11+
def show_blocking_message(msg: str, reason: str | None = None) -> None:
12+
"""
13+
Displays a blocking message with the given text.
14+
15+
This message blocks all user input until it is hidden.
16+
17+
This message will stay until it is explicitly hidden, see `hide_blocking_message`.
18+
19+
Args:
20+
msg: The message to display.
21+
reason: An optional reason for the blocking message, which will be displayed as a subtitle.
22+
If None, the default text will show.
23+
"""
24+
if (msg_movie := get_pc().GetOnlineMessageMovie()) is None:
25+
return
26+
27+
backup = msg_movie.BlockingSubtitle
28+
msg_movie.BlockingSubtitle = reason if reason is not None else backup
29+
msg_movie.DisplayBlockingMessage(msg)
30+
msg_movie.BlockingSubtitle = backup
31+
32+
33+
def hide_blocking_message() -> None:
34+
"""Hides the currently displayed blocking message, if any."""
35+
if (msg_movie := get_pc().GetOnlineMessageMovie()) is None:
36+
return
37+
38+
msg_movie.HideBlocking()
39+
40+
41+
def show_coop_message(msg: str) -> None:
42+
"""
43+
Displays a short message on the left of the screen, like those used when coop players join.
44+
45+
This message will stay until it is explicitly hidden, see `hide_coop_message`.
46+
47+
Args:
48+
msg: The message to display.
49+
"""
50+
if (msg_movie := get_pc().GetOnlineMessageMovie()) is None:
51+
return
52+
53+
msg_movie.DisplayMessage(msg)
54+
55+
56+
def hide_coop_message() -> None:
57+
"""Hides the currently displayed coop message, if any."""
58+
if (msg_movie := get_pc().GetOnlineMessageMovie()) is None:
59+
return
60+
61+
msg_movie.Hide()

0 commit comments

Comments
 (0)