Added "remembering" launchers and wads added
This commit is contained in:
47
src/main.rs
47
src/main.rs
@@ -1,18 +1,18 @@
|
||||
use eframe::egui;
|
||||
use std::path::PathBuf;
|
||||
use config::{default_save_filename, save_config, load_config, Config};
|
||||
use infos::{WadInfo, LauncherInfo};
|
||||
|
||||
pub mod config;
|
||||
pub mod infos;
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
println!("Hello, world!");
|
||||
let options = eframe::NativeOptions {
|
||||
let gui_options = eframe::NativeOptions {
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native(
|
||||
"Rust Doom Launcher",
|
||||
options,
|
||||
gui_options,
|
||||
Box::new(|_cc| Box::<RustDoomLauncher>::default()),
|
||||
)
|
||||
}
|
||||
@@ -25,6 +25,8 @@ struct RustDoomLauncher {
|
||||
selected_iwad: Option<usize>,
|
||||
selected_pwads: Vec<usize>,
|
||||
name: String,
|
||||
config_filename: PathBuf,
|
||||
config_file_loaded: bool,
|
||||
}
|
||||
|
||||
impl Default for RustDoomLauncher {
|
||||
@@ -37,12 +39,51 @@ impl Default for RustDoomLauncher {
|
||||
selected_iwad: None,
|
||||
selected_pwads: Vec::new(),
|
||||
name: "".to_string(),
|
||||
config_filename: default_save_filename(),
|
||||
config_file_loaded: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RustDoomLauncher {
|
||||
// There must be a better way than this - maybe for the RustDoomLauncher to
|
||||
// have a config thing
|
||||
fn get_config_file_stuff(&mut self) -> () {
|
||||
let config = load_config(&self.config_filename).unwrap();
|
||||
if let Some(iwads) = config.iwads {
|
||||
for iwad in iwads {
|
||||
self.all_iwads.push(iwad.clone());
|
||||
}
|
||||
}
|
||||
if let Some(pwads) = config.pwads {
|
||||
for pwad in pwads {
|
||||
self.all_pwads.push(pwad.clone());
|
||||
}
|
||||
}
|
||||
if let Some(launchers) = config.launchers {
|
||||
for launcher in launchers {
|
||||
self.all_launchers.push(launcher.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for RustDoomLauncher {
|
||||
fn on_close_event(&mut self) -> bool {
|
||||
let config = Config {
|
||||
iwads: Some(self.all_iwads.clone()),
|
||||
pwads: Some(self.all_pwads.clone()),
|
||||
launchers: Some(self.all_launchers.clone()),
|
||||
};
|
||||
save_config(&self.config_filename, &config);
|
||||
true
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
if self.config_file_loaded == false {
|
||||
self.get_config_file_stuff();
|
||||
self.config_file_loaded = true;
|
||||
}
|
||||
egui::containers::panel::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("RustDoomLauncher");
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
|
||||
Reference in New Issue
Block a user