Skip to content

Commit

Permalink
toolbar ui bits are now faded when not connected to the master server
Browse files Browse the repository at this point in the history
  • Loading branch information
efroemling committed Dec 25, 2024
1 parent 66b7121 commit da64da2
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 76 deletions.
78 changes: 39 additions & 39 deletions .efrocachemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 1.7.37 (build 22143, api 9, 2024-12-22)
### 1.7.37 (build 22145, api 9, 2024-12-25)
- Bumping api version to 9. As you'll see below, there's some UI changes that
will require a bit of work for any UI mods to adapt to. If your mods don't
touch UI stuff at all you can simply bump your api version and call it a day.
Expand Down
12 changes: 11 additions & 1 deletion src/assets/ba_data/python/babase/_accountv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ def __init__(self) -> None:

from babase._login import LoginAdapterGPGS, LoginAdapterGameCenter

# Register to be informed when connectivity changes.
plus = _babase.app.plus
self._connectivity_changed_cb = (
None
if plus is None
else plus.cloud.on_connectivity_changed_callbacks.register(
self._on_cloud_connectivity_changed
)
)

# Whether or not everything related to an initial sign in (or
# lack thereof) has completed. This includes things like
# workspace syncing. Completion of this is what flips the app
Expand Down Expand Up @@ -265,7 +275,7 @@ def on_implicit_login_state_changed(
# We may want to auto-sign-in based on this new state.
self._update_auto_sign_in()

def on_cloud_connectivity_changed(self, connected: bool) -> None:
def _on_cloud_connectivity_changed(self, connected: bool) -> None:
"""Should be called with cloud connectivity changes."""
del connected # Unused.
assert _babase.in_logic_thread()
Expand Down
16 changes: 9 additions & 7 deletions src/assets/ba_data/python/babase/_appmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@ def can_handle_intent(cls, intent: AppIntent) -> bool:
"""Return whether this mode can handle the provided intent.
For this to return True, the AppMode must claim to support the
provided intent (via its _supports_intent() method) AND the
provided intent (via its _can_handle_intent() method) AND the
AppExperience associated with the AppMode must be supported by
the current app and runtime environment.
"""
# TODO: check AppExperience.
return cls._supports_intent(intent)
# TODO: check AppExperience against current environment.
return cls._can_handle_intent(intent)

@classmethod
def _supports_intent(cls, intent: AppIntent) -> bool:
def _can_handle_intent(cls, intent: AppIntent) -> bool:
"""Return whether our mode can handle the provided intent.
AppModes should override this to define what they can handle.
Note that AppExperience does not have to be considered here; that
is handled automatically by the can_handle_intent() call."""
AppModes should override this to communicate what they can
handle. Note that AppExperience does not have to be considered
here; that is handled automatically by the can_handle_intent()
call.
"""
raise NotImplementedError('AppMode subclasses must override this.')

def handle_intent(self, intent: AppIntent) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/assets/ba_data/python/babase/_emptyappmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_app_experience(cls) -> AppExperience:

@override
@classmethod
def _supports_intent(cls, intent: AppIntent) -> bool:
def _can_handle_intent(cls, intent: AppIntent) -> bool:
# We support default and exec intents currently.
return isinstance(intent, AppIntentExec | AppIntentDefault)

Expand Down
50 changes: 42 additions & 8 deletions src/assets/ba_data/python/baclassic/_appmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,23 @@ def __init__(self) -> None:
self._on_primary_account_changed_callback: (
CallbackRegistration | None
) = None
self._on_connectivity_changed_callback: CallbackRegistration | None = (
None
)
self._test_sub: babase.CloudSubscription | None = None
self._account_data_sub: babase.CloudSubscription | None = None

self._have_account_values = False
self._have_connectivity = False

@override
@classmethod
def get_app_experience(cls) -> AppExperience:
return AppExperience.MELEE

@override
@classmethod
def _supports_intent(cls, intent: babase.AppIntent) -> bool:
def _can_handle_intent(cls, intent: babase.AppIntent) -> bool:
# We support default and exec intents currently.
return isinstance(
intent, babase.AppIntentExec | babase.AppIntentDefault
Expand Down Expand Up @@ -118,14 +124,22 @@ def on_activate(self) -> None:
self._root_ui_chest_slot_pressed, 3
)

# We want to be informed when connectivity changes.
self._on_connectivity_changed_callback = (
plus.cloud.on_connectivity_changed_callbacks.register(
self._update_for_connectivity_change
)
)
# We want to be informed when primary account changes.
self._on_primary_account_changed_callback = (
plus.accounts.on_primary_account_changed_callbacks.register(
self.update_for_primary_account
self._update_for_primary_account
)
)
# Establish subscriptions/etc. for any current primary account.
self.update_for_primary_account(plus.accounts.primary)
self._update_for_primary_account(plus.accounts.primary)
self._have_connectivity = plus.cloud.is_connected()
self._update_for_connectivity_change(self._have_connectivity)

@override
def on_deactivate(self) -> None:
Expand All @@ -136,7 +150,7 @@ def on_deactivate(self) -> None:
self._on_primary_account_changed_callback = None

# Remove anything following any current account.
self.update_for_primary_account(None)
self._update_for_primary_account(None)

# Save where we were in the UI so we return there next time.
if classic is not None:
Expand All @@ -152,7 +166,7 @@ def on_app_active_changed(self) -> None:
if not babase.app.active:
babase.invoke_main_menu()

def update_for_primary_account(
def _update_for_primary_account(
self, account: babase.AccountV2Handle | None
) -> None:
"""Update subscriptions/etc. for a new primary account state."""
Expand Down Expand Up @@ -180,7 +194,7 @@ def update_for_primary_account(

if account is None:
self._account_data_sub = None
_baclassic.set_root_ui_values(
_baclassic.set_root_ui_account_values(
tickets_text='-',
tokens_text='-',
league_rank_text='-',
Expand All @@ -195,7 +209,6 @@ def update_for_primary_account(
chest_2_appearance='',
chest_3_appearance='',
)

else:
with account:
self._account_data_sub = (
Expand All @@ -204,6 +217,23 @@ def update_for_primary_account(
)
)

def _update_for_connectivity_change(self, connected: bool) -> None:
"""Update when the app's connectivity state changes."""
self._have_connectivity = connected
self._update_have_live_values()

def _update_have_live_values(self) -> None:

# We want to show ui elements faded out unless we have a live
# connection to the master-server AND have received a set of UI
# values from them. If we just plug in connectivity here we get
# UI stuff un-fading a moment or two before values appear (since
# the subscriptions have not sent us any values yet) which looks
# odd.
_baclassic.set_root_ui_have_live_values(
self._have_connectivity and self._have_account_values
)

def _on_sub_test_update(self, val: int | None) -> None:
print(f'GOT SUB TEST UPDATE: {val}')

Expand All @@ -221,7 +251,7 @@ def _on_classic_account_data_change(
chest2 = val.chests.get('2')
chest3 = val.chests.get('3')

_baclassic.set_root_ui_values(
_baclassic.set_root_ui_account_values(
tickets_text=str(val.tickets),
tokens_text=str(val.tokens),
league_rank_text=(
Expand Down Expand Up @@ -249,6 +279,10 @@ def _on_classic_account_data_change(
),
)

# Note that we have values and updated faded state accordingly.
self._have_account_values = True
self._update_have_live_values()

def _root_ui_menu_press(self) -> None:
from babase import push_back_press

Expand Down
2 changes: 1 addition & 1 deletion src/assets/ba_data/python/baenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

# Build number and version of the ballistica binary we expect to be
# using.
TARGET_BALLISTICA_BUILD = 22143
TARGET_BALLISTICA_BUILD = 22145
TARGET_BALLISTICA_VERSION = '1.7.37'


Expand Down
16 changes: 13 additions & 3 deletions src/assets/ba_data/python/baplus/_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
from typing import TYPE_CHECKING, overload

from efro.call import CallbackSet
import babase

if TYPE_CHECKING:
Expand All @@ -24,6 +25,12 @@
class CloudSubsystem(babase.AppSubsystem):
"""Manages communication with cloud components."""

def __init__(self) -> None:
super().__init__()
self.on_connectivity_changed_callbacks: CallbackSet[
Callable[[bool], None]
] = CallbackSet()

@property
def connected(self) -> bool:
"""Property equivalent of CloudSubsystem.is_connected()."""
Expand All @@ -44,9 +51,12 @@ def on_connectivity_changed(self, connected: bool) -> None:
plus = babase.app.plus
assert plus is not None

# Inform things that use this.
# (TODO: should generalize this into some sort of registration system)
plus.accounts.on_cloud_connectivity_changed(connected)
# Fire any registered callbacks for this.
for call in self.on_connectivity_changed_callbacks.getcalls():
try:
call(connected)
except Exception:
logging.exception('Error in connectivity-changed callback.')

@overload
def send_message_cb(
Expand Down
Loading

0 comments on commit da64da2

Please sign in to comment.