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