Center player stats and scroll to the viewed account in a chosen Match
This commit was merged in pull request #139.
This commit is contained in:
1 parent
d2f5a6b96d
commit
8b6062aebc
5 files changed
+165
-63
No files matched your search
@@ -36,7 +36,6 @@ pub(in crate::page) use shown::{AWAITED, Described, ShownPlayer, Slot, UNAVAILAB
|
||||
use shown::{Champions, ShownRecap};
|
||||
|
||||
use super::{Page, Tab};
|
||||
use crate::card_images::CardImages;
|
||||
use crate::worker::{MatchEntry, RefreshGate, spawn_match_list, spawn_recap};
|
||||
use arena_tracker_core::{DeathRecapState, GameCatalog, MatchRecap, Season};
|
||||
use gpui_kit::component::input::InputEvent;
|
||||
@@ -48,7 +47,9 @@ pub(in crate::page) enum Recap {
|
||||
/// No Match chosen.
|
||||
None,
|
||||
/// The Match chosen is being decoded.
|
||||
Loading,
|
||||
Loading {
|
||||
center_player: bool,
|
||||
},
|
||||
/// The Match is no longer stored.
|
||||
Missing,
|
||||
Failed(SharedString),
|
||||
@@ -289,7 +290,13 @@ impl Page {
|
||||
&& (matches.selected.as_ref())
|
||||
.is_some_and(|id| entries.iter().any(|entry| entry.match_id == *id));
|
||||
if corrected || failed {
|
||||
self.request_recap();
|
||||
let center = matches!(
|
||||
matches.recap,
|
||||
Recap::Loading {
|
||||
center_player: true
|
||||
}
|
||||
);
|
||||
self.request_recap(center);
|
||||
}
|
||||
self.dress_matches(cx);
|
||||
}
|
||||
@@ -303,7 +310,16 @@ impl Page {
|
||||
self.matches.arriving = None;
|
||||
if self.matches.selected.as_deref() != Some(match_id.as_str()) {
|
||||
self.matches.selected = Some(match_id);
|
||||
self.request_recap();
|
||||
self.request_recap(true);
|
||||
} else {
|
||||
match &mut self.matches.recap {
|
||||
Recap::Loading { center_player } => *center_player = true,
|
||||
Recap::Ready { pane, .. } => pane.update(cx, |pane, cx| {
|
||||
pane.center_player = true;
|
||||
cx.notify();
|
||||
}),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
self.dress_banner(cx);
|
||||
cx.notify();
|
||||
@@ -311,7 +327,7 @@ impl Page {
|
||||
|
||||
/// Decodes the Match chosen on a worker, one at a time: a choice made meanwhile is decoded
|
||||
/// once it reports, and its result dropped.
|
||||
fn request_recap(&mut self) {
|
||||
fn request_recap(&mut self, center_player: bool) {
|
||||
let matches = &mut self.matches;
|
||||
matches.recap_generation += 1;
|
||||
let Some(selected) = &matches.selected else {
|
||||
@@ -322,7 +338,7 @@ impl Page {
|
||||
let same =
|
||||
matches!(&matches.recap, Recap::Ready { recap, .. } if recap.match_id == *selected);
|
||||
if !same {
|
||||
matches.recap = Recap::Loading;
|
||||
matches.recap = Recap::Loading { center_player };
|
||||
}
|
||||
if matches.recap_job.request() {
|
||||
self.spawn_recap();
|
||||
@@ -392,16 +408,13 @@ impl Page {
|
||||
});
|
||||
pane
|
||||
} else {
|
||||
let page = cx.weak_entity();
|
||||
let images = CardImages::new(cx);
|
||||
cx.new(|_| recap::RecapPane {
|
||||
page,
|
||||
images,
|
||||
shown,
|
||||
open,
|
||||
#[cfg(test)]
|
||||
renders: 0,
|
||||
})
|
||||
let center = matches!(
|
||||
self.matches.recap,
|
||||
Recap::Loading {
|
||||
center_player: true
|
||||
}
|
||||
);
|
||||
recap::RecapPane::new(shown, center, cx)
|
||||
};
|
||||
Recap::Ready {
|
||||
recap: Box::new(recap),
|
||||
|
||||
@@ -159,7 +159,7 @@ impl Page {
|
||||
.list
|
||||
.update(cx, |list, cx| list.set_rows(rows, selected.as_deref(), cx));
|
||||
if choose {
|
||||
self.request_recap();
|
||||
self.request_recap(false);
|
||||
}
|
||||
self.dress_banner(cx);
|
||||
}
|
||||
|
||||
@@ -22,10 +22,33 @@ pub(in crate::page) struct RecapPane {
|
||||
pub(super) open: Option<usize>,
|
||||
pub(super) page: WeakEntity<Page>,
|
||||
pub(super) images: Entity<CardImages>,
|
||||
scroll: ScrollHandle,
|
||||
pub(super) center_player: bool,
|
||||
#[cfg(test)]
|
||||
pub(in crate::page) renders: usize,
|
||||
}
|
||||
|
||||
impl RecapPane {
|
||||
pub(super) fn new(
|
||||
shown: ShownRecap,
|
||||
center_player: bool,
|
||||
cx: &mut Context<Page>,
|
||||
) -> Entity<Self> {
|
||||
let page = cx.weak_entity();
|
||||
let images = CardImages::new(cx);
|
||||
cx.new(|_| Self {
|
||||
page,
|
||||
images,
|
||||
shown,
|
||||
open: None,
|
||||
scroll: ScrollHandle::new(),
|
||||
center_player,
|
||||
#[cfg(test)]
|
||||
renders: 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for RecapPane {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
#[cfg(test)]
|
||||
@@ -34,8 +57,11 @@ impl Render for RecapPane {
|
||||
}
|
||||
self.images
|
||||
.update(cx, |images, cx| images.start_render(window, cx));
|
||||
let center = std::mem::take(&mut self.center_player).then_some(&self.scroll);
|
||||
div()
|
||||
.id("recap-scroll")
|
||||
.track_scroll(&self.scroll)
|
||||
.debug_selector(|| "recap-viewport".into())
|
||||
.size_full()
|
||||
.overflow_y_scroll()
|
||||
.child(
|
||||
@@ -45,7 +71,7 @@ impl Render for RecapPane {
|
||||
.pr_2()
|
||||
.debug_selector(|| "recap".into())
|
||||
.child(header(&self.shown, cx))
|
||||
.child(teams(&self.shown, self.open, cx)),
|
||||
.child(teams(&self.shown, self.open, center, cx)),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -157,6 +183,7 @@ pub(in crate::page) fn provisional_badge(theme: &Theme) -> impl IntoElement {
|
||||
pub(in crate::page) fn teams(
|
||||
recap: &ShownRecap,
|
||||
open: Option<usize>,
|
||||
center: Option<&ScrollHandle>,
|
||||
cx: &Context<RecapPane>,
|
||||
) -> impl IntoElement {
|
||||
let mut index = 0;
|
||||
@@ -166,7 +193,7 @@ pub(in crate::page) fn teams(
|
||||
.children(recap.teams.iter().map(|shown| {
|
||||
let first = index;
|
||||
index += shown.players.len();
|
||||
team(shown, first, open, cx)
|
||||
team(shown, first, open, center, cx)
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -175,6 +202,7 @@ fn team(
|
||||
shown: &ShownTeam,
|
||||
first: usize,
|
||||
open: Option<usize>,
|
||||
center: Option<&ScrollHandle>,
|
||||
cx: &Context<RecapPane>,
|
||||
) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
@@ -189,16 +217,36 @@ fn team(
|
||||
text.text_color(gold_ink(theme))
|
||||
}),
|
||||
)
|
||||
.children(
|
||||
(shown.players.iter())
|
||||
.enumerate()
|
||||
.map(|(ix, shown)| player(shown, first + ix, open == Some(first + ix), cx)),
|
||||
)
|
||||
.children((shown.players.iter()).enumerate().map(|(ix, shown)| {
|
||||
let row = player(shown, first + ix, open == Some(first + ix), cx);
|
||||
match center.filter(|_| shown.is_account) {
|
||||
Some(scroll) => center_player_row(row, scroll.clone(), cx.weak_entity()),
|
||||
None => row,
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
/// Center the player's button once its actual position and the viewport are known.
|
||||
fn center_player_row(row: Div, scroll: ScrollHandle, pane: WeakEntity<RecapPane>) -> Div {
|
||||
row.on_children_prepainted(move |children, window, cx| {
|
||||
let Some(line) = children.first() else { return };
|
||||
let mut offset = scroll.offset();
|
||||
let target = (offset.y + scroll.bounds().center().y - line.center().y)
|
||||
.clamp(-scroll.max_offset().y, px(0.));
|
||||
if (target - offset.y).abs() >= px(0.5) {
|
||||
offset.y = target;
|
||||
scroll.set_offset(offset);
|
||||
let pane = pane.clone();
|
||||
window.defer(cx, move |_, cx| {
|
||||
let _ = pane.update(cx, |_, cx| cx.notify());
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// One line per player: who, their level, K/D/A and damage to champions, then their items and
|
||||
/// augments under their name. The line is a button: it unfolds the details, built only then.
|
||||
fn player(shown: &ShownPlayer, ix: usize, open: bool, cx: &Context<RecapPane>) -> impl IntoElement {
|
||||
fn player(shown: &ShownPlayer, ix: usize, open: bool, cx: &Context<RecapPane>) -> Div {
|
||||
let theme = cx.theme();
|
||||
let gold = gold_ink(theme);
|
||||
let (ring, hover, hover_foreground) = (theme.ring, theme.accent, theme.accent_foreground);
|
||||
@@ -215,11 +263,21 @@ fn player(shown: &ShownPlayer, ix: usize, open: bool, cx: &Context<RecapPane>) -
|
||||
.child(shown.champion.clone()),
|
||||
)
|
||||
.child(value(&shown.riot_id, theme).text_xs());
|
||||
let line = BaseButton::new(("recap-player", ix))
|
||||
.v_flex()
|
||||
.items_stretch()
|
||||
.w_full()
|
||||
let equipment = div()
|
||||
.h_flex()
|
||||
.flex_wrap()
|
||||
.items_center()
|
||||
.gap_1()
|
||||
.pl(px(PORTRAIT + 12.))
|
||||
.child(items(&shown.items, ix, theme))
|
||||
.child(augments(&shown.augments, ix, theme));
|
||||
let line = BaseButton::new(("recap-player", ix))
|
||||
.h_flex()
|
||||
.items_center()
|
||||
.flex_wrap()
|
||||
.w_full()
|
||||
.gap_x_3()
|
||||
.gap_y_1()
|
||||
.px_2()
|
||||
.py_1()
|
||||
.rounded_md()
|
||||
@@ -231,42 +289,40 @@ fn player(shown: &ShownPlayer, ix: usize, open: bool, cx: &Context<RecapPane>) -
|
||||
.debug_selector(move || format!("recap-player-{ix}"))
|
||||
.child(
|
||||
div()
|
||||
.h_flex()
|
||||
.items_center()
|
||||
.gap_3()
|
||||
.child(portrait(shown.portrait.as_ref(), PORTRAIT, theme))
|
||||
.child(identity)
|
||||
.child(stat("Niveau", &shown.level, 72., theme))
|
||||
.child(stat("K/D/A", &shown.kda, 120., theme))
|
||||
.v_flex()
|
||||
.flex_1()
|
||||
.min_w(px(PORTRAIT + 12. + SLOT * 7. + 3. * 6. + 8.))
|
||||
.gap_1()
|
||||
.child(
|
||||
labelled(
|
||||
DEALT,
|
||||
details_view::dealt(&shown.details, theme),
|
||||
// The bar, then « Indisponible » at its widest.
|
||||
180.,
|
||||
theme,
|
||||
)
|
||||
.debug_selector(move || format!("recap-dealt-{ix}")),
|
||||
div()
|
||||
.h_flex()
|
||||
.items_center()
|
||||
.gap_3()
|
||||
.child(portrait(shown.portrait.as_ref(), PORTRAIT, theme))
|
||||
.child(identity),
|
||||
)
|
||||
.child(
|
||||
Icon::new(if open {
|
||||
IconName::ChevronDown
|
||||
} else {
|
||||
IconName::ChevronRight
|
||||
})
|
||||
.small()
|
||||
.text_color(theme.muted_foreground),
|
||||
),
|
||||
.child(equipment),
|
||||
)
|
||||
.child(stat("Niveau", &shown.level, 72., theme))
|
||||
.child(stat("K/D/A", &shown.kda, 120., theme))
|
||||
.child(
|
||||
labelled(
|
||||
DEALT,
|
||||
details_view::dealt(&shown.details, theme),
|
||||
// The bar, then « Indisponible » at its widest.
|
||||
180.,
|
||||
theme,
|
||||
)
|
||||
.debug_selector(move || format!("recap-dealt-{ix}")),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.h_flex()
|
||||
.flex_wrap()
|
||||
.items_center()
|
||||
.gap_1()
|
||||
.pl(px(PORTRAIT + 12.))
|
||||
.child(items(&shown.items, ix, theme))
|
||||
.child(augments(&shown.augments, ix, theme)),
|
||||
Icon::new(if open {
|
||||
IconName::ChevronDown
|
||||
} else {
|
||||
IconName::ChevronRight
|
||||
})
|
||||
.small()
|
||||
.text_color(theme.muted_foreground),
|
||||
)
|
||||
.on_click(cx.listener(move |page, _, _, cx| {
|
||||
page.open = (page.open != Some(ix)).then_some(ix);
|
||||
|
||||
@@ -206,7 +206,7 @@ impl Page {
|
||||
let muted = cx.theme().muted_foreground;
|
||||
let content: Vec<AnyElement> = match &self.matches.recap {
|
||||
Recap::None => Vec::new(),
|
||||
Recap::Loading => vec![notice_line(
|
||||
Recap::Loading { .. } => vec![notice_line(
|
||||
"recap-loading",
|
||||
"Chargement du récapitulatif…".into(),
|
||||
muted,
|
||||
|
||||
@@ -165,7 +165,9 @@ async fn a_click_unfolds_a_player_and_another_click_folds_them(cx: &mut TestAppC
|
||||
let cx = &mut window;
|
||||
// Folded: nothing of the details is built, but each line draws its damage as a bar.
|
||||
assert_eq!(unfolded(&page, cx), None);
|
||||
assert!(cx.debug_bounds("recap-dealt-0").is_some());
|
||||
let line = cx.debug_bounds("recap-player-0").unwrap();
|
||||
let damage = cx.debug_bounds("recap-dealt-0").unwrap();
|
||||
assert!((damage.center().y - line.center().y).abs() < gpui_kit::px(1.));
|
||||
assert!(cx.debug_bounds("recap-details").is_none());
|
||||
|
||||
let (first, _) = player(&page, cx, "Autre03");
|
||||
@@ -233,3 +235,34 @@ async fn the_details_are_not_kept_from_one_match_to_another(cx: &mut TestAppCont
|
||||
recap_ready(&page, cx).await;
|
||||
assert_eq!(unfolded(&page, &mut window), None);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn choosing_a_match_centers_the_displayed_accounts_row(cx: &mut TestAppContext) {
|
||||
use gpui_kit::{px, size};
|
||||
|
||||
let (page, mut window) = open_matches(cx).await;
|
||||
let banner = window.debug_bounds("banner").unwrap().size.height;
|
||||
window.simulate_resize(size(px(1280.), banner + px(380.)));
|
||||
draw(&mut window);
|
||||
open_full_recap(&page, cx, &mut window).await;
|
||||
window.run_until_parked();
|
||||
draw(&mut window);
|
||||
let row = window.debug_bounds("recap-account").unwrap();
|
||||
let viewport = window.debug_bounds("recap-viewport").unwrap();
|
||||
assert!(
|
||||
(row.center().y - viewport.center().y).abs() < px(1.),
|
||||
"{row:?} in {viewport:?}"
|
||||
);
|
||||
window.simulate_event(gpui_kit::ScrollEvent {
|
||||
position: viewport.center(),
|
||||
delta: gpui_kit::ScrollDelta::Pixels(gpui_kit::point(px(0.), px(5000.))),
|
||||
..Default::default()
|
||||
});
|
||||
draw(&mut window);
|
||||
assert!(window.debug_bounds("recap-account").unwrap().top() > row.top() + px(1.));
|
||||
click(&mut window, "match-row-2");
|
||||
window.run_until_parked();
|
||||
draw(&mut window);
|
||||
assert!((window.debug_bounds("recap-account").unwrap().top() - row.top()).abs() < px(1.));
|
||||
assert_eq!(unfolded(&page, &mut window), None);
|
||||
}
|
||||
Reference in new issue
Block a user