diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index aa54577..39c8b9f 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -6,7 +6,7 @@ English (US) release notes, mirroring CHANGELOG.md (Brazilian Portuguese). Befor - The 2.0 alpha plays the Console Mode startup sound with every opening animation. -- Version 2.0 opens on a welcome dashboard with a session overview and a customizable background. +- The 2.0 welcome screen shows recent Steam games when enabled, a display and audio summary, and a shortcut to test your controller. The launcher row is unchanged. - In 2.0 Alpha, Steam Big Picture, Playnite and custom apps can use the experimental Windows Full Screen Experience. Under System → Startup, you can register Console Mode, select it as Home and restore your previous Home. The button shows progress during each operation. diff --git a/CHANGELOG.md b/CHANGELOG.md index 7450ddf..acc7bf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Notas em português do Brasil; a versão em inglês (Estados Unidos) fica em `CH - A alpha 2.0 usa o som de abertura do Console Mode em todos os estilos visuais. -- A 2.0 abre na tela de boas-vindas, com um resumo da sessão e um fundo personalizável. +- A tela de boas-vindas da 2.0 mostra os jogos recentes da Steam quando habilitados, um resumo de tela e áudio e um atalho para testar o controle. A fileira de iniciadores não muda. - Na alpha 2.0, Steam Big Picture, Playnite e apps próprios podem usar a FSE experimental do Windows. Em Sistema → Inicialização, você pode registrar o Console Mode, selecioná-lo como Home e restaurar a Home anterior. A operação em andamento aparece no próprio botão. diff --git a/crates/cm-app/locales/de-DE.json b/crates/cm-app/locales/de-DE.json index ee554e8..e838d54 100644 --- a/crates/cm-app/locales/de-DE.json +++ b/crates/cm-app/locales/de-DE.json @@ -15,10 +15,19 @@ "Registre e selecione o Console Mode como Home em Sistema › Inicialização antes de usar FSE": "Registriere und wähle Console Mode unter System › Start als Startseite, bevor du FSE nutzt", "Abrir pela Home do Windows": "Über die Windows-Startseite öffnen", "Tour do aplicativo": "App-Rundgang", - "Primeiros passos": "Erste Schritte", - "Mais usado": "Am häufigsten genutzt", "Boas-vindas": "Willkommen", - "Seu PC, pronto para jogar.": "Dein PC ist spielbereit.", + "Jogados recentemente": "Zuletzt gespielt", + "Biblioteca Steam": "Steam-Bibliothek", + "Jogos recentes": "Letzte Spiele", + "Nenhum jogo recente para mostrar": "Keine letzten Spiele vorhanden", + "Os jogos da Steam aparecem aqui quando há histórico disponível.": "Hier erscheinen Steam-Spiele, sobald ein Spielverlauf vorliegt.", + "Ative os jogos da Steam em Sistema → Aparência para ver o histórico aqui.": "Aktiviere Steam-Spiele unter System → Darstellung, um deinen Spielverlauf hier zu sehen.", + "Ajustar em Sessão": "Unter Sitzung anpassen", + "Testar controle": "Controller testen", + "Abre o teste de controle do Windows.": "Öffnet den Windows-Controller-Test.", + "Não foi possível abrir o teste de controle do Windows": "Der Windows-Controller-Test konnte nicht geöffnet werden", + "Explorar Boas-vindas": "Willkommen erkunden", + "Jogado {0}": "Zuletzt gespielt: {0}", "Configurar sessão": "Sitzung konfigurieren", "Fundo de boas-vindas": "Willkommenshintergrund", "Animar fundo de boas-vindas": "Willkommenshintergrund animieren", diff --git a/crates/cm-app/locales/en-US.json b/crates/cm-app/locales/en-US.json index 7ec1845..524f311 100644 --- a/crates/cm-app/locales/en-US.json +++ b/crates/cm-app/locales/en-US.json @@ -15,10 +15,19 @@ "Registre e selecione o Console Mode como Home em Sistema › Inicialização antes de usar FSE": "Register and select Console Mode as Home in System › Startup before using FSE", "Abrir pela Home do Windows": "Open from Windows Home", "Tour do aplicativo": "App tour", - "Primeiros passos": "Getting started", - "Mais usado": "Most used", "Boas-vindas": "Welcome", - "Seu PC, pronto para jogar.": "Your PC, ready to play.", + "Jogados recentemente": "Recently played", + "Biblioteca Steam": "Steam library", + "Jogos recentes": "Recent games", + "Nenhum jogo recente para mostrar": "No recent games to show", + "Os jogos da Steam aparecem aqui quando há histórico disponível.": "Steam games appear here when play history is available.", + "Ative os jogos da Steam em Sistema → Aparência para ver o histórico aqui.": "Enable Steam games in System → Appearance to see your play history here.", + "Ajustar em Sessão": "Adjust in Session", + "Testar controle": "Test controller", + "Abre o teste de controle do Windows.": "Opens the Windows controller test.", + "Não foi possível abrir o teste de controle do Windows": "Couldn't open the Windows controller test", + "Explorar Boas-vindas": "Explore Welcome", + "Jogado {0}": "Played {0}", "Configurar sessão": "Configure session", "Fundo de boas-vindas": "Welcome background", "Animar fundo de boas-vindas": "Animate welcome background", diff --git a/crates/cm-app/locales/es-ES.json b/crates/cm-app/locales/es-ES.json index b380d6a..cb8cc69 100644 --- a/crates/cm-app/locales/es-ES.json +++ b/crates/cm-app/locales/es-ES.json @@ -15,10 +15,19 @@ "Registre e selecione o Console Mode como Home em Sistema › Inicialização antes de usar FSE": "Registra y selecciona Console Mode como inicio en Sistema › Inicio antes de usar FSE", "Abrir pela Home do Windows": "Abrir desde el inicio de Windows", "Tour do aplicativo": "Guía de la aplicación", - "Primeiros passos": "Primeros pasos", - "Mais usado": "Más usado", "Boas-vindas": "Bienvenida", - "Seu PC, pronto para jogar.": "Tu PC, listo para jugar.", + "Jogados recentemente": "Jugados recientemente", + "Biblioteca Steam": "Biblioteca de Steam", + "Jogos recentes": "Juegos recientes", + "Nenhum jogo recente para mostrar": "No hay juegos recientes para mostrar", + "Os jogos da Steam aparecem aqui quando há histórico disponível.": "Los juegos de Steam aparecen aquí cuando hay historial disponible.", + "Ative os jogos da Steam em Sistema → Aparência para ver o histórico aqui.": "Activa los juegos de Steam en Sistema → Apariencia para ver el historial aquí.", + "Ajustar em Sessão": "Ajustar en Sesión", + "Testar controle": "Probar mando", + "Abre o teste de controle do Windows.": "Abre la prueba de mandos de Windows.", + "Não foi possível abrir o teste de controle do Windows": "No se pudo abrir la prueba de mandos de Windows", + "Explorar Boas-vindas": "Explorar Bienvenida", + "Jogado {0}": "Jugado {0}", "Configurar sessão": "Configurar sesión", "Fundo de boas-vindas": "Fondo de bienvenida", "Animar fundo de boas-vindas": "Animar fondo de bienvenida", diff --git a/crates/cm-app/locales/fr-FR.json b/crates/cm-app/locales/fr-FR.json index f9d3884..83d0203 100644 --- a/crates/cm-app/locales/fr-FR.json +++ b/crates/cm-app/locales/fr-FR.json @@ -15,10 +15,19 @@ "Registre e selecione o Console Mode como Home em Sistema › Inicialização antes de usar FSE": "Enregistrez et sélectionnez Console Mode comme accueil dans Système › Démarrage avant d’utiliser le mode plein écran", "Abrir pela Home do Windows": "Ouvrir depuis l’accueil Windows", "Tour do aplicativo": "Visite de l’application", - "Primeiros passos": "Premiers pas", - "Mais usado": "Le plus utilisé", "Boas-vindas": "Bienvenue", - "Seu PC, pronto para jogar.": "Votre PC est prêt à jouer.", + "Jogados recentemente": "Joués récemment", + "Biblioteca Steam": "Bibliothèque Steam", + "Jogos recentes": "Jeux récents", + "Nenhum jogo recente para mostrar": "Aucun jeu récent à afficher", + "Os jogos da Steam aparecem aqui quando há histórico disponível.": "Les jeux Steam s’affichent ici quand un historique est disponible.", + "Ative os jogos da Steam em Sistema → Aparência para ver o histórico aqui.": "Activez les jeux Steam dans Système → Apparence pour voir votre historique ici.", + "Ajustar em Sessão": "Modifier dans Session", + "Testar controle": "Tester la manette", + "Abre o teste de controle do Windows.": "Ouvre le test des manettes de Windows.", + "Não foi possível abrir o teste de controle do Windows": "Impossible d’ouvrir le test des manettes de Windows", + "Explorar Boas-vindas": "Explorer l’accueil", + "Jogado {0}": "Joué {0}", "Configurar sessão": "Configurer la session", "Fundo de boas-vindas": "Arrière-plan de bienvenue", "Animar fundo de boas-vindas": "Animer le fond de bienvenue", diff --git a/crates/cm-app/locales/ru-RU.json b/crates/cm-app/locales/ru-RU.json index 5c018fd..b99f3ce 100644 --- a/crates/cm-app/locales/ru-RU.json +++ b/crates/cm-app/locales/ru-RU.json @@ -15,10 +15,19 @@ "Registre e selecione o Console Mode como Home em Sistema › Inicialização antes de usar FSE": "Зарегистрируйте и выберите Console Mode как главный экран в разделе «Система › Запуск» перед использованием FSE", "Abrir pela Home do Windows": "Открывать с главного экрана Windows", "Tour do aplicativo": "Обзор приложения", - "Primeiros passos": "Первые шаги", - "Mais usado": "Чаще всего", "Boas-vindas": "Добро пожаловать", - "Seu PC, pronto para jogar.": "Ваш ПК готов к игре.", + "Jogados recentemente": "Недавно запущенные игры", + "Biblioteca Steam": "Библиотека Steam", + "Jogos recentes": "Недавние игры", + "Nenhum jogo recente para mostrar": "Нет недавних игр для показа", + "Os jogos da Steam aparecem aqui quando há histórico disponível.": "Игры Steam появятся здесь, когда будет доступна история запусков.", + "Ative os jogos da Steam em Sistema → Aparência para ver o histórico aqui.": "Включите отображение игр Steam в разделе «Система → Внешний вид», чтобы увидеть здесь историю запусков.", + "Ajustar em Sessão": "Настроить в разделе «Сеанс»", + "Testar controle": "Проверить геймпад", + "Abre o teste de controle do Windows.": "Открывает средство проверки геймпада в Windows.", + "Não foi possível abrir o teste de controle do Windows": "Не удалось открыть средство проверки геймпада в Windows", + "Explorar Boas-vindas": "Открыть раздел приветствия", + "Jogado {0}": "Последний запуск: {0}", "Configurar sessão": "Настроить сеанс", "Fundo de boas-vindas": "Фон приветствия", "Animar fundo de boas-vindas": "Анимировать фон приветствия", diff --git a/crates/cm-app/src/home.rs b/crates/cm-app/src/home.rs index d3c09db..b154132 100644 --- a/crates/cm-app/src/home.rs +++ b/crates/cm-app/src/home.rs @@ -16,6 +16,7 @@ use gpui::{ use cm_core::config::{Config, Paths}; use crate::{i18n::{n, shown, t, tn}, input::Pad, settings::{self, Category, Nav, Section, Value}, sound::{Sound, Sounds}}; +use crate::welcome::WelcomeTarget; /// What is on screen besides the tabs. #[derive(Clone, Copy, PartialEq)] @@ -148,6 +149,8 @@ pub struct Console { pub(crate) hidden_games: Vec, pub steam_icon: Option>, pub focus: usize, + pub(crate) welcome_target: Option, + pub(crate) welcome_scroll: gpui::ScrollHandle, pub tab: usize, pub controller: Option, /// Batteries of the connected pads and the low-battery warnings already given (battery.rs). @@ -267,6 +270,7 @@ impl Console { Self { custom_editor: None, picking_app: false, running: None, return_to_pc_pending: false, toast: None, window: None, app_in_front: true, hardware, config, paths, items, hidden_games: games, steam_icon, focus: 0, tab: 0, controller: None, batteries: Vec::new(), battery_alarms: HashMap::new(), guide_tour: None, tour_on_open: false, guide_from_tray: false, intro: None, intro_run: 0, wake: Default::default(), report_busy: false, tv_testing: false, helper_rows: Default::default(), shortcut_capture: None, pads: None, pending_whats_new: None, whats_new: None, clock: cm_platform::local_time(), now: unix_now(), + welcome_target: None, welcome_scroll: Default::default(), view: View::Home, session, system, nav: Nav::default(), game_opts, pinned, volume: 60, launch_task: None, guide_row: 0, guide_windows: Vec::new(), live_thumbs: Default::default(), session_vrr: None, session_fps: 0, session_hdr: None, prev_focus: 0, prev_tab: 0, tab_anim: 0, tab_dir: 1., menu_anim: 0, exiting: None, exit_anim: 0, exit_task: None, @@ -290,8 +294,13 @@ impl Console { match p { Pad::LB | Pad::RB => return self.set_tab(if p == Pad::LB { (self.tab + 2) % 3 } else { (self.tab + 1) % 3 }, cx), _ if self.tab != 0 => return self.settings_press(p, cx), + _ if self.items[self.focus].is_welcome() && self.view == View::Home && self.welcome_press(p, cx) => return, Pad::A if self.items[self.focus].is_welcome() => return self.launch_welcome_pick(cx), - Pad::Y if self.items[self.focus].is_welcome() => return self.start_tour(cx), + Pad::Y if self.items[self.focus].is_welcome() => { + self.welcome_target = None; + self.welcome_scroll.scroll_to_item(0); + return self.start_tour(cx); + } Pad::X if self.items[self.focus].is_welcome() => return self.set_tab(1, cx), Pad::Menu | Pad::Y => return self.open_card_menu(cx), Pad::A => return self.start_launch(cx), @@ -337,6 +346,8 @@ impl Console { fn set_focus(&mut self, next: usize, cx: &mut Context) { if next == self.focus || next >= self.items.len() { return; } + self.welcome_target = None; + self.welcome_scroll.scroll_to_item(0); self.backdrop_transition = if motion::reduced() { None } else { @@ -377,7 +388,11 @@ impl Console { /// Mouse: a click focuses a card; the row only moves if that card is cut at an edge. fn click_card(&mut self, i: usize, cx: &mut Context) { if matches!(self.items[i], Item::Add) { self.click_card_focus(i, cx); return self.press(Pad::A, cx); } - if self.focus == i { return self.press(Pad::A, cx); } + if self.focus == i { + self.welcome_target = None; + self.welcome_scroll.scroll_to_item(0); + return self.press(Pad::A, cx); + } self.click_card_focus(i, cx); } @@ -388,7 +403,7 @@ impl Console { self.open_card_menu(cx); } - fn click_card_focus(&mut self, i: usize, cx: &mut Context) { + pub(crate) fn click_card_focus(&mut self, i: usize, cx: &mut Context) { self.set_focus(i, cx); let (l, r) = (self.card_left(i, i) - 24., self.card_left(i, i) + TILE_F + RING + 24.); if l < self.scroll { self.set_scroll(l, cx); } else if r > self.scroll + self.row_view { self.set_scroll(r - self.row_view, cx); } @@ -405,6 +420,8 @@ impl Console { return; } self.dropdown = None; + self.welcome_target = None; + self.welcome_scroll.scroll_to_item(0); // the new tab slides in from the side it sits on (LB/left tabs from the left) self.tab_dir = if tab > self.tab { 1. } else { -1. }; self.prev_tab = self.tab; @@ -733,35 +750,6 @@ impl Console { } } - fn welcome(&self, ui: &Ui, cx: &mut Context) -> Div { - let card = |id: &'static str, pad, icon, action, label: SharedString, cx: &mut Context| { - div().id(id).flex_1().min_w_0().flex().items_center().gap(ui.u(16.)) - .px(ui.u(20.)).py(ui.u(22.)).rounded(ui.u(18.)) - .bg(color::white(0.065)).border(ui.u(1.)).border_color(color::white(0.16)) - .hover(|s| s.bg(color::white(0.13))).cursor_pointer() - .child(div().flex_none().size(ui.u(54.)).rounded(ui.u(14.)).bg(hex(0x72e5b5, 0.14)) - .flex().items_center().justify_center().child(ui.icon(icon, 27., hex(0xa2f5cd, 1.)))) - .child(div().flex_1().min_w_0().flex().flex_col().gap(ui.u(4.)) - .child(div().text_size(ui.u(18.)).text_color(color::mute()).child(action)) - .child(div().text_size(ui.u(26.)).font_weight(FontWeight::SEMIBOLD).truncate().child(label))) - .child(ui.icon(glyph::CHEVRON_RIGHT, 24., color::mute())) - .on_click(cx.listener(move |this, _, _, cx| this.press(pad, cx))) - }; - let mut cards = div().flex().w_full().gap(ui.u(16.)); - if let Some((_, launcher, count)) = self.welcome_pick() { - cards = cards.child(card("welcome-play", Pad::A, glyph::PLAY_ARROW, - if count == 0 { t("Jogar") } else { t("Mais usado") }, launcher.shown_name(), cx)); - } - cards = cards - .child(card("welcome-tour", Pad::Y, glyph::INFO, t("Primeiros passos"), t("Tour do aplicativo").into(), cx)) - .child(card("welcome-session", Pad::X, glyph::TUNE, t("Configurar sessão"), self.setup_text(0, 0).into(), cx)); - div().absolute().left(ui.u(ROW_X)).right(ui.u(96.)).top(ui.u(448.)) - .max_w(ui.u(1480.)).flex().flex_col().items_start().gap(ui.u(24.)) - .child(div().text_size(ui.u(56.)).line_height(ui.u(66.)).font_family(cm_ui::LAUNCHER_TITLE_FONT) - .font_weight(FontWeight::BOLD).child(t("Seu PC, pronto para jogar."))) - .child(cards) - } - fn hero(&self, ui: &Ui, cx: &mut Context) -> Div { let logo_box = div().h(ui.u(170.)).flex().items_end().mb(ui.u(30.)); let word = |text: &str| div().whitespace_nowrap().text_size(ui.u(86.)).font_family(cm_ui::LAUNCHER_TITLE_FONT).font_weight(FontWeight::BOLD).line_height(ui.u(92.)).child(ui.lifted(text.to_string())); @@ -958,10 +946,19 @@ impl Console { (mk(l), mk(r)) } else if self.tab == 0 { if matches!(self.items[self.focus], Item::Welcome) { - (vec![], mk(vec![ + let left = if self.welcome_target.is_some() { + mk(vec![(Pad::B, Glyph::Text("B"), t("Voltar"))]) + } else { + mk(vec![(Pad::Down, Glyph::Text("↓"), t("Explorar Boas-vindas"))]) + }; + let primary = match self.welcome_target { + Some(WelcomeTarget::Session | WelcomeTarget::Controller) => t("Abrir"), + _ => t("Jogar"), + }; + (left, mk(vec![ (Pad::Y, Glyph::Text("Y"), t("Tour do aplicativo")), (Pad::X, Glyph::Text("X"), t("Configurar sessão")), - (Pad::A, Glyph::Text("A"), t("Jogar")), + (Pad::A, Glyph::Text("A"), primary), ])) } else if self.has_card_menu(self.focus) { (vec![(Pad::Menu, ui.hint(Glyph::Icon(glyph::MENU), t("Menu"), None))], diff --git a/crates/cm-app/src/main.rs b/crates/cm-app/src/main.rs index 255fbc6..d0866b1 100644 --- a/crates/cm-app/src/main.rs +++ b/crates/cm-app/src/main.rs @@ -32,6 +32,7 @@ mod tv; mod shell; mod updates; mod wake; +mod welcome; mod video; mod whats_new; diff --git a/crates/cm-app/src/welcome.rs b/crates/cm-app/src/welcome.rs new file mode 100644 index 0000000..899245b --- /dev/null +++ b/crates/cm-app/src/welcome.rs @@ -0,0 +1,408 @@ +use std::path::PathBuf; + +use cm_platform::steam::Game; +use cm_ui::{Ui, color, glyph}; +use gpui::{ + Context, Div, ImageSource, ObjectFit, div, img, linear_color_stop, linear_gradient, prelude::*, +}; + +use crate::{ + home::{Console, Item, ROW_X, ago}, + i18n::{t, tf}, + input::Pad, + sound::Sound, +}; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(crate) enum WelcomeTarget { + Game(usize), + Session, + Controller, +} + +fn recent_games(items: &[Item], enabled: bool) -> Vec<(usize, &Game)> { + if !enabled { + return Vec::new(); + } + let mut games: Vec<_> = items + .iter() + .enumerate() + .filter_map(|(index, item)| match item { + Item::Game(game, _) if game.last_played != 0 => Some((index, game)), + _ => None, + }) + .collect(); + games.sort_by_key(|(_, game)| std::cmp::Reverse(game.last_played)); + let mut seen = std::collections::HashSet::new(); + games.retain(|(_, game)| seen.insert(game.app_id)); + games.truncate(3); + games +} + +fn next_target(current: Option, key: Pad, games: usize) -> Option { + use WelcomeTarget::{Controller, Game, Session}; + match (current, key) { + (None, Pad::Down) => Some(if games == 0 { Session } else { Game(0) }), + (_, Pad::B) | (Some(Game(_)), Pad::Up) => None, + (Some(Game(i)), Pad::Left) => Some(Game(i.saturating_sub(1))), + (Some(Game(i)), Pad::Right) if i + 1 < games => Some(Game(i + 1)), + (Some(Game(i)), Pad::Down) => Some(if i < 2 { Session } else { Controller }), + (Some(Session), Pad::Right) => Some(Controller), + (Some(Controller), Pad::Left) => Some(Session), + (Some(Session), Pad::Up) => (games > 0).then_some(Game(0)), + (Some(Controller), Pad::Up) => games.checked_sub(1).map(Game), + _ => current, + } +} + +impl Console { + pub(crate) fn welcome_press(&mut self, key: Pad, cx: &mut Context) -> bool { + if self.welcome_target.is_none() && key != Pad::Down { + return false; + } + if key == Pad::A { + if let Some(target) = self.welcome_target { + self.open_welcome_target(target, cx); + } + return true; + } + if !matches!(key, Pad::Up | Pad::Down | Pad::Left | Pad::Right | Pad::B) { + return false; + } + let games = recent_games(&self.items, self.config.show_steam_games).len(); + let next = next_target(self.welcome_target, key, games); + if next != self.welcome_target { + self.welcome_target = next; + let section = usize::from(games > 0 && matches!(next, Some(WelcomeTarget::Session | WelcomeTarget::Controller))); + self.welcome_scroll.scroll_to_item(section); + self.sounds.play(if next.is_some() { Sound::Move } else { Sound::Back }); + cx.notify(); + } + true + } + + fn open_welcome_target(&mut self, target: WelcomeTarget, cx: &mut Context) { + match target { + WelcomeTarget::Game(slot) => { + if let Some(&(index, _)) = recent_games(&self.items, self.config.show_steam_games).get(slot) { + self.click_card_focus(index, cx); + self.start_launch(cx); + } + } + WelcomeTarget::Session => self.set_tab(1, cx), + WelcomeTarget::Controller => { + let opened = std::env::var_os("SystemRoot").is_some_and(|root| { + let system = PathBuf::from(root).join("System32"); + std::process::Command::new(system.join("control.exe")) + .arg(system.join("joy.cpl")) + .current_dir(&system) + .spawn() + .is_ok() + }); + if !opened { + self.show_toast(t("Não foi possível abrir o teste de controle do Windows"), cx); + } + } + } + } + + pub(crate) fn welcome(&self, ui: &Ui, cx: &mut Context) -> Div { + let games = recent_games(&self.items, self.config.show_steam_games); + let mut content = div() + .id("welcome-panel") + .absolute() + .left(ui.u(ROW_X)) + .right(ui.u(96.)) + .top(ui.u(442.)) + .bottom(ui.u(116.)) + .overflow_y_scroll() + .track_scroll(&self.welcome_scroll) + .flex() + .flex_col() + .gap(ui.u(36.)) + .pb(ui.u(4.)); + let session = self.welcome_session(ui, cx); + if games.is_empty() { + content = content.child(session).child( + div() + .flex_none() + .flex() + .flex_col() + .gap(ui.u(17.)) + .child(heading(ui, t("Jogos recentes"))) + .child( + panel(ui, false) + .flex() + .items_center() + .gap(ui.u(20.)) + .child(icon_box(ui, glyph::SPORTS_ESPORTS)) + .child( + div() + .min_w_0() + .child(title(ui, t("Nenhum jogo recente para mostrar"))) + .child(detail( + ui, + if self.config.show_steam_games { + t("Os jogos da Steam aparecem aqui quando há histórico disponível.") + } else { + t("Ative os jogos da Steam em Sistema → Aparência para ver o histórico aqui.") + }, + )), + ), + ), + ); + } else { + let height = (ui.design.height - 880.).clamp(162., 264.); + let cards = games.iter().enumerate().map(|(slot, (_, game))| { + let target = WelcomeTarget::Game(slot); + let focused = self.welcome_target == Some(target); + let radius = ui.u(20.); + div() + .id(("welcome-game", slot)) + .relative() + .flex_none() + .min_w_0() + .w(ui.u((ui.design.width - ROW_X - 96. - 48.) / 3.)) + .h(ui.u(height)) + .rounded(radius) + .overflow_hidden() + .bg(color::panel_solid()) + .border(ui.u(if focused { 3. } else { 1. })) + .border_color(if focused { color::focus() } else { color::white(0.19) }) + .hover(|s| s.border_color(color::focus())) + .cursor_pointer() + .children(game.hero.as_ref().map(|art| { + img(ImageSource::from(art.clone())) + .absolute() + .top_0() + .left_0() + .size_full() + .object_fit(ObjectFit::Cover) + .rounded(radius) + })) + .child( + div() + .absolute() + .top_0() + .left_0() + .size_full() + .rounded(radius) + .bg(linear_gradient( + 0., + linear_color_stop(color::shade(0.98), 0.), + linear_color_stop(color::shade(0.), 0.75), + )), + ) + .child( + div() + .absolute() + .left(ui.u(22.)) + .right(ui.u(22.)) + .bottom(ui.u(16.)) + .child(title(ui, game.name.clone())) + .child(detail(ui, tf("Jogado {0}", &[&ago(game.last_played, self.now)]))), + ) + .on_click(cx.listener(move |this, _, _, cx| this.open_welcome_target(target, cx))) + }); + content = content + .child( + div() + .flex_none() + .flex() + .flex_col() + .gap(ui.u(17.)) + .child( + div() + .flex() + .items_center() + .justify_between() + .gap(ui.u(18.)) + .child(heading(ui, t("Jogados recentemente"))) + .child(detail(ui, t("Biblioteca Steam"))), + ) + .child(div().flex().gap(ui.u(24.)).children(cards)), + ) + .child(session); + } + div().absolute().size_full().child(content) + } + + fn welcome_session(&self, ui: &Ui, cx: &mut Context) -> Div { + let session_focus = self.welcome_target == Some(WelcomeTarget::Session); + let pad_focus = self.welcome_target == Some(WelcomeTarget::Controller); + let value = |name, value, icon| { + div() + .flex_1() + .min_w_0() + .flex() + .items_center() + .gap(ui.u(18.)) + .child(icon_box(ui, icon)) + .child(div().min_w_0().child(detail(ui, name)).child(title(ui, value))) + }; + div() + .flex_none() + .flex() + .items_start() + .gap(ui.u(32.)) + .child( + div() + .id("welcome-session") + .flex_1() + .min_w_0() + .flex() + .flex_col() + .gap(ui.u(17.)) + .cursor_pointer() + .on_click(cx.listener(|this, _, _, cx| this.open_welcome_target(WelcomeTarget::Session, cx))) + .child( + div() + .flex() + .items_center() + .justify_between() + .gap(ui.u(12.)) + .child(heading(ui, t("Sua sessão"))) + .child( + div() + .flex() + .items_center() + .gap(ui.u(5.)) + .text_size(ui.u(23.)) + .text_color(color::accent()) + .child(t("Ajustar em Sessão")) + .child(ui.icon(glyph::CHEVRON_RIGHT, 19., color::accent())), + ), + ) + .child( + panel(ui, session_focus) + .flex() + .items_center() + .gap(ui.u(24.)) + .child(value(t("Tela de jogo"), self.setup_text(0, 0), glyph::TV)) + .child(div().flex_none().w(ui.u(1.)).h(ui.u(68.)).bg(color::white(0.19))) + .child(value(t("Saída de áudio"), self.setup_text(2, 0), glyph::VOLUME_UP)), + ), + ) + .child( + div() + .id("welcome-controller") + .w(ui.u(556.)) + .flex_none() + .flex() + .flex_col() + .gap(ui.u(17.)) + .cursor_pointer() + .on_click(cx.listener(|this, _, _, cx| this.open_welcome_target(WelcomeTarget::Controller, cx))) + .child(heading(ui, t("Controle"))) + .child( + panel(ui, pad_focus) + .flex() + .items_center() + .gap(ui.u(18.)) + .child(icon_box(ui, glyph::SPORTS_ESPORTS)) + .child( + div() + .flex_1() + .min_w_0() + .child(title(ui, t("Testar controle"))) + .child(detail(ui, t("Abre o teste de controle do Windows."))), + ) + .child(ui.icon(glyph::CHEVRON_RIGHT, 22., color::accent())), + ), + ) + } +} + +fn panel(ui: &Ui, focused: bool) -> Div { + div() + .min_h(ui.u(132.)) + .px(ui.u(24.)) + .py(ui.u(22.)) + .rounded(ui.u(18.)) + .bg(color::white(if focused { 0.12 } else { 0.065 })) + .border(ui.u(if focused { 3. } else { 1. })) + .border_color(if focused { color::focus() } else { color::white(0.16) }) +} + +fn icon_box(ui: &Ui, icon: char) -> Div { + div() + .flex_none() + .size(ui.u(62.)) + .rounded(ui.u(14.)) + .bg(color::accent_alpha(0.16)) + .flex() + .items_center() + .justify_center() + .child(ui.icon(icon, 30., color::accent())) +} + +fn heading(ui: &Ui, text: &str) -> Div { + div() + .font_family(cm_ui::LAUNCHER_TITLE_FONT) + .font_weight(gpui::FontWeight::BOLD) + .text_size(ui.u(39.)) + .line_height(ui.u(47.)) + .child(text.to_string()) +} + +fn title(ui: &Ui, text: impl Into) -> Div { + div() + .font_weight(gpui::FontWeight::SEMIBOLD) + .text_size(ui.u(32.)) + .line_height(ui.u(37.)) + .truncate() + .child(text.into()) +} + +fn detail(ui: &Ui, text: impl Into) -> Div { + div() + .text_size(ui.u(24.)) + .line_height(ui.u(29.)) + .text_color(color::mute()) + .child(text.into()) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn game(app_id: u32, last_played: u64) -> Item { + Item::Game(Game { + app_id, last_played, name: format!("Game {app_id}"), + hero: None, hero_blur: None, logo: None, cover: None, + }, None) + } + + #[test] + fn recent_games_respect_the_preference_and_do_not_follow_custom_row_order() { + let items = [Item::Welcome, game(1, 52), game(2, 0), game(3, 50), game(1, 55), game(4, 60), game(5, 10)]; + assert!(recent_games(&items, false).is_empty()); + let recent = recent_games(&items, true); + assert_eq!(recent.iter().map(|(index, _)| *index).collect::>(), [5, 4, 3]); + assert!(recent_games(&items[..1], true).is_empty()); + assert!(recent_games(&[game(2, 0)], true).is_empty()); + } + + #[test] + fn welcome_navigation_enters_and_leaves_without_changing_launcher_selection() { + use WelcomeTarget::{Controller, Game, Session}; + assert_eq!(next_target(None, Pad::Right, 3), None); + assert_eq!(next_target(None, Pad::Down, 3), Some(Game(0))); + assert_eq!(next_target(Some(Game(0)), Pad::Up, 3), None); + assert_eq!(next_target(Some(Game(2)), Pad::Right, 3), Some(Game(2))); + assert_eq!(next_target(Some(Game(2)), Pad::Down, 3), Some(Controller)); + assert_eq!(next_target(Some(Controller), Pad::Up, 3), Some(Game(2))); + assert_eq!(next_target(None, Pad::Down, 0), Some(Session)); + assert_eq!(next_target(Some(Session), Pad::Right, 0), Some(Controller)); + assert_eq!(next_target(Some(Controller), Pad::Up, 0), None); + assert_eq!(next_target(Some(Session), Pad::B, 3), None); + } + + #[test] + fn down_from_the_second_game_reaches_session_with_two_visible_games() { + assert_eq!( + next_target(Some(WelcomeTarget::Game(1)), Pad::Down, 2), + Some(WelcomeTarget::Session) + ); + } +}