use super::{ChampSelectTransition, Page, Tab}; use crate::worker::LiveChampSelect; use arena_tracker_core::{account_riot_id, same_riot_id}; use gpui_kit::*; pub(in crate::page) const UNKNOWN_ANVIL: &str = "Champions de l'Enclume non communiqués par le client"; mod cards; mod motion; mod render; impl Page { /// The Account of the live champ select. Resolved when the signed-in Riot ID changes (or the /// Accounts do), so preparing statistics builds no Riot ID per Account every time. pub(in crate::page) fn champ_select_account(&mut self) -> Option { let id = self.champ_select.as_ref().map(|(id, _)| id.as_str())?; if self.champ_select_riot_id.as_deref() != Some(id) { self.champ_select_riot_id = Some(id.into()); self.champ_select_account = self .accounts .iter() .find(|a| same_riot_id(&account_riot_id(a), id)) .map(|a| a.puuid.clone()); } self.champ_select_account.clone() } /// The champ select the client reports changed: entered, left, another one, or the same /// one with new picks and bans. pub(in crate::page) fn change_champ_select( &mut self, champ_select: LiveChampSelect, window: &mut Window, cx: &mut Context, ) { let previous = self.champ_select.as_ref(); let next = champ_select.as_ref(); let changed_page = previous.is_some() != next.is_some(); let switch = changed_page || previous.map(|(id, _)| id) != next.map(|(id, _)| id); self.champ_select = champ_select; if changed_page { if self.in_champ_select() { // The champ select is about the Challenge, whatever tab was open. self.tab = Tab::Challenge; // Nothing plays during a champ select: what waited is no longer news. self.stop_holding(); self.end_match(cx); self.end_fade(window, cx); // The home grid gives way to the champ select's sections. self.home_grid .update(cx, |grid, cx| grid.release_images(window, cx)); // Its entry plays once the window shows it (#63 reveals it without focus). self.entry_waiting = true; } else { self.forget_stage(); self.reset_home_view(window, cx); self.anvil_grid .update(cx, |grid, cx| grid.release_images(window, cx)); // An animation asked for during the champ select plays on the home. self.playback.stats_pending = self.playback.active(); } } if switch { // The Account belongs to the signed-in Riot ID: resolve it once, not on every // statistics preparation. self.champ_select_riot_id = None; self.stats_generation += 1; self.stats = None; self.stats_error = None; self.forget_home(); self.stored = None; self.reorder(); // A new champ select starts with « Autres champions » folded and searchless, at the // top of the page. self.fold_others(window, cx); self.paging.scroll.set_offset(point(px(0.), px(0.))); self.reload_in_background(window, cx); // Nor does the banner keep the previous scope's Challenge while the new one // loads: its Season, its ticks and its splash go with the statistics. self.prepare_banner(cx); } if changed_page { cx.emit(ChampSelectTransition { entered: self.in_champ_select(), }); } // The hand as it was, to see which card an ally just took. let before = (!switch).then(|| self.anvil_grid.read(cx).cards().clone()); // Any change (a hover or a lock-in too) changes the reasons of the cards. Only // the client's events get here: no polling. self.prepare_champ_select(cx); if let Some(before) = before { self.lower_taken(&before, window, cx); } self.start_entry(window, cx); } }