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

1325 lines
48 KiB
Python
Raw Normal View History

2021-03-29 03:24:13 +05:30
# Released under the MIT License. See LICENSE for details.
#
"""Implements the main menu window."""
# pylint: disable=too-many-lines
from __future__ import annotations
from typing import TYPE_CHECKING
2023-08-13 17:21:49 +05:30
import logging
2021-03-29 03:24:13 +05:30
2023-08-13 17:21:49 +05:30
import bauiv1 as bui
import bascenev1 as bs
2021-03-29 03:24:13 +05:30
if TYPE_CHECKING:
2022-06-30 00:31:52 +05:30
from typing import Any, Callable
2021-03-29 03:24:13 +05:30
2023-08-13 17:21:49 +05:30
class MainMenuWindow(bui.Window):
2021-03-29 03:24:13 +05:30
"""The main menu window, both in-game and in the main menu session."""
2022-06-30 00:31:52 +05:30
def __init__(self, transition: str | None = 'in_right'):
2021-03-29 03:24:13 +05:30
# pylint: disable=cyclic-import
import threading
2023-08-13 17:21:49 +05:30
from bascenev1lib.mainmenu import MainMenuSession
plus = bui.app.plus
assert plus is not None
2022-10-01 14:51:35 +05:30
self._in_game = not isinstance(
2023-08-13 17:21:49 +05:30
bs.get_foreground_host_session(),
MainMenuSession,
)
2021-03-29 03:24:13 +05:30
# Preload some modules we use in a background thread so we won't
# have a visual hitch when the user taps them.
threading.Thread(target=self._preload_modules).start()
if not self._in_game:
2023-08-13 17:21:49 +05:30
bui.set_analytics_screen('Main Menu')
2021-03-29 03:24:13 +05:30
self._show_remote_app_info_on_first_launch()
# Make a vanilla container; we'll modify it to our needs in refresh.
super().__init__(
2023-08-13 17:21:49 +05:30
root_widget=bui.containerwidget(
transition=transition,
toolbar_visibility='menu_minimal_no_back'
if self._in_game
else 'menu_minimal_no_back',
)
)
2021-03-29 03:24:13 +05:30
# Grab this stuff in case it changes.
2023-09-30 17:21:33 +05:30
self._is_demo = bui.app.env.demo
self._is_arcade = bui.app.env.arcade
2021-03-29 03:24:13 +05:30
self._tdelay = 0.0
self._t_delay_inc = 0.02
self._t_delay_play = 1.7
self._p_index = 0
self._use_autoselect = True
self._button_width = 200.0
self._button_height = 45.0
self._width = 100.0
self._height = 100.0
2023-08-13 17:21:49 +05:30
self._demo_menu_button: bui.Widget | None = None
self._gather_button: bui.Widget | None = None
self._start_button: bui.Widget | None = None
self._watch_button: bui.Widget | None = None
self._account_button: bui.Widget | None = None
self._how_to_play_button: bui.Widget | None = None
self._credits_button: bui.Widget | None = None
self._settings_button: bui.Widget | None = None
2022-10-08 01:41:38 +05:30
self._next_refresh_allow_time = 0.0
2021-03-29 03:24:13 +05:30
self._store_char_tex = self._get_store_char_tex()
self._refresh()
self._restore_state()
# Keep an eye on a few things and refresh if they change.
2023-08-13 17:21:49 +05:30
self._account_state = plus.get_v1_account_state()
self._account_state_num = plus.get_v1_account_state_num()
self._account_type = (
2023-08-13 17:21:49 +05:30
plus.get_v1_account_type()
if self._account_state == 'signed_in'
else None
)
2023-08-13 17:21:49 +05:30
self._refresh_timer = bui.AppTimer(
0.27, bui.WeakCall(self._check_refresh), repeat=True
)
2021-03-29 03:24:13 +05:30
2022-06-09 01:26:46 +05:30
# noinspection PyUnresolvedReferences
2021-03-29 03:24:13 +05:30
@staticmethod
def _preload_modules() -> None:
2023-09-30 17:21:33 +05:30
"""Preload modules we use; avoids hitches (called in bg thread)."""
2023-08-13 17:21:49 +05:30
import bauiv1lib.getremote as _unused
import bauiv1lib.confirm as _unused2
import bauiv1lib.store.button as _unused3
import bauiv1lib.kiosk as _unused4
import bauiv1lib.account.settings as _unused5
import bauiv1lib.store.browser as _unused6
import bauiv1lib.creditslist as _unused7
import bauiv1lib.helpui as _unused8
import bauiv1lib.settings.allsettings as _unused9
import bauiv1lib.gather as _unused10
import bauiv1lib.watch as _unused11
import bauiv1lib.play as _unused12
2021-03-29 03:24:13 +05:30
def _show_remote_app_info_on_first_launch(self) -> None:
2023-08-13 17:21:49 +05:30
app = bui.app
assert app.classic is not None
2021-03-29 03:24:13 +05:30
# The first time the non-in-game menu pops up, we might wanna show
# a 'get-remote-app' dialog in front of it.
2023-08-13 17:21:49 +05:30
if app.classic.first_main_menu:
app.classic.first_main_menu = False
2021-03-29 03:24:13 +05:30
try:
force_test = False
2023-08-13 17:21:49 +05:30
bs.get_local_active_input_devices_count()
if (
2023-09-30 17:21:33 +05:30
(app.env.tv or app.classic.platform == 'mac')
2023-08-13 17:21:49 +05:30
and bui.app.config.get('launchCount', 0) <= 1
) or force_test:
2021-03-29 03:24:13 +05:30
def _check_show_bs_remote_window() -> None:
try:
2023-08-13 17:21:49 +05:30
from bauiv1lib.getremote import GetBSRemoteWindow
2023-08-13 17:21:49 +05:30
bui.getsound('swish').play()
2021-03-29 03:24:13 +05:30
GetBSRemoteWindow()
except Exception:
2023-08-13 17:21:49 +05:30
logging.exception(
'Error showing get-remote window.'
)
2023-08-13 17:21:49 +05:30
bui.apptimer(2.5, _check_show_bs_remote_window)
2021-03-29 03:24:13 +05:30
except Exception:
2023-08-13 17:21:49 +05:30
logging.exception('Error showing get-remote-app info.')
2021-03-29 03:24:13 +05:30
def _get_store_char_tex(self) -> str:
2023-08-13 17:21:49 +05:30
plus = bui.app.plus
assert plus is not None
2022-10-01 14:51:35 +05:30
return (
'storeCharacterXmas'
2023-08-13 17:21:49 +05:30
if plus.get_v1_account_misc_read_val('xmas', False)
else 'storeCharacterEaster'
2023-08-13 17:21:49 +05:30
if plus.get_v1_account_misc_read_val('easter', False)
else 'storeCharacter'
)
2021-03-29 03:24:13 +05:30
def _check_refresh(self) -> None:
2023-08-13 17:21:49 +05:30
plus = bui.app.plus
assert plus is not None
2021-03-29 03:24:13 +05:30
if not self._root_widget:
return
2023-08-13 17:21:49 +05:30
now = bui.apptime()
2022-10-08 01:41:38 +05:30
if now < self._next_refresh_allow_time:
return
2021-03-29 03:24:13 +05:30
# Don't refresh for the first few seconds the game is up so we don't
# interrupt the transition in.
2023-08-13 17:21:49 +05:30
# bui.app.main_menu_window_refresh_check_count += 1
# if bui.app.main_menu_window_refresh_check_count < 4:
2022-10-08 01:41:38 +05:30
# return
2021-03-29 03:24:13 +05:30
store_char_tex = self._get_store_char_tex()
2023-08-13 17:21:49 +05:30
account_state_num = plus.get_v1_account_state_num()
if (
account_state_num != self._account_state_num
or store_char_tex != self._store_char_tex
):
2021-03-29 03:24:13 +05:30
self._store_char_tex = store_char_tex
self._account_state_num = account_state_num
2023-08-13 17:21:49 +05:30
account_state = self._account_state = plus.get_v1_account_state()
self._account_type = (
2023-08-13 17:21:49 +05:30
plus.get_v1_account_type()
if account_state == 'signed_in'
else None
)
2021-03-29 03:24:13 +05:30
self._save_state()
self._refresh()
self._restore_state()
2023-08-13 17:21:49 +05:30
def get_play_button(self) -> bui.Widget | None:
2021-03-29 03:24:13 +05:30
"""Return the play button."""
return self._start_button
def _refresh(self) -> None:
# pylint: disable=too-many-branches
# pylint: disable=too-many-locals
# pylint: disable=too-many-statements
2023-08-13 17:21:49 +05:30
from bauiv1lib.confirm import QuitWindow
from bauiv1lib.store.button import StoreButton
plus = bui.app.plus
assert plus is not None
2021-03-29 03:24:13 +05:30
# Clear everything that was there.
children = self._root_widget.get_children()
for child in children:
child.delete()
self._tdelay = 0.0
self._t_delay_inc = 0.0
self._t_delay_play = 0.0
self._button_width = 200.0
self._button_height = 45.0
self._r = 'mainMenu'
2023-08-13 17:21:49 +05:30
app = bui.app
assert app.classic is not None
self._have_quit_button = app.ui_v1.uiscale is bui.UIScale.LARGE or (
app.classic.platform == 'windows'
and app.classic.subplatform == 'oculus'
)
2021-03-29 03:24:13 +05:30
self._have_store_button = not self._in_game
self._have_settings_button = (
2023-09-30 17:21:33 +05:30
not self._in_game or not app.ui_v1.use_toolbars
) and not (self._is_demo or self._is_arcade)
2021-03-29 03:24:13 +05:30
2023-08-13 17:21:49 +05:30
self._input_device = input_device = bs.get_ui_input_device()
# Are we connected to a local player?
2021-03-29 03:24:13 +05:30
self._input_player = input_device.player if input_device else None
2023-08-13 17:21:49 +05:30
# Are we connected to a remote player?.
2021-03-29 03:24:13 +05:30
self._connected_to_remote_player = (
2023-08-13 17:21:49 +05:30
input_device.is_attached_to_player()
if (input_device and self._input_player is None)
else False
)
2021-03-29 03:24:13 +05:30
positions: list[tuple[float, float, float]] = []
2021-03-29 03:24:13 +05:30
self._p_index = 0
if self._in_game:
h, v, scale = self._refresh_in_game(positions)
else:
h, v, scale = self._refresh_not_in_game(positions)
if self._have_settings_button:
h, v, scale = positions[self._p_index]
self._p_index += 1
2023-08-13 17:21:49 +05:30
self._settings_button = bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
position=(h - self._button_width * 0.5 * scale, v),
size=(self._button_width, self._button_height),
scale=scale,
autoselect=self._use_autoselect,
2023-08-13 17:21:49 +05:30
label=bui.Lstr(resource=self._r + '.settingsText'),
2021-03-29 03:24:13 +05:30
transition_delay=self._tdelay,
on_activate_call=self._settings,
)
2021-03-29 03:24:13 +05:30
# Scattered eggs on easter.
if (
2023-08-13 17:21:49 +05:30
plus.get_v1_account_misc_read_val('easter', False)
and not self._in_game
):
2021-03-29 03:24:13 +05:30
icon_size = 34
2023-08-13 17:21:49 +05:30
bui.imagewidget(
parent=self._root_widget,
position=(
h - icon_size * 0.5 - 15,
v + self._button_height * scale - icon_size * 0.24 + 1.5,
),
transition_delay=self._tdelay,
size=(icon_size, icon_size),
2023-08-13 17:21:49 +05:30
texture=bui.gettexture('egg3'),
tilt_scale=0.0,
)
2021-03-29 03:24:13 +05:30
self._tdelay += self._t_delay_inc
if self._in_game:
h, v, scale = positions[self._p_index]
self._p_index += 1
# If we're in a replay, we have a 'Leave Replay' button.
2023-08-13 17:21:49 +05:30
if bs.is_in_replay():
bui.buttonwidget(
parent=self._root_widget,
position=(h - self._button_width * 0.5 * scale, v),
scale=scale,
size=(self._button_width, self._button_height),
autoselect=self._use_autoselect,
2023-08-13 17:21:49 +05:30
label=bui.Lstr(resource='replayEndText'),
on_activate_call=self._confirm_end_replay,
)
2023-08-13 17:21:49 +05:30
elif bs.get_foreground_host_session() is not None:
bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
position=(h - self._button_width * 0.5 * scale, v),
scale=scale,
size=(self._button_width, self._button_height),
autoselect=self._use_autoselect,
2023-08-13 17:21:49 +05:30
label=bui.Lstr(
resource=self._r
+ (
'.endTestText'
if self._is_benchmark()
else '.endGameText'
)
),
on_activate_call=(
self._confirm_end_test
if self._is_benchmark()
else self._confirm_end_game
),
)
2021-03-29 03:24:13 +05:30
# Assume we're in a client-session.
else:
2023-08-13 17:21:49 +05:30
bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
position=(h - self._button_width * 0.5 * scale, v),
scale=scale,
size=(self._button_width, self._button_height),
autoselect=self._use_autoselect,
2023-08-13 17:21:49 +05:30
label=bui.Lstr(resource=self._r + '.leavePartyText'),
on_activate_call=self._confirm_leave_party,
)
2021-03-29 03:24:13 +05:30
2023-08-13 17:21:49 +05:30
self._store_button: bui.Widget | None
2021-03-29 03:24:13 +05:30
if self._have_store_button:
this_b_width = self._button_width
h, v, scale = positions[self._p_index]
self._p_index += 1
sbtn = self._store_button_instance = StoreButton(
parent=self._root_widget,
position=(h - this_b_width * 0.5 * scale, v),
size=(this_b_width, self._button_height),
scale=scale,
2023-08-13 17:21:49 +05:30
on_activate_call=bui.WeakCall(self._on_store_pressed),
2021-03-29 03:24:13 +05:30
sale_scale=1.3,
transition_delay=self._tdelay,
)
2021-03-29 03:24:13 +05:30
self._store_button = store_button = sbtn.get_button()
2023-08-13 17:21:49 +05:30
assert bui.app.classic is not None
uiscale = bui.app.ui_v1.uiscale
icon_size = (
55
2023-08-13 17:21:49 +05:30
if uiscale is bui.UIScale.SMALL
else 55
2023-08-13 17:21:49 +05:30
if uiscale is bui.UIScale.MEDIUM
else 70
)
2023-08-13 17:21:49 +05:30
bui.imagewidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
position=(
h - icon_size * 0.5,
v + self._button_height * scale - icon_size * 0.23,
),
2021-03-29 03:24:13 +05:30
transition_delay=self._tdelay,
size=(icon_size, icon_size),
2023-08-13 17:21:49 +05:30
texture=bui.gettexture(self._store_char_tex),
2021-03-29 03:24:13 +05:30
tilt_scale=0.0,
draw_controller=store_button,
)
2021-03-29 03:24:13 +05:30
self._tdelay += self._t_delay_inc
else:
self._store_button = None
2023-08-13 17:21:49 +05:30
self._quit_button: bui.Widget | None
2021-03-29 03:24:13 +05:30
if not self._in_game and self._have_quit_button:
h, v, scale = positions[self._p_index]
self._p_index += 1
2023-08-13 17:21:49 +05:30
self._quit_button = quit_button = bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
autoselect=self._use_autoselect,
position=(h - self._button_width * 0.5 * scale, v),
size=(self._button_width, self._button_height),
scale=scale,
2023-08-13 17:21:49 +05:30
label=bui.Lstr(
resource=self._r
+ (
'.quitText'
2023-08-13 17:21:49 +05:30
if 'Mac' in app.classic.legacy_user_agent_string
else '.exitGameText'
)
),
2021-03-29 03:24:13 +05:30
on_activate_call=self._quit,
transition_delay=self._tdelay,
)
2021-03-29 03:24:13 +05:30
# Scattered eggs on easter.
2023-08-13 17:21:49 +05:30
if plus.get_v1_account_misc_read_val('easter', False):
2021-03-29 03:24:13 +05:30
icon_size = 30
2023-08-13 17:21:49 +05:30
bui.imagewidget(
parent=self._root_widget,
position=(
h - icon_size * 0.5 + 25,
v
+ self._button_height * scale
- icon_size * 0.24
+ 1.5,
),
transition_delay=self._tdelay,
size=(icon_size, icon_size),
2023-08-13 17:21:49 +05:30
texture=bui.gettexture('egg1'),
tilt_scale=0.0,
)
2023-08-13 17:21:49 +05:30
bui.containerwidget(
edit=self._root_widget, cancel_button=quit_button
)
2021-03-29 03:24:13 +05:30
self._tdelay += self._t_delay_inc
else:
self._quit_button = None
# If we're not in-game, have no quit button, and this is android,
# we want back presses to quit our activity.
if (
not self._in_game
and not self._have_quit_button
2023-08-13 17:21:49 +05:30
and app.classic.platform == 'android'
):
2021-03-29 03:24:13 +05:30
def _do_quit() -> None:
QuitWindow(swish=True, back=True)
2023-08-13 17:21:49 +05:30
bui.containerwidget(
edit=self._root_widget, on_cancel_call=_do_quit
)
2021-03-29 03:24:13 +05:30
# Add speed-up/slow-down buttons for replays.
# (ideally this should be part of a fading-out playback bar like most
# media players but this works for now).
2023-08-13 17:21:49 +05:30
if bs.is_in_replay():
2021-03-29 03:24:13 +05:30
b_size = 50.0
b_buffer = 10.0
t_scale = 0.75
2023-08-13 17:21:49 +05:30
assert bui.app.classic is not None
uiscale = bui.app.ui_v1.uiscale
if uiscale is bui.UIScale.SMALL:
2021-03-29 03:24:13 +05:30
b_size *= 0.6
b_buffer *= 1.0
v_offs = -40
t_scale = 0.5
2023-08-13 17:21:49 +05:30
elif uiscale is bui.UIScale.MEDIUM:
2021-03-29 03:24:13 +05:30
v_offs = -70
else:
v_offs = -100
2023-08-13 17:21:49 +05:30
self._replay_speed_text = bui.textwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
2023-08-13 17:21:49 +05:30
text=bui.Lstr(
resource='watchWindow.playbackSpeedText',
subs=[('${SPEED}', str(1.23))],
),
2021-03-29 03:24:13 +05:30
position=(h, v + v_offs + 7 * t_scale),
h_align='center',
v_align='center',
size=(0, 0),
scale=t_scale,
)
2021-03-29 03:24:13 +05:30
# Update to current value.
self._change_replay_speed(0)
# Keep updating in a timer in case it gets changed elsewhere.
2023-08-13 17:21:49 +05:30
self._change_replay_speed_timer = bui.AppTimer(
0.25, bui.WeakCall(self._change_replay_speed, 0), repeat=True
)
2023-08-13 17:21:49 +05:30
btn = bui.buttonwidget(
parent=self._root_widget,
position=(
h - b_size - b_buffer,
v - b_size - b_buffer + v_offs,
),
button_type='square',
size=(b_size, b_size),
label='',
autoselect=True,
2023-08-13 17:21:49 +05:30
on_activate_call=bui.Call(self._change_replay_speed, -1),
)
2023-08-13 17:21:49 +05:30
bui.textwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
draw_controller=btn,
text='-',
position=(
h - b_size * 0.5 - b_buffer,
v - b_size * 0.5 - b_buffer + 5 * t_scale + v_offs,
),
2021-03-29 03:24:13 +05:30
h_align='center',
v_align='center',
size=(0, 0),
scale=3.0 * t_scale,
)
2023-08-13 17:21:49 +05:30
btn = bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
position=(h + b_buffer, v - b_size - b_buffer + v_offs),
button_type='square',
size=(b_size, b_size),
label='',
autoselect=True,
2023-08-13 17:21:49 +05:30
on_activate_call=bui.Call(self._change_replay_speed, 1),
)
2023-08-13 17:21:49 +05:30
bui.textwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
draw_controller=btn,
text='+',
position=(
h + b_size * 0.5 + b_buffer,
v - b_size * 0.5 - b_buffer + 5 * t_scale + v_offs,
),
2021-03-29 03:24:13 +05:30
h_align='center',
v_align='center',
size=(0, 0),
scale=3.0 * t_scale,
)
2021-03-29 03:24:13 +05:30
def _refresh_not_in_game(
self, positions: list[tuple[float, float, float]]
) -> tuple[float, float, float]:
2021-03-29 03:24:13 +05:30
# pylint: disable=too-many-branches
# pylint: disable=too-many-locals
# pylint: disable=too-many-statements
2023-08-13 17:21:49 +05:30
plus = bui.app.plus
assert plus is not None
assert bui.app.classic is not None
if not bui.app.classic.did_menu_intro:
2021-03-29 03:24:13 +05:30
self._tdelay = 2.0
self._t_delay_inc = 0.02
self._t_delay_play = 1.7
2022-12-25 00:39:49 +05:30
def _set_allow_time() -> None:
2023-08-13 17:21:49 +05:30
self._next_refresh_allow_time = bui.apptime() + 2.5
2022-12-25 00:39:49 +05:30
# Slight hack: widget transitions currently only progress when
# frames are being drawn, but this tends to get called before
# frame drawing even starts, meaning we don't know exactly how
# long we should wait before refreshing to avoid interrupting
# the transition. To make things a bit better, let's do a
# redundant set of the time in a deferred call which hopefully
# happens closer to actual frame draw times.
_set_allow_time()
2023-08-13 17:21:49 +05:30
bui.pushcall(_set_allow_time)
2022-12-25 00:39:49 +05:30
2023-08-13 17:21:49 +05:30
bui.app.classic.did_menu_intro = True
2021-03-29 03:24:13 +05:30
self._width = 400.0
self._height = 200.0
enable_account_button = True
2023-08-13 17:21:49 +05:30
account_type_name: str | bui.Lstr
if plus.get_v1_account_state() == 'signed_in':
account_type_name = plus.get_v1_account_display_string()
2021-03-29 03:24:13 +05:30
account_type_icon = None
account_textcolor = (1.0, 1.0, 1.0)
else:
2023-08-13 17:21:49 +05:30
account_type_name = bui.Lstr(
2021-03-29 03:24:13 +05:30
resource='notSignedInText',
fallback_resource='accountSettingsWindow.titleText',
)
2021-03-29 03:24:13 +05:30
account_type_icon = None
account_textcolor = (1.0, 0.2, 0.2)
account_type_icon_color = (1.0, 1.0, 1.0)
account_type_call = self._show_account_window
account_type_enable_button_sound = True
b_count = 3 # play, help, credits
if self._have_settings_button:
b_count += 1
if enable_account_button:
b_count += 1
if self._have_quit_button:
b_count += 1
if self._have_store_button:
b_count += 1
2023-08-13 17:21:49 +05:30
uiscale = bui.app.ui_v1.uiscale
if uiscale is bui.UIScale.SMALL:
2021-03-29 03:24:13 +05:30
root_widget_scale = 1.6
play_button_width = self._button_width * 0.65
play_button_height = self._button_height * 1.1
small_button_scale = 0.51 if b_count > 6 else 0.63
button_y_offs = -20.0
button_y_offs2 = -60.0
self._button_height *= 1.3
button_spacing = 1.04
2023-08-13 17:21:49 +05:30
elif uiscale is bui.UIScale.MEDIUM:
2021-03-29 03:24:13 +05:30
root_widget_scale = 1.3
play_button_width = self._button_width * 0.65
play_button_height = self._button_height * 1.1
small_button_scale = 0.6
button_y_offs = -55.0
button_y_offs2 = -75.0
self._button_height *= 1.25
button_spacing = 1.1
else:
root_widget_scale = 1.0
play_button_width = self._button_width * 0.65
play_button_height = self._button_height * 1.1
small_button_scale = 0.75
button_y_offs = -80.0
button_y_offs2 = -100.0
self._button_height *= 1.2
button_spacing = 1.1
spc = self._button_width * small_button_scale * button_spacing
2023-08-13 17:21:49 +05:30
bui.containerwidget(
edit=self._root_widget,
size=(self._width, self._height),
background=False,
scale=root_widget_scale,
)
2021-03-29 03:24:13 +05:30
assert not positions
positions.append((self._width * 0.5, button_y_offs, 1.7))
x_offs = self._width * 0.5 - (spc * (b_count - 1) * 0.5) + (spc * 0.5)
for i in range(b_count - 1):
positions.append(
(
x_offs + spc * i - 1.0,
button_y_offs + button_y_offs2,
small_button_scale,
)
)
2021-03-29 03:24:13 +05:30
# In kiosk mode, provide a button to get back to the kiosk menu.
2023-09-30 17:21:33 +05:30
if bui.app.env.demo or bui.app.env.arcade:
2021-03-29 03:24:13 +05:30
h, v, scale = positions[self._p_index]
this_b_width = self._button_width * 0.4 * scale
demo_menu_delay = (
0.0
if self._t_delay_play == 0.0
else max(0, self._t_delay_play + 0.1)
)
2023-08-13 17:21:49 +05:30
self._demo_menu_button = bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
position=(self._width * 0.5 - this_b_width * 0.5, v + 90),
size=(this_b_width, 45),
autoselect=True,
color=(0.45, 0.55, 0.45),
textcolor=(0.7, 0.8, 0.7),
2023-08-13 17:21:49 +05:30
label=bui.Lstr(
resource='modeArcadeText'
2023-09-30 17:21:33 +05:30
if bui.app.env.arcade
else 'modeDemoText'
),
2021-03-29 03:24:13 +05:30
transition_delay=demo_menu_delay,
on_activate_call=self._demo_menu_press,
)
2021-03-29 03:24:13 +05:30
else:
self._demo_menu_button = None
2023-08-13 17:21:49 +05:30
uiscale = bui.app.ui_v1.uiscale
foof = (
-1
2023-08-13 17:21:49 +05:30
if uiscale is bui.UIScale.SMALL
else 1
2023-08-13 17:21:49 +05:30
if uiscale is bui.UIScale.MEDIUM
else 3
)
2021-03-29 03:24:13 +05:30
h, v, scale = positions[self._p_index]
v = v + foof
gather_delay = (
0.0
if self._t_delay_play == 0.0
else max(0.0, self._t_delay_play + 0.1)
)
2021-03-29 03:24:13 +05:30
assert play_button_width is not None
assert play_button_height is not None
this_h = h - play_button_width * 0.5 * scale - 40 * scale
this_b_width = self._button_width * 0.25 * scale
this_b_height = self._button_height * 0.82 * scale
2023-08-13 17:21:49 +05:30
self._gather_button = btn = bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
position=(this_h - this_b_width * 0.5, v),
size=(this_b_width, this_b_height),
autoselect=self._use_autoselect,
button_type='square',
label='',
transition_delay=gather_delay,
on_activate_call=self._gather_press,
)
2023-08-13 17:21:49 +05:30
bui.textwidget(
parent=self._root_widget,
position=(this_h, v + self._button_height * 0.33),
size=(0, 0),
scale=0.75,
transition_delay=gather_delay,
draw_controller=btn,
color=(0.75, 1.0, 0.7),
maxwidth=self._button_width * 0.33,
2023-08-13 17:21:49 +05:30
text=bui.Lstr(resource='gatherWindow.titleText'),
h_align='center',
v_align='center',
)
2021-03-29 03:24:13 +05:30
icon_size = this_b_width * 0.6
2023-08-13 17:21:49 +05:30
bui.imagewidget(
parent=self._root_widget,
size=(icon_size, icon_size),
draw_controller=btn,
transition_delay=gather_delay,
position=(this_h - 0.5 * icon_size, v + 0.31 * this_b_height),
2023-08-13 17:21:49 +05:30
texture=bui.gettexture('usersButton'),
)
2021-03-29 03:24:13 +05:30
# Play button.
h, v, scale = positions[self._p_index]
self._p_index += 1
2023-08-13 17:21:49 +05:30
self._start_button = start_button = bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
position=(h - play_button_width * 0.5 * scale, v),
size=(play_button_width, play_button_height),
autoselect=self._use_autoselect,
scale=scale,
text_res_scale=2.0,
2023-08-13 17:21:49 +05:30
label=bui.Lstr(resource='playText'),
2021-03-29 03:24:13 +05:30
transition_delay=self._t_delay_play,
on_activate_call=self._play_press,
)
2023-08-13 17:21:49 +05:30
bui.containerwidget(
edit=self._root_widget,
start_button=start_button,
selected_child=start_button,
)
2021-03-29 03:24:13 +05:30
v = v + foof
watch_delay = (
0.0
if self._t_delay_play == 0.0
else max(0.0, self._t_delay_play - 0.1)
)
2021-03-29 03:24:13 +05:30
this_h = h + play_button_width * 0.5 * scale + 40 * scale
this_b_width = self._button_width * 0.25 * scale
this_b_height = self._button_height * 0.82 * scale
2023-08-13 17:21:49 +05:30
self._watch_button = btn = bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
position=(this_h - this_b_width * 0.5, v),
size=(this_b_width, this_b_height),
autoselect=self._use_autoselect,
button_type='square',
label='',
transition_delay=watch_delay,
on_activate_call=self._watch_press,
)
2023-08-13 17:21:49 +05:30
bui.textwidget(
parent=self._root_widget,
position=(this_h, v + self._button_height * 0.33),
size=(0, 0),
scale=0.75,
transition_delay=watch_delay,
color=(0.75, 1.0, 0.7),
draw_controller=btn,
maxwidth=self._button_width * 0.33,
2023-08-13 17:21:49 +05:30
text=bui.Lstr(resource='watchWindow.titleText'),
h_align='center',
v_align='center',
)
2021-03-29 03:24:13 +05:30
icon_size = this_b_width * 0.55
2023-08-13 17:21:49 +05:30
bui.imagewidget(
parent=self._root_widget,
size=(icon_size, icon_size),
draw_controller=btn,
transition_delay=watch_delay,
position=(this_h - 0.5 * icon_size, v + 0.33 * this_b_height),
2023-08-13 17:21:49 +05:30
texture=bui.gettexture('tv'),
)
2021-03-29 03:24:13 +05:30
if not self._in_game and enable_account_button:
this_b_width = self._button_width
h, v, scale = positions[self._p_index]
self._p_index += 1
2023-08-13 17:21:49 +05:30
self._account_button = bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
position=(h - this_b_width * 0.5 * scale, v),
size=(this_b_width, self._button_height),
scale=scale,
label=account_type_name,
autoselect=self._use_autoselect,
on_activate_call=account_type_call,
textcolor=account_textcolor,
icon=account_type_icon,
icon_color=account_type_icon_color,
transition_delay=self._tdelay,
enable_sound=account_type_enable_button_sound,
)
2021-03-29 03:24:13 +05:30
# Scattered eggs on easter.
if (
2023-08-13 17:21:49 +05:30
plus.get_v1_account_misc_read_val('easter', False)
and not self._in_game
):
2021-03-29 03:24:13 +05:30
icon_size = 32
2023-08-13 17:21:49 +05:30
bui.imagewidget(
parent=self._root_widget,
position=(
h - icon_size * 0.5 + 35,
v
+ self._button_height * scale
- icon_size * 0.24
+ 1.5,
),
transition_delay=self._tdelay,
size=(icon_size, icon_size),
2023-08-13 17:21:49 +05:30
texture=bui.gettexture('egg2'),
tilt_scale=0.0,
)
2021-03-29 03:24:13 +05:30
self._tdelay += self._t_delay_inc
else:
2022-10-08 01:41:38 +05:30
self._account_button = None
2021-03-29 03:24:13 +05:30
# How-to-play button.
h, v, scale = positions[self._p_index]
self._p_index += 1
2023-08-13 17:21:49 +05:30
btn = bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
position=(h - self._button_width * 0.5 * scale, v),
scale=scale,
autoselect=self._use_autoselect,
size=(self._button_width, self._button_height),
2023-08-13 17:21:49 +05:30
label=bui.Lstr(resource=self._r + '.howToPlayText'),
2021-03-29 03:24:13 +05:30
transition_delay=self._tdelay,
on_activate_call=self._howtoplay,
)
2021-03-29 03:24:13 +05:30
self._how_to_play_button = btn
# Scattered eggs on easter.
if (
2023-08-13 17:21:49 +05:30
plus.get_v1_account_misc_read_val('easter', False)
and not self._in_game
):
2021-03-29 03:24:13 +05:30
icon_size = 28
2023-08-13 17:21:49 +05:30
bui.imagewidget(
parent=self._root_widget,
position=(
h - icon_size * 0.5 + 30,
v + self._button_height * scale - icon_size * 0.24 + 1.5,
),
transition_delay=self._tdelay,
size=(icon_size, icon_size),
2023-08-13 17:21:49 +05:30
texture=bui.gettexture('egg4'),
tilt_scale=0.0,
)
2021-03-29 03:24:13 +05:30
# Credits button.
self._tdelay += self._t_delay_inc
h, v, scale = positions[self._p_index]
self._p_index += 1
2023-08-13 17:21:49 +05:30
self._credits_button = bui.buttonwidget(
2021-03-29 03:24:13 +05:30
parent=self._root_widget,
position=(h - self._button_width * 0.5 * scale, v),
size=(self._button_width, self._button_height),
autoselect=self._use_autoselect,
2023-08-13 17:21:49 +05:30
label=bui.Lstr(resource=self._r + '.creditsText'),
2021-03-29 03:24:13 +05:30
scale=scale,
transition_delay=self._tdelay,
on_activate_call=self._credits,
)
2021-03-29 03:24:13 +05:30
self._tdelay += self._t_delay_inc
return h, v, scale
def _refresh_in_game(
self, positions: list[tuple[float, float, float]]
) -> tuple[float, float, float]:
2021-03-29 03:24:13 +05:30
# pylint: disable=too-many-branches
# pylint: disable=too-many-locals
# pylint: disable=too-many-statements
2023-08-13 17:21:49 +05:30
assert bui.app.classic is not None
custom_menu_entries: list[dict[str, Any]] = []
2023-08-13 17:21:49 +05:30
session = bs.get_foreground_host_session()
2021-03-29 03:24:13 +05:30
if session is not None:
try:
custom_menu_entries = session.get_custom_menu_entries()
for cme in custom_menu_entries:
2023-08-13 17:21:49 +05:30
cme_any: Any = cme # Type check may not hold true.
if (
2023-08-13 17:21:49 +05:30
not isinstance(cme_any, dict)
or 'label' not in cme
2023-08-13 17:21:49 +05:30
or not isinstance(cme['label'], (str, bui.Lstr))
or 'call' not in cme
or not callable(cme['call'])
):
raise ValueError(
'invalid custom menu entry: ' + str(cme)
)
2021-03-29 03:24:13 +05:30
except Exception:
custom_menu_entries = []
2023-08-13 17:21:49 +05:30
logging.exception(
'Error getting custom menu entries for %s.', session
)
2021-03-29 03:24:13 +05:30
self._width = 250.0
self._height = 250.0 if self._input_player else 180.0
if (self._is_demo or self._is_arcade) and self._input_player:
self._height -= 40
if not self._have_settings_button:
self._height -= 50
if self._connected_to_remote_player:
# In this case we have a leave *and* a disconnect button.
self._height += 50
self._height += 50 * (len(custom_menu_entries))
2023-08-13 17:21:49 +05:30
uiscale = bui.app.ui_v1.uiscale
bui.containerwidget(
2021-03-29 03:24:13 +05:30
edit=self._root_widget,
size=(self._width, self._height),
scale=(
2.15
2023-08-13 17:21:49 +05:30
if uiscale is bui.UIScale.SMALL
else 1.6
2023-08-13 17:21:49 +05:30
if uiscale is bui.UIScale.MEDIUM
else 1.0
),
)
2021-03-29 03:24:13 +05:30
h = 125.0
v = self._height - 80.0 if self._input_player else self._height - 60
2021-03-29 03:24:13 +05:30
h_offset = 0
d_h_offset = 0
v_offset = -50
for _i in range(6 + len(custom_menu_entries)):
positions.append((h, v, 1.0))
v += v_offset
h += h_offset
h_offset += d_h_offset
self._start_button = None
2023-08-13 17:21:49 +05:30
bui.app.classic.pause()
2021-03-29 03:24:13 +05:30
# Player name if applicable.
if self._input_player:
player_name = self._input_player.getname()
h, v, scale = positions[self._p_index]
v += 35
2023-08-13 17:21:49 +05:30
bui.textwidget(
parent=self._root_widget,
position=(h - self._button_width / 2, v),
size=(self._button_width, self._button_height),
color=(1, 1, 1, 0.5),
scale=0.7,
h_align='center',
2023-08-13 17:21:49 +05:30
text=bui.Lstr(value=player_name),
)
2021-03-29 03:24:13 +05:30
else:
player_name = ''
h, v, scale = positions[self._p_index]
self._p_index += 1
2023-08-13 17:21:49 +05:30
btn = bui.buttonwidget(
parent=self._root_widget,
position=(h - self._button_width / 2, v),
size=(self._button_width, self._button_height),
scale=scale,
2023-08-13 17:21:49 +05:30
label=bui.Lstr(resource=self._r + '.resumeText'),
autoselect=self._use_autoselect,
on_activate_call=self._resume,
)
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, cancel_button=btn)
2021-03-29 03:24:13 +05:30
# Add any custom options defined by the current game.
for entry in custom_menu_entries:
h, v, scale = positions[self._p_index]
self._p_index += 1
# Ask the entry whether we should resume when we call
# it (defaults to true).
resume = bool(entry.get('resume_on_call', True))
if resume:
2023-08-13 17:21:49 +05:30
call = bui.Call(self._resume_and_call, entry['call'])
2021-03-29 03:24:13 +05:30
else:
2023-08-13 17:21:49 +05:30
call = bui.Call(entry['call'], bui.WeakCall(self._resume))
2021-03-29 03:24:13 +05:30
2023-08-13 17:21:49 +05:30
bui.buttonwidget(
parent=self._root_widget,
position=(h - self._button_width / 2, v),
size=(self._button_width, self._button_height),
scale=scale,
on_activate_call=call,
label=entry['label'],
autoselect=self._use_autoselect,
)
2021-03-29 03:24:13 +05:30
# Add a 'leave' button if the menu-owner has a player.
if (self._input_player or self._connected_to_remote_player) and not (
self._is_demo or self._is_arcade
):
2021-03-29 03:24:13 +05:30
h, v, scale = positions[self._p_index]
self._p_index += 1
2023-08-13 17:21:49 +05:30
btn = bui.buttonwidget(
parent=self._root_widget,
position=(h - self._button_width / 2, v),
size=(self._button_width, self._button_height),
scale=scale,
on_activate_call=self._leave,
label='',
autoselect=self._use_autoselect,
)
if (
player_name != ''
and player_name[0] != '<'
and player_name[-1] != '>'
):
2023-08-13 17:21:49 +05:30
txt = bui.Lstr(
resource=self._r + '.justPlayerText',
subs=[('${NAME}', player_name)],
)
2021-03-29 03:24:13 +05:30
else:
2023-08-13 17:21:49 +05:30
txt = bui.Lstr(value=player_name)
bui.textwidget(
parent=self._root_widget,
position=(
h,
v
+ self._button_height
* (0.64 if player_name != '' else 0.5),
),
size=(0, 0),
2023-08-13 17:21:49 +05:30
text=bui.Lstr(resource=self._r + '.leaveGameText'),
scale=(0.83 if player_name != '' else 1.0),
color=(0.75, 1.0, 0.7),
h_align='center',
v_align='center',
draw_controller=btn,
maxwidth=self._button_width * 0.9,
)
2023-08-13 17:21:49 +05:30
bui.textwidget(
parent=self._root_widget,
position=(h, v + self._button_height * 0.27),
size=(0, 0),
text=txt,
color=(0.75, 1.0, 0.7),
h_align='center',
v_align='center',
draw_controller=btn,
scale=0.45,
maxwidth=self._button_width * 0.9,
)
2021-03-29 03:24:13 +05:30
return h, v, scale
def _change_replay_speed(self, offs: int) -> None:
if not self._replay_speed_text:
2023-08-13 17:21:49 +05:30
if bui.do_once():
2021-03-29 03:24:13 +05:30
print('_change_replay_speed called without widget')
return
2023-08-13 17:21:49 +05:30
bs.set_replay_speed_exponent(bs.get_replay_speed_exponent() + offs)
actual_speed = pow(2.0, bs.get_replay_speed_exponent())
bui.textwidget(
edit=self._replay_speed_text,
2023-08-13 17:21:49 +05:30
text=bui.Lstr(
resource='watchWindow.playbackSpeedText',
subs=[('${SPEED}', str(actual_speed))],
),
)
2021-03-29 03:24:13 +05:30
def _quit(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.confirm import QuitWindow
2021-03-29 03:24:13 +05:30
QuitWindow(origin_widget=self._quit_button)
def _demo_menu_press(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.kiosk import KioskWindow
2021-03-29 03:24:13 +05:30
self._save_state()
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, transition='out_right')
assert bui.app.classic is not None
bui.app.ui_v1.set_main_menu_window(
KioskWindow(transition='in_left').get_root_widget()
)
2021-03-29 03:24:13 +05:30
def _show_account_window(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.account.settings import AccountSettingsWindow
2021-03-29 03:24:13 +05:30
self._save_state()
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, transition='out_left')
assert bui.app.classic is not None
bui.app.ui_v1.set_main_menu_window(
2021-03-29 03:24:13 +05:30
AccountSettingsWindow(
origin_widget=self._account_button
).get_root_widget()
)
2021-03-29 03:24:13 +05:30
def _on_store_pressed(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.store.browser import StoreBrowserWindow
from bauiv1lib.account import show_sign_in_prompt
plus = bui.app.plus
assert plus is not None
2023-08-13 17:21:49 +05:30
if plus.get_v1_account_state() != 'signed_in':
2021-03-29 03:24:13 +05:30
show_sign_in_prompt()
return
self._save_state()
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, transition='out_left')
assert bui.app.classic is not None
bui.app.ui_v1.set_main_menu_window(
2021-03-29 03:24:13 +05:30
StoreBrowserWindow(
origin_widget=self._store_button
).get_root_widget()
)
2021-03-29 03:24:13 +05:30
2022-10-08 01:41:38 +05:30
def _is_benchmark(self) -> bool:
2023-08-13 17:21:49 +05:30
session = bs.get_foreground_host_session()
return getattr(session, 'benchmark_type', None) == 'cpu' or (
bui.app.classic is not None
and bui.app.classic.stress_test_reset_timer is not None
)
2022-10-08 01:41:38 +05:30
2021-03-29 03:24:13 +05:30
def _confirm_end_game(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.confirm import ConfirmWindow
2021-03-29 03:24:13 +05:30
# FIXME: Currently we crash calling this on client-sessions.
# Select cancel by default; this occasionally gets called by accident
# in a fit of button mashing and this will help reduce damage.
ConfirmWindow(
2023-08-13 17:21:49 +05:30
bui.Lstr(resource=self._r + '.exitToMenuText'),
self._end_game,
cancel_is_selected=True,
)
2021-03-29 03:24:13 +05:30
2022-10-08 01:41:38 +05:30
def _confirm_end_test(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.confirm import ConfirmWindow
2022-10-08 01:41:38 +05:30
# Select cancel by default; this occasionally gets called by accident
# in a fit of button mashing and this will help reduce damage.
ConfirmWindow(
2023-08-13 17:21:49 +05:30
bui.Lstr(resource=self._r + '.exitToMenuText'),
self._end_game,
cancel_is_selected=True,
)
2022-10-08 01:41:38 +05:30
2021-03-29 03:24:13 +05:30
def _confirm_end_replay(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.confirm import ConfirmWindow
2021-03-29 03:24:13 +05:30
# Select cancel by default; this occasionally gets called by accident
# in a fit of button mashing and this will help reduce damage.
ConfirmWindow(
2023-08-13 17:21:49 +05:30
bui.Lstr(resource=self._r + '.exitToMenuText'),
self._end_game,
cancel_is_selected=True,
)
2021-03-29 03:24:13 +05:30
def _confirm_leave_party(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.confirm import ConfirmWindow
2021-03-29 03:24:13 +05:30
# Select cancel by default; this occasionally gets called by accident
# in a fit of button mashing and this will help reduce damage.
ConfirmWindow(
2023-08-13 17:21:49 +05:30
bui.Lstr(resource=self._r + '.leavePartyConfirmText'),
self._leave_party,
cancel_is_selected=True,
)
2021-03-29 03:24:13 +05:30
def _leave_party(self) -> None:
2023-08-13 17:21:49 +05:30
bs.disconnect_from_host()
2021-03-29 03:24:13 +05:30
def _end_game(self) -> None:
2023-08-13 17:21:49 +05:30
assert bui.app.classic is not None
2021-03-29 03:24:13 +05:30
if not self._root_widget:
return
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, transition='out_left')
bui.app.classic.return_to_main_menu_session_gracefully(reset_ui=False)
2021-03-29 03:24:13 +05:30
def _leave(self) -> None:
if self._input_player:
self._input_player.remove_from_game()
elif self._connected_to_remote_player:
if self._input_device:
2023-08-13 17:21:49 +05:30
self._input_device.detach_from_player()
2021-03-29 03:24:13 +05:30
self._resume()
def _credits(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.creditslist import CreditsListWindow
2021-03-29 03:24:13 +05:30
self._save_state()
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, transition='out_left')
assert bui.app.classic is not None
bui.app.ui_v1.set_main_menu_window(
2021-03-29 03:24:13 +05:30
CreditsListWindow(
origin_widget=self._credits_button
).get_root_widget()
)
2021-03-29 03:24:13 +05:30
def _howtoplay(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.helpui import HelpWindow
2021-03-29 03:24:13 +05:30
self._save_state()
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, transition='out_left')
assert bui.app.classic is not None
bui.app.ui_v1.set_main_menu_window(
2021-03-29 03:24:13 +05:30
HelpWindow(
main_menu=True, origin_widget=self._how_to_play_button
).get_root_widget()
)
2021-03-29 03:24:13 +05:30
def _settings(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.settings.allsettings import AllSettingsWindow
2021-03-29 03:24:13 +05:30
self._save_state()
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, transition='out_left')
assert bui.app.classic is not None
bui.app.ui_v1.set_main_menu_window(
2021-03-29 03:24:13 +05:30
AllSettingsWindow(
origin_widget=self._settings_button
).get_root_widget()
)
2021-03-29 03:24:13 +05:30
def _resume_and_call(self, call: Callable[[], Any]) -> None:
self._resume()
call()
def _do_game_service_press(self) -> None:
self._save_state()
2023-08-13 17:21:49 +05:30
if bui.app.classic is not None:
bui.app.classic.show_online_score_ui()
else:
logging.warning('classic is required to show game service ui')
2021-03-29 03:24:13 +05:30
def _save_state(self) -> None:
# Don't do this for the in-game menu.
if self._in_game:
return
2023-08-13 17:21:49 +05:30
assert bui.app.classic is not None
ui = bui.app.ui_v1
2021-03-29 03:24:13 +05:30
sel = self._root_widget.get_selected_child()
if sel == self._start_button:
2023-08-13 17:21:49 +05:30
ui.main_menu_selection = 'Start'
2021-03-29 03:24:13 +05:30
elif sel == self._gather_button:
2023-08-13 17:21:49 +05:30
ui.main_menu_selection = 'Gather'
2021-03-29 03:24:13 +05:30
elif sel == self._watch_button:
2023-08-13 17:21:49 +05:30
ui.main_menu_selection = 'Watch'
2021-03-29 03:24:13 +05:30
elif sel == self._how_to_play_button:
2023-08-13 17:21:49 +05:30
ui.main_menu_selection = 'HowToPlay'
2021-03-29 03:24:13 +05:30
elif sel == self._credits_button:
2023-08-13 17:21:49 +05:30
ui.main_menu_selection = 'Credits'
2021-03-29 03:24:13 +05:30
elif sel == self._settings_button:
2023-08-13 17:21:49 +05:30
ui.main_menu_selection = 'Settings'
2022-10-08 01:41:38 +05:30
elif sel == self._account_button:
2023-08-13 17:21:49 +05:30
ui.main_menu_selection = 'Account'
2021-03-29 03:24:13 +05:30
elif sel == self._store_button:
2023-08-13 17:21:49 +05:30
ui.main_menu_selection = 'Store'
2021-03-29 03:24:13 +05:30
elif sel == self._quit_button:
2023-08-13 17:21:49 +05:30
ui.main_menu_selection = 'Quit'
2021-03-29 03:24:13 +05:30
elif sel == self._demo_menu_button:
2023-08-13 17:21:49 +05:30
ui.main_menu_selection = 'DemoMenu'
2021-03-29 03:24:13 +05:30
else:
print('unknown widget in main menu store selection:', sel)
2023-08-13 17:21:49 +05:30
ui.main_menu_selection = 'Start'
2021-03-29 03:24:13 +05:30
def _restore_state(self) -> None:
# pylint: disable=too-many-branches
# Don't do this for the in-game menu.
if self._in_game:
return
2023-08-13 17:21:49 +05:30
assert bui.app.classic is not None
sel_name = bui.app.ui_v1.main_menu_selection
sel: bui.Widget | None
2021-03-29 03:24:13 +05:30
if sel_name is None:
sel_name = 'Start'
if sel_name == 'HowToPlay':
sel = self._how_to_play_button
elif sel_name == 'Gather':
sel = self._gather_button
elif sel_name == 'Watch':
sel = self._watch_button
elif sel_name == 'Credits':
sel = self._credits_button
elif sel_name == 'Settings':
sel = self._settings_button
2022-10-08 01:41:38 +05:30
elif sel_name == 'Account':
sel = self._account_button
2021-03-29 03:24:13 +05:30
elif sel_name == 'Store':
sel = self._store_button
elif sel_name == 'Quit':
sel = self._quit_button
elif sel_name == 'DemoMenu':
sel = self._demo_menu_button
else:
sel = self._start_button
if sel is not None:
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, selected_child=sel)
2021-03-29 03:24:13 +05:30
def _gather_press(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.gather import GatherWindow
2021-03-29 03:24:13 +05:30
self._save_state()
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, transition='out_left')
assert bui.app.classic is not None
bui.app.ui_v1.set_main_menu_window(
GatherWindow(origin_widget=self._gather_button).get_root_widget()
)
2021-03-29 03:24:13 +05:30
def _watch_press(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.watch import WatchWindow
2021-03-29 03:24:13 +05:30
self._save_state()
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, transition='out_left')
assert bui.app.classic is not None
bui.app.ui_v1.set_main_menu_window(
WatchWindow(origin_widget=self._watch_button).get_root_widget()
)
2021-03-29 03:24:13 +05:30
def _play_press(self) -> None:
# pylint: disable=cyclic-import
2023-08-13 17:21:49 +05:30
from bauiv1lib.play import PlayWindow
2021-03-29 03:24:13 +05:30
self._save_state()
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, transition='out_left')
2021-03-29 03:24:13 +05:30
2023-08-13 17:21:49 +05:30
assert bui.app.classic is not None
bui.app.ui_v1.selecting_private_party_playlist = False
bui.app.ui_v1.set_main_menu_window(
PlayWindow(origin_widget=self._start_button).get_root_widget()
)
2021-03-29 03:24:13 +05:30
def _resume(self) -> None:
2023-08-13 17:21:49 +05:30
assert bui.app.classic is not None
bui.app.classic.resume()
2021-03-29 03:24:13 +05:30
if self._root_widget:
2023-08-13 17:21:49 +05:30
bui.containerwidget(edit=self._root_widget, transition='out_right')
bui.app.ui_v1.clear_main_menu_window()
2021-03-29 03:24:13 +05:30
# If there's callbacks waiting for this window to go away, call them.
2023-08-13 17:21:49 +05:30
for call in bui.app.ui_v1.main_menu_resume_callbacks:
2021-03-29 03:24:13 +05:30
call()
2023-08-13 17:21:49 +05:30
del bui.app.ui_v1.main_menu_resume_callbacks[:]