Bombsquad-Ballistica-Modded.../dist/ba_data/python/bauiv1lib/v2upgrade.py

127 lines
3.9 KiB
Python
Raw Permalink Normal View History

2022-12-25 00:39:49 +05:30
# Released under the MIT License. See LICENSE for details.
#
"""UI for upgrading V1 accounts to V2."""
from __future__ import annotations
2023-08-13 17:21:49 +05:30
import bauiv1 as bui
2022-12-25 00:39:49 +05:30
2023-08-13 17:21:49 +05:30
class V2UpgradeWindow(bui.Window):
2022-12-25 00:39:49 +05:30
"""A window presenting a URL to the user visually."""
def __init__(self, login_name: str, code: str):
2023-08-13 17:21:49 +05:30
app = bui.app
assert app.classic is not None
uiscale = app.ui_v1.uiscale
2022-12-25 00:39:49 +05:30
self._code = code
self._width = 700
self._height = 270
super().__init__(
2023-08-13 17:21:49 +05:30
root_widget=bui.containerwidget(
2022-12-25 00:39:49 +05:30
size=(self._width, self._height + 40),
transition='in_right',
scale=(
1.25
2023-08-13 17:21:49 +05:30
if uiscale is bui.UIScale.SMALL
2024-05-19 18:25:43 +05:30
else 1.25 if uiscale is bui.UIScale.MEDIUM else 1.25
2022-12-25 00:39:49 +05:30
),
)
)
2023-08-13 17:21:49 +05:30
bui.getsound('error').play()
2022-12-25 00:39:49 +05:30
2023-08-13 17:21:49 +05:30
bui.textwidget(
2022-12-25 00:39:49 +05:30
parent=self._root_widget,
position=(self._width * 0.5, self._height - 46),
size=(0, 0),
2023-08-13 17:21:49 +05:30
color=app.ui_v1.title_color,
2022-12-25 00:39:49 +05:30
h_align='center',
v_align='center',
2023-08-13 17:21:49 +05:30
text=bui.Lstr(
2022-12-25 00:39:49 +05:30
resource='deviceAccountUpgradeText',
subs=[('${NAME}', login_name)],
),
maxwidth=self._width * 0.95,
)
2023-08-13 17:21:49 +05:30
bui.textwidget(
2022-12-25 00:39:49 +05:30
parent=self._root_widget,
position=(self._width * 0.5, 125),
size=(0, 0),
scale=0.8,
color=(0.7, 0.8, 0.7),
h_align='center',
v_align='center',
text=(
2023-08-13 17:21:49 +05:30
bui.charstr(bui.SpecialChar.LOCAL_ACCOUNT)
2022-12-25 00:39:49 +05:30
+ login_name
+ ' ----> '
2023-08-13 17:21:49 +05:30
+ bui.charstr(bui.SpecialChar.V2_LOGO)
2022-12-25 00:39:49 +05:30
+ login_name
),
maxwidth=self._width * 0.95,
)
button_width = 200
2023-08-13 17:21:49 +05:30
cancel_button = bui.buttonwidget(
2022-12-25 00:39:49 +05:30
parent=self._root_widget,
position=(20, 25),
size=(button_width, 65),
autoselect=True,
2023-08-13 17:21:49 +05:30
label=bui.Lstr(resource='notNowText'),
2022-12-25 00:39:49 +05:30
on_activate_call=self._done,
)
2023-08-13 17:21:49 +05:30
_what_is_this_button = bui.buttonwidget(
2022-12-25 00:39:49 +05:30
parent=self._root_widget,
position=(self._width * 0.5 - button_width * 0.5, 25),
size=(button_width, 65),
autoselect=True,
2023-08-13 17:21:49 +05:30
label=bui.Lstr(resource='whatIsThisText'),
2022-12-25 00:39:49 +05:30
color=(0.55, 0.5, 0.6),
textcolor=(0.75, 0.7, 0.8),
on_activate_call=show_what_is_v2_page,
)
2023-08-13 17:21:49 +05:30
upgrade_button = bui.buttonwidget(
2022-12-25 00:39:49 +05:30
parent=self._root_widget,
position=(self._width - button_width - 20, 25),
size=(button_width, 65),
autoselect=True,
2023-08-13 17:21:49 +05:30
label=bui.Lstr(resource='upgradeText'),
2022-12-25 00:39:49 +05:30
on_activate_call=self._upgrade_press,
)
2023-08-13 17:21:49 +05:30
bui.containerwidget(
2022-12-25 00:39:49 +05:30
edit=self._root_widget,
selected_child=upgrade_button,
cancel_button=cancel_button,
)
def _upgrade_press(self) -> None:
2023-08-13 17:21:49 +05:30
plus = bui.app.plus
assert plus is not None
2022-12-25 00:39:49 +05:30
# Get rid of the window and sign out before kicking the
# user over to a browser to do the upgrade. This hopefully
# makes it more clear when they come back that they need to
# sign in with the 'BombSquad account' option.
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, transition='out_left')
plus.sign_out_v1()
2025-09-07 18:34:55 +05:30
bamasteraddr = plus.get_master_server_address()
2023-08-13 17:21:49 +05:30
bui.open_url(f'{bamasteraddr}/v2uda/{self._code}')
2022-12-25 00:39:49 +05:30
def _done(self) -> None:
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, transition='out_left')
2025-02-09 00:17:58 +05:30
def show_what_is_v2_page() -> None:
"""Show the webpage describing V2 accounts."""
plus = bui.app.plus
assert plus is not None
2025-09-07 18:34:55 +05:30
bamasteraddr = plus.get_master_server_address()
2025-02-09 00:17:58 +05:30
bui.open_url(f'{bamasteraddr}/whatisv2')