bascenev1lib.activity.coopjoin

Functionality related to the co-op join screen.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""Functionality related to the co-op join screen."""
  4
  5from __future__ import annotations
  6
  7from typing import override
  8
  9import bascenev1 as bs
 10
 11
 12class CoopJoinActivity(bs.JoinActivity):
 13    """Join-screen for co-op mode."""
 14
 15    # We can assume our session is a CoopSession.
 16    session: bs.CoopSession
 17
 18    def __init__(self, settings: dict):
 19        super().__init__(settings)
 20        session = self.session
 21        assert isinstance(session, bs.CoopSession)
 22
 23    @override
 24    def on_transition_in(self) -> None:
 25        from bascenev1lib.actor.controlsguide import ControlsGuide
 26        from bascenev1lib.actor.text import Text
 27
 28        super().on_transition_in()
 29        assert isinstance(self.session, bs.CoopSession)
 30        assert self.session.campaign
 31        Text(
 32            self.session.campaign.getlevel(
 33                self.session.campaign_level_name
 34            ).displayname,
 35            scale=1.3,
 36            h_attach=Text.HAttach.CENTER,
 37            h_align=Text.HAlign.CENTER,
 38            v_attach=Text.VAttach.TOP,
 39            transition=Text.Transition.FADE_IN,
 40            transition_delay=4.0,
 41            color=(1, 1, 1, 0.6),
 42            position=(0, -95),
 43        ).autoretain()
 44        ControlsGuide(delay=1.0).autoretain()
 45
 46        bs.pushcall(self._show_remaining_achievements)
 47
 48    def _show_remaining_achievements(self) -> None:
 49        from bascenev1lib.actor.text import Text
 50
 51        app = bs.app
 52        env = app.env
 53
 54        # We only show achievements and challenges for CoopGameActivities.
 55        session = self.session
 56        assert isinstance(session, bs.CoopSession)
 57        gameinstance = session.get_current_game_instance()
 58        if not isinstance(gameinstance, bs.CoopGameActivity):
 59            return
 60
 61        delay = 1.0
 62        vpos = -140.0
 63
 64        # Now list our remaining achievements for this level.
 65        assert self.session.campaign is not None
 66        assert isinstance(self.session, bs.CoopSession)
 67        levelname = (
 68            self.session.campaign.name + ':' + self.session.campaign_level_name
 69        )
 70        ts_h_offs = 60
 71
 72        # Show remaining achievements in some cases.
 73        if app.classic is not None and not (env.demo or env.arcade):
 74            achievements = [
 75                a
 76                for a in app.classic.ach.achievements_for_coop_level(levelname)
 77                if not a.complete
 78            ]
 79            have_achievements = bool(achievements)
 80            achievements = [a for a in achievements if not a.complete]
 81            vrmode = env.vr
 82            if have_achievements:
 83                Text(
 84                    bs.Lstr(resource='achievementsRemainingText'),
 85                    host_only=True,
 86                    position=(ts_h_offs - 10, vpos),
 87                    transition=Text.Transition.FADE_IN,
 88                    scale=1.1 * 0.76,
 89                    h_attach=Text.HAttach.LEFT,
 90                    v_attach=Text.VAttach.TOP,
 91                    color=(1, 1, 1.2, 1) if vrmode else (0.8, 0.8, 1, 1),
 92                    shadow=1.0,
 93                    flatness=1.0 if vrmode else 0.6,
 94                    transition_delay=delay,
 95                ).autoretain()
 96                hval = ts_h_offs + 50
 97                vpos -= 35
 98                for ach in achievements:
 99                    delay += 0.05
100                    ach.create_display(hval, vpos, delay, style='in_game')
101                    vpos -= 55
102                if not achievements:
103                    Text(
104                        bs.Lstr(resource='noAchievementsRemainingText'),
105                        host_only=True,
106                        position=(ts_h_offs + 15, vpos + 10),
107                        transition=Text.Transition.FADE_IN,
108                        scale=0.7,
109                        h_attach=Text.HAttach.LEFT,
110                        v_attach=Text.VAttach.TOP,
111                        color=(1, 1, 1, 0.5),
112                        transition_delay=delay + 0.5,
113                    ).autoretain()
class CoopJoinActivity(bascenev1._activity.Activity[bascenev1._player.EmptyPlayer, bascenev1._team.EmptyTeam]):
 13class CoopJoinActivity(bs.JoinActivity):
 14    """Join-screen for co-op mode."""
 15
 16    # We can assume our session is a CoopSession.
 17    session: bs.CoopSession
 18
 19    def __init__(self, settings: dict):
 20        super().__init__(settings)
 21        session = self.session
 22        assert isinstance(session, bs.CoopSession)
 23
 24    @override
 25    def on_transition_in(self) -> None:
 26        from bascenev1lib.actor.controlsguide import ControlsGuide
 27        from bascenev1lib.actor.text import Text
 28
 29        super().on_transition_in()
 30        assert isinstance(self.session, bs.CoopSession)
 31        assert self.session.campaign
 32        Text(
 33            self.session.campaign.getlevel(
 34                self.session.campaign_level_name
 35            ).displayname,
 36            scale=1.3,
 37            h_attach=Text.HAttach.CENTER,
 38            h_align=Text.HAlign.CENTER,
 39            v_attach=Text.VAttach.TOP,
 40            transition=Text.Transition.FADE_IN,
 41            transition_delay=4.0,
 42            color=(1, 1, 1, 0.6),
 43            position=(0, -95),
 44        ).autoretain()
 45        ControlsGuide(delay=1.0).autoretain()
 46
 47        bs.pushcall(self._show_remaining_achievements)
 48
 49    def _show_remaining_achievements(self) -> None:
 50        from bascenev1lib.actor.text import Text
 51
 52        app = bs.app
 53        env = app.env
 54
 55        # We only show achievements and challenges for CoopGameActivities.
 56        session = self.session
 57        assert isinstance(session, bs.CoopSession)
 58        gameinstance = session.get_current_game_instance()
 59        if not isinstance(gameinstance, bs.CoopGameActivity):
 60            return
 61
 62        delay = 1.0
 63        vpos = -140.0
 64
 65        # Now list our remaining achievements for this level.
 66        assert self.session.campaign is not None
 67        assert isinstance(self.session, bs.CoopSession)
 68        levelname = (
 69            self.session.campaign.name + ':' + self.session.campaign_level_name
 70        )
 71        ts_h_offs = 60
 72
 73        # Show remaining achievements in some cases.
 74        if app.classic is not None and not (env.demo or env.arcade):
 75            achievements = [
 76                a
 77                for a in app.classic.ach.achievements_for_coop_level(levelname)
 78                if not a.complete
 79            ]
 80            have_achievements = bool(achievements)
 81            achievements = [a for a in achievements if not a.complete]
 82            vrmode = env.vr
 83            if have_achievements:
 84                Text(
 85                    bs.Lstr(resource='achievementsRemainingText'),
 86                    host_only=True,
 87                    position=(ts_h_offs - 10, vpos),
 88                    transition=Text.Transition.FADE_IN,
 89                    scale=1.1 * 0.76,
 90                    h_attach=Text.HAttach.LEFT,
 91                    v_attach=Text.VAttach.TOP,
 92                    color=(1, 1, 1.2, 1) if vrmode else (0.8, 0.8, 1, 1),
 93                    shadow=1.0,
 94                    flatness=1.0 if vrmode else 0.6,
 95                    transition_delay=delay,
 96                ).autoretain()
 97                hval = ts_h_offs + 50
 98                vpos -= 35
 99                for ach in achievements:
100                    delay += 0.05
101                    ach.create_display(hval, vpos, delay, style='in_game')
102                    vpos -= 55
103                if not achievements:
104                    Text(
105                        bs.Lstr(resource='noAchievementsRemainingText'),
106                        host_only=True,
107                        position=(ts_h_offs + 15, vpos + 10),
108                        transition=Text.Transition.FADE_IN,
109                        scale=0.7,
110                        h_attach=Text.HAttach.LEFT,
111                        v_attach=Text.VAttach.TOP,
112                        color=(1, 1, 1, 0.5),
113                        transition_delay=delay + 0.5,
114                    ).autoretain()

Join-screen for co-op mode.

CoopJoinActivity(settings: dict)
19    def __init__(self, settings: dict):
20        super().__init__(settings)
21        session = self.session
22        assert isinstance(session, bs.CoopSession)

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.

session: bascenev1.Session
331    @property
332    def session(self) -> bascenev1.Session:
333        """The bascenev1.Session this bascenev1.Activity belongs to.
334
335        Raises a babase.SessionNotFoundError if the Session no longer exists.
336        """
337        session = self._session()
338        if session is None:
339            raise babase.SessionNotFoundError()
340        return session

The bascenev1.Session this bascenev1.Activity belongs to.

Raises a babase.SessionNotFoundError if the Session no longer exists.

@override
def on_transition_in(self) -> None:
24    @override
25    def on_transition_in(self) -> None:
26        from bascenev1lib.actor.controlsguide import ControlsGuide
27        from bascenev1lib.actor.text import Text
28
29        super().on_transition_in()
30        assert isinstance(self.session, bs.CoopSession)
31        assert self.session.campaign
32        Text(
33            self.session.campaign.getlevel(
34                self.session.campaign_level_name
35            ).displayname,
36            scale=1.3,
37            h_attach=Text.HAttach.CENTER,
38            h_align=Text.HAlign.CENTER,
39            v_attach=Text.VAttach.TOP,
40            transition=Text.Transition.FADE_IN,
41            transition_delay=4.0,
42            color=(1, 1, 1, 0.6),
43            position=(0, -95),
44        ).autoretain()
45        ControlsGuide(delay=1.0).autoretain()
46
47        bs.pushcall(self._show_remaining_achievements)

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.