From 6004df73f74d425123b0c9a85e2f2dbfd60f21c4 Mon Sep 17 00:00:00 2001 From: Arthur Roberts Date: Tue, 4 Jul 2023 23:34:34 +0100 Subject: [PATCH] Fixed the flag/command line stuff Also added it all into the command_manager thing so the App struct doesn't look quite so busy --- src/infos.rs | 16 +++++++----- src/main.rs | 73 +++++++++++++++++++++++++++++++--------------------- 2 files changed, 54 insertions(+), 35 deletions(-) diff --git a/src/infos.rs b/src/infos.rs index fed5844..f5cd10b 100644 --- a/src/infos.rs +++ b/src/infos.rs @@ -4,13 +4,12 @@ use std::path::PathBuf; use std::slice::Iter; use std::cmp::Ordering; -#[derive(Default)] pub struct CommandManager { pub launcher: Option, pub iwad: Option, pub pwads: Vec, pub warp: String, - pub difficulty: Option, + pub difficulty: Difficulty, pub fast_monsters: bool, pub respawning_monsters: bool, pub command_string: String, @@ -28,7 +27,7 @@ impl CommandManager { iwad: None, pwads: Vec::new(), warp: "".to_string(), - difficulty: None, + difficulty: Difficulty::None, fast_monsters: false, respawning_monsters: false, command_string: "".to_string(), @@ -73,13 +72,18 @@ impl CommandManager { command.push("-file".to_string()); command.push(pwad.clone().into_os_string().into_string().unwrap()); } - if let Some(d) = self.difficulty { + if self.difficulty != Difficulty::None { command.push("-skill".to_string()); - command.push(d.flag_number().to_string()); + command.push(self.difficulty.flag_number().to_string()); } if !self.warp.is_empty() { command.push("-warp".to_string()); - command.push(self.warp.to_string()); + // Again, feel like there's must be a _much_ better way than this... + let warp_string = self.warp.to_string(); + let strings: Vec<&str> = warp_string.split_whitespace().collect(); + for string in strings { + command.push(string.to_string()); + } } if self.respawning_monsters { command.push("-respawn".to_string()); diff --git a/src/main.rs b/src/main.rs index e3aa21b..0f090f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,10 +38,6 @@ struct RustDoomLauncher { config_filename: PathBuf, config_file_loaded: bool, command_manager: CommandManager, - warp_string: String, - difficulty: Difficulty, - fast_monsters: bool, - respawning_monsters: bool, display_command: bool, add_stuff_window_displayed: bool, selected_file_type: FileType, @@ -58,10 +54,6 @@ impl Default for RustDoomLauncher { add_name: "".to_string(), config_filename: default_save_filename(), config_file_loaded: false, - warp_string: String::new(), - difficulty: Difficulty::None, - fast_monsters: false, - respawning_monsters: false, display_command: false, add_stuff_window_displayed: false, selected_file_type: FileType::Pwad, @@ -267,42 +259,65 @@ impl eframe::App for RustDoomLauncher { }); let mut text = "Placeholder for WAD info stuffs"; let window_size = frame.info().window_info.size; - ui.add(egui::TextEdit::multiline(&mut text).desired_width(window_size[0]/1.6).desired_rows(20)); + ui.add( + egui::TextEdit::multiline(&mut text) + .desired_width(window_size[0] / 1.6) + .desired_rows(20), + ); }); ui.separator(); ui.horizontal_wrapped(|ui| { ui.horizontal(|ui| { ui.set_max_width(180.0); let warp_label = ui.label("warp"); - ui.text_edit_singleline(&mut self.warp_string) + let r = ui.text_edit_singleline(&mut self.command_manager.warp) .labelled_by(warp_label.id); + if r.changed() { + let _ = self.command_manager.generate_command_str(); + } }); ui.separator(); ui.horizontal(|ui| { - ui.label("difficulty"); - eframe::egui::ComboBox::new("difficulty", "") - .selected_text(format!("{}", self.difficulty)) - .show_ui(ui, |ui| { - for diff in Difficulty::iterator() { - ui.selectable_value(&mut self.difficulty, *diff, diff.to_string()); - } - }); - }); - ui.separator(); - ui.horizontal(|ui| { - ui.label("fast"); - ui.checkbox(&mut self.fast_monsters, ""); - }); - ui.separator(); - ui.horizontal(|ui| { - ui.label("respawn"); - ui.checkbox(&mut self.respawning_monsters, ""); + ui.horizontal(|ui| { + ui.label("difficulty"); + ui.set_max_width(180.0); + eframe::egui::ComboBox::new("difficulty", "") + .selected_text(format!("{}", self.command_manager.difficulty)) + .show_ui(ui, |ui| { + for diff in Difficulty::iterator() { + let r = ui.selectable_value( + &mut self.command_manager.difficulty, + *diff, + diff.to_string(), + ); + if r.clicked() { + let _ = self.command_manager.generate_command_str(); + } + } + }); + }); + ui.separator(); + ui.horizontal(|ui| { + ui.label("fast"); + let r = ui.add(egui::Checkbox::without_text(&mut self.command_manager.fast_monsters)); + if r.clicked() { + let _ = self.command_manager.generate_command_str(); + } + }); + ui.separator(); + ui.horizontal(|ui| { + ui.label("respawn"); + let r = ui.add(egui::Checkbox::without_text(&mut self.command_manager.respawning_monsters)); + if r.clicked() { + let _ = self.command_manager.generate_command_str(); + } + }); }); }); ui.separator(); ui.horizontal(|ui| { ui.label("Command"); - ui.checkbox(&mut self.display_command, ""); + ui.add(egui::Checkbox::without_text(&mut self.display_command)); }); ui.horizontal_wrapped(|ui| { if let Some(l) = self.launcher_manager.get_current() {