bastd.ui.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 8 9import ba 10import _ba 11from bastd.ui.gather import GatherTab 12 13if TYPE_CHECKING: 14 from bastd.ui.gather import GatherWindow 15 16 17class AboutGatherTab(GatherTab): 18 """The about tab in the gather UI""" 19 20 def __init__(self, window: GatherWindow) -> None: 21 super().__init__(window) 22 self._container: ba.Widget | None = None 23 24 def on_activate( 25 self, 26 parent_widget: ba.Widget, 27 tab_button: ba.Widget, 28 region_width: float, 29 region_height: float, 30 region_left: float, 31 region_bottom: float, 32 ) -> ba.Widget: 33 party_button_label = ('X' if ba.app.iircade_mode else ba.charstr( 34 ba.SpecialChar.TOP_BUTTON)) 35 message = ba.Lstr( 36 resource='gatherWindow.aboutDescriptionText', 37 subs=[('${PARTY}', ba.charstr(ba.SpecialChar.PARTY_ICON)), 38 ('${BUTTON}', party_button_label)], 39 ) 40 41 # Let's not talk about sharing in vr-mode; its tricky to fit more 42 # than one head in a VR-headset ;-) 43 if not ba.app.vr_mode: 44 message = ba.Lstr( 45 value='${A}\n\n${B}', 46 subs=[('${A}', message), 47 ('${B}', 48 ba.Lstr(resource='gatherWindow.' 49 'aboutDescriptionLocalMultiplayerExtraText'))]) 50 string_height = 400 51 include_invite = True 52 msc_scale = 1.1 53 c_height_2 = min(region_height, string_height * msc_scale + 100) 54 try_tickets = _ba.get_v1_account_misc_read_val('friendTryTickets', 55 None) 56 if try_tickets is None: 57 include_invite = False 58 self._container = ba.containerwidget( 59 parent=parent_widget, 60 position=(region_left, 61 region_bottom + (region_height - c_height_2) * 0.5), 62 size=(region_width, c_height_2), 63 background=False, 64 selectable=include_invite) 65 ba.widget(edit=self._container, up_widget=tab_button) 66 67 ba.textwidget(parent=self._container, 68 position=(region_width * 0.5, c_height_2 * 69 (0.58 if include_invite else 0.5)), 70 color=(0.6, 1.0, 0.6), 71 scale=msc_scale, 72 size=(0, 0), 73 maxwidth=region_width * 0.9, 74 max_height=c_height_2 * (0.7 if include_invite else 0.9), 75 h_align='center', 76 v_align='center', 77 text=message) 78 79 if include_invite: 80 ba.textwidget(parent=self._container, 81 position=(region_width * 0.57, 35), 82 color=(0, 1, 0), 83 scale=0.6, 84 size=(0, 0), 85 maxwidth=region_width * 0.5, 86 h_align='right', 87 v_align='center', 88 flatness=1.0, 89 text=ba.Lstr( 90 resource='gatherWindow.inviteAFriendText', 91 subs=[('${COUNT}', str(try_tickets))])) 92 ba.buttonwidget( 93 parent=self._container, 94 position=(region_width * 0.59, 10), 95 size=(230, 50), 96 color=(0.54, 0.42, 0.56), 97 textcolor=(0, 1, 0), 98 label=ba.Lstr(resource='gatherWindow.inviteFriendsText', 99 fallback_resource=( 100 'gatherWindow.getFriendInviteCodeText')), 101 autoselect=True, 102 on_activate_call=ba.WeakCall(self._invite_to_try_press), 103 up_widget=tab_button) 104 return self._container 105 106 def _invite_to_try_press(self) -> None: 107 from bastd.ui.account import show_sign_in_prompt 108 from bastd.ui.appinvite import handle_app_invites_press 109 if _ba.get_v1_account_state() != 'signed_in': 110 show_sign_in_prompt() 111 return 112 handle_app_invites_press()
18class AboutGatherTab(GatherTab): 19 """The about tab in the gather UI""" 20 21 def __init__(self, window: GatherWindow) -> None: 22 super().__init__(window) 23 self._container: ba.Widget | None = None 24 25 def on_activate( 26 self, 27 parent_widget: ba.Widget, 28 tab_button: ba.Widget, 29 region_width: float, 30 region_height: float, 31 region_left: float, 32 region_bottom: float, 33 ) -> ba.Widget: 34 party_button_label = ('X' if ba.app.iircade_mode else ba.charstr( 35 ba.SpecialChar.TOP_BUTTON)) 36 message = ba.Lstr( 37 resource='gatherWindow.aboutDescriptionText', 38 subs=[('${PARTY}', ba.charstr(ba.SpecialChar.PARTY_ICON)), 39 ('${BUTTON}', party_button_label)], 40 ) 41 42 # Let's not talk about sharing in vr-mode; its tricky to fit more 43 # than one head in a VR-headset ;-) 44 if not ba.app.vr_mode: 45 message = ba.Lstr( 46 value='${A}\n\n${B}', 47 subs=[('${A}', message), 48 ('${B}', 49 ba.Lstr(resource='gatherWindow.' 50 'aboutDescriptionLocalMultiplayerExtraText'))]) 51 string_height = 400 52 include_invite = True 53 msc_scale = 1.1 54 c_height_2 = min(region_height, string_height * msc_scale + 100) 55 try_tickets = _ba.get_v1_account_misc_read_val('friendTryTickets', 56 None) 57 if try_tickets is None: 58 include_invite = False 59 self._container = ba.containerwidget( 60 parent=parent_widget, 61 position=(region_left, 62 region_bottom + (region_height - c_height_2) * 0.5), 63 size=(region_width, c_height_2), 64 background=False, 65 selectable=include_invite) 66 ba.widget(edit=self._container, up_widget=tab_button) 67 68 ba.textwidget(parent=self._container, 69 position=(region_width * 0.5, c_height_2 * 70 (0.58 if include_invite else 0.5)), 71 color=(0.6, 1.0, 0.6), 72 scale=msc_scale, 73 size=(0, 0), 74 maxwidth=region_width * 0.9, 75 max_height=c_height_2 * (0.7 if include_invite else 0.9), 76 h_align='center', 77 v_align='center', 78 text=message) 79 80 if include_invite: 81 ba.textwidget(parent=self._container, 82 position=(region_width * 0.57, 35), 83 color=(0, 1, 0), 84 scale=0.6, 85 size=(0, 0), 86 maxwidth=region_width * 0.5, 87 h_align='right', 88 v_align='center', 89 flatness=1.0, 90 text=ba.Lstr( 91 resource='gatherWindow.inviteAFriendText', 92 subs=[('${COUNT}', str(try_tickets))])) 93 ba.buttonwidget( 94 parent=self._container, 95 position=(region_width * 0.59, 10), 96 size=(230, 50), 97 color=(0.54, 0.42, 0.56), 98 textcolor=(0, 1, 0), 99 label=ba.Lstr(resource='gatherWindow.inviteFriendsText', 100 fallback_resource=( 101 'gatherWindow.getFriendInviteCodeText')), 102 autoselect=True, 103 on_activate_call=ba.WeakCall(self._invite_to_try_press), 104 up_widget=tab_button) 105 return self._container 106 107 def _invite_to_try_press(self) -> None: 108 from bastd.ui.account import show_sign_in_prompt 109 from bastd.ui.appinvite import handle_app_invites_press 110 if _ba.get_v1_account_state() != 'signed_in': 111 show_sign_in_prompt() 112 return 113 handle_app_invites_press()
The about tab in the gather UI
AboutGatherTab(window: bastd.ui.gather.GatherWindow)
def
on_activate( self, parent_widget: _ba.Widget, tab_button: _ba.Widget, region_width: float, region_height: float, region_left: float, region_bottom: float) -> _ba.Widget:
25 def on_activate( 26 self, 27 parent_widget: ba.Widget, 28 tab_button: ba.Widget, 29 region_width: float, 30 region_height: float, 31 region_left: float, 32 region_bottom: float, 33 ) -> ba.Widget: 34 party_button_label = ('X' if ba.app.iircade_mode else ba.charstr( 35 ba.SpecialChar.TOP_BUTTON)) 36 message = ba.Lstr( 37 resource='gatherWindow.aboutDescriptionText', 38 subs=[('${PARTY}', ba.charstr(ba.SpecialChar.PARTY_ICON)), 39 ('${BUTTON}', party_button_label)], 40 ) 41 42 # Let's not talk about sharing in vr-mode; its tricky to fit more 43 # than one head in a VR-headset ;-) 44 if not ba.app.vr_mode: 45 message = ba.Lstr( 46 value='${A}\n\n${B}', 47 subs=[('${A}', message), 48 ('${B}', 49 ba.Lstr(resource='gatherWindow.' 50 'aboutDescriptionLocalMultiplayerExtraText'))]) 51 string_height = 400 52 include_invite = True 53 msc_scale = 1.1 54 c_height_2 = min(region_height, string_height * msc_scale + 100) 55 try_tickets = _ba.get_v1_account_misc_read_val('friendTryTickets', 56 None) 57 if try_tickets is None: 58 include_invite = False 59 self._container = ba.containerwidget( 60 parent=parent_widget, 61 position=(region_left, 62 region_bottom + (region_height - c_height_2) * 0.5), 63 size=(region_width, c_height_2), 64 background=False, 65 selectable=include_invite) 66 ba.widget(edit=self._container, up_widget=tab_button) 67 68 ba.textwidget(parent=self._container, 69 position=(region_width * 0.5, c_height_2 * 70 (0.58 if include_invite else 0.5)), 71 color=(0.6, 1.0, 0.6), 72 scale=msc_scale, 73 size=(0, 0), 74 maxwidth=region_width * 0.9, 75 max_height=c_height_2 * (0.7 if include_invite else 0.9), 76 h_align='center', 77 v_align='center', 78 text=message) 79 80 if include_invite: 81 ba.textwidget(parent=self._container, 82 position=(region_width * 0.57, 35), 83 color=(0, 1, 0), 84 scale=0.6, 85 size=(0, 0), 86 maxwidth=region_width * 0.5, 87 h_align='right', 88 v_align='center', 89 flatness=1.0, 90 text=ba.Lstr( 91 resource='gatherWindow.inviteAFriendText', 92 subs=[('${COUNT}', str(try_tickets))])) 93 ba.buttonwidget( 94 parent=self._container, 95 position=(region_width * 0.59, 10), 96 size=(230, 50), 97 color=(0.54, 0.42, 0.56), 98 textcolor=(0, 1, 0), 99 label=ba.Lstr(resource='gatherWindow.inviteFriendsText', 100 fallback_resource=( 101 'gatherWindow.getFriendInviteCodeText')), 102 autoselect=True, 103 on_activate_call=ba.WeakCall(self._invite_to_try_press), 104 up_widget=tab_button) 105 return self._container
Called when the tab becomes the active one.
The tab should create and return a container widget covering the specified region.