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.internal
 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 = (
 34            'X'
 35            if ba.app.iircade_mode
 36            else ba.charstr(ba.SpecialChar.TOP_BUTTON)
 37        )
 38        message = ba.Lstr(
 39            resource='gatherWindow.aboutDescriptionText',
 40            subs=[
 41                ('${PARTY}', ba.charstr(ba.SpecialChar.PARTY_ICON)),
 42                ('${BUTTON}', party_button_label),
 43            ],
 44        )
 45
 46        # Let's not talk about sharing in vr-mode; its tricky to fit more
 47        # than one head in a VR-headset ;-)
 48        if not ba.app.vr_mode:
 49            message = ba.Lstr(
 50                value='${A}\n\n${B}',
 51                subs=[
 52                    ('${A}', message),
 53                    (
 54                        '${B}',
 55                        ba.Lstr(
 56                            resource='gatherWindow.'
 57                            'aboutDescriptionLocalMultiplayerExtraText'
 58                        ),
 59                    ),
 60                ],
 61            )
 62        string_height = 400
 63        include_invite = True
 64        msc_scale = 1.1
 65        c_height_2 = min(region_height, string_height * msc_scale + 100)
 66        try_tickets = ba.internal.get_v1_account_misc_read_val(
 67            'friendTryTickets', None
 68        )
 69        if try_tickets is None:
 70            include_invite = False
 71        self._container = ba.containerwidget(
 72            parent=parent_widget,
 73            position=(
 74                region_left,
 75                region_bottom + (region_height - c_height_2) * 0.5,
 76            ),
 77            size=(region_width, c_height_2),
 78            background=False,
 79            selectable=include_invite,
 80        )
 81        ba.widget(edit=self._container, up_widget=tab_button)
 82
 83        ba.textwidget(
 84            parent=self._container,
 85            position=(
 86                region_width * 0.5,
 87                c_height_2 * (0.58 if include_invite else 0.5),
 88            ),
 89            color=(0.6, 1.0, 0.6),
 90            scale=msc_scale,
 91            size=(0, 0),
 92            maxwidth=region_width * 0.9,
 93            max_height=c_height_2 * (0.7 if include_invite else 0.9),
 94            h_align='center',
 95            v_align='center',
 96            text=message,
 97        )
 98
 99        if include_invite:
100            ba.textwidget(
101                parent=self._container,
102                position=(region_width * 0.57, 35),
103                color=(0, 1, 0),
104                scale=0.6,
105                size=(0, 0),
106                maxwidth=region_width * 0.5,
107                h_align='right',
108                v_align='center',
109                flatness=1.0,
110                text=ba.Lstr(
111                    resource='gatherWindow.inviteAFriendText',
112                    subs=[('${COUNT}', str(try_tickets))],
113                ),
114            )
115            ba.buttonwidget(
116                parent=self._container,
117                position=(region_width * 0.59, 10),
118                size=(230, 50),
119                color=(0.54, 0.42, 0.56),
120                textcolor=(0, 1, 0),
121                label=ba.Lstr(
122                    resource='gatherWindow.inviteFriendsText',
123                    fallback_resource='gatherWindow.getFriendInviteCodeText',
124                ),
125                autoselect=True,
126                on_activate_call=ba.WeakCall(self._invite_to_try_press),
127                up_widget=tab_button,
128            )
129        return self._container
130
131    def _invite_to_try_press(self) -> None:
132        from bastd.ui.account import show_sign_in_prompt
133        from bastd.ui.appinvite import handle_app_invites_press
134
135        if ba.internal.get_v1_account_state() != 'signed_in':
136            show_sign_in_prompt()
137            return
138        handle_app_invites_press()
class AboutGatherTab(bastd.ui.gather.GatherTab):
 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 = (
 35            'X'
 36            if ba.app.iircade_mode
 37            else ba.charstr(ba.SpecialChar.TOP_BUTTON)
 38        )
 39        message = ba.Lstr(
 40            resource='gatherWindow.aboutDescriptionText',
 41            subs=[
 42                ('${PARTY}', ba.charstr(ba.SpecialChar.PARTY_ICON)),
 43                ('${BUTTON}', party_button_label),
 44            ],
 45        )
 46
 47        # Let's not talk about sharing in vr-mode; its tricky to fit more
 48        # than one head in a VR-headset ;-)
 49        if not ba.app.vr_mode:
 50            message = ba.Lstr(
 51                value='${A}\n\n${B}',
 52                subs=[
 53                    ('${A}', message),
 54                    (
 55                        '${B}',
 56                        ba.Lstr(
 57                            resource='gatherWindow.'
 58                            'aboutDescriptionLocalMultiplayerExtraText'
 59                        ),
 60                    ),
 61                ],
 62            )
 63        string_height = 400
 64        include_invite = True
 65        msc_scale = 1.1
 66        c_height_2 = min(region_height, string_height * msc_scale + 100)
 67        try_tickets = ba.internal.get_v1_account_misc_read_val(
 68            'friendTryTickets', None
 69        )
 70        if try_tickets is None:
 71            include_invite = False
 72        self._container = ba.containerwidget(
 73            parent=parent_widget,
 74            position=(
 75                region_left,
 76                region_bottom + (region_height - c_height_2) * 0.5,
 77            ),
 78            size=(region_width, c_height_2),
 79            background=False,
 80            selectable=include_invite,
 81        )
 82        ba.widget(edit=self._container, up_widget=tab_button)
 83
 84        ba.textwidget(
 85            parent=self._container,
 86            position=(
 87                region_width * 0.5,
 88                c_height_2 * (0.58 if include_invite else 0.5),
 89            ),
 90            color=(0.6, 1.0, 0.6),
 91            scale=msc_scale,
 92            size=(0, 0),
 93            maxwidth=region_width * 0.9,
 94            max_height=c_height_2 * (0.7 if include_invite else 0.9),
 95            h_align='center',
 96            v_align='center',
 97            text=message,
 98        )
 99
100        if include_invite:
101            ba.textwidget(
102                parent=self._container,
103                position=(region_width * 0.57, 35),
104                color=(0, 1, 0),
105                scale=0.6,
106                size=(0, 0),
107                maxwidth=region_width * 0.5,
108                h_align='right',
109                v_align='center',
110                flatness=1.0,
111                text=ba.Lstr(
112                    resource='gatherWindow.inviteAFriendText',
113                    subs=[('${COUNT}', str(try_tickets))],
114                ),
115            )
116            ba.buttonwidget(
117                parent=self._container,
118                position=(region_width * 0.59, 10),
119                size=(230, 50),
120                color=(0.54, 0.42, 0.56),
121                textcolor=(0, 1, 0),
122                label=ba.Lstr(
123                    resource='gatherWindow.inviteFriendsText',
124                    fallback_resource='gatherWindow.getFriendInviteCodeText',
125                ),
126                autoselect=True,
127                on_activate_call=ba.WeakCall(self._invite_to_try_press),
128                up_widget=tab_button,
129            )
130        return self._container
131
132    def _invite_to_try_press(self) -> None:
133        from bastd.ui.account import show_sign_in_prompt
134        from bastd.ui.appinvite import handle_app_invites_press
135
136        if ba.internal.get_v1_account_state() != 'signed_in':
137            show_sign_in_prompt()
138            return
139        handle_app_invites_press()

The about tab in the gather UI

AboutGatherTab(window: bastd.ui.gather.GatherWindow)
21    def __init__(self, window: GatherWindow) -> None:
22        super().__init__(window)
23        self._container: ba.Widget | None = None
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 = (
 35            'X'
 36            if ba.app.iircade_mode
 37            else ba.charstr(ba.SpecialChar.TOP_BUTTON)
 38        )
 39        message = ba.Lstr(
 40            resource='gatherWindow.aboutDescriptionText',
 41            subs=[
 42                ('${PARTY}', ba.charstr(ba.SpecialChar.PARTY_ICON)),
 43                ('${BUTTON}', party_button_label),
 44            ],
 45        )
 46
 47        # Let's not talk about sharing in vr-mode; its tricky to fit more
 48        # than one head in a VR-headset ;-)
 49        if not ba.app.vr_mode:
 50            message = ba.Lstr(
 51                value='${A}\n\n${B}',
 52                subs=[
 53                    ('${A}', message),
 54                    (
 55                        '${B}',
 56                        ba.Lstr(
 57                            resource='gatherWindow.'
 58                            'aboutDescriptionLocalMultiplayerExtraText'
 59                        ),
 60                    ),
 61                ],
 62            )
 63        string_height = 400
 64        include_invite = True
 65        msc_scale = 1.1
 66        c_height_2 = min(region_height, string_height * msc_scale + 100)
 67        try_tickets = ba.internal.get_v1_account_misc_read_val(
 68            'friendTryTickets', None
 69        )
 70        if try_tickets is None:
 71            include_invite = False
 72        self._container = ba.containerwidget(
 73            parent=parent_widget,
 74            position=(
 75                region_left,
 76                region_bottom + (region_height - c_height_2) * 0.5,
 77            ),
 78            size=(region_width, c_height_2),
 79            background=False,
 80            selectable=include_invite,
 81        )
 82        ba.widget(edit=self._container, up_widget=tab_button)
 83
 84        ba.textwidget(
 85            parent=self._container,
 86            position=(
 87                region_width * 0.5,
 88                c_height_2 * (0.58 if include_invite else 0.5),
 89            ),
 90            color=(0.6, 1.0, 0.6),
 91            scale=msc_scale,
 92            size=(0, 0),
 93            maxwidth=region_width * 0.9,
 94            max_height=c_height_2 * (0.7 if include_invite else 0.9),
 95            h_align='center',
 96            v_align='center',
 97            text=message,
 98        )
 99
100        if include_invite:
101            ba.textwidget(
102                parent=self._container,
103                position=(region_width * 0.57, 35),
104                color=(0, 1, 0),
105                scale=0.6,
106                size=(0, 0),
107                maxwidth=region_width * 0.5,
108                h_align='right',
109                v_align='center',
110                flatness=1.0,
111                text=ba.Lstr(
112                    resource='gatherWindow.inviteAFriendText',
113                    subs=[('${COUNT}', str(try_tickets))],
114                ),
115            )
116            ba.buttonwidget(
117                parent=self._container,
118                position=(region_width * 0.59, 10),
119                size=(230, 50),
120                color=(0.54, 0.42, 0.56),
121                textcolor=(0, 1, 0),
122                label=ba.Lstr(
123                    resource='gatherWindow.inviteFriendsText',
124                    fallback_resource='gatherWindow.getFriendInviteCodeText',
125                ),
126                autoselect=True,
127                on_activate_call=ba.WeakCall(self._invite_to_try_press),
128                up_widget=tab_button,
129            )
130        return self._container

Called when the tab becomes the active one.

The tab should create and return a container widget covering the specified region.