diff --git a/VERSION b/VERSION index aa35920..581e05c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v202611-00009 +v202611-00010 diff --git a/src/main.rs b/src/main.rs index f0f5dfd..4763174 100644 --- a/src/main.rs +++ b/src/main.rs @@ -639,7 +639,7 @@ async fn main() { // ---------------- multiplayer relay: receive messages, send queued requests, update the menu state app.poll_match(); - if matches!(menu.page, Some(Page::Match)) { + if matches!(menu.page, Some(Page::Match { .. })) { menu.set_match_ui(app.client.ui()); } if let Some(info) = app.client.take_start() { diff --git a/src/menu.rs b/src/menu.rs index 25c9db9..4a6175c 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -27,7 +27,7 @@ pub enum Page { Briefing { mission: usize, ingame: bool }, // story and goals of a mission Login, // login to the savegame service (before the title) Account, // password, logout, users (admin) - Match, // multiplayer lobby and match status + Match { from_title: bool }, // multiplayer lobby and match status Bestiary { tab: usize, sel: usize, level: u32, from_title: bool }, // units, buildings, ranks } @@ -375,7 +375,7 @@ impl Menu { Some(Page::Campaign) => Some(Page::Title), Some(Page::Login) => Some(Page::Login), Some(Page::Account) => Some(Page::Title), - Some(Page::Match) => Some(Page::Title), + Some(Page::Match { from_title }) => Some(if from_title { Page::Title } else { Page::Pause }), Some(Page::Bestiary { from_title: true, .. }) => Some(Page::Title), Some(Page::Bestiary { from_title: false, .. }) => Some(Page::Pause), Some(Page::Briefing { ingame: true, .. }) => Some(Page::Pause), @@ -396,7 +396,7 @@ impl Menu { // pages with text fields take keyboard input pub fn typing(&self) -> bool { - matches!(self.page, Some(Page::Saves { save: true, .. }) | Some(Page::Login) | Some(Page::Account) | Some(Page::Match)) + matches!(self.page, Some(Page::Saves { save: true, .. }) | Some(Page::Login) | Some(Page::Account) | Some(Page::Match { .. })) } fn input(&mut self) -> &mut String { @@ -423,7 +423,7 @@ impl Menu { let n = match self.page { Some(Page::Login) => 2, Some(Page::Account) => 4, - Some(Page::Match) => 2, + Some(Page::Match { .. }) => 2, _ => 1, }; self.focus = (self.focus + 1) % n; @@ -433,7 +433,7 @@ impl Menu { pub fn submit(&mut self) -> MenuAction { match self.page { Some(Page::Login) => MenuAction::Login(self.fields[0].trim().to_string(), self.fields[1].clone()), - Some(Page::Match) => { + Some(Page::Match { .. }) => { let action = if self.focus == 1 { MenuAction::MatchChat(self.fields[1].clone()) } else { MenuAction::MatchJoin(self.fields[0].trim().to_string()) }; if self.focus == 1 { self.fields[1].clear(); @@ -446,8 +446,8 @@ impl Menu { } } - pub fn open_match(&mut self) { - self.page = Some(Page::Match); + pub fn open_match(&mut self, from_title: bool) { + self.page = Some(Page::Match { from_title }); self.fields[1].clear(); self.focus = 0; self.error = None; @@ -578,7 +578,7 @@ impl Menu { Some(Btn::ClaudeCode) => MenuAction::OpenClaudeCode, Some(Btn::Field(i)) => { self.focus = i; - if matches!(self.page, Some(Page::Match)) { + if matches!(self.page, Some(Page::Match { .. })) { MenuAction::MatchEditField(i) } else { MenuAction::EditField(i) @@ -605,7 +605,7 @@ impl Menu { None => MenuAction::Consumed, }, Some(Btn::Match) => { - self.open_match(); + self.open_match(from_title); MenuAction::OpenMatch } Some(Btn::MatchJoin) => MenuAction::MatchJoin(self.fields[0].trim().to_string()), @@ -684,7 +684,7 @@ impl Menu { Page::Campaign => self.draw_campaign(gfx), Page::Login => self.draw_login(gfx, cloud), Page::Account => self.draw_account(gfx, cloud), - Page::Match => self.draw_match(gfx, cloud), + Page::Match { .. } => self.draw_match(gfx, cloud), Page::Briefing { mission, ingame } => self.draw_briefing(gfx, mission, ingame), Page::Bestiary { tab, sel, level, .. } => self.draw_bestiary(gfx, tab, sel, level), Page::KeyCapture { action, .. } => { @@ -1466,6 +1466,22 @@ pub fn goal_text(g: Goal) -> String { #[cfg(test)] mod tests { + use super::{Menu, Page}; + + #[test] + fn the_multiplayer_page_remembers_where_it_came_from() { + let mut from_pause = Menu::new(); + from_pause.page = Some(Page::Pause); + from_pause.open_match(false); + from_pause.back(); + assert_eq!(from_pause.page, Some(Page::Pause), "back from a match menu goes back to the pause menu"); + + let mut from_title = Menu::new(); + from_title.open_match(true); + from_title.back(); + assert_eq!(from_title.page, Some(Page::Title), "back from the title multiplayer page goes to the title"); + } + #[test] fn the_version_follows_the_scheme() { let rest = super::version().strip_prefix('v').expect("the version starts with v");