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

The about tab in the gather UI

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

Called when the tab becomes the active one.

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