bastd.ui.appinvite

UI functionality related to inviting people to try the game.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""UI functionality related to inviting people to try the game."""
  4
  5from __future__ import annotations
  6
  7import copy
  8import time
  9from typing import TYPE_CHECKING
 10
 11import _ba
 12import ba
 13
 14if TYPE_CHECKING:
 15    from typing import Any
 16
 17
 18class AppInviteWindow(ba.Window):
 19    """Window for showing different ways to invite people to try the game."""
 20
 21    def __init__(self) -> None:
 22        ba.set_analytics_screen('AppInviteWindow')
 23        self._data: dict[str, Any] | None = None
 24        self._width = 650
 25        self._height = 400
 26
 27        uiscale = ba.app.ui.uiscale
 28        super().__init__(root_widget=ba.containerwidget(
 29            size=(self._width, self._height),
 30            transition='in_scale',
 31            scale=(1.8 if uiscale is ba.UIScale.SMALL else
 32                   1.35 if uiscale is ba.UIScale.MEDIUM else 1.0)))
 33
 34        self._cancel_button = ba.buttonwidget(parent=self._root_widget,
 35                                              scale=0.8,
 36                                              position=(60, self._height - 50),
 37                                              size=(50, 50),
 38                                              label='',
 39                                              on_activate_call=self.close,
 40                                              autoselect=True,
 41                                              color=(0.4, 0.4, 0.6),
 42                                              icon=ba.gettexture('crossOut'),
 43                                              iconscale=1.2)
 44
 45        ba.containerwidget(edit=self._root_widget,
 46                           cancel_button=self._cancel_button)
 47
 48        ba.textwidget(
 49            parent=self._root_widget,
 50            size=(0, 0),
 51            position=(self._width * 0.5, self._height * 0.5 + 110),
 52            autoselect=True,
 53            scale=0.8,
 54            maxwidth=self._width * 0.9,
 55            h_align='center',
 56            v_align='center',
 57            color=(0.3, 0.8, 0.3),
 58            flatness=1.0,
 59            text=ba.Lstr(
 60                resource='gatherWindow.earnTicketsForRecommendingAmountText',
 61                fallback_resource=(
 62                    'gatherWindow.earnTicketsForRecommendingText'),
 63                subs=[('${COUNT}',
 64                       str(
 65                           _ba.get_v1_account_misc_read_val(
 66                               'friendTryTickets', 300))),
 67                      ('${YOU_COUNT}',
 68                       str(
 69                           _ba.get_v1_account_misc_read_val(
 70                               'friendTryAwardTickets', 100)))]))
 71
 72        or_text = ba.Lstr(resource='orText',
 73                          subs=[('${A}', ''),
 74                                ('${B}', '')]).evaluate().strip()
 75        ba.buttonwidget(
 76            parent=self._root_widget,
 77            size=(250, 150),
 78            position=(self._width * 0.5 - 125, self._height * 0.5 - 80),
 79            autoselect=True,
 80            button_type='square',
 81            label=ba.Lstr(resource='gatherWindow.inviteFriendsText'),
 82            on_activate_call=ba.WeakCall(self._google_invites))
 83
 84        ba.textwidget(parent=self._root_widget,
 85                      size=(0, 0),
 86                      position=(self._width * 0.5, self._height * 0.5 - 94),
 87                      autoselect=True,
 88                      scale=0.9,
 89                      h_align='center',
 90                      v_align='center',
 91                      color=(0.5, 0.5, 0.5),
 92                      flatness=1.0,
 93                      text=or_text)
 94
 95        ba.buttonwidget(
 96            parent=self._root_widget,
 97            size=(180, 50),
 98            position=(self._width * 0.5 - 90, self._height * 0.5 - 170),
 99            autoselect=True,
100            color=(0.5, 0.5, 0.6),
101            textcolor=(0.7, 0.7, 0.8),
102            text_scale=0.8,
103            label=ba.Lstr(resource='gatherWindow.appInviteSendACodeText'),
104            on_activate_call=ba.WeakCall(self._send_code))
105
106        # kick off a transaction to get our code
107        _ba.add_transaction(
108            {
109                'type': 'FRIEND_PROMO_CODE_REQUEST',
110                'ali': False,
111                'expire_time': time.time() + 20
112            },
113            callback=ba.WeakCall(self._on_code_result))
114        _ba.run_transactions()
115
116    def _on_code_result(self, result: dict[str, Any] | None) -> None:
117        if result is not None:
118            self._data = result
119
120    def _send_code(self) -> None:
121        handle_app_invites_press(force_code=True)
122
123    def _google_invites(self) -> None:
124        if self._data is None:
125            ba.screenmessage(ba.Lstr(
126                resource='getTicketsWindow.unavailableTemporarilyText'),
127                             color=(1, 0, 0))
128            ba.playsound(ba.getsound('error'))
129            return
130
131        if _ba.get_v1_account_state() == 'signed_in':
132            ba.set_analytics_screen('App Invite UI')
133            _ba.show_app_invite(
134                ba.Lstr(resource='gatherWindow.appInviteTitleText',
135                        subs=[('${APP_NAME}', ba.Lstr(resource='titleText'))
136                              ]).evaluate(),
137                ba.Lstr(resource='gatherWindow.appInviteMessageText',
138                        subs=[
139                            ('${COUNT}', str(self._data['tickets'])),
140                            ('${NAME}', _ba.get_v1_account_name().split()[0]),
141                            ('${APP_NAME}', ba.Lstr(resource='titleText'))
142                        ]).evaluate(), self._data['code'])
143        else:
144            ba.playsound(ba.getsound('error'))
145
146    def close(self) -> None:
147        """Close the window."""
148        ba.containerwidget(edit=self._root_widget, transition='out_scale')
149
150
151class ShowFriendCodeWindow(ba.Window):
152    """Window showing a code for sharing with friends."""
153
154    def __init__(self, data: dict[str, Any]):
155        from ba.internal import is_browser_likely_available
156        ba.set_analytics_screen('Friend Promo Code')
157        self._width = 650
158        self._height = 400
159        uiscale = ba.app.ui.uiscale
160        super().__init__(root_widget=ba.containerwidget(
161            size=(self._width, self._height),
162            color=(0.45, 0.63, 0.15),
163            transition='in_scale',
164            scale=(1.7 if uiscale is ba.UIScale.SMALL else
165                   1.35 if uiscale is ba.UIScale.MEDIUM else 1.0)))
166        self._data = copy.deepcopy(data)
167        ba.playsound(ba.getsound('cashRegister'))
168        ba.playsound(ba.getsound('swish'))
169
170        self._cancel_button = ba.buttonwidget(parent=self._root_widget,
171                                              scale=0.7,
172                                              position=(50, self._height - 50),
173                                              size=(60, 60),
174                                              label='',
175                                              on_activate_call=self.close,
176                                              autoselect=True,
177                                              color=(0.45, 0.63, 0.15),
178                                              icon=ba.gettexture('crossOut'),
179                                              iconscale=1.2)
180        ba.containerwidget(edit=self._root_widget,
181                           cancel_button=self._cancel_button)
182
183        ba.textwidget(
184            parent=self._root_widget,
185            position=(self._width * 0.5, self._height * 0.8),
186            size=(0, 0),
187            color=ba.app.ui.infotextcolor,
188            scale=1.0,
189            flatness=1.0,
190            h_align='center',
191            v_align='center',
192            text=ba.Lstr(resource='gatherWindow.shareThisCodeWithFriendsText'),
193            maxwidth=self._width * 0.85)
194
195        ba.textwidget(parent=self._root_widget,
196                      position=(self._width * 0.5, self._height * 0.645),
197                      size=(0, 0),
198                      color=(1.0, 3.0, 1.0),
199                      scale=2.0,
200                      h_align='center',
201                      v_align='center',
202                      text=data['code'],
203                      maxwidth=self._width * 0.85)
204
205        award_str: str | ba.Lstr | None
206        if self._data['awardTickets'] != 0:
207            award_str = ba.Lstr(
208                resource='gatherWindow.friendPromoCodeAwardText',
209                subs=[('${COUNT}', str(self._data['awardTickets']))])
210        else:
211            award_str = ''
212        ba.textwidget(
213            parent=self._root_widget,
214            position=(self._width * 0.5, self._height * 0.37),
215            size=(0, 0),
216            color=ba.app.ui.infotextcolor,
217            scale=1.0,
218            flatness=1.0,
219            h_align='center',
220            v_align='center',
221            text=ba.Lstr(
222                value='${A}\n${B}\n${C}\n${D}',
223                subs=[
224                    ('${A}',
225                     ba.Lstr(
226                         resource='gatherWindow.friendPromoCodeRedeemLongText',
227                         subs=[('${COUNT}', str(self._data['tickets'])),
228                               ('${MAX_USES}',
229                                str(self._data['usesRemaining']))])),
230                    ('${B}',
231                     ba.Lstr(resource=(
232                         'gatherWindow.friendPromoCodeWhereToEnterText'))),
233                    ('${C}', award_str),
234                    ('${D}',
235                     ba.Lstr(resource='gatherWindow.friendPromoCodeExpireText',
236                             subs=[('${EXPIRE_HOURS}',
237                                    str(self._data['expireHours']))]))
238                ]),
239            maxwidth=self._width * 0.9,
240            max_height=self._height * 0.35)
241
242        if is_browser_likely_available():
243            xoffs = 0
244            ba.buttonwidget(parent=self._root_widget,
245                            size=(200, 40),
246                            position=(self._width * 0.5 - 100 + xoffs, 39),
247                            autoselect=True,
248                            label=ba.Lstr(resource='gatherWindow.emailItText'),
249                            on_activate_call=ba.WeakCall(self._email))
250
251    def _google_invites(self) -> None:
252        ba.set_analytics_screen('App Invite UI')
253        _ba.show_app_invite(
254            ba.Lstr(resource='gatherWindow.appInviteTitleText',
255                    subs=[('${APP_NAME}', ba.Lstr(resource='titleText'))
256                          ]).evaluate(),
257            ba.Lstr(resource='gatherWindow.appInviteMessageText',
258                    subs=[('${COUNT}', str(self._data['tickets'])),
259                          ('${NAME}', _ba.get_v1_account_name().split()[0]),
260                          ('${APP_NAME}', ba.Lstr(resource='titleText'))
261                          ]).evaluate(), self._data['code'])
262
263    def _email(self) -> None:
264        import urllib.parse
265
266        # If somehow we got signed out.
267        if _ba.get_v1_account_state() != 'signed_in':
268            ba.screenmessage(ba.Lstr(resource='notSignedInText'),
269                             color=(1, 0, 0))
270            ba.playsound(ba.getsound('error'))
271            return
272
273        ba.set_analytics_screen('Email Friend Code')
274        subject = (ba.Lstr(resource='gatherWindow.friendHasSentPromoCodeText').
275                   evaluate().replace(
276                       '${NAME}', _ba.get_v1_account_name()).replace(
277                           '${APP_NAME}',
278                           ba.Lstr(resource='titleText').evaluate()).replace(
279                               '${COUNT}', str(self._data['tickets'])))
280        body = (ba.Lstr(resource='gatherWindow.youHaveBeenSentAPromoCodeText').
281                evaluate().replace('${APP_NAME}',
282                                   ba.Lstr(resource='titleText').evaluate()) +
283                '\n\n' + str(self._data['code']) + '\n\n')
284        body += (
285            (ba.Lstr(resource='gatherWindow.friendPromoCodeRedeemShortText').
286             evaluate().replace('${COUNT}', str(self._data['tickets']))) +
287            '\n\n' +
288            ba.Lstr(resource='gatherWindow.friendPromoCodeInstructionsText').
289            evaluate().replace('${APP_NAME}',
290                               ba.Lstr(resource='titleText').evaluate()) +
291            '\n' + ba.Lstr(resource='gatherWindow.friendPromoCodeExpireText').
292            evaluate().replace('${EXPIRE_HOURS}', str(
293                self._data['expireHours'])) + '\n' +
294            ba.Lstr(resource='enjoyText').evaluate())
295        ba.open_url('mailto:?subject=' + urllib.parse.quote(subject) +
296                    '&body=' + urllib.parse.quote(body))
297
298    def close(self) -> None:
299        """Close the window."""
300        ba.containerwidget(edit=self._root_widget, transition='out_scale')
301
302
303def handle_app_invites_press(force_code: bool = False) -> None:
304    """(internal)"""
305    app = ba.app
306    do_app_invites = (app.platform == 'android' and app.subplatform == 'google'
307                      and _ba.get_v1_account_misc_read_val(
308                          'enableAppInvites', False) and not app.on_tv)
309    if force_code:
310        do_app_invites = False
311
312    # FIXME: Should update this to grab a code before showing the invite UI.
313    if do_app_invites:
314        AppInviteWindow()
315    else:
316        ba.screenmessage(
317            ba.Lstr(resource='gatherWindow.requestingAPromoCodeText'),
318            color=(0, 1, 0))
319
320        def handle_result(result: dict[str, Any] | None) -> None:
321            with ba.Context('ui'):
322                if result is None:
323                    ba.screenmessage(ba.Lstr(resource='errorText'),
324                                     color=(1, 0, 0))
325                    ba.playsound(ba.getsound('error'))
326                else:
327                    ShowFriendCodeWindow(result)
328
329        _ba.add_transaction(
330            {
331                'type': 'FRIEND_PROMO_CODE_REQUEST',
332                'ali': False,
333                'expire_time': time.time() + 10
334            },
335            callback=handle_result)
336        _ba.run_transactions()
class AppInviteWindow(ba.ui.Window):
 19class AppInviteWindow(ba.Window):
 20    """Window for showing different ways to invite people to try the game."""
 21
 22    def __init__(self) -> None:
 23        ba.set_analytics_screen('AppInviteWindow')
 24        self._data: dict[str, Any] | None = None
 25        self._width = 650
 26        self._height = 400
 27
 28        uiscale = ba.app.ui.uiscale
 29        super().__init__(root_widget=ba.containerwidget(
 30            size=(self._width, self._height),
 31            transition='in_scale',
 32            scale=(1.8 if uiscale is ba.UIScale.SMALL else
 33                   1.35 if uiscale is ba.UIScale.MEDIUM else 1.0)))
 34
 35        self._cancel_button = ba.buttonwidget(parent=self._root_widget,
 36                                              scale=0.8,
 37                                              position=(60, self._height - 50),
 38                                              size=(50, 50),
 39                                              label='',
 40                                              on_activate_call=self.close,
 41                                              autoselect=True,
 42                                              color=(0.4, 0.4, 0.6),
 43                                              icon=ba.gettexture('crossOut'),
 44                                              iconscale=1.2)
 45
 46        ba.containerwidget(edit=self._root_widget,
 47                           cancel_button=self._cancel_button)
 48
 49        ba.textwidget(
 50            parent=self._root_widget,
 51            size=(0, 0),
 52            position=(self._width * 0.5, self._height * 0.5 + 110),
 53            autoselect=True,
 54            scale=0.8,
 55            maxwidth=self._width * 0.9,
 56            h_align='center',
 57            v_align='center',
 58            color=(0.3, 0.8, 0.3),
 59            flatness=1.0,
 60            text=ba.Lstr(
 61                resource='gatherWindow.earnTicketsForRecommendingAmountText',
 62                fallback_resource=(
 63                    'gatherWindow.earnTicketsForRecommendingText'),
 64                subs=[('${COUNT}',
 65                       str(
 66                           _ba.get_v1_account_misc_read_val(
 67                               'friendTryTickets', 300))),
 68                      ('${YOU_COUNT}',
 69                       str(
 70                           _ba.get_v1_account_misc_read_val(
 71                               'friendTryAwardTickets', 100)))]))
 72
 73        or_text = ba.Lstr(resource='orText',
 74                          subs=[('${A}', ''),
 75                                ('${B}', '')]).evaluate().strip()
 76        ba.buttonwidget(
 77            parent=self._root_widget,
 78            size=(250, 150),
 79            position=(self._width * 0.5 - 125, self._height * 0.5 - 80),
 80            autoselect=True,
 81            button_type='square',
 82            label=ba.Lstr(resource='gatherWindow.inviteFriendsText'),
 83            on_activate_call=ba.WeakCall(self._google_invites))
 84
 85        ba.textwidget(parent=self._root_widget,
 86                      size=(0, 0),
 87                      position=(self._width * 0.5, self._height * 0.5 - 94),
 88                      autoselect=True,
 89                      scale=0.9,
 90                      h_align='center',
 91                      v_align='center',
 92                      color=(0.5, 0.5, 0.5),
 93                      flatness=1.0,
 94                      text=or_text)
 95
 96        ba.buttonwidget(
 97            parent=self._root_widget,
 98            size=(180, 50),
 99            position=(self._width * 0.5 - 90, self._height * 0.5 - 170),
100            autoselect=True,
101            color=(0.5, 0.5, 0.6),
102            textcolor=(0.7, 0.7, 0.8),
103            text_scale=0.8,
104            label=ba.Lstr(resource='gatherWindow.appInviteSendACodeText'),
105            on_activate_call=ba.WeakCall(self._send_code))
106
107        # kick off a transaction to get our code
108        _ba.add_transaction(
109            {
110                'type': 'FRIEND_PROMO_CODE_REQUEST',
111                'ali': False,
112                'expire_time': time.time() + 20
113            },
114            callback=ba.WeakCall(self._on_code_result))
115        _ba.run_transactions()
116
117    def _on_code_result(self, result: dict[str, Any] | None) -> None:
118        if result is not None:
119            self._data = result
120
121    def _send_code(self) -> None:
122        handle_app_invites_press(force_code=True)
123
124    def _google_invites(self) -> None:
125        if self._data is None:
126            ba.screenmessage(ba.Lstr(
127                resource='getTicketsWindow.unavailableTemporarilyText'),
128                             color=(1, 0, 0))
129            ba.playsound(ba.getsound('error'))
130            return
131
132        if _ba.get_v1_account_state() == 'signed_in':
133            ba.set_analytics_screen('App Invite UI')
134            _ba.show_app_invite(
135                ba.Lstr(resource='gatherWindow.appInviteTitleText',
136                        subs=[('${APP_NAME}', ba.Lstr(resource='titleText'))
137                              ]).evaluate(),
138                ba.Lstr(resource='gatherWindow.appInviteMessageText',
139                        subs=[
140                            ('${COUNT}', str(self._data['tickets'])),
141                            ('${NAME}', _ba.get_v1_account_name().split()[0]),
142                            ('${APP_NAME}', ba.Lstr(resource='titleText'))
143                        ]).evaluate(), self._data['code'])
144        else:
145            ba.playsound(ba.getsound('error'))
146
147    def close(self) -> None:
148        """Close the window."""
149        ba.containerwidget(edit=self._root_widget, transition='out_scale')

Window for showing different ways to invite people to try the game.

AppInviteWindow()
 22    def __init__(self) -> None:
 23        ba.set_analytics_screen('AppInviteWindow')
 24        self._data: dict[str, Any] | None = None
 25        self._width = 650
 26        self._height = 400
 27
 28        uiscale = ba.app.ui.uiscale
 29        super().__init__(root_widget=ba.containerwidget(
 30            size=(self._width, self._height),
 31            transition='in_scale',
 32            scale=(1.8 if uiscale is ba.UIScale.SMALL else
 33                   1.35 if uiscale is ba.UIScale.MEDIUM else 1.0)))
 34
 35        self._cancel_button = ba.buttonwidget(parent=self._root_widget,
 36                                              scale=0.8,
 37                                              position=(60, self._height - 50),
 38                                              size=(50, 50),
 39                                              label='',
 40                                              on_activate_call=self.close,
 41                                              autoselect=True,
 42                                              color=(0.4, 0.4, 0.6),
 43                                              icon=ba.gettexture('crossOut'),
 44                                              iconscale=1.2)
 45
 46        ba.containerwidget(edit=self._root_widget,
 47                           cancel_button=self._cancel_button)
 48
 49        ba.textwidget(
 50            parent=self._root_widget,
 51            size=(0, 0),
 52            position=(self._width * 0.5, self._height * 0.5 + 110),
 53            autoselect=True,
 54            scale=0.8,
 55            maxwidth=self._width * 0.9,
 56            h_align='center',
 57            v_align='center',
 58            color=(0.3, 0.8, 0.3),
 59            flatness=1.0,
 60            text=ba.Lstr(
 61                resource='gatherWindow.earnTicketsForRecommendingAmountText',
 62                fallback_resource=(
 63                    'gatherWindow.earnTicketsForRecommendingText'),
 64                subs=[('${COUNT}',
 65                       str(
 66                           _ba.get_v1_account_misc_read_val(
 67                               'friendTryTickets', 300))),
 68                      ('${YOU_COUNT}',
 69                       str(
 70                           _ba.get_v1_account_misc_read_val(
 71                               'friendTryAwardTickets', 100)))]))
 72
 73        or_text = ba.Lstr(resource='orText',
 74                          subs=[('${A}', ''),
 75                                ('${B}', '')]).evaluate().strip()
 76        ba.buttonwidget(
 77            parent=self._root_widget,
 78            size=(250, 150),
 79            position=(self._width * 0.5 - 125, self._height * 0.5 - 80),
 80            autoselect=True,
 81            button_type='square',
 82            label=ba.Lstr(resource='gatherWindow.inviteFriendsText'),
 83            on_activate_call=ba.WeakCall(self._google_invites))
 84
 85        ba.textwidget(parent=self._root_widget,
 86                      size=(0, 0),
 87                      position=(self._width * 0.5, self._height * 0.5 - 94),
 88                      autoselect=True,
 89                      scale=0.9,
 90                      h_align='center',
 91                      v_align='center',
 92                      color=(0.5, 0.5, 0.5),
 93                      flatness=1.0,
 94                      text=or_text)
 95
 96        ba.buttonwidget(
 97            parent=self._root_widget,
 98            size=(180, 50),
 99            position=(self._width * 0.5 - 90, self._height * 0.5 - 170),
100            autoselect=True,
101            color=(0.5, 0.5, 0.6),
102            textcolor=(0.7, 0.7, 0.8),
103            text_scale=0.8,
104            label=ba.Lstr(resource='gatherWindow.appInviteSendACodeText'),
105            on_activate_call=ba.WeakCall(self._send_code))
106
107        # kick off a transaction to get our code
108        _ba.add_transaction(
109            {
110                'type': 'FRIEND_PROMO_CODE_REQUEST',
111                'ali': False,
112                'expire_time': time.time() + 20
113            },
114            callback=ba.WeakCall(self._on_code_result))
115        _ba.run_transactions()
def close(self) -> None:
147    def close(self) -> None:
148        """Close the window."""
149        ba.containerwidget(edit=self._root_widget, transition='out_scale')

Close the window.

Inherited Members
ba.ui.Window
get_root_widget
class ShowFriendCodeWindow(ba.ui.Window):
152class ShowFriendCodeWindow(ba.Window):
153    """Window showing a code for sharing with friends."""
154
155    def __init__(self, data: dict[str, Any]):
156        from ba.internal import is_browser_likely_available
157        ba.set_analytics_screen('Friend Promo Code')
158        self._width = 650
159        self._height = 400
160        uiscale = ba.app.ui.uiscale
161        super().__init__(root_widget=ba.containerwidget(
162            size=(self._width, self._height),
163            color=(0.45, 0.63, 0.15),
164            transition='in_scale',
165            scale=(1.7 if uiscale is ba.UIScale.SMALL else
166                   1.35 if uiscale is ba.UIScale.MEDIUM else 1.0)))
167        self._data = copy.deepcopy(data)
168        ba.playsound(ba.getsound('cashRegister'))
169        ba.playsound(ba.getsound('swish'))
170
171        self._cancel_button = ba.buttonwidget(parent=self._root_widget,
172                                              scale=0.7,
173                                              position=(50, self._height - 50),
174                                              size=(60, 60),
175                                              label='',
176                                              on_activate_call=self.close,
177                                              autoselect=True,
178                                              color=(0.45, 0.63, 0.15),
179                                              icon=ba.gettexture('crossOut'),
180                                              iconscale=1.2)
181        ba.containerwidget(edit=self._root_widget,
182                           cancel_button=self._cancel_button)
183
184        ba.textwidget(
185            parent=self._root_widget,
186            position=(self._width * 0.5, self._height * 0.8),
187            size=(0, 0),
188            color=ba.app.ui.infotextcolor,
189            scale=1.0,
190            flatness=1.0,
191            h_align='center',
192            v_align='center',
193            text=ba.Lstr(resource='gatherWindow.shareThisCodeWithFriendsText'),
194            maxwidth=self._width * 0.85)
195
196        ba.textwidget(parent=self._root_widget,
197                      position=(self._width * 0.5, self._height * 0.645),
198                      size=(0, 0),
199                      color=(1.0, 3.0, 1.0),
200                      scale=2.0,
201                      h_align='center',
202                      v_align='center',
203                      text=data['code'],
204                      maxwidth=self._width * 0.85)
205
206        award_str: str | ba.Lstr | None
207        if self._data['awardTickets'] != 0:
208            award_str = ba.Lstr(
209                resource='gatherWindow.friendPromoCodeAwardText',
210                subs=[('${COUNT}', str(self._data['awardTickets']))])
211        else:
212            award_str = ''
213        ba.textwidget(
214            parent=self._root_widget,
215            position=(self._width * 0.5, self._height * 0.37),
216            size=(0, 0),
217            color=ba.app.ui.infotextcolor,
218            scale=1.0,
219            flatness=1.0,
220            h_align='center',
221            v_align='center',
222            text=ba.Lstr(
223                value='${A}\n${B}\n${C}\n${D}',
224                subs=[
225                    ('${A}',
226                     ba.Lstr(
227                         resource='gatherWindow.friendPromoCodeRedeemLongText',
228                         subs=[('${COUNT}', str(self._data['tickets'])),
229                               ('${MAX_USES}',
230                                str(self._data['usesRemaining']))])),
231                    ('${B}',
232                     ba.Lstr(resource=(
233                         'gatherWindow.friendPromoCodeWhereToEnterText'))),
234                    ('${C}', award_str),
235                    ('${D}',
236                     ba.Lstr(resource='gatherWindow.friendPromoCodeExpireText',
237                             subs=[('${EXPIRE_HOURS}',
238                                    str(self._data['expireHours']))]))
239                ]),
240            maxwidth=self._width * 0.9,
241            max_height=self._height * 0.35)
242
243        if is_browser_likely_available():
244            xoffs = 0
245            ba.buttonwidget(parent=self._root_widget,
246                            size=(200, 40),
247                            position=(self._width * 0.5 - 100 + xoffs, 39),
248                            autoselect=True,
249                            label=ba.Lstr(resource='gatherWindow.emailItText'),
250                            on_activate_call=ba.WeakCall(self._email))
251
252    def _google_invites(self) -> None:
253        ba.set_analytics_screen('App Invite UI')
254        _ba.show_app_invite(
255            ba.Lstr(resource='gatherWindow.appInviteTitleText',
256                    subs=[('${APP_NAME}', ba.Lstr(resource='titleText'))
257                          ]).evaluate(),
258            ba.Lstr(resource='gatherWindow.appInviteMessageText',
259                    subs=[('${COUNT}', str(self._data['tickets'])),
260                          ('${NAME}', _ba.get_v1_account_name().split()[0]),
261                          ('${APP_NAME}', ba.Lstr(resource='titleText'))
262                          ]).evaluate(), self._data['code'])
263
264    def _email(self) -> None:
265        import urllib.parse
266
267        # If somehow we got signed out.
268        if _ba.get_v1_account_state() != 'signed_in':
269            ba.screenmessage(ba.Lstr(resource='notSignedInText'),
270                             color=(1, 0, 0))
271            ba.playsound(ba.getsound('error'))
272            return
273
274        ba.set_analytics_screen('Email Friend Code')
275        subject = (ba.Lstr(resource='gatherWindow.friendHasSentPromoCodeText').
276                   evaluate().replace(
277                       '${NAME}', _ba.get_v1_account_name()).replace(
278                           '${APP_NAME}',
279                           ba.Lstr(resource='titleText').evaluate()).replace(
280                               '${COUNT}', str(self._data['tickets'])))
281        body = (ba.Lstr(resource='gatherWindow.youHaveBeenSentAPromoCodeText').
282                evaluate().replace('${APP_NAME}',
283                                   ba.Lstr(resource='titleText').evaluate()) +
284                '\n\n' + str(self._data['code']) + '\n\n')
285        body += (
286            (ba.Lstr(resource='gatherWindow.friendPromoCodeRedeemShortText').
287             evaluate().replace('${COUNT}', str(self._data['tickets']))) +
288            '\n\n' +
289            ba.Lstr(resource='gatherWindow.friendPromoCodeInstructionsText').
290            evaluate().replace('${APP_NAME}',
291                               ba.Lstr(resource='titleText').evaluate()) +
292            '\n' + ba.Lstr(resource='gatherWindow.friendPromoCodeExpireText').
293            evaluate().replace('${EXPIRE_HOURS}', str(
294                self._data['expireHours'])) + '\n' +
295            ba.Lstr(resource='enjoyText').evaluate())
296        ba.open_url('mailto:?subject=' + urllib.parse.quote(subject) +
297                    '&body=' + urllib.parse.quote(body))
298
299    def close(self) -> None:
300        """Close the window."""
301        ba.containerwidget(edit=self._root_widget, transition='out_scale')

Window showing a code for sharing with friends.

ShowFriendCodeWindow(data: dict[str, typing.Any])
155    def __init__(self, data: dict[str, Any]):
156        from ba.internal import is_browser_likely_available
157        ba.set_analytics_screen('Friend Promo Code')
158        self._width = 650
159        self._height = 400
160        uiscale = ba.app.ui.uiscale
161        super().__init__(root_widget=ba.containerwidget(
162            size=(self._width, self._height),
163            color=(0.45, 0.63, 0.15),
164            transition='in_scale',
165            scale=(1.7 if uiscale is ba.UIScale.SMALL else
166                   1.35 if uiscale is ba.UIScale.MEDIUM else 1.0)))
167        self._data = copy.deepcopy(data)
168        ba.playsound(ba.getsound('cashRegister'))
169        ba.playsound(ba.getsound('swish'))
170
171        self._cancel_button = ba.buttonwidget(parent=self._root_widget,
172                                              scale=0.7,
173                                              position=(50, self._height - 50),
174                                              size=(60, 60),
175                                              label='',
176                                              on_activate_call=self.close,
177                                              autoselect=True,
178                                              color=(0.45, 0.63, 0.15),
179                                              icon=ba.gettexture('crossOut'),
180                                              iconscale=1.2)
181        ba.containerwidget(edit=self._root_widget,
182                           cancel_button=self._cancel_button)
183
184        ba.textwidget(
185            parent=self._root_widget,
186            position=(self._width * 0.5, self._height * 0.8),
187            size=(0, 0),
188            color=ba.app.ui.infotextcolor,
189            scale=1.0,
190            flatness=1.0,
191            h_align='center',
192            v_align='center',
193            text=ba.Lstr(resource='gatherWindow.shareThisCodeWithFriendsText'),
194            maxwidth=self._width * 0.85)
195
196        ba.textwidget(parent=self._root_widget,
197                      position=(self._width * 0.5, self._height * 0.645),
198                      size=(0, 0),
199                      color=(1.0, 3.0, 1.0),
200                      scale=2.0,
201                      h_align='center',
202                      v_align='center',
203                      text=data['code'],
204                      maxwidth=self._width * 0.85)
205
206        award_str: str | ba.Lstr | None
207        if self._data['awardTickets'] != 0:
208            award_str = ba.Lstr(
209                resource='gatherWindow.friendPromoCodeAwardText',
210                subs=[('${COUNT}', str(self._data['awardTickets']))])
211        else:
212            award_str = ''
213        ba.textwidget(
214            parent=self._root_widget,
215            position=(self._width * 0.5, self._height * 0.37),
216            size=(0, 0),
217            color=ba.app.ui.infotextcolor,
218            scale=1.0,
219            flatness=1.0,
220            h_align='center',
221            v_align='center',
222            text=ba.Lstr(
223                value='${A}\n${B}\n${C}\n${D}',
224                subs=[
225                    ('${A}',
226                     ba.Lstr(
227                         resource='gatherWindow.friendPromoCodeRedeemLongText',
228                         subs=[('${COUNT}', str(self._data['tickets'])),
229                               ('${MAX_USES}',
230                                str(self._data['usesRemaining']))])),
231                    ('${B}',
232                     ba.Lstr(resource=(
233                         'gatherWindow.friendPromoCodeWhereToEnterText'))),
234                    ('${C}', award_str),
235                    ('${D}',
236                     ba.Lstr(resource='gatherWindow.friendPromoCodeExpireText',
237                             subs=[('${EXPIRE_HOURS}',
238                                    str(self._data['expireHours']))]))
239                ]),
240            maxwidth=self._width * 0.9,
241            max_height=self._height * 0.35)
242
243        if is_browser_likely_available():
244            xoffs = 0
245            ba.buttonwidget(parent=self._root_widget,
246                            size=(200, 40),
247                            position=(self._width * 0.5 - 100 + xoffs, 39),
248                            autoselect=True,
249                            label=ba.Lstr(resource='gatherWindow.emailItText'),
250                            on_activate_call=ba.WeakCall(self._email))
def close(self) -> None:
299    def close(self) -> None:
300        """Close the window."""
301        ba.containerwidget(edit=self._root_widget, transition='out_scale')

Close the window.

Inherited Members
ba.ui.Window
get_root_widget