Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 83f37bada6 | |||
| d989d07fe7 | |||
| fa54c58bc4 | |||
| dd304913df | |||
| 48ad6b6618 | |||
| 81ac4a5383 | |||
| f51ee7b234 | |||
| fc87b13e5b | |||
| 560470b86b | |||
| 1fded5ff16 |
@@ -6,6 +6,51 @@ project follows [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.45.0] — 2026-07-13
|
||||
|
||||
### Added
|
||||
|
||||
- **Thumb-reach action bar on touch (menu redesign Phase F).** The bottom
|
||||
bar slims to five buttons: an enlarged **Undo · Draw · Hint** trio
|
||||
(96×64 px targets) between compact Menu and Pause. **Draw is new** — it
|
||||
draws from the stock exactly like tapping the deck, without the reach to
|
||||
the top of a tall folded screen. Help, Modes, and New Game moved off the
|
||||
touch bar (Menu → System, the Home grid, and Home's hero button cover
|
||||
them). Desktop keeps its seven-button bar unchanged.
|
||||
- **Hold-to-repeat Undo.** Press and hold Undo to step back repeatedly
|
||||
(~5.5 undos/s after a short delay) instead of tap-tap-tap. Every step
|
||||
goes through the normal undo path, so scoring penalties apply as usual.
|
||||
|
||||
## [0.44.0] — 2026-07-13
|
||||
|
||||
### Added
|
||||
|
||||
- **Home is now a real home (menu redesign Phase B).** The mode picker became
|
||||
a hierarchy: a **Continue** card (mode · elapsed · score) appears while a
|
||||
game is in progress and returns to the table; a hero **New Game** button
|
||||
replays your last mode with the current deal options in one tap; deal
|
||||
options (draw 1/3, a new **winnable-only** toggle, difficulty tiers) moved
|
||||
into a disclosure under the hero; the six modes sit in a compact symmetric
|
||||
2×3 grid with descriptions on wide screens; and the stats strip moved to
|
||||
the bottom. Wide viewports (desktop, unfolded foldables) get a two-pane
|
||||
layout — launch surfaces left, Continue/daily/stats right. Cancel is now
|
||||
**Back to table** and only appears while a live game exists. (#175)
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Save files are self-contained (schema v6).** Like replays in 0.43.3, a
|
||||
saved game now stores the dealt board via the upstream session serializers
|
||||
instead of re-dealing from the seed on load; v4/v5 saves still load through
|
||||
the legacy path and rewrite as v6 on next save. (#171)
|
||||
|
||||
### Internal
|
||||
|
||||
- **CI is ~9× faster.** Root-caused why the actions cache never restored on
|
||||
the host-executor runner (per-run workdir paths poisoned the cache version
|
||||
hash); the test workflow now uses a persistent on-runner target dir, and a
|
||||
seconds-long `fmt` gate fails formatting mistakes before the build. Warm
|
||||
full-gate runs: 4m29s, down from ~40 min. (#176)
|
||||
|
||||
## [0.43.3] — 2026-07-10
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# Menu UX Redesign — July 2026
|
||||
|
||||
Status: PLANNING. Visual identity (Terminal / base16-eighties) is settled and
|
||||
out of scope — this is about **structure and interaction**, not colors or type.
|
||||
Status: IN PROGRESS. A / E / C / G shipped in v0.43.0; B implemented on
|
||||
`feat/home-hierarchy` (2026-07-13); F / H and the I–M backlog remain open.
|
||||
Visual identity (Terminal / base16-eighties) is settled and out of
|
||||
scope — this is about **structure and interaction**, not colors or type.
|
||||
|
||||
## Diagnosis (from code survey, 2026-07-07)
|
||||
|
||||
@@ -197,8 +199,13 @@ slimming), then **B**, then **F/G/H** as independent follow-ups.
|
||||
## Open decisions
|
||||
|
||||
1. ~~Settings: tabs vs. sub-pages~~ — **DECIDED 2026-07-07: tabs.**
|
||||
2. Deal options: disclosure on Classic card (proposed) vs. keep global row?
|
||||
3. Time Attack + Seed: top-level cards (proposed, grid stays symmetric) vs.
|
||||
tucked under a "More" card?
|
||||
4. Stitch mockups for Phase B, or iterate directly in-engine?
|
||||
5. Phase F bottom bar: touch-only (proposed) or also desktop?
|
||||
2. ~~Deal options: disclosure on Classic card vs. keep global row~~ —
|
||||
**DECIDED 2026-07-09: disclosure on the Classic card / New Game hero.**
|
||||
3. ~~Time Attack + Seed: top-level cards vs. "More" card~~ —
|
||||
**DECIDED 2026-07-09: top-level cards, symmetric 2×3 grid.**
|
||||
4. ~~Stitch mockups for Phase B, or iterate directly in-engine~~ —
|
||||
**DECIDED 2026-07-09: directly in-engine.**
|
||||
5. ~~Phase F bottom bar: touch-only vs. also desktop~~ —
|
||||
**DECIDED 2026-07-13: touch-only.** Desktop keeps the current top
|
||||
band; the bar is additive per §3.3 so a later desktop rollout stays
|
||||
a settings flag away.
|
||||
|
||||
@@ -9,7 +9,10 @@ use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solitaire_core::{DrawStockConfig, game_state::DifficultyLevel};
|
||||
use solitaire_core::{
|
||||
DrawStockConfig,
|
||||
game_state::{DifficultyLevel, GameMode},
|
||||
};
|
||||
|
||||
const SETTINGS_FILE_NAME: &str = "settings.json";
|
||||
|
||||
@@ -248,6 +251,12 @@ pub struct Settings {
|
||||
/// cleanly to `None` via `#[serde(default)]`.
|
||||
#[serde(default)]
|
||||
pub last_difficulty: Option<DifficultyLevel>,
|
||||
/// Mode of the last game the player launched from the home overlay.
|
||||
/// The home hero "New Game" button replays this mode with one tap.
|
||||
/// Older `settings.json` files written before this field existed
|
||||
/// deserialize cleanly to `GameMode::Classic` via `#[serde(default)]`.
|
||||
#[serde(default)]
|
||||
pub last_mode: GameMode,
|
||||
/// Custom public name displayed on the leaderboard. When `None`, the
|
||||
/// player's server `username` is used instead. Trimmed to 32 characters
|
||||
/// before submission. Older `settings.json` files written before this
|
||||
@@ -415,6 +424,7 @@ impl Default for Settings {
|
||||
disable_smart_default_size: false,
|
||||
replay_move_interval_secs: default_replay_move_interval_secs(),
|
||||
last_difficulty: None,
|
||||
last_mode: GameMode::Classic,
|
||||
leaderboard_display_name: None,
|
||||
leaderboard_opted_in: false,
|
||||
take_from_foundation: true,
|
||||
|
||||
@@ -86,6 +86,14 @@ pub struct NewGameRequestWriters;
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct UndoRequestWriters;
|
||||
|
||||
/// Self-ambiguous set for writers of `DrawRequestEvent` — same rationale as
|
||||
/// [`NewGameRequestWriters`]: consumers drain the queue, append order is
|
||||
/// meaningless (#143). Members: keyboard `D`/`Space`, stock click, touch
|
||||
/// stock tap (input_plugin), and the touch action bar's Draw button
|
||||
/// (hud_plugin, Phase F).
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct DrawRequestWriters;
|
||||
|
||||
/// Self-ambiguous set for writers of `InfoToastEvent` — toasts queue in
|
||||
/// arrival order and any same-frame order is fine (#143).
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
||||
+1119
-307
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,86 @@ pub(super) fn handle_undo_button(
|
||||
}
|
||||
}
|
||||
|
||||
/// Seconds the Undo button must be continuously held before hold-to-repeat
|
||||
/// kicks in. Long enough that a normal tap (press + release inside one or
|
||||
/// two frames) never triggers a second undo.
|
||||
const UNDO_HOLD_INITIAL_DELAY_SECS: f32 = 0.45;
|
||||
|
||||
/// Interval between repeated undos while the hold continues. ~5.5 undos/s —
|
||||
/// fast enough to unwind a long line, slow enough to release in time when
|
||||
/// the board reaches the state the player wants.
|
||||
const UNDO_HOLD_REPEAT_INTERVAL_SECS: f32 = 0.18;
|
||||
|
||||
/// Hold-to-repeat undo (Phase F): while the Undo button stays pressed,
|
||||
/// fire additional [`UndoRequestEvent`]s after an initial delay, one per
|
||||
/// repeat interval. The plain tap path stays in [`handle_undo_button`]
|
||||
/// (its `Changed<Interaction>` filter fires exactly once per press);
|
||||
/// this system only adds events once the hold outlives the delay, so a
|
||||
/// tap never double-undoes.
|
||||
///
|
||||
/// Each repeat goes through the normal request queue — the scoring
|
||||
/// penalty and No-Undo-mode gating in the consumer apply to every step.
|
||||
pub(super) fn repeat_undo_on_hold(
|
||||
time: Res<Time>,
|
||||
buttons: Query<&Interaction, With<UndoButton>>,
|
||||
mut state: ResMut<UndoHoldState>,
|
||||
mut undo: MessageWriter<UndoRequestEvent>,
|
||||
) {
|
||||
let held = buttons.iter().any(|i| *i == Interaction::Pressed);
|
||||
if !held {
|
||||
if state.held_secs != 0.0 {
|
||||
state.held_secs = 0.0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let before = state.held_secs;
|
||||
state.held_secs += time.delta_secs();
|
||||
if undo_hold_crossed_fire_boundary(before, state.held_secs) {
|
||||
undo.write(UndoRequestEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/// `true` when a hold that lasted `before` seconds at the previous frame
|
||||
/// and `now` seconds this frame should fire a repeat undo: once when the
|
||||
/// hold first outlives the initial delay, then once per repeat-interval
|
||||
/// boundary. Pure so the timing contract is unit-testable without
|
||||
/// fighting `Time`.
|
||||
pub(super) fn undo_hold_crossed_fire_boundary(before: f32, now: f32) -> bool {
|
||||
if now < UNDO_HOLD_INITIAL_DELAY_SECS {
|
||||
return false;
|
||||
}
|
||||
if before < UNDO_HOLD_INITIAL_DELAY_SECS {
|
||||
// Crossed the initial-delay threshold this frame — first repeat.
|
||||
return true;
|
||||
}
|
||||
// Fire once each time the hold crosses another repeat-interval boundary.
|
||||
let intervals_before =
|
||||
((before - UNDO_HOLD_INITIAL_DELAY_SECS) / UNDO_HOLD_REPEAT_INTERVAL_SECS).floor();
|
||||
let intervals_now =
|
||||
((now - UNDO_HOLD_INITIAL_DELAY_SECS) / UNDO_HOLD_REPEAT_INTERVAL_SECS).floor();
|
||||
intervals_now > intervals_before
|
||||
}
|
||||
|
||||
/// Click on the touch action bar's Draw button — same
|
||||
/// [`DrawRequestEvent`] the stock-pile tap writes, so the consumer's
|
||||
/// rules (recycle, won-game rejection) apply identically. Skipped while
|
||||
/// paused, mirroring `handle_stock_click`'s guard.
|
||||
pub(super) fn handle_draw_button(
|
||||
interaction_query: Query<&Interaction, (With<DrawButton>, Changed<Interaction>)>,
|
||||
paused: Option<Res<PausedResource>>,
|
||||
mut draw: MessageWriter<DrawRequestEvent>,
|
||||
) {
|
||||
if paused.is_some_and(|p| p.0) {
|
||||
return;
|
||||
}
|
||||
for interaction in &interaction_query {
|
||||
if *interaction == Interaction::Pressed {
|
||||
draw.write(DrawRequestEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn handle_pause_button(
|
||||
interaction_query: Query<&Interaction, (With<PauseButton>, Changed<Interaction>)>,
|
||||
mut pause: MessageWriter<PauseRequestEvent>,
|
||||
|
||||
@@ -28,7 +28,7 @@ struct AvatarResource(Option<bevy::prelude::Handle<bevy::prelude::Image>>);
|
||||
use crate::challenge_plugin::CHALLENGE_UNLOCK_LEVEL;
|
||||
use crate::daily_challenge_plugin::DailyChallengeResource;
|
||||
use crate::events::{
|
||||
HelpRequestEvent, InfoToastEvent, NewGameRequestEvent, PauseRequestEvent,
|
||||
DrawRequestEvent, HelpRequestEvent, InfoToastEvent, NewGameRequestEvent, PauseRequestEvent,
|
||||
StartChallengeRequestEvent, StartDailyChallengeRequestEvent, StartTimeAttackRequestEvent,
|
||||
StartZenRequestEvent, ToggleAchievementsRequestEvent, ToggleHomeRequestEvent,
|
||||
ToggleLeaderboardRequestEvent, ToggleProfileRequestEvent, ToggleSettingsRequestEvent,
|
||||
@@ -313,6 +313,18 @@ pub struct UndoButton;
|
||||
#[derive(Component, Debug)]
|
||||
pub struct PauseButton;
|
||||
|
||||
/// Accumulated hold time on the Undo button, driving hold-to-repeat undo
|
||||
/// (Phase F). `handle_undo_button` owns the instant first undo on press;
|
||||
/// `repeat_undo_on_hold` starts firing additional [`UndoRequestEvent`]s
|
||||
/// once the hold passes `UNDO_HOLD_INITIAL_DELAY_SECS` and then every
|
||||
/// `UNDO_HOLD_REPEAT_INTERVAL_SECS`. Each repeated undo goes through the
|
||||
/// normal request path, so the existing scoring penalty applies per step.
|
||||
#[derive(Resource, Debug, Default)]
|
||||
pub struct UndoHoldState {
|
||||
/// Seconds the Undo button has been continuously held.
|
||||
held_secs: f32,
|
||||
}
|
||||
|
||||
/// Marker on the "Help" action button. Click fires [`HelpRequestEvent`],
|
||||
/// mirroring the `F1` keyboard accelerator.
|
||||
#[derive(Component, Debug)]
|
||||
@@ -323,31 +335,27 @@ pub struct HelpButton;
|
||||
#[derive(Component, Debug)]
|
||||
pub struct HintButton;
|
||||
|
||||
/// Marker on the touch action bar's "Draw" button (Phase F). Click fires
|
||||
/// [`DrawRequestEvent`] — same queue as tapping the stock pile — so the
|
||||
/// draw action is within thumb reach without stretching to the top of a
|
||||
/// tall folded screen. Touch layout only; desktop draws via stock
|
||||
/// click / `D` / `Space`.
|
||||
#[derive(Component, Debug)]
|
||||
pub struct DrawButton;
|
||||
|
||||
/// Android HUD label for the Hint button — shared with the help screen's
|
||||
/// controls reference so both always agree.
|
||||
#[cfg(target_os = "android")]
|
||||
pub(crate) const ANDROID_HINT_LABEL: &str = "Hint";
|
||||
|
||||
/// Hint label used by the touch action bar. Aliases [`ANDROID_HINT_LABEL`]
|
||||
/// on Android so the bar and the help screen's controls reference can
|
||||
/// never drift; the non-Android value only exists so the touch spawn
|
||||
/// path stays host-compilable for tests.
|
||||
#[cfg(target_os = "android")]
|
||||
const ACTION_BAR_LABELS: [&str; 7] = [
|
||||
"Menu",
|
||||
"Undo",
|
||||
"Pause",
|
||||
"Help",
|
||||
ANDROID_HINT_LABEL,
|
||||
"Mode",
|
||||
"New",
|
||||
];
|
||||
const TOUCH_HINT_LABEL: &str = ANDROID_HINT_LABEL;
|
||||
#[cfg(not(target_os = "android"))]
|
||||
const ACTION_BAR_LABELS: [&str; 7] = [
|
||||
"Menu \u{2193}",
|
||||
"Undo",
|
||||
"Pause",
|
||||
"Help",
|
||||
"Hint",
|
||||
"Modes \u{2193}",
|
||||
"New Game",
|
||||
];
|
||||
const TOUCH_HINT_LABEL: &str = "Hint";
|
||||
#[cfg(target_os = "android")]
|
||||
const ACTION_BAR_COLUMN_GAP: Val = Val::Px(4.0);
|
||||
#[cfg(not(target_os = "android"))]
|
||||
@@ -455,6 +463,7 @@ impl Plugin for HudPlugin {
|
||||
// idempotent.
|
||||
app.add_message::<NewGameRequestEvent>()
|
||||
.add_message::<UndoRequestEvent>()
|
||||
.add_message::<DrawRequestEvent>()
|
||||
.add_message::<PauseRequestEvent>()
|
||||
.add_message::<HelpRequestEvent>()
|
||||
.add_message::<StartZenRequestEvent>()
|
||||
@@ -471,6 +480,7 @@ impl Plugin for HudPlugin {
|
||||
.init_resource::<PreviousScore>()
|
||||
.init_resource::<HudActionFade>()
|
||||
.init_resource::<HudVisibility>()
|
||||
.init_resource::<UndoHoldState>()
|
||||
// Escape-close handlers for popovers read this; init defensively
|
||||
// so HudPlugin works under MinimalPlugins in tests.
|
||||
.init_resource::<ButtonInput<KeyCode>>()
|
||||
@@ -560,6 +570,14 @@ impl Plugin for HudPlugin {
|
||||
.in_set(crate::game_plugin::UndoRequestWriters)
|
||||
.ambiguous_with(crate::game_plugin::UndoRequestWriters)
|
||||
.before(GameMutation),
|
||||
repeat_undo_on_hold
|
||||
.in_set(crate::game_plugin::UndoRequestWriters)
|
||||
.ambiguous_with(crate::game_plugin::UndoRequestWriters)
|
||||
.before(GameMutation),
|
||||
handle_draw_button
|
||||
.in_set(crate::game_plugin::DrawRequestWriters)
|
||||
.ambiguous_with(crate::game_plugin::DrawRequestWriters)
|
||||
.before(GameMutation),
|
||||
handle_pause_button,
|
||||
handle_help_button,
|
||||
handle_hint_button
|
||||
|
||||
@@ -400,83 +400,152 @@ pub(super) fn spawn_action_buttons(
|
||||
HudActionBar,
|
||||
))
|
||||
.with_children(|row| {
|
||||
// The trailing `order` argument feeds `Focusable { group: Hud, order }`
|
||||
// so Tab cycles the action bar in visual reading order.
|
||||
// Undo and Pause are the primary gameplay actions — full brightness.
|
||||
// Menu, Help, Hint, Modes, New are navigation/utility — dimmed.
|
||||
spawn_action_button(
|
||||
row,
|
||||
MenuButton,
|
||||
ACTION_BAR_LABELS[0],
|
||||
None,
|
||||
"Open Stats, Achievements, Profile, Settings, or Leaderboard.",
|
||||
&font,
|
||||
0,
|
||||
TEXT_SECONDARY,
|
||||
);
|
||||
spawn_action_button(
|
||||
row,
|
||||
UndoButton,
|
||||
ACTION_BAR_LABELS[1],
|
||||
Some("U"),
|
||||
"Take back your last move. Costs points and blocks No Undo.",
|
||||
&font,
|
||||
1,
|
||||
TEXT_PRIMARY,
|
||||
);
|
||||
spawn_action_button(
|
||||
row,
|
||||
PauseButton,
|
||||
ACTION_BAR_LABELS[2],
|
||||
Some("Esc"),
|
||||
"Pause the game and freeze the timer.",
|
||||
&font,
|
||||
2,
|
||||
TEXT_PRIMARY,
|
||||
);
|
||||
spawn_action_button(
|
||||
row,
|
||||
HelpButton,
|
||||
ACTION_BAR_LABELS[3],
|
||||
Some("F1"),
|
||||
"Show controls, rules, and keyboard shortcuts.",
|
||||
&font,
|
||||
3,
|
||||
TEXT_SECONDARY,
|
||||
);
|
||||
spawn_action_button(
|
||||
row,
|
||||
HintButton,
|
||||
ACTION_BAR_LABELS[4],
|
||||
Some("H"),
|
||||
"Highlight a suggested move. Cycles through alternatives on repeat taps.",
|
||||
&font,
|
||||
4,
|
||||
TEXT_SECONDARY,
|
||||
);
|
||||
spawn_action_button(
|
||||
row,
|
||||
ModesButton,
|
||||
ACTION_BAR_LABELS[5],
|
||||
None,
|
||||
"Switch modes: Classic, Daily, Zen, Challenge, Time Attack.",
|
||||
&font,
|
||||
5,
|
||||
TEXT_SECONDARY,
|
||||
);
|
||||
spawn_action_button(
|
||||
row,
|
||||
NewGameButton,
|
||||
ACTION_BAR_LABELS[6],
|
||||
Some("N"),
|
||||
"Start a fresh deal. Confirms first if a game is in progress.",
|
||||
&font,
|
||||
6,
|
||||
TEXT_SECONDARY,
|
||||
);
|
||||
if USE_TOUCH_UI_LAYOUT {
|
||||
spawn_touch_action_bar(row, &font);
|
||||
} else {
|
||||
spawn_desktop_action_bar(row, &font);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Phase F touch action bar — five buttons, three of them big.
|
||||
///
|
||||
/// The core gameplay trio (**Undo · Draw · Hint**) gets enlarged
|
||||
/// thumb-reach targets; Menu and Pause stay compact at the edges. The
|
||||
/// utility actions the desktop bar carries are reachable elsewhere on
|
||||
/// touch and are deliberately absent here: Help lives in Menu → System,
|
||||
/// mode switching lives on the Home screen (Phase B), and New Game is
|
||||
/// Home's hero button. Draw duplicates the stock-pile tap so the most
|
||||
/// frequent action of all no longer requires reaching the top half of a
|
||||
/// tall folded screen.
|
||||
pub(super) fn spawn_touch_action_bar(row: &mut ChildSpawnerCommands, font: &TextFont) {
|
||||
// The trailing `order` argument feeds `Focusable { group: Hud, order }`
|
||||
// so Tab (external keyboard) cycles the bar in visual reading order.
|
||||
spawn_action_button(
|
||||
row,
|
||||
MenuButton,
|
||||
"Menu",
|
||||
None,
|
||||
"Open Home, Stats, Achievements, Profile, Settings, or Leaderboard.",
|
||||
font,
|
||||
0,
|
||||
TEXT_SECONDARY,
|
||||
);
|
||||
spawn_primary_action_button(
|
||||
row,
|
||||
UndoButton,
|
||||
"Undo",
|
||||
"Take back your last move. Hold to keep undoing. Costs points and blocks No Undo.",
|
||||
font,
|
||||
1,
|
||||
);
|
||||
spawn_primary_action_button(
|
||||
row,
|
||||
DrawButton,
|
||||
"Draw",
|
||||
"Draw from the stock — same as tapping the deck.",
|
||||
font,
|
||||
2,
|
||||
);
|
||||
spawn_primary_action_button(
|
||||
row,
|
||||
HintButton,
|
||||
TOUCH_HINT_LABEL,
|
||||
"Highlight a suggested move. Cycles through alternatives on repeat taps.",
|
||||
font,
|
||||
3,
|
||||
);
|
||||
spawn_action_button(
|
||||
row,
|
||||
PauseButton,
|
||||
"Pause",
|
||||
None,
|
||||
"Pause the game and freeze the timer.",
|
||||
font,
|
||||
4,
|
||||
TEXT_SECONDARY,
|
||||
);
|
||||
}
|
||||
|
||||
/// Desktop action bar — unchanged by Phase F (decision 5: the touch bar
|
||||
/// is touch-only). All seven actions, uniform sizing.
|
||||
pub(super) fn spawn_desktop_action_bar(row: &mut ChildSpawnerCommands, font: &TextFont) {
|
||||
// The trailing `order` argument feeds `Focusable { group: Hud, order }`
|
||||
// so Tab cycles the action bar in visual reading order.
|
||||
// Undo and Pause are the primary gameplay actions — full brightness.
|
||||
// Menu, Help, Hint, Modes, New are navigation/utility — dimmed.
|
||||
spawn_action_button(
|
||||
row,
|
||||
MenuButton,
|
||||
"Menu \u{2193}",
|
||||
None,
|
||||
"Open Stats, Achievements, Profile, Settings, or Leaderboard.",
|
||||
font,
|
||||
0,
|
||||
TEXT_SECONDARY,
|
||||
);
|
||||
spawn_action_button(
|
||||
row,
|
||||
UndoButton,
|
||||
"Undo",
|
||||
Some("U"),
|
||||
"Take back your last move. Hold to keep undoing. Costs points and blocks No Undo.",
|
||||
font,
|
||||
1,
|
||||
TEXT_PRIMARY,
|
||||
);
|
||||
spawn_action_button(
|
||||
row,
|
||||
PauseButton,
|
||||
"Pause",
|
||||
Some("Esc"),
|
||||
"Pause the game and freeze the timer.",
|
||||
font,
|
||||
2,
|
||||
TEXT_PRIMARY,
|
||||
);
|
||||
spawn_action_button(
|
||||
row,
|
||||
HelpButton,
|
||||
"Help",
|
||||
Some("F1"),
|
||||
"Show controls, rules, and keyboard shortcuts.",
|
||||
font,
|
||||
3,
|
||||
TEXT_SECONDARY,
|
||||
);
|
||||
spawn_action_button(
|
||||
row,
|
||||
HintButton,
|
||||
"Hint",
|
||||
Some("H"),
|
||||
"Highlight a suggested move. Cycles through alternatives on repeat taps.",
|
||||
font,
|
||||
4,
|
||||
TEXT_SECONDARY,
|
||||
);
|
||||
spawn_action_button(
|
||||
row,
|
||||
ModesButton,
|
||||
"Modes \u{2193}",
|
||||
None,
|
||||
"Switch modes: Classic, Daily, Zen, Challenge, Time Attack.",
|
||||
font,
|
||||
5,
|
||||
TEXT_SECONDARY,
|
||||
);
|
||||
spawn_action_button(
|
||||
row,
|
||||
NewGameButton,
|
||||
"New Game",
|
||||
Some("N"),
|
||||
"Start a fresh deal. Confirms first if a game is in progress.",
|
||||
font,
|
||||
6,
|
||||
TEXT_SECONDARY,
|
||||
);
|
||||
}
|
||||
|
||||
/// Spawns a single action button as a child of `row`. Each button shares
|
||||
/// the same node geometry, idle colour, and `ActionButton` marker so
|
||||
/// `paint_action_buttons` can recolour all of them with one query.
|
||||
@@ -510,13 +579,69 @@ pub(super) fn spawn_action_button<M: Component>(
|
||||
None
|
||||
};
|
||||
|
||||
let (pad, min_w, min_h) = action_button_metrics();
|
||||
spawn_action_button_sized(
|
||||
row, marker, label, hotkey, tooltip, font, order, text_color, pad, min_w, min_h,
|
||||
);
|
||||
}
|
||||
|
||||
/// Enlarged variant for the touch bar's core gameplay trio (Phase F):
|
||||
/// bigger padding / minimum target and a scaled-up label so Undo, Draw,
|
||||
/// and Hint read (and hit) as the primary actions. Hotkey chips are
|
||||
/// irrelevant on touch, so the variant takes none.
|
||||
pub(super) fn spawn_primary_action_button<M: Component>(
|
||||
row: &mut ChildSpawnerCommands,
|
||||
marker: M,
|
||||
label: &str,
|
||||
tooltip: &'static str,
|
||||
font: &TextFont,
|
||||
order: i32,
|
||||
) {
|
||||
let (pad, min_w, min_h) = primary_action_button_metrics();
|
||||
let primary_font = TextFont {
|
||||
font: font.font.clone(),
|
||||
// 1.35× the bar's responsive size, capped so landscape tablets
|
||||
// don't blow the row height out.
|
||||
font_size: (font.font_size * 1.35).min(24.0),
|
||||
..default()
|
||||
};
|
||||
spawn_action_button_sized(
|
||||
row,
|
||||
marker,
|
||||
label,
|
||||
None,
|
||||
tooltip,
|
||||
&primary_font,
|
||||
order,
|
||||
TEXT_PRIMARY,
|
||||
pad,
|
||||
min_w,
|
||||
min_h,
|
||||
);
|
||||
}
|
||||
|
||||
/// Shared body of [`spawn_action_button`] / [`spawn_primary_action_button`]
|
||||
/// — one place owns the component set so `paint_action_buttons`, tooltips,
|
||||
/// and the focus ring treat every bar button identically.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn spawn_action_button_sized<M: Component>(
|
||||
row: &mut ChildSpawnerCommands,
|
||||
marker: M,
|
||||
label: &str,
|
||||
hotkey: Option<&'static str>,
|
||||
tooltip: &'static str,
|
||||
font: &TextFont,
|
||||
order: i32,
|
||||
text_color: Color,
|
||||
pad: UiRect,
|
||||
min_w: Val,
|
||||
min_h: Val,
|
||||
) {
|
||||
let hotkey_font = TextFont {
|
||||
font: font.font.clone(),
|
||||
font_size: TYPE_CAPTION,
|
||||
..default()
|
||||
};
|
||||
let (pad, min_w, min_h) = action_button_metrics();
|
||||
|
||||
row.spawn((
|
||||
marker,
|
||||
ActionButton,
|
||||
|
||||
@@ -670,7 +670,7 @@ fn hud_elements_carry_expected_tooltip_strings() {
|
||||
);
|
||||
assert_eq!(
|
||||
tooltip_for::<UndoButton>(&mut app),
|
||||
"Take back your last move. Costs points and blocks No Undo."
|
||||
"Take back your last move. Hold to keep undoing. Costs points and blocks No Undo."
|
||||
);
|
||||
assert_eq!(
|
||||
tooltip_for::<PauseButton>(&mut app),
|
||||
@@ -899,3 +899,157 @@ fn hud_focus_only_engages_when_button_hovered() {
|
||||
"Hud-engaged Tab must focus a Hud-grouped entity"
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Phase F: touch action bar + hold-to-repeat undo
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Bare app (no `HudPlugin`) so bar-content assertions count only the
|
||||
/// buttons the tested spawn function creates — `headless_app` would
|
||||
/// pre-spawn the platform-default bar and pollute the counts.
|
||||
fn bar_only_app(touch: bool) -> App {
|
||||
let mut app = App::new();
|
||||
app.add_plugins(MinimalPlugins);
|
||||
app.update();
|
||||
let font = TextFont::default();
|
||||
let world = app.world_mut();
|
||||
let mut commands = world.commands();
|
||||
commands.spawn(Node::default()).with_children(|row| {
|
||||
if touch {
|
||||
spawn_touch_action_bar(row, &font);
|
||||
} else {
|
||||
spawn_desktop_action_bar(row, &font);
|
||||
}
|
||||
});
|
||||
app.update();
|
||||
app
|
||||
}
|
||||
|
||||
fn count_buttons<C: Component>(app: &mut App) -> usize {
|
||||
app.world_mut()
|
||||
.query_filtered::<(), With<C>>()
|
||||
.iter(app.world())
|
||||
.count()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn touch_action_bar_has_thumb_trio_plus_menu_and_pause() {
|
||||
let mut app = bar_only_app(true);
|
||||
|
||||
assert_eq!(count_buttons::<UndoButton>(&mut app), 1);
|
||||
assert_eq!(count_buttons::<DrawButton>(&mut app), 1);
|
||||
assert_eq!(count_buttons::<HintButton>(&mut app), 1);
|
||||
assert_eq!(count_buttons::<MenuButton>(&mut app), 1);
|
||||
assert_eq!(count_buttons::<PauseButton>(&mut app), 1);
|
||||
|
||||
// Utility actions live elsewhere on touch: Help in Menu → System,
|
||||
// modes on the Home screen, New Game on Home's hero button.
|
||||
assert_eq!(count_buttons::<HelpButton>(&mut app), 0);
|
||||
assert_eq!(count_buttons::<ModesButton>(&mut app), 0);
|
||||
assert_eq!(count_buttons::<NewGameButton>(&mut app), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn desktop_action_bar_keeps_all_seven_and_no_draw() {
|
||||
let mut app = bar_only_app(false);
|
||||
|
||||
for (count, name) in [
|
||||
(count_buttons::<MenuButton>(&mut app), "Menu"),
|
||||
(count_buttons::<UndoButton>(&mut app), "Undo"),
|
||||
(count_buttons::<PauseButton>(&mut app), "Pause"),
|
||||
(count_buttons::<HelpButton>(&mut app), "Help"),
|
||||
(count_buttons::<HintButton>(&mut app), "Hint"),
|
||||
(count_buttons::<ModesButton>(&mut app), "Modes"),
|
||||
(count_buttons::<NewGameButton>(&mut app), "New Game"),
|
||||
] {
|
||||
assert_eq!(count, 1, "desktop bar must keep its {name} button");
|
||||
}
|
||||
assert_eq!(
|
||||
count_buttons::<DrawButton>(&mut app),
|
||||
0,
|
||||
"Draw is touch-only (decision 5); desktop draws via stock click / D / Space"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn draw_button_press_fires_draw_request() {
|
||||
let mut app = headless_app();
|
||||
app.world_mut()
|
||||
.resource_mut::<Messages<DrawRequestEvent>>()
|
||||
.clear();
|
||||
|
||||
app.world_mut().spawn((DrawButton, Interaction::Pressed));
|
||||
app.update();
|
||||
|
||||
let events = app.world().resource::<Messages<DrawRequestEvent>>();
|
||||
let mut cursor = events.get_cursor();
|
||||
assert_eq!(
|
||||
cursor.read(events).count(),
|
||||
1,
|
||||
"pressing the Draw button must fire exactly one DrawRequestEvent"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn draw_button_press_is_noop_while_paused() {
|
||||
let mut app = headless_app();
|
||||
app.insert_resource(PausedResource(true));
|
||||
app.world_mut()
|
||||
.resource_mut::<Messages<DrawRequestEvent>>()
|
||||
.clear();
|
||||
|
||||
app.world_mut().spawn((DrawButton, Interaction::Pressed));
|
||||
app.update();
|
||||
|
||||
let events = app.world().resource::<Messages<DrawRequestEvent>>();
|
||||
let mut cursor = events.get_cursor();
|
||||
assert_eq!(
|
||||
cursor.read(events).count(),
|
||||
0,
|
||||
"the Draw button must be inert while paused (mirrors the stock-click guard)"
|
||||
);
|
||||
}
|
||||
|
||||
/// The timing contract for hold-to-repeat undo, exercised through the
|
||||
/// pure boundary function so no wall-clock is involved. Delay = 0.45 s,
|
||||
/// interval = 0.18 s → boundaries at 0.45, 0.63, 0.81, …
|
||||
#[test]
|
||||
fn undo_hold_boundary_math() {
|
||||
// A tap never repeats.
|
||||
assert!(!undo_hold_crossed_fire_boundary(0.0, 0.05));
|
||||
assert!(!undo_hold_crossed_fire_boundary(0.2, 0.44));
|
||||
// Crossing the initial delay fires the first repeat.
|
||||
assert!(undo_hold_crossed_fire_boundary(0.44, 0.46));
|
||||
// Inside the first repeat interval: quiet.
|
||||
assert!(!undo_hold_crossed_fire_boundary(0.46, 0.62));
|
||||
// Each interval boundary fires exactly once.
|
||||
assert!(undo_hold_crossed_fire_boundary(0.62, 0.64));
|
||||
assert!(!undo_hold_crossed_fire_boundary(0.64, 0.80));
|
||||
assert!(undo_hold_crossed_fire_boundary(0.80, 0.82));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn undo_hold_state_accumulates_and_resets_on_release() {
|
||||
let mut app = headless_app();
|
||||
let button = app
|
||||
.world_mut()
|
||||
.spawn((UndoButton, Interaction::Pressed))
|
||||
.id();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
|
||||
assert!(
|
||||
app.world().resource::<UndoHoldState>().held_secs > 0.0,
|
||||
"held time must accumulate while the Undo button stays pressed"
|
||||
);
|
||||
|
||||
app.world_mut().entity_mut(button).insert(Interaction::None);
|
||||
app.update();
|
||||
|
||||
assert_eq!(
|
||||
app.world().resource::<UndoHoldState>().held_secs,
|
||||
0.0,
|
||||
"releasing the Undo button must reset the hold state"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -554,11 +554,11 @@ pub(super) fn action_bar_font_size(window_width: f32) -> f32 {
|
||||
|
||||
pub(super) fn action_button_metrics() -> (UiRect, Val, Val) {
|
||||
if USE_TOUCH_UI_LAYOUT {
|
||||
// Tight 3 px horizontal padding (down from 4) trims 14 px off the row
|
||||
// total across 7 buttons, and a 44 px min_width (down from 52) lets the
|
||||
// shortest labels ("New", "Help") shrink to their text rather than
|
||||
// padding the row out past the 900 logical-px viewport. min_height
|
||||
// stays at 44 px to preserve the comfortable touch target.
|
||||
// Tight 3 px horizontal padding keeps the compact buttons narrow;
|
||||
// Phase F trimmed the touch bar to 5 buttons (2 compact + 3
|
||||
// primary), so width pressure is lower than the old 7-button row.
|
||||
// min_height stays at 44 px to preserve the comfortable touch
|
||||
// target on the compact buttons.
|
||||
(
|
||||
UiRect::axes(Val::Px(3.0), Val::Px(4.0)),
|
||||
Val::Px(44.0),
|
||||
@@ -573,6 +573,20 @@ pub(super) fn action_button_metrics() -> (UiRect, Val, Val) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Metrics for the touch bar's enlarged Undo / Draw / Hint trio (Phase F).
|
||||
/// 96×64 px targets — comfortably past the 44 px accessibility floor and
|
||||
/// big enough to hit one-handed without looking. Only the touch layout
|
||||
/// spawns primary buttons, so no desktop branch is needed; the desktop
|
||||
/// values exist purely so host-side tests can exercise the touch spawn
|
||||
/// path with sensible numbers.
|
||||
pub(super) fn primary_action_button_metrics() -> (UiRect, Val, Val) {
|
||||
(
|
||||
UiRect::axes(Val::Px(10.0), Val::Px(8.0)),
|
||||
Val::Px(96.0),
|
||||
Val::Px(64.0),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn spawn_action_button_label(
|
||||
parent: &mut ChildSpawnerCommands,
|
||||
label: &str,
|
||||
|
||||
@@ -136,11 +136,22 @@ impl Plugin for InputPlugin {
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
handle_keyboard_core,
|
||||
// The three `DrawRequestEvent` writers join the
|
||||
// self-ambiguous `DrawRequestWriters` set so the HUD's
|
||||
// touch Draw button (hud_plugin, Phase F) can write the
|
||||
// same queue without tripping the ambiguity gate. The
|
||||
// `.chain()` still orders them relative to each other.
|
||||
handle_keyboard_core
|
||||
.in_set(crate::game_plugin::DrawRequestWriters)
|
||||
.ambiguous_with(crate::game_plugin::DrawRequestWriters),
|
||||
handle_keyboard_hint,
|
||||
handle_keyboard_forfeit,
|
||||
handle_stock_click,
|
||||
handle_touch_stock_tap,
|
||||
handle_stock_click
|
||||
.in_set(crate::game_plugin::DrawRequestWriters)
|
||||
.ambiguous_with(crate::game_plugin::DrawRequestWriters),
|
||||
handle_touch_stock_tap
|
||||
.in_set(crate::game_plugin::DrawRequestWriters)
|
||||
.ambiguous_with(crate::game_plugin::DrawRequestWriters),
|
||||
handle_double_click,
|
||||
// Mouse drag pipeline.
|
||||
start_drag,
|
||||
|
||||
@@ -178,6 +178,32 @@ pub fn spawn_modal<M: Component, F>(
|
||||
z_panel: i32,
|
||||
build_card: F,
|
||||
) -> Entity
|
||||
where
|
||||
F: FnOnce(&mut ChildSpawnerCommands),
|
||||
{
|
||||
spawn_modal_sized(
|
||||
commands,
|
||||
plugin_marker,
|
||||
z_panel,
|
||||
MODAL_CARD_MAX_WIDTH,
|
||||
build_card,
|
||||
)
|
||||
}
|
||||
|
||||
/// Default maximum card width in logical pixels — every [`spawn_modal`]
|
||||
/// caller gets this. Surfaces that lay out side-by-side panes (e.g. the
|
||||
/// two-pane Home on wide viewports) can raise it via [`spawn_modal_sized`].
|
||||
pub const MODAL_CARD_MAX_WIDTH: f32 = 720.0;
|
||||
|
||||
/// [`spawn_modal`] with an explicit card `max_width`. Behaviour is
|
||||
/// otherwise identical — same scrim, enter animation, and card chrome.
|
||||
pub fn spawn_modal_sized<M: Component, F>(
|
||||
commands: &mut Commands,
|
||||
plugin_marker: M,
|
||||
z_panel: i32,
|
||||
max_width: f32,
|
||||
build_card: F,
|
||||
) -> Entity
|
||||
where
|
||||
F: FnOnce(&mut ChildSpawnerCommands),
|
||||
{
|
||||
@@ -235,7 +261,7 @@ where
|
||||
padding: UiRect::all(VAL_SPACE_5),
|
||||
border: UiRect::all(Val::Px(1.0)),
|
||||
border_radius: BorderRadius::all(Val::Px(RADIUS_LG)),
|
||||
max_width: Val::Px(720.0),
|
||||
max_width: Val::Px(max_width),
|
||||
align_items: AlignItems::Stretch,
|
||||
..default()
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user