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