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 {
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.
if g.tag("Black") == Some("") {
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}")
}
@ -936,7 +951,7 @@ impl GameView {
ui.set_max_width(title_room);
// The unsaved mark first: it must not be truncated away.
let mut mark_w = 0.0;
if self.game.is_modified() {
if self.game.is_modified() && self.play.is_none() {
let mark = ui
.label(RichText::new("•").strong().size(16.0))
.on_hover_text(tr("Unsaved changes"));
@ -2538,6 +2553,9 @@ impl GameView {
ui.add_space(4.0);
ui.horizontal_wrapped(|ui| {
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() {
self.goto(NodeId::ROOT);
}
@ -2568,7 +2586,7 @@ impl GameView {
.is_some_and(|p| p.turn() == user)
});
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)"))
.clicked()
{
@ -2576,29 +2594,32 @@ impl GameView {
}
if !self.play_started() {
if ui
.button(tr("× Abort"))
.add(word(tr("× Abort")))
.on_hover_text(tr("Leave without a result: no moves made yet"))
.clicked()
{
actions.push(GameAction::Back);
}
} 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
.add(
egui::Button::new(RichText::new(tr("Yes")).color(Color32::WHITE))
.fill(ui.visuals().error_fg_color),
egui::Button::new(
RichText::new(tr("Yes")).size(14.0).color(Color32::WHITE),
)
.fill(ui.visuals().error_fg_color)
.min_size(vec2(0.0, 28.0)),
)
.clicked()
{
let user = self.play.as_ref().map_or(Color::White, |s| s.user);
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()
{
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()
{
s.resign_asked = true;
@ -2657,28 +2678,72 @@ impl GameView {
);
}
ui.add_space(4.0);
ui.horizontal_wrapped(|ui| {
if crate::widgets::primary(ui, tr("📈 Analyse")).clicked() {
self.review.dialog_open = true;
// All four in a row when they fit; else Analyse, then Rematch and New
// game side by side, then Save — each as wide as the strip.
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
.button(tr("↻ Rematch"))
.on_hover_text(tr("Same settings, colours swapped"))
.clicked()
{
actions.push(GameAction::Rematch);
let mut r = ui.add(b.min_size(vec2(w, 30.0)));
if k == 1 {
r = r.on_hover_text(tr("Same settings, colours swapped"));
}
if ui.button(tr("⚔ New game")).clicked() {
actions.push(GameAction::PlayAgain);
if k == 3 {
r = r.on_hover_text("Ctrl+S");
}
if ui
.button(tr("💾 Save to a database…"))
.on_hover_text("Ctrl+S")
.clicked()
{
actions.push(GameAction::Save);
}
});
clicked[k] = r.clicked();
};
if fits {
ui.horizontal(|ui| {
for k in 0..4 {
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 {
self.play_end = None;

View file

@ -10446,15 +10446,15 @@ const ROWS: &[[&str; 9]] = &[
"Баптаулар сол, түстер ауысады",
],
[
"⚔ New game",
"⚔ Новая игра",
"⚔ Nouvelle partie",
"⚔ Neue Partie",
"⚔ Nueva partida",
"⚔ Nuova partita",
"⚔ Nova partida",
"⚔ Yangi o‘yin",
"⚔ Жаңа ойын",
"♞ New game",
"♞ Новая игра",
"♞ Nouvelle partie",
"♞ Neue Partie",
"♞ Nueva partida",
"♞ Nuova partita",
"♞ Nova partida",
"♞ Yangi o‘yin",
"♞ Жаңа ойын",
],
[
"💾 Save to a database…",
@ -10468,15 +10468,15 @@ const ROWS: &[[&str; 9]] = &[
"💾 Базаға сақтау…",
],
[
"⚔ Play",
"⚔ Играть",
"⚔ Jouer",
"⚔ Spielen",
"⚔ Jugar",
"⚔ Gioca",
"⚔ Jogar",
"⚔ O‘ynash",
"⚔ Ойнау",
"♞ Play",
"♞ Играть",
"♞ Jouer",
"♞ Spielen",
"♞ Jugar",
"♞ Gioca",
"♞ Jogar",
"♞ O‘ynash",
"♞ Ойнау",
],
[
"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",
"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)]

View file

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

View file

@ -680,6 +680,8 @@ pub struct Dialog {
prefs: PlayPrefs,
custom: bool,
download: Option<crate::maia_download::Download>,
/// «Download and play» was pressed: the game starts once Maia is there.
play_after: bool,
focus: bool,
}
@ -698,6 +700,7 @@ impl Dialog {
prefs,
custom,
download: None,
play_after: false,
focus: true,
}
}
@ -724,7 +727,7 @@ impl Dialog {
ui.set_width(460.0);
ui.heading(tr("Play against the computer"));
// 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)
.auto_shrink([false, true])
.show(ui, |ui| {
@ -873,17 +876,23 @@ impl Dialog {
.weak()
.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 busy = !ready
&& matches!(
stage,
Some(crate::maia_download::Stage::Downloading { .. } | crate::maia_download::Stage::Checking)
);
if !ready {
match self.download.as_ref().map(|d| d.stage()) {
ui.add_space(6.0);
match stage {
None => {
ui.label(trf_size());
if ui.button(tr("Download Maia")).clicked() {
self.download = Some(crate::maia_download::Download::start(ctx));
}
ui.label(RichText::new(trf_size()).weak());
}
Some(crate::maia_download::Stage::Downloading { done }) => {
ui.add(
@ -900,22 +909,23 @@ impl Dialog {
Some(crate::maia_download::Stage::Done(_)) => ready = true,
Some(crate::maia_download::Stage::Failed(e)) => {
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.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let play = ui
.add_enabled_ui(ready, |ui| crate::widgets::primary(ui, tr("Play")))
let label = if ready { tr("Play") } else { tr("Download and play") };
let main = ui
.add_enabled_ui(!busy, |ui| crate::widgets::primary(ui, label))
.inner;
let enter = ready && ui.input(|i| i.key_pressed(egui::Key::Enter));
if play.clicked() || enter {
let pressed = !busy
&& (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 {
ColorChoice::White => Color::White,
ColorChoice::Black => Color::Black,