bauiv1lib.gather.abouttab
Defines the about tab in the gather UI.
1# Released under the MIT License. See LICENSE for details. 2# 3"""Defines the about tab in the gather UI.""" 4 5from __future__ import annotations 6 7from typing import TYPE_CHECKING, override 8 9from bauiv1lib.gather import GatherTab 10import bauiv1 as bui 11 12if TYPE_CHECKING: 13 from bauiv1lib.gather import GatherWindow 14 15 16class AboutGatherTab(GatherTab): 17 """The about tab in the gather UI""" 18 19 @override 20 def on_activate( 21 self, 22 parent_widget: bui.Widget, 23 tab_button: bui.Widget, 24 region_width: float, 25 region_height: float, 26 region_left: float, 27 region_bottom: float, 28 ) -> bui.Widget: 29 # pylint: disable=too-many-locals 30 # pylint: disable=too-many-positional-arguments 31 32 plus = bui.app.plus 33 assert plus is not None 34 35 try_tickets = plus.get_v1_account_misc_read_val( 36 'friendTryTickets', None 37 ) 38 39 show_message = True 40 # Squish message as needed to get things to fit nicely at 41 # various scales. 42 uiscale = bui.app.ui_v1.uiscale 43 message_height = ( 44 210 45 if uiscale is bui.UIScale.SMALL 46 else 305 if uiscale is bui.UIScale.MEDIUM else 370 47 ) 48 # Let's not talk about sharing in vr-mode; its tricky to fit more 49 # than one head in a VR-headset. 50 show_message_extra = not bui.app.env.vr 51 message_extra_height = 60 52 show_invite = try_tickets is not None 53 invite_height = 80 54 show_discord = True 55 discord_height = 80 56 57 c_height = 0 58 if show_message: 59 c_height += message_height 60 if show_message_extra: 61 c_height += message_extra_height 62 if show_invite: 63 c_height += invite_height 64 if show_discord: 65 c_height += discord_height 66 67 party_button_label = bui.charstr(bui.SpecialChar.TOP_BUTTON) 68 message = bui.Lstr( 69 resource='gatherWindow.aboutDescriptionText', 70 subs=[ 71 ('${PARTY}', bui.charstr(bui.SpecialChar.PARTY_ICON)), 72 ('${BUTTON}', party_button_label), 73 ], 74 ) 75 76 if show_message_extra: 77 message = bui.Lstr( 78 value='${A}\n\n${B}', 79 subs=[ 80 ('${A}', message), 81 ( 82 '${B}', 83 bui.Lstr( 84 resource='gatherWindow.' 85 'aboutDescriptionLocalMultiplayerExtraText' 86 ), 87 ), 88 ], 89 ) 90 91 scroll_widget = bui.scrollwidget( 92 parent=parent_widget, 93 position=(region_left, region_bottom), 94 size=(region_width, region_height), 95 highlight=False, 96 border_opacity=0, 97 ) 98 msc_scale = 1.1 99 100 container = bui.containerwidget( 101 parent=scroll_widget, 102 position=( 103 region_left, 104 region_bottom + (region_height - c_height) * 0.5, 105 ), 106 size=(region_width, c_height), 107 background=False, 108 selectable=show_invite or show_discord, 109 ) 110 # Allows escaping if we select the container somehow (though 111 # shouldn't be possible when buttons are present). 112 bui.widget(edit=container, up_widget=tab_button) 113 114 y = c_height - 30 115 if show_message: 116 bui.textwidget( 117 parent=container, 118 position=(region_width * 0.5, y), 119 color=(0.6, 1.0, 0.6), 120 scale=msc_scale, 121 size=(0, 0), 122 maxwidth=region_width * 0.9, 123 max_height=message_height, 124 h_align='center', 125 v_align='top', 126 text=message, 127 ) 128 y -= message_height 129 if show_message_extra: 130 y -= message_extra_height 131 132 if show_invite: 133 bui.textwidget( 134 parent=container, 135 position=(region_width * 0.57, y), 136 color=(0, 1, 0), 137 scale=0.6, 138 size=(0, 0), 139 maxwidth=region_width * 0.5, 140 h_align='right', 141 v_align='center', 142 flatness=1.0, 143 text=bui.Lstr( 144 resource='gatherWindow.inviteAFriendText', 145 subs=[('${COUNT}', str(try_tickets))], 146 ), 147 ) 148 invite_button = bui.buttonwidget( 149 parent=container, 150 position=(region_width * 0.59, y - 25), 151 size=(230, 50), 152 color=(0.54, 0.42, 0.56), 153 textcolor=(0, 1, 0), 154 label=bui.Lstr( 155 resource='gatherWindow.inviteFriendsText', 156 fallback_resource='gatherWindow.getFriendInviteCodeText', 157 ), 158 autoselect=True, 159 on_activate_call=bui.WeakCall(self._invite_to_try_press), 160 up_widget=tab_button, 161 show_buffer_top=500, 162 ) 163 y -= invite_height 164 else: 165 invite_button = None 166 167 if show_discord: 168 bui.textwidget( 169 parent=container, 170 position=(region_width * 0.57, y), 171 color=(0.6, 0.6, 1), 172 scale=0.6, 173 size=(0, 0), 174 maxwidth=region_width * 0.5, 175 h_align='right', 176 v_align='center', 177 flatness=1.0, 178 text=bui.Lstr(resource='discordFriendsText'), 179 ) 180 discord_button = bui.buttonwidget( 181 parent=container, 182 position=(region_width * 0.59, y - 25), 183 size=(230, 50), 184 color=(0.54, 0.42, 0.56), 185 textcolor=(0.6, 0.6, 1), 186 label=bui.Lstr(resource='discordJoinText'), 187 autoselect=True, 188 on_activate_call=bui.WeakCall(self._join_the_discord_press), 189 up_widget=( 190 invite_button if invite_button is not None else tab_button 191 ), 192 ) 193 y -= discord_height 194 else: 195 discord_button = None 196 197 if discord_button is not None: 198 pass 199 200 return scroll_widget 201 202 def _invite_to_try_press(self) -> None: 203 from bauiv1lib.account import show_sign_in_prompt 204 from bauiv1lib.appinvite import handle_app_invites_press 205 206 plus = bui.app.plus 207 assert plus is not None 208 209 if plus.get_v1_account_state() != 'signed_in': 210 show_sign_in_prompt() 211 return 212 handle_app_invites_press() 213 214 def _join_the_discord_press(self) -> None: 215 # pylint: disable=cyclic-import 216 from bauiv1lib.discord import DiscordWindow 217 218 assert bui.app.classic is not None 219 DiscordWindow().get_root_widget()
17class AboutGatherTab(GatherTab): 18 """The about tab in the gather UI""" 19 20 @override 21 def on_activate( 22 self, 23 parent_widget: bui.Widget, 24 tab_button: bui.Widget, 25 region_width: float, 26 region_height: float, 27 region_left: float, 28 region_bottom: float, 29 ) -> bui.Widget: 30 # pylint: disable=too-many-locals 31 # pylint: disable=too-many-positional-arguments 32 33 plus = bui.app.plus 34 assert plus is not None 35 36 try_tickets = plus.get_v1_account_misc_read_val( 37 'friendTryTickets', None 38 ) 39 40 show_message = True 41 # Squish message as needed to get things to fit nicely at 42 # various scales. 43 uiscale = bui.app.ui_v1.uiscale 44 message_height = ( 45 210 46 if uiscale is bui.UIScale.SMALL 47 else 305 if uiscale is bui.UIScale.MEDIUM else 370 48 ) 49 # Let's not talk about sharing in vr-mode; its tricky to fit more 50 # than one head in a VR-headset. 51 show_message_extra = not bui.app.env.vr 52 message_extra_height = 60 53 show_invite = try_tickets is not None 54 invite_height = 80 55 show_discord = True 56 discord_height = 80 57 58 c_height = 0 59 if show_message: 60 c_height += message_height 61 if show_message_extra: 62 c_height += message_extra_height 63 if show_invite: 64 c_height += invite_height 65 if show_discord: 66 c_height += discord_height 67 68 party_button_label = bui.charstr(bui.SpecialChar.TOP_BUTTON) 69 message = bui.Lstr( 70 resource='gatherWindow.aboutDescriptionText', 71 subs=[ 72 ('${PARTY}', bui.charstr(bui.SpecialChar.PARTY_ICON)), 73 ('${BUTTON}', party_button_label), 74 ], 75 ) 76 77 if show_message_extra: 78 message = bui.Lstr( 79 value='${A}\n\n${B}', 80 subs=[ 81 ('${A}', message), 82 ( 83 '${B}', 84 bui.Lstr( 85 resource='gatherWindow.' 86 'aboutDescriptionLocalMultiplayerExtraText' 87 ), 88 ), 89 ], 90 ) 91 92 scroll_widget = bui.scrollwidget( 93 parent=parent_widget, 94 position=(region_left, region_bottom), 95 size=(region_width, region_height), 96 highlight=False, 97 border_opacity=0, 98 ) 99 msc_scale = 1.1 100 101 container = bui.containerwidget( 102 parent=scroll_widget, 103 position=( 104 region_left, 105 region_bottom + (region_height - c_height) * 0.5, 106 ), 107 size=(region_width, c_height), 108 background=False, 109 selectable=show_invite or show_discord, 110 ) 111 # Allows escaping if we select the container somehow (though 112 # shouldn't be possible when buttons are present). 113 bui.widget(edit=container, up_widget=tab_button) 114 115 y = c_height - 30 116 if show_message: 117 bui.textwidget( 118 parent=container, 119 position=(region_width * 0.5, y), 120 color=(0.6, 1.0, 0.6), 121 scale=msc_scale, 122 size=(0, 0), 123 maxwidth=region_width * 0.9, 124 max_height=message_height, 125 h_align='center', 126 v_align='top', 127 text=message, 128 ) 129 y -= message_height 130 if show_message_extra: 131 y -= message_extra_height 132 133 if show_invite: 134 bui.textwidget( 135 parent=container, 136 position=(region_width * 0.57, y), 137 color=(0, 1, 0), 138 scale=0.6, 139 size=(0, 0), 140 maxwidth=region_width * 0.5, 141 h_align='right', 142 v_align='center', 143 flatness=1.0, 144 text=bui.Lstr( 145 resource='gatherWindow.inviteAFriendText', 146 subs=[('${COUNT}', str(try_tickets))], 147 ), 148 ) 149 invite_button = bui.buttonwidget( 150 parent=container, 151 position=(region_width * 0.59, y - 25), 152 size=(230, 50), 153 color=(0.54, 0.42, 0.56), 154 textcolor=(0, 1, 0), 155 label=bui.Lstr( 156 resource='gatherWindow.inviteFriendsText', 157 fallback_resource='gatherWindow.getFriendInviteCodeText', 158 ), 159 autoselect=True, 160 on_activate_call=bui.WeakCall(self._invite_to_try_press), 161 up_widget=tab_button, 162 show_buffer_top=500, 163 ) 164 y -= invite_height 165 else: 166 invite_button = None 167 168 if show_discord: 169 bui.textwidget( 170 parent=container, 171 position=(region_width * 0.57, y), 172 color=(0.6, 0.6, 1), 173 scale=0.6, 174 size=(0, 0), 175 maxwidth=region_width * 0.5, 176 h_align='right', 177 v_align='center', 178 flatness=1.0, 179 text=bui.Lstr(resource='discordFriendsText'), 180 ) 181 discord_button = bui.buttonwidget( 182 parent=container, 183 position=(region_width * 0.59, y - 25), 184 size=(230, 50), 185 color=(0.54, 0.42, 0.56), 186 textcolor=(0.6, 0.6, 1), 187 label=bui.Lstr(resource='discordJoinText'), 188 autoselect=True, 189 on_activate_call=bui.WeakCall(self._join_the_discord_press), 190 up_widget=( 191 invite_button if invite_button is not None else tab_button 192 ), 193 ) 194 y -= discord_height 195 else: 196 discord_button = None 197 198 if discord_button is not None: 199 pass 200 201 return scroll_widget 202 203 def _invite_to_try_press(self) -> None: 204 from bauiv1lib.account import show_sign_in_prompt 205 from bauiv1lib.appinvite import handle_app_invites_press 206 207 plus = bui.app.plus 208 assert plus is not None 209 210 if plus.get_v1_account_state() != 'signed_in': 211 show_sign_in_prompt() 212 return 213 handle_app_invites_press() 214 215 def _join_the_discord_press(self) -> None: 216 # pylint: disable=cyclic-import 217 from bauiv1lib.discord import DiscordWindow 218 219 assert bui.app.classic is not None 220 DiscordWindow().get_root_widget()
The about tab in the gather UI
@override
def
on_activate( self, parent_widget: _bauiv1.Widget, tab_button: _bauiv1.Widget, region_width: float, region_height: float, region_left: float, region_bottom: float) -> _bauiv1.Widget:
20 @override 21 def on_activate( 22 self, 23 parent_widget: bui.Widget, 24 tab_button: bui.Widget, 25 region_width: float, 26 region_height: float, 27 region_left: float, 28 region_bottom: float, 29 ) -> bui.Widget: 30 # pylint: disable=too-many-locals 31 # pylint: disable=too-many-positional-arguments 32 33 plus = bui.app.plus 34 assert plus is not None 35 36 try_tickets = plus.get_v1_account_misc_read_val( 37 'friendTryTickets', None 38 ) 39 40 show_message = True 41 # Squish message as needed to get things to fit nicely at 42 # various scales. 43 uiscale = bui.app.ui_v1.uiscale 44 message_height = ( 45 210 46 if uiscale is bui.UIScale.SMALL 47 else 305 if uiscale is bui.UIScale.MEDIUM else 370 48 ) 49 # Let's not talk about sharing in vr-mode; its tricky to fit more 50 # than one head in a VR-headset. 51 show_message_extra = not bui.app.env.vr 52 message_extra_height = 60 53 show_invite = try_tickets is not None 54 invite_height = 80 55 show_discord = True 56 discord_height = 80 57 58 c_height = 0 59 if show_message: 60 c_height += message_height 61 if show_message_extra: 62 c_height += message_extra_height 63 if show_invite: 64 c_height += invite_height 65 if show_discord: 66 c_height += discord_height 67 68 party_button_label = bui.charstr(bui.SpecialChar.TOP_BUTTON) 69 message = bui.Lstr( 70 resource='gatherWindow.aboutDescriptionText', 71 subs=[ 72 ('${PARTY}', bui.charstr(bui.SpecialChar.PARTY_ICON)), 73 ('${BUTTON}', party_button_label), 74 ], 75 ) 76 77 if show_message_extra: 78 message = bui.Lstr( 79 value='${A}\n\n${B}', 80 subs=[ 81 ('${A}', message), 82 ( 83 '${B}', 84 bui.Lstr( 85 resource='gatherWindow.' 86 'aboutDescriptionLocalMultiplayerExtraText' 87 ), 88 ), 89 ], 90 ) 91 92 scroll_widget = bui.scrollwidget( 93 parent=parent_widget, 94 position=(region_left, region_bottom), 95 size=(region_width, region_height), 96 highlight=False, 97 border_opacity=0, 98 ) 99 msc_scale = 1.1 100 101 container = bui.containerwidget( 102 parent=scroll_widget, 103 position=( 104 region_left, 105 region_bottom + (region_height - c_height) * 0.5, 106 ), 107 size=(region_width, c_height), 108 background=False, 109 selectable=show_invite or show_discord, 110 ) 111 # Allows escaping if we select the container somehow (though 112 # shouldn't be possible when buttons are present). 113 bui.widget(edit=container, up_widget=tab_button) 114 115 y = c_height - 30 116 if show_message: 117 bui.textwidget( 118 parent=container, 119 position=(region_width * 0.5, y), 120 color=(0.6, 1.0, 0.6), 121 scale=msc_scale, 122 size=(0, 0), 123 maxwidth=region_width * 0.9, 124 max_height=message_height, 125 h_align='center', 126 v_align='top', 127 text=message, 128 ) 129 y -= message_height 130 if show_message_extra: 131 y -= message_extra_height 132 133 if show_invite: 134 bui.textwidget( 135 parent=container, 136 position=(region_width * 0.57, y), 137 color=(0, 1, 0), 138 scale=0.6, 139 size=(0, 0), 140 maxwidth=region_width * 0.5, 141 h_align='right', 142 v_align='center', 143 flatness=1.0, 144 text=bui.Lstr( 145 resource='gatherWindow.inviteAFriendText', 146 subs=[('${COUNT}', str(try_tickets))], 147 ), 148 ) 149 invite_button = bui.buttonwidget( 150 parent=container, 151 position=(region_width * 0.59, y - 25), 152 size=(230, 50), 153 color=(0.54, 0.42, 0.56), 154 textcolor=(0, 1, 0), 155 label=bui.Lstr( 156 resource='gatherWindow.inviteFriendsText', 157 fallback_resource='gatherWindow.getFriendInviteCodeText', 158 ), 159 autoselect=True, 160 on_activate_call=bui.WeakCall(self._invite_to_try_press), 161 up_widget=tab_button, 162 show_buffer_top=500, 163 ) 164 y -= invite_height 165 else: 166 invite_button = None 167 168 if show_discord: 169 bui.textwidget( 170 parent=container, 171 position=(region_width * 0.57, y), 172 color=(0.6, 0.6, 1), 173 scale=0.6, 174 size=(0, 0), 175 maxwidth=region_width * 0.5, 176 h_align='right', 177 v_align='center', 178 flatness=1.0, 179 text=bui.Lstr(resource='discordFriendsText'), 180 ) 181 discord_button = bui.buttonwidget( 182 parent=container, 183 position=(region_width * 0.59, y - 25), 184 size=(230, 50), 185 color=(0.54, 0.42, 0.56), 186 textcolor=(0.6, 0.6, 1), 187 label=bui.Lstr(resource='discordJoinText'), 188 autoselect=True, 189 on_activate_call=bui.WeakCall(self._join_the_discord_press), 190 up_widget=( 191 invite_button if invite_button is not None else tab_button 192 ), 193 ) 194 y -= discord_height 195 else: 196 discord_button = None 197 198 if discord_button is not None: 199 pass 200 201 return scroll_widget
Called when the tab becomes the active one.
The tab should create and return a container widget covering the specified region.