From e569a2720c1c00d49b9d3c11e3735057d0b8e32a Mon Sep 17 00:00:00 2001 From: pjht Date: Thu, 8 Feb 2024 13:08:53 -0600 Subject: [PATCH] Only allow changing cards when system power is off --- src/option_window.rs | 9 +++++++-- src/state.rs | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/option_window.rs b/src/option_window.rs index 3933b16..6ad4f78 100644 --- a/src/option_window.rs +++ b/src/option_window.rs @@ -19,6 +19,7 @@ pub struct OptionWindow { category: OptionsCategory, card_options: Vec<(&'static Type, Box)>, select_idx: Option, + allow_changing_cards: bool, } #[derive(PartialEq, Eq)] @@ -41,13 +42,16 @@ impl OptionWindow { category: OptionsCategory::General, card_options, select_idx, + allow_changing_cards: !state.power(), } } fn sync_settings(&self, state: &mut EmuState) { state.update_options(self.options); - let cards = self.card_options.iter().map(|(typ, settings_ui)| (*typ, typ.new_card(ron::from_str(&settings_ui.serialize_settings()).unwrap()).unwrap())).collect(); - state.set_cards(cards); + if self.allow_changing_cards { + let cards = self.card_options.iter().map(|(typ, settings_ui)| (*typ, typ.new_card(ron::from_str(&settings_ui.serialize_settings()).unwrap()).unwrap())).collect(); + state.set_cards(cards); + } } } @@ -69,6 +73,7 @@ impl Window for OptionWindow { } OptionsCategory::Cards => { TopBottomPanel::top("card_opts").show_inside(ui, |ui| { + ui.set_enabled(self.allow_changing_cards); SidePanel::left("card_opts_left") .show_separator_line(false) .show_inside(ui, |ui| { diff --git a/src/state.rs b/src/state.rs index 97fe804..857caf1 100644 --- a/src/state.rs +++ b/src/state.rs @@ -229,6 +229,10 @@ impl EmuState { self.cards.iter().map(|(typ, card)| (typ.name().to_string(), card.get_settings())).collect() } + pub fn power(&self) -> bool { + self.fp_state.power() + } + fn read_mem(&mut self, address: u16) -> u8 { self.cards.iter_mut().find_map(|(_, card)| card.read_mem(address)).unwrap_or(0xFF) }