def _show_winner(self, team: ba.SessionTeam) -> None: from bastd.actor.image import Image from bastd.actor.zoomtext import ZoomText if not self._is_ffa: offs_v = 0.0 ZoomText(team.name, position=(0, 97), color=team.color, scale=1.15, jitter=1.0, maxwidth=250).autoretain() else: offs_v = -80.0 if len(team.players) == 1: i = Image(team.players[0].get_icon(), position=(0, 143), scale=(100, 100)).autoretain() assert i.node ba.animate(i.node, 'opacity', {0.0: 0.0, 0.25: 1.0}) ZoomText(ba.Lstr( value=team.players[0].getname(full=True, icon=False)), position=(0, 97 + offs_v), color=team.color, scale=1.15, jitter=1.0, maxwidth=250).autoretain() s_extra = 1.0 if self._is_ffa else 1.0 # Some languages say "FOO WINS" differently for teams vs players. if isinstance(self.session, ba.FreeForAllSession): wins_resource = 'seriesWinLine1PlayerText' else: wins_resource = 'seriesWinLine1TeamText' wins_text = ba.Lstr(resource=wins_resource) # Temp - if these come up as the english default, fall-back to the # unified old form which is more likely to be translated. ZoomText(wins_text, position=(0, -10 + offs_v), color=team.color, scale=0.65 * s_extra, jitter=1.0, maxwidth=250).autoretain() ZoomText(ba.Lstr(resource='seriesWinLine2Text'), position=(0, -110 + offs_v), scale=1.0 * s_extra, color=team.color, jitter=1.0, maxwidth=250).autoretain()
def show_zoom_message(self, message: ba.Lstr, color: Sequence[float] = (0.9, 0.4, 0.0), scale: float = 0.8, duration: float = 2.0, trail: bool = False) -> None: """Zooming text used to announce game names and winners.""" # pylint: disable=cyclic-import from bastd.actor.zoomtext import ZoomText # Reserve a spot on the screen (in case we get multiple of these so # they don't overlap). i = 0 cur_time = _ba.time() while True: if (i not in self._zoom_message_times or self._zoom_message_times[i] < cur_time): self._zoom_message_times[i] = cur_time + duration break i += 1 ZoomText(message, lifespan=duration, jitter=2.0, position=(0, 200 - i * 100), scale=scale, maxwidth=800, trail=trail, color=color).autoretain()
def on_begin(self) -> None: from ba.deprecated import get_resource ba.set_analytics_screen('Teams Score Screen') super().on_begin() height = 130 active_team_count = len(self.teams) vval = (height * active_team_count) / 2 - height / 2 i = 0 shift_time = 2.5 # Usually we say 'Best of 7', but if the language prefers we can say # 'First to 4'. session = self.session assert isinstance(session, ba.TeamBaseSession) if get_resource('bestOfUseFirstToInstead'): best_txt = ba.Lstr(resource='firstToSeriesText', subs=[('${COUNT}', str(session.get_series_length() / 2 + 1)) ]) else: best_txt = ba.Lstr(resource='bestOfSeriesText', subs=[('${COUNT}', str(session.get_series_length()))]) ZoomText(best_txt, position=(0, 175), shiftposition=(-250, 175), shiftdelay=2.5, flash=False, trail=False, h_align='center', scale=0.25, color=(0.5, 0.5, 0.5, 1.0), jitter=3.0).autoretain() for team in self.teams: ba.timer( i * 0.15 + 0.15, ba.WeakCall(self._show_team_name, vval - i * height, team, i * 0.2, shift_time - (i * 0.150 + 0.150))) ba.timer(i * 0.150 + 0.5, ba.Call(ba.playsound, self._score_display_sound_small)) scored = (team is self.settings['winner']) delay = 0.2 if scored: delay = 1.2 ba.timer( i * 0.150 + 0.2, ba.WeakCall(self._show_team_old_score, vval - i * height, team, shift_time - (i * 0.15 + 0.2))) ba.timer(i * 0.15 + 1.5, ba.Call(ba.playsound, self._score_display_sound)) ba.timer( i * 0.150 + delay, ba.WeakCall(self._show_team_score, vval - i * height, team, scored, i * 0.2 + 0.1, shift_time - (i * 0.15 + delay))) i += 1 self.show_player_scores()
def _show_team_old_score(self, pos_v: float, team: ba.Team, shiftdelay: float) -> None: ZoomText(str(team.sessiondata['score'] - 1), position=(150, pos_v), maxwidth=100, color=(0.6, 0.6, 0.7), shiftposition=(-100, pos_v), shiftdelay=shiftdelay, flash=False, trail=False, lifespan=1.0, h_align='left', jitter=1.0).autoretain()
def _show_team_name(self, pos_v: float, team: ba.Team, kill_delay: float, shiftdelay: float) -> None: del kill_delay # unused arg ZoomText(ba.Lstr(value='${A}:', subs=[('${A}', team.name)]), position=(100, pos_v), shiftposition=(-150, pos_v), shiftdelay=shiftdelay, flash=False, trail=False, h_align='right', maxwidth=300, color=team.color, jitter=1.0).autoretain()
def on_begin(self) -> None: ba.set_analytics_screen('Draw Score Screen') super().on_begin() ZoomText(ba.Lstr(resource='drawText'), position=(0, 0), maxwidth=400, shiftposition=(-220, 0), shiftdelay=2.0, flash=False, trail=False, jitter=1.0).autoretain() ba.timer(0.35, ba.Call(ba.playsound, self._score_display_sound)) self.show_player_scores(results=self.settings_raw.get('results', None))
def _show_team_score(self, pos_v: float, team: ba.Team, scored: bool, kill_delay: float, shiftdelay: float) -> None: del kill_delay # unused arg ZoomText(str(team.sessiondata['score']), position=(150, pos_v), maxwidth=100, color=(1.0, 0.9, 0.5) if scored else (0.6, 0.6, 0.7), shiftposition=(-100, pos_v), shiftdelay=shiftdelay, flash=scored, trail=scored, h_align='left', jitter=1.0, trailcolor=(1, 0.8, 0.0, 0)).autoretain()
def _show_team_old_score(self, pos_v: float, sessionteam: ba.SessionTeam, shiftdelay: float) -> None: ZoomText(str(sessionteam.customdata['score'] - 1), position=(-250, 190) if pos_v == 65 else (250, 190), maxwidth=100, color=(0.6, 0.6, 0.7), shiftposition=(-250, 190) if pos_v == 65 else (250, 190), shiftdelay=shiftdelay, flash=False, trail=False, lifespan=1.0, scale=0.56, h_align='center', jitter=1.0).autoretain()
def _show_team_name(self, pos_v: float, team: ba.SessionTeam, kill_delay: float, shiftdelay: float) -> None: del kill_delay # Unused arg. ZoomText(ba.Lstr(value='${A}', subs=[('${A}', team.name)]), position=(-250, 260) if pos_v == 65 else (250, 260), shiftposition=(-250, 260) if pos_v == 65 else (250, 260), shiftdelay=shiftdelay, flash=False, trail=False, h_align='center', maxwidth=300, scale=0.45, color=team.color, jitter=1.0).autoretain()
def _show_team_score(self, pos_v: float, sessionteam: ba.SessionTeam, scored: bool, kill_delay: float, shiftdelay: float) -> None: del kill_delay # Unused arg. ZoomText(str(sessionteam.customdata['score']), position=(-250, 190) if pos_v == 65 else (250, 190), maxwidth=100, color=(1.0, 0.9, 0.5) if scored else (0.6, 0.6, 0.7), shiftposition=(-250, 190) if pos_v == 65 else (250, 190), shiftdelay=shiftdelay, flash=scored, trail=scored, scale=0.56, h_align='center', jitter=1.0, trailcolor=(1, 0.8, 0.0, 0)).autoretain()
def _show_info(self) -> None: """Show the game description.""" from ba._gameutils import animate from bastd.actor.zoomtext import ZoomText name = self.get_instance_display_string() ZoomText(name, maxwidth=800, lifespan=2.5, jitter=2.0, position=(0, 180), flash=False, color=(0.93 * 1.25, 0.9 * 1.25, 1.0 * 1.25), trailcolor=(0.15, 0.05, 1.0, 0.0)).autoretain() _ba.timer(0.2, Call(_ba.playsound, _ba.getsound('gong'))) # The description can be either a string or a sequence with args # to swap in post-translation. desc_in = self.get_instance_description() desc_l: Sequence if isinstance(desc_in, str): desc_l = [desc_in] # handle simple string case else: desc_l = desc_in if not isinstance(desc_l[0], str): raise TypeError('Invalid format for instance description') subs = [] for i in range(len(desc_l) - 1): subs.append(('${ARG' + str(i + 1) + '}', str(desc_l[i + 1]))) translation = Lstr(translate=('gameDescriptions', desc_l[0]), subs=subs) # Do some standard filters (epic mode, etc). if self.settings_raw.get('Epic Mode', False): translation = Lstr(resource='epicDescriptionFilterText', subs=[('${DESCRIPTION}', translation)]) vrmode = _ba.app.vr_mode dnode = _ba.newnode('text', attrs={ 'v_attach': 'center', 'h_attach': 'center', 'h_align': 'center', 'color': (1, 1, 1, 1), 'shadow': 1.0 if vrmode else 0.5, 'flatness': 1.0 if vrmode else 0.5, 'vr_depth': -30, 'position': (0, 80), 'scale': 1.2, 'maxwidth': 700, 'text': translation }) cnode = _ba.newnode('combine', owner=dnode, attrs={ 'input0': 1.0, 'input1': 1.0, 'input2': 1.0, 'size': 4 }) cnode.connectattr('output', dnode, 'color') keys = {0.5: 0, 1.0: 1.0, 2.5: 1.0, 4.0: 0.0} animate(cnode, 'input3', keys) _ba.timer(4.0, dnode.delete)