bauiv1lib.account.link

UI functionality for linking accounts.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""UI functionality for linking accounts."""
  4
  5from __future__ import annotations
  6
  7import copy
  8import time
  9from typing import TYPE_CHECKING
 10
 11import bauiv1 as bui
 12
 13if TYPE_CHECKING:
 14    from typing import Any
 15
 16
 17class AccountLinkWindow(bui.Window):
 18    """Window for linking accounts."""
 19
 20    def __init__(self, origin_widget: bui.Widget | None = None):
 21        plus = bui.app.plus
 22        assert plus is not None
 23
 24        scale_origin: tuple[float, float] | None
 25        if origin_widget is not None:
 26            self._transition_out = 'out_scale'
 27            scale_origin = origin_widget.get_screen_space_center()
 28            transition = 'in_scale'
 29        else:
 30            self._transition_out = 'out_right'
 31            scale_origin = None
 32            transition = 'in_right'
 33        bg_color = (0.4, 0.4, 0.5)
 34        self._width = 560
 35        self._height = 420
 36        assert bui.app.classic is not None
 37        uiscale = bui.app.ui_v1.uiscale
 38        base_scale = (
 39            1.65
 40            if uiscale is bui.UIScale.SMALL
 41            else 1.5
 42            if uiscale is bui.UIScale.MEDIUM
 43            else 1.1
 44        )
 45        super().__init__(
 46            root_widget=bui.containerwidget(
 47                size=(self._width, self._height),
 48                transition=transition,
 49                scale=base_scale,
 50                scale_origin_stack_offset=scale_origin,
 51                stack_offset=(0, -10)
 52                if uiscale is bui.UIScale.SMALL
 53                else (0, 0),
 54            )
 55        )
 56        self._cancel_button = bui.buttonwidget(
 57            parent=self._root_widget,
 58            position=(40, self._height - 45),
 59            size=(50, 50),
 60            scale=0.7,
 61            label='',
 62            color=bg_color,
 63            on_activate_call=self._cancel,
 64            autoselect=True,
 65            icon=bui.gettexture('crossOut'),
 66            iconscale=1.2,
 67        )
 68        maxlinks = plus.get_v1_account_misc_read_val('maxLinkAccounts', 5)
 69        bui.textwidget(
 70            parent=self._root_widget,
 71            position=(self._width * 0.5, self._height * 0.56),
 72            size=(0, 0),
 73            text=bui.Lstr(
 74                resource=(
 75                    'accountSettingsWindow.linkAccountsInstructionsNewText'
 76                ),
 77                subs=[('${COUNT}', str(maxlinks))],
 78            ),
 79            maxwidth=self._width * 0.9,
 80            color=bui.app.ui_v1.infotextcolor,
 81            max_height=self._height * 0.6,
 82            h_align='center',
 83            v_align='center',
 84        )
 85        bui.containerwidget(
 86            edit=self._root_widget, cancel_button=self._cancel_button
 87        )
 88        bui.buttonwidget(
 89            parent=self._root_widget,
 90            position=(40, 30),
 91            size=(200, 60),
 92            label=bui.Lstr(
 93                resource='accountSettingsWindow.linkAccountsGenerateCodeText'
 94            ),
 95            autoselect=True,
 96            on_activate_call=self._generate_press,
 97        )
 98        self._enter_code_button = bui.buttonwidget(
 99            parent=self._root_widget,
100            position=(self._width - 240, 30),
101            size=(200, 60),
102            label=bui.Lstr(
103                resource='accountSettingsWindow.linkAccountsEnterCodeText'
104            ),
105            autoselect=True,
106            on_activate_call=self._enter_code_press,
107        )
108
109    def _generate_press(self) -> None:
110        from bauiv1lib import account
111
112        plus = bui.app.plus
113        assert plus is not None
114
115        if plus.get_v1_account_state() != 'signed_in':
116            account.show_sign_in_prompt()
117            return
118        bui.screenmessage(
119            bui.Lstr(resource='gatherWindow.requestingAPromoCodeText'),
120            color=(0, 1, 0),
121        )
122        plus.add_v1_account_transaction(
123            {
124                'type': 'ACCOUNT_LINK_CODE_REQUEST',
125                'expire_time': time.time() + 5,
126            }
127        )
128        plus.run_v1_account_transactions()
129
130    def _enter_code_press(self) -> None:
131        from bauiv1lib import promocode
132
133        promocode.PromoCodeWindow(
134            modal=True, origin_widget=self._enter_code_button
135        )
136        bui.containerwidget(
137            edit=self._root_widget, transition=self._transition_out
138        )
139
140    def _cancel(self) -> None:
141        bui.containerwidget(
142            edit=self._root_widget, transition=self._transition_out
143        )
144
145
146class AccountLinkCodeWindow(bui.Window):
147    """Window showing code for account-linking."""
148
149    def __init__(self, data: dict[str, Any]):
150        self._width = 350
151        self._height = 200
152        assert bui.app.classic is not None
153        uiscale = bui.app.ui_v1.uiscale
154        super().__init__(
155            root_widget=bui.containerwidget(
156                size=(self._width, self._height),
157                color=(0.45, 0.63, 0.15),
158                transition='in_scale',
159                scale=(
160                    1.8
161                    if uiscale is bui.UIScale.SMALL
162                    else 1.35
163                    if uiscale is bui.UIScale.MEDIUM
164                    else 1.0
165                ),
166            )
167        )
168        self._data = copy.deepcopy(data)
169        bui.getsound('cashRegister').play()
170        bui.getsound('swish').play()
171        self._cancel_button = bui.buttonwidget(
172            parent=self._root_widget,
173            scale=0.5,
174            position=(40, self._height - 40),
175            size=(50, 50),
176            label='',
177            on_activate_call=self.close,
178            autoselect=True,
179            color=(0.45, 0.63, 0.15),
180            icon=bui.gettexture('crossOut'),
181            iconscale=1.2,
182        )
183        bui.containerwidget(
184            edit=self._root_widget, cancel_button=self._cancel_button
185        )
186        bui.textwidget(
187            parent=self._root_widget,
188            position=(self._width * 0.5, self._height * 0.5),
189            size=(0, 0),
190            color=(1.0, 3.0, 1.0),
191            scale=2.0,
192            h_align='center',
193            v_align='center',
194            text=data['code'],
195            maxwidth=self._width * 0.85,
196        )
197
198    def close(self) -> None:
199        """close the window"""
200        bui.containerwidget(edit=self._root_widget, transition='out_scale')
class AccountLinkWindow(bauiv1._uitypes.Window):
 18class AccountLinkWindow(bui.Window):
 19    """Window for linking accounts."""
 20
 21    def __init__(self, origin_widget: bui.Widget | None = None):
 22        plus = bui.app.plus
 23        assert plus is not None
 24
 25        scale_origin: tuple[float, float] | None
 26        if origin_widget is not None:
 27            self._transition_out = 'out_scale'
 28            scale_origin = origin_widget.get_screen_space_center()
 29            transition = 'in_scale'
 30        else:
 31            self._transition_out = 'out_right'
 32            scale_origin = None
 33            transition = 'in_right'
 34        bg_color = (0.4, 0.4, 0.5)
 35        self._width = 560
 36        self._height = 420
 37        assert bui.app.classic is not None
 38        uiscale = bui.app.ui_v1.uiscale
 39        base_scale = (
 40            1.65
 41            if uiscale is bui.UIScale.SMALL
 42            else 1.5
 43            if uiscale is bui.UIScale.MEDIUM
 44            else 1.1
 45        )
 46        super().__init__(
 47            root_widget=bui.containerwidget(
 48                size=(self._width, self._height),
 49                transition=transition,
 50                scale=base_scale,
 51                scale_origin_stack_offset=scale_origin,
 52                stack_offset=(0, -10)
 53                if uiscale is bui.UIScale.SMALL
 54                else (0, 0),
 55            )
 56        )
 57        self._cancel_button = bui.buttonwidget(
 58            parent=self._root_widget,
 59            position=(40, self._height - 45),
 60            size=(50, 50),
 61            scale=0.7,
 62            label='',
 63            color=bg_color,
 64            on_activate_call=self._cancel,
 65            autoselect=True,
 66            icon=bui.gettexture('crossOut'),
 67            iconscale=1.2,
 68        )
 69        maxlinks = plus.get_v1_account_misc_read_val('maxLinkAccounts', 5)
 70        bui.textwidget(
 71            parent=self._root_widget,
 72            position=(self._width * 0.5, self._height * 0.56),
 73            size=(0, 0),
 74            text=bui.Lstr(
 75                resource=(
 76                    'accountSettingsWindow.linkAccountsInstructionsNewText'
 77                ),
 78                subs=[('${COUNT}', str(maxlinks))],
 79            ),
 80            maxwidth=self._width * 0.9,
 81            color=bui.app.ui_v1.infotextcolor,
 82            max_height=self._height * 0.6,
 83            h_align='center',
 84            v_align='center',
 85        )
 86        bui.containerwidget(
 87            edit=self._root_widget, cancel_button=self._cancel_button
 88        )
 89        bui.buttonwidget(
 90            parent=self._root_widget,
 91            position=(40, 30),
 92            size=(200, 60),
 93            label=bui.Lstr(
 94                resource='accountSettingsWindow.linkAccountsGenerateCodeText'
 95            ),
 96            autoselect=True,
 97            on_activate_call=self._generate_press,
 98        )
 99        self._enter_code_button = bui.buttonwidget(
100            parent=self._root_widget,
101            position=(self._width - 240, 30),
102            size=(200, 60),
103            label=bui.Lstr(
104                resource='accountSettingsWindow.linkAccountsEnterCodeText'
105            ),
106            autoselect=True,
107            on_activate_call=self._enter_code_press,
108        )
109
110    def _generate_press(self) -> None:
111        from bauiv1lib import account
112
113        plus = bui.app.plus
114        assert plus is not None
115
116        if plus.get_v1_account_state() != 'signed_in':
117            account.show_sign_in_prompt()
118            return
119        bui.screenmessage(
120            bui.Lstr(resource='gatherWindow.requestingAPromoCodeText'),
121            color=(0, 1, 0),
122        )
123        plus.add_v1_account_transaction(
124            {
125                'type': 'ACCOUNT_LINK_CODE_REQUEST',
126                'expire_time': time.time() + 5,
127            }
128        )
129        plus.run_v1_account_transactions()
130
131    def _enter_code_press(self) -> None:
132        from bauiv1lib import promocode
133
134        promocode.PromoCodeWindow(
135            modal=True, origin_widget=self._enter_code_button
136        )
137        bui.containerwidget(
138            edit=self._root_widget, transition=self._transition_out
139        )
140
141    def _cancel(self) -> None:
142        bui.containerwidget(
143            edit=self._root_widget, transition=self._transition_out
144        )

Window for linking accounts.

AccountLinkWindow(origin_widget: _bauiv1.Widget | None = None)
 21    def __init__(self, origin_widget: bui.Widget | None = None):
 22        plus = bui.app.plus
 23        assert plus is not None
 24
 25        scale_origin: tuple[float, float] | None
 26        if origin_widget is not None:
 27            self._transition_out = 'out_scale'
 28            scale_origin = origin_widget.get_screen_space_center()
 29            transition = 'in_scale'
 30        else:
 31            self._transition_out = 'out_right'
 32            scale_origin = None
 33            transition = 'in_right'
 34        bg_color = (0.4, 0.4, 0.5)
 35        self._width = 560
 36        self._height = 420
 37        assert bui.app.classic is not None
 38        uiscale = bui.app.ui_v1.uiscale
 39        base_scale = (
 40            1.65
 41            if uiscale is bui.UIScale.SMALL
 42            else 1.5
 43            if uiscale is bui.UIScale.MEDIUM
 44            else 1.1
 45        )
 46        super().__init__(
 47            root_widget=bui.containerwidget(
 48                size=(self._width, self._height),
 49                transition=transition,
 50                scale=base_scale,
 51                scale_origin_stack_offset=scale_origin,
 52                stack_offset=(0, -10)
 53                if uiscale is bui.UIScale.SMALL
 54                else (0, 0),
 55            )
 56        )
 57        self._cancel_button = bui.buttonwidget(
 58            parent=self._root_widget,
 59            position=(40, self._height - 45),
 60            size=(50, 50),
 61            scale=0.7,
 62            label='',
 63            color=bg_color,
 64            on_activate_call=self._cancel,
 65            autoselect=True,
 66            icon=bui.gettexture('crossOut'),
 67            iconscale=1.2,
 68        )
 69        maxlinks = plus.get_v1_account_misc_read_val('maxLinkAccounts', 5)
 70        bui.textwidget(
 71            parent=self._root_widget,
 72            position=(self._width * 0.5, self._height * 0.56),
 73            size=(0, 0),
 74            text=bui.Lstr(
 75                resource=(
 76                    'accountSettingsWindow.linkAccountsInstructionsNewText'
 77                ),
 78                subs=[('${COUNT}', str(maxlinks))],
 79            ),
 80            maxwidth=self._width * 0.9,
 81            color=bui.app.ui_v1.infotextcolor,
 82            max_height=self._height * 0.6,
 83            h_align='center',
 84            v_align='center',
 85        )
 86        bui.containerwidget(
 87            edit=self._root_widget, cancel_button=self._cancel_button
 88        )
 89        bui.buttonwidget(
 90            parent=self._root_widget,
 91            position=(40, 30),
 92            size=(200, 60),
 93            label=bui.Lstr(
 94                resource='accountSettingsWindow.linkAccountsGenerateCodeText'
 95            ),
 96            autoselect=True,
 97            on_activate_call=self._generate_press,
 98        )
 99        self._enter_code_button = bui.buttonwidget(
100            parent=self._root_widget,
101            position=(self._width - 240, 30),
102            size=(200, 60),
103            label=bui.Lstr(
104                resource='accountSettingsWindow.linkAccountsEnterCodeText'
105            ),
106            autoselect=True,
107            on_activate_call=self._enter_code_press,
108        )
Inherited Members
bauiv1._uitypes.Window
get_root_widget
class AccountLinkCodeWindow(bauiv1._uitypes.Window):
147class AccountLinkCodeWindow(bui.Window):
148    """Window showing code for account-linking."""
149
150    def __init__(self, data: dict[str, Any]):
151        self._width = 350
152        self._height = 200
153        assert bui.app.classic is not None
154        uiscale = bui.app.ui_v1.uiscale
155        super().__init__(
156            root_widget=bui.containerwidget(
157                size=(self._width, self._height),
158                color=(0.45, 0.63, 0.15),
159                transition='in_scale',
160                scale=(
161                    1.8
162                    if uiscale is bui.UIScale.SMALL
163                    else 1.35
164                    if uiscale is bui.UIScale.MEDIUM
165                    else 1.0
166                ),
167            )
168        )
169        self._data = copy.deepcopy(data)
170        bui.getsound('cashRegister').play()
171        bui.getsound('swish').play()
172        self._cancel_button = bui.buttonwidget(
173            parent=self._root_widget,
174            scale=0.5,
175            position=(40, self._height - 40),
176            size=(50, 50),
177            label='',
178            on_activate_call=self.close,
179            autoselect=True,
180            color=(0.45, 0.63, 0.15),
181            icon=bui.gettexture('crossOut'),
182            iconscale=1.2,
183        )
184        bui.containerwidget(
185            edit=self._root_widget, cancel_button=self._cancel_button
186        )
187        bui.textwidget(
188            parent=self._root_widget,
189            position=(self._width * 0.5, self._height * 0.5),
190            size=(0, 0),
191            color=(1.0, 3.0, 1.0),
192            scale=2.0,
193            h_align='center',
194            v_align='center',
195            text=data['code'],
196            maxwidth=self._width * 0.85,
197        )
198
199    def close(self) -> None:
200        """close the window"""
201        bui.containerwidget(edit=self._root_widget, transition='out_scale')

Window showing code for account-linking.

AccountLinkCodeWindow(data: dict[str, typing.Any])
150    def __init__(self, data: dict[str, Any]):
151        self._width = 350
152        self._height = 200
153        assert bui.app.classic is not None
154        uiscale = bui.app.ui_v1.uiscale
155        super().__init__(
156            root_widget=bui.containerwidget(
157                size=(self._width, self._height),
158                color=(0.45, 0.63, 0.15),
159                transition='in_scale',
160                scale=(
161                    1.8
162                    if uiscale is bui.UIScale.SMALL
163                    else 1.35
164                    if uiscale is bui.UIScale.MEDIUM
165                    else 1.0
166                ),
167            )
168        )
169        self._data = copy.deepcopy(data)
170        bui.getsound('cashRegister').play()
171        bui.getsound('swish').play()
172        self._cancel_button = bui.buttonwidget(
173            parent=self._root_widget,
174            scale=0.5,
175            position=(40, self._height - 40),
176            size=(50, 50),
177            label='',
178            on_activate_call=self.close,
179            autoselect=True,
180            color=(0.45, 0.63, 0.15),
181            icon=bui.gettexture('crossOut'),
182            iconscale=1.2,
183        )
184        bui.containerwidget(
185            edit=self._root_widget, cancel_button=self._cancel_button
186        )
187        bui.textwidget(
188            parent=self._root_widget,
189            position=(self._width * 0.5, self._height * 0.5),
190            size=(0, 0),
191            color=(1.0, 3.0, 1.0),
192            scale=2.0,
193            h_align='center',
194            v_align='center',
195            text=data['code'],
196            maxwidth=self._width * 0.85,
197        )
def close(self) -> None:
199    def close(self) -> None:
200        """close the window"""
201        bui.containerwidget(edit=self._root_widget, transition='out_scale')

close the window

Inherited Members
bauiv1._uitypes.Window
get_root_widget