From f074aa55d0e6e0cbb5f54c4c3619878b2692ae37 Mon Sep 17 00:00:00 2001 From: Arthur Roberts Date: Mon, 12 Jun 2023 21:10:11 +0100 Subject: [PATCH] Adding some nice things --- src/main.rs | 60 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/src/main.rs b/src/main.rs index 40ad9d6..88f3625 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use config::{default_save_filename, load_config, save_config, Config}; use eframe::egui; +use eframe::egui::Color32; use infos::{Difficulty, LauncherInfo, WadInfo}; use native_dialog::{MessageDialog, MessageType}; use std::path::PathBuf; @@ -86,33 +87,27 @@ impl RustDoomLauncher { } fn get_launcher_and_command(&self, show_dialogs: bool) -> Result<(&str, Vec<&str>), MyErrors> { - let launcher = match self.selected_launcher { - Some(l) => self.all_launchers.get(l).unwrap(), - None => { + let (launcher, iwad) = match self.launcher_and_iwad() { + Err(e) => { + let text = match e { + MyErrors::NoIwad => { + "an IWAD" + }, + MyErrors::NoLauncher => { + "a launcher" + } + }; if show_dialogs { MessageDialog::new() .set_type(MessageType::Error) .set_title("I can't let you do that") - .set_text("You didn't pick a launcher!\nPlease do that") + .set_text(&format!("You didn't pick {}!\nPlease do that", text)) .show_alert() .unwrap(); } - return Err(MyErrors::NoLauncher); - } - }; - let iwad = match self.selected_iwad { - Some(i) => self.all_iwads.get(i).unwrap(), - None => { - if show_dialogs { - MessageDialog::new() - .set_type(MessageType::Error) - .set_title("I can't let you do that") - .set_text("You didn't pick an IWAD!\nPlease do that") - .show_alert() - .unwrap(); - } - return Err(MyErrors::NoIwad); - } + return Err(e); + }, + Ok((l, i)) => (l, i) }; let mut command = vec!["-iwad", iwad.path.to_str().unwrap()]; for pwad_index in &self.selected_pwads { @@ -156,6 +151,22 @@ impl RustDoomLauncher { Command::new(launcher).args(command).spawn(); } } + + fn launcher_and_iwad(&self) -> Result<(&LauncherInfo,& WadInfo), MyErrors> { + let launcher = match self.selected_launcher { + Some(l) => self.all_launchers.get(l).unwrap(), + None => { + return Err(MyErrors::NoLauncher); + } + }; + let iwad = match self.selected_iwad { + Some(i) => self.all_iwads.get(i).unwrap(), + None => { + return Err(MyErrors::NoIwad); + } + }; + Ok((launcher, iwad)) + } } impl eframe::App for RustDoomLauncher { @@ -177,7 +188,11 @@ impl eframe::App for RustDoomLauncher { egui::containers::panel::CentralPanel::default().show(ctx, |ui| { ui.horizontal(|ui| { ui.heading("RustDoomLauncher"); - if ui.button("PLAY SOME DOOM!").clicked() { + let button = match self.launcher_and_iwad() { + Err(_) => egui::Button::new("PLAY SOME DOOM!"), + Ok((_, _)) => egui::Button::new("PLAY SOME DOOM!").fill(Color32::DARK_GREEN) + }; + if ui.add(button).clicked() { self.launch_doom(); } }); @@ -217,7 +232,7 @@ impl eframe::App for RustDoomLauncher { ui.separator(); ui.vertical(|ui| { ui.set_min_width(100.0); - ui.label("PWADs and Mods"); + ui.label("PWADs"); for (pos, pwad) in self.all_pwads.iter().enumerate() { if ui .add(egui::SelectableLabel::new( @@ -267,6 +282,7 @@ impl eframe::App for RustDoomLauncher { }); } } + // TODO - add Mod button - or probably just rethink the whole thing if ui.button("Add PWAD or Mod").clicked() { if let Some(path) = rfd::FileDialog::new().pick_file() { self.all_pwads.push(WadInfo {