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

Creates an Activity in the current bascenev1.Session.

The activity will not be actually run until bascenev1.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.

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