Only allow changing cards when system power is off

This commit is contained in:
pjht 2024-02-08 13:08:53 -06:00
parent 476c744bfa
commit e569a2720c
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A
2 changed files with 11 additions and 2 deletions

View File

@ -19,6 +19,7 @@ pub struct OptionWindow {
category: OptionsCategory, category: OptionsCategory,
card_options: Vec<(&'static Type, Box<dyn SettingsUi>)>, card_options: Vec<(&'static Type, Box<dyn SettingsUi>)>,
select_idx: Option<usize>, select_idx: Option<usize>,
allow_changing_cards: bool,
} }
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
@ -41,15 +42,18 @@ impl OptionWindow {
category: OptionsCategory::General, category: OptionsCategory::General,
card_options, card_options,
select_idx, select_idx,
allow_changing_cards: !state.power(),
} }
} }
fn sync_settings(&self, state: &mut EmuState) { fn sync_settings(&self, state: &mut EmuState) {
state.update_options(self.options); state.update_options(self.options);
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(); 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); state.set_cards(cards);
} }
} }
}
impl Window for OptionWindow { impl Window for OptionWindow {
fn draw(&mut self, ctx: &egui::Context, state: &mut EmuState) -> bool { fn draw(&mut self, ctx: &egui::Context, state: &mut EmuState) -> bool {
@ -69,6 +73,7 @@ impl Window for OptionWindow {
} }
OptionsCategory::Cards => { OptionsCategory::Cards => {
TopBottomPanel::top("card_opts").show_inside(ui, |ui| { TopBottomPanel::top("card_opts").show_inside(ui, |ui| {
ui.set_enabled(self.allow_changing_cards);
SidePanel::left("card_opts_left") SidePanel::left("card_opts_left")
.show_separator_line(false) .show_separator_line(false)
.show_inside(ui, |ui| { .show_inside(ui, |ui| {

View File

@ -229,6 +229,10 @@ impl EmuState {
self.cards.iter().map(|(typ, card)| (typ.name().to_string(), card.get_settings())).collect() 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 { fn read_mem(&mut self, address: u16) -> u8 {
self.cards.iter_mut().find_map(|(_, card)| card.read_mem(address)).unwrap_or(0xFF) self.cards.iter_mut().find_map(|(_, card)| card.read_mem(address)).unwrap_or(0xFF)
} }