Display (Player 1) or (Player 2) consistently

This commit is contained in:
Simon Gellis 2026-07-16 23:56:20 -04:00
parent b283b69f74
commit d934c843eb
No known key found for this signature in database
GPG Key ID: DA576912FED9577B
12 changed files with 68 additions and 33 deletions

View File

@ -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)
}

View File

@ -28,11 +28,11 @@ mod utils;
mod vip;
pub trait AppWindow {
fn sim_id(&self) -> SimId {
SimId::Player1
fn sim_id(&self) -> Option<SimId> {
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);

View File

@ -53,6 +53,7 @@ pub struct GameWindow {
children: ViewportIdMap<ChildWindowWrapper>,
child_states: UiData<ViewportIdMap<ChildState>>,
queued_children: Vec<ChildWindow>,
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<SimId> {
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<Mutex<AppWrapper>>,
title: String,
sim_id: Option<SimId>,
updates: Option<ViewportBuilder>,
close_requested: Arc<AtomicBool>,
}

View File

@ -42,13 +42,13 @@ impl GdbServerWindow {
}
impl AppWindow for GdbServerWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
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))
}

View File

@ -82,13 +82,13 @@ impl ProfileWindow {
}
impl AppWindow for ProfileWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
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))
}

View File

@ -29,13 +29,13 @@ impl TerminalWindow {
}
impl AppWindow for TerminalWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
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))
}

View File

@ -191,13 +191,13 @@ impl BgMapWindow {
}
impl AppWindow for BgMapWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
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))
}

View File

@ -251,13 +251,13 @@ impl CharacterDataWindow {
}
impl AppWindow for CharacterDataWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
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))
}

View File

@ -151,13 +151,13 @@ impl FrameBufferWindow {
}
impl AppWindow for FrameBufferWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
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))
}

View File

@ -207,13 +207,13 @@ impl ObjectWindow {
}
impl AppWindow for ObjectWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
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))
}

View File

@ -630,13 +630,13 @@ fn read_address<T: MemoryValue>(registers: &MemoryRef, address: usize) -> T {
}
impl AppWindow for RegisterWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
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))
}

View File

@ -527,13 +527,13 @@ impl WorldWindow {
}
impl AppWindow for WorldWindow {
fn sim_id(&self) -> SimId {
self.sim_id
fn sim_id(&self) -> Option<SimId> {
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))
}