Profiles: the Profiles page, a game's profile and screen pickers, editing a shared profile, and the change-the-profile-or-make-individual prompt
A fifth view lists Default, Built-in, My profiles and Individual games; each shared profile shows its games with Remove and what it comes to on each screen, with suggestions. The settings pane edits a shared profile too and gets a Screen section (frame rate native or pinned). Changing an engine setting on a game that uses a shared profile asks first.
This commit is contained in:
1 parent
ebdc989bf0
commit
1aac9d1203
12 files changed
+1604
-46
No files matched your search
@@ -77,6 +77,29 @@ pub fn slugify(name: &str) -> String {
|
||||
s.trim_end_matches('-').to_string()
|
||||
}
|
||||
|
||||
/// Profile files lying in `dirs` (not below them): every `.toml` that reads as a profile and has a `name`, with that
|
||||
/// name. What "Import" offers without a file dialog.
|
||||
pub fn importable(dirs: &[PathBuf]) -> Vec<(PathBuf, String)> {
|
||||
let mut v: Vec<(PathBuf, String)> = vec![];
|
||||
for d in dirs {
|
||||
for e in std::fs::read_dir(d).into_iter().flatten().flatten().take(2000) {
|
||||
let p = e.path();
|
||||
if p.extension().and_then(|x| x.to_str()) != Some("toml") || std::fs::metadata(&p).map(|m| m.len() > 1 << 20).unwrap_or(true) { continue; }
|
||||
let Ok(text) = std::fs::read_to_string(&p) else { continue };
|
||||
let Ok(l) = profile::parse_layer(&text) else { continue };
|
||||
if l.version.is_some_and(|x| x > LAYER_VERSION) { continue; }
|
||||
if let Some(name) = l.name.filter(|n| !n.trim().is_empty()) { if !v.iter().any(|(q, _)| *q == p) { v.push((p, name)); } }
|
||||
}
|
||||
}
|
||||
v.sort();
|
||||
v
|
||||
}
|
||||
|
||||
/// Where exported profiles are looked for: Documents, Downloads and the home folder.
|
||||
pub fn exchange_dirs() -> Vec<PathBuf> {
|
||||
[dirs::document_dir(), dirs::download_dir(), dirs::home_dir()].into_iter().flatten().filter(|d| d.is_dir()).collect()
|
||||
}
|
||||
|
||||
/// A built-in profile's settings: the preset's values, as a layer.
|
||||
pub fn builtin_layer(p: &crate::presets::Preset) -> Layer {
|
||||
let mut l = Layer::default();
|
||||
@@ -432,6 +455,14 @@ impl Store {
|
||||
self.create(&name, &l)
|
||||
}
|
||||
|
||||
/// Where an exported profile is put when no place is given: the user's Documents folder (their home without one).
|
||||
pub fn export_path(&self, r: &Ref) -> Result<PathBuf> {
|
||||
let s = self.get(r)?;
|
||||
let dir = dirs::document_dir().filter(|d| d.is_dir()).or_else(dirs::home_dir).context("no home folder")?;
|
||||
let base = match r { Ref::User(slug) => slug.clone(), _ => slugify(&s.name) };
|
||||
Ok(dir.join(format!("summit-profile-{base}.toml")))
|
||||
}
|
||||
|
||||
/// Bring the files of an older Summit up to this one, once (`profiles.toml` says it was done). Before anything is
|
||||
/// written, `profiles/` is copied to `backups/profiles-v2-<time>/`. A game's file that sets engine or picture
|
||||
/// settings becomes an Individual game with exactly those settings; every other file keeps its content and only
|
||||
@@ -685,6 +716,10 @@ mod tests {
|
||||
std::fs::write(&f, "version = 3\nname = \"Odd\"\nmonitor = \"DP-9\"\nupscaler = \"fsr\"\n").unwrap();
|
||||
let odd = other.get(&other.import(&f).unwrap()).unwrap();
|
||||
assert!(odd.layer.monitor.is_none() && odd.layer.upscaler.as_deref() == Some("fsr"));
|
||||
// what Import offers: the profile files in a folder, by name (the odd one too; not the broken one below)
|
||||
s.export(&r, &f).unwrap();
|
||||
std::fs::write(s.root.join("out/notes.toml"), "title = \"not a profile\"\n").unwrap();
|
||||
assert_eq!(importable(&[s.root.join("out")]), vec![(f.clone(), "Couch".to_string())]);
|
||||
std::fs::write(&f, "this is not toml [").unwrap();
|
||||
assert!(other.import(&f).is_err());
|
||||
std::fs::write(&f, "version = 99\nname = \"Future\"\n").unwrap();
|
||||
|
||||
@@ -4,6 +4,7 @@ mod art;
|
||||
mod data;
|
||||
mod pad;
|
||||
mod pane;
|
||||
mod profiles;
|
||||
mod rows;
|
||||
mod shot;
|
||||
|
||||
@@ -73,6 +74,11 @@ pub struct App {
|
||||
pick: RefCell<Vec<winmode::OpenWindow>>,
|
||||
pick_listed: Cell<Option<Instant>>,
|
||||
pick_seq: Cell<u64>,
|
||||
/// The Profiles page as last built, and the answers its two dialogs wait for (profiles.rs).
|
||||
page: RefCell<profiles::Page>,
|
||||
dialogs: RefCell<profiles::Dialogs>,
|
||||
/// The screens of this PC, listed once (None: not listed yet, or to be listed again).
|
||||
screens: RefCell<Option<Result<Vec<display::Output>, String>>>,
|
||||
}
|
||||
|
||||
/// Enhance on a game started with Play: how far the engine has got with the game's window (from `summit run`'s log),
|
||||
@@ -306,6 +312,9 @@ impl App {
|
||||
let reasons: Vec<SharedString> = e.reasons.iter().map(|r| short(r).into()).collect();
|
||||
let prof = profile::load(&e.id).unwrap_or_default();
|
||||
let (has_account, account, account_note) = self.account_card(&e, &st);
|
||||
let cards = self.game_cards(&e.id);
|
||||
let on = summit_core::profiles::Store::user().map(|s| s.assignment(&e.id)).unwrap_or(summit_core::profiles::Ref::Default);
|
||||
let own_n = if on == summit_core::profiles::Ref::Individual { own_n } else { profile::KEYS.iter().filter(|k| !profile::is_shared(k) && own.has(k)).count() };
|
||||
self.ui.global::<Lib>().set_detail(Detail {
|
||||
idx, sessions: sessions.into(), sessions_note: note.into(), reasons: ModelRc::new(VecModel::from(reasons)),
|
||||
path: short(&con.as_ref().map(|c| match &c.link {
|
||||
@@ -314,11 +323,17 @@ impl App {
|
||||
console::Link::Capture { device } => format!("capture device · {device}"),
|
||||
}).or(e.path.clone()).unwrap_or_default()).into(),
|
||||
monitor: p.monitor.into(), mode: p.mode.into(), upscaler: engine_lines.0.into(), framegen: engine_lines.1.into(), window: p.window.into(), profile_set: p.set,
|
||||
profile_note: if own_n == 0 { "Follows the global settings (Settings).".into() } else { format!("{own_n} setting{} of its own; the rest follow the global settings (Settings).", if own_n == 1 { "" } else { "s" }).into() },
|
||||
profile_note: match (&on, own_n) {
|
||||
(summit_core::profiles::Ref::Individual, 0) => "Individual: follows the global settings (Settings) until it sets its own.".into(),
|
||||
(summit_core::profiles::Ref::Individual, n) => format!("Individual: {n} setting{} of its own; the rest follow the global settings (Settings).", if n == 1 { "" } else { "s" }).into(),
|
||||
(_, 0) => format!("Engine settings from the profile {}.", cards.0).into(),
|
||||
(_, n) => format!("Engine settings from the profile {}; {n} launch setting{} of its own.", cards.0, if n == 1 { "" } else { "s" }).into(),
|
||||
},
|
||||
play_label: label.into(), play_note: play_note.into(), can_play: can,
|
||||
enhance: prof.enhance && can_enhance, can_enhance, enhance_note: enhance_note.into(),
|
||||
has_account, account, account_note: account_note.into(),
|
||||
compare_note: self.compare_state(&e, can_enhance).1.into(),
|
||||
prof_name: cards.0.into(), prof_line: cards.1.into(), screen_name: cards.2.into(), screen_line: cards.3.into(),
|
||||
});
|
||||
drop(st);
|
||||
self.want_cover(idx as usize);
|
||||
@@ -1188,6 +1203,10 @@ pub fn build(headless: bool) -> Rc<App> {
|
||||
let st = state::load();
|
||||
state::apply(&mut entries, &st);
|
||||
|
||||
// Profile files of an older Summit are brought up to this one once, after a backup (the toast below says so).
|
||||
let known: Vec<String> = entries.iter().map(|e| e.id.clone()).collect();
|
||||
let migrated = summit_core::profiles::Store::user().and_then(|s| s.migrate(&known));
|
||||
|
||||
let ui = MainWindow::new().expect("could not create the window");
|
||||
let theme_keys: Vec<String> = ui.get_palettes().iter().map(|p| p.key.to_string()).collect();
|
||||
let loader = if headless { art::Loader::queued() } else {
|
||||
@@ -1205,6 +1224,7 @@ pub fn build(headless: bool) -> Rc<App> {
|
||||
steam_accounts: Default::default(),
|
||||
playing: Default::default(), play_seq: Cell::new(0), play_timer: slint::Timer::default(),
|
||||
pick: Default::default(), pick_listed: Cell::new(None), pick_seq: Cell::new(0),
|
||||
page: Default::default(), dialogs: Default::default(), screens: Default::default(),
|
||||
});
|
||||
APP.with(|a| *a.borrow_mut() = Some(app.clone()));
|
||||
|
||||
@@ -1243,6 +1263,14 @@ pub fn build(headless: bool) -> Rc<App> {
|
||||
lib.on_open_compare(|i| with_app(|a| a.open_compare(i)));
|
||||
lib.on_compare_start(|i| with_app(|a| a.compare_start(i)));
|
||||
pane::wire(&app);
|
||||
profiles::wire(&app);
|
||||
match &migrated {
|
||||
Ok(Some(m)) if m.backup.is_some() => app.toast(format!("Profiles were updated for shared profiles{}. The files as they were are in {}",
|
||||
match m.individual.len() { 0 => String::new(), 1 => ": 1 game with its own settings is now an Individual game".into(), n => format!(": {n} games with their own settings are now Individual games") },
|
||||
m.backup.as_deref().map(tilde).unwrap_or_default())),
|
||||
Err(e) => app.toast(format!("The profile files could not be updated ({e:#}); they are used as they are")),
|
||||
_ => {}
|
||||
}
|
||||
lib.on_play_back(|| with_app(|a| a.play_back()));
|
||||
lib.on_play_stop(|| with_app(|a| a.play_stop()));
|
||||
lib.on_pick_show(|| with_app(|a| a.pick_show()));
|
||||
@@ -1264,7 +1292,9 @@ pub fn build(headless: bool) -> Rc<App> {
|
||||
app.rebuild_shelves();
|
||||
app.requery();
|
||||
app.nvidia_refresh();
|
||||
if let Some(v) = env("SUMMIT_VIEW").or_else(|| env("SUMMIT_TAB")).and_then(|v| pick(&v, &names(&["home", "library", "unfiltered", "settings"]))) { app.ui.invoke_goto(v.clamp(0, 3)); }
|
||||
if let Some(v) = env("SUMMIT_VIEW").or_else(|| env("SUMMIT_TAB")).and_then(|v| pick(&v, &names(&["home", "library", "unfiltered", "settings", "profiles"]))) { app.ui.invoke_goto(v.clamp(0, 4)); }
|
||||
// SUMMIT_PROFILE, SUMMIT_PZONE, SUMMIT_PITEM: where the Profiles page is (profiles.rs)
|
||||
app.profiles_overrides(&env);
|
||||
if let Some(v) = env("SUMMIT_FOCUS").and_then(|v| v.parse::<i32>().ok()) { app.ui.set_lib_focus(v); app.ui.set_unf_focus(v); }
|
||||
if let Some(want) = env("SUMMIT_DETAIL") {
|
||||
let w = want.to_lowercase();
|
||||
|
||||
+231
-28
@@ -6,16 +6,30 @@
|
||||
//! launch profiles (and a game's own) ~/.config/summit/profiles/<id>.toml
|
||||
//! the engine's global settings the engine's settings.json (the registry says where)
|
||||
use crate::rows::{self, Kind, Row, Section};
|
||||
use crate::{data, short, tilde, with_app, App, CmpRow, Lib, SNav, SPreset, SRow, SessField, SessRow, StatTile, Sx};
|
||||
use crate::{data, profiles, short, tilde, with_app, App, CmpRow, Lib, SNav, SPreset, SRow, SessField, SessRow, StatTile, Sx};
|
||||
use serde_json::Value;
|
||||
use slint::{ComponentHandle, Model, ModelRc, SharedString, VecModel};
|
||||
use std::collections::BTreeMap;
|
||||
use summit_core::model::{Entry, Source};
|
||||
use summit_core::registry::{self, Registry};
|
||||
use summit_core::{console, display, launch, presets, profile, sessions, ui as prefs};
|
||||
use summit_core::profiles::Ref;
|
||||
use summit_core::{console, display, launch, presets, profile, resolve, sessions, ui as prefs};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum Scope { #[default] Settings, Game(usize) }
|
||||
/// Whose settings the pane shows: the Settings page (the global settings, which are the Default profile), a game,
|
||||
/// or one of the user's shared profiles.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub enum Scope { #[default] Settings, Game(usize), Shared(Ref) }
|
||||
|
||||
/// Where a change is written.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
enum Owner { Global, Game(String), Profile(Ref) }
|
||||
|
||||
/// A change to an engine or picture setting: engine settings by key (None: stop setting it), or who decides the
|
||||
/// frame multiplier (None: not said here; "native"; "": pinned, the Frame multiplier setting).
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
enum Change { Engine(Vec<(String, Option<Value>)>), Rate(Option<String>) }
|
||||
|
||||
const NATIVE_LOCK: &str = "Decided by Frame rate: Native (the Screen section): the multiplier is worked out from the screen when a game starts.";
|
||||
|
||||
/// What the pane is showing: whose settings, its sections as last built, and what each row on screen is.
|
||||
#[derive(Default)]
|
||||
@@ -102,23 +116,112 @@ impl App {
|
||||
let defaults = profile::load_defaults().unwrap_or_default();
|
||||
let mut base = registry::forced(&defaults);
|
||||
let mut locked = BTreeMap::new();
|
||||
if game.is_none() && defaults.native_rate() { locked.insert("hz".to_string(), NATIVE_LOCK.to_string()); }
|
||||
// Fullscreen is the launch profile's Window mode once that is chosen: one place decides it.
|
||||
if base.remove("fullscreen").is_some() && game.is_none() {
|
||||
locked.insert("fullscreen".to_string(), format!("Decided by Window mode in Game defaults ({}).", data::window_mode_label(&defaults.window_mode)));
|
||||
}
|
||||
let own = game.map(|e| {
|
||||
let layer = profile::load_layer(&e.id).unwrap_or_default();
|
||||
// An Individual game's own settings; for a game on a shared profile, the profile's (Default has none of
|
||||
// its own: its values are the global ones).
|
||||
let layer = match self.store().map(|s| (s.assignment(&e.id), s)) {
|
||||
Some((Ref::Individual, _)) | None => profile::load_layer(&e.id).unwrap_or_default(),
|
||||
Some((Ref::Default, _)) => profile::Layer::default(),
|
||||
Some((r, s)) => s.get(&r).map(|p| p.layer).unwrap_or_default(),
|
||||
};
|
||||
let mut m = registry::forced(&profile::resolve(&[&layer]));
|
||||
m.remove("fullscreen");
|
||||
let p = profile::load(&e.id).unwrap_or_default();
|
||||
if p.native_rate() { locked.insert("hz".to_string(), NATIVE_LOCK.to_string()); }
|
||||
if !p.window_mode.is_empty() { locked.insert("fullscreen".to_string(), format!("Decided by this game's Window mode in Launch ({}).", data::window_mode_label(&p.window_mode))); }
|
||||
(m, source_kind(self, e).to_string())
|
||||
});
|
||||
Ok(Engine { reg, saved, base, own, locked })
|
||||
}
|
||||
|
||||
/// The same for one of the user's shared profiles: its own settings over the global ones.
|
||||
fn engine_shared(&self, r: &Ref) -> Result<Engine, String> {
|
||||
let mut en = self.engine(None)?;
|
||||
en.locked.clear();
|
||||
en.locked.insert("fullscreen".to_string(), "Decided by each game's own Window mode (its Launch settings).".to_string());
|
||||
let store = self.store().ok_or("no config folder")?;
|
||||
let layer = store.get(r).map_err(|e| format!("{e:#}"))?.layer;
|
||||
let mut m = registry::forced(&profile::resolve(&[&layer]));
|
||||
m.remove("fullscreen");
|
||||
if store.effective(&r.text()).is_ok_and(|p| p.native_rate()) { en.locked.insert("hz".to_string(), NATIVE_LOCK.to_string()); }
|
||||
en.own = Some((m, "window".to_string()));
|
||||
Ok(en)
|
||||
}
|
||||
|
||||
fn pane_scope(&self) -> Scope { self.pane.borrow().scope.clone() }
|
||||
|
||||
/// The engine rows' data for whatever the pane shows.
|
||||
fn pane_engine(&self) -> Result<Engine, String> {
|
||||
match self.pane_scope() { Scope::Shared(r) => self.engine_shared(&r), _ => self.engine(self.pane_entry().as_ref()) }
|
||||
}
|
||||
|
||||
fn pane_entry(&self) -> Option<Entry> {
|
||||
match self.pane.borrow().scope { Scope::Game(i) => self.entries.borrow().get(i).cloned(), Scope::Settings => None }
|
||||
match self.pane.borrow().scope { Scope::Game(i) => self.entries.borrow().get(i).cloned(), _ => None }
|
||||
}
|
||||
|
||||
/// The Screen section: who decides the frame multiplier (native, or pinned), and what the settings come to on
|
||||
/// this game's screen (a game) or on each screen that is on (the Settings page, a shared profile).
|
||||
fn screen_section(&self) -> Section {
|
||||
let scope = self.pane_scope();
|
||||
let store = self.store();
|
||||
let game = self.pane_entry();
|
||||
// the layer the row changes, and the profile the settings come to
|
||||
let (own, p): (Option<String>, profile::Profile) = match (&scope, &game, &store) {
|
||||
(Scope::Game(_), Some(e), Some(s)) => (match s.assignment(&e.id) {
|
||||
Ref::Individual => s.layer(&e.id).ok().and_then(|l| l.rate),
|
||||
Ref::Default => None,
|
||||
r => s.get(&r).ok().and_then(|p| p.layer.rate),
|
||||
}, s.effective(&e.id).unwrap_or_default()),
|
||||
(Scope::Shared(r), _, Some(s)) => (s.get(r).ok().and_then(|p| p.layer.rate), s.effective(&r.text()).unwrap_or_default()),
|
||||
_ => (profile::load_layer(profile::DEFAULT_ID).ok().and_then(|l| l.rate), profile::load_defaults().unwrap_or_default()),
|
||||
};
|
||||
let layered = scope != Scope::Settings;
|
||||
let global_native = profile::load_defaults().is_ok_and(|d| d.native_rate());
|
||||
let word = |native: bool| if native { "Native" } else { "Pinned" };
|
||||
let (pinned, native) = ("The Frame multiplier setting (Frame generation) is used on every screen.", "Worked out when a game starts, from the screen it runs on: as many whole multiples of the game's frame rate as the screen shows. A 30 fps game gets 2x on a 60 Hz screen and 4x on a 144 Hz one.");
|
||||
let mut options = vec!["Pinned".to_string(), "Native".to_string()];
|
||||
let mut hints = vec![pinned.to_string(), native.to_string()];
|
||||
let mine = own.as_deref() == Some(profile::NATIVE);
|
||||
let mut value = usize::from(mine);
|
||||
if layered {
|
||||
options.insert(0, "Global".to_string());
|
||||
hints.insert(0, format!("Follows the global setting (Settings): {} now.", word(global_native)));
|
||||
value = match own.as_deref() { None => 0, Some(profile::NATIVE) => 2, Some(_) => 1 };
|
||||
}
|
||||
let mut rows = vec![Row {
|
||||
kind: Kind::Choice, key: "prof:rate".into(), label: "Frame rate".into(), seg: true, options, hints, value,
|
||||
help: "Who decides the frame multiplier. Native follows the screen, so one profile fits a 144 Hz monitor and a 60 Hz projector. Pinned uses the Frame multiplier setting whatever the screen. The output size has the same choice in Upscaling: Output resolution \"Screen\" is native, a size is pinned.".into(),
|
||||
changed: if layered { own.is_some() } else { mine },
|
||||
base: if layered { format!("Global: {}", word(global_native)) } else { "Default: Pinned".into() }, ..Default::default()
|
||||
}];
|
||||
let saved = self.saved_values();
|
||||
match (self.outputs(), &game) {
|
||||
(Ok(outs), Some(_)) => {
|
||||
rows.push(rows::heading("On this game's screen"));
|
||||
let (res, unknown) = resolve::for_game(&p, &saved, &outs, &resolve::SourceFacts::default());
|
||||
if let Some(why) = unknown { rows.push(rows::note(format!("The screen is not known: {why}. Pick one in Launch (Monitor) and the frame multiplier follows it."))); }
|
||||
rows.push(rows::note(res.line()));
|
||||
rows.extend(res.why.iter().map(|w| rows::note(w.clone())));
|
||||
rows.extend(res.suggestions.iter().map(|s| rows::note(format!("Suggestion: {}", s.line()))));
|
||||
}
|
||||
(Ok(outs), None) => {
|
||||
rows.push(rows::heading("On each screen"));
|
||||
let all = resolve::per_screen(&p, &saved, &outs);
|
||||
if all.is_empty() { rows.push(rows::note("No screen is on.")); }
|
||||
for res in all {
|
||||
rows.push(rows::note(res.line()));
|
||||
rows.extend(res.why.iter().map(|w| rows::note(w.clone())));
|
||||
rows.extend(res.suggestions.iter().map(|s| rows::note(format!("Suggestion: {}", s.line()))));
|
||||
}
|
||||
}
|
||||
(Err(e), _) => rows.push(rows::note(format!("The screens can't be listed here ({e}), so nothing is worked out on this page. A game still gets its frame multiplier from its screen when it starts."))),
|
||||
}
|
||||
Section { title: "Screen".into(), rows }
|
||||
}
|
||||
/// The profile the pane's launch rows edit.
|
||||
fn pane_profile_id(&self) -> String { self.pane_entry().map(|e| e.id).unwrap_or_else(|| profile::DEFAULT_ID.to_string()) }
|
||||
@@ -130,7 +233,7 @@ impl App {
|
||||
let own = profile::load_layer(&id).unwrap_or_else(|e| { self.toast(format!("Could not read the profile: {e}")); profile::Layer::default() });
|
||||
let base = if game.is_none() { profile::Profile::default() } else { profile::load_defaults().unwrap_or_default() };
|
||||
let (s, d) = (display::detect_session(), display::detect_desktop());
|
||||
if self.pane.borrow().outs.is_none() { self.pane.borrow_mut().outs = Some(display::outputs(s, d)); }
|
||||
if self.pane.borrow().outs.is_none() { let o = self.outputs(); self.pane.borrow_mut().outs = Some(o); }
|
||||
let pane = self.pane.borrow();
|
||||
let (list, err) = match pane.outs.as_ref() { Some(Ok(o)) => (o.as_slice(), None), Some(Err(e)) => (&[][..], Some(e.as_str())), None => (&[][..], None) };
|
||||
let tool = match (s, d) { (display::Session::X11, _) => "xrandr", (_, display::Desktop::Kde) => "kscreen-doctor", (_, display::Desktop::Wlroots) => "wlr-randr", _ => "" };
|
||||
@@ -157,10 +260,26 @@ impl App {
|
||||
/// Build the pane from the files and put it on screen, keeping the section and the focused row where they are.
|
||||
pub fn fill_pane(&self) {
|
||||
let game = self.pane_entry();
|
||||
let scope = self.pane_scope();
|
||||
let shared = match &scope { Scope::Shared(r) => Some(r.clone()), _ => None };
|
||||
// the profile the pane's game is on, and its name and how many games use it
|
||||
let on = game.as_ref().and_then(|e| self.store().map(|s| s.assignment(&e.id)));
|
||||
let on_name = on.as_ref().map(|r| if *r == Ref::Individual { "Individual".to_string() } else { self.store().and_then(|s| s.get(r).ok()).map(|s| s.name).unwrap_or_default() }).unwrap_or_default();
|
||||
let known: Vec<String> = self.game_ids();
|
||||
let sx = self.ui.global::<Sx>();
|
||||
let mut sections: Vec<Section> = vec![];
|
||||
if game.is_none() { sections.push(rows::launcher_section(&self.settings.borrow(), &self.launcher_info())); }
|
||||
if scope == Scope::Settings { sections.push(rows::launcher_section(&self.settings.borrow(), &self.launcher_info())); }
|
||||
let mut launch = rows::launch_section(if game.is_some() { "Launch" } else { "Game defaults" }, self.with_edit(data::edit_rows), game.is_none());
|
||||
if let Some(r) = &on {
|
||||
launch.rows.insert(0, Row {
|
||||
kind: Kind::Action, key: "act:profile".into(), label: format!("Profile: {on_name}"), button: "Change".into(),
|
||||
help: match r {
|
||||
Ref::Individual => "This game has its own engine settings: the sections below change only this game. Pick a profile to share settings with other games.".into(),
|
||||
r => format!("The engine settings in the sections below are {on_name}'s{}. Changing one asks whether to change the profile or to make this game individual.",
|
||||
match self.store().map(|s| s.games_of(r, &known).len().saturating_sub(1)).unwrap_or(0) { 0 => String::new(), 1 => ", shared with 1 other game".into(), n => format!(", shared with {n} other games") }),
|
||||
}, ..Default::default()
|
||||
});
|
||||
}
|
||||
let own_all = profile::load_layer(&self.pane_profile_id()).map(|l| !l.is_empty()).unwrap_or(false);
|
||||
launch.rows.push(Row {
|
||||
kind: Kind::Action, key: "act:reset-all".into(), off: !own_all, locked: !own_all, button: if game.is_some() { "Use global".into() } else { "Reset".into() },
|
||||
@@ -172,8 +291,9 @@ impl App {
|
||||
(false, true) => "Forget every game default above (and engine settings an older Summit stored with them).".into(),
|
||||
}, ..Default::default()
|
||||
});
|
||||
sections.push(launch);
|
||||
let engine = self.engine(game.as_ref());
|
||||
if shared.is_none() { sections.push(launch); }
|
||||
sections.push(self.screen_section());
|
||||
let engine = self.pane_engine();
|
||||
let (mut quick, mut preset_views, mut state) = (vec![], vec![], String::new());
|
||||
match &engine {
|
||||
Ok(en) => {
|
||||
@@ -185,15 +305,24 @@ impl App {
|
||||
Err(e) => sections.push(Section { title: "Engine".into(), rows: vec![rows::note(format!("The engine's settings can't be shown: {e}"))] }),
|
||||
}
|
||||
sx.set_engine_note(engine.as_ref().err().cloned().unwrap_or_default().into());
|
||||
sx.set_game(game.is_some());
|
||||
sx.set_title(match &game { Some(e) => format!("Profile · {}", e.title), None => "Settings".into() }.into());
|
||||
sx.set_subtitle(match &game {
|
||||
Some(e) => {
|
||||
sx.set_game(scope != Scope::Settings);
|
||||
let shared_name = shared.as_ref().and_then(|r| self.store().and_then(|s| s.get(r).ok())).map(|s| s.name).unwrap_or_default();
|
||||
sx.set_own_tag(match (&shared, &on) { (Some(_), _) => "THE PROFILE'S OWN", (_, Some(r)) if *r != Ref::Individual => "FROM THE PROFILE", _ => "THIS GAME'S OWN" }.into());
|
||||
sx.set_title(match (&game, &shared) { (Some(e), _) => format!("Profile · {}", e.title), (_, Some(_)) => format!("Profile · {shared_name}"), _ => "Settings".into() }.into());
|
||||
sx.set_subtitle(match (&game, &shared) {
|
||||
(Some(e), _) if on.as_ref().is_some_and(|r| *r != Ref::Individual) => format!("Uses the profile {on_name}: engine settings are the profile's · its own launch settings are saved to {}", profile::file(&e.id).map(|f| tilde(&f)).unwrap_or_default()),
|
||||
(Some(e), _) => {
|
||||
let n: usize = sections.iter().map(|s| s.changed()).sum();
|
||||
format!("{} · saved to {}", if n == 0 { "Everything follows the global settings".to_string() } else { format!("{n} setting{} of its own (dotted); the rest follow Settings", if n == 1 { "" } else { "s" }) },
|
||||
format!("Individual · {} · saved to {}", if n == 0 { "everything follows the global settings".to_string() } else { format!("{n} setting{} of its own (dotted); the rest follow Settings", if n == 1 { "" } else { "s" }) },
|
||||
profile::file(&e.id).map(|f| tilde(&f)).unwrap_or_default())
|
||||
}
|
||||
None => "For every game, unless a game's profile sets its own. Saved as you change them.".to_string(),
|
||||
(_, Some(r)) => {
|
||||
let g = self.store().map(|s| s.games_of(r, &known)).unwrap_or_default();
|
||||
let names: Vec<String> = g.iter().map(|id| self.entries.borrow().iter().find(|e| e.id == *id).map(|e| e.title.clone()).unwrap_or_else(|| id.clone())).collect();
|
||||
format!("{} · saved to {}", match g.len() { 0 => "No game uses it yet".to_string(), 1 => format!("1 game uses it: {}", names[0]), n => format!("{n} games use it: {}", names.join(", ")) },
|
||||
match r { Ref::User(slug) => self.store().map(|s| tilde(&s.shared_file(slug))).unwrap_or_default(), _ => String::new() })
|
||||
}
|
||||
_ => "For every game on Default, and under every other profile for what it does not set. Saved as you change them.".to_string(),
|
||||
}.into());
|
||||
sx.set_nav(ModelRc::new(VecModel::from(sections.iter().map(|s| SNav { label: s.title.as_str().into(), changed: s.changed() as i32, count: s.settings() as i32 }).collect::<Vec<_>>())));
|
||||
sx.set_presets(ModelRc::new(VecModel::from(preset_views.iter().map(|p| SPreset { name: p.name.as_str().into(), summary: p.summary.as_str().into(), detail: p.detail.as_str().into(), sets: strings(&p.sets), active: p.active }).collect::<Vec<_>>())));
|
||||
@@ -233,24 +362,78 @@ impl App {
|
||||
self.ui.global::<Lib>().set_editor_open(true);
|
||||
}
|
||||
|
||||
/// One of the user's shared profiles, in the same pane (from the Profiles page).
|
||||
pub fn open_shared_profile(&self, r: Ref) {
|
||||
if !matches!(r, Ref::User(_)) { return; }
|
||||
self.open_pane(Scope::Shared(r));
|
||||
self.ui.global::<Lib>().set_editor_open(true);
|
||||
}
|
||||
|
||||
/// The profile closes: the pane is the Settings page's again.
|
||||
pub fn close_profile(&self) {
|
||||
self.ui.global::<Lib>().set_editor_open(false);
|
||||
self.open_pane(Scope::Settings);
|
||||
if self.ui.get_view() == 4 { self.fill_profiles(None); }
|
||||
}
|
||||
|
||||
/// After a change: the pane again from the files, and whatever else shows the same values.
|
||||
fn changed(&self) {
|
||||
self.fill_pane();
|
||||
if let Scope::Game(i) = self.pane.borrow().scope { self.open_detail(i as i32); }
|
||||
let game = match self.pane.borrow().scope { Scope::Game(i) => Some(i), _ => None };
|
||||
// (a game's settings opened from the Profiles page have no game page under them)
|
||||
if let Some(i) = game { if self.ui.get_detail_open() { self.open_detail(i as i32); } }
|
||||
}
|
||||
|
||||
/// Store engine settings where the pane's scope keeps them (None: stop setting it).
|
||||
fn store_engine(&self, changes: &[(String, Option<Value>)]) {
|
||||
let result: Result<(), String> = (|| {
|
||||
if let Some(e) = self.pane_entry() {
|
||||
return profile::update_layer(&e.id, |l| for (k, v) in changes { l.set_engine(k, v.as_ref()); }).map(|_| ()).map_err(|e| format!("{e:#}"));
|
||||
/// Store engine settings where they belong (None: stop setting it).
|
||||
fn store_engine(&self, changes: &[(String, Option<Value>)]) { self.store_change(Change::Engine(changes.to_vec())); }
|
||||
|
||||
/// A change made in the pane. On the Settings page it is global; in a shared profile it is the profile's; in an
|
||||
/// Individual game it is the game's. A game on a shared profile has no settings of its own on top of it, so the
|
||||
/// change is either the profile's (every game on it) or the game leaves the profile first: that is asked.
|
||||
fn store_change(&self, c: Change) {
|
||||
match self.pane_scope() {
|
||||
Scope::Settings => self.write_change(&Owner::Global, &c),
|
||||
Scope::Shared(r) => self.write_change(&Owner::Profile(r), &c),
|
||||
Scope::Game(_) => {
|
||||
let (Some(e), Some(store)) = (self.pane_entry(), self.store()) else { return };
|
||||
let on = store.assignment(&e.id);
|
||||
if on == Ref::Individual { return self.write_change(&Owner::Game(e.id), &c); }
|
||||
let name = store.get(&on).map(|s| s.name).unwrap_or_else(|_| on.text());
|
||||
let affects = self.affects(&on);
|
||||
let mut rows = vec![];
|
||||
if on.editable() {
|
||||
let (owner, cc) = (if on == Ref::Default { Owner::Global } else { Owner::Profile(on.clone()) }, c.clone());
|
||||
rows.push(profiles::Choice::new(if on == Ref::Default { "Change Default (the global settings)".to_string() } else { format!("Change the profile {name}") }, affects, move |a: &App| a.write_change(&owner, &cc)));
|
||||
} else {
|
||||
rows.push(profiles::Choice::off(format!("Change the profile {name}"), format!("{name} is built-in and read-only. {affects}")));
|
||||
}
|
||||
let (id, cc) = (e.id.clone(), c.clone());
|
||||
rows.push(profiles::Choice::new("Make this game individual", format!("{} leaves {name} and keeps its values as its own settings, then gets this change. No other game is affected.", e.title), move |a: &App| {
|
||||
if let Some(s) = a.store() { if let Err(err) = s.detach(&id) { return a.toast(format!("Not changed: {err:#}")); } }
|
||||
a.write_change(&Owner::Game(id.clone()), &cc);
|
||||
}));
|
||||
rows.push(profiles::Choice::new("Cancel", "Nothing is changed.", |a: &App| a.fill_pane()));
|
||||
self.ask(&format!("{} uses the profile {name}", e.title), "This is one of the profile's settings, and a game on a shared profile has none of its own on top of it. Change it for the profile, or only for this game?", rows, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn write_change(&self, owner: &Owner, c: &Change) {
|
||||
fn put(l: &mut profile::Layer, c: &Change) {
|
||||
match c {
|
||||
Change::Engine(changes) => for (k, v) in changes { l.set_engine(k, v.as_ref()); },
|
||||
// (native ends a multiplier pinned in the same layer; set_engine drops the rate, so it goes first)
|
||||
Change::Rate(r) => { if r.as_deref() == Some(profile::NATIVE) { l.set_engine("hz", None); } l.rate = r.clone(); }
|
||||
}
|
||||
}
|
||||
let result: Result<(), String> = (|| {
|
||||
match (owner, c) {
|
||||
(Owner::Game(id), c) => return profile::update_layer(id, |l| put(l, c)).map(|_| ()).map_err(|e| format!("{e:#}")),
|
||||
(Owner::Profile(r), c) => return self.store().ok_or("no config folder")?.update(r, |l| put(l, c)).map(|_| ()).map_err(|e| format!("{e:#}")),
|
||||
(Owner::Global, Change::Rate(_)) => return profile::update_layer(profile::DEFAULT_ID, |l| put(l, c)).map(|_| ()).map_err(|e| format!("{e:#}")),
|
||||
(Owner::Global, Change::Engine(_)) => {}
|
||||
}
|
||||
let Change::Engine(changes) = c else { return Ok(()) };
|
||||
let reg = self.registry()?;
|
||||
let (ours, engines): (Vec<_>, Vec<_>) = changes.iter().partition(|(k, _)| k == "replay" || k == "replay_clip");
|
||||
if !ours.is_empty() {
|
||||
@@ -277,6 +460,7 @@ impl App {
|
||||
})();
|
||||
if let Err(e) = result { self.toast(format!("Not saved: {e}")); }
|
||||
self.changed();
|
||||
if self.ui.get_view() == 4 && !self.ui.get_detail_open() { self.fill_profile_detail(); }
|
||||
}
|
||||
|
||||
fn row_key(&self, row: i32, quick: bool) -> Option<String> {
|
||||
@@ -294,6 +478,15 @@ impl App {
|
||||
self.set_ui_settings(s.sanitized());
|
||||
self.fill_pane();
|
||||
}
|
||||
"prof" if name == "rate" => {
|
||||
let layered = self.pane_scope() != Scope::Settings;
|
||||
let rate = match (option, layered) {
|
||||
(None, _) | (Some(0), _) => None,
|
||||
(Some(1), true) => Some(String::new()),
|
||||
_ => Some(profile::NATIVE.to_string()),
|
||||
};
|
||||
self.store_change(Change::Rate(rate));
|
||||
}
|
||||
"prof" => {
|
||||
let id = self.pane_profile_id();
|
||||
let own = profile::load_layer(&id).unwrap_or_default();
|
||||
@@ -305,7 +498,7 @@ impl App {
|
||||
self.changed();
|
||||
}
|
||||
"eng" | "engtext" => {
|
||||
let Ok(en) = self.engine(self.pane_entry().as_ref()) else { return };
|
||||
let Ok(en) = self.pane_engine() else { return };
|
||||
let store = match option { Some(o) if kind == "eng" => en.cx().pick(name, o), Some(_) => None, None => (!en.locked.contains_key(name)).then_some(None) };
|
||||
if let Some(v) = store { self.store_engine(&[(name.to_string(), v)]); }
|
||||
}
|
||||
@@ -327,7 +520,7 @@ impl App {
|
||||
self.changed();
|
||||
}
|
||||
"engtext" => {
|
||||
let Ok(en) = self.engine(self.pane_entry().as_ref()) else { return };
|
||||
let Ok(en) = self.pane_engine() else { return };
|
||||
match en.cx().typed(name, text) {
|
||||
Ok(Some(v)) => self.store_engine(&[(name.to_string(), v)]),
|
||||
Ok(None) => self.fill_pane(),
|
||||
@@ -343,9 +536,12 @@ impl App {
|
||||
match key {
|
||||
"act:clips" => self.open_clips(),
|
||||
"act:nvidia" => { lib.set_nvidia_btn(if lib.get_nvidia_installed() { 2 } else { 0 }); lib.set_nvidia_open(true); }
|
||||
"act:profile" => { if let Some(e) = self.pane_entry() { self.pick_profile_for(&e.id); } }
|
||||
"act:reset-all" => {
|
||||
let id = self.pane_profile_id();
|
||||
match profile::save_layer(&id, &profile::Layer::default()) {
|
||||
// (which profile the game uses is not one of its settings: it stays)
|
||||
let keep = profile::load_layer(&id).ok().and_then(|l| l.profile);
|
||||
match profile::save_layer(&id, &profile::Layer { profile: keep, ..Default::default() }) {
|
||||
Ok(_) => self.toast(if id == profile::DEFAULT_ID { "The game defaults are Summit's own again".to_string() } else { "This game follows the global settings again".to_string() }),
|
||||
Err(e) => self.toast(format!("Could not save the profile: {e}")),
|
||||
}
|
||||
@@ -368,14 +564,16 @@ impl App {
|
||||
/// Apply preset `i`: its settings, nothing else, to the engine's file or to this game's profile.
|
||||
fn apply_preset(&self, i: i32) {
|
||||
let Some(p) = presets::PRESETS.get(i.max(0) as usize) else { return };
|
||||
let Ok(en) = self.engine(self.pane_entry().as_ref()) else { return };
|
||||
// In a game the presets are the built-in profiles: picking one puts the game on it.
|
||||
if let Some(e) = self.pane_entry() { return self.assign_game(&e.id, &Ref::Builtin(p.id.into())); }
|
||||
let Ok(en) = self.pane_engine() else { return };
|
||||
let game = en.own.is_some();
|
||||
let changes: Vec<(String, Option<Value>)> = p.values().into_iter().filter_map(|(k, v)| {
|
||||
let spec = en.reg.get(k)?; // (a setting this engine does not have is left out, and the preset's list says so)
|
||||
Some((k.to_string(), if !game && registry::same(&v, &spec.default) { None } else { Some(v) }))
|
||||
}).collect();
|
||||
self.store_engine(&changes);
|
||||
self.toast(format!("{}: {}", p.name, if game { "set for this game" } else { "set for every game without its own" }));
|
||||
self.toast(format!("{}: {}", p.name, if game { "its settings are now this profile's" } else { "set as the global settings (Default)" }));
|
||||
}
|
||||
|
||||
/// The launcher's own settings changed: the window follows, and ui.toml is written.
|
||||
@@ -403,7 +601,12 @@ impl App {
|
||||
let cx = en.cx();
|
||||
let name = |k: &str| en.reg.get(k).map(|s| s.name_of(&cx.value(s)));
|
||||
let up = name("scaler")?;
|
||||
let fg = if cx.value_of("interp") == Value::Bool(false) { "Off".to_string() } else { format!("{} {}", name("model")?, name("hz")?) };
|
||||
// a native-rate profile has no multiplier of its own: the one worked out for this game's screen is shown
|
||||
let native = profile::load(&e.id).ok().filter(|p| p.native_rate()).map(|p| {
|
||||
let res = self.outputs().ok().map(|outs| resolve::for_game(&p, &self.saved_values(), &outs, &resolve::SourceFacts::default()).0);
|
||||
match res { Some(r) if r.rate_from_screen && !r.framegen => "off on this screen (native)".to_string(), Some(r) if r.rate_from_screen => format!("{}x (native)", r.multiplier.unwrap_or(2)), _ => "native".to_string() }
|
||||
});
|
||||
let fg = if cx.value_of("interp") == Value::Bool(false) { "Off".to_string() } else { format!("{} {}", name("model")?, match native { Some(n) => n, None => name("hz")? }) };
|
||||
Some((up, fg))
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,861 @@
|
||||
//! The Profiles page (ui/profiles.slint), the two small dialogs it shares with a game's page (a list of choices, a
|
||||
//! name), and a game's profile and screen pickers. What is listed is built here from the files as plain data
|
||||
//! ([`list`], [`shared_items`], [`game_items`]: unit tested); every action goes through summit_core::profiles and
|
||||
//! the page is built again from the files afterwards.
|
||||
use crate::{tilde, with_app, App, AskRow, Lib, PItem, PRow, Px};
|
||||
use serde_json::Value;
|
||||
use slint::{ComponentHandle, ModelRc, VecModel};
|
||||
use std::collections::BTreeMap;
|
||||
use std::rc::Rc;
|
||||
use summit_core::display::{self, Output};
|
||||
use summit_core::profile::{self, Layer};
|
||||
use summit_core::profiles::{self as shared, Ref, Store};
|
||||
use summit_core::registry::{self, Registry};
|
||||
use summit_core::{optimizer, resolve};
|
||||
|
||||
/// What a row of the list is.
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub enum RowKey { #[default] None, Profile(Ref), Game(String), New, Import }
|
||||
|
||||
/// What a row on the right does.
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub enum Act {
|
||||
#[default] None,
|
||||
OpenSettings, Edit(Ref), EditGame(String), AddGame(Ref), Duplicate(Ref), Rename(Ref), NewGames(Ref), Export(Ref), Delete(Ref),
|
||||
Remove(String), FromGame(String), PickProfile(String), PickScreen(String),
|
||||
/// One of the optimizer's measured configurations: (which result, which entry).
|
||||
Result(usize, usize),
|
||||
}
|
||||
|
||||
/// A row as it is drawn: PRow / PItem without the UI types. kind: see ui/profiles.slint.
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct Line { pub kind: i32, pub label: String, pub detail: String, pub button: String, pub tag: String, pub enabled: bool }
|
||||
|
||||
fn head(label: impl Into<String>) -> Line { Line { kind: 0, label: label.into(), ..Default::default() } }
|
||||
fn note(text: impl Into<String>) -> Line { Line { kind: 1, label: text.into(), ..Default::default() } }
|
||||
fn action(label: &str, detail: impl Into<String>, button: &str) -> Line { Line { kind: 2, label: label.into(), detail: detail.into(), button: button.into(), enabled: true, ..Default::default() } }
|
||||
fn plural(n: usize, one: &str, many: &str) -> String { if n == 1 { format!("1 {one}") } else { format!("{n} {many}") } }
|
||||
|
||||
/// The page as last built: what each row is, for the keys that come back from the UI.
|
||||
#[derive(Default)]
|
||||
pub struct Page { rows: Vec<RowKey>, acts: Vec<Act>, results: Vec<optimizer::ResultFile> }
|
||||
|
||||
/// What the lists are built from.
|
||||
pub struct Cx<'a> {
|
||||
pub store: &'a Store,
|
||||
/// The library: (id, title).
|
||||
pub games: &'a [(String, String)],
|
||||
pub reg: Option<&'a Registry>,
|
||||
pub saved: &'a BTreeMap<String, Value>,
|
||||
/// The screens, or why they cannot be listed.
|
||||
pub outs: Result<&'a [Output], &'a str>,
|
||||
pub results: &'a [optimizer::ResultFile],
|
||||
/// Files that are in the results folder but could not be read: (file, why).
|
||||
pub unread: &'a [(String, String)],
|
||||
pub results_dir: String,
|
||||
}
|
||||
|
||||
impl Cx<'_> {
|
||||
fn ids(&self) -> Vec<String> { self.games.iter().map(|(i, _)| i.clone()).collect() }
|
||||
pub fn title(&self, id: &str) -> String { self.games.iter().find(|(i, _)| i == id).map(|(_, t)| t.clone()).unwrap_or_else(|| id.to_string()) }
|
||||
|
||||
/// A profile's settings in a few words, in the registry's names when the engine is there to ask.
|
||||
pub fn describe(&self, l: &Layer) -> String {
|
||||
let p = profile::resolve(&[l]);
|
||||
let forced = registry::forced(&p);
|
||||
let order = ["interp", "hz", "scaler", "output_res", "motion", "model", "vsync", "aa"];
|
||||
let mut keys: Vec<&String> = forced.keys().collect();
|
||||
keys.sort_by_key(|k| (order.iter().position(|o| o == k).unwrap_or(order.len()), (*k).clone()));
|
||||
let mut v: Vec<String> = keys.iter().map(|k| match self.reg.and_then(|r| r.get(k)) {
|
||||
Some(s) => format!("{} {}", s.label, s.name_of(&forced[*k])),
|
||||
None => format!("{k} {}", registry::plain(&forced[*k])),
|
||||
}).collect();
|
||||
if p.native_rate() { v.insert(0, "Frame rate Native".into()); }
|
||||
match v.len() {
|
||||
0 => "Nothing of its own: follows the global settings".into(),
|
||||
n if n > 5 => format!("{} · +{} more", v[..5].join(" · "), n - 5),
|
||||
_ => v.join(" · "),
|
||||
}
|
||||
}
|
||||
|
||||
fn games_line(&self, r: &Ref) -> String {
|
||||
let g = self.store.games_of(r, &self.ids());
|
||||
match g.len() { 0 => "No games".into(), n if n <= 3 => g.iter().map(|i| self.title(i)).collect::<Vec<_>>().join(", "), n => format!("{}, +{} more", g[..2].iter().map(|i| self.title(i)).collect::<Vec<_>>().join(", "), n - 2) }
|
||||
}
|
||||
|
||||
/// The effective profile a shared profile gives a game that sets nothing itself.
|
||||
fn profile_of(&self, r: &Ref) -> profile::Profile {
|
||||
let id = if *r == Ref::Default { profile::DEFAULT_ID.to_string() } else { r.text() };
|
||||
self.store.effective(&id).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The left side: Default, Built-in, My profiles, Individual games.
|
||||
pub fn list(&self) -> Vec<(RowKey, Line)> {
|
||||
let all = self.store.list();
|
||||
let new = self.store.new_games();
|
||||
let row = |s: &shared::Shared| (RowKey::Profile(s.r.clone()), Line { kind: 1, label: s.name.clone(), detail: self.games_line(&s.r),
|
||||
tag: if s.r == new && new != Ref::Default { "New games".into() } else { String::new() }, enabled: true, ..Default::default() });
|
||||
let mut v = vec![(RowKey::None, head("DEFAULT"))];
|
||||
v.extend(all.iter().filter(|s| s.r == Ref::Default).map(row));
|
||||
v.push((RowKey::None, head("BUILT-IN")));
|
||||
v.extend(all.iter().filter(|s| matches!(s.r, Ref::Builtin(_))).map(row));
|
||||
v.push((RowKey::None, head("MY PROFILES")));
|
||||
v.extend(all.iter().filter(|s| matches!(s.r, Ref::User(_))).map(row));
|
||||
v.push((RowKey::New, Line { kind: 3, label: "New profile".into(), detail: "Native: the screen's resolution and refresh rate".into(), enabled: true, ..Default::default() }));
|
||||
v.push((RowKey::Import, Line { kind: 3, label: "Import from a file".into(), detail: "A profile someone exported".into(), enabled: true, ..Default::default() }));
|
||||
v.push((RowKey::None, head("INDIVIDUAL GAMES")));
|
||||
let ind = self.store.games_of(&Ref::Individual, &self.ids());
|
||||
if ind.is_empty() { v.push((RowKey::None, Line { kind: 4, label: "No game has settings of its own.".into(), ..Default::default() })); }
|
||||
for g in ind {
|
||||
let own = self.store.layer(&g).unwrap_or_default().shared_part();
|
||||
v.push((RowKey::Game(g.clone()), Line { kind: 2, label: self.title(&g), detail: self.describe(&own), enabled: true, ..Default::default() }));
|
||||
}
|
||||
v
|
||||
}
|
||||
|
||||
/// What a resolved profile says: the line, why, and the suggestions.
|
||||
fn resolved(&self, r: &resolve::Resolved, v: &mut Vec<(Act, Line)>) {
|
||||
v.push((Act::None, Line { kind: 4, label: r.line(), ..Default::default() }));
|
||||
for w in &r.why { v.push((Act::None, note(w.clone()))); }
|
||||
for s in &r.suggestions { v.push((Act::None, Line { kind: 5, label: s.line(), ..Default::default() })); }
|
||||
}
|
||||
|
||||
/// The optimizer's results: an action for each measured configuration, or what there is instead.
|
||||
fn results(&self, v: &mut Vec<(Act, Line)>) {
|
||||
v.push((Act::None, Line { tag: "Experimental".into(), ..head("BENCHMARK RESULTS") }));
|
||||
if self.results.is_empty() {
|
||||
v.push((Act::None, note(format!("No results yet. The engine's optimizer (--optimize, or Optimize in the in-game overlay) measures settings while a game runs and writes its best three to {}; a result found there can be applied here.", self.results_dir))));
|
||||
}
|
||||
for (fi, f) in self.results.iter().enumerate() {
|
||||
let mut what = vec![];
|
||||
if let Some(g) = &f.game { what.push(format!("measured in {g}")); }
|
||||
if !f.goal.is_empty() { what.push(format!("goal: {}", f.goal)); }
|
||||
if !f.machine.is_empty() { what.push(f.machine.clone()); }
|
||||
if f.when > 0 { what.push(summit_core::sessions::stamp(f.when)); }
|
||||
v.push((Act::None, note(format!("{} ({})", what.join(" · "), f.file.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default()))));
|
||||
if !f.note.is_empty() { v.push((Act::None, note(f.note.clone()))); }
|
||||
for (pi, p) in f.top.iter().enumerate() {
|
||||
v.push((Act::Result(fi, pi), action(&format!("{}. {}", p.rank, p.label), p.numbers.join(" · "), "Use")));
|
||||
}
|
||||
}
|
||||
for (f, why) in self.unread { v.push((Act::None, note(format!("{f} is not read: {why}")))); }
|
||||
if !self.results.is_empty() {
|
||||
v.push((Act::None, note("Read from the engine's result files as they are. Experimental: the reader was written against the engine's format with a test file, not checked against a result from a real run.")));
|
||||
}
|
||||
}
|
||||
|
||||
/// The right side for a shared profile.
|
||||
pub fn shared_items(&self, r: &Ref) -> (String, String, String, Vec<(Act, Line)>) {
|
||||
let Ok(s) = self.store.get(r) else { return (r.text(), String::new(), "This profile is gone.".into(), vec![]) };
|
||||
let kind = match r { Ref::Default => "The global settings", Ref::Builtin(_) => "Built-in · read-only", _ => "Yours" };
|
||||
let summary = if s.summary.is_empty() { self.describe(&s.layer) } else { format!("{} {}", s.summary, self.describe(&s.layer)) };
|
||||
let games = self.store.games_of(r, &self.ids());
|
||||
let new = self.store.new_games();
|
||||
let mut v: Vec<(Act, Line)> = vec![];
|
||||
match r {
|
||||
Ref::Default => v.push((Act::OpenSettings, action("Change its settings", "Default is the global settings: they are on the Settings page.", "Settings"))),
|
||||
Ref::Builtin(_) => v.push((Act::None, Line { enabled: false, ..action("Change its settings", "Built-in profiles are read-only. Duplicate it and change the copy.", "") })),
|
||||
_ => v.push((Act::Edit(r.clone()), action("Change its settings", format!("Every game on it gets the change ({}).", plural(games.len(), "game", "games")), "Edit"))),
|
||||
}
|
||||
v.push((Act::AddGame(r.clone()), action("Put a game on it", "Pick a game: it uses this profile from then on. Its screen, window and launch options stay its own.", "Add")));
|
||||
v.push((Act::Duplicate(r.clone()), action("Duplicate", "An editable copy with a name of its own.", "Copy")));
|
||||
if matches!(r, Ref::User(_)) { v.push((Act::Rename(r.clone()), action("Rename", "Its games stay on it.", "Rename"))); }
|
||||
v.push((Act::NewGames(r.clone()), if *r == new {
|
||||
Line { enabled: false, tag: "In use".into(), ..action("Use for games without a profile", "Games that were never given a profile use this one.", "") }
|
||||
} else {
|
||||
action("Use for games without a profile", format!("Now: {}. Games that were given a profile keep it.", self.store.get(&new).map(|n| n.name).unwrap_or_default()), "Use")
|
||||
}));
|
||||
v.push((Act::Export(r.clone()), action("Export to a file", self.store.export_path(r).map(|p| format!("Writes {}", tilde(&p))).unwrap_or_default(), "Export")));
|
||||
if matches!(r, Ref::User(_)) {
|
||||
v.push((Act::Delete(r.clone()), action("Delete", if games.is_empty() { "No game is on it.".to_string() } else { format!("Its {} become Individual and keep the settings they had.", plural(games.len(), "game", "games")) }, "Delete")));
|
||||
}
|
||||
|
||||
v.push((Act::None, head(format!("GAMES ON THIS PROFILE · {}", games.len()))));
|
||||
if games.is_empty() { v.push((Act::None, note("No game uses it yet."))); }
|
||||
for g in &games {
|
||||
let p = self.store.effective(g).unwrap_or_default();
|
||||
let detail = match self.outs {
|
||||
Ok(outs) => match resolve::for_game(&p, self.saved, outs, &resolve::SourceFacts::default()) {
|
||||
(res, None) => res.line(),
|
||||
(res, Some(why)) => format!("{} · the screen is not known: {why}", res.summary()),
|
||||
},
|
||||
Err(_) => p.monitor.clone().map(|m| format!("on {m}")).unwrap_or_else(|| "no screen chosen".into()),
|
||||
};
|
||||
v.push((Act::Remove(g.clone()), Line { kind: 3, label: self.title(g), detail, button: "Remove".into(), enabled: true, ..Default::default() }));
|
||||
}
|
||||
if !games.is_empty() { v.push((Act::None, note("Remove takes a game off the profile: it becomes an Individual game and keeps these settings as its own."))); }
|
||||
|
||||
v.push((Act::None, head("ON EACH SCREEN")));
|
||||
match self.outs {
|
||||
Ok(outs) => {
|
||||
let lines = resolve::per_screen(&self.profile_of(r), self.saved, outs);
|
||||
if lines.is_empty() { v.push((Act::None, note("No screen is on."))); }
|
||||
for res in &lines { self.resolved(res, &mut v); }
|
||||
}
|
||||
Err(e) => v.push((Act::None, note(format!("The screens can't be listed here ({e}), so nothing is worked out. A game still gets its frame multiplier from its screen when it starts.")))),
|
||||
}
|
||||
self.results(&mut v);
|
||||
(s.name, kind.into(), summary, v)
|
||||
}
|
||||
|
||||
/// The right side for an Individual game.
|
||||
pub fn game_items(&self, game: &str, in_library: bool) -> (String, String, String, Vec<(Act, Line)>) {
|
||||
let own = self.store.layer(game).unwrap_or_default();
|
||||
let mut v: Vec<(Act, Line)> = vec![];
|
||||
v.push(if in_library { (Act::EditGame(game.to_string()), action("Change its settings", "This game's own settings: nothing else uses them.", "Edit")) }
|
||||
else { (Act::None, Line { enabled: false, ..action("Change its settings", "This game is not in the library on this PC.", "") }) });
|
||||
v.push((Act::FromGame(game.to_string()), action("Create a profile from this game", "A new profile with these settings, which this game then uses and other games can share.", "Create")));
|
||||
v.push((Act::PickProfile(game.to_string()), action("Put it on a profile", "Its own settings are replaced by the profile's (a copy of its file is kept).", "Choose")));
|
||||
v.push((Act::PickScreen(game.to_string()), action("Screen", own.monitor.clone().filter(|m| !m.is_empty()).map(|m| format!("Runs on {m}.")).unwrap_or_else(|| "No screen chosen for this game.".into()), "Choose")));
|
||||
v.push((Act::None, head("ON ITS SCREEN")));
|
||||
let p = self.store.effective(game).unwrap_or_default();
|
||||
match self.outs {
|
||||
Ok(outs) => {
|
||||
let (res, unknown) = resolve::for_game(&p, self.saved, outs, &resolve::SourceFacts::default());
|
||||
if let Some(why) = unknown { v.push((Act::None, note(format!("The screen is not known: {why}.")))); }
|
||||
self.resolved(&res, &mut v);
|
||||
}
|
||||
Err(e) => v.push((Act::None, note(format!("The screens can't be listed here ({e}), so nothing is worked out.")))),
|
||||
}
|
||||
self.results(&mut v);
|
||||
(self.title(game), "Individual game".into(), self.describe(&own.shared_part()), v)
|
||||
}
|
||||
}
|
||||
|
||||
/// For each row, the row above and below it that can take the focus (-1: none).
|
||||
pub fn neighbours(can: &[bool]) -> Vec<(i32, i32)> {
|
||||
(0..can.len()).map(|i| (can[..i].iter().rposition(|c| *c).map_or(-1, |j| j as i32), can[i + 1..].iter().position(|c| *c).map_or(-1, |j| (i + 1 + j) as i32))).collect()
|
||||
}
|
||||
|
||||
type Then = Rc<dyn Fn(&App)>;
|
||||
type Named = Rc<dyn Fn(&App, &str) -> Result<(), String>>;
|
||||
|
||||
/// One row of the list of choices: what it shows, and what picking it does (None: it cannot be picked).
|
||||
pub struct Choice { pub label: String, pub detail: String, pub tag: String, pub then: Option<Then> }
|
||||
impl Choice {
|
||||
pub fn new(label: impl Into<String>, detail: impl Into<String>, then: impl Fn(&App) + 'static) -> Choice { Choice { label: label.into(), detail: detail.into(), tag: String::new(), then: Some(Rc::new(then)) } }
|
||||
pub fn off(label: impl Into<String>, detail: impl Into<String>) -> Choice { Choice { label: label.into(), detail: detail.into(), tag: String::new(), then: None } }
|
||||
pub fn cancel() -> Choice { Choice::new("Cancel", "Nothing is changed.", |_| {}) }
|
||||
pub fn tag(mut self, t: &str) -> Choice { self.tag = t.into(); self }
|
||||
}
|
||||
|
||||
/// The two dialogs' pending answers.
|
||||
#[derive(Default)]
|
||||
pub struct Dialogs { asks: Vec<Option<Then>>, named: Option<Named> }
|
||||
|
||||
impl App {
|
||||
pub fn store(&self) -> Option<Store> { Store::user().ok() }
|
||||
|
||||
/// The games profiles are listed with: the library's games (not its tools and other software; one of those that
|
||||
/// was given a profile still shows, through its file).
|
||||
pub fn library(&self) -> Vec<(String, String)> {
|
||||
self.entries.borrow().iter().filter(|e| e.kind == summit_core::model::Kind::Game).map(|e| (e.id.clone(), e.title.clone())).collect()
|
||||
}
|
||||
|
||||
/// The screens of this PC, listed once and kept (None: list them again). `SUMMIT_SCREENS=sample` gives two
|
||||
/// made-up screens (a 4K 144 Hz monitor and a 1080p 60 Hz projector) for renders and tests on a PC without one.
|
||||
pub fn outputs(&self) -> Result<Vec<Output>, String> {
|
||||
if let Some(o) = self.screens.borrow().as_ref() { return o.clone(); }
|
||||
let o = if std::env::var("SUMMIT_SCREENS").is_ok_and(|v| v == "sample") { Ok(resolve::sample_outputs()) }
|
||||
else { display::outputs(display::detect_session(), display::detect_desktop()) };
|
||||
*self.screens.borrow_mut() = Some(o.clone());
|
||||
o
|
||||
}
|
||||
pub fn forget_screens(&self) { *self.screens.borrow_mut() = None; }
|
||||
|
||||
/// The engine's saved settings: its own file when the engine is here to say where that is.
|
||||
pub fn saved_values(&self) -> BTreeMap<String, Value> {
|
||||
match self.registry() { Ok(r) => registry::read_values(&r.path), Err(_) => resolve::saved_settings() }
|
||||
}
|
||||
|
||||
fn with_cx<T>(&self, f: impl FnOnce(&Cx) -> T) -> Option<T> {
|
||||
let store = self.store()?;
|
||||
let games = self.library();
|
||||
let reg = self.registry().ok();
|
||||
let saved = self.saved_values();
|
||||
let outs = self.outputs();
|
||||
let dirs = optimizer::dirs();
|
||||
let (results, unread) = optimizer::read(&dirs);
|
||||
let unread: Vec<(String, String)> = unread.iter().map(|(p, w)| (tilde(p), w.clone())).collect();
|
||||
let cx = Cx { store: &store, games: &games, reg: reg.as_ref(), saved: &saved, outs: outs.as_deref().map_err(|e| e.as_str()), results: &results, unread: &unread,
|
||||
results_dir: dirs.last().map(|d| tilde(d)).unwrap_or_default() };
|
||||
let out = f(&cx);
|
||||
self.page.borrow_mut().results = results;
|
||||
Some(out)
|
||||
}
|
||||
|
||||
/// Build the page from the files, keeping the selection on `keep` (or where it was).
|
||||
pub fn fill_profiles(&self, keep: Option<RowKey>) {
|
||||
let px = self.ui.global::<Px>();
|
||||
let Some(list) = self.with_cx(|cx| cx.list()) else { return };
|
||||
let was = keep.or_else(|| self.page.borrow().rows.get(px.get_sel().max(0) as usize).cloned());
|
||||
let can: Vec<bool> = list.iter().map(|(_, l)| matches!(l.kind, 1 | 2 | 3)).collect();
|
||||
let nb = neighbours(&can);
|
||||
px.set_rows(ModelRc::new(VecModel::from(list.iter().zip(&nb).map(|((_, l), (up, down))| PRow { kind: l.kind, label: l.label.as_str().into(), detail: l.detail.as_str().into(), tag: l.tag.as_str().into(), up: *up, down: *down }).collect::<Vec<_>>())));
|
||||
let keys: Vec<RowKey> = list.into_iter().map(|(k, _)| k).collect();
|
||||
let sel = was.and_then(|w| keys.iter().position(|k| *k == w && w != RowKey::None)).or_else(|| can.iter().position(|c| *c)).unwrap_or(0);
|
||||
self.page.borrow_mut().rows = keys;
|
||||
px.set_sel(sel as i32);
|
||||
self.fill_profile_detail();
|
||||
}
|
||||
|
||||
/// The right side, for the selected row.
|
||||
pub fn fill_profile_detail(&self) {
|
||||
let px = self.ui.global::<Px>();
|
||||
let key = self.page.borrow().rows.get(px.get_sel().max(0) as usize).cloned().unwrap_or_default();
|
||||
let in_lib = |g: &str| self.entries.borrow().iter().any(|e| e.id == g);
|
||||
let (title, kind, summary, items) = match &key {
|
||||
RowKey::Profile(r) => self.with_cx(|cx| cx.shared_items(r)).unwrap_or_default(),
|
||||
RowKey::Game(g) => self.with_cx(|cx| cx.game_items(g, in_lib(g))).unwrap_or_default(),
|
||||
RowKey::New => ("New profile".into(), String::new(), "Enter makes a profile and asks for its name.".into(),
|
||||
vec![(Act::None, note("A new profile starts native: its output is the resolution of whichever screen a game runs on, and its frame multiplier is as many frames as that screen shows. So one profile fits a 4K 144 Hz monitor and a 1080p 60 Hz projector. Either can be pinned to a fixed value in the profile's settings.")),
|
||||
(Act::None, note("To start from a game's own settings instead, pick the game under Individual games and use Create a profile from this game."))]),
|
||||
RowKey::Import => ("Import from a file".into(), String::new(), "Enter lists the profile files in your Documents, Downloads and home folders.".into(),
|
||||
vec![(Act::None, note("A profile exported from Summit (Export to a file, or summit profile export) is one small text file. Importing adds it to My profiles; if the name is taken it gets \"(imported)\" added."))]),
|
||||
RowKey::None => Default::default(),
|
||||
};
|
||||
let can: Vec<bool> = items.iter().map(|(_, l)| matches!(l.kind, 2 | 3) && l.enabled).collect();
|
||||
let nb = neighbours(&can);
|
||||
px.set_title(title.into());
|
||||
px.set_kind(kind.into());
|
||||
px.set_summary(summary.into());
|
||||
px.set_items(ModelRc::new(VecModel::from(items.iter().zip(&nb).map(|((_, l), (up, down))| PItem { kind: l.kind, label: l.label.as_str().into(), detail: l.detail.as_str().into(), button: l.button.as_str().into(),
|
||||
tag: l.tag.as_str().into(), enabled: l.enabled, up: *up, down: *down }).collect::<Vec<_>>())));
|
||||
let first = can.iter().position(|c| *c);
|
||||
px.set_first_item(first.map_or(-1, |i| i as i32));
|
||||
if !can.get(px.get_item().max(0) as usize).copied().unwrap_or(false) {
|
||||
px.set_item(first.unwrap_or(0) as i32);
|
||||
if first.is_none() { px.set_zone(0); }
|
||||
}
|
||||
self.page.borrow_mut().acts = items.into_iter().map(|(a, _)| a).collect();
|
||||
}
|
||||
|
||||
/// Something about profiles changed: every place that shows them is built again from the files.
|
||||
pub fn profiles_changed(&self, keep: Option<RowKey>) {
|
||||
if self.ui.get_view() == 4 || keep.is_some() { self.fill_profiles(keep); }
|
||||
if self.ui.global::<Lib>().get_editor_open() { self.fill_pane(); }
|
||||
if self.ui.get_detail_open() { self.open_detail(self.ui.global::<Lib>().get_detail().idx); }
|
||||
}
|
||||
|
||||
// ---- the two dialogs ----
|
||||
pub fn ask(&self, title: &str, note: &str, choices: Vec<Choice>, sel: usize) {
|
||||
let px = self.ui.global::<Px>();
|
||||
px.set_ask_title(title.into());
|
||||
px.set_ask_note(note.into());
|
||||
let nb = neighbours(&choices.iter().map(|c| c.then.is_some()).collect::<Vec<_>>());
|
||||
px.set_ask_rows(ModelRc::new(VecModel::from(choices.iter().zip(&nb).map(|(c, (up, down))| AskRow { label: c.label.as_str().into(), detail: c.detail.as_str().into(), tag: c.tag.as_str().into(), enabled: c.then.is_some(), up: *up, down: *down }).collect::<Vec<_>>())));
|
||||
let sel = if choices.get(sel).is_some_and(|c| c.then.is_some()) { sel } else { choices.iter().position(|c| c.then.is_some()).unwrap_or(0) };
|
||||
px.set_ask_sel(sel as i32);
|
||||
self.dialogs.borrow_mut().asks = choices.into_iter().map(|c| c.then).collect();
|
||||
px.set_ask_open(true);
|
||||
}
|
||||
|
||||
fn ask_pick(&self, i: i32) {
|
||||
let then = self.dialogs.borrow_mut().asks.get_mut(i.max(0) as usize).and_then(Option::take);
|
||||
let Some(then) = then else { return };
|
||||
self.dialogs.borrow_mut().asks.clear();
|
||||
self.ui.global::<Px>().set_ask_open(false);
|
||||
then(self);
|
||||
}
|
||||
|
||||
/// Ask for a name, filled in with `suggest`. `done` gets it; an Err is shown in the dialog, which stays open.
|
||||
pub fn ask_name(&self, title: &str, note: &str, suggest: &str, done: impl Fn(&App, &str) -> Result<(), String> + 'static) {
|
||||
let px = self.ui.global::<Px>();
|
||||
px.set_name_title(title.into());
|
||||
px.set_name_note(note.into());
|
||||
px.set_name_text(suggest.into());
|
||||
px.set_name_error("".into());
|
||||
self.dialogs.borrow_mut().named = Some(Rc::new(done));
|
||||
px.set_name_open(true);
|
||||
}
|
||||
|
||||
fn name_done(&self, text: &str) {
|
||||
let Some(done) = self.dialogs.borrow().named.clone() else { return };
|
||||
let px = self.ui.global::<Px>();
|
||||
match done(self, text) {
|
||||
Ok(()) => { self.dialogs.borrow_mut().named = None; px.set_name_open(false); }
|
||||
Err(e) => px.set_name_error(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// A name no profile has yet: "Couch copy", "Couch copy 2"...
|
||||
fn free_name(&self, base: &str) -> String {
|
||||
let taken: Vec<String> = self.store().map(|s| s.list().into_iter().map(|p| p.name.to_lowercase()).collect()).unwrap_or_default();
|
||||
let mut name = base.to_string();
|
||||
let mut n = 2;
|
||||
while taken.contains(&name.to_lowercase()) { name = format!("{base} {n}"); n += 1; }
|
||||
name
|
||||
}
|
||||
|
||||
/// The library's game ids (what a profile's games are counted over).
|
||||
pub fn game_ids(&self) -> Vec<String> { self.library().into_iter().map(|(i, _)| i).collect() }
|
||||
|
||||
/// "Affects 3 games: A, B, C" for the games on `r` (the first few by name, then how many more).
|
||||
pub fn affects(&self, r: &Ref) -> String {
|
||||
let games = self.store().map(|s| s.games_of(r, &self.game_ids())).unwrap_or_default();
|
||||
let mut names: Vec<String> = games.iter().take(4).map(|g| self.game_title(g)).collect();
|
||||
if games.len() > 4 { names.push(format!("+{} more", games.len() - 4)); }
|
||||
match games.len() { 0 => "No game is on it".to_string(), 1 => format!("Affects 1 game: {}", names[0]), n => format!("Affects {n} games: {}", names.join(", ")) }
|
||||
}
|
||||
|
||||
pub fn game_title(&self, id: &str) -> String { self.entries.borrow().iter().find(|e| e.id == id).map(|e| e.title.clone()).unwrap_or_else(|| id.to_string()) }
|
||||
|
||||
// ---- actions ----
|
||||
fn page_row_act(&self, i: i32) {
|
||||
let key = self.page.borrow().rows.get(i.max(0) as usize).cloned().unwrap_or_default();
|
||||
match key {
|
||||
RowKey::New => self.ask_name("New profile", "It starts native: the screen's own resolution, and as many frames as the screen shows. Give it a name.", &self.free_name("My profile"), |a, name| {
|
||||
let s = a.store().ok_or("no config folder")?;
|
||||
let r = s.create(name, &Store::blank()).map_err(|e| format!("{e:#}"))?;
|
||||
a.toast(format!("Made {}", name.trim()));
|
||||
a.profiles_changed(Some(RowKey::Profile(r)));
|
||||
Ok(())
|
||||
}),
|
||||
RowKey::Import => self.import_profile(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn import_profile(&self) {
|
||||
let dirs = shared::exchange_dirs();
|
||||
let files = shared::importable(&dirs);
|
||||
let mut rows: Vec<Choice> = files.into_iter().map(|(path, name)| {
|
||||
let shown = tilde(&path);
|
||||
Choice::new(name, shown, move |a: &App| {
|
||||
let Some(s) = a.store() else { return };
|
||||
match s.import(&path) {
|
||||
Ok(r) => { a.toast(format!("Added {}", s.get(&r).map(|p| p.name).unwrap_or_default())); a.profiles_changed(Some(RowKey::Profile(r))); }
|
||||
Err(e) => a.toast(format!("Not imported: {e:#}")),
|
||||
}
|
||||
})
|
||||
}).collect();
|
||||
let none = rows.is_empty();
|
||||
rows.push(Choice::cancel());
|
||||
let places = dirs.iter().map(|d| tilde(d)).collect::<Vec<_>>().join(", ");
|
||||
self.ask("Import a profile", &if none { format!("No profile file found in {places}. Put the exported file (summit-profile-<name>.toml) in one of them, or use: summit profile import <file>.") }
|
||||
else { format!("Profile files found in {places}.") }, rows, 0);
|
||||
}
|
||||
|
||||
fn page_act(&self, i: i32) {
|
||||
let act = self.page.borrow().acts.get(i.max(0) as usize).cloned().unwrap_or_default();
|
||||
let Some(store) = self.store() else { return };
|
||||
let name_of = |r: &Ref| store.get(r).map(|s| s.name).unwrap_or_else(|_| r.text());
|
||||
match act {
|
||||
Act::None => {}
|
||||
Act::OpenSettings => { self.ui.invoke_goto(3); self.ui.set_zone(1); }
|
||||
Act::Edit(r) => self.open_shared_profile(r),
|
||||
Act::EditGame(g) => { if let Some(i) = self.entries.borrow().iter().position(|e| e.id == g) { self.open_profile(i as i32); } }
|
||||
Act::AddGame(r) => {
|
||||
let name = name_of(&r);
|
||||
let members = store.membership(&self.library().into_iter().map(|(i, _)| i).collect::<Vec<_>>());
|
||||
let mut games: Vec<(String, String, Ref)> = members.into_iter().filter(|(_, on)| *on != r).map(|(g, on)| (self.game_title(&g), g, on)).collect();
|
||||
games.sort_by_key(|(t, _, _)| t.to_lowercase());
|
||||
let mut rows: Vec<Choice> = games.into_iter().map(|(title, g, on)| {
|
||||
let r = r.clone();
|
||||
let now = if on == Ref::Individual { "Now Individual: its own settings are replaced (a copy of its file is kept)".to_string() } else { format!("Now on {}", name_of(&on)) };
|
||||
Choice::new(title, now, move |a: &App| a.assign_game(&g, &r))
|
||||
}).collect();
|
||||
let none = rows.is_empty();
|
||||
rows.push(Choice::cancel());
|
||||
self.ask(&format!("Put a game on {name}"), if none { "Every game is on it already." } else { "The game uses this profile from then on. Its screen, window and launch options stay its own." }, rows, 0);
|
||||
}
|
||||
Act::Duplicate(r) => {
|
||||
let from = name_of(&r);
|
||||
self.ask_name(&format!("Duplicate {from}"), "An editable copy. Give it a name.", &self.free_name(&format!("{from} copy")), move |a, name| {
|
||||
let s = a.store().ok_or("no config folder")?;
|
||||
let new = s.duplicate(&r, name).map_err(|e| format!("{e:#}"))?;
|
||||
a.toast(format!("Made {} from {from}", name.trim()));
|
||||
a.profiles_changed(Some(RowKey::Profile(new)));
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
Act::Rename(r) => {
|
||||
let from = name_of(&r);
|
||||
self.ask_name(&format!("Rename {from}"), "Its games stay on it.", &from, move |a, name| {
|
||||
a.store().ok_or("no config folder")?.rename(&r, name).map_err(|e| format!("{e:#}"))?;
|
||||
a.profiles_changed(Some(RowKey::Profile(r.clone())));
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
Act::NewGames(r) => {
|
||||
match store.set_new_games(&r) { Ok(()) => self.toast(format!("Games without a profile now use {}", name_of(&r))), Err(e) => self.toast(format!("Not changed: {e:#}")) }
|
||||
self.profiles_changed(Some(RowKey::Profile(r)));
|
||||
}
|
||||
Act::Export(r) => match store.export_path(&r).and_then(|p| store.export(&r, &p).map(|_| p)) {
|
||||
Ok(p) => self.toast(format!("Exported {} to {}", name_of(&r), tilde(&p))),
|
||||
Err(e) => self.toast(format!("Not exported: {e:#}")),
|
||||
},
|
||||
Act::Delete(r) => {
|
||||
let name = name_of(&r);
|
||||
let games = store.games_of(&r, &self.library().into_iter().map(|(i, _)| i).collect::<Vec<_>>());
|
||||
let what = if games.is_empty() { "No game is on it.".to_string() } else {
|
||||
format!("{} on it become{} Individual and keep the settings they have now: {}.", plural(games.len(), "game", "games"), if games.len() == 1 { "s" } else { "" }, games.iter().map(|g| self.game_title(g)).collect::<Vec<_>>().join(", "))
|
||||
};
|
||||
let rr = r.clone();
|
||||
self.ask(&format!("Delete {name}?"), &format!("{what} The profile's file is moved to {}.", tilde(&store.root.join("backups"))), vec![
|
||||
Choice::new(format!("Delete {name}"), "It is taken off the list.", move |a: &App| {
|
||||
let Some(s) = a.store() else { return };
|
||||
let known: Vec<String> = a.library().into_iter().map(|(i, _)| i).collect();
|
||||
match s.delete(&rr, &known) {
|
||||
Ok(g) => a.toast(if g.is_empty() { "Deleted".to_string() } else { format!("Deleted. {} now Individual, with the same settings", plural(g.len(), "game is", "games are")) }),
|
||||
Err(e) => a.toast(format!("Not deleted: {e:#}")),
|
||||
}
|
||||
a.profiles_changed(Some(RowKey::Profile(Ref::Default)));
|
||||
}),
|
||||
Choice::cancel(),
|
||||
], 1);
|
||||
}
|
||||
Act::Remove(g) => {
|
||||
let title = self.game_title(&g);
|
||||
match store.detach(&g) {
|
||||
Ok(was) => self.toast(format!("{title} is off {} and Individual: it keeps those settings as its own", name_of(&was))),
|
||||
Err(e) => self.toast(format!("Not removed: {e:#}")),
|
||||
}
|
||||
self.profiles_changed(None);
|
||||
}
|
||||
Act::FromGame(g) => {
|
||||
let title = self.game_title(&g);
|
||||
self.ask_name(&format!("Create a profile from {title}"), "A new profile with this game's settings. The game then uses it, and other games can be put on it.", &self.free_name(&format!("{title} profile")), move |a, name| {
|
||||
let r = a.store().ok_or("no config folder")?.from_game(&g, name).map_err(|e| format!("{e:#}"))?;
|
||||
a.toast(format!("Made {}: {} uses it now", name.trim(), a.game_title(&g)));
|
||||
a.profiles_changed(Some(RowKey::Profile(r)));
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
Act::PickProfile(g) => self.pick_profile_for(&g),
|
||||
Act::PickScreen(g) => self.pick_screen_for(&g),
|
||||
Act::Result(fi, pi) => self.use_result(fi, pi),
|
||||
}
|
||||
}
|
||||
|
||||
/// Put `game` on `r`, and say what happened to what it had.
|
||||
pub fn assign_game(&self, game: &str, r: &Ref) {
|
||||
let Some(store) = self.store() else { return };
|
||||
let title = self.game_title(game);
|
||||
let was = store.assignment(game);
|
||||
match store.assign(game, r) {
|
||||
Ok(kept) => {
|
||||
let on = if *r == Ref::Individual { "is Individual now: it keeps the settings it had as its own".to_string() } else { format!("uses {} now", store.get(r).map(|s| s.name).unwrap_or_default()) };
|
||||
self.toast(match kept { Some(k) => format!("{title} {on}. Its own settings were replaced; a copy is in {}", tilde(&k)), None => format!("{title} {on}") });
|
||||
}
|
||||
Err(e) => self.toast(format!("Not changed: {e:#}")),
|
||||
}
|
||||
// the page follows the game: an Individual game that left that list is selected where it went
|
||||
let keep = if self.ui.get_view() == 4 { Some(match (&was, r) { (Ref::Individual, r) if *r != Ref::Individual => RowKey::Profile(r.clone()), _ => self.page.borrow().rows.get(self.ui.global::<Px>().get_sel().max(0) as usize).cloned().unwrap_or_default() }) } else { None };
|
||||
self.profiles_changed(keep);
|
||||
}
|
||||
|
||||
/// The profile picker for a game: every profile and Individual, the one in use marked.
|
||||
pub fn pick_profile_for(&self, game: &str) {
|
||||
let Some(store) = self.store() else { return };
|
||||
let now = store.assignment(game);
|
||||
let title = self.game_title(game);
|
||||
let lines: Vec<(Ref, String, String)> = self.with_cx(|cx| store.list().iter().map(|s| (s.r.clone(), s.name.clone(), match &s.r {
|
||||
Ref::Default => "The global settings".to_string(),
|
||||
_ => cx.describe(&s.layer),
|
||||
})).collect()).unwrap_or_default();
|
||||
let mut sel = 0;
|
||||
let mut rows: Vec<Choice> = vec![];
|
||||
for (r, name, detail) in lines {
|
||||
if r == now { sel = rows.len(); }
|
||||
let (g, rr) = (game.to_string(), r.clone());
|
||||
let kind = match &r { Ref::Builtin(_) => "Built-in · ", Ref::User(_) => "Yours · ", _ => "" };
|
||||
let c = Choice::new(name, format!("{kind}{detail}"), move |a: &App| a.assign_game(&g, &rr));
|
||||
rows.push(if r == now { c.tag("In use") } else { c });
|
||||
}
|
||||
if now == Ref::Individual { sel = rows.len(); }
|
||||
let g = game.to_string();
|
||||
let c = Choice::new("Individual", if now == Ref::Individual { "Its own settings, only for this game" } else { "Its own settings: it starts with the ones it has now and no longer follows the profile" }, move |a: &App| a.assign_game(&g, &Ref::Individual));
|
||||
rows.push(if now == Ref::Individual { c.tag("In use") } else { c });
|
||||
let note = if now == Ref::Individual { "Picking a profile replaces this game's own engine settings with the profile's (a copy of its file is kept). Its screen, window and launch options stay." }
|
||||
else { "A shared profile's changes reach every game on it. The game's screen, window and launch options stay its own." };
|
||||
self.ask(&format!("Profile · {title}"), note, rows, sel);
|
||||
}
|
||||
|
||||
/// The screen picker for a game: no screen chosen, or one of the connected ones with what the profile comes to there.
|
||||
pub fn pick_screen_for(&self, game: &str) {
|
||||
let Some(store) = self.store() else { return };
|
||||
self.forget_screens();
|
||||
let title = self.game_title(game);
|
||||
let own = store.layer(game).unwrap_or_default();
|
||||
let p = store.effective(game).unwrap_or_default();
|
||||
let saved = self.saved_values();
|
||||
let set = |game: &str, monitor: Option<String>| {
|
||||
let (g, m) = (game.to_string(), monitor);
|
||||
move |a: &App| {
|
||||
let Some(s) = a.store() else { return };
|
||||
let r = s.layer(&g).and_then(|mut l| {
|
||||
// a screen brings its own mode: the mode chosen for another screen is not kept
|
||||
if l.monitor != m { l.width = None; l.height = None; l.refresh_hz = None; }
|
||||
l.monitor = m.clone();
|
||||
s.save_layer(&g, &l)
|
||||
});
|
||||
match r { Ok(_) => a.toast(match &m { Some(m) => format!("{} runs on {m}", a.game_title(&g)), None => format!("{}: no screen chosen", a.game_title(&g)) }), Err(e) => a.toast(format!("Not saved: {e:#}")) }
|
||||
a.profiles_changed(None);
|
||||
}
|
||||
};
|
||||
let defaults = profile::load_defaults().ok().and_then(|d| d.monitor);
|
||||
let mut rows = vec![];
|
||||
let mut sel = 0;
|
||||
let c = Choice::new("No screen chosen", match &defaults { Some(m) => format!("Follows Game defaults in Settings ({m})"), None => "The game opens where the desktop puts it; nothing is switched".into() }, set(game, None));
|
||||
rows.push(if own.monitor.is_none() { c.tag("In use") } else { c });
|
||||
let mut note = "The screen stays with this game whatever profile it uses. The profile's output size and frame multiplier are worked out for it when the game starts.".to_string();
|
||||
match self.outputs() {
|
||||
Ok(outs) => {
|
||||
let want = resolve::Wanted::of(&p, &saved);
|
||||
for s in resolve::screens(&outs) {
|
||||
let res = resolve::resolve(&want, Some(&s), &resolve::SourceFacts::default());
|
||||
let mine = own.monitor.as_deref() == Some(s.name.as_str());
|
||||
if mine { sel = rows.len(); }
|
||||
let c = Choice::new(format!("{} {}x{} {} Hz", s.name, s.width, s.height, s.rate()), format!("This game's profile here: {}", res.summary()), set(game, Some(s.name.clone())));
|
||||
rows.push(if mine { c.tag("In use") } else { c });
|
||||
}
|
||||
// a screen the game names that is not connected now stays in the list
|
||||
if let Some(m) = own.monitor.as_deref().filter(|m| !m.is_empty() && !outs.iter().any(|o| o.connected && o.current.is_some() && o.name == *m)) {
|
||||
sel = rows.len();
|
||||
rows.push(Choice::new(m.to_string(), "Not on right now", set(game, Some(m.to_string()))).tag("In use"));
|
||||
}
|
||||
}
|
||||
Err(e) => note = format!("{note} The screens can't be listed here ({e}); a screen's name can be typed in the game's settings, under Launch."),
|
||||
}
|
||||
rows.push(Choice::cancel());
|
||||
self.ask(&format!("Screen · {title}"), ¬e, rows, sel);
|
||||
}
|
||||
|
||||
/// One of the optimizer's measured configurations: where to put it.
|
||||
fn use_result(&self, fi: usize, pi: usize) {
|
||||
let Some(pick) = self.page.borrow().results.get(fi).and_then(|f| f.top.get(pi)).cloned() else { return };
|
||||
let key = self.page.borrow().rows.get(self.ui.global::<Px>().get_sel().max(0) as usize).cloned().unwrap_or_default();
|
||||
let Some(store) = self.store() else { return };
|
||||
let mut rows = vec![];
|
||||
match &key {
|
||||
RowKey::Profile(r) if matches!(r, Ref::User(_)) => {
|
||||
let n = store.games_of(r, &self.library().into_iter().map(|(i, _)| i).collect::<Vec<_>>()).len();
|
||||
let (r, p) = (r.clone(), pick.clone());
|
||||
rows.push(Choice::new("Apply to profile", format!("{}: {} get these settings", store.get(&r).map(|s| s.name).unwrap_or_default(), plural(n, "game", "games")), move |a: &App| {
|
||||
let Some(s) = a.store() else { return };
|
||||
match s.update(&r, |l| p.apply_to(l)) { Ok(_) => a.toast("Applied to the profile"), Err(e) => a.toast(format!("Not applied: {e:#}")) }
|
||||
a.profiles_changed(None);
|
||||
}));
|
||||
}
|
||||
RowKey::Profile(r) => rows.push(Choice::off("Apply to profile", if *r == Ref::Default { "Default is the global settings: apply it in the in-game overlay's Optimize tab, or save it as a new profile" } else { "Built-in profiles are read-only: save it as a new profile" })),
|
||||
RowKey::Game(g) => {
|
||||
let (g, p) = (g.clone(), pick.clone());
|
||||
rows.push(Choice::new("Apply to this game", format!("{} gets these settings as its own", self.game_title(&g)), move |a: &App| {
|
||||
let Some(s) = a.store() else { return };
|
||||
match s.layer(&g).and_then(|mut l| { p.apply_to(&mut l); s.save_layer(&g, &l) }) { Ok(_) => a.toast("Applied to this game"), Err(e) => a.toast(format!("Not applied: {e:#}")) }
|
||||
a.profiles_changed(None);
|
||||
}));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
let p = pick.clone();
|
||||
rows.push(Choice::new("Save as new profile", "A profile of yours with these settings; nothing else changes", move |a: &App| {
|
||||
let p = p.clone();
|
||||
a.ask_name("Save the result as a profile", "A new profile with the measured settings. Give it a name.", &a.free_name("Optimized"), move |a, name| {
|
||||
let r = a.store().ok_or("no config folder")?.create(name, &p.layer()).map_err(|e| format!("{e:#}"))?;
|
||||
a.toast(format!("Made {}", name.trim()));
|
||||
a.profiles_changed(Some(RowKey::Profile(r)));
|
||||
Ok(())
|
||||
});
|
||||
}));
|
||||
rows.push(Choice::cancel());
|
||||
self.ask(&pick.label, &format!("{}{} A measured result is one fixed configuration: it pins the frame multiplier and the output size (they no longer follow the screen).",
|
||||
pick.numbers.join(" · "), if pick.why.is_empty() { String::new() } else { format!(" · {}", pick.why) }), rows, 0);
|
||||
}
|
||||
|
||||
/// The game's page: its profile and its screen, each as a name and a line.
|
||||
pub fn game_cards(&self, game: &str) -> (String, String, String, String) {
|
||||
let Some(store) = self.store() else { return Default::default() };
|
||||
let r = store.assignment(game);
|
||||
let known: Vec<String> = self.library().into_iter().map(|(i, _)| i).collect();
|
||||
let (name, line) = match &r {
|
||||
Ref::Individual => ("Individual".to_string(), "Its own settings, only for this game".to_string()),
|
||||
r => {
|
||||
let others = store.games_of(r, &known).len().saturating_sub(1);
|
||||
let kind = match r { Ref::Default => "The global settings", Ref::Builtin(_) => "Built-in", _ => "Yours" };
|
||||
(store.get(r).map(|s| s.name).unwrap_or_default(), format!("{kind} · {}", match others { 0 => "no other game uses it".to_string(), n => format!("shared with {}", plural(n, "other game", "other games")) }))
|
||||
}
|
||||
};
|
||||
let p = store.effective(game).unwrap_or_default();
|
||||
let (screen, sline) = match self.outputs() {
|
||||
Ok(outs) => match resolve::for_game(&p, &self.saved_values(), &outs, &resolve::SourceFacts::default()) {
|
||||
(res, None) => (res.screen.clone(), res.summary()),
|
||||
(res, Some(why)) => (p.monitor.clone().unwrap_or_else(|| "Not chosen".into()), format!("{} · {why}", res.summary())),
|
||||
},
|
||||
Err(e) => (p.monitor.clone().unwrap_or_else(|| "Not chosen".into()), format!("The screens can't be listed here ({e})")),
|
||||
};
|
||||
(name, line, screen, sline)
|
||||
}
|
||||
|
||||
/// SUMMIT_PROFILE (a profile's or an Individual game's name), SUMMIT_PZONE (1: the right side), SUMMIT_PITEM (its
|
||||
/// focused row): where the Profiles page is, for renders and tests.
|
||||
pub fn profiles_overrides(&self, env: &dyn Fn(&str) -> Option<String>) {
|
||||
if self.ui.get_view() != 4 { return; }
|
||||
let px = self.ui.global::<Px>();
|
||||
if let Some(want) = env("SUMMIT_PROFILE") {
|
||||
let w = want.to_lowercase();
|
||||
let store = self.store();
|
||||
let hit = self.page.borrow().rows.iter().position(|k| match k {
|
||||
RowKey::Profile(r) => r.text() == w || store.as_ref().and_then(|s| s.get(r).ok()).is_some_and(|s| s.name.to_lowercase() == w),
|
||||
RowKey::Game(g) => g.to_lowercase() == w || self.game_title(g).to_lowercase().contains(&w),
|
||||
RowKey::New => w == "new", RowKey::Import => w == "import", RowKey::None => false,
|
||||
});
|
||||
if let Some(i) = hit { px.set_sel(i as i32); self.fill_profile_detail(); }
|
||||
}
|
||||
if env("SUMMIT_PZONE").is_some_and(|z| z == "1") && px.get_first_item() >= 0 { px.set_zone(1); px.set_item(px.get_first_item()); }
|
||||
if let Some(i) = env("SUMMIT_PITEM").and_then(|v| v.parse::<i32>().ok()) { px.set_zone(1); px.set_item(i); }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wire(app: &App) {
|
||||
let px = app.ui.global::<Px>();
|
||||
px.on_enter(|| with_app(|a| { a.forget_screens(); a.fill_profiles(None); }));
|
||||
px.on_select(|_| with_app(|a| a.fill_profile_detail()));
|
||||
px.on_act_row(|i| with_app(|a| a.page_row_act(i)));
|
||||
px.on_act(|i| with_app(|a| a.page_act(i)));
|
||||
px.on_ask_pick(|i| with_app(|a| a.ask_pick(i)));
|
||||
px.on_ask_cancel(|| with_app(|a| { a.dialogs.borrow_mut().asks.clear(); a.ui.global::<Px>().set_ask_open(false); }));
|
||||
px.on_name_done(|t| with_app(|a| a.name_done(&t)));
|
||||
px.on_name_cancel(|| with_app(|a| { a.dialogs.borrow_mut().named = None; a.ui.global::<Px>().set_name_open(false); }));
|
||||
let lib = app.ui.global::<Lib>();
|
||||
lib.on_pick_profile(|i| with_app(|a| { let id = a.entries.borrow().get(i.max(0) as usize).map(|e| e.id.clone()); if let Some(id) = id { a.pick_profile_for(&id); } }));
|
||||
lib.on_pick_screen(|i| with_app(|a| { let id = a.entries.borrow().get(i.max(0) as usize).map(|e| e.id.clone()); if let Some(id) = id { a.pick_screen_for(&id); } }));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
fn store(name: &str) -> Store {
|
||||
let d = std::env::temp_dir().join(format!("summit-gui-profiles-{name}-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&d);
|
||||
Store::at(d)
|
||||
}
|
||||
fn eng(pairs: &[(&str, Value)]) -> Layer { let mut l = Layer::default(); for (k, v) in pairs { l.set_engine(k, Some(v)); } l }
|
||||
fn games() -> Vec<(String, String)> { [("g:void", "Voidrunner"), ("g:star", "Starfall"), ("g:hollow", "Hollow Reach"), ("g:kart", "Kart Kings")].iter().map(|(i, t)| (i.to_string(), t.to_string())).collect() }
|
||||
|
||||
/// The owner's set-up: one profile on two games, one on the monitor and one on the projector; one game on a
|
||||
/// built-in profile; one Individual.
|
||||
fn set_up(s: &Store) -> Ref {
|
||||
let mut l = Store::blank();
|
||||
l.set_engine("motion", Some(&json!("half")));
|
||||
l.rate = Some("native".into());
|
||||
let couch = s.create("Couch", &l).unwrap();
|
||||
s.save_layer("g:void", &Layer { monitor: Some("DP-1".into()), ..Default::default() }).unwrap();
|
||||
s.save_layer("g:star", &Layer { monitor: Some("HDMI-A-1".into()), ..Default::default() }).unwrap();
|
||||
s.assign("g:void", &couch).unwrap();
|
||||
s.assign("g:star", &couch).unwrap();
|
||||
s.assign("g:hollow", &Ref::Builtin("quality".into())).unwrap();
|
||||
s.save_layer("g:kart", &Layer { profile: Some("individual".into()), monitor: Some("DP-1".into()), ..eng(&[("scaler", json!("bilinear")), ("hz", json!(120))]) }).unwrap();
|
||||
couch
|
||||
}
|
||||
fn cx<'a>(s: &'a Store, g: &'a [(String, String)], saved: &'a BTreeMap<String, Value>, outs: &'a [Output]) -> Cx<'a> {
|
||||
Cx { store: s, games: g, reg: None, saved, outs: Ok(outs), results: &[], unread: &[], results_dir: "~/.local/share/smoovplay/optimize".into() }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_list_has_the_four_sections_with_their_games() {
|
||||
let s = store("list");
|
||||
let couch = set_up(&s);
|
||||
let (g, saved, outs) = (games(), BTreeMap::new(), resolve::sample_outputs());
|
||||
let list = cx(&s, &g, &saved, &outs).list();
|
||||
let heads: Vec<&str> = list.iter().filter(|(_, l)| l.kind == 0).map(|(_, l)| l.label.as_str()).collect();
|
||||
assert_eq!(heads, ["DEFAULT", "BUILT-IN", "MY PROFILES", "INDIVIDUAL GAMES"]);
|
||||
let find = |k: &RowKey| list.iter().find(|(x, _)| x == k).map(|(_, l)| l.clone()).unwrap();
|
||||
assert_eq!(find(&RowKey::Profile(couch.clone())).detail, "Starfall, Voidrunner");
|
||||
assert_eq!(find(&RowKey::Profile(Ref::Builtin("quality".into()))).detail, "Hollow Reach");
|
||||
assert_eq!(find(&RowKey::Profile(Ref::Default)).detail, "No games");
|
||||
let kart = find(&RowKey::Game("g:kart".into()));
|
||||
assert_eq!((kart.kind, kart.label.as_str()), (2, "Kart Kings"));
|
||||
assert!(kart.detail.contains("scaler bilinear") && kart.detail.contains("hz 120"), "{}", kart.detail);
|
||||
// the order: Default, the four built-in ones, the user's, the two actions, then the games
|
||||
let keys: Vec<&RowKey> = list.iter().map(|(k, _)| k).filter(|k| **k != RowKey::None).collect();
|
||||
assert_eq!(keys.len(), 1 + 4 + 1 + 2 + 1);
|
||||
assert_eq!((keys[5], keys[6], keys[7]), (&RowKey::Profile(couch), &RowKey::New, &RowKey::Import));
|
||||
// no Individual game: the section is still there, and says so
|
||||
let empty = store("list-empty");
|
||||
let list = cx(&empty, &g, &saved, &outs).list();
|
||||
assert_eq!(list.last().unwrap().1.label, "No game has settings of its own.");
|
||||
assert_eq!(list.iter().find(|(k, _)| *k == RowKey::Profile(Ref::Default)).unwrap().1.detail, "Hollow Reach, Kart Kings, +2 more");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_profiles_page_lists_its_games_with_remove_and_each_screen() {
|
||||
let s = store("items");
|
||||
let couch = set_up(&s);
|
||||
let (g, saved, outs) = (games(), BTreeMap::new(), resolve::sample_outputs());
|
||||
let c = cx(&s, &g, &saved, &outs);
|
||||
let (title, kind, summary, items) = c.shared_items(&couch);
|
||||
assert_eq!((title.as_str(), kind.as_str()), ("Couch", "Yours"));
|
||||
assert!(summary.starts_with("Frame rate Native"), "{summary}");
|
||||
let removes: Vec<(&Act, &Line)> = items.iter().filter(|(_, l)| l.kind == 3).map(|(a, l)| (a, l)).collect();
|
||||
assert_eq!(removes.len(), 2);
|
||||
assert_eq!((removes[0].0, removes[0].1.label.as_str(), removes[0].1.button.as_str()), (&Act::Remove("g:star".into()), "Starfall", "Remove"));
|
||||
// each game's line is for its own screen
|
||||
assert_eq!(removes[0].1.detail, "on HDMI-A-1 1920x1080 60 Hz: 1920x1080 (native) · 2x = 60 fps");
|
||||
assert_eq!(removes[1].1.detail, "on DP-1 3840x2160 144 Hz: 3840x2160 (native) · 4x = 120 fps");
|
||||
// what it comes to on each connected screen, with the reason and the suggestion
|
||||
let lines: Vec<&str> = items.iter().filter(|(_, l)| l.kind == 4).map(|(_, l)| l.label.as_str()).collect();
|
||||
assert_eq!(lines, ["on DP-1 3840x2160 144 Hz: 3840x2160 (native) · 4x = 120 fps", "on HDMI-A-1 1920x1080 60 Hz: 1920x1080 (native) · 2x = 60 fps"]);
|
||||
assert!(items.iter().any(|(_, l)| l.kind == 5 && l.label.contains("Motion detail Full") && l.label.contains("60 Hz needs only 2x")));
|
||||
assert!(items.iter().any(|(_, l)| l.kind == 1 && l.label.contains("30 fps x 4 = 120 fps")));
|
||||
// the actions a user profile has; a built-in one cannot be changed, renamed or deleted
|
||||
let acts = |items: &[(Act, Line)]| items.iter().filter(|(_, l)| l.kind == 2 && l.enabled).map(|(a, _)| a.clone()).collect::<Vec<_>>();
|
||||
assert_eq!(acts(&items), [Act::Edit(couch.clone()), Act::AddGame(couch.clone()), Act::Duplicate(couch.clone()), Act::Rename(couch.clone()), Act::NewGames(couch.clone()), Act::Export(couch.clone()), Act::Delete(couch.clone())]);
|
||||
let q = Ref::Builtin("quality".into());
|
||||
let (_, kind, _, items) = c.shared_items(&q);
|
||||
assert_eq!(kind, "Built-in · read-only");
|
||||
assert_eq!(acts(&items), [Act::AddGame(q.clone()), Act::Duplicate(q.clone()), Act::NewGames(q.clone()), Act::Export(q.clone())]);
|
||||
assert!(items.iter().any(|(_, l)| !l.enabled && l.detail.contains("read-only")));
|
||||
// a pinned built-in profile on the fast monitor: the suggestion says what the screen could show
|
||||
assert!(items.iter().any(|(_, l)| l.kind == 5 && l.label.contains("up to 4x")), "{items:?}");
|
||||
// Default is in use for games without a profile: that action says so and cannot be pressed
|
||||
let (_, _, _, items) = c.shared_items(&Ref::Default);
|
||||
assert!(items.iter().any(|(a, l)| *a == Act::NewGames(Ref::Default) && !l.enabled && l.tag == "In use"));
|
||||
assert_eq!(acts(&items)[0], Act::OpenSettings);
|
||||
// no results: a clear line, marked Experimental
|
||||
assert!(items.iter().any(|(_, l)| l.kind == 0 && l.label == "BENCHMARK RESULTS" && l.tag == "Experimental"));
|
||||
assert!(items.iter().any(|(_, l)| l.kind == 1 && l.label.starts_with("No results yet.")));
|
||||
// screens that cannot be listed: said, nothing made up
|
||||
let c2 = Cx { outs: Err("no display"), ..cx(&s, &g, &saved, &outs) };
|
||||
let (_, _, _, items) = c2.shared_items(&couch);
|
||||
assert!(items.iter().all(|(_, l)| l.kind != 4));
|
||||
assert!(items.iter().any(|(_, l)| l.label.contains("can't be listed here (no display)")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_individual_games_page_and_the_results() {
|
||||
let s = store("game");
|
||||
set_up(&s);
|
||||
let (g, saved, outs) = (games(), BTreeMap::new(), resolve::sample_outputs());
|
||||
let fixture = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../summit-core/tests/fixtures/optimize");
|
||||
let (results, unread) = optimizer::read(&[fixture]);
|
||||
let unread: Vec<(String, String)> = unread.iter().map(|(p, w)| (p.display().to_string(), w.clone())).collect();
|
||||
let c = Cx { results: &results, unread: &unread, ..cx(&s, &g, &saved, &outs) };
|
||||
let (title, kind, summary, items) = c.game_items("g:kart", true);
|
||||
assert_eq!((title.as_str(), kind.as_str()), ("Kart Kings", "Individual game"));
|
||||
assert!(summary.contains("scaler bilinear"));
|
||||
let acts: Vec<&Act> = items.iter().filter(|(_, l)| l.kind == 2 && l.enabled).map(|(a, _)| a).collect();
|
||||
assert_eq!(acts[..4], [&Act::EditGame("g:kart".into()), &Act::FromGame("g:kart".into()), &Act::PickProfile("g:kart".into()), &Act::PickScreen("g:kart".into())]);
|
||||
// pinned 4x on the 144 Hz monitor
|
||||
assert!(items.iter().any(|(_, l)| l.kind == 4 && l.label == "on DP-1 3840x2160 144 Hz: 3840x2160 (native) · 4x = 120 fps"));
|
||||
// the optimizer's three, each an action; the files that could not be read are named
|
||||
assert_eq!(&acts[4..], [&Act::Result(0, 0), &Act::Result(0, 1), &Act::Result(0, 2)]);
|
||||
let first = items.iter().find(|(a, _)| *a == Act::Result(0, 0)).unwrap();
|
||||
assert!(first.1.label.starts_with("1. ") && first.1.detail.contains("avg 60 fps"), "{:?}", first.1);
|
||||
assert_eq!(items.iter().filter(|(_, l)| l.label.contains("is not read:")).count(), 3);
|
||||
assert!(items.iter().any(|(_, l)| l.label.contains("measured in Voidrunner")));
|
||||
assert!(!items.iter().any(|(_, l)| l.label.starts_with("No results yet.")));
|
||||
// a game that is not in the library here cannot be edited from this page
|
||||
let (_, _, _, items) = c.game_items("g:kart", false);
|
||||
assert!(items.iter().any(|(a, l)| *a == Act::None && !l.enabled && l.detail.contains("not in the library")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focus_moves_over_what_cannot_take_it() {
|
||||
assert_eq!(neighbours(&[false, true, false, false, true, true, false]), vec![(-1, 1), (-1, 4), (1, 4), (1, 4), (1, 5), (4, -1), (5, -1)]);
|
||||
assert_eq!(neighbours(&[]), vec![]);
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ impl Section {
|
||||
/// The engine's texts name it by its own name; in the launcher it is Summit's engine.
|
||||
fn brand(s: &str) -> String { s.replace("SmoovPlay's", "Summit's").replace("SmoovPlay", "Summit") }
|
||||
|
||||
fn heading(t: &str) -> Row { Row { kind: Kind::Heading, label: t.to_uppercase(), ..Default::default() } }
|
||||
pub fn heading(t: &str) -> Row { Row { kind: Kind::Heading, label: t.to_uppercase(), ..Default::default() } }
|
||||
pub fn note(t: impl Into<String>) -> Row { Row { kind: Kind::Note, help: t.into(), ..Default::default() } }
|
||||
|
||||
// ---- engine settings ----
|
||||
|
||||
@@ -3,7 +3,12 @@
|
||||
//! SUMMIT_SHOT=<dir> write <dir>/<name>.png and exit
|
||||
//! SUMMIT_NAME=<name> file name without extension (default "shot")
|
||||
//! SUMMIT_SIZE=1600x900 window size in pixels
|
||||
//! SUMMIT_VIEW=home|library|unfiltered|settings SUMMIT_LAYOUT=bigpicture|grid|list SUMMIT_THEME=<key>
|
||||
//! SUMMIT_VIEW=home|library|unfiltered|settings|profiles SUMMIT_LAYOUT=bigpicture|grid|list SUMMIT_THEME=<key>
|
||||
//! The Profiles page: SUMMIT_PROFILE=<a profile's or an Individual game's name, "new", "import"> the selected row
|
||||
//! SUMMIT_PZONE=1 the focus on its right side; SUMMIT_PITEM=<n> the focused row there
|
||||
//! SUMMIT_SCREENS=sample two made-up screens (DP-1 3840x2160 144 Hz, HDMI-A-1 1920x1080 60 Hz) instead of this
|
||||
//! PC's, for renders on a machine without a display
|
||||
//! SUMMIT_OPTIMIZE_DIR=<dir> where the engine's optimizer results are read from (first)
|
||||
//! SUMMIT_DETAIL=<entry id or part of a title> open that game's page
|
||||
//! SUMMIT_FOCUS=<n> focused item in the library or unfiltered list; focused row of the settings pane
|
||||
//! SUMMIT_EDITOR=1 with SUMMIT_DETAIL: the game's profile (the settings pane for that game)
|
||||
|
||||
@@ -9,6 +9,8 @@ import { SettingsView } from "settings.slint";
|
||||
import { Sx, SRow, SNav, SPreset } from "pane.slint";
|
||||
import { PlayingView } from "playing.slint";
|
||||
import { Splash } from "splash.slint";
|
||||
import { ProfilesView, AskDialog, NameDialog, Px, PRow, PItem, AskRow } from "profiles.slint";
|
||||
export { Px, PRow, PItem, AskRow }
|
||||
export { Lib, Sx, SRow, SNav, SPreset, Game, URow, Detail, PickRow, AddItem, SteamAccount, StatTile, SessRow, SessField, CmpRow, Palette }
|
||||
|
||||
component NavTab inherits Rectangle {
|
||||
@@ -64,7 +66,7 @@ export component MainWindow inherits Window {
|
||||
in-out property <int> anim-style <=> Theme.style;
|
||||
out property <[Palette]> palettes: Theme.palettes;
|
||||
in property <bool> still <=> Theme.still;
|
||||
in-out property <int> view: 0; // 0 home, 1 library, 2 unfiltered, 3 settings
|
||||
in-out property <int> view: 0; // 0 home, 1 library, 2 unfiltered, 3 settings, 4 profiles (between Unfiltered and Settings in the navbar)
|
||||
in-out property <int> zone: 1; // 0 navbar, 1 content
|
||||
in-out property <bool> detail-open: false;
|
||||
in property <image> bg-a;
|
||||
@@ -88,6 +90,14 @@ export component MainWindow inherits Window {
|
||||
root.view = v;
|
||||
if (v == 0) { home.sync(); Lib.focus-game(home.hero-idx); }
|
||||
if (v == 3) { Sx.enter(); }
|
||||
if (v == 4) { Px.zone = 0; Px.enter(); }
|
||||
}
|
||||
// the navbar's order: Home, Library, Unfiltered, Profiles, Settings
|
||||
pure function nav-pos(v: int) -> int { return v == 4 ? 3 : v == 3 ? 4 : v; }
|
||||
pure function nav-view(p: int) -> int { return p == 3 ? 4 : p == 4 ? 3 : p; }
|
||||
function nav-step(d: int, wrap: bool) {
|
||||
let p = root.nav-pos(root.view) + d;
|
||||
root.goto(root.nav-view(wrap ? Math.mod(p + 5, 5) : Math.max(0, Math.min(4, p))));
|
||||
}
|
||||
public function close-detail() {
|
||||
root.detail-open = false;
|
||||
@@ -111,25 +121,29 @@ export component MainWindow inherits Window {
|
||||
fs := FocusScope {
|
||||
key-pressed(e) => {
|
||||
if (e.text == Key.F11) { Lib.toggle-fullscreen(); return accept; }
|
||||
// the two small dialogs (a list of choices, a name) sit over everything but a running game
|
||||
if (!Lib.playing && Px.name-open) { return name.key(e) ? accept : reject; }
|
||||
if (!Lib.playing && Px.ask-open) { ask.key(e); return accept; }
|
||||
// a game is running: only the "now playing" screen takes keys
|
||||
if (Lib.playing) { playing.key(e); return accept; }
|
||||
if (Lib.add-open) { return add.key(e) || e.text == Key.Tab || e.text == Key.Backtab ? accept : reject; }
|
||||
// a game's page: its overlays take Tab too (LB / RB change section in the profile)
|
||||
if (root.detail-open) { return detail.key(e) ? accept : reject; }
|
||||
if (root.view == 3 && Lib.nvidia-open) { return settings.key(e) ? accept : reject; }
|
||||
if (e.text == Key.Backtab || (e.text == Key.Tab && e.modifiers.shift)) { root.goto(Math.mod(root.view + 3, 4)); root.zone = 1; return accept; }
|
||||
if (e.text == Key.Tab) { root.goto(Math.mod(root.view + 1, 4)); root.zone = 1; return accept; }
|
||||
if (root.view == 4 && Lib.editor-open) { return profiles.key(e) ? accept : reject; }
|
||||
if (e.text == Key.Backtab || (e.text == Key.Tab && e.modifiers.shift)) { root.nav-step(-1, true); root.zone = 1; return accept; }
|
||||
if (e.text == Key.Tab) { root.nav-step(1, true); root.zone = 1; return accept; }
|
||||
if (e.text == "/" || (e.modifiers.control && e.text == "f")) {
|
||||
if (root.view == 3) { root.zone = 1; settings.focus-search(); } else { root.goto(1); root.zone = 1; library.focus-search(); }
|
||||
return accept;
|
||||
}
|
||||
if (root.zone == 0) {
|
||||
if (e.text == Key.LeftArrow) { root.goto(Math.max(0, root.view - 1)); return accept; }
|
||||
if (e.text == Key.RightArrow) { root.goto(Math.min(3, root.view + 1)); return accept; }
|
||||
if (e.text == Key.LeftArrow) { root.nav-step(-1, false); return accept; }
|
||||
if (e.text == Key.RightArrow) { root.nav-step(1, false); return accept; }
|
||||
if (e.text == Key.DownArrow || e.text == Key.Return || e.text == " ") { root.zone = 1; return accept; }
|
||||
return reject;
|
||||
}
|
||||
if (root.view == 0 ? home.key(e) : root.view == 1 ? library.key(e) : root.view == 2 ? unfiltered.key(e) : settings.key(e)) { return accept; }
|
||||
if (root.view == 0 ? home.key(e) : root.view == 1 ? library.key(e) : root.view == 2 ? unfiltered.key(e) : root.view == 4 ? profiles.key(e) : settings.key(e)) { return accept; }
|
||||
if (e.text == Key.Escape) { if (root.view != 0) { root.goto(0); } return accept; }
|
||||
return reject;
|
||||
}
|
||||
@@ -168,6 +182,14 @@ export component MainWindow inherits Window {
|
||||
exit-up => { root.zone = 0; }
|
||||
refocus => { fs.focus(); }
|
||||
}
|
||||
profiles := ProfilesView {
|
||||
y: root.navbar-h + (root.view == 4 ? 0px : 16px); height: parent.height - root.navbar-h;
|
||||
active: root.view == 4 && root.zone == 1 && !root.detail-open;
|
||||
opacity: root.view == 4 && !root.detail-open ? 1 : 0; visible: self.opacity > 0.01;
|
||||
animate opacity { duration: Theme.ms(240); } animate y { duration: Theme.ms(320); easing: Theme.ease; }
|
||||
exit-up => { root.zone = 0; }
|
||||
refocus => { fs.focus(); }
|
||||
}
|
||||
}
|
||||
|
||||
// ---- navbar ----
|
||||
@@ -184,6 +206,7 @@ export component MainWindow inherits Window {
|
||||
VerticalLayout { alignment: center; NavTab { label: "Home"; icon: Icons.home; active: root.view == 0; focused: root.zone == 0 && root.view == 0; clicked => { root.goto(0); root.zone = 1; } } }
|
||||
VerticalLayout { alignment: center; NavTab { label: "Library"; icon: Icons.grid; active: root.view == 1; focused: root.zone == 0 && root.view == 1; clicked => { root.goto(1); root.zone = 1; } } }
|
||||
VerticalLayout { alignment: center; NavTab { label: "Unfiltered"; icon: Icons.layers; active: root.view == 2; focused: root.zone == 0 && root.view == 2; clicked => { root.goto(2); root.zone = 1; } } }
|
||||
VerticalLayout { alignment: center; NavTab { label: "Profiles"; icon: Icons.sliders; active: root.view == 4; focused: root.zone == 0 && root.view == 4; clicked => { root.goto(4); root.zone = 1; } } }
|
||||
}
|
||||
if root.width >= 1180px: Text {
|
||||
x: parent.width - Theme.pad - 60px - self.width; width: 420px; height: parent.height; horizontal-alignment: right; vertical-alignment: center;
|
||||
@@ -209,6 +232,17 @@ export component MainWindow inherits Window {
|
||||
animate opacity { duration: Theme.ms(200); }
|
||||
}
|
||||
|
||||
// ---- a list of choices, a name to type (profiles.slint): over a game's page and the profile editor too ----
|
||||
ask := AskDialog {
|
||||
height: root.height - root.hint-h;
|
||||
visible: Px.ask-open; opacity: self.visible ? 1 : 0;
|
||||
}
|
||||
name := NameDialog {
|
||||
height: root.height - root.hint-h;
|
||||
visible: Px.name-open; opacity: self.visible ? 1 : 0;
|
||||
refocus => { fs.focus(); }
|
||||
}
|
||||
|
||||
// ---- key hints (big picture) ----
|
||||
if root.hint-h > 0px: Rectangle {
|
||||
y: root.height - root.hint-h; height: root.hint-h; background: Theme.p.bg.with-alpha(0.92);
|
||||
@@ -218,7 +252,7 @@ export component MainWindow inherits Window {
|
||||
VerticalLayout { alignment: center; KeyCap { key: "Arrows"; label: "Navigate"; } }
|
||||
VerticalLayout { alignment: center; KeyCap { key: "Enter"; label: root.detail-open || Lib.add-open ? "Activate" : "Select"; } }
|
||||
if !root.detail-open && !Lib.add-open: VerticalLayout { alignment: center; KeyCap { key: "Tab"; label: "Next section"; } }
|
||||
if root.view != 3 || root.detail-open: VerticalLayout { alignment: center; KeyCap { key: "P"; label: "Pin"; } }
|
||||
if (root.view != 3 && root.view != 4) || root.detail-open: VerticalLayout { alignment: center; KeyCap { key: "P"; label: "Pin"; } }
|
||||
if root.view == 3 && !root.detail-open: VerticalLayout { alignment: center; KeyCap { key: "Del"; label: "Reset"; } }
|
||||
if (root.view == 1 || root.view == 3) && !root.detail-open: VerticalLayout { alignment: center; KeyCap { key: "/"; label: "Search"; } }
|
||||
if root.detail-open || root.view != 0: VerticalLayout { alignment: center; KeyCap { key: "Esc"; label: root.detail-open ? "Back" : "Home"; } }
|
||||
|
||||
@@ -37,9 +37,29 @@ component Field inherits Rectangle {
|
||||
}
|
||||
|
||||
|
||||
// The game's profile, and the screen it runs on: what it is now, and Enter to pick another.
|
||||
component PickCard inherits Rectangle {
|
||||
in property <string> title;
|
||||
in property <string> icon;
|
||||
in property <string> value;
|
||||
in property <string> line;
|
||||
in property <bool> focused;
|
||||
callback clicked;
|
||||
height: 76px; border-radius: Theme.r-md; horizontal-stretch: 1;
|
||||
background: root.focused ? Theme.p.raised : ta.has-hover ? Theme.p.raised.with-alpha(0.7) : Theme.p.surface.with-alpha(Theme.p.dark ? 0.78 : 0.92);
|
||||
border-width: Theme.p.border-w; border-color: Theme.p.border;
|
||||
ta := TouchArea { mouse-cursor: pointer; clicked => { root.clicked(); } }
|
||||
Icon { x: 18px; y: 28px; size: 20px; color: Theme.p.accent; commands: root.icon; }
|
||||
Text { x: 54px; y: 12px; text: root.title; color: Theme.p.dim; font-size: 10px; font-weight: 800; letter-spacing: 1.6px; }
|
||||
Text { x: 54px; y: 28px; width: parent.width - 54px - 96px; text: root.value; color: Theme.p.text; font-size: Theme.t-md; font-weight: 800; overflow: elide; }
|
||||
Text { x: 54px; y: 52px; width: parent.width - 54px - 16px; text: root.line; color: Theme.p.faint; font-size: Theme.t-xs; overflow: elide; }
|
||||
Text { x: parent.width - 96px; width: 80px; y: 22px; height: 24px; horizontal-alignment: right; vertical-alignment: center; text: "Change ›"; color: Theme.p.accent; font-size: Theme.t-sm; font-weight: 800; }
|
||||
FocusRing { on: root.focused; radius: Theme.r-md; }
|
||||
}
|
||||
|
||||
export component DetailView inherits Rectangle {
|
||||
in property <bool> open;
|
||||
in-out property <int> btn: 0; // 0 play, 1 enhance, 2 compare, 3 pin, 4 profile, 5 statistics, 6 artwork, 7 Steam account
|
||||
in-out property <int> btn: 0; // 0 play, 1 enhance, 2 compare, 3 pin, 4 profile, 5 statistics, 6 artwork, 7 Steam account, 8 its profile, 9 its screen
|
||||
callback close();
|
||||
callback refocus(); // give the keyboard back to the window (the editor's text rows)
|
||||
property <Detail> d: Lib.detail;
|
||||
@@ -62,8 +82,8 @@ export component DetailView inherits Rectangle {
|
||||
if (Lib.accounts-open) { return picker.key(e); }
|
||||
if (e.text == Key.Tab || e.text == Key.Backtab) { return true; }
|
||||
if (e.text == Key.Escape || e.text == Key.Backspace) { root.close(); }
|
||||
else if (e.text == Key.RightArrow) { root.btn = Math.min(root.d.has-account ? 7 : 6, root.btn + 1); }
|
||||
else if (e.text == Key.LeftArrow) { root.btn = Math.max(0, root.btn - 1); }
|
||||
else if (e.text == Key.RightArrow) { root.btn = Math.min(9, root.btn == 6 && !root.d.has-account ? 8 : root.btn + 1); }
|
||||
else if (e.text == Key.LeftArrow) { root.btn = Math.max(0, root.btn == 8 && !root.d.has-account ? 6 : root.btn - 1); }
|
||||
else if (e.text == Key.DownArrow) { body.content-y = Math.max(Math.min(0px, body.height - body.content-height), body.content-y - 96px); }
|
||||
else if (e.text == Key.UpArrow) { body.content-y = Math.min(0px, body.content-y + 96px); }
|
||||
else if (e.text == Key.Return || e.text == " ") {
|
||||
@@ -75,6 +95,8 @@ export component DetailView inherits Rectangle {
|
||||
else if (root.btn == 5) { Lib.open-stats(root.d.idx); }
|
||||
else if (root.btn == 6) { Lib.change-art(root.d.idx); }
|
||||
else if (root.btn == 7) { Lib.open-accounts(root.d.idx); }
|
||||
else if (root.btn == 8) { Lib.pick-profile(root.d.idx); }
|
||||
else if (root.btn == 9) { Lib.pick-screen(root.d.idx); }
|
||||
} else if (e.text == "p" || e.text == "P") { Lib.toggle-pin(root.d.idx); }
|
||||
else if (e.text == "e" || e.text == "E") { if (root.d.can-enhance) { Lib.toggle-enhance(root.d.idx); } }
|
||||
else { return false; }
|
||||
@@ -135,8 +157,14 @@ export component DetailView inherits Rectangle {
|
||||
text: "Change ›"; color: Theme.p.accent; font-size: Theme.t-sm; font-weight: 800; }
|
||||
FocusRing { on: root.open && root.btn == 7; radius: Theme.r-md; }
|
||||
}
|
||||
HorizontalLayout { spacing: 16px;
|
||||
PickCard { title: "PROFILE"; icon: Icons.sliders; value: root.d.prof-name; line: root.d.prof-line; focused: root.open && root.btn == 8; clicked => { root.btn = 8; Lib.pick-profile(root.d.idx); } }
|
||||
PickCard { title: "SCREEN"; icon: Icons.monitor; value: root.d.screen-name; line: root.d.screen-line; focused: root.open && root.btn == 9; clicked => { root.btn = 9; Lib.pick-screen(root.d.idx); } }
|
||||
}
|
||||
Text {
|
||||
text: root.btn == 7 ? "Which Steam account this game is played on. Play switches Steam to it first (Steam closes and starts again signed in as it). Automatic: the account it was last played on."
|
||||
text: root.btn == 9 ? "Which screen this game runs on. It stays with the game whatever profile it uses: the profile's output size and frame multiplier are worked out for this screen when the game starts."
|
||||
: root.btn == 8 ? "The profile this game uses: Default, a built-in one, one of yours, or Individual (its own settings). A shared profile's changes reach every game on it."
|
||||
: root.btn == 7 ? "Which Steam account this game is played on. Play switches Steam to it first (Steam closes and starts again signed in as it). Automatic: the account it was last played on."
|
||||
: root.btn == 6 ? "Change artwork: pick a cover image (PNG, JPEG or WebP; portrait 2:3 looks best). Summit keeps a link to the file, so leave it where it is."
|
||||
: root.btn == 5 ? "Statistics: the time played and the sessions Summit counted, and the session summaries the engine has written for this game (duration, frame rates, the settings it ran with)."
|
||||
: root.btn == 4 ? "Profile: everything this game launches with. Monitor and mode, window mode, focus, launch arguments and environment, and every engine setting (frame generation, upscaling, overlay, clips), each following the global one in Settings until you change it here. Presets too."
|
||||
|
||||
@@ -42,7 +42,8 @@ export struct SPreset { name: string, summary: string, detail: string, sets: [st
|
||||
export global Sx {
|
||||
in property <string> title;
|
||||
in property <string> subtitle;
|
||||
in property <bool> game; // a game's profile, not the Settings page
|
||||
in property <bool> game; // a game's profile (or a shared profile), not the Settings page
|
||||
in property <string> own-tag: "THIS GAME'S OWN"; // on a row the game (or the profile) sets itself
|
||||
in property <[SNav]> nav;
|
||||
in-out property <int> section;
|
||||
in property <[SRow]> rows; // the section's rows, or the search results
|
||||
@@ -253,7 +254,7 @@ component Details inherits Rectangle {
|
||||
if root.show-row && (root.r.experimental || root.r.tag != "" || root.r.changed): HorizontalLayout { alignment: start; spacing: 6px;
|
||||
if root.r.experimental: Pill { text: "EXPERIMENTAL"; tint: Theme.p.accent; }
|
||||
if root.r.tag != "": Pill { text: root.r.tag; }
|
||||
if root.r.changed: Pill { text: Sx.game ? "THIS GAME'S OWN" : "CHANGED"; tint: Theme.p.accent; }
|
||||
if root.r.changed: Pill { text: Sx.game ? Sx.own-tag : "CHANGED"; tint: Theme.p.accent; }
|
||||
}
|
||||
if root.show-row && root.r.off: Text { text: root.r.why; color: Theme.p.text; font-size: Theme.t-sm; font-italic: true; wrap: word-wrap; }
|
||||
if root.show-row && root.r.help != "": Text { text: root.r.help; color: Theme.p.dim; font-size: Theme.t-sm; wrap: word-wrap; }
|
||||
@@ -279,7 +280,7 @@ component Details inherits Rectangle {
|
||||
|
||||
if !root.show-row && !root.show-preset: Text { text: root.nav.label; color: Theme.p.text; font-size: Theme.t-lg; font-weight: 800; wrap: word-wrap; }
|
||||
if !root.show-row && !root.show-preset: Text {
|
||||
text: root.nav.count + (root.nav.count == 1 ? " setting" : " settings") + (root.nav.changed > 0 ? ", " + root.nav.changed + (Sx.game ? " the game's own" : " changed") : "");
|
||||
text: root.nav.count + (root.nav.count == 1 ? " setting" : " settings") + (root.nav.changed > 0 ? ", " + root.nav.changed + (Sx.game ? " its own" : " changed") : "");
|
||||
color: Theme.p.dim; font-size: Theme.t-sm; wrap: word-wrap; }
|
||||
if !root.show-row && !root.show-preset: Text {
|
||||
text: "Right or Enter opens the section. In a row, Left and Right change the value, Delete puts it back, Esc comes back here. Page Up and Page Down change section from anywhere; / searches every section.";
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
// Profiles: every shared profile and every Individual game on the left, what the chosen one is on the right (its
|
||||
// actions, the games on it with Remove, what it comes to on each screen, suggestions, benchmark results). Two small
|
||||
// dialogs are shared with the game's page and the settings pane: a list of choices, and a name to type.
|
||||
// Everything is in Px; the lists are built in Rust (src/profiles.rs).
|
||||
import { Theme } from "theme.slint";
|
||||
import { Icon, Icons, Btn, Tag, FocusRing } from "widgets.slint";
|
||||
import { ProfileEditor } from "editor.slint";
|
||||
import { Lib } from "widgets.slint";
|
||||
|
||||
// A row of the list on the left. kind: 0 heading, 1 profile, 2 Individual game, 3 action (new, import), 4 a note
|
||||
export struct PRow { kind: int, label: string, detail: string, tag: string, up: int, down: int }
|
||||
// A row on the right. kind: 0 heading, 1 note, 2 action, 3 a game on the profile (its button removes it),
|
||||
// 4 what it comes to on one screen, 5 a suggestion
|
||||
export struct PItem { kind: int, label: string, detail: string, button: string, tag: string, enabled: bool, up: int, down: int }
|
||||
// (up, down: the row above and below that can be picked; -1: none)
|
||||
export struct AskRow { label: string, detail: string, tag: string, enabled: bool, up: int, down: int }
|
||||
|
||||
export global Px {
|
||||
in property <[PRow]> rows;
|
||||
in-out property <int> sel;
|
||||
in property <string> title;
|
||||
in property <string> kind; // "Built-in · read-only", "Yours", "Individual game"
|
||||
in property <string> summary;
|
||||
in property <[PItem]> items;
|
||||
in property <int> first-item: -1; // the first row on the right that can take the focus
|
||||
in-out property <int> item;
|
||||
in-out property <int> zone; // 0 the list, 1 the right side
|
||||
callback enter(); // the page was opened: build it from the files
|
||||
callback select(int);
|
||||
callback act-row(int); // Enter on an action row of the list
|
||||
callback act(int); // Enter on a row of the right side
|
||||
// a list of choices
|
||||
in-out property <bool> ask-open;
|
||||
in property <string> ask-title;
|
||||
in property <string> ask-note;
|
||||
in property <[AskRow]> ask-rows;
|
||||
in-out property <int> ask-sel;
|
||||
callback ask-pick(int);
|
||||
callback ask-cancel();
|
||||
// a name to type
|
||||
in-out property <bool> name-open;
|
||||
in property <string> name-title;
|
||||
in property <string> name-note;
|
||||
in-out property <string> name-text;
|
||||
in property <string> name-error;
|
||||
callback name-done(string);
|
||||
callback name-cancel();
|
||||
}
|
||||
|
||||
component ListRow inherits Rectangle {
|
||||
in property <PRow> r;
|
||||
in property <bool> selected;
|
||||
in property <bool> focused;
|
||||
callback clicked;
|
||||
callback reveal(length, length);
|
||||
height: root.r.kind == 0 ? 34px : root.r.kind == 4 ? 32px : root.r.kind == 3 ? 40px : 52px;
|
||||
changed selected => { if (root.selected) { root.reveal(self.y, self.height); } }
|
||||
if root.r.kind == 0: Text { x: 14px; y: 14px; text: root.r.label; color: Theme.p.dim; font-size: 10px; font-weight: 800; letter-spacing: 1.6px; }
|
||||
if root.r.kind == 4: Text { x: 14px; width: parent.width - 28px; height: parent.height; text: root.r.label; color: Theme.p.faint; font-size: Theme.t-sm; vertical-alignment: center; overflow: elide; }
|
||||
if root.r.kind != 0 && root.r.kind != 4: Rectangle {
|
||||
border-radius: Theme.r-md;
|
||||
background: root.selected ? Theme.p.raised : ta.has-hover ? Theme.p.raised.with-alpha(0.5) : transparent;
|
||||
border-width: root.selected ? Theme.p.border-w : 0px; border-color: Theme.p.border;
|
||||
ta := TouchArea { mouse-cursor: pointer; clicked => { root.clicked(); } }
|
||||
if root.r.kind == 3: Icon { x: 14px; y: 11px; size: 18px; color: Theme.p.accent; commands: Icons.plus; }
|
||||
// (an action is one line: what it does shows on the right when it is selected)
|
||||
if root.r.kind == 3: Text { x: 42px; width: parent.width - 56px; height: parent.height; text: root.r.label; vertical-alignment: center;
|
||||
color: Theme.p.text; font-size: Theme.t-md; font-weight: root.selected ? 800 : 600; overflow: elide; }
|
||||
if root.r.kind != 3: Text { x: 14px; y: 7px; width: parent.width - 28px - (root.r.tag == "" ? 0px : tg.width + 8px); text: root.r.label;
|
||||
color: Theme.p.text; font-size: Theme.t-md; font-weight: root.selected ? 800 : 600; overflow: elide; }
|
||||
if root.r.kind != 3: Text { x: 14px; y: 30px; width: parent.width - 28px; text: root.r.detail; color: Theme.p.dim; font-size: Theme.t-xs; overflow: elide; }
|
||||
tg := Tag { visible: root.r.tag != ""; x: parent.width - self.width - 10px; y: 8px; text: root.r.tag; tint: Theme.p.accent; }
|
||||
FocusRing { on: root.focused; radius: Theme.r-md; }
|
||||
}
|
||||
}
|
||||
|
||||
component ItemRow inherits Rectangle {
|
||||
in property <PItem> r;
|
||||
in property <bool> focused;
|
||||
callback clicked;
|
||||
callback reveal(length, length);
|
||||
property <bool> can: root.r.kind == 2 || root.r.kind == 3;
|
||||
changed focused => { if (root.focused) { root.reveal(self.y, self.height); } }
|
||||
VerticalLayout {
|
||||
if root.r.kind == 0: Rectangle { height: 44px;
|
||||
Text { x: 4px; y: 22px; text: root.r.label; color: Theme.p.dim; font-size: 10px; font-weight: 800; letter-spacing: 1.6px; }
|
||||
if root.r.tag != "": Tag { x: parent.width - self.width; y: 14px; text: root.r.tag; tint: Theme.p.accent; }
|
||||
}
|
||||
if root.r.kind == 1 || root.r.kind == 5: HorizontalLayout { padding-left: root.r.kind == 5 ? 4px : 20px; padding-top: 3px; padding-bottom: 3px; spacing: 8px;
|
||||
if root.r.kind == 5: Text { text: "Suggestion"; color: Theme.p.accent; font-size: Theme.t-xs; font-weight: 800; vertical-alignment: top; }
|
||||
Text { text: root.r.label; color: root.r.kind == 5 ? Theme.p.text : Theme.p.dim; font-size: Theme.t-sm; wrap: word-wrap; horizontal-stretch: 1; }
|
||||
}
|
||||
if root.r.kind == 4: Rectangle { height: 34px;
|
||||
Icon { x: 4px; y: 9px; size: 16px; color: Theme.p.accent; commands: Icons.monitor; }
|
||||
Text { x: 30px; width: parent.width - 30px; height: parent.height; text: root.r.label; color: Theme.p.text; font-size: Theme.t-md; font-weight: 700; vertical-alignment: center; overflow: elide; }
|
||||
}
|
||||
if root.can: Rectangle { height: 58px;
|
||||
Rectangle { y: 3px; height: 52px; border-radius: Theme.r-md;
|
||||
background: root.focused ? Theme.p.raised : ta.has-hover && root.r.enabled ? Theme.p.raised.with-alpha(0.6) : Theme.p.surface.with-alpha(Theme.p.dark ? 0.7 : 0.9);
|
||||
border-width: Theme.p.border-w; border-color: Theme.p.border;
|
||||
ta := TouchArea { mouse-cursor: root.r.enabled ? pointer : default; clicked => { root.clicked(); } }
|
||||
Text { x: 16px; y: 7px; width: parent.width - 32px - bt.width - (root.r.tag == "" ? 0px : tg.width + 10px); text: root.r.label;
|
||||
color: root.r.enabled ? Theme.p.text : Theme.p.faint; font-size: Theme.t-md; font-weight: 700; overflow: elide; }
|
||||
Text { x: 16px; y: 29px; width: parent.width - 32px - bt.width; text: root.r.detail; color: root.r.enabled ? Theme.p.dim : Theme.p.faint; font-size: Theme.t-xs; overflow: elide; }
|
||||
tg := Tag { visible: root.r.tag != ""; x: parent.width - bt.width - self.width - 22px; y: 6px; text: root.r.tag; tint: Theme.p.accent; }
|
||||
bt := Text { x: parent.width - self.width - 16px; height: parent.height; text: root.r.button == "" ? "" : root.r.button + " ›"; vertical-alignment: center;
|
||||
color: root.r.enabled ? Theme.p.accent : Theme.p.faint; font-size: Theme.t-sm; font-weight: 800; }
|
||||
FocusRing { on: root.focused; radius: Theme.r-md; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export component ProfilesView inherits Rectangle {
|
||||
in property <bool> active;
|
||||
callback exit-up();
|
||||
callback refocus();
|
||||
property <length> pad: Theme.pad;
|
||||
property <length> lw: Math.clamp(root.width * 0.3, 280px, 460px);
|
||||
|
||||
function show-left(y: length, h: length) {
|
||||
if (y + left.content-y < 0px) { left.content-y = -y; }
|
||||
else if (y + h + left.content-y > left.height) { left.content-y = left.height - y - h; }
|
||||
}
|
||||
function show-right(y: length, h: length) {
|
||||
if (y + right.content-y < 0px) { right.content-y = -y; }
|
||||
else if (y + h + right.content-y > right.height) { right.content-y = right.height - y - h; }
|
||||
}
|
||||
public function key(e: KeyEvent) -> bool {
|
||||
if (Lib.editor-open) { return editor.key(e); }
|
||||
if (Px.zone == 0) {
|
||||
if (e.text == Key.UpArrow) {
|
||||
if (Px.rows[Px.sel].up < 0) { root.exit-up(); } else { Px.sel = Px.rows[Px.sel].up; Px.select(Px.sel); right.content-y = 0; }
|
||||
} else if (e.text == Key.DownArrow) {
|
||||
if (Px.rows[Px.sel].down >= 0) { Px.sel = Px.rows[Px.sel].down; Px.select(Px.sel); right.content-y = 0; }
|
||||
} else if (e.text == Key.RightArrow || e.text == Key.Return || e.text == " ") {
|
||||
if (Px.rows[Px.sel].kind == 3) { if (e.text != Key.RightArrow) { Px.act-row(Px.sel); } }
|
||||
else if (Px.first-item >= 0) { Px.item = Px.first-item; Px.zone = 1; }
|
||||
} else if (e.text == Key.LeftArrow) {
|
||||
} else { return false; }
|
||||
return true;
|
||||
}
|
||||
if (e.text == Key.UpArrow) { if (Px.items[Px.item].up >= 0) { Px.item = Px.items[Px.item].up; } else { right.content-y = 0; } }
|
||||
else if (e.text == Key.DownArrow) { if (Px.items[Px.item].down >= 0) { Px.item = Px.items[Px.item].down; } else { right.content-y = Math.min(0px, right.height - right.content-height); } }
|
||||
else if (e.text == Key.LeftArrow || e.text == Key.Escape || e.text == Key.Backspace) { Px.zone = 0; }
|
||||
else if (e.text == Key.Return || e.text == " ") { Px.act(Px.item); }
|
||||
else if (e.text == Key.RightArrow) { }
|
||||
else { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
Text { x: root.pad; y: 8px; text: "Profiles"; color: Theme.p.text; font-size: Theme.t-xl; font-weight: 800; }
|
||||
Text { x: root.pad; y: 42px; width: root.width - 2 * root.pad; color: Theme.p.dim; font-size: Theme.t-sm; overflow: elide;
|
||||
text: "Every game is on one: Default, a built-in one, one of yours, or its own settings. A change to a profile reaches every game on it."; }
|
||||
|
||||
// ---- the list ----
|
||||
left := Flickable {
|
||||
x: root.pad - 8px; y: 76px; width: root.lw; height: root.height - 76px - 34px;
|
||||
content-width: self.width; content-height: lcol.preferred-height + 12px;
|
||||
animate content-y { duration: Theme.ms(160); easing: ease-out; }
|
||||
lcol := VerticalLayout {
|
||||
x: 4px; width: parent.width - 8px; alignment: start; spacing: 2px;
|
||||
for r[i] in Px.rows: ListRow {
|
||||
r: r; selected: Px.sel == i; focused: root.active && Px.zone == 0 && Px.sel == i && !Px.ask-open && !Px.name-open;
|
||||
clicked => { Px.zone = 0; Px.sel = i; Px.select(i); if (r.kind == 3) { Px.act-row(i); } }
|
||||
reveal(y, h) => { root.show-left(y, h); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle { x: root.pad + root.lw + 8px; y: 76px; width: 1px; height: root.height - 76px - 34px; background: Theme.p.border.with-alpha(0.7); }
|
||||
|
||||
// ---- the chosen one ----
|
||||
Rectangle {
|
||||
x: root.pad + root.lw + 32px; y: 76px; width: root.width - self.x - root.pad; height: root.height - 76px - 34px;
|
||||
HorizontalLayout { x: 0; y: 4px; height: 32px; spacing: 12px; alignment: start;
|
||||
Text { text: Px.title; color: Theme.p.text; font-size: Theme.t-xl; font-weight: 800; vertical-alignment: center; }
|
||||
VerticalLayout { alignment: center; if Px.kind != "": Tag { text: Px.kind; } }
|
||||
}
|
||||
Text { x: 0; y: 42px; width: parent.width; text: Px.summary; color: Theme.p.dim; font-size: Theme.t-sm; overflow: elide; }
|
||||
right := Flickable {
|
||||
x: 0; y: 70px; width: parent.width; height: parent.height - 70px;
|
||||
content-width: self.width; content-height: rcol.preferred-height + 24px;
|
||||
animate content-y { duration: Theme.ms(160); easing: ease-out; }
|
||||
rcol := VerticalLayout {
|
||||
x: 4px; width: parent.width - 12px; alignment: start;
|
||||
for it[i] in Px.items: ItemRow {
|
||||
r: it; focused: root.active && Px.zone == 1 && Px.item == i && !Px.ask-open && !Px.name-open && !Lib.editor-open;
|
||||
clicked => { if (it.enabled) { Px.zone = 1; Px.item = i; Px.act(i); } }
|
||||
reveal(y, h) => { root.show-right(y, h); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Text { x: root.pad; y: root.height - 26px; width: root.width - 2 * root.pad; horizontal-alignment: center; color: Theme.p.faint; font-size: Theme.t-xs; overflow: elide;
|
||||
text: Px.zone == 0 ? "Up / Down: profile or game · Right, Enter: its page · Tab: next view" : "Up / Down: move · Enter: do it · Left, Esc: back to the list"; }
|
||||
|
||||
editor := ProfileEditor {
|
||||
visible: Lib.editor-open && root.visible; opacity: self.visible ? 1 : 0;
|
||||
close => { Lib.close-profile(); }
|
||||
refocus => { root.refocus(); }
|
||||
}
|
||||
}
|
||||
|
||||
// A list of choices: Up/Down, Enter picks, Esc cancels. Rows that cannot be picked are greyed and skipped.
|
||||
export component AskDialog inherits Rectangle {
|
||||
property <length> step: 68px;
|
||||
function reveal() {
|
||||
let y = Px.ask-sel * root.step;
|
||||
if (y + list.content-y < 0px) { list.content-y = -y; }
|
||||
else if (y + 60px + list.content-y > list.height) { list.content-y = list.height - y - 60px; }
|
||||
}
|
||||
function move(d: int) {
|
||||
let i = d > 0 ? Px.ask-rows[Px.ask-sel].down : Px.ask-rows[Px.ask-sel].up;
|
||||
if (i >= 0) { Px.ask-sel = i; root.reveal(); }
|
||||
}
|
||||
public function key(e: KeyEvent) -> bool {
|
||||
if (e.text == Key.Escape || e.text == Key.Backspace) { Px.ask-cancel(); }
|
||||
else if (e.text == Key.DownArrow) { root.move(1); }
|
||||
else if (e.text == Key.UpArrow) { root.move(-1); }
|
||||
else if (e.text == Key.Return || e.text == " ") { if (Px.ask-rows[Px.ask-sel].enabled) { Px.ask-pick(Px.ask-sel); } }
|
||||
return true;
|
||||
}
|
||||
changed visible => { if (self.visible) { list.content-y = 0; root.reveal(); } }
|
||||
|
||||
background: Theme.p.bg.with-alpha(0.82);
|
||||
TouchArea { clicked => { Px.ask-cancel(); } }
|
||||
Rectangle {
|
||||
property <length> w: Math.min(root.width - 48px, 860px);
|
||||
property <length> head: 72px + note.preferred-height;
|
||||
property <length> h: Math.min(root.height - 32px, self.head + Px.ask-rows.length * root.step + 44px);
|
||||
x: (root.width - self.w) / 2; width: self.w; y: (root.height - self.h) / 2; height: self.h;
|
||||
border-radius: Theme.r-lg; background: Theme.p.bg2; border-width: Theme.p.border-w; border-color: Theme.p.border;
|
||||
drop-shadow-blur: 40px; drop-shadow-color: #00000090;
|
||||
TouchArea { }
|
||||
Text { x: 24px; y: 20px; width: parent.width - 48px; text: Px.ask-title; color: Theme.p.text; font-size: Theme.t-lg; font-weight: 800; overflow: elide; }
|
||||
note := Text { x: 24px; y: 52px; width: parent.width - 48px; text: Px.ask-note; color: Theme.p.dim; font-size: Theme.t-sm; wrap: word-wrap; }
|
||||
list := Flickable {
|
||||
x: 20px; y: parent.head; width: parent.width - 40px; height: parent.height - parent.head - 40px;
|
||||
content-width: self.width; content-height: Px.ask-rows.length * root.step;
|
||||
animate content-y { duration: Theme.ms(160); easing: ease-out; }
|
||||
for r[i] in Px.ask-rows: Rectangle {
|
||||
x: 0; y: i * root.step; width: parent.width; height: 60px; border-radius: Theme.r-md;
|
||||
background: Px.ask-sel == i ? Theme.p.raised : ta.has-hover && r.enabled ? Theme.p.raised.with-alpha(0.6) : Theme.p.surface.with-alpha(0.7);
|
||||
border-width: Theme.p.border-w; border-color: Theme.p.border;
|
||||
ta := TouchArea { mouse-cursor: r.enabled ? pointer : default; clicked => { if (r.enabled) { Px.ask-sel = i; Px.ask-pick(i); } } }
|
||||
Text { x: 18px; y: 10px; width: parent.width - 36px - (r.tag == "" ? 0px : tg.width + 10px); text: r.label; color: r.enabled ? Theme.p.text : Theme.p.faint; font-size: Theme.t-md; font-weight: 800; overflow: elide; }
|
||||
Text { x: 18px; y: 34px; width: parent.width - 36px; text: r.detail; color: r.enabled ? Theme.p.dim : Theme.p.faint; font-size: Theme.t-xs; overflow: elide; }
|
||||
tg := Tag { visible: r.tag != ""; x: parent.width - self.width - 14px; y: 8px; text: r.tag; tint: Theme.p.accent; dot: true; }
|
||||
FocusRing { on: Px.ask-sel == i; radius: Theme.r-md; }
|
||||
}
|
||||
}
|
||||
Text { x: 20px; y: parent.height - 30px; width: parent.width - 40px; horizontal-alignment: center; color: Theme.p.faint; font-size: Theme.t-xs;
|
||||
text: "Up / Down: choose · Enter: pick · Esc: cancel"; }
|
||||
}
|
||||
}
|
||||
|
||||
// A name: it comes filled in, so Enter (or A on a controller) takes it as it is; typing changes it.
|
||||
export component NameDialog inherits Rectangle {
|
||||
callback refocus();
|
||||
public function key(e: KeyEvent) -> bool {
|
||||
if (e.text == Key.Escape) { Px.name-cancel(); }
|
||||
else if (e.text == Key.Return) { Px.name-done(Px.name-text); }
|
||||
else { input.focus(); return false; }
|
||||
return true;
|
||||
}
|
||||
changed visible => { if (self.visible) { input.focus(); input.select-all(); } else { root.refocus(); } }
|
||||
background: Theme.p.bg.with-alpha(0.82);
|
||||
TouchArea { clicked => { Px.name-cancel(); } }
|
||||
Rectangle {
|
||||
property <length> w: Math.min(root.width - 48px, 640px);
|
||||
x: (root.width - self.w) / 2; width: self.w; height: col.preferred-height; y: (root.height - self.height) / 2;
|
||||
border-radius: Theme.r-lg; background: Theme.p.bg2; border-width: Theme.p.border-w; border-color: Theme.p.border;
|
||||
drop-shadow-blur: 40px; drop-shadow-color: #00000090;
|
||||
TouchArea { }
|
||||
col := VerticalLayout { padding: 24px; spacing: 12px;
|
||||
Text { text: Px.name-title; color: Theme.p.text; font-size: Theme.t-lg; font-weight: 800; wrap: word-wrap; }
|
||||
Text { text: Px.name-note; color: Theme.p.dim; font-size: Theme.t-sm; wrap: word-wrap; }
|
||||
Rectangle { height: 44px; border-radius: 10px; background: Theme.p.surface; border-width: 2px; border-color: Theme.p.accent;
|
||||
input := TextInput {
|
||||
x: 14px; width: parent.width - 28px; height: parent.height; vertical-alignment: center; single-line: true;
|
||||
text <=> Px.name-text; color: Theme.p.text; font-size: Theme.t-md; selection-background-color: Theme.p.accent; selection-foreground-color: Theme.p.on-accent;
|
||||
accepted => { Px.name-done(self.text); }
|
||||
key-pressed(e) => {
|
||||
if (e.text == Key.Escape) { Px.name-cancel(); return accept; }
|
||||
return reject;
|
||||
}
|
||||
}
|
||||
}
|
||||
if Px.name-error != "": Text { text: Px.name-error; color: #e0a43a; font-size: Theme.t-sm; wrap: word-wrap; }
|
||||
Text { text: "Enter: save · Esc: cancel"; color: Theme.p.faint; font-size: Theme.t-xs; horizontal-alignment: center; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,10 @@ export struct Detail {
|
||||
account: SteamAccount, // the account Play starts it on (login "": whichever account Steam is on)
|
||||
account-note: string, // why that one
|
||||
compare-note: string, // what Compare does here, or why it cannot
|
||||
prof-name: string, // the profile the game is on: "Couch", "Individual"
|
||||
prof-line: string, // "Shared with 2 games: ...", "Its own settings"
|
||||
screen-name: string, // the screen it runs on: "DP-1", "Not chosen"
|
||||
screen-line: string, // what its profile comes to there
|
||||
}
|
||||
|
||||
// A window in the "pick the game's window" list: what it shows, and whether it opened after Play was pressed.
|
||||
@@ -185,6 +189,9 @@ export global Lib {
|
||||
callback pick-show();
|
||||
callback pick-choose(int);
|
||||
callback pick-close();
|
||||
// a game's page: pick its profile, pick its screen (profiles.slint's list of choices)
|
||||
callback pick-profile(int);
|
||||
callback pick-screen(int);
|
||||
}
|
||||
|
||||
// 24x24 line icons, drawn as paths so they follow the theme and scale cleanly.
|
||||
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/bin/sh
|
||||
# Regenerate docs/media/profiles/: headless renders (software renderer, no display needed) of the Profiles page, a
|
||||
# profile's games and per-screen lines, the "change the profile or make individual" prompt and a game's page with its
|
||||
# profile and screen pickers, each in two themes. Static frames: no animation is shown or checked by these.
|
||||
# docs/demo/profiles-shots.sh [path/to/debug-dir] (default: $CARGO_TARGET_DIR/debug or target/debug)
|
||||
# The demo library is invented (make_demo_home.py). The profiles are made here with the real `summit profile`
|
||||
# commands. SUMMIT_SCREENS=sample gives the launcher two MADE-UP screens (DP-1 3840x2160 144 Hz, HDMI-A-1 1920x1080
|
||||
# 60 Hz): this host has no display. The benchmark result shown in one render is the test fixture
|
||||
# (crates/summit-core/tests/fixtures/optimize: the engine's format, numbers from a fake measurer, not measured).
|
||||
set -e
|
||||
cd "$(dirname "$0")/../.."
|
||||
ROOT=$PWD
|
||||
BIN=${1:-${CARGO_TARGET_DIR:-$ROOT/target}/debug}
|
||||
DEMO=${SUMMIT_DEMO_HOME:-/tmp/summit-profiles-demo}
|
||||
OUT=$ROOT/docs/media/profiles
|
||||
PY=${PYTHON:-python3}
|
||||
rm -rf "$DEMO"
|
||||
$PY docs/demo/make_demo_home.py "$DEMO" >/dev/null
|
||||
mkdir -p "$OUT"
|
||||
E="env HOME=$DEMO XDG_CONFIG_HOME=$DEMO/.config XDG_DATA_HOME=$DEMO/.local/share XDG_CACHE_HOME=$DEMO/.cache XDG_STATE_HOME=$DEMO/.local/state SUMMIT_ENGINE=$ROOT/engine SUMMIT_SCREENS=sample"
|
||||
S="$E $BIN/summit"
|
||||
# The demo's Voidrunner has a profile file from an older Summit: the first command migrates it (it becomes an
|
||||
# Individual game, with a backup). Then the owner's set-up: one profile, two games, two screens.
|
||||
$S profile list >/dev/null
|
||||
$S profile new "Couch" >/dev/null
|
||||
$S profile edit couch --set scaler=fsr --set motion=half --set vsync=true >/dev/null
|
||||
$S profile reset custom:voidrunner width height refresh_hz >/dev/null
|
||||
$S profile set custom:voidrunner --monitor DP-1 --window-mode borderless --enhance true >/dev/null # the desk monitor
|
||||
$S profile set steam:900001 --monitor HDMI-A-1 --window-mode borderless --enhance true >/dev/null # Ember Circuit: the projector
|
||||
$S profile assign custom:voidrunner couch >/dev/null
|
||||
$S profile assign steam:900001 couch >/dev/null
|
||||
$S profile assign steam:900003 quality >/dev/null # Starlane Drifters
|
||||
$S profile assign steam:900002 performance >/dev/null # Hollow Tide
|
||||
$S profile set steam:900007 --monitor DP-1 --upscaler rtx-vsr --multiplier 3 --individual >/dev/null # Rustwake: its own settings
|
||||
$S profile set steam:900009 --upscaler bilinear --framegen none --individual >/dev/null # Thornfield Rally: its own settings
|
||||
run() { # run <name> VAR=value...
|
||||
n=$1; shift
|
||||
$E SUMMIT_SHOT="$OUT" SUMMIT_NAME="$n" "$@" "$BIN/summit-gui" "$DEMO/Games" >/dev/null
|
||||
}
|
||||
both() { # both <name> <theme2> VAR=value...: midnight and one more theme
|
||||
name=$1; t2=$2; shift 2
|
||||
run "$name-midnight" SUMMIT_THEME=midnight "$@"
|
||||
run "$name-$t2" SUMMIT_THEME=$t2 "$@"
|
||||
}
|
||||
G=custom:voidrunner
|
||||
both profiles-page daylight SUMMIT_VIEW=profiles SUMMIT_PROFILE=couch
|
||||
both profile-games steam SUMMIT_VIEW=profiles SUMMIT_PROFILE=couch SUMMIT_KEYS="Right Down Down Down Down Down Down Down"
|
||||
both profile-screens violet SUMMIT_VIEW=profiles SUMMIT_PROFILE=couch SUMMIT_KEYS="Right Down Down Down Down Down Down Down Down Down"
|
||||
both profile-builtin oled SUMMIT_VIEW=profiles SUMMIT_PROFILE=quality SUMMIT_KEYS="Right"
|
||||
both profile-individual daylight SUMMIT_VIEW=profiles SUMMIT_PROFILE=rustwake SUMMIT_KEYS="Right Down"
|
||||
both profile-results steam SUMMIT_VIEW=profiles SUMMIT_PROFILE=rustwake SUMMIT_OPTIMIZE_DIR="$ROOT/crates/summit-core/tests/fixtures/optimize" SUMMIT_KEYS="Right Down Down Down Down Down Down"
|
||||
both profile-new-name contrast SUMMIT_VIEW=profiles SUMMIT_PROFILE=new SUMMIT_KEYS="Enter"
|
||||
both profile-delete violet SUMMIT_VIEW=profiles SUMMIT_PROFILE=couch SUMMIT_KEYS="Right Down Down Down Down Down Down Enter"
|
||||
both profile-edit daylight SUMMIT_VIEW=profiles SUMMIT_PROFILE=couch SUMMIT_KEYS="Right Enter"
|
||||
both change-or-individual steam SUMMIT_DETAIL=$G SUMMIT_EDITOR=1 SUMMIT_SECTION=upscaling SUMMIT_ZONE=3 SUMMIT_KEYS="Right"
|
||||
both game-page daylight SUMMIT_DETAIL=$G SUMMIT_KEYS="Right Right Right Right Right Right Right" XDG_SESSION_TYPE=x11 DISPLAY=:99
|
||||
both game-profile-picker oled SUMMIT_DETAIL=$G SUMMIT_KEYS="Right Right Right Right Right Right Right Enter" XDG_SESSION_TYPE=x11 DISPLAY=:99
|
||||
both game-screen-picker violet SUMMIT_DETAIL=$G SUMMIT_KEYS="Right Right Right Right Right Right Right Right Enter" XDG_SESSION_TYPE=x11 DISPLAY=:99
|
||||
both game-settings-screen steam SUMMIT_DETAIL=$G SUMMIT_EDITOR=1 SUMMIT_SECTION=screen SUMMIT_ZONE=3
|
||||
run profiles-small-contrast SUMMIT_THEME=contrast SUMMIT_LAYOUT=list SUMMIT_SIZE=1024x640 SUMMIT_VIEW=profiles SUMMIT_PROFILE=couch
|
||||
ls "$OUT"
|
||||
Reference in new issue
Block a user