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