From d934c843eb423048b5d06047f32e48c7f89c00a1 Mon Sep 17 00:00:00 2001 From: Simon Gellis Date: Thu, 16 Jul 2026 23:56:20 -0400 Subject: [PATCH] Display (Player 1) or (Player 2) consistently --- src/emulator.rs | 3 +++ src/window.rs | 6 +++--- src/window/game.rs | 38 ++++++++++++++++++++++++++++++++--- src/window/gdb.rs | 6 +++--- src/window/profile.rs | 6 +++--- src/window/terminal.rs | 6 +++--- src/window/vip/bgmap.rs | 6 +++--- src/window/vip/chardata.rs | 6 +++--- src/window/vip/framebuffer.rs | 6 +++--- src/window/vip/object.rs | 6 +++--- src/window/vip/registers.rs | 6 +++--- src/window/vip/world.rs | 6 +++--- 12 files changed, 68 insertions(+), 33 deletions(-) diff --git a/src/emulator.rs b/src/emulator.rs index 976dde1..32dc1e0 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -946,6 +946,9 @@ pub struct EmulatorClient { } impl EmulatorClient { + pub fn has_player_2(&self) -> bool { + self.sim_state(SimId::Player2) != SimState::Uninitialized + } pub fn sim_state(&self, sim_id: SimId) -> SimState { self.sim_state[sim_id.to_index()].load(Ordering::Acquire) } diff --git a/src/window.rs b/src/window.rs index 55a6ae8..8e4d930 100644 --- a/src/window.rs +++ b/src/window.rs @@ -28,11 +28,11 @@ mod utils; mod vip; pub trait AppWindow { - fn sim_id(&self) -> SimId { - SimId::Player1 + fn sim_id(&self) -> Option { + None } fn image_url(&self, name: &str) -> String { - format!("vip://{}/{name}", self.sim_id()) + format!("vip://{}/{name}", self.sim_id().unwrap_or(SimId::Player1)) } fn initial_viewport(&self) -> ViewportBuilder; fn show(&mut self, ui: &mut Ui); diff --git a/src/window/game.rs b/src/window/game.rs index 2f299e0..9a24b85 100644 --- a/src/window/game.rs +++ b/src/window/game.rs @@ -53,6 +53,7 @@ pub struct GameWindow { children: ViewportIdMap, child_states: UiData>, queued_children: Vec, + show_player_name: bool, } impl GameWindow { @@ -94,6 +95,7 @@ impl GameWindow { children: ViewportIdMap::default(), child_states: UiData::new(), queued_children: vec![], + show_player_name: false, } } @@ -176,6 +178,8 @@ impl GameWindow { }; let mut viewport = child.initial_viewport(); + let title = viewport.title.clone().unwrap(); + let sim_id = child.sim_id(); if let Some(state) = self.child_states.get(&viewport_id) { viewport.position = Some(state.position); viewport.inner_size = Some(state.size); @@ -184,6 +188,8 @@ impl GameWindow { viewport_id, ChildWindowWrapper { app: Arc::new(Mutex::new(child)), + title, + sim_id, updates: Some(viewport), close_requested: Arc::new(AtomicBool::new(false)), }, @@ -371,7 +377,7 @@ impl GameWindow { }); ui.menu_button("Options", |ui| self.show_options_menu(ui)); ui.menu_button("Multiplayer", |ui| { - let has_player_2 = self.client.sim_state(SimId::Player2) != SimState::Uninitialized; + let has_player_2 = self.client.has_player_2(); if self.sim_id == SimId::Player1 && !has_player_2 && ui.button("Open Player 2").clicked() @@ -623,8 +629,8 @@ impl GameWindow { } impl AppWindow for GameWindow { - fn sim_id(&self) -> SimId { - self.sim_id + fn sim_id(&self) -> Option { + Some(self.sim_id) } fn initial_viewport(&self) -> ViewportBuilder { @@ -639,6 +645,30 @@ impl AppWindow for GameWindow { } fn show(&mut self, ui: &mut Ui) { + let has_player_2 = self.client.has_player_2(); + if !self.show_player_name && has_player_2 { + ui.send_viewport_cmd(ViewportCommand::Title(format!("Lemur ({})", self.sim_id))); + for (viewport_id, child) in &self.children { + if let Some(sim_id) = child.sim_id { + ui.send_viewport_cmd_to( + *viewport_id, + ViewportCommand::Title(format!("{} ({sim_id})", child.title)), + ); + } + } + self.show_player_name = true; + } else if self.show_player_name && !has_player_2 { + ui.send_viewport_cmd(ViewportCommand::Title("Lemur".to_string())); + for (viewport_id, child) in &self.children { + if child.sim_id.is_some() { + ui.send_viewport_cmd_to( + *viewport_id, + ViewportCommand::Title(child.title.clone()), + ); + } + } + self.show_player_name = false; + } self.child_states.load(ui); let dimensions = { let bounds = ui.content_rect(); @@ -745,6 +775,8 @@ struct ColorPickerState { struct ChildWindowWrapper { app: Arc>, + title: String, + sim_id: Option, updates: Option, close_requested: Arc, } diff --git a/src/window/gdb.rs b/src/window/gdb.rs index f22dc40..0b835b5 100644 --- a/src/window/gdb.rs +++ b/src/window/gdb.rs @@ -42,13 +42,13 @@ impl GdbServerWindow { } impl AppWindow for GdbServerWindow { - fn sim_id(&self) -> SimId { - self.sim_id + fn sim_id(&self) -> Option { + Some(self.sim_id) } fn initial_viewport(&self) -> ViewportBuilder { ViewportBuilder::default() - .with_title(format!("GDB Server ({})", self.sim_id)) + .with_title("GDB Server") .with_inner_size((300.0, 200.0)) } diff --git a/src/window/profile.rs b/src/window/profile.rs index 71fb81d..c498388 100644 --- a/src/window/profile.rs +++ b/src/window/profile.rs @@ -82,13 +82,13 @@ impl ProfileWindow { } impl AppWindow for ProfileWindow { - fn sim_id(&self) -> SimId { - self.sim_id + fn sim_id(&self) -> Option { + Some(self.sim_id) } fn initial_viewport(&self) -> ViewportBuilder { ViewportBuilder::default() - .with_title(format!("Profiler ({})", self.sim_id)) + .with_title("Profiler") .with_inner_size((300.0, 200.0)) } diff --git a/src/window/terminal.rs b/src/window/terminal.rs index c4877e5..2617b91 100644 --- a/src/window/terminal.rs +++ b/src/window/terminal.rs @@ -29,13 +29,13 @@ impl TerminalWindow { } impl AppWindow for TerminalWindow { - fn sim_id(&self) -> SimId { - self.sim_id + fn sim_id(&self) -> Option { + Some(self.sim_id) } fn initial_viewport(&self) -> ViewportBuilder { ViewportBuilder::default() - .with_title(format!("Terminal ({})", self.sim_id)) + .with_title("Terminal") .with_inner_size((640.0, 480.0)) } diff --git a/src/window/vip/bgmap.rs b/src/window/vip/bgmap.rs index 182f7da..9285b8b 100644 --- a/src/window/vip/bgmap.rs +++ b/src/window/vip/bgmap.rs @@ -191,13 +191,13 @@ impl BgMapWindow { } impl AppWindow for BgMapWindow { - fn sim_id(&self) -> SimId { - self.sim_id + fn sim_id(&self) -> Option { + Some(self.sim_id) } fn initial_viewport(&self) -> ViewportBuilder { ViewportBuilder::default() - .with_title(format!("BG Map Data ({})", self.sim_id)) + .with_title("BG Map Data") .with_inner_size((640.0, 480.0)) } diff --git a/src/window/vip/chardata.rs b/src/window/vip/chardata.rs index e70e7ad..6435b88 100644 --- a/src/window/vip/chardata.rs +++ b/src/window/vip/chardata.rs @@ -251,13 +251,13 @@ impl CharacterDataWindow { } impl AppWindow for CharacterDataWindow { - fn sim_id(&self) -> SimId { - self.sim_id + fn sim_id(&self) -> Option { + Some(self.sim_id) } fn initial_viewport(&self) -> ViewportBuilder { ViewportBuilder::default() - .with_title(format!("Character Data ({})", self.sim_id)) + .with_title("Character Data") .with_inner_size((640.0, 480.0)) } diff --git a/src/window/vip/framebuffer.rs b/src/window/vip/framebuffer.rs index 59015ba..cfcfcba 100644 --- a/src/window/vip/framebuffer.rs +++ b/src/window/vip/framebuffer.rs @@ -151,13 +151,13 @@ impl FrameBufferWindow { } impl AppWindow for FrameBufferWindow { - fn sim_id(&self) -> SimId { - self.sim_id + fn sim_id(&self) -> Option { + Some(self.sim_id) } fn initial_viewport(&self) -> ViewportBuilder { ViewportBuilder::default() - .with_title(format!("Frame Buffers ({})", self.sim_id)) + .with_title("Frame Buffers") .with_inner_size((640.0, 480.0)) } diff --git a/src/window/vip/object.rs b/src/window/vip/object.rs index 869230d..4da1d86 100644 --- a/src/window/vip/object.rs +++ b/src/window/vip/object.rs @@ -207,13 +207,13 @@ impl ObjectWindow { } impl AppWindow for ObjectWindow { - fn sim_id(&self) -> SimId { - self.sim_id + fn sim_id(&self) -> Option { + Some(self.sim_id) } fn initial_viewport(&self) -> ViewportBuilder { ViewportBuilder::default() - .with_title(format!("Object Data ({})", self.sim_id)) + .with_title("Object Data") .with_inner_size((640.0, 500.0)) } diff --git a/src/window/vip/registers.rs b/src/window/vip/registers.rs index 5204dab..790057a 100644 --- a/src/window/vip/registers.rs +++ b/src/window/vip/registers.rs @@ -630,13 +630,13 @@ fn read_address(registers: &MemoryRef, address: usize) -> T { } impl AppWindow for RegisterWindow { - fn sim_id(&self) -> SimId { - self.sim_id + fn sim_id(&self) -> Option { + Some(self.sim_id) } fn initial_viewport(&self) -> ViewportBuilder { ViewportBuilder::default() - .with_title(format!("Registers ({})", self.sim_id)) + .with_title("Registers") .with_inner_size((800.0, 480.0)) } diff --git a/src/window/vip/world.rs b/src/window/vip/world.rs index 931c78f..a84fd3e 100644 --- a/src/window/vip/world.rs +++ b/src/window/vip/world.rs @@ -527,13 +527,13 @@ impl WorldWindow { } impl AppWindow for WorldWindow { - fn sim_id(&self) -> SimId { - self.sim_id + fn sim_id(&self) -> Option { + Some(self.sim_id) } fn initial_viewport(&self) -> ViewportBuilder { ViewportBuilder::default() - .with_title(format!("Worlds ({})", self.sim_id)) + .with_title("Worlds") .with_inner_size((640.0, 520.0)) }