|
| 1 | +from types import EllipsisType |
| 2 | +from typing import TYPE_CHECKING |
| 3 | + |
1 | 4 | import unrealsdk |
| 5 | +from unrealsdk import unreal |
2 | 6 |
|
3 | 7 | from mods_base import get_pc |
4 | 8 |
|
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 | +) |
6 | 31 |
|
7 | 32 |
|
8 | 33 | 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: |
39 | 64 | True, |
40 | 65 | 0, |
41 | 66 | ) |
| 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) |
0 commit comments