Play against Maia: the designer's must-fix items

- The toolbar's words (Take back, Abort, Resign, Yes/No) at 14 pt, as tall
  as the icon buttons beside them.
- The result strip: four even buttons in a row when they fit; else Analyse,
  Rematch and New game side by side, Save — each as wide as the strip.
- ♞ instead of ⚔ for Play and New game: at small sizes ⚔ read as a cross.
- Maia not downloaded: the main button says «Download and play» and starts
  the game once she is there; the size line, progress and errors sit by the
  buttons, outside the scrolling body.
- No unsaved mark during the game; an unnamed user is «You» in the title.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-25 05:04:34 +03:00
parent 9d44c3fea0
commit ff4dc8b7ed
4 changed files with 155 additions and 69 deletions

View file

@ -194,12 +194,27 @@ impl GameView {
pub fn title(&self) -> String { pub fn title(&self) -> String {
let g = &self.game; let g = &self.game;
let white = g.tag("White").filter(|s| *s != "?").unwrap_or(tr("White")); // In a game against Maia an unnamed user is «You».
let user = self.play.as_ref().map(|s| s.user);
let unnamed = |c: Color| {
if user == Some(c) {
tr("You")
} else {
c.fold_wb(tr("White"), tr("Black"))
}
};
let white = g
.tag("White")
.filter(|s| *s != "?")
.unwrap_or(unnamed(Color::White));
// A book chapter imported from ChessBase: its title is in White, Black is empty. // A book chapter imported from ChessBase: its title is in White, Black is empty.
if g.tag("Black") == Some("") { if g.tag("Black") == Some("") {
return white.to_string(); return white.to_string();
} }
let black = g.tag("Black").filter(|s| *s != "?").unwrap_or(tr("Black")); let black = g
.tag("Black")
.filter(|s| *s != "?")
.unwrap_or(unnamed(Color::Black));
format!("{white} — {black}") format!("{white} — {black}")
} }
@ -936,7 +951,7 @@ impl GameView {
ui.set_max_width(title_room); ui.set_max_width(title_room);
// The unsaved mark first: it must not be truncated away. // The unsaved mark first: it must not be truncated away.
let mut mark_w = 0.0; let mut mark_w = 0.0;
if self.game.is_modified() { if self.game.is_modified() && self.play.is_none() {
let mark = ui let mark = ui
.label(RichText::new("•").strong().size(16.0)) .label(RichText::new("•").strong().size(16.0))
.on_hover_text(tr("Unsaved changes")); .on_hover_text(tr("Unsaved changes"));
@ -2538,6 +2553,9 @@ impl GameView {
ui.add_space(4.0); ui.add_space(4.0);
ui.horizontal_wrapped(|ui| { ui.horizontal_wrapped(|ui| {
let big = |s: &str| RichText::new(s).size(18.0); let big = |s: &str| RichText::new(s).size(18.0);
// The words as tall as the icon buttons beside them.
let word =
|s: &str| egui::Button::new(RichText::new(s).size(14.0)).min_size(vec2(0.0, 28.0));
if ui.button(big("⏮")).clicked() { if ui.button(big("⏮")).clicked() {
self.goto(NodeId::ROOT); self.goto(NodeId::ROOT);
} }
@ -2568,7 +2586,7 @@ impl GameView {
.is_some_and(|p| p.turn() == user) .is_some_and(|p| p.turn() == user)
}); });
if ui if ui
.add_enabled(user_moved, egui::Button::new(tr("↶ Take back"))) .add_enabled(user_moved, word(tr("↶ Take back")))
.on_hover_text(tr("Take back a move (Ctrl+Z)")) .on_hover_text(tr("Take back a move (Ctrl+Z)"))
.clicked() .clicked()
{ {
@ -2576,29 +2594,32 @@ impl GameView {
} }
if !self.play_started() { if !self.play_started() {
if ui if ui
.button(tr("× Abort")) .add(word(tr("× Abort")))
.on_hover_text(tr("Leave without a result: no moves made yet")) .on_hover_text(tr("Leave without a result: no moves made yet"))
.clicked() .clicked()
{ {
actions.push(GameAction::Back); actions.push(GameAction::Back);
} }
} else if self.play.as_ref().is_some_and(|s| s.resign_asked) { } else if self.play.as_ref().is_some_and(|s| s.resign_asked) {
ui.label(tr("Resign?")); ui.label(RichText::new(tr("Resign?")).size(14.0));
if ui if ui
.add( .add(
egui::Button::new(RichText::new(tr("Yes")).color(Color32::WHITE)) egui::Button::new(
.fill(ui.visuals().error_fg_color), RichText::new(tr("Yes")).size(14.0).color(Color32::WHITE),
)
.fill(ui.visuals().error_fg_color)
.min_size(vec2(0.0, 28.0)),
) )
.clicked() .clicked()
{ {
let user = self.play.as_ref().map_or(Color::White, |s| s.user); let user = self.play.as_ref().map_or(Color::White, |s| s.user);
self.finish_play(crate::play::Ending::Resigned { loser: user }, actions); self.finish_play(crate::play::Ending::Resigned { loser: user }, actions);
} else if ui.button(tr("No")).clicked() } else if ui.add(word(tr("No"))).clicked()
&& let Some(s) = self.play.as_mut() && let Some(s) = self.play.as_mut()
{ {
s.resign_asked = false; s.resign_asked = false;
} }
} else if ui.button(tr("⚑ Resign")).clicked() } else if ui.add(word(tr("⚑ Resign"))).clicked()
&& let Some(s) = self.play.as_mut() && let Some(s) = self.play.as_mut()
{ {
s.resign_asked = true; s.resign_asked = true;
@ -2657,28 +2678,72 @@ impl GameView {
); );
} }
ui.add_space(4.0); ui.add_space(4.0);
ui.horizontal_wrapped(|ui| { // All four in a row when they fit; else Analyse, then Rematch and New
if crate::widgets::primary(ui, tr("📈 Analyse")).clicked() { // game side by side, then Save — each as wide as the strip.
self.review.dialog_open = true; let labels = [
tr("📈 Analyse"),
tr("↻ Rematch"),
tr("♞ New game"),
tr("💾 Save to a database…"),
];
let font = egui::FontId::proportional(14.0);
let pad = 2.0 * ui.spacing().button_padding.x + ui.spacing().item_spacing.x;
let one_row: f32 = labels
.iter()
.map(|l| {
ui.painter()
.layout_no_wrap((*l).to_owned(), font.clone(), Color32::WHITE)
.size()
.x
+ pad
})
.sum();
let fits = one_row <= ui.available_width();
let mut clicked = [false; 4];
let mut button = |ui: &mut Ui, k: usize, w: f32| {
let mut text = RichText::new(labels[k]).size(14.0);
let mut b = egui::Button::new(text.clone());
if k == 0 {
text = text.strong();
b = egui::Button::new(text).fill(ui.visuals().selection.bg_fill);
} }
if ui let mut r = ui.add(b.min_size(vec2(w, 30.0)));
.button(tr("↻ Rematch")) if k == 1 {
.on_hover_text(tr("Same settings, colours swapped")) r = r.on_hover_text(tr("Same settings, colours swapped"));
.clicked()
{
actions.push(GameAction::Rematch);
} }
if ui.button(tr("⚔ New game")).clicked() { if k == 3 {
actions.push(GameAction::PlayAgain); r = r.on_hover_text("Ctrl+S");
} }
if ui clicked[k] = r.clicked();
.button(tr("💾 Save to a database…")) };
.on_hover_text("Ctrl+S") if fits {
.clicked() ui.horizontal(|ui| {
{ for k in 0..4 {
actions.push(GameAction::Save); button(ui, k, 0.0);
} }
}); });
} else {
let full = ui.available_width();
button(ui, 0, full);
ui.horizontal(|ui| {
let half = (full - ui.spacing().item_spacing.x) / 2.0;
button(ui, 1, half);
button(ui, 2, half);
});
button(ui, 3, full);
}
if clicked[0] {
self.review.dialog_open = true;
}
if clicked[1] {
actions.push(GameAction::Rematch);
}
if clicked[2] {
actions.push(GameAction::PlayAgain);
}
if clicked[3] {
actions.push(GameAction::Save);
}
}); });
if close { if close {
self.play_end = None; self.play_end = None;

View file

@ -10446,15 +10446,15 @@ const ROWS: &[[&str; 9]] = &[
"Баптаулар сол, түстер ауысады", "Баптаулар сол, түстер ауысады",
], ],
[ [
"⚔ New game", "♞ New game",
"⚔ Новая игра", "♞ Новая игра",
"⚔ Nouvelle partie", "♞ Nouvelle partie",
"⚔ Neue Partie", "♞ Neue Partie",
"⚔ Nueva partida", "♞ Nueva partida",
"⚔ Nuova partita", "♞ Nuova partita",
"⚔ Nova partida", "♞ Nova partida",
"⚔ Yangi o‘yin", "♞ Yangi o‘yin",
"⚔ Жаңа ойын", "♞ Жаңа ойын",
], ],
[ [
"💾 Save to a database…", "💾 Save to a database…",
@ -10468,15 +10468,15 @@ const ROWS: &[[&str; 9]] = &[
"💾 Базаға сақтау…", "💾 Базаға сақтау…",
], ],
[ [
"⚔ Play", "♞ Play",
"⚔ Играть", "♞ Играть",
"⚔ Jouer", "♞ Jouer",
"⚔ Spielen", "♞ Spielen",
"⚔ Jugar", "♞ Jugar",
"⚔ Gioca", "♞ Gioca",
"⚔ Jogar", "♞ Jogar",
"⚔ O‘ynash", "♞ O‘ynash",
"⚔ Ойнау", "♞ Ойнау",
], ],
[ [
"A game against Maia, which plays like a human of the chosen rating (Ctrl+G)", "A game against Maia, which plays like a human of the chosen rating (Ctrl+G)",
@ -10902,6 +10902,17 @@ const ROWS: &[[&str; 9]] = &[
"Maiada vaqt tugadi, lekin sizda mot qilishga yetarli kuch yo‘q", "Maiada vaqt tugadi, lekin sizda mot qilishga yetarli kuch yo‘q",
"Maia-ның уақыты бітті, бірақ сізде мат қоюға күш жоқ", "Maia-ның уақыты бітті, бірақ сізде мат қоюға күш жоқ",
], ],
[
"Download and play",
"Скачать и играть",
"Télécharger et jouer",
"Herunterladen und spielen",
"Descargar y jugar",
"Scarica e gioca",
"Baixar e jogar",
"Yuklab olish va o‘ynash",
"Жүктеп алып ойнау",
],
]; ];
#[cfg(test)] #[cfg(test)]

View file

@ -119,13 +119,13 @@ fn legacy_pgn(path: &Path) -> bool {
/// database actions. /// database actions.
fn shelf_buttons_w(ui: &Ui, update: Option<&str>, icons: bool) -> f32 { fn shelf_buttons_w(ui: &Ui, update: Option<&str>, icons: bool) -> f32 {
let texts: [&str; 4] = if icons { let texts: [&str; 4] = if icons {
["⚙", "📋", "♟", "⚔"] ["⚙", "📋", "♟", "♞"]
} else { } else {
[ [
tr("⚙ Settings"), tr("⚙ Settings"),
tr("📋 Paste PGN"), tr("📋 Paste PGN"),
tr("♟ New game"), tr("♟ New game"),
tr("⚔ Play"), tr("♞ Play"),
] ]
}; };
texts.iter().map(|t| button_w(ui, t)).sum::<f32>() texts.iter().map(|t| button_w(ui, t)).sum::<f32>()
@ -713,9 +713,9 @@ impl Library {
actions.push(LibraryAction::NewGame); actions.push(LibraryAction::NewGame);
} }
if ui if ui
.button(label(tr("⚔ Play"), "⚔")) .button(label(tr("♞ Play"), "♞"))
.on_hover_text(hint( .on_hover_text(hint(
tr("⚔ Play"), tr("♞ Play"),
tr("A game against Maia, which plays like a human of the chosen rating (Ctrl+G)"), tr("A game against Maia, which plays like a human of the chosen rating (Ctrl+G)"),
)) ))
.clicked() .clicked()

View file

@ -680,6 +680,8 @@ pub struct Dialog {
prefs: PlayPrefs, prefs: PlayPrefs,
custom: bool, custom: bool,
download: Option<crate::maia_download::Download>, download: Option<crate::maia_download::Download>,
/// «Download and play» was pressed: the game starts once Maia is there.
play_after: bool,
focus: bool, focus: bool,
} }
@ -698,6 +700,7 @@ impl Dialog {
prefs, prefs,
custom, custom,
download: None, download: None,
play_after: false,
focus: true, focus: true,
} }
} }
@ -724,7 +727,7 @@ impl Dialog {
ui.set_width(460.0); ui.set_width(460.0);
ui.heading(tr("Play against the computer")); ui.heading(tr("Play against the computer"));
// The body scrolls in a low window; the buttons below it stay in view. // The body scrolls in a low window; the buttons below it stay in view.
let (ready, rating) = egui::ScrollArea::vertical() let rating = egui::ScrollArea::vertical()
.max_height(body_h) .max_height(body_h)
.auto_shrink([false, true]) .auto_shrink([false, true])
.show(ui, |ui| { .show(ui, |ui| {
@ -873,17 +876,23 @@ impl Dialog {
.weak() .weak()
.size(11.5), .size(11.5),
); );
ui.add_space(10.0); rating
})
.inner;
// Maia itself: downloaded once. // Maia itself, downloaded once: under the body, by the buttons, always seen.
let stage = self.download.as_ref().map(|d| d.stage());
let mut ready = installed.is_some(); let mut ready = installed.is_some();
let busy = !ready
&& matches!(
stage,
Some(crate::maia_download::Stage::Downloading { .. } | crate::maia_download::Stage::Checking)
);
if !ready { if !ready {
match self.download.as_ref().map(|d| d.stage()) { ui.add_space(6.0);
match stage {
None => { None => {
ui.label(trf_size()); ui.label(RichText::new(trf_size()).weak());
if ui.button(tr("Download Maia")).clicked() {
self.download = Some(crate::maia_download::Download::start(ctx));
}
} }
Some(crate::maia_download::Stage::Downloading { done }) => { Some(crate::maia_download::Stage::Downloading { done }) => {
ui.add( ui.add(
@ -900,22 +909,23 @@ impl Dialog {
Some(crate::maia_download::Stage::Done(_)) => ready = true, Some(crate::maia_download::Stage::Done(_)) => ready = true,
Some(crate::maia_download::Stage::Failed(e)) => { Some(crate::maia_download::Stage::Failed(e)) => {
ui.label(RichText::new(e).color(ui.visuals().error_fg_color)); ui.label(RichText::new(e).color(ui.visuals().error_fg_color));
if ui.button(tr("Try again")).clicked() {
self.download = Some(crate::maia_download::Download::start(ctx));
}
} }
} }
} }
(ready, rating)
})
.inner;
ui.add_space(6.0); ui.add_space(6.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let play = ui let label = if ready { tr("Play") } else { tr("Download and play") };
.add_enabled_ui(ready, |ui| crate::widgets::primary(ui, tr("Play"))) let main = ui
.add_enabled_ui(!busy, |ui| crate::widgets::primary(ui, label))
.inner; .inner;
let enter = ready && ui.input(|i| i.key_pressed(egui::Key::Enter)); let pressed = !busy
if play.clicked() || enter { && (main.clicked() || ui.input(|i| i.key_pressed(egui::Key::Enter)));
if pressed && !ready {
self.download = Some(crate::maia_download::Download::start(ctx));
self.play_after = true;
}
if ready && (pressed || self.play_after) {
self.play_after = false;
let user = match self.prefs.color { let user = match self.prefs.color {
ColorChoice::White => Color::White, ColorChoice::White => Color::White,
ColorChoice::Black => Color::Black, ColorChoice::Black => Color::Black,