diff --git a/src/main.rs b/src/main.rs index 8029c50..d35361b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use eframe::egui; +use std::path::PathBuf; fn main() -> Result<(), eframe::Error> { println!("Hello, world!"); @@ -12,24 +13,35 @@ fn main() -> Result<(), eframe::Error> { ) } +struct WadInfo { + path: PathBuf, + name: String, +} + struct RustDoomLauncher { - launchers: Vec, - all_iwads: Vec, - all_pwads: Vec, + all_launchers: Vec, + all_iwads: Vec, + all_pwads: Vec, selected_launcher: Option, - selected_iwad: Option, - selected_pwads: Vec, + selected_iwad: Option, + selected_pwads: Vec, + launcher_name: String, + iwad_name: String, + pwad_name: String, } impl Default for RustDoomLauncher { fn default() -> Self { Self { - launchers: vec!["GZDoom 1.9".to_string(), "PRBoom+".to_string()], + all_launchers: vec!["GZDoom 1.9".to_string(), "PRBoom+".to_string()], all_iwads: Vec::new(), all_pwads: Vec::new(), selected_launcher: None, selected_iwad: None, selected_pwads: Vec::new(), + launcher_name: "".to_string(), + iwad_name: "".to_string(), + pwad_name: "".to_string(), } } } @@ -39,12 +51,14 @@ impl eframe::App for RustDoomLauncher { egui::containers::panel::CentralPanel::default().show(ctx, |ui| { ui.heading("RustDoomLauncher"); ui.horizontal(|ui| { - ui.label("Launcers"); + ui.label("Launchers"); if ui.button("Add Launcher").clicked() { - todo!(); + if let Some(path) = rfd::FileDialog::new().pick_file() { + self.all_launchers.push(path.display().to_string()); + } } }); - for launcher in &self.launchers { + for launcher in &self.all_launchers { if ui .add(egui::SelectableLabel::new( self.selected_launcher.is_some() @@ -59,44 +73,46 @@ impl eframe::App for RustDoomLauncher { ui.horizontal(|ui| { ui.label("IWADs"); if ui.button("Add IWAD").clicked() { - if let Some(paths) = rfd::FileDialog::new().pick_files() { - for path in paths { - self.all_iwads.push(path.display().to_string()); - } + if let Some(path) = rfd::FileDialog::new().pick_file() { + self.all_iwads.push(WadInfo { + name: path.display().to_string(), + path: path, + }); } } }); - for iwad in &self.all_iwads { + for (pos, iwad) in self.all_iwads.iter().enumerate() { if ui .add(egui::SelectableLabel::new( self.selected_iwad.is_some() - && self.selected_iwad.as_ref().unwrap() == iwad, - iwad, + && *self.selected_iwad.as_ref().unwrap() == pos, + &iwad.name, )) .clicked() { - self.selected_iwad = Some(iwad.to_string()); + self.selected_iwad = Some(pos); } } ui.horizontal(|ui| { - ui.label("PWADs"); - if ui.button("Add PWAD").clicked() { - if let Some(paths) = rfd::FileDialog::new().pick_files() { - for path in paths { - self.all_pwads.push(path.display().to_string()); - } + ui.label("PWADs and Mods"); + if ui.button("Add PWAD or Mod").clicked() { + if let Some(path) = rfd::FileDialog::new().pick_file() { + self.all_pwads.push(WadInfo { + path: path.clone(), + name: path.display().to_string(), + }); } } }); - for pwad in &self.all_pwads { + for (pos, pwad) in self.all_pwads.iter().enumerate() { if ui .add(egui::SelectableLabel::new( - self.selected_pwads.contains(pwad), - pwad, + self.selected_pwads.contains(&pos), + &pwad.name, )) .clicked() { - self.selected_pwads.push(pwad.to_string()); + self.selected_pwads.push(pos); } } ui.label("Command"); @@ -111,7 +127,14 @@ impl eframe::App for RustDoomLauncher { ui.label("Select a launcher plz"); } if let Some(i) = &self.selected_iwad { - if ui.add(egui::SelectableLabel::new(false, i)).clicked() { + if let Some(iwad) = &self.all_iwads.get(*i) { + if ui + .add(egui::SelectableLabel::new(false, &iwad.name)) + .clicked() + { + self.selected_iwad = None; + } + } else { self.selected_iwad = None; } } else { @@ -123,7 +146,7 @@ impl eframe::App for RustDoomLauncher { if ui .add(egui::SelectableLabel::new( false, - self.selected_pwads[pos].clone(), + &self.all_pwads.get(*self.selected_pwads.get(pos).unwrap()).unwrap().name, )) .clicked() {