bastd.activity.multiteamjoin

Functionality related to the join screen for multi-team sessions.

 1# Released under the MIT License. See LICENSE for details.
 2#
 3"""Functionality related to the join screen for multi-team sessions."""
 4
 5from __future__ import annotations
 6
 7from typing import TYPE_CHECKING
 8
 9import ba
10from ba.internal import JoinActivity
11from bastd.actor.text import Text
12
13if TYPE_CHECKING:
14    pass
15
16
17class MultiTeamJoinActivity(JoinActivity):
18    """Join screen for teams sessions."""
19
20    def __init__(self, settings: dict):
21        super().__init__(settings)
22        self._next_up_text: Text | None = None
23
24    def on_transition_in(self) -> None:
25        from bastd.actor.controlsguide import ControlsGuide
26        from ba import DualTeamSession
27        super().on_transition_in()
28        ControlsGuide(delay=1.0).autoretain()
29
30        session = self.session
31        assert isinstance(session, ba.MultiTeamSession)
32
33        # Show info about the next up game.
34        self._next_up_text = Text(ba.Lstr(
35            value='${1} ${2}',
36            subs=[('${1}', ba.Lstr(resource='upFirstText')),
37                  ('${2}', session.get_next_game_description())]),
38                                  h_attach=Text.HAttach.CENTER,
39                                  scale=0.7,
40                                  v_attach=Text.VAttach.TOP,
41                                  h_align=Text.HAlign.CENTER,
42                                  position=(0, -70),
43                                  flash=False,
44                                  color=(0.5, 0.5, 0.5, 1.0),
45                                  transition=Text.Transition.FADE_IN,
46                                  transition_delay=5.0)
47
48        # In teams mode, show our two team names.
49        # FIXME: Lobby should handle this.
50        if isinstance(ba.getsession(), DualTeamSession):
51            team_names = [team.name for team in ba.getsession().sessionteams]
52            team_colors = [
53                tuple(team.color) + (0.5, )
54                for team in ba.getsession().sessionteams
55            ]
56            if len(team_names) == 2:
57                for i in range(2):
58                    Text(team_names[i],
59                         scale=0.7,
60                         h_attach=Text.HAttach.CENTER,
61                         v_attach=Text.VAttach.TOP,
62                         h_align=Text.HAlign.CENTER,
63                         position=(-200 + 350 * i, -100),
64                         color=team_colors[i],
65                         transition=Text.Transition.FADE_IN).autoretain()
66
67        Text(ba.Lstr(resource='mustInviteFriendsText',
68                     subs=[('${GATHER}',
69                            ba.Lstr(resource='gatherWindow.titleText'))]),
70             h_attach=Text.HAttach.CENTER,
71             scale=0.8,
72             host_only=True,
73             v_attach=Text.VAttach.CENTER,
74             h_align=Text.HAlign.CENTER,
75             position=(0, 0),
76             flash=False,
77             color=(0, 1, 0, 1.0),
78             transition=Text.Transition.FADE_IN,
79             transition_delay=2.0,
80             transition_out_delay=7.0).autoretain()
class MultiTeamJoinActivity(ba._activity.Activity[ba._player.EmptyPlayer, ba._team.EmptyTeam]):
18class MultiTeamJoinActivity(JoinActivity):
19    """Join screen for teams sessions."""
20
21    def __init__(self, settings: dict):
22        super().__init__(settings)
23        self._next_up_text: Text | None = None
24
25    def on_transition_in(self) -> None:
26        from bastd.actor.controlsguide import ControlsGuide
27        from ba import DualTeamSession
28        super().on_transition_in()
29        ControlsGuide(delay=1.0).autoretain()
30
31        session = self.session
32        assert isinstance(session, ba.MultiTeamSession)
33
34        # Show info about the next up game.
35        self._next_up_text = Text(ba.Lstr(
36            value='${1} ${2}',
37            subs=[('${1}', ba.Lstr(resource='upFirstText')),
38                  ('${2}', session.get_next_game_description())]),
39                                  h_attach=Text.HAttach.CENTER,
40                                  scale=0.7,
41                                  v_attach=Text.VAttach.TOP,
42                                  h_align=Text.HAlign.CENTER,
43                                  position=(0, -70),
44                                  flash=False,
45                                  color=(0.5, 0.5, 0.5, 1.0),
46                                  transition=Text.Transition.FADE_IN,
47                                  transition_delay=5.0)
48
49        # In teams mode, show our two team names.
50        # FIXME: Lobby should handle this.
51        if isinstance(ba.getsession(), DualTeamSession):
52            team_names = [team.name for team in ba.getsession().sessionteams]
53            team_colors = [
54                tuple(team.color) + (0.5, )
55                for team in ba.getsession().sessionteams
56            ]
57            if len(team_names) == 2:
58                for i in range(2):
59                    Text(team_names[i],
60                         scale=0.7,
61                         h_attach=Text.HAttach.CENTER,
62                         v_attach=Text.VAttach.TOP,
63                         h_align=Text.HAlign.CENTER,
64                         position=(-200 + 350 * i, -100),
65                         color=team_colors[i],
66                         transition=Text.Transition.FADE_IN).autoretain()
67
68        Text(ba.Lstr(resource='mustInviteFriendsText',
69                     subs=[('${GATHER}',
70                            ba.Lstr(resource='gatherWindow.titleText'))]),
71             h_attach=Text.HAttach.CENTER,
72             scale=0.8,
73             host_only=True,
74             v_attach=Text.VAttach.CENTER,
75             h_align=Text.HAlign.CENTER,
76             position=(0, 0),
77             flash=False,
78             color=(0, 1, 0, 1.0),
79             transition=Text.Transition.FADE_IN,
80             transition_delay=2.0,
81             transition_out_delay=7.0).autoretain()

Join screen for teams sessions.

MultiTeamJoinActivity(settings: dict)
21    def __init__(self, settings: dict):
22        super().__init__(settings)
23        self._next_up_text: Text | None = None

Creates an Activity in the current ba.Session.

The activity will not be actually run until ba.Session.setactivity is called. 'settings' should be a dict of key/value pairs specific to the activity.

Activities should preload as much of their media/etc as possible in their constructor, but none of it should actually be used until they are transitioned in.

def on_transition_in(self) -> None:
25    def on_transition_in(self) -> None:
26        from bastd.actor.controlsguide import ControlsGuide
27        from ba import DualTeamSession
28        super().on_transition_in()
29        ControlsGuide(delay=1.0).autoretain()
30
31        session = self.session
32        assert isinstance(session, ba.MultiTeamSession)
33
34        # Show info about the next up game.
35        self._next_up_text = Text(ba.Lstr(
36            value='${1} ${2}',
37            subs=[('${1}', ba.Lstr(resource='upFirstText')),
38                  ('${2}', session.get_next_game_description())]),
39                                  h_attach=Text.HAttach.CENTER,
40                                  scale=0.7,
41                                  v_attach=Text.VAttach.TOP,
42                                  h_align=Text.HAlign.CENTER,
43                                  position=(0, -70),
44                                  flash=False,
45                                  color=(0.5, 0.5, 0.5, 1.0),
46                                  transition=Text.Transition.FADE_IN,
47                                  transition_delay=5.0)
48
49        # In teams mode, show our two team names.
50        # FIXME: Lobby should handle this.
51        if isinstance(ba.getsession(), DualTeamSession):
52            team_names = [team.name for team in ba.getsession().sessionteams]
53            team_colors = [
54                tuple(team.color) + (0.5, )
55                for team in ba.getsession().sessionteams
56            ]
57            if len(team_names) == 2:
58                for i in range(2):
59                    Text(team_names[i],
60                         scale=0.7,
61                         h_attach=Text.HAttach.CENTER,
62                         v_attach=Text.VAttach.TOP,
63                         h_align=Text.HAlign.CENTER,
64                         position=(-200 + 350 * i, -100),
65                         color=team_colors[i],
66                         transition=Text.Transition.FADE_IN).autoretain()
67
68        Text(ba.Lstr(resource='mustInviteFriendsText',
69                     subs=[('${GATHER}',
70                            ba.Lstr(resource='gatherWindow.titleText'))]),
71             h_attach=Text.HAttach.CENTER,
72             scale=0.8,
73             host_only=True,
74             v_attach=Text.VAttach.CENTER,
75             h_align=Text.HAlign.CENTER,
76             position=(0, 0),
77             flash=False,
78             color=(0, 1, 0, 1.0),
79             transition=Text.Transition.FADE_IN,
80             transition_delay=2.0,
81             transition_out_delay=7.0).autoretain()

Called when the Activity is first becoming visible.

Upon this call, the Activity should fade in backgrounds, start playing music, etc. It does not yet have access to players or teams, however. They remain owned by the previous Activity up until ba.Activity.on_begin() is called.

Inherited Members
ba._activity.Activity
is_joining_activity
allow_kick_idle_players
use_fixed_vr_overlay
settings_raw
teams
players
announce_player_deaths
allow_pausing
slow_motion
inherits_slow_motion
inherits_music
inherits_vr_camera_offset
inherits_vr_overlay_center
inherits_tint
allow_mid_activity_joins
transition_time
can_show_ad_on_death
globalsnode
stats
on_expire
customdata
expired
playertype
teamtype
retain_actor
add_actor_weak_ref
session
on_player_join
on_player_leave
on_team_join
on_team_leave
on_transition_out
on_begin
handlemessage
has_transitioned_in
has_begun
has_ended
is_transitioning_out
transition_out
end
create_player
create_team
ba._dependency.DependencyComponent
dep_is_present
get_dynamic_deps