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
 31        plus = bui.app.plus
 32        assert plus is not None
 33
 34        try_tickets = plus.get_v1_account_misc_read_val(
 35            'friendTryTickets', None
 36        )
 37
 38        show_message = True
 39        # Squish message as needed to get things to fit nicely at
 40        # various scales.
 41        uiscale = bui.app.ui_v1.uiscale
 42        message_height = (
 43            210
 44            if uiscale is bui.UIScale.SMALL
 45            else 305 if uiscale is bui.UIScale.MEDIUM else 370
 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        show_message_extra = not bui.app.env.vr
 50        message_extra_height = 60
 51        show_invite = try_tickets is not None
 52        invite_height = 80
 53        show_discord = True
 54        discord_height = 80
 55
 56        c_height = 0
 57        if show_message:
 58            c_height += message_height
 59        if show_message_extra:
 60            c_height += message_extra_height
 61        if show_invite:
 62            c_height += invite_height
 63        if show_discord:
 64            c_height += discord_height
 65
 66        party_button_label = bui.charstr(bui.SpecialChar.TOP_BUTTON)
 67        message = bui.Lstr(
 68            resource='gatherWindow.aboutDescriptionText',
 69            subs=[
 70                ('${PARTY}', bui.charstr(bui.SpecialChar.PARTY_ICON)),
 71                ('${BUTTON}', party_button_label),
 72            ],
 73        )
 74
 75        if show_message_extra:
 76            message = bui.Lstr(
 77                value='${A}\n\n${B}',
 78                subs=[
 79                    ('${A}', message),
 80                    (
 81                        '${B}',
 82                        bui.Lstr(
 83                            resource='gatherWindow.'
 84                            'aboutDescriptionLocalMultiplayerExtraText'
 85                        ),
 86                    ),
 87                ],
 88            )
 89
 90        scroll_widget = bui.scrollwidget(
 91            parent=parent_widget,
 92            position=(region_left, region_bottom),
 93            size=(region_width, region_height),
 94            highlight=False,
 95            border_opacity=0,
 96        )
 97        msc_scale = 1.1
 98
 99        container = bui.containerwidget(
100            parent=scroll_widget,
101            position=(
102                region_left,
103                region_bottom + (region_height - c_height) * 0.5,
104            ),
105            size=(region_width, c_height),
106            background=False,
107            selectable=show_invite or show_discord,
108        )
109        # Allows escaping if we select the container somehow (though
110        # shouldn't be possible when buttons are present).
111        bui.widget(edit=container, up_widget=tab_button)
112
113        y = c_height - 30
114        if show_message:
115            bui.textwidget(
116                parent=container,
117                position=(region_width * 0.5, y),
118                color=(0.6, 1.0, 0.6),
119                scale=msc_scale,
120                size=(0, 0),
121                maxwidth=region_width * 0.9,
122                max_height=message_height,
123                h_align='center',
124                v_align='top',
125                text=message,
126            )
127            y -= message_height
128            if show_message_extra:
129                y -= message_extra_height
130
131        if show_invite:
132            bui.textwidget(
133                parent=container,
134                position=(region_width * 0.57, y),
135                color=(0, 1, 0),
136                scale=0.6,
137                size=(0, 0),
138                maxwidth=region_width * 0.5,
139                h_align='right',
140                v_align='center',
141                flatness=1.0,
142                text=bui.Lstr(
143                    resource='gatherWindow.inviteAFriendText',
144                    subs=[('${COUNT}', str(try_tickets))],
145                ),
146            )
147            invite_button = bui.buttonwidget(
148                parent=container,
149                position=(region_width * 0.59, y - 25),
150                size=(230, 50),
151                color=(0.54, 0.42, 0.56),
152                textcolor=(0, 1, 0),
153                label=bui.Lstr(
154                    resource='gatherWindow.inviteFriendsText',
155                    fallback_resource='gatherWindow.getFriendInviteCodeText',
156                ),
157                autoselect=True,
158                on_activate_call=bui.WeakCall(self._invite_to_try_press),
159                up_widget=tab_button,
160            )
161            y -= invite_height
162        else:
163            invite_button = None
164
165        if show_discord:
166            bui.textwidget(
167                parent=container,
168                position=(region_width * 0.57, y),
169                color=(0.6, 0.6, 1),
170                scale=0.6,
171                size=(0, 0),
172                maxwidth=region_width * 0.5,
173                h_align='right',
174                v_align='center',
175                flatness=1.0,
176                text=bui.Lstr(resource='discordFriendsText'),
177            )
178            discord_button = bui.buttonwidget(
179                parent=container,
180                position=(region_width * 0.59, y - 25),
181                size=(230, 50),
182                color=(0.54, 0.42, 0.56),
183                textcolor=(0.6, 0.6, 1),
184                label=bui.Lstr(resource='discordJoinText'),
185                autoselect=True,
186                on_activate_call=bui.WeakCall(self._join_the_discord_press),
187                up_widget=(
188                    invite_button if invite_button is not None else tab_button
189                ),
190            )
191            y -= discord_height
192        else:
193            discord_button = None
194
195        if discord_button is not None:
196            pass
197
198        return scroll_widget
199
200    def _invite_to_try_press(self) -> None:
201        from bauiv1lib.account import show_sign_in_prompt
202        from bauiv1lib.appinvite import handle_app_invites_press
203
204        plus = bui.app.plus
205        assert plus is not None
206
207        if plus.get_v1_account_state() != 'signed_in':
208            show_sign_in_prompt()
209            return
210        handle_app_invites_press()
211
212    def _join_the_discord_press(self) -> None:
213        # pylint: disable=cyclic-import
214        from bauiv1lib.discord import DiscordWindow
215
216        assert bui.app.classic is not None
217        DiscordWindow().get_root_widget()
class AboutGatherTab(bauiv1lib.gather.GatherTab):
 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
 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            )
162            y -= invite_height
163        else:
164            invite_button = None
165
166        if show_discord:
167            bui.textwidget(
168                parent=container,
169                position=(region_width * 0.57, y),
170                color=(0.6, 0.6, 1),
171                scale=0.6,
172                size=(0, 0),
173                maxwidth=region_width * 0.5,
174                h_align='right',
175                v_align='center',
176                flatness=1.0,
177                text=bui.Lstr(resource='discordFriendsText'),
178            )
179            discord_button = bui.buttonwidget(
180                parent=container,
181                position=(region_width * 0.59, y - 25),
182                size=(230, 50),
183                color=(0.54, 0.42, 0.56),
184                textcolor=(0.6, 0.6, 1),
185                label=bui.Lstr(resource='discordJoinText'),
186                autoselect=True,
187                on_activate_call=bui.WeakCall(self._join_the_discord_press),
188                up_widget=(
189                    invite_button if invite_button is not None else tab_button
190                ),
191            )
192            y -= discord_height
193        else:
194            discord_button = None
195
196        if discord_button is not None:
197            pass
198
199        return scroll_widget
200
201    def _invite_to_try_press(self) -> None:
202        from bauiv1lib.account import show_sign_in_prompt
203        from bauiv1lib.appinvite import handle_app_invites_press
204
205        plus = bui.app.plus
206        assert plus is not None
207
208        if plus.get_v1_account_state() != 'signed_in':
209            show_sign_in_prompt()
210            return
211        handle_app_invites_press()
212
213    def _join_the_discord_press(self) -> None:
214        # pylint: disable=cyclic-import
215        from bauiv1lib.discord import DiscordWindow
216
217        assert bui.app.classic is not None
218        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
 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            )
162            y -= invite_height
163        else:
164            invite_button = None
165
166        if show_discord:
167            bui.textwidget(
168                parent=container,
169                position=(region_width * 0.57, y),
170                color=(0.6, 0.6, 1),
171                scale=0.6,
172                size=(0, 0),
173                maxwidth=region_width * 0.5,
174                h_align='right',
175                v_align='center',
176                flatness=1.0,
177                text=bui.Lstr(resource='discordFriendsText'),
178            )
179            discord_button = bui.buttonwidget(
180                parent=container,
181                position=(region_width * 0.59, y - 25),
182                size=(230, 50),
183                color=(0.54, 0.42, 0.56),
184                textcolor=(0.6, 0.6, 1),
185                label=bui.Lstr(resource='discordJoinText'),
186                autoselect=True,
187                on_activate_call=bui.WeakCall(self._join_the_discord_press),
188                up_widget=(
189                    invite_button if invite_button is not None else tab_button
190                ),
191            )
192            y -= discord_height
193        else:
194            discord_button = None
195
196        if discord_button is not None:
197            pass
198
199        return scroll_widget

Called when the tab becomes the active one.

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