Light the ring's tick under the pointer and present its champion (#112)
- 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 <noreply@anthropic.com>
This commit is contained in:
1 parent
cae84c1577
commit
c9d53055d9
14 files changed
+569
-28
No files matched your search
@@ -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<Ring>,
|
||||
/// The grid whose card lit the ring's tick.
|
||||
lit_by: Option<EntityId>,
|
||||
/// 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<BannerArt>,
|
||||
/// The home's own filter and search: never persisted, « Tous » at each launch.
|
||||
|
||||
@@ -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<u32>, cx: &mut Context<Self>) {
|
||||
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));
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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(|_| {
|
||||
|
||||
@@ -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<Rc<Splash>>,
|
||||
}
|
||||
|
||||
#[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<Cell<Bounds<Pixels>>>,
|
||||
pub(in crate::page) aimed: Option<Aimed>,
|
||||
}
|
||||
|
||||
/// 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<Page>,
|
||||
) -> 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<Pixels>, cx: &mut Context<Self>) {
|
||||
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<Self>) {
|
||||
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<Aimed> {
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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(""),
|
||||
|
||||
@@ -35,5 +35,6 @@ mod matches_refresh;
|
||||
mod navigation;
|
||||
mod page_fixtures;
|
||||
mod portraits;
|
||||
mod ring_hover;
|
||||
mod sorting;
|
||||
mod sorting_fixtures;
|
||||
@@ -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<ChampionRow> {
|
||||
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<Page>, cx: &mut VisualTestContext, index: usize) -> Point<Pixels> {
|
||||
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<Page>, cx: &mut VisualTestContext, index: usize) {
|
||||
let at = tick_at(page, cx, index);
|
||||
move_to(cx, at);
|
||||
}
|
||||
|
||||
fn move_to(cx: &mut VisualTestContext, at: Point<Pixels>) {
|
||||
cx.simulate_mouse_move(at, None, Modifiers::none());
|
||||
draw(cx);
|
||||
}
|
||||
|
||||
fn lit(page: &Entity<Page>, cx: &mut VisualTestContext) -> Option<u32> {
|
||||
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<Page>, cx: &mut VisualTestContext) -> Option<String> {
|
||||
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<Page>, cx: &mut VisualTestContext) -> Option<String> {
|
||||
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<Page>, 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<Page>, 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
|
||||
);
|
||||
}
|
||||
@@ -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<u32> {
|
||||
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<Pixels>, size: Size<Pixels>) -> Option<u32> {
|
||||
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;
|
||||
@@ -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<Pixels>, size: Size<Pixels>, count: usize) -> Option<usize> {
|
||||
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))
|
||||
}
|
||||
@@ -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<u64>) -> 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<Pixels>) -> Point<Pixels> {
|
||||
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<Pixels>) -> Point<Pixels> {
|
||||
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
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user