Every end of a game the page decides on (recap opened, Challenge with the preference off, or a game left without its block) emits MatchEndShown, formerly RecapOpened: « Paramètres » gives way and the window is raised above the others without taking the focus, through tray::reveal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
165 lines
6.9 KiB
Rust
165 lines
6.9 KiB
Rust
//! The end of a Match opens its recap (#129): when its end-of-game block arrives, « Parties »
|
|
//! shows the new Match, from any screen; the window comes forward without taking the focus.
|
|
//! With the preference off, or when the game ended without a block, the Challenge shows instead.
|
|
//! The animation of the end of the Match plays on « Parties » then (#110). Each game's end is
|
|
//! decided once: nothing brings the player back to either screen afterwards.
|
|
//! During a Live Match, « En partie » stays until the block or the lobby (#109).
|
|
|
|
use crate::page::{ALL_SEASONS, MatchEndShown, Page, Tab};
|
|
use crate::worker::MatchEntry;
|
|
use arena_tracker_core::{FollowedMatch, GameEnd, SeasonScope};
|
|
use gpui_kit::component::IndexPath;
|
|
use gpui_kit::*;
|
|
|
|
impl Page {
|
|
/// The preference changed in « Paramètres ».
|
|
pub(crate) fn set_open_recap_at_match_end(&mut self, open: bool) {
|
|
self.open_recap_at_match_end = open;
|
|
}
|
|
|
|
#[cfg(test)]
|
|
pub(crate) fn opens_recap_at_match_end(&self) -> bool {
|
|
self.open_recap_at_match_end
|
|
}
|
|
|
|
/// A round reported `followed`, and `end` when the client left an Arena game. The most
|
|
/// recent Match of the active Account whose end-of-game block arrived is shown in
|
|
/// « Parties », once the list holds it; with the preference off it shows the Challenge. A game
|
|
/// that ended without one shows the Challenge, unless its block was already decided on. A
|
|
/// Match found later on Riot's side (no block) changes nothing. Nothing during a champ
|
|
/// select, which the phase rule keeps in front.
|
|
pub(in crate::page) fn follow_match_end(
|
|
&mut self,
|
|
followed: &[FollowedMatch],
|
|
end: Option<GameEnd>,
|
|
window: &mut Window,
|
|
cx: &mut Context<Self>,
|
|
) {
|
|
if self.in_champ_select() {
|
|
return;
|
|
}
|
|
let puuid = self.active_account().map(|a| a.puuid.clone());
|
|
let arrived = (followed.iter())
|
|
.filter(|m| m.provisional && Some(&m.puuid) == puuid.as_ref())
|
|
.max_by_key(|m| m.started_at_ms);
|
|
if let Some(arrived) = arrived {
|
|
let decided = self.decided_game.is_some() && self.decided_game == arrived.game_id;
|
|
self.decided_game = arrived.game_id;
|
|
if self.open_recap_at_match_end {
|
|
// A block that comes after its game was decided on still opens its recap.
|
|
self.open_arrived_recap(arrived, window, cx);
|
|
} else if !decided {
|
|
// The end decides, as a phase does: the active Account's Challenge shows.
|
|
if self.pinned.is_some() {
|
|
self.show_account(None, window, cx);
|
|
}
|
|
self.set_tab(Tab::Challenge, window, cx);
|
|
cx.emit(MatchEndShown);
|
|
}
|
|
return;
|
|
}
|
|
let Some(end) = end else {
|
|
return;
|
|
};
|
|
// « En partie » stays on the game's end-of-game screen: the block, or the lobby
|
|
// without one, decides then (#109).
|
|
if self.in_live_match() {
|
|
return;
|
|
}
|
|
self.game_ended_without_block(end.game_id, window, cx);
|
|
}
|
|
|
|
/// The game `game` ended without its block: « Défi » shows, once per game, from wherever
|
|
/// the player is.
|
|
pub(in crate::page) fn game_ended_without_block(
|
|
&mut self,
|
|
game: Option<u64>,
|
|
window: &mut Window,
|
|
cx: &mut Context<Self>,
|
|
) {
|
|
if game.is_none() || game != self.decided_game {
|
|
self.decided_game = game;
|
|
if self.pinned.is_some() {
|
|
self.show_account(None, window, cx);
|
|
}
|
|
self.set_tab(Tab::Challenge, window, cx);
|
|
cx.emit(MatchEndShown);
|
|
}
|
|
}
|
|
|
|
/// Shows « Parties » with the Match `ended` chosen once the list holds it.
|
|
fn open_arrived_recap(
|
|
&mut self,
|
|
ended: &FollowedMatch,
|
|
window: &mut Window,
|
|
cx: &mut Context<Self>,
|
|
) {
|
|
// The active Account's Match shows the active Account, before the list is chosen again.
|
|
if self.pinned.is_some() {
|
|
self.show_account(None, window, cx);
|
|
}
|
|
let matches = &mut self.matches;
|
|
matches.arriving = Some(ended.match_id.clone());
|
|
// The list may not hold it yet: read again.
|
|
matches.stale = true;
|
|
// Neither the Placement nor the search of an earlier visit hides it.
|
|
matches.filters.clear(window, cx);
|
|
let hidden = match &self.season {
|
|
SeasonScope::AllSeasons => false,
|
|
SeasonScope::Season(name) => Some(name) != ended.season.as_ref(),
|
|
} || self.format.is_some_and(|format| format != ended.format);
|
|
if hidden {
|
|
self.show_every_format_of_the_season(ended.season.clone(), window, cx);
|
|
}
|
|
// The animation of the end of a Match waiting plays on this screen, not on « Défi » (#110).
|
|
self.playback.on_matches = self.playback.waiting.waiting().is_some();
|
|
let drawn = self.shown_tab == Tab::Matches;
|
|
// Hidden, minimised or behind « Paramètres », the switch is at once, without the veil.
|
|
self.set_tab(Tab::Matches, window, cx);
|
|
if drawn {
|
|
// Already drawn, the screen does not open again by itself: an earlier recap goes.
|
|
self.open_matches(cx);
|
|
}
|
|
cx.emit(MatchEndShown);
|
|
}
|
|
|
|
/// The Season and Format of « Statistiques » hide the Match that just ended: to its Season
|
|
/// (all of them when none holds it) and every Format, so the new Match is the one shown.
|
|
/// The selectors are shared with « Statistiques », whose statistics follow on a worker
|
|
/// (#129).
|
|
fn show_every_format_of_the_season(
|
|
&mut self,
|
|
season: Option<String>,
|
|
window: &mut Window,
|
|
cx: &mut Context<Self>,
|
|
) {
|
|
let (scope, name) = match season {
|
|
Some(name) => (SeasonScope::Season(name.clone()), SharedString::from(name)),
|
|
None => (SeasonScope::AllSeasons, SharedString::from(ALL_SEASONS)),
|
|
};
|
|
self.season = scope;
|
|
self.format = None;
|
|
self.season_select.update(cx, |select, cx| {
|
|
select.set_selected_value(&name, window, cx)
|
|
});
|
|
self.format_select.update(cx, |select, cx| {
|
|
select.set_selected_index(Some(IndexPath::new(0)), window, cx)
|
|
});
|
|
// A statistics job already running is for the scope left.
|
|
self.stats_generation += 1;
|
|
let start_job = self.stats_job.request();
|
|
self.recompute_in_background(start_job, window, cx);
|
|
}
|
|
}
|
|
|
|
/// A list read after the Match ended that does not hold it never will (another Account's, or
|
|
/// already gone): the screen chooses as when opened by hand.
|
|
pub(super) fn forget_unlisted(arriving: &mut Option<String>, entries: &[MatchEntry]) {
|
|
if arriving
|
|
.as_ref()
|
|
.is_some_and(|id| !entries.iter().any(|entry| entry.match_id == *id))
|
|
{
|
|
*arriving = None;
|
|
}
|
|
}
|