bastd.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 TYPE_CHECKING
  8
  9import ba
 10from ba.internal import JoinActivity
 11
 12if TYPE_CHECKING:
 13    pass
 14
 15
 16class CoopJoinActivity(JoinActivity):
 17    """Join-screen for co-op mode."""
 18
 19    # We can assume our session is a CoopSession.
 20    session: ba.CoopSession
 21
 22    def __init__(self, settings: dict):
 23        super().__init__(settings)
 24        session = self.session
 25        assert isinstance(session, ba.CoopSession)
 26
 27    def on_transition_in(self) -> None:
 28        from bastd.actor.controlsguide import ControlsGuide
 29        from bastd.actor.text import Text
 30
 31        super().on_transition_in()
 32        assert isinstance(self.session, ba.CoopSession)
 33        assert self.session.campaign
 34        Text(
 35            self.session.campaign.getlevel(
 36                self.session.campaign_level_name
 37            ).displayname,
 38            scale=1.3,
 39            h_attach=Text.HAttach.CENTER,
 40            h_align=Text.HAlign.CENTER,
 41            v_attach=Text.VAttach.TOP,
 42            transition=Text.Transition.FADE_IN,
 43            transition_delay=4.0,
 44            color=(1, 1, 1, 0.6),
 45            position=(0, -95),
 46        ).autoretain()
 47        ControlsGuide(delay=1.0).autoretain()
 48
 49        ba.pushcall(self._show_remaining_achievements)
 50
 51    def _show_remaining_achievements(self) -> None:
 52        from bastd.actor.text import Text
 53
 54        # We only show achievements and challenges for CoopGameActivities.
 55        session = self.session
 56        assert isinstance(session, ba.CoopSession)
 57        gameinstance = session.get_current_game_instance()
 58        if not isinstance(gameinstance, ba.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, ba.CoopSession)
 67        levelname = (
 68            self.session.campaign.name + ':' + self.session.campaign_level_name
 69        )
 70        ts_h_offs = 60
 71
 72        if not (ba.app.demo_mode or ba.app.arcade_mode):
 73            achievements = [
 74                a
 75                for a in ba.app.ach.achievements_for_coop_level(levelname)
 76                if not a.complete
 77            ]
 78            have_achievements = bool(achievements)
 79            achievements = [a for a in achievements if not a.complete]
 80            vrmode = ba.app.vr_mode
 81            if have_achievements:
 82                Text(
 83                    ba.Lstr(resource='achievementsRemainingText'),
 84                    host_only=True,
 85                    position=(ts_h_offs - 10, vpos),
 86                    transition=Text.Transition.FADE_IN,
 87                    scale=1.1 * 0.76,
 88                    h_attach=Text.HAttach.LEFT,
 89                    v_attach=Text.VAttach.TOP,
 90                    color=(1, 1, 1.2, 1) if vrmode else (0.8, 0.8, 1, 1),
 91                    shadow=1.0,
 92                    flatness=1.0 if vrmode else 0.6,
 93                    transition_delay=delay,
 94                ).autoretain()
 95                hval = ts_h_offs + 50
 96                vpos -= 35
 97                for ach in achievements:
 98                    delay += 0.05
 99                    ach.create_display(hval, vpos, delay, style='in_game')
100                    vpos -= 55
101                if not achievements:
102                    Text(
103                        ba.Lstr(resource='noAchievementsRemainingText'),
104                        host_only=True,
105                        position=(ts_h_offs + 15, vpos + 10),
106                        transition=Text.Transition.FADE_IN,
107                        scale=0.7,
108                        h_attach=Text.HAttach.LEFT,
109                        v_attach=Text.VAttach.TOP,
110                        color=(1, 1, 1, 0.5),
111                        transition_delay=delay + 0.5,
112                    ).autoretain()
class CoopJoinActivity(ba._activity.Activity[ba._player.EmptyPlayer, ba._team.EmptyTeam]):
 17class CoopJoinActivity(JoinActivity):
 18    """Join-screen for co-op mode."""
 19
 20    # We can assume our session is a CoopSession.
 21    session: ba.CoopSession
 22
 23    def __init__(self, settings: dict):
 24        super().__init__(settings)
 25        session = self.session
 26        assert isinstance(session, ba.CoopSession)
 27
 28    def on_transition_in(self) -> None:
 29        from bastd.actor.controlsguide import ControlsGuide
 30        from bastd.actor.text import Text
 31
 32        super().on_transition_in()
 33        assert isinstance(self.session, ba.CoopSession)
 34        assert self.session.campaign
 35        Text(
 36            self.session.campaign.getlevel(
 37                self.session.campaign_level_name
 38            ).displayname,
 39            scale=1.3,
 40            h_attach=Text.HAttach.CENTER,
 41            h_align=Text.HAlign.CENTER,
 42            v_attach=Text.VAttach.TOP,
 43            transition=Text.Transition.FADE_IN,
 44            transition_delay=4.0,
 45            color=(1, 1, 1, 0.6),
 46            position=(0, -95),
 47        ).autoretain()
 48        ControlsGuide(delay=1.0).autoretain()
 49
 50        ba.pushcall(self._show_remaining_achievements)
 51
 52    def _show_remaining_achievements(self) -> None:
 53        from bastd.actor.text import Text
 54
 55        # We only show achievements and challenges for CoopGameActivities.
 56        session = self.session
 57        assert isinstance(session, ba.CoopSession)
 58        gameinstance = session.get_current_game_instance()
 59        if not isinstance(gameinstance, ba.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, ba.CoopSession)
 68        levelname = (
 69            self.session.campaign.name + ':' + self.session.campaign_level_name
 70        )
 71        ts_h_offs = 60
 72
 73        if not (ba.app.demo_mode or ba.app.arcade_mode):
 74            achievements = [
 75                a
 76                for a in ba.app.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 = ba.app.vr_mode
 82            if have_achievements:
 83                Text(
 84                    ba.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                        ba.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()

Join-screen for co-op mode.

CoopJoinActivity(settings: dict)
23    def __init__(self, settings: dict):
24        super().__init__(settings)
25        session = self.session
26        assert isinstance(session, ba.CoopSession)

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.

session: ba._session.Session

The ba.Session this ba.Activity belongs go.

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

def on_transition_in(self) -> None:
28    def on_transition_in(self) -> None:
29        from bastd.actor.controlsguide import ControlsGuide
30        from bastd.actor.text import Text
31
32        super().on_transition_in()
33        assert isinstance(self.session, ba.CoopSession)
34        assert self.session.campaign
35        Text(
36            self.session.campaign.getlevel(
37                self.session.campaign_level_name
38            ).displayname,
39            scale=1.3,
40            h_attach=Text.HAttach.CENTER,
41            h_align=Text.HAlign.CENTER,
42            v_attach=Text.VAttach.TOP,
43            transition=Text.Transition.FADE_IN,
44            transition_delay=4.0,
45            color=(1, 1, 1, 0.6),
46            position=(0, -95),
47        ).autoretain()
48        ControlsGuide(delay=1.0).autoretain()
49
50        ba.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 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
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