From c9d53055d964207ef2670e86dc08daa8833f78b4 Mon Sep 17 00:00:00 2001 From: Nessar Date: Wed, 25 Nov 2026 19:06:19 +0100 Subject: [PATCH] Light the ring's tick under the pointer and present its champion (#112) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Hovering the crown aims at the nearest tick by angle (`ring/aim.rs`, a band a little wider than the ticks); the tick lights and the banner fades to that champion's splash. - The banner's first line becomes the champion's (validé le … · N Tentatives / N Parties · meilleur Placement / jamais joué); the second is hidden but keeps its height. - The hover is a layer over `dress_banner`'s rest state (`page/ring_hover.rs`): leaving the crown clears it. Listeners sit on a non-cached slot around the ring; nothing happens until the aimed tick changes, and it is ignored while the end of a Match plays. - Page tests for the aim, the three lines, rest on « Défi » and « En partie », no new render without a change of tick, the two-splash sweep and the no-fade setting; docs updated. Co-Authored-By: Claude Sonnet 5.5 --- crates/app/src/page.rs | 3 + crates/app/src/page/home/banner.rs | 46 ++-- crates/app/src/page/home/content.rs | 2 +- crates/app/src/page/hover.rs | 6 +- crates/app/src/page/playback.rs | 2 + crates/app/src/page/ring_hover.rs | 139 +++++++++++ crates/app/src/page/setup.rs | 1 + crates/app/src/page/tests.rs | 1 + crates/app/src/page/tests/ring_hover.rs | 298 ++++++++++++++++++++++++ crates/app/src/ring.rs | 10 +- crates/app/src/ring/aim.rs | 32 +++ crates/app/src/ring/tests.rs | 53 ++++- docs/guide-utilisation.md | 2 +- docs/interface.md | 2 +- 14 files changed, 569 insertions(+), 28 deletions(-) create mode 100644 crates/app/src/page/ring_hover.rs create mode 100644 crates/app/src/page/tests/ring_hover.rs create mode 100644 crates/app/src/ring/aim.rs diff --git a/crates/app/src/page.rs b/crates/app/src/page.rs index e07ab94..4ba0da3 100644 --- a/crates/app/src/page.rs +++ b/crates/app/src/page.rs @@ -40,6 +40,7 @@ mod matches; mod navigation; mod playback; mod profiling; +mod ring_hover; mod scrollbar; mod setup; mod statistics; @@ -304,6 +305,8 @@ pub struct Page { ring: Entity, /// The grid whose card lit the ring's tick. lit_by: Option, + /// The champion the pointer aims at on the ring. + ring_hover: ring_hover::RingHover, /// The banner's illustration, its own: given back while the banner is not shown. banner_art: Entity, /// The home's own filter and search: never persisted, « Tous » at each launch. diff --git a/crates/app/src/page/home/banner.rs b/crates/app/src/page/home/banner.rs index eceacad..b3c53e6 100644 --- a/crates/app/src/page/home/banner.rs +++ b/crates/app/src/page/home/banner.rs @@ -34,6 +34,7 @@ impl Page { .and(landed) .filter(|t| (0. ..COUNTER_ROLL).contains(t)) .map(|t| t / COUNTER_ROLL); + let aimed = self.ring_hover.aimed.as_ref(); let theme = cx.theme(); let (band, muted, foreground, ink) = ( banner_band(theme), @@ -131,9 +132,17 @@ impl Page { .child(title) .children(rolling) }) - .child(div().text_sm().text_color(muted).child(name(&text.detail))) + // The champion aimed at on the ring takes the first line's place, and the + // second one is only hidden, so that nothing moves. + .child( + div() + .text_sm() + .text_color(muted) + .child(name(aimed.map_or(&text.detail, |aimed| &aimed.line))), + ) .children(text.last_match.as_ref().map(|line| { div() + .when(aimed.is_some(), |line| line.invisible()) // The new line fades in once the comet lands; the old one stays. .opacity( (landed.filter(|t| *t >= 0.)) @@ -166,21 +175,8 @@ impl Page { .py(px(24.)) .debug_selector(|| "banner".into()) .child(self.banner_art.clone()) - .child( - // Cached: only a change of its ticks or of the lit one draws it again. - div() - .relative() - .size(px(layout.ring)) - .flex_none() - .child( - self.ring - .clone() - .cached(StyleRefinement::default().size_full()), - ) - .children( - animation.map(|a| self.ring.read(cx).match_layer(a, a.elapsed(now), cx)), - ), - ) + // Cached: only a change of its ticks or of the lit one draws the ring again. + .child(self.ring_slot(layout.ring, now, cx)) .child(copy) } } @@ -413,6 +409,7 @@ impl Page { self.banner = BannerContent::new(self.home_season.as_ref(), stats); self.name_other_account(); self.champ_select_splashes = splashes; + self.reaim(); self.ring.update(cx, |ring, cx| ring.set_ticks(ticks, cx)); if self.shown_tab == Tab::InGame { // « En partie » reads the same statistics, prepared only while shown (rule #1). @@ -443,7 +440,10 @@ impl Page { self.ring.update(cx, |ring, cx| ring.set_anvil(anvil, cx)); let playing = self.shown_tab == Tab::InGame; // Elsewhere only a card under the pointer lights a tick. - let lit = if playing { + let aimed = (self.ring_hover.aimed.as_ref()).map(|aimed| (aimed.id, aimed.splash.clone())); + let lit = if let Some((id, _)) = &aimed { + Some(Some(*id)) + } else if playing { Some(self.in_game.champion) } else { self.lit_by.is_none().then_some(None) @@ -451,7 +451,10 @@ impl Page { if let Some(lit) = lit { self.ring.update(cx, |ring, cx| ring.set_lit(lit, cx)); } - if selecting { + if let Some((_, splash)) = aimed { + self.banner_art + .update(cx, |art, cx| art.set_target(splash, cx)); + } else if selecting { self.select_art(self.ring.read(cx).lit(), cx); } else if playing { let splash = self.in_game.banner.splash.clone(); @@ -465,9 +468,10 @@ impl Page { /// The illustration of the champ select's banner: the card hovered's, else its own. pub(in crate::page) fn select_art(&self, hovered: Option, cx: &mut Context) { - let splash = match hovered { - Some(id) => self.champ_select_splashes.get(&id), - None => self.champ_select_banner.splash.as_ref(), + let splash = match (&self.ring_hover.aimed, hovered) { + (Some(aimed), _) => aimed.splash.as_ref(), + (None, Some(id)) => self.champ_select_splashes.get(&id), + (None, None) => self.champ_select_banner.splash.as_ref(), }; self.banner_art .update(cx, |art, cx| art.set_target(splash.cloned(), cx)); diff --git a/crates/app/src/page/home/content.rs b/crates/app/src/page/home/content.rs index 90480f1..cfaed27 100644 --- a/crates/app/src/page/home/content.rs +++ b/crates/app/src/page/home/content.rs @@ -16,7 +16,7 @@ pub(in crate::page) struct Line { impl Line { /// `before`, then `bold`, then `after`. - fn new(before: &str, bold: &str, after: &str) -> Line { + pub(in crate::page) fn new(before: &str, bold: &str, after: &str) -> Line { Line { text: format!("{before}{bold}{after}").into(), bold: before.len()..before.len() + bold.len(), diff --git a/crates/app/src/page/hover.rs b/crates/app/src/page/hover.rs index 84592f1..f86aca7 100644 --- a/crates/app/src/page/hover.rs +++ b/crates/app/src/page/hover.rs @@ -149,7 +149,11 @@ impl Page { if id.is_none() && grid == self.home_grid.entity_id() { self.release_home(cx); } - self.ring.update(cx, |ring, cx| ring.set_lit(id, cx)); + // The pointer cannot be on a card and on the ring, but one's leaving may come after the + // other's entering. + let aimed = self.ring_hover.aimed.as_ref().map(|aimed| aimed.id); + self.ring + .update(cx, |ring, cx| ring.set_lit(id.or(aimed), cx)); if self.shown_tab == Tab::ChampSelect { self.select_art(id, cx); } diff --git a/crates/app/src/page/playback.rs b/crates/app/src/page/playback.rs index 69717dc..404ccbf 100644 --- a/crates/app/src/page/playback.rs +++ b/crates/app/src/page/playback.rs @@ -74,6 +74,8 @@ impl Page { waiting.end, cx.background_executor().now(), ); + // Nothing is aimed at while it plays. + self.leave_ring(cx); // Under the comet, the splash of the champion of the Match before. let target = (self.playback.previous_banner.as_ref()) .filter(|_| { diff --git a/crates/app/src/page/ring_hover.rs b/crates/app/src/page/ring_hover.rs new file mode 100644 index 0000000..ece641e --- /dev/null +++ b/crates/app/src/page/ring_hover.rs @@ -0,0 +1,139 @@ +//! The ring under the pointer (#112): it aims at the tick nearest by angle, lights it and has the +//! banner present its champion, over the rest state of the screen shown (`dress_banner`). Nothing +//! is touched until the aimed tick changes (rule #1), and nothing outside the ring. + +use std::cell::Cell; +use std::rc::Rc; + +use arena_tracker_core::{ChampionRow, Splash}; +use gpui_kit::*; + +use super::Page; +use super::home::Line; +use crate::text::{ordinal, short_date}; + +/// The champion aimed at, with what the banner shows for it, prepared when the aim changes. +pub(in crate::page) struct Aimed { + pub(in crate::page) id: u32, + /// Replaces the banner's first line. + pub(in crate::page) line: Line, + pub(in crate::page) splash: Option>, +} + +#[derive(Default)] +pub(in crate::page) struct RingHover { + /// Where the ring is, written by its slot at each prepaint (no render, no notification). + bounds: Rc>>, + pub(in crate::page) aimed: Option, +} + +/// The champion's line: « X · validé le 12 nov. · 3 Tentatives », « X · 2 Parties · meilleur +/// Placement 3ᵉ » or « X · jamais joué », from the Season's Challenge figures, all Formats. +fn champion_line(row: &ChampionRow) -> Line { + let challenge = row.challenge.unwrap_or_default(); + let detail = if let Some(day) = challenge.completed_on { + let attempts = match row.attempts { + Some(1) => " · du premier coup".to_owned(), + Some(n) => format!(" · {n} Tentatives"), + None => String::new(), + }; + format!(" · validé le {}{attempts}", short_date(day)) + } else if challenge.matches == 0 { + " · jamais joué".to_owned() + } else { + let n = challenge.matches; + let best = (challenge.best_placement) + .map(|placement| format!(" · meilleur Placement {}", ordinal(placement))) + .unwrap_or_default(); + format!(" · {n} {}{best}", if n == 1 { "Partie" } else { "Parties" }) + }; + Line::new("", &row.champion.name, &detail) +} + +impl Page { + /// The ring's slot of the banner, `size` wide: the cached ring, the end of a Match over it, + /// and the pointer's listeners, which are not the ring's (it stays cached). + pub(in crate::page) fn ring_slot( + &self, + size: f32, + now: std::time::Instant, + cx: &mut Context, + ) -> impl IntoElement { + let bounds = self.ring_hover.bounds.clone(); + div() + .id("ring-slot") + .relative() + .size(px(size)) + .flex_none() + .on_mouse_move( + cx.listener(|page, event: &MouseMoveEvent, _, cx| { + page.aim_ring(event.position, cx) + }), + ) + .on_hover(cx.listener(|page, hovered: &bool, _, cx| { + if !*hovered { + page.leave_ring(cx); + } + })) + .child( + canvas(move |at, _, _| bounds.set(at), |_, _, _, _| {}) + .absolute() + .inset_0(), + ) + .child( + self.ring + .clone() + .cached(StyleRefinement::default().size_full()), + ) + .children( + (self.playback.animation) + .map(|a| self.ring.read(cx).match_layer(a, a.elapsed(now), cx)), + ) + } + + /// The pointer moved over the ring's slot, at `at` in the window: a change of the aimed + /// tick lights it and shows its champion, else nothing is done. Ignored while the end of a + /// Match plays. + pub(in crate::page) fn aim_ring(&mut self, at: Point, cx: &mut Context) { + if self.playback.animation.is_some() { + return; + } + let bounds = self.ring_hover.bounds.get(); + let id = (self.ring.read(cx)).champion_at(at - bounds.origin, bounds.size); + if id == self.ring_hover.aimed.as_ref().map(|aimed| aimed.id) { + return; + } + self.ring_hover.aimed = id.and_then(|id| self.aimed(id)); + self.dress_banner(cx); + cx.notify(); + } + + /// The pointer left the ring's slot, or the end of a Match starts: the banner is at rest + /// again. + pub(in crate::page) fn leave_ring(&mut self, cx: &mut Context) { + if self.ring_hover.aimed.take().is_some() { + self.dress_banner(cx); + cx.notify(); + } + } + + /// New statistics: the champion aimed at, if any, is presented from them. + pub(in crate::page) fn reaim(&mut self) { + let id = self.ring_hover.aimed.as_ref().map(|aimed| aimed.id); + self.ring_hover.aimed = id.and_then(|id| self.aimed(id)); + } + + fn aimed(&self, id: u32) -> Option { + let row = (self.home_statistics()?.rows.iter()).find(|row| row.champion.id == id)?; + // The champ select keeps its champions' splashes: no new one to allocate for them. + let splash = match self.champ_select_splashes.get(&id) { + Some(splash) => Some(splash.clone()), + None => row.splash.clone().map(Rc::new), + }; + Some(Aimed { + id, + line: champion_line(row), + splash, + }) + } +} diff --git a/crates/app/src/page/setup.rs b/crates/app/src/page/setup.rs index e2a9231..21f3833 100644 --- a/crates/app/src/page/setup.rs +++ b/crates/app/src/page/setup.rs @@ -263,6 +263,7 @@ impl Page { champ_select_splashes: HashMap::new(), ring, lit_by: None, + ring_hover: Default::default(), banner_art, home_filter: StateFilter::All, home_search: ChampionSearch::new(""), diff --git a/crates/app/src/page/tests.rs b/crates/app/src/page/tests.rs index 8c60117..30fb93f 100644 --- a/crates/app/src/page/tests.rs +++ b/crates/app/src/page/tests.rs @@ -35,5 +35,6 @@ mod matches_refresh; mod navigation; mod page_fixtures; mod portraits; +mod ring_hover; mod sorting; mod sorting_fixtures; diff --git a/crates/app/src/page/tests/ring_hover.rs b/crates/app/src/page/tests/ring_hover.rs new file mode 100644 index 0000000..3763516 --- /dev/null +++ b/crates/app/src/page/tests/ring_hover.rs @@ -0,0 +1,298 @@ +//! The ring under the pointer (#112): it aims at a tick by angle, lights it and has the banner +//! present its champion, back to the screen's rest state once the pointer leaves the crown. + +use super::banner_fixtures::{ + banner_champion, banner_rows, banner_statistics, draw_loaded, held_splashes, last_match_of, + ring_renders, ring_ticks, splash, +}; +use super::match_end_fixtures::animate; +use super::page_fixtures::{animations, draw, frame_after, open_page_in_season, show, statistics}; +use crate::card_images::tests::TestDir; +use crate::motion::MatchEnd; +use crate::page::Page; +use crate::ring::tests::{on_crown, tick_centre}; +use arena_tracker_core::{ChampionRow, Statistics}; +use std::cell::Cell; +use std::rc::Rc; + +use gpui_kit::{Entity, Modifiers, Pixels, Point, TestAppContext, VisualTestContext, point, px}; + +/// Brand then Ahri Completed, Garen then Zyra played, Lux never played: the ring's order. Each +/// has a splash; Brand took 1 Attempt, Ahri 3; Garen's best Placement is 3ᵉ, Zyra's unknown. +fn rows(dir: &std::path::Path) -> Vec { + let mut rows = banner_rows(); + for row in &mut rows { + row.splash = Some(splash(dir, &row.champion.name)); + } + rows[0].attempts = Some(3); + rows[1].attempts = Some(1); + rows[2].challenge.as_mut().unwrap().best_placement = Some(3); + rows[4] = banner_champion(3, "Zyra", 1, None, 50); + rows[4].splash = Some(splash(dir, "Zyra")); + rows +} + +fn challenge(dir: &std::path::Path) -> Statistics { + banner_statistics(rows(dir), vec![2, 1], last_match_of(1)) +} + +/// Where the middle of tick `index` is, in the window. +fn tick_at(page: &Entity, cx: &mut VisualTestContext, index: usize) -> Point { + let ring = cx.debug_bounds("ring").unwrap(); + ring.origin + tick_centre(index, ring_ticks(page, cx).len(), ring.size) +} + +/// The pointer on the middle of tick `index`. +fn aim(page: &Entity, cx: &mut VisualTestContext, index: usize) { + let at = tick_at(page, cx, index); + move_to(cx, at); +} + +fn move_to(cx: &mut VisualTestContext, at: Point) { + cx.simulate_mouse_move(at, None, Modifiers::none()); + draw(cx); +} + +fn lit(page: &Entity, cx: &mut VisualTestContext) -> Option { + page.read_with(cx, |p, cx| p.ring.read(cx).lit()) +} + +/// The first line the banner shows for the champion aimed at, none at rest. +fn line(page: &Entity, cx: &mut VisualTestContext) -> Option { + page.read_with(cx, |p, _| { + (p.ring_hover.aimed.as_ref()).map(|aimed| aimed.line.text.to_string()) + }) +} + +/// The file of the splash the banner's illustration is going to show. +fn art(page: &Entity, cx: &mut VisualTestContext) -> Option { + page.read_with(cx, |p, cx| { + let target = p.banner_art.read(cx).target.clone(); + target.map(|s| s.path.file_name().unwrap().to_string_lossy().into_owned()) + }) +} + +#[gpui::test] +fn aiming_the_ring_lights_the_tick_and_presents_its_champion_until_the_pointer_leaves( + cx: &mut TestAppContext, +) { + let dir = TestDir::new("ring-hover"); + let (page, cx) = open_page_in_season(cx); + let cx = &mut { cx }; + show(&page, cx, challenge(dir.path())); + draw(cx); + assert_eq!(ring_ticks(&page, cx).len(), 5); + let banner = cx.debug_bounds("banner").unwrap(); + // At rest: the last Match's champion, no tick lit. + assert_eq!((lit(&page, cx), line(&page, cx)), (None, None)); + assert_eq!(art(&page, cx).as_deref(), Some("Ahri.50.30.jpg")); + + // Completed in 1 Attempt, then in 3: the second tick, a third of the way round, is Ahri's. + aim(&page, cx, 0); + assert_eq!(lit(&page, cx), Some(2)); + assert_eq!( + line(&page, cx).as_deref(), + Some("Brand · validé le 3 nov. · du premier coup") + ); + assert_eq!(art(&page, cx).as_deref(), Some("Brand.50.30.jpg")); + aim(&page, cx, 1); + assert_eq!(lit(&page, cx), Some(1)); + assert_eq!( + line(&page, cx).as_deref(), + Some("Ahri · validé le 20 nov. · 3 Tentatives") + ); + assert_eq!(art(&page, cx).as_deref(), Some("Ahri.50.30.jpg")); + // Played: its Matches and best Placement, then without a Placement, then a single Match. + aim(&page, cx, 2); + assert_eq!( + line(&page, cx).as_deref(), + Some("Garen · 2 Parties · meilleur Placement 3ᵉ") + ); + aim(&page, cx, 3); + assert_eq!(line(&page, cx).as_deref(), Some("Zyra · 1 Partie")); + aim(&page, cx, 4); + assert_eq!(line(&page, cx).as_deref(), Some("Lux · jamais joué")); + assert_eq!(art(&page, cx).as_deref(), Some("Lux.50.30.jpg")); + // Nothing of the banner moved. + assert_eq!(cx.debug_bounds("banner"), Some(banner)); + + // The middle of the ring is not the crown: back to rest. + let ring = cx.debug_bounds("ring").unwrap(); + move_to(cx, ring.center()); + assert_eq!((lit(&page, cx), line(&page, cx)), (None, None)); + assert_eq!(art(&page, cx).as_deref(), Some("Ahri.50.30.jpg")); + // Aimed again, then the pointer leaves the ring for the page. + aim(&page, cx, 4); + assert_eq!(lit(&page, cx), Some(5)); + move_to(cx, point(px(5.), px(5.))); + assert_eq!((lit(&page, cx), line(&page, cx)), (None, None)); + assert_eq!(art(&page, cx).as_deref(), Some("Ahri.50.30.jpg")); +} + +// Rule #1: the ring is drawn again only for a new tick, and nothing is done off the crown. +#[gpui::test] +fn nothing_is_drawn_again_until_the_aimed_tick_changes(cx: &mut TestAppContext) { + let dir = TestDir::new("ring-hover-light"); + let (page, cx) = open_page_in_season(cx); + let cx = &mut { cx }; + show(&page, cx, challenge(dir.path())); + draw(cx); + let renders = ring_renders(&page, cx); + aim(&page, cx, 1); + assert_eq!(ring_renders(&page, cx), renders + 1); + // The page is told of nothing more. + let notified = Rc::new(Cell::new(0)); + let counted = notified.clone(); + cx.update(|_, cx| { + cx.observe(&page, move |_, _| counted.set(counted.get() + 1)) + .detach() + }); + + // Elsewhere in the same tick's sector, on the crown or not quite: no change, no frame. + let ring = cx.debug_bounds("ring").unwrap(); + for (degrees, radius) in [(80., 230.), (90., 205.), (100., 250.)] { + cx.simulate_mouse_move( + ring.origin + on_crown(degrees, radius, ring.size), + None, + Modifiers::none(), + ); + assert_eq!(notified.get(), 0, "{degrees}"); + } + assert_eq!(ring_renders(&page, cx), renders + 1); + + // Off the crown, inside the ring's square or out of it: the tick goes out, once. + move_to(cx, ring.center()); + assert_eq!(ring_renders(&page, cx), renders + 2); + for at in [ + ring.center(), + ring.origin + point(px(1.), px(1.)), + point(px(5.), px(5.)), + ] { + cx.simulate_mouse_move(at, None, Modifiers::none()); + } + // Told once, of the tick going out. + assert_eq!(notified.get(), 1); + assert_eq!(ring_renders(&page, cx), renders + 2); +} + +// A quick sweep of the crown asks for many illustrations and decodes the first and the last. +#[gpui::test] +fn a_sweep_holds_two_splashes_at_most_and_ends_on_the_last_aimed(cx: &mut TestAppContext) { + let dir = TestDir::new("ring-hover-sweep"); + let (page, cx) = open_page_in_season(cx); + let cx = &mut { cx }; + show(&page, cx, challenge(dir.path())); + draw_loaded(cx); + let loads = |page: &Entity, cx: &mut VisualTestContext| { + page.read_with(cx, |p, cx| p.banner_art.read(cx).loads) + }; + let before = loads(&page, cx); + for index in [0, 2, 4, 3, 1, 4, 2] { + aim(&page, cx, index); + assert!(held_splashes(&page, cx).len() <= 2); + } + // Only the first splash aimed at and the last are decoded, one at a time. + for _ in 0..4 { + cx.run_until_parked(); + frame_after(cx, 600); + assert!(held_splashes(&page, cx).len() <= 2); + } + assert_eq!(loads(&page, cx), before + 2); + assert_eq!(art(&page, cx).as_deref(), Some("Garen.50.30.jpg")); + assert_eq!(held_splashes(&page, cx), ["Garen.50.30.jpg"]); +} + +#[gpui::test] +fn without_animations_the_illustration_changes_without_a_fade(cx: &mut TestAppContext) { + let dir = TestDir::new("ring-hover-still"); + let (page, cx) = open_page_in_season(cx); + let cx = &mut { cx }; + show(&page, cx, challenge(dir.path())); + draw_loaded(cx); + let shown = |page: &Entity, cx: &mut VisualTestContext| { + page.read_with(cx, |p, cx| p.banner_art.read(cx).loaded().len()) + }; + animations(cx, false); + aim(&page, cx, 0); + draw_loaded(cx); + assert_eq!(art(&page, cx).as_deref(), Some("Brand.50.30.jpg")); + // Only the new image: the old one has no fade to wait for. + assert_eq!(shown(&page, cx), 1); + assert_eq!(held_splashes(&page, cx), ["Brand.50.30.jpg"]); + + animations(cx, true); + aim(&page, cx, 1); + draw_loaded(cx); + assert_eq!(shown(&page, cx), 2); +} + +#[gpui::test] +fn the_ring_is_not_aimed_at_while_the_end_of_a_match_plays(cx: &mut TestAppContext) { + let (page, cx) = open_page_in_season(cx); + let cx = &mut { cx }; + show( + &page, + cx, + statistics(0, 5, super::page_fixtures::champions(5)), + ); + draw(cx); + animate(&page, cx, MatchEnd::Mark); + assert!(page.read_with(cx, |p, _| p.playback.animation.is_some())); + draw(cx); + aim(&page, cx, 3); + assert_eq!((lit(&page, cx), line(&page, cx)), (None, None)); + + page.update(cx, |p, cx| p.end_match(cx)); + draw(cx); + aim(&page, cx, 3); + assert_eq!(lit(&page, cx), Some(4)); +} + +// A pointer on the ring when the end of a Match starts: the tick goes out. +#[gpui::test] +fn the_end_of_a_match_starting_ends_the_aim(cx: &mut TestAppContext) { + let (page, cx) = open_page_in_season(cx); + let cx = &mut { cx }; + show( + &page, + cx, + statistics(0, 5, super::page_fixtures::champions(5)), + ); + draw(cx); + aim(&page, cx, 3); + assert_eq!(lit(&page, cx), Some(4)); + animate(&page, cx, MatchEnd::Mark); + assert!(page.read_with(cx, |p, _| p.playback.animation.is_some())); + assert_eq!((lit(&page, cx), line(&page, cx)), (None, None)); +} + +// « En partie »: the champion played is lit at rest, and it is again once the pointer leaves. +#[gpui::test] +async fn on_en_partie_leaving_the_crown_lights_the_champion_played_again(app: &mut TestAppContext) { + use super::champ_select_fixtures::finish_motion; + use super::in_game_fixtures::{in_game_ready, joueur_in_game}; + let (page, mut window, mut client, _) = joueur_in_game(app, 233).await; + let cx = &mut window; + client.read(&page, cx); + finish_motion(&page, cx); + in_game_ready(&page, app).await; + let cx = &mut window; + draw(cx); + assert_eq!(lit(&page, cx), Some(233)); + + let other = ring_ticks(&page, cx) + .iter() + .position(|(id, _)| *id != 233) + .unwrap(); + aim(&page, cx, other); + let aimed = ring_ticks(&page, cx)[other].0; + assert_eq!(lit(&page, cx), Some(aimed)); + assert!(line(&page, cx).is_some()); + move_to(cx, point(px(5.), px(5.))); + assert_eq!((lit(&page, cx), line(&page, cx)), (Some(233), None)); + let rest = page.read_with(cx, |p, _| p.in_game.banner.splash.clone()); + assert_eq!( + page.read_with(cx, |p, cx| p.banner_art.read(cx).target.clone()), + rest + ); +} diff --git a/crates/app/src/ring.rs b/crates/app/src/ring.rs index a7d5be6..463a646 100644 --- a/crates/app/src/ring.rs +++ b/crates/app/src/ring.rs @@ -17,6 +17,7 @@ use gpui_kit::*; use crate::motion::{MATCH_SETTLE, MatchAnimation, MatchEnd, ease_out}; use crate::theme::{ring_never, ring_played}; +mod aim; mod ticks; pub use ticks::{Tick, ticks}; @@ -267,6 +268,13 @@ impl Ring { pub(crate) fn lit(&self) -> Option { self.lit } + + /// The champion of the tick the pointer aims at, `at` being relative to the ring's bounds, + /// of `size`; none when it is off the crown. + pub(crate) fn champion_at(&self, at: Point, size: Size) -> Option { + let index = aim::aimed(at, size, self.ticks.len())?; + Some(self.ticks[index].id) + } } impl Ring { @@ -457,4 +465,4 @@ impl Render for Ring { } #[cfg(test)] -mod tests; +pub(crate) mod tests; diff --git a/crates/app/src/ring/aim.rs b/crates/app/src/ring/aim.rs new file mode 100644 index 0000000..a63706c --- /dev/null +++ b/crates/app/src/ring/aim.rs @@ -0,0 +1,32 @@ +//! Which tick the pointer aims at: the nearest by angle, not to the pixel, so that the thin +//! ticks are as easy to reach as the long ones. + +use std::f32::consts::TAU; + +use gpui_kit::{Pixels, Point, Size}; + +use super::{BOX, C, PAD, R1, R2}; + +/// The band around the crown that aims, in the reference page's units: from a little inside the +/// longest tick's foot to a little beyond its head. The shorter ticks lie within it. +const FROM: f32 = R1 - 12.; +const TO: f32 = R2 + 10.; + +/// The index of the tick of `count` the pointer at `at` aims at, `at` being relative to the +/// ring's top left corner and the ring `size`; none off the band. Tick `i` is the sector of +/// `TAU / count` it sits in the middle of, counted clockwise from noon. +pub(super) fn aimed(at: Point, size: Size, count: usize) -> Option { + let scale = size.width.min(size.height).as_f32() / BOX; + if count == 0 || scale <= 0. { + return None; + } + let (x, y) = ( + at.x.as_f32() / scale - PAD - C, + at.y.as_f32() / scale - PAD - C, + ); + if !(FROM..=TO).contains(&x.hypot(y)) { + return None; + } + let turn = x.atan2(-y).rem_euclid(TAU) / TAU; + Some(((turn * count as f32) as usize).min(count - 1)) +} diff --git a/crates/app/src/ring/tests.rs b/crates/app/src/ring/tests.rs index d4cc988..86adc4c 100644 --- a/crates/app/src/ring/tests.rs +++ b/crates/app/src/ring/tests.rs @@ -1,8 +1,9 @@ use arena_tracker_core::{Champion, ChampionRow, ChampionState}; -use gpui_kit::{px, size}; +use gpui_kit::{Pixels, Point, Size, point, px, size}; -use super::{Geometry, Tick, ticks}; +use super::aim::aimed; +use super::{BOX, C, Geometry, PAD, R1, R2, Tick, ticks}; use crate::champion_table::tests::row; fn champion(id: u32, name: &str, state: ChampionState, points: Option) -> ChampionRow { @@ -110,3 +111,51 @@ fn only_the_anvil_champions_ticks_stay_bright() { [(Completed, true), (InProgress, true), (NeverPlayed, true)] ); } + +/// The point `radius` units from the centre of a ring of `size`, `degrees` clockwise from noon, +/// relative to its corner. +pub(crate) fn on_crown(degrees: f32, radius: f32, size: Size) -> Point { + let angle = degrees.to_radians(); + let scale = size.width.min(size.height).as_f32() / BOX; + point( + px((PAD + C + radius * angle.sin()) * scale), + px((PAD + C - radius * angle.cos()) * scale), + ) +} + +/// The middle of the tick `index` of `count`, on the crown. +pub(crate) fn tick_centre(index: usize, count: usize, size: Size) -> Point { + let degrees = (index as f32 + 0.5) * 360. / count as f32; + on_crown(degrees, (R1 + R2) / 2., size) +} + +#[test] +fn the_pointer_aims_at_the_nearest_tick_by_angle_on_the_crown_only() { + let ring = size(px(200.), px(200.)); + let middle = (R1 + R2) / 2.; + // Each tick is aimed at from its own place, at any radius of the band. + for count in [1, 7, 172] { + for index in 0..count { + let degrees = (index as f32 + 0.5) * 360. / count as f32; + for radius in [R1 - 10., middle, R2 + 8.] { + let at = on_crown(degrees, radius, ring); + assert_eq!(aimed(at, ring, count), Some(index), "{index} of {count}"); + } + } + } + // Not to the pixel: with four ticks the first owns the quarter from noon to three o'clock. + let aim = |degrees, radius, count| aimed(on_crown(degrees, radius, ring), ring, count); + assert_eq!(aim(1., middle, 4), Some(0)); + assert_eq!(aim(89., middle, 4), Some(0)); + assert_eq!(aim(91., middle, 4), Some(1)); + assert_eq!(aim(359., middle, 4), Some(3)); + // Off the band, inside the disc or beyond the crown, and without ticks: none. + assert_eq!(aim(45., R1 - 20., 4), None); + assert_eq!(aim(45., 0., 4), None); + assert_eq!(aim(45., R2 + 14., 4), None); + assert_eq!(aim(45., middle, 0), None); + assert_eq!( + aimed(on_crown(45., middle, ring), size(px(0.), px(0.)), 4), + None + ); +} diff --git a/docs/guide-utilisation.md b/docs/guide-utilisation.md index ffeeba6..2d74eb0 100644 --- a/docs/guide-utilisation.md +++ b/docs/guide-utilisation.md @@ -2,7 +2,7 @@ ## Défi et Statistiques -L’appli s’ouvre sur **Défi** : la bannière du Défi de la Saison, puis les cartes de vos champions. À côté des onglets, le sélecteur de **Compte** liste les Comptes déjà connectés au client sur ce PC, le Compte actif (celui du client) en premier, et choisit le Compte que montrent **Défi**, **Statistiques** et **Parties**. Pour un autre Compte, la bannière commence par « Défi de Pseudo · », et la Progression officielle et l’animation de fin de Partie sont réservées au Compte actif. Le filtre **Tous** revient à chaque changement de Compte ; le tri et le thème restent les mêmes. L’appli revient sur le Compte actif quand une Sélection ou une Partie en cours commence, et à la fin d’une Partie suivie. Pour l’analyse détaillée (courbe des champions validés, Placements, Tentatives, tableau des champions, avec les sélecteurs de Saison et de Format), ouvrez **Statistiques ›**, le lien au bout de la ligne de la Saison, en haut de la bannière. La page porte **‹ Défi** en haut à gauche, qui ramène au Défi ; l’onglet **Défi** de la barre du haut y ramène aussi. Au clavier, Tab atteint le lien et le retour, Entrée ou Espace les active. +L’appli s’ouvre sur **Défi** : la bannière du Défi de la Saison, puis les cartes de vos champions. À côté des onglets, le sélecteur de **Compte** liste les Comptes déjà connectés au client sur ce PC, le Compte actif (celui du client) en premier, et choisit le Compte que montrent **Défi**, **Statistiques** et **Parties**. Pour un autre Compte, la bannière commence par « Défi de Pseudo · », et la Progression officielle et l’animation de fin de Partie sont réservées au Compte actif. Le filtre **Tous** revient à chaque changement de Compte ; le tri et le thème restent les mêmes. L’appli revient sur le Compte actif quand une Sélection ou une Partie en cours commence, et à la fin d’une Partie suivie. Pour l’analyse détaillée (courbe des champions validés, Placements, Tentatives, tableau des champions, avec les sélecteurs de Saison et de Format), ouvrez **Statistiques ›**, le lien au bout de la ligne de la Saison, en haut de la bannière. La page porte **‹ Défi** en haut à gauche, qui ramène au Défi ; l’onglet **Défi** de la barre du haut y ramène aussi. Au clavier, Tab atteint le lien et le retour, Entrée ou Espace les active. Survolez l’anneau de la bannière : la graduation visée s’allume et la bannière présente ce champion (« X · validé le 12 nov. · 3 Tentatives », « X · 2 Parties · meilleur Placement 3ᵉ » ou « X · jamais joué ») ; elle revient à son état habituel quand vous quittez l’anneau. Au début d’une Sélection des champions Arena, l’onglet **Sélection** apparaît à droite de **Défi** et **Parties** et l’appli l’affiche d’elle-même, où que vous soyez. Il montre les Champions de l’Enclume et « Autres champions ». Pendant la sélection, l’onglet **Défi** montre l’accueil habituel (et **Statistiques ›**) ; revenez sur **Sélection** quand vous voulez, la main y est posée. Les bans et les choix des alliés ne vous ramènent pas sur **Sélection**. À la fin de la sélection, l’onglet disparaît et l’appli affiche le Défi, ou **En partie** si la partie est lancée. diff --git a/docs/interface.md b/docs/interface.md index 6e5e54a..0d4dcf3 100644 --- a/docs/interface.md +++ b/docs/interface.md @@ -60,7 +60,7 @@ Cette section décrit l’identité « L’Anneau ». [La page de référence](p **Bannière de sélection.** Elle ouvre l’onglet « Sélection » pendant une sélection Arena ; « Défi » garde la bannière d’accueil. Son surtitre porte le compteur, son titre est « Sélection des champions », et sa ligne indique « Champions de l’Enclume · k à valider et disponibles ». Seules les graduations des Champions de l’Enclume y restent vives. L’illustration suit la carte survolée ; au repos, c’est celle du premier Champion de l’Enclume à valider et disponible. La barre du haut n’affiche pas d’autre indicateur de sélection que l’onglet « Sélection ». -**Anneau.** Une graduation par champion du Défi, dans un ordre fixe : d’abord les validés, dans l’ordre de leur Premier top 1 en tournant depuis midi, puis les champions joués, puis ceux jamais joués, ces deux derniers groupes par points de maîtrise décroissants (A–Z tant que les points sont inconnus, comme les cartes). Il ne suit pas le tri choisi. +**Anneau.** Une graduation par champion du Défi, dans un ordre fixe : d’abord les validés, dans l’ordre de leur Premier top 1 en tournant depuis midi, puis les champions joués, puis ceux jamais joués, ces deux derniers groupes par points de maîtrise décroissants (A–Z tant que les points sont inconnus, comme les cartes). Il ne suit pas le tri choisi. Survoler la couronne vise la graduation la plus proche par l’angle, pas au pixel près (dans une bande qui déborde un peu les graduations, à l’intérieur comme à l’extérieur) : elle s’allume comme au survol d’une carte, l’illustration de la bannière passe en fondu sur ce champion (sans fondu quand les animations Windows sont coupées) et la première ligne de la bannière devient la sienne, son nom en gras : « X · validé le 12 nov. · 3 Tentatives » (« · du premier coup » pour une seule), « X · 2 Parties · meilleur Placement 3ᵉ » (« 1 Partie » au singulier ; sans Placement connu, la fin est omise) ou « X · jamais joué », selon les chiffres de la Saison, tous Formats. Le titre ne change pas ; la seconde ligne (« Dernière Partie : … ») est masquée sans que rien ne bouge. En quittant la couronne, la bannière revient à l’état de repos de l’écran affiché (« Défi », « Sélection », « En partie »), et il en va de même partout où l’anneau est affiché. Pendant l’animation de fin de Partie, le survol de l’anneau est ignoré. Règle n° 1 : rien n’est redessiné tant que la graduation visée ne change pas, hors de la couronne il n’y a aucun travail, et un balayage rapide ne décode jamais plus de deux illustrations à la fois, la dernière graduation visée l’emportant. **Illustration.** La bannière montre une fenêtre d’environ 80 % de la largeur du splash du champion, centrée sur lui (voir les décisions d’implémentation pour le cadrage). Elle passe d’une illustration à l’autre par un fondu.